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 ScopedJavaLocalRef
<jobject
> GetNonPODDatatype(JNIEnv
* env
, jobject
94 Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetNonPODDatatype(JNIEnv
*
95 env
, jobject jcaller
) {
96 return GetNonPODDatatype(env
, jcaller
).Release();
100 Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod(JNIEnv
*
103 jlong nativeCPPClass
) {
104 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
105 CHECK_NATIVE_PTR(env
, jcaller
, native
, "Method", 0);
106 return native
->Method(env
, jcaller
);
110 Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethodOtherP0(JNIEnv
*
114 CPPClass::InnerClass
* native
=
115 reinterpret_cast<CPPClass::InnerClass
*>(nativePtr
);
116 CHECK_NATIVE_PTR(env
, jcaller
, native
, "MethodOtherP0", 0);
117 return native
->MethodOtherP0(env
, jcaller
);
121 Java_org_chromium_example_jni_1generator_SampleForTests_nativeAddStructB(JNIEnv
*
124 jlong nativeCPPClass
,
126 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
127 CHECK_NATIVE_PTR(env
, jcaller
, native
, "AddStructB");
128 return native
->AddStructB(env
, jcaller
, b
);
132 Java_org_chromium_example_jni_1generator_SampleForTests_nativeIterateAndDoSomethingWithStructB(JNIEnv
*
135 jlong nativeCPPClass
) {
136 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
137 CHECK_NATIVE_PTR(env
, jcaller
, native
, "IterateAndDoSomethingWithStructB");
138 return native
->IterateAndDoSomethingWithStructB(env
, jcaller
);
142 Java_org_chromium_example_jni_1generator_SampleForTests_nativeReturnAString(JNIEnv
*
145 jlong nativeCPPClass
) {
146 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
147 CHECK_NATIVE_PTR(env
, jcaller
, native
, "ReturnAString", NULL
);
148 return native
->ReturnAString(env
, jcaller
).Release();
151 static base::subtle::AtomicWord g_SampleForTests_javaMethod
= 0;
152 static jint
Java_SampleForTests_javaMethod(JNIEnv
* env
, jobject obj
,
155 /* Must call RegisterNativesImpl() */
156 CHECK_CLAZZ(env
, obj
,
157 SampleForTests_clazz(env
), 0);
158 jmethodID method_id
=
159 base::android::MethodID::LazyGet
<
160 base::android::MethodID::TYPE_INSTANCE
>(
161 env
, SampleForTests_clazz(env
),
169 &g_SampleForTests_javaMethod
);
172 env
->CallIntMethod(obj
,
173 method_id
, as_jint(foo
), as_jint(bar
));
174 jni_generator::CheckException(env
);
178 static base::subtle::AtomicWord g_SampleForTests_staticJavaMethod
= 0;
179 static jboolean
Java_SampleForTests_staticJavaMethod(JNIEnv
* env
) {
180 /* Must call RegisterNativesImpl() */
181 CHECK_CLAZZ(env
, SampleForTests_clazz(env
),
182 SampleForTests_clazz(env
), false);
183 jmethodID method_id
=
184 base::android::MethodID::LazyGet
<
185 base::android::MethodID::TYPE_STATIC
>(
186 env
, SampleForTests_clazz(env
),
192 &g_SampleForTests_staticJavaMethod
);
195 env
->CallStaticBooleanMethod(SampleForTests_clazz(env
),
197 jni_generator::CheckException(env
);
201 static base::subtle::AtomicWord g_SampleForTests_packagePrivateJavaMethod
= 0;
202 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv
* env
, jobject
204 /* Must call RegisterNativesImpl() */
205 CHECK_CLAZZ(env
, obj
,
206 SampleForTests_clazz(env
));
207 jmethodID method_id
=
208 base::android::MethodID::LazyGet
<
209 base::android::MethodID::TYPE_INSTANCE
>(
210 env
, SampleForTests_clazz(env
),
211 "packagePrivateJavaMethod",
216 &g_SampleForTests_packagePrivateJavaMethod
);
218 env
->CallVoidMethod(obj
,
220 jni_generator::CheckException(env
);
224 static base::subtle::AtomicWord g_SampleForTests_methodThatThrowsException
= 0;
225 static void Java_SampleForTests_methodThatThrowsException(JNIEnv
* env
, jobject
227 /* Must call RegisterNativesImpl() */
228 CHECK_CLAZZ(env
, obj
,
229 SampleForTests_clazz(env
));
230 jmethodID method_id
=
231 base::android::MethodID::LazyGet
<
232 base::android::MethodID::TYPE_INSTANCE
>(
233 env
, SampleForTests_clazz(env
),
234 "methodThatThrowsException",
239 &g_SampleForTests_methodThatThrowsException
);
241 env
->CallVoidMethod(obj
,
246 static base::subtle::AtomicWord g_InnerStructA_create
= 0;
247 static ScopedJavaLocalRef
<jobject
> Java_InnerStructA_create(JNIEnv
* env
, jlong
251 /* Must call RegisterNativesImpl() */
252 CHECK_CLAZZ(env
, InnerStructA_clazz(env
),
253 InnerStructA_clazz(env
), NULL
);
254 jmethodID method_id
=
255 base::android::MethodID::LazyGet
<
256 base::android::MethodID::TYPE_STATIC
>(
257 env
, InnerStructA_clazz(env
),
265 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;",
266 &g_InnerStructA_create
);
269 env
->CallStaticObjectMethod(InnerStructA_clazz(env
),
270 method_id
, l
, as_jint(i
), s
);
271 jni_generator::CheckException(env
);
272 return ScopedJavaLocalRef
<jobject
>(env
, ret
);
275 static base::subtle::AtomicWord g_SampleForTests_addStructA
= 0;
276 static void Java_SampleForTests_addStructA(JNIEnv
* env
, jobject obj
, jobject a
)
278 /* Must call RegisterNativesImpl() */
279 CHECK_CLAZZ(env
, obj
,
280 SampleForTests_clazz(env
));
281 jmethodID method_id
=
282 base::android::MethodID::LazyGet
<
283 base::android::MethodID::TYPE_INSTANCE
>(
284 env
, SampleForTests_clazz(env
),
288 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;"
291 &g_SampleForTests_addStructA
);
293 env
->CallVoidMethod(obj
,
295 jni_generator::CheckException(env
);
299 static base::subtle::AtomicWord g_SampleForTests_iterateAndDoSomething
= 0;
300 static void Java_SampleForTests_iterateAndDoSomething(JNIEnv
* env
, jobject obj
)
302 /* Must call RegisterNativesImpl() */
303 CHECK_CLAZZ(env
, obj
,
304 SampleForTests_clazz(env
));
305 jmethodID method_id
=
306 base::android::MethodID::LazyGet
<
307 base::android::MethodID::TYPE_INSTANCE
>(
308 env
, SampleForTests_clazz(env
),
309 "iterateAndDoSomething",
314 &g_SampleForTests_iterateAndDoSomething
);
316 env
->CallVoidMethod(obj
,
318 jni_generator::CheckException(env
);
322 static base::subtle::AtomicWord g_InnerStructB_getKey
= 0;
323 static jlong
Java_InnerStructB_getKey(JNIEnv
* env
, jobject obj
) {
324 /* Must call RegisterNativesImpl() */
325 CHECK_CLAZZ(env
, obj
,
326 InnerStructB_clazz(env
), 0);
327 jmethodID method_id
=
328 base::android::MethodID::LazyGet
<
329 base::android::MethodID::TYPE_INSTANCE
>(
330 env
, InnerStructB_clazz(env
),
336 &g_InnerStructB_getKey
);
339 env
->CallLongMethod(obj
,
341 jni_generator::CheckException(env
);
345 static base::subtle::AtomicWord g_InnerStructB_getValue
= 0;
346 static ScopedJavaLocalRef
<jstring
> Java_InnerStructB_getValue(JNIEnv
* env
,
348 /* Must call RegisterNativesImpl() */
349 CHECK_CLAZZ(env
, obj
,
350 InnerStructB_clazz(env
), NULL
);
351 jmethodID method_id
=
352 base::android::MethodID::LazyGet
<
353 base::android::MethodID::TYPE_INSTANCE
>(
354 env
, InnerStructB_clazz(env
),
359 "Ljava/lang/String;",
360 &g_InnerStructB_getValue
);
363 static_cast<jstring
>(env
->CallObjectMethod(obj
,
365 jni_generator::CheckException(env
);
366 return ScopedJavaLocalRef
<jstring
>(env
, ret
);
369 // Step 3: RegisterNatives.
371 static const JNINativeMethod kMethodsSampleForTests
[] = {
377 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeInit
)
384 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeDestroy
)
386 { "nativeGetDoubleFunction",
390 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetDoubleFunction
)
392 { "nativeGetFloatFunction",
396 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetFloatFunction
)
398 { "nativeSetNonPODDatatype",
400 "Landroid/graphics/Rect;"
403 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeSetNonPODDatatype
)
405 { "nativeGetNonPODDatatype",
408 "Ljava/lang/Object;",
409 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetNonPODDatatype
)
416 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod
)
418 { "nativeMethodOtherP0",
423 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethodOtherP0
)
425 { "nativeAddStructB",
428 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructB;"
431 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeAddStructB
)
433 { "nativeIterateAndDoSomethingWithStructB",
438 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeIterateAndDoSomethingWithStructB
)
440 { "nativeReturnAString",
444 "Ljava/lang/String;",
445 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeReturnAString
)
449 static bool RegisterNativesImpl(JNIEnv
* env
) {
451 g_InnerStructA_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
452 base::android::GetClass(env
, kInnerStructAClassPath
).obj()));
453 g_SampleForTests_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
454 base::android::GetClass(env
, kSampleForTestsClassPath
).obj()));
455 g_InnerStructB_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
456 base::android::GetClass(env
, kInnerStructBClassPath
).obj()));
458 const int kMethodsSampleForTestsSize
= arraysize(kMethodsSampleForTests
);
460 if (env
->RegisterNatives(SampleForTests_clazz(env
),
461 kMethodsSampleForTests
,
462 kMethodsSampleForTestsSize
) < 0) {
463 jni_generator::HandleRegistrationError(
464 env
, SampleForTests_clazz(env
), __FILE__
);
471 } // namespace android
474 #endif // org_chromium_example_jni_generator_SampleForTests_JNI