1 // Copyright (c) 2012 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 // Leaking this jclass as we cannot use LazyInstance from some threads.
30 jclass g_SampleForTests_clazz = NULL;
31 // Leaking this jclass as we cannot use LazyInstance from some threads.
32 jclass g_InnerStructB_clazz = NULL;
39 static jlong Init(JNIEnv* env, jobject jcaller,
42 static jdouble GetDoubleFunction(JNIEnv* env, jobject jcaller);
44 static jfloat GetFloatFunction(JNIEnv* env, jclass jcaller);
46 static void SetNonPODDatatype(JNIEnv* env, jobject jcaller,
49 static jobject GetNonPODDatatype(JNIEnv* env, jobject jcaller);
51 // Step 2: method stubs.
52 static void Destroy(JNIEnv* env, jobject jcaller,
53 jlong nativeCPPClass) {
54 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
55 CHECK_NATIVE_PTR(env, jcaller, native, "Destroy");
56 return native->Destroy(env, jcaller);
59 static jint Method(JNIEnv* env, jobject jcaller,
60 jlong nativeCPPClass) {
61 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
62 CHECK_NATIVE_PTR(env, jcaller, native, "Method", 0);
63 return native->Method(env, jcaller);
66 static jdouble MethodOtherP0(JNIEnv* env, jobject jcaller,
68 CPPClass::InnerClass* native =
69 reinterpret_cast<CPPClass::InnerClass*>(nativePtr);
70 CHECK_NATIVE_PTR(env, jcaller, native, "MethodOtherP0", 0);
71 return native->MethodOtherP0(env, jcaller);
74 static void AddStructB(JNIEnv* env, jobject jcaller,
77 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
78 CHECK_NATIVE_PTR(env, jcaller, native, "AddStructB");
79 return native->AddStructB(env, jcaller, b);
82 static void IterateAndDoSomethingWithStructB(JNIEnv* env, jobject jcaller,
83 jlong nativeCPPClass) {
84 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
85 CHECK_NATIVE_PTR(env, jcaller, native, "IterateAndDoSomethingWithStructB");
86 return native->IterateAndDoSomethingWithStructB(env, jcaller);
89 static jstring ReturnAString(JNIEnv* env, jobject jcaller,
90 jlong nativeCPPClass) {
91 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
92 CHECK_NATIVE_PTR(env, jcaller, native, "ReturnAString", NULL);
93 return native->ReturnAString(env, jcaller).Release();
96 static base::subtle::AtomicWord g_SampleForTests_javaMethod = 0;
97 static jint Java_SampleForTests_javaMethod(JNIEnv* env, jobject obj,
100 /* Must call RegisterNativesImpl() */
101 CHECK_CLAZZ(env, obj,
102 g_SampleForTests_clazz, 0);
103 jmethodID method_id =
104 base::android::MethodID::LazyGet<
105 base::android::MethodID::TYPE_INSTANCE>(
106 env, g_SampleForTests_clazz,
114 &g_SampleForTests_javaMethod);
117 env->CallIntMethod(obj,
118 method_id, as_jint(foo), as_jint(bar));
119 jni_generator::CheckException(env);
123 static base::subtle::AtomicWord g_SampleForTests_staticJavaMethod = 0;
124 static jboolean Java_SampleForTests_staticJavaMethod(JNIEnv* env) {
125 /* Must call RegisterNativesImpl() */
126 CHECK_CLAZZ(env, g_SampleForTests_clazz,
127 g_SampleForTests_clazz, false);
128 jmethodID method_id =
129 base::android::MethodID::LazyGet<
130 base::android::MethodID::TYPE_STATIC>(
131 env, g_SampleForTests_clazz,
137 &g_SampleForTests_staticJavaMethod);
140 env->CallStaticBooleanMethod(g_SampleForTests_clazz,
142 jni_generator::CheckException(env);
146 static base::subtle::AtomicWord g_SampleForTests_packagePrivateJavaMethod = 0;
147 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject
149 /* Must call RegisterNativesImpl() */
150 CHECK_CLAZZ(env, obj,
151 g_SampleForTests_clazz);
152 jmethodID method_id =
153 base::android::MethodID::LazyGet<
154 base::android::MethodID::TYPE_INSTANCE>(
155 env, g_SampleForTests_clazz,
156 "packagePrivateJavaMethod",
161 &g_SampleForTests_packagePrivateJavaMethod);
163 env->CallVoidMethod(obj,
165 jni_generator::CheckException(env);
169 static base::subtle::AtomicWord g_SampleForTests_methodThatThrowsException = 0;
170 static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject
172 /* Must call RegisterNativesImpl() */
173 CHECK_CLAZZ(env, obj,
174 g_SampleForTests_clazz);
175 jmethodID method_id =
176 base::android::MethodID::LazyGet<
177 base::android::MethodID::TYPE_INSTANCE>(
178 env, g_SampleForTests_clazz,
179 "methodThatThrowsException",
184 &g_SampleForTests_methodThatThrowsException);
186 env->CallVoidMethod(obj,
191 static base::subtle::AtomicWord g_InnerStructA_create = 0;
192 static base::android::ScopedJavaLocalRef<jobject>
193 Java_InnerStructA_create(JNIEnv* env, jlong l,
196 /* Must call RegisterNativesImpl() */
197 CHECK_CLAZZ(env, g_InnerStructA_clazz,
198 g_InnerStructA_clazz, NULL);
199 jmethodID method_id =
200 base::android::MethodID::LazyGet<
201 base::android::MethodID::TYPE_STATIC>(
202 env, g_InnerStructA_clazz,
210 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;",
211 &g_InnerStructA_create);
214 env->CallStaticObjectMethod(g_InnerStructA_clazz,
215 method_id, l, as_jint(i), s);
216 jni_generator::CheckException(env);
217 return base::android::ScopedJavaLocalRef<jobject>(env, ret);
220 static base::subtle::AtomicWord g_SampleForTests_addStructA = 0;
221 static void Java_SampleForTests_addStructA(JNIEnv* env, jobject obj, jobject a)
223 /* Must call RegisterNativesImpl() */
224 CHECK_CLAZZ(env, obj,
225 g_SampleForTests_clazz);
226 jmethodID method_id =
227 base::android::MethodID::LazyGet<
228 base::android::MethodID::TYPE_INSTANCE>(
229 env, g_SampleForTests_clazz,
233 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;"
236 &g_SampleForTests_addStructA);
238 env->CallVoidMethod(obj,
240 jni_generator::CheckException(env);
244 static base::subtle::AtomicWord g_SampleForTests_iterateAndDoSomething = 0;
245 static void Java_SampleForTests_iterateAndDoSomething(JNIEnv* env, jobject obj)
247 /* Must call RegisterNativesImpl() */
248 CHECK_CLAZZ(env, obj,
249 g_SampleForTests_clazz);
250 jmethodID method_id =
251 base::android::MethodID::LazyGet<
252 base::android::MethodID::TYPE_INSTANCE>(
253 env, g_SampleForTests_clazz,
254 "iterateAndDoSomething",
259 &g_SampleForTests_iterateAndDoSomething);
261 env->CallVoidMethod(obj,
263 jni_generator::CheckException(env);
267 static base::subtle::AtomicWord g_InnerStructB_getKey = 0;
268 static jlong Java_InnerStructB_getKey(JNIEnv* env, jobject obj) {
269 /* Must call RegisterNativesImpl() */
270 CHECK_CLAZZ(env, obj,
271 g_InnerStructB_clazz, 0);
272 jmethodID method_id =
273 base::android::MethodID::LazyGet<
274 base::android::MethodID::TYPE_INSTANCE>(
275 env, g_InnerStructB_clazz,
281 &g_InnerStructB_getKey);
284 env->CallLongMethod(obj,
286 jni_generator::CheckException(env);
290 static base::subtle::AtomicWord g_InnerStructB_getValue = 0;
291 static base::android::ScopedJavaLocalRef<jstring>
292 Java_InnerStructB_getValue(JNIEnv* env, jobject obj) {
293 /* Must call RegisterNativesImpl() */
294 CHECK_CLAZZ(env, obj,
295 g_InnerStructB_clazz, NULL);
296 jmethodID method_id =
297 base::android::MethodID::LazyGet<
298 base::android::MethodID::TYPE_INSTANCE>(
299 env, g_InnerStructB_clazz,
304 "Ljava/lang/String;",
305 &g_InnerStructB_getValue);
308 static_cast<jstring>(env->CallObjectMethod(obj,
310 jni_generator::CheckException(env);
311 return base::android::ScopedJavaLocalRef<jstring>(env, ret);
314 // Step 3: RegisterNatives.
316 static const JNINativeMethod kMethodsSampleForTests[] = {
321 "J", reinterpret_cast<void*>(Init) },
326 "V", reinterpret_cast<void*>(Destroy) },
327 { "nativeGetDoubleFunction",
330 "D", reinterpret_cast<void*>(GetDoubleFunction) },
331 { "nativeGetFloatFunction",
334 "F", reinterpret_cast<void*>(GetFloatFunction) },
335 { "nativeSetNonPODDatatype",
337 "Landroid/graphics/Rect;"
339 "V", reinterpret_cast<void*>(SetNonPODDatatype) },
340 { "nativeGetNonPODDatatype",
343 "Ljava/lang/Object;", reinterpret_cast<void*>(GetNonPODDatatype) },
348 "I", reinterpret_cast<void*>(Method) },
349 { "nativeMethodOtherP0",
353 "D", reinterpret_cast<void*>(MethodOtherP0) },
354 { "nativeAddStructB",
357 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructB;"
359 "V", reinterpret_cast<void*>(AddStructB) },
360 { "nativeIterateAndDoSomethingWithStructB",
364 "V", reinterpret_cast<void*>(IterateAndDoSomethingWithStructB) },
365 { "nativeReturnAString",
369 "Ljava/lang/String;", reinterpret_cast<void*>(ReturnAString) },
372 static bool RegisterNativesImpl(JNIEnv* env) {
373 g_InnerStructA_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
374 base::android::GetClass(env, kInnerStructAClassPath).obj()));
375 g_SampleForTests_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
376 base::android::GetClass(env, kSampleForTestsClassPath).obj()));
377 g_InnerStructB_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
378 base::android::GetClass(env, kInnerStructBClassPath).obj()));
380 const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests);
382 if (env->RegisterNatives(g_SampleForTests_clazz,
383 kMethodsSampleForTests,
384 kMethodsSampleForTestsSize) < 0) {
385 jni_generator::HandleRegistrationError(
386 env, g_SampleForTests_clazz, __FILE__);
393 } // namespace android
396 #endif // org_chromium_example_jni_generator_SampleForTests_JNI