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
, const JavaParamRef
<jobject
>& jcaller
,
45 const JavaParamRef
<jstring
>& param
);
48 Java_org_chromium_example_jni_1generator_SampleForTests_nativeInit(JNIEnv
*
51 return Init(env
, JavaParamRef
<jobject
>(env
, jcaller
),
52 JavaParamRef
<jstring
>(env
, param
));
56 Java_org_chromium_example_jni_1generator_SampleForTests_nativeDestroy(JNIEnv
*
59 jlong nativeCPPClass
) {
60 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
61 CHECK_NATIVE_PTR(env
, jcaller
, native
, "Destroy");
62 return native
->Destroy(env
, JavaParamRef
<jobject
>(env
, jcaller
));
65 static jdouble
GetDoubleFunction(JNIEnv
* env
, const JavaParamRef
<jobject
>&
69 Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetDoubleFunction(JNIEnv
*
70 env
, jobject jcaller
) {
71 return GetDoubleFunction(env
, JavaParamRef
<jobject
>(env
, jcaller
));
74 static jfloat
GetFloatFunction(JNIEnv
* env
, const JavaParamRef
<jclass
>&
78 Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetFloatFunction(JNIEnv
*
79 env
, jclass jcaller
) {
80 return GetFloatFunction(env
, JavaParamRef
<jclass
>(env
, jcaller
));
83 static void SetNonPODDatatype(JNIEnv
* env
, const JavaParamRef
<jobject
>& jcaller
,
84 const JavaParamRef
<jobject
>& rect
);
87 Java_org_chromium_example_jni_1generator_SampleForTests_nativeSetNonPODDatatype(JNIEnv
*
90 return SetNonPODDatatype(env
, JavaParamRef
<jobject
>(env
, jcaller
),
91 JavaParamRef
<jobject
>(env
, rect
));
94 static ScopedJavaLocalRef
<jobject
> GetNonPODDatatype(JNIEnv
* env
, const
95 JavaParamRef
<jobject
>& jcaller
);
98 Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetNonPODDatatype(JNIEnv
*
99 env
, jobject jcaller
) {
100 return GetNonPODDatatype(env
, JavaParamRef
<jobject
>(env
, jcaller
)).Release();
104 Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod(JNIEnv
*
107 jlong nativeCPPClass
) {
108 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
109 CHECK_NATIVE_PTR(env
, jcaller
, native
, "Method", 0);
110 return native
->Method(env
, JavaParamRef
<jobject
>(env
, jcaller
));
114 Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethodOtherP0(JNIEnv
*
118 CPPClass::InnerClass
* native
=
119 reinterpret_cast<CPPClass::InnerClass
*>(nativePtr
);
120 CHECK_NATIVE_PTR(env
, jcaller
, native
, "MethodOtherP0", 0);
121 return native
->MethodOtherP0(env
, JavaParamRef
<jobject
>(env
, jcaller
));
125 Java_org_chromium_example_jni_1generator_SampleForTests_nativeAddStructB(JNIEnv
*
128 jlong nativeCPPClass
,
130 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
131 CHECK_NATIVE_PTR(env
, jcaller
, native
, "AddStructB");
132 return native
->AddStructB(env
, JavaParamRef
<jobject
>(env
, jcaller
),
133 JavaParamRef
<jobject
>(env
, b
));
137 Java_org_chromium_example_jni_1generator_SampleForTests_nativeIterateAndDoSomethingWithStructB(JNIEnv
*
140 jlong nativeCPPClass
) {
141 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
142 CHECK_NATIVE_PTR(env
, jcaller
, native
, "IterateAndDoSomethingWithStructB");
143 return native
->IterateAndDoSomethingWithStructB(env
,
144 JavaParamRef
<jobject
>(env
, jcaller
));
148 Java_org_chromium_example_jni_1generator_SampleForTests_nativeReturnAString(JNIEnv
*
151 jlong nativeCPPClass
) {
152 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
153 CHECK_NATIVE_PTR(env
, jcaller
, native
, "ReturnAString", NULL
);
154 return native
->ReturnAString(env
, JavaParamRef
<jobject
>(env
,
158 static base::subtle::AtomicWord g_SampleForTests_javaMethod
= 0;
159 static jint
Java_SampleForTests_javaMethod(JNIEnv
* env
, jobject obj
,
162 /* Must call RegisterNativesImpl() */
163 CHECK_CLAZZ(env
, obj
,
164 SampleForTests_clazz(env
), 0);
165 jmethodID method_id
=
166 base::android::MethodID::LazyGet
<
167 base::android::MethodID::TYPE_INSTANCE
>(
168 env
, SampleForTests_clazz(env
),
176 &g_SampleForTests_javaMethod
);
179 env
->CallIntMethod(obj
,
180 method_id
, as_jint(foo
), as_jint(bar
));
181 jni_generator::CheckException(env
);
185 static base::subtle::AtomicWord g_SampleForTests_staticJavaMethod
= 0;
186 static jboolean
Java_SampleForTests_staticJavaMethod(JNIEnv
* env
) {
187 /* Must call RegisterNativesImpl() */
188 CHECK_CLAZZ(env
, SampleForTests_clazz(env
),
189 SampleForTests_clazz(env
), false);
190 jmethodID method_id
=
191 base::android::MethodID::LazyGet
<
192 base::android::MethodID::TYPE_STATIC
>(
193 env
, SampleForTests_clazz(env
),
199 &g_SampleForTests_staticJavaMethod
);
202 env
->CallStaticBooleanMethod(SampleForTests_clazz(env
),
204 jni_generator::CheckException(env
);
208 static base::subtle::AtomicWord g_SampleForTests_packagePrivateJavaMethod
= 0;
209 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv
* env
, jobject
211 /* Must call RegisterNativesImpl() */
212 CHECK_CLAZZ(env
, obj
,
213 SampleForTests_clazz(env
));
214 jmethodID method_id
=
215 base::android::MethodID::LazyGet
<
216 base::android::MethodID::TYPE_INSTANCE
>(
217 env
, SampleForTests_clazz(env
),
218 "packagePrivateJavaMethod",
223 &g_SampleForTests_packagePrivateJavaMethod
);
225 env
->CallVoidMethod(obj
,
227 jni_generator::CheckException(env
);
231 static base::subtle::AtomicWord g_SampleForTests_methodThatThrowsException
= 0;
232 static void Java_SampleForTests_methodThatThrowsException(JNIEnv
* env
, jobject
234 /* Must call RegisterNativesImpl() */
235 CHECK_CLAZZ(env
, obj
,
236 SampleForTests_clazz(env
));
237 jmethodID method_id
=
238 base::android::MethodID::LazyGet
<
239 base::android::MethodID::TYPE_INSTANCE
>(
240 env
, SampleForTests_clazz(env
),
241 "methodThatThrowsException",
246 &g_SampleForTests_methodThatThrowsException
);
248 env
->CallVoidMethod(obj
,
253 static base::subtle::AtomicWord g_InnerStructA_create
= 0;
254 static ScopedJavaLocalRef
<jobject
> Java_InnerStructA_create(JNIEnv
* env
, jlong
258 /* Must call RegisterNativesImpl() */
259 CHECK_CLAZZ(env
, InnerStructA_clazz(env
),
260 InnerStructA_clazz(env
), NULL
);
261 jmethodID method_id
=
262 base::android::MethodID::LazyGet
<
263 base::android::MethodID::TYPE_STATIC
>(
264 env
, InnerStructA_clazz(env
),
272 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;",
273 &g_InnerStructA_create
);
276 env
->CallStaticObjectMethod(InnerStructA_clazz(env
),
277 method_id
, l
, as_jint(i
), s
);
278 jni_generator::CheckException(env
);
279 return ScopedJavaLocalRef
<jobject
>(env
, ret
);
282 static base::subtle::AtomicWord g_SampleForTests_addStructA
= 0;
283 static void Java_SampleForTests_addStructA(JNIEnv
* env
, jobject obj
, jobject a
)
285 /* Must call RegisterNativesImpl() */
286 CHECK_CLAZZ(env
, obj
,
287 SampleForTests_clazz(env
));
288 jmethodID method_id
=
289 base::android::MethodID::LazyGet
<
290 base::android::MethodID::TYPE_INSTANCE
>(
291 env
, SampleForTests_clazz(env
),
295 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;"
298 &g_SampleForTests_addStructA
);
300 env
->CallVoidMethod(obj
,
302 jni_generator::CheckException(env
);
306 static base::subtle::AtomicWord g_SampleForTests_iterateAndDoSomething
= 0;
307 static void Java_SampleForTests_iterateAndDoSomething(JNIEnv
* env
, jobject obj
)
309 /* Must call RegisterNativesImpl() */
310 CHECK_CLAZZ(env
, obj
,
311 SampleForTests_clazz(env
));
312 jmethodID method_id
=
313 base::android::MethodID::LazyGet
<
314 base::android::MethodID::TYPE_INSTANCE
>(
315 env
, SampleForTests_clazz(env
),
316 "iterateAndDoSomething",
321 &g_SampleForTests_iterateAndDoSomething
);
323 env
->CallVoidMethod(obj
,
325 jni_generator::CheckException(env
);
329 static base::subtle::AtomicWord g_InnerStructB_getKey
= 0;
330 static jlong
Java_InnerStructB_getKey(JNIEnv
* env
, jobject obj
) {
331 /* Must call RegisterNativesImpl() */
332 CHECK_CLAZZ(env
, obj
,
333 InnerStructB_clazz(env
), 0);
334 jmethodID method_id
=
335 base::android::MethodID::LazyGet
<
336 base::android::MethodID::TYPE_INSTANCE
>(
337 env
, InnerStructB_clazz(env
),
343 &g_InnerStructB_getKey
);
346 env
->CallLongMethod(obj
,
348 jni_generator::CheckException(env
);
352 static base::subtle::AtomicWord g_InnerStructB_getValue
= 0;
353 static ScopedJavaLocalRef
<jstring
> Java_InnerStructB_getValue(JNIEnv
* env
,
355 /* Must call RegisterNativesImpl() */
356 CHECK_CLAZZ(env
, obj
,
357 InnerStructB_clazz(env
), NULL
);
358 jmethodID method_id
=
359 base::android::MethodID::LazyGet
<
360 base::android::MethodID::TYPE_INSTANCE
>(
361 env
, InnerStructB_clazz(env
),
366 "Ljava/lang/String;",
367 &g_InnerStructB_getValue
);
370 static_cast<jstring
>(env
->CallObjectMethod(obj
,
372 jni_generator::CheckException(env
);
373 return ScopedJavaLocalRef
<jstring
>(env
, ret
);
376 // Step 3: RegisterNatives.
378 static const JNINativeMethod kMethodsSampleForTests
[] = {
384 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeInit
)
391 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeDestroy
)
393 { "nativeGetDoubleFunction",
397 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetDoubleFunction
)
399 { "nativeGetFloatFunction",
403 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetFloatFunction
)
405 { "nativeSetNonPODDatatype",
407 "Landroid/graphics/Rect;"
410 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeSetNonPODDatatype
)
412 { "nativeGetNonPODDatatype",
415 "Ljava/lang/Object;",
416 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetNonPODDatatype
)
423 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod
)
425 { "nativeMethodOtherP0",
430 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethodOtherP0
)
432 { "nativeAddStructB",
435 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructB;"
438 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeAddStructB
)
440 { "nativeIterateAndDoSomethingWithStructB",
445 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeIterateAndDoSomethingWithStructB
)
447 { "nativeReturnAString",
451 "Ljava/lang/String;",
452 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeReturnAString
)
456 static bool RegisterNativesImpl(JNIEnv
* env
) {
458 g_InnerStructA_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
459 base::android::GetClass(env
, kInnerStructAClassPath
).obj()));
460 g_SampleForTests_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
461 base::android::GetClass(env
, kSampleForTestsClassPath
).obj()));
462 g_InnerStructB_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
463 base::android::GetClass(env
, kInnerStructBClassPath
).obj()));
465 const int kMethodsSampleForTestsSize
= arraysize(kMethodsSampleForTests
);
467 if (env
->RegisterNatives(SampleForTests_clazz(env
),
468 kMethodsSampleForTests
,
469 kMethodsSampleForTestsSize
) < 0) {
470 jni_generator::HandleRegistrationError(
471 env
, SampleForTests_clazz(env
), __FILE__
);
478 } // namespace android
481 #endif // org_chromium_example_jni_generator_SampleForTests_JNI