1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This file is autogenerated by
6 // base/android/jni_generator/jni_generator.py
8 // org/chromium/example/jni_generator/SampleForTests
10 #ifndef org_chromium_example_jni_generator_SampleForTests_JNI
11 #define org_chromium_example_jni_generator_SampleForTests_JNI
15 #include "base/android/jni_generator/jni_generator_helper.h"
17 #include "base/android/jni_int_wrapper.h"
19 // Step 1: forward declarations.
21 const char kSampleForTestsClassPath[] =
22 "org/chromium/example/jni_generator/SampleForTests";
23 // Leaking this jclass as we cannot use LazyInstance from some threads.
24 base::subtle::AtomicWord g_SampleForTests_clazz __attribute__((unused)) = 0;
25 #define SampleForTests_clazz(env) base::android::LazyGetClass(env, kSampleForTestsClassPath, &g_SampleForTests_clazz)
31 static jint Init(JNIEnv* env, jobject jcaller);
33 __attribute__((visibility("default")))
35 Java_org_chromium_example_jni_1generator_SampleForTests_00024MyInnerClass_nativeInit(JNIEnv*
36 env, jobject jcaller) {
37 return Init(env, jcaller);
40 static jint Init(JNIEnv* env, jobject jcaller);
42 __attribute__((visibility("default")))
44 Java_org_chromium_example_jni_1generator_SampleForTests_00024MyOtherInnerClass_nativeInit(JNIEnv*
45 env, jobject jcaller) {
46 return Init(env, jcaller);
51 // Step 2: method stubs.
54 __attribute__((visibility("default")))
56 Java_org_chromium_example_jni_1generator_SampleForTests_nativeStaticMethod(JNIEnv*
61 Test* native = reinterpret_cast<Test*>(nativeTest);
62 CHECK_NATIVE_PTR(env, jcaller, native, "StaticMethod", 0);
63 return native->StaticMethod(env, jcaller, arg1);
66 __attribute__((visibility("default")))
68 Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod(JNIEnv*
73 Test* native = reinterpret_cast<Test*>(nativeTest);
74 CHECK_NATIVE_PTR(env, jcaller, native, "Method", 0);
75 return native->Method(env, jcaller, arg1);
78 static base::subtle::AtomicWord g_SampleForTests_testMethodWithParam = 0;
79 static void Java_SampleForTests_testMethodWithParam(JNIEnv* env, jobject obj,
80 JniIntWrapper iParam) {
81 /* Must call RegisterNativesImpl() */
83 SampleForTests_clazz(env));
85 base::android::MethodID::LazyGet<
86 base::android::MethodID::TYPE_INSTANCE>(
87 env, SampleForTests_clazz(env),
88 "testMethodWithParam",
94 &g_SampleForTests_testMethodWithParam);
96 env->CallVoidMethod(obj,
97 method_id, as_jint(iParam));
98 jni_generator::CheckException(env);
102 static base::subtle::AtomicWord g_SampleForTests_testMethodWithParamAndReturn =
104 static base::android::ScopedJavaLocalRef<jstring>
105 Java_SampleForTests_testMethodWithParamAndReturn(JNIEnv* env, jobject obj,
106 JniIntWrapper iParam) {
107 /* Must call RegisterNativesImpl() */
108 CHECK_CLAZZ(env, obj,
109 SampleForTests_clazz(env), NULL);
110 jmethodID method_id =
111 base::android::MethodID::LazyGet<
112 base::android::MethodID::TYPE_INSTANCE>(
113 env, SampleForTests_clazz(env),
114 "testMethodWithParamAndReturn",
119 "Ljava/lang/String;",
120 &g_SampleForTests_testMethodWithParamAndReturn);
123 static_cast<jstring>(env->CallObjectMethod(obj,
124 method_id, as_jint(iParam)));
125 jni_generator::CheckException(env);
126 return base::android::ScopedJavaLocalRef<jstring>(env, ret);
129 static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithParam = 0;
130 static jint Java_SampleForTests_testStaticMethodWithParam(JNIEnv* env,
131 JniIntWrapper iParam) {
132 /* Must call RegisterNativesImpl() */
133 CHECK_CLAZZ(env, SampleForTests_clazz(env),
134 SampleForTests_clazz(env), 0);
135 jmethodID method_id =
136 base::android::MethodID::LazyGet<
137 base::android::MethodID::TYPE_STATIC>(
138 env, SampleForTests_clazz(env),
139 "testStaticMethodWithParam",
145 &g_SampleForTests_testStaticMethodWithParam);
148 env->CallStaticIntMethod(SampleForTests_clazz(env),
149 method_id, as_jint(iParam));
150 jni_generator::CheckException(env);
154 static base::subtle::AtomicWord g_SampleForTests_testMethodWithNoParam = 0;
155 static jdouble Java_SampleForTests_testMethodWithNoParam(JNIEnv* env) {
156 /* Must call RegisterNativesImpl() */
157 CHECK_CLAZZ(env, SampleForTests_clazz(env),
158 SampleForTests_clazz(env), 0);
159 jmethodID method_id =
160 base::android::MethodID::LazyGet<
161 base::android::MethodID::TYPE_STATIC>(
162 env, SampleForTests_clazz(env),
163 "testMethodWithNoParam",
168 &g_SampleForTests_testMethodWithNoParam);
171 env->CallStaticDoubleMethod(SampleForTests_clazz(env),
173 jni_generator::CheckException(env);
177 static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithNoParam =
179 static base::android::ScopedJavaLocalRef<jstring>
180 Java_SampleForTests_testStaticMethodWithNoParam(JNIEnv* env) {
181 /* Must call RegisterNativesImpl() */
182 CHECK_CLAZZ(env, SampleForTests_clazz(env),
183 SampleForTests_clazz(env), NULL);
184 jmethodID method_id =
185 base::android::MethodID::LazyGet<
186 base::android::MethodID::TYPE_STATIC>(
187 env, SampleForTests_clazz(env),
188 "testStaticMethodWithNoParam",
192 "Ljava/lang/String;",
193 &g_SampleForTests_testStaticMethodWithNoParam);
196 static_cast<jstring>(env->CallStaticObjectMethod(SampleForTests_clazz(env),
198 jni_generator::CheckException(env);
199 return base::android::ScopedJavaLocalRef<jstring>(env, ret);
203 // Step 3: RegisterNatives.
205 static const JNINativeMethod kMethodsMyOtherInnerClass[] = {
210 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_00024MyOtherInnerClass_nativeInit)
214 static const JNINativeMethod kMethodsMyInnerClass[] = {
219 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_00024MyInnerClass_nativeInit)
223 static const JNINativeMethod kMethodsSampleForTests[] = {
224 { "nativeStaticMethod",
230 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeStaticMethod)
238 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod)
242 static bool RegisterNativesImpl(JNIEnv* env, jclass clazz) {
243 if (base::android::IsManualJniRegistrationDisabled()) return true;
245 base::subtle::Release_Store(&g_SampleForTests_clazz,
246 static_cast<base::subtle::AtomicWord>(env->NewWeakGlobalRef(clazz));
248 const int kMethodsMyOtherInnerClassSize =
249 arraysize(kMethodsMyOtherInnerClass);
251 if (env->RegisterNatives(MyOtherInnerClass_clazz(env),
252 kMethodsMyOtherInnerClass,
253 kMethodsMyOtherInnerClassSize) < 0) {
254 jni_generator::HandleRegistrationError(
255 env, MyOtherInnerClass_clazz(env), __FILE__);
259 const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass);
261 if (env->RegisterNatives(MyInnerClass_clazz(env),
262 kMethodsMyInnerClass,
263 kMethodsMyInnerClassSize) < 0) {
264 jni_generator::HandleRegistrationError(
265 env, MyInnerClass_clazz(env), __FILE__);
269 const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests);
271 if (env->RegisterNatives(SampleForTests_clazz(env),
272 kMethodsSampleForTests,
273 kMethodsSampleForTestsSize) < 0) {
274 jni_generator::HandleRegistrationError(
275 env, SampleForTests_clazz(env), __FILE__);
282 extern "C" JNIEXPORT bool JNICALL
283 Java_org_chromium_example_jni_1generator_SampleForTests_nativeInitNativeClass(JNIEnv*
285 return RegisterNativesImpl(env, clazz);
288 #endif // org_chromium_example_jni_generator_SampleForTests_JNI