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 BASE_ANDROID_JNI_GENERATOR_GOLDEN_SAMPLE_FOR_TESTS_JNI_H_
11 #define BASE_ANDROID_JNI_GENERATOR_GOLDEN_SAMPLE_FOR_TESTS_JNI_H_
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 static jlong
Init(JNIEnv
* env
, jobject jcaller
,
45 static jdouble
GetDoubleFunction(JNIEnv
* env
, jobject jcaller
);
47 static jfloat
GetFloatFunction(JNIEnv
* env
, jclass jcaller
);
49 static void SetNonPODDatatype(JNIEnv
* env
, jobject jcaller
,
52 static jobject
GetNonPODDatatype(JNIEnv
* env
, jobject jcaller
);
54 // Step 2: method stubs.
55 static void Destroy(JNIEnv
* env
, jobject jcaller
,
56 jlong nativeCPPClass
) {
57 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
58 CHECK_NATIVE_PTR(env
, jcaller
, native
, "Destroy");
59 return native
->Destroy(env
, jcaller
);
62 static jint
Method(JNIEnv
* env
, jobject jcaller
,
63 jlong nativeCPPClass
) {
64 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
65 CHECK_NATIVE_PTR(env
, jcaller
, native
, "Method", 0);
66 return native
->Method(env
, jcaller
);
69 static jdouble
MethodOtherP0(JNIEnv
* env
, jobject jcaller
,
71 CPPClass::InnerClass
* native
=
72 reinterpret_cast<CPPClass::InnerClass
*>(nativePtr
);
73 CHECK_NATIVE_PTR(env
, jcaller
, native
, "MethodOtherP0", 0);
74 return native
->MethodOtherP0(env
, jcaller
);
77 static void AddStructB(JNIEnv
* env
, jobject jcaller
,
80 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
81 CHECK_NATIVE_PTR(env
, jcaller
, native
, "AddStructB");
82 return native
->AddStructB(env
, jcaller
, b
);
85 static void IterateAndDoSomethingWithStructB(JNIEnv
* env
, jobject jcaller
,
86 jlong nativeCPPClass
) {
87 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
88 CHECK_NATIVE_PTR(env
, jcaller
, native
, "IterateAndDoSomethingWithStructB");
89 return native
->IterateAndDoSomethingWithStructB(env
, jcaller
);
92 static jstring
ReturnAString(JNIEnv
* env
, jobject jcaller
,
93 jlong nativeCPPClass
) {
94 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
95 CHECK_NATIVE_PTR(env
, jcaller
, native
, "ReturnAString", NULL
);
96 return native
->ReturnAString(env
, jcaller
).Release();
99 static base::subtle::AtomicWord g_SampleForTests_javaMethod
= 0;
100 static jint
Java_SampleForTests_javaMethod(JNIEnv
* env
, jobject obj
,
103 /* Must call RegisterNativesImpl() */
104 CHECK_CLAZZ(env
, obj
,
105 SampleForTests_clazz(env
), 0);
106 jmethodID method_id
=
107 base::android::MethodID::LazyGet
<
108 base::android::MethodID::TYPE_INSTANCE
>(
109 env
, SampleForTests_clazz(env
),
117 &g_SampleForTests_javaMethod
);
120 env
->CallIntMethod(obj
,
121 method_id
, as_jint(foo
), as_jint(bar
));
122 jni_generator::CheckException(env
);
126 static base::subtle::AtomicWord g_SampleForTests_staticJavaMethod
= 0;
127 static jboolean
Java_SampleForTests_staticJavaMethod(JNIEnv
* env
) {
128 /* Must call RegisterNativesImpl() */
129 CHECK_CLAZZ(env
, SampleForTests_clazz(env
),
130 SampleForTests_clazz(env
), false);
131 jmethodID method_id
=
132 base::android::MethodID::LazyGet
<
133 base::android::MethodID::TYPE_STATIC
>(
134 env
, SampleForTests_clazz(env
),
140 &g_SampleForTests_staticJavaMethod
);
143 env
->CallStaticBooleanMethod(SampleForTests_clazz(env
),
145 jni_generator::CheckException(env
);
149 static base::subtle::AtomicWord g_SampleForTests_packagePrivateJavaMethod
= 0;
150 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv
* env
, jobject
152 /* Must call RegisterNativesImpl() */
153 CHECK_CLAZZ(env
, obj
,
154 SampleForTests_clazz(env
));
155 jmethodID method_id
=
156 base::android::MethodID::LazyGet
<
157 base::android::MethodID::TYPE_INSTANCE
>(
158 env
, SampleForTests_clazz(env
),
159 "packagePrivateJavaMethod",
164 &g_SampleForTests_packagePrivateJavaMethod
);
166 env
->CallVoidMethod(obj
,
168 jni_generator::CheckException(env
);
172 static base::subtle::AtomicWord g_SampleForTests_methodThatThrowsException
= 0;
173 static void Java_SampleForTests_methodThatThrowsException(JNIEnv
* env
, jobject
175 /* Must call RegisterNativesImpl() */
176 CHECK_CLAZZ(env
, obj
,
177 SampleForTests_clazz(env
));
178 jmethodID method_id
=
179 base::android::MethodID::LazyGet
<
180 base::android::MethodID::TYPE_INSTANCE
>(
181 env
, SampleForTests_clazz(env
),
182 "methodThatThrowsException",
187 &g_SampleForTests_methodThatThrowsException
);
189 env
->CallVoidMethod(obj
,
194 static base::subtle::AtomicWord g_InnerStructA_create
= 0;
195 static base::android::ScopedJavaLocalRef
<jobject
>
196 Java_InnerStructA_create(JNIEnv
* env
, jlong l
,
199 /* Must call RegisterNativesImpl() */
200 CHECK_CLAZZ(env
, InnerStructA_clazz(env
),
201 InnerStructA_clazz(env
), NULL
);
202 jmethodID method_id
=
203 base::android::MethodID::LazyGet
<
204 base::android::MethodID::TYPE_STATIC
>(
205 env
, InnerStructA_clazz(env
),
213 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;",
214 &g_InnerStructA_create
);
217 env
->CallStaticObjectMethod(InnerStructA_clazz(env
),
218 method_id
, l
, as_jint(i
), s
);
219 jni_generator::CheckException(env
);
220 return base::android::ScopedJavaLocalRef
<jobject
>(env
, ret
);
223 static base::subtle::AtomicWord g_SampleForTests_addStructA
= 0;
224 static void Java_SampleForTests_addStructA(JNIEnv
* env
, jobject obj
, jobject a
)
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
),
236 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;"
239 &g_SampleForTests_addStructA
);
241 env
->CallVoidMethod(obj
,
243 jni_generator::CheckException(env
);
247 static base::subtle::AtomicWord g_SampleForTests_iterateAndDoSomething
= 0;
248 static void Java_SampleForTests_iterateAndDoSomething(JNIEnv
* env
, jobject obj
)
250 /* Must call RegisterNativesImpl() */
251 CHECK_CLAZZ(env
, obj
,
252 SampleForTests_clazz(env
));
253 jmethodID method_id
=
254 base::android::MethodID::LazyGet
<
255 base::android::MethodID::TYPE_INSTANCE
>(
256 env
, SampleForTests_clazz(env
),
257 "iterateAndDoSomething",
262 &g_SampleForTests_iterateAndDoSomething
);
264 env
->CallVoidMethod(obj
,
266 jni_generator::CheckException(env
);
270 static base::subtle::AtomicWord g_InnerStructB_getKey
= 0;
271 static jlong
Java_InnerStructB_getKey(JNIEnv
* env
, jobject obj
) {
272 /* Must call RegisterNativesImpl() */
273 CHECK_CLAZZ(env
, obj
,
274 InnerStructB_clazz(env
), 0);
275 jmethodID method_id
=
276 base::android::MethodID::LazyGet
<
277 base::android::MethodID::TYPE_INSTANCE
>(
278 env
, InnerStructB_clazz(env
),
284 &g_InnerStructB_getKey
);
287 env
->CallLongMethod(obj
,
289 jni_generator::CheckException(env
);
293 static base::subtle::AtomicWord g_InnerStructB_getValue
= 0;
294 static base::android::ScopedJavaLocalRef
<jstring
>
295 Java_InnerStructB_getValue(JNIEnv
* env
, jobject obj
) {
296 /* Must call RegisterNativesImpl() */
297 CHECK_CLAZZ(env
, obj
,
298 InnerStructB_clazz(env
), NULL
);
299 jmethodID method_id
=
300 base::android::MethodID::LazyGet
<
301 base::android::MethodID::TYPE_INSTANCE
>(
302 env
, InnerStructB_clazz(env
),
307 "Ljava/lang/String;",
308 &g_InnerStructB_getValue
);
311 static_cast<jstring
>(env
->CallObjectMethod(obj
,
313 jni_generator::CheckException(env
);
314 return base::android::ScopedJavaLocalRef
<jstring
>(env
, ret
);
317 // Step 3: RegisterNatives.
319 static const JNINativeMethod kMethodsSampleForTests
[] = {
324 "J", reinterpret_cast<void*>(Init
) },
329 "V", reinterpret_cast<void*>(Destroy
) },
330 { "nativeGetDoubleFunction",
333 "D", reinterpret_cast<void*>(GetDoubleFunction
) },
334 { "nativeGetFloatFunction",
337 "F", reinterpret_cast<void*>(GetFloatFunction
) },
338 { "nativeSetNonPODDatatype",
340 "Landroid/graphics/Rect;"
342 "V", reinterpret_cast<void*>(SetNonPODDatatype
) },
343 { "nativeGetNonPODDatatype",
346 "Ljava/lang/Object;", reinterpret_cast<void*>(GetNonPODDatatype
) },
351 "I", reinterpret_cast<void*>(Method
) },
352 { "nativeMethodOtherP0",
356 "D", reinterpret_cast<void*>(MethodOtherP0
) },
357 { "nativeAddStructB",
360 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructB;"
362 "V", reinterpret_cast<void*>(AddStructB
) },
363 { "nativeIterateAndDoSomethingWithStructB",
367 "V", reinterpret_cast<void*>(IterateAndDoSomethingWithStructB
) },
368 { "nativeReturnAString",
372 "Ljava/lang/String;", reinterpret_cast<void*>(ReturnAString
) },
375 static bool RegisterNativesImpl(JNIEnv
* env
) {
377 g_InnerStructA_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
378 base::android::GetClass(env
, kInnerStructAClassPath
).obj()));
379 g_SampleForTests_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
380 base::android::GetClass(env
, kSampleForTestsClassPath
).obj()));
381 g_InnerStructB_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
382 base::android::GetClass(env
, kInnerStructBClassPath
).obj()));
384 const int kMethodsSampleForTestsSize
= arraysize(kMethodsSampleForTests
);
386 if (env
->RegisterNatives(SampleForTests_clazz(env
),
387 kMethodsSampleForTests
,
388 kMethodsSampleForTestsSize
) < 0) {
389 jni_generator::HandleRegistrationError(
390 env
, SampleForTests_clazz(env
), __FILE__
);
397 } // namespace android
400 #endif // BASE_ANDROID_JNI_GENERATOR_GOLDEN_SAMPLE_FOR_TESTS_JNI_H_