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 kInnerStructAClassPath
[] =
22 "org/chromium/example/jni_generator/SampleForTests$InnerStructA";
23 const char kSampleForTestsClassPath
[] =
24 "org/chromium/example/jni_generator/SampleForTests";
25 const char kInnerStructBClassPath
[] =
26 "org/chromium/example/jni_generator/SampleForTests$InnerStructB";
27 // Leaking this jclass as we cannot use LazyInstance from some threads.
28 jclass g_InnerStructA_clazz
= NULL
;
29 #define InnerStructA_clazz(env) g_InnerStructA_clazz
30 // Leaking this jclass as we cannot use LazyInstance from some threads.
31 jclass g_SampleForTests_clazz
= NULL
;
32 #define SampleForTests_clazz(env) g_SampleForTests_clazz
33 // Leaking this jclass as we cannot use LazyInstance from some threads.
34 jclass g_InnerStructB_clazz
= NULL
;
35 #define InnerStructB_clazz(env) g_InnerStructB_clazz
42 // Step 2: method stubs.
44 static jlong
Init(JNIEnv
* env
, jobject jcaller
,
48 Java_org_chromium_example_jni_1generator_SampleForTests_nativeInit(JNIEnv
*
51 return Init(env
, jcaller
, param
);
55 Java_org_chromium_example_jni_1generator_SampleForTests_nativeDestroy(JNIEnv
*
58 jlong nativeCPPClass
) {
59 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
60 CHECK_NATIVE_PTR(env
, jcaller
, native
, "Destroy");
61 return native
->Destroy(env
, jcaller
);
64 static jdouble
GetDoubleFunction(JNIEnv
* env
, jobject jcaller
);
67 Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetDoubleFunction(JNIEnv
*
68 env
, jobject jcaller
) {
69 return GetDoubleFunction(env
, jcaller
);
72 static jfloat
GetFloatFunction(JNIEnv
* env
, jclass jcaller
);
75 Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetFloatFunction(JNIEnv
*
76 env
, jclass jcaller
) {
77 return GetFloatFunction(env
, jcaller
);
80 static void SetNonPODDatatype(JNIEnv
* env
, jobject jcaller
,
84 Java_org_chromium_example_jni_1generator_SampleForTests_nativeSetNonPODDatatype(JNIEnv
*
87 return SetNonPODDatatype(env
, jcaller
, rect
);
90 static jobject
GetNonPODDatatype(JNIEnv
* env
, jobject jcaller
);
93 Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetNonPODDatatype(JNIEnv
*
94 env
, jobject jcaller
) {
95 return GetNonPODDatatype(env
, jcaller
);
99 Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod(JNIEnv
*
102 jlong nativeCPPClass
) {
103 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
104 CHECK_NATIVE_PTR(env
, jcaller
, native
, "Method", 0);
105 return native
->Method(env
, jcaller
);
109 Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethodOtherP0(JNIEnv
*
113 CPPClass::InnerClass
* native
=
114 reinterpret_cast<CPPClass::InnerClass
*>(nativePtr
);
115 CHECK_NATIVE_PTR(env
, jcaller
, native
, "MethodOtherP0", 0);
116 return native
->MethodOtherP0(env
, jcaller
);
120 Java_org_chromium_example_jni_1generator_SampleForTests_nativeAddStructB(JNIEnv
*
123 jlong nativeCPPClass
,
125 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
126 CHECK_NATIVE_PTR(env
, jcaller
, native
, "AddStructB");
127 return native
->AddStructB(env
, jcaller
, b
);
131 Java_org_chromium_example_jni_1generator_SampleForTests_nativeIterateAndDoSomethingWithStructB(JNIEnv
*
134 jlong nativeCPPClass
) {
135 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
136 CHECK_NATIVE_PTR(env
, jcaller
, native
, "IterateAndDoSomethingWithStructB");
137 return native
->IterateAndDoSomethingWithStructB(env
, jcaller
);
141 Java_org_chromium_example_jni_1generator_SampleForTests_nativeReturnAString(JNIEnv
*
144 jlong nativeCPPClass
) {
145 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
146 CHECK_NATIVE_PTR(env
, jcaller
, native
, "ReturnAString", NULL
);
147 return native
->ReturnAString(env
, jcaller
).Release();
150 static base::subtle::AtomicWord g_SampleForTests_javaMethod
= 0;
151 static jint
Java_SampleForTests_javaMethod(JNIEnv
* env
, jobject obj
,
154 /* Must call RegisterNativesImpl() */
155 CHECK_CLAZZ(env
, obj
,
156 SampleForTests_clazz(env
), 0);
157 jmethodID method_id
=
158 base::android::MethodID::LazyGet
<
159 base::android::MethodID::TYPE_INSTANCE
>(
160 env
, SampleForTests_clazz(env
),
168 &g_SampleForTests_javaMethod
);
171 env
->CallIntMethod(obj
,
172 method_id
, as_jint(foo
), as_jint(bar
));
173 jni_generator::CheckException(env
);
177 static base::subtle::AtomicWord g_SampleForTests_staticJavaMethod
= 0;
178 static jboolean
Java_SampleForTests_staticJavaMethod(JNIEnv
* env
) {
179 /* Must call RegisterNativesImpl() */
180 CHECK_CLAZZ(env
, SampleForTests_clazz(env
),
181 SampleForTests_clazz(env
), false);
182 jmethodID method_id
=
183 base::android::MethodID::LazyGet
<
184 base::android::MethodID::TYPE_STATIC
>(
185 env
, SampleForTests_clazz(env
),
191 &g_SampleForTests_staticJavaMethod
);
194 env
->CallStaticBooleanMethod(SampleForTests_clazz(env
),
196 jni_generator::CheckException(env
);
200 static base::subtle::AtomicWord g_SampleForTests_packagePrivateJavaMethod
= 0;
201 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv
* env
, jobject
203 /* Must call RegisterNativesImpl() */
204 CHECK_CLAZZ(env
, obj
,
205 SampleForTests_clazz(env
));
206 jmethodID method_id
=
207 base::android::MethodID::LazyGet
<
208 base::android::MethodID::TYPE_INSTANCE
>(
209 env
, SampleForTests_clazz(env
),
210 "packagePrivateJavaMethod",
215 &g_SampleForTests_packagePrivateJavaMethod
);
217 env
->CallVoidMethod(obj
,
219 jni_generator::CheckException(env
);
223 static base::subtle::AtomicWord g_SampleForTests_methodThatThrowsException
= 0;
224 static void Java_SampleForTests_methodThatThrowsException(JNIEnv
* env
, jobject
226 /* Must call RegisterNativesImpl() */
227 CHECK_CLAZZ(env
, obj
,
228 SampleForTests_clazz(env
));
229 jmethodID method_id
=
230 base::android::MethodID::LazyGet
<
231 base::android::MethodID::TYPE_INSTANCE
>(
232 env
, SampleForTests_clazz(env
),
233 "methodThatThrowsException",
238 &g_SampleForTests_methodThatThrowsException
);
240 env
->CallVoidMethod(obj
,
245 static base::subtle::AtomicWord g_InnerStructA_create
= 0;
246 static base::android::ScopedJavaLocalRef
<jobject
>
247 Java_InnerStructA_create(JNIEnv
* env
, jlong l
,
250 /* Must call RegisterNativesImpl() */
251 CHECK_CLAZZ(env
, InnerStructA_clazz(env
),
252 InnerStructA_clazz(env
), NULL
);
253 jmethodID method_id
=
254 base::android::MethodID::LazyGet
<
255 base::android::MethodID::TYPE_STATIC
>(
256 env
, InnerStructA_clazz(env
),
264 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;",
265 &g_InnerStructA_create
);
268 env
->CallStaticObjectMethod(InnerStructA_clazz(env
),
269 method_id
, l
, as_jint(i
), s
);
270 jni_generator::CheckException(env
);
271 return base::android::ScopedJavaLocalRef
<jobject
>(env
, ret
);
274 static base::subtle::AtomicWord g_SampleForTests_addStructA
= 0;
275 static void Java_SampleForTests_addStructA(JNIEnv
* env
, jobject obj
, jobject a
)
277 /* Must call RegisterNativesImpl() */
278 CHECK_CLAZZ(env
, obj
,
279 SampleForTests_clazz(env
));
280 jmethodID method_id
=
281 base::android::MethodID::LazyGet
<
282 base::android::MethodID::TYPE_INSTANCE
>(
283 env
, SampleForTests_clazz(env
),
287 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;"
290 &g_SampleForTests_addStructA
);
292 env
->CallVoidMethod(obj
,
294 jni_generator::CheckException(env
);
298 static base::subtle::AtomicWord g_SampleForTests_iterateAndDoSomething
= 0;
299 static void Java_SampleForTests_iterateAndDoSomething(JNIEnv
* env
, jobject obj
)
301 /* Must call RegisterNativesImpl() */
302 CHECK_CLAZZ(env
, obj
,
303 SampleForTests_clazz(env
));
304 jmethodID method_id
=
305 base::android::MethodID::LazyGet
<
306 base::android::MethodID::TYPE_INSTANCE
>(
307 env
, SampleForTests_clazz(env
),
308 "iterateAndDoSomething",
313 &g_SampleForTests_iterateAndDoSomething
);
315 env
->CallVoidMethod(obj
,
317 jni_generator::CheckException(env
);
321 static base::subtle::AtomicWord g_InnerStructB_getKey
= 0;
322 static jlong
Java_InnerStructB_getKey(JNIEnv
* env
, jobject obj
) {
323 /* Must call RegisterNativesImpl() */
324 CHECK_CLAZZ(env
, obj
,
325 InnerStructB_clazz(env
), 0);
326 jmethodID method_id
=
327 base::android::MethodID::LazyGet
<
328 base::android::MethodID::TYPE_INSTANCE
>(
329 env
, InnerStructB_clazz(env
),
335 &g_InnerStructB_getKey
);
338 env
->CallLongMethod(obj
,
340 jni_generator::CheckException(env
);
344 static base::subtle::AtomicWord g_InnerStructB_getValue
= 0;
345 static base::android::ScopedJavaLocalRef
<jstring
>
346 Java_InnerStructB_getValue(JNIEnv
* env
, jobject obj
) {
347 /* Must call RegisterNativesImpl() */
348 CHECK_CLAZZ(env
, obj
,
349 InnerStructB_clazz(env
), NULL
);
350 jmethodID method_id
=
351 base::android::MethodID::LazyGet
<
352 base::android::MethodID::TYPE_INSTANCE
>(
353 env
, InnerStructB_clazz(env
),
358 "Ljava/lang/String;",
359 &g_InnerStructB_getValue
);
362 static_cast<jstring
>(env
->CallObjectMethod(obj
,
364 jni_generator::CheckException(env
);
365 return base::android::ScopedJavaLocalRef
<jstring
>(env
, ret
);
368 // Step 3: RegisterNatives.
370 static const JNINativeMethod kMethodsSampleForTests
[] = {
376 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeInit
)
383 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeDestroy
)
385 { "nativeGetDoubleFunction",
389 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetDoubleFunction
)
391 { "nativeGetFloatFunction",
395 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetFloatFunction
)
397 { "nativeSetNonPODDatatype",
399 "Landroid/graphics/Rect;"
402 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeSetNonPODDatatype
)
404 { "nativeGetNonPODDatatype",
407 "Ljava/lang/Object;",
408 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetNonPODDatatype
)
415 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod
)
417 { "nativeMethodOtherP0",
422 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethodOtherP0
)
424 { "nativeAddStructB",
427 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructB;"
430 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeAddStructB
)
432 { "nativeIterateAndDoSomethingWithStructB",
437 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeIterateAndDoSomethingWithStructB
)
439 { "nativeReturnAString",
443 "Ljava/lang/String;",
444 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeReturnAString
)
448 static bool RegisterNativesImpl(JNIEnv
* env
) {
450 g_InnerStructA_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
451 base::android::GetClass(env
, kInnerStructAClassPath
).obj()));
452 g_SampleForTests_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
453 base::android::GetClass(env
, kSampleForTestsClassPath
).obj()));
454 g_InnerStructB_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
455 base::android::GetClass(env
, kInnerStructBClassPath
).obj()));
457 const int kMethodsSampleForTestsSize
= arraysize(kMethodsSampleForTests
);
459 if (env
->RegisterNatives(SampleForTests_clazz(env
),
460 kMethodsSampleForTests
,
461 kMethodsSampleForTestsSize
) < 0) {
462 jni_generator::HandleRegistrationError(
463 env
, SampleForTests_clazz(env
), __FILE__
);
470 } // namespace android
473 #endif // org_chromium_example_jni_generator_SampleForTests_JNI