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_tests.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_android.h"
16 #include "base/android/scoped_java_ref.h"
17 #include "base/basictypes.h"
18 #include "base/logging.h"
20 using base::android::ScopedJavaLocalRef
;
22 // Step 1: forward declarations.
24 const char kInnerStructAClassPath
[] =
25 "org/chromium/example/jni_generator/SampleForTests$InnerStructA";
26 const char kSampleForTestsClassPath
[] =
27 "org/chromium/example/jni_generator/SampleForTests";
28 const char kInnerStructBClassPath
[] =
29 "org/chromium/example/jni_generator/SampleForTests$InnerStructB";
30 // Leaking this jclass as we cannot use LazyInstance from some threads.
31 jclass g_InnerStructA_clazz
= NULL
;
32 // Leaking this jclass as we cannot use LazyInstance from some threads.
33 jclass g_SampleForTests_clazz
= NULL
;
34 // Leaking this jclass as we cannot use LazyInstance from some threads.
35 jclass g_InnerStructB_clazz
= NULL
;
41 static jint
Init(JNIEnv
* env
, jobject obj
,
44 static jdouble
GetDoubleFunction(JNIEnv
* env
, jobject obj
);
46 static jfloat
GetFloatFunction(JNIEnv
* env
, jclass clazz
);
48 static void SetNonPODDatatype(JNIEnv
* env
, jobject obj
,
51 static jobject
GetNonPODDatatype(JNIEnv
* env
, jobject obj
);
53 // Step 2: method stubs.
54 static void Destroy(JNIEnv
* env
, jobject obj
,
55 jint nativeCPPClass
) {
56 DCHECK(nativeCPPClass
) << "Destroy";
57 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
58 return native
->Destroy(env
, obj
);
61 static jint
Method(JNIEnv
* env
, jobject obj
,
62 jint nativeCPPClass
) {
63 DCHECK(nativeCPPClass
) << "Method";
64 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
65 return native
->Method(env
, obj
);
68 static jdouble
MethodOtherP0(JNIEnv
* env
, jobject obj
,
70 DCHECK(nativePtr
) << "MethodOtherP0";
71 CPPClass::InnerClass
* native
=
72 reinterpret_cast<CPPClass::InnerClass
*>(nativePtr
);
73 return native
->MethodOtherP0(env
, obj
);
76 static void AddStructB(JNIEnv
* env
, jobject obj
,
79 DCHECK(nativeCPPClass
) << "AddStructB";
80 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
81 return native
->AddStructB(env
, obj
, b
);
84 static void IterateAndDoSomethingWithStructB(JNIEnv
* env
, jobject obj
,
85 jint nativeCPPClass
) {
86 DCHECK(nativeCPPClass
) << "IterateAndDoSomethingWithStructB";
87 CPPClass
* native
= reinterpret_cast<CPPClass
*>(nativeCPPClass
);
88 return native
->IterateAndDoSomethingWithStructB(env
, obj
);
91 static base::subtle::AtomicWord g_SampleForTests_javaMethod
= 0;
92 static jint
Java_SampleForTests_javaMethod(JNIEnv
* env
, jobject obj
, jint foo
,
94 /* Must call RegisterNativesImpl() */
95 DCHECK(g_SampleForTests_clazz
);
97 base::android::MethodID::LazyGet
<
98 base::android::MethodID::TYPE_INSTANCE
>(
99 env
, g_SampleForTests_clazz
,
107 &g_SampleForTests_javaMethod
);
110 env
->CallIntMethod(obj
,
111 method_id
, foo
, bar
);
112 base::android::CheckException(env
);
116 static base::subtle::AtomicWord g_SampleForTests_staticJavaMethod
= 0;
117 static jboolean
Java_SampleForTests_staticJavaMethod(JNIEnv
* env
) {
118 /* Must call RegisterNativesImpl() */
119 DCHECK(g_SampleForTests_clazz
);
120 jmethodID method_id
=
121 base::android::MethodID::LazyGet
<
122 base::android::MethodID::TYPE_STATIC
>(
123 env
, g_SampleForTests_clazz
,
129 &g_SampleForTests_staticJavaMethod
);
132 env
->CallStaticBooleanMethod(g_SampleForTests_clazz
,
134 base::android::CheckException(env
);
138 static base::subtle::AtomicWord g_SampleForTests_packagePrivateJavaMethod
= 0;
139 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv
* env
, jobject
141 /* Must call RegisterNativesImpl() */
142 DCHECK(g_SampleForTests_clazz
);
143 jmethodID method_id
=
144 base::android::MethodID::LazyGet
<
145 base::android::MethodID::TYPE_INSTANCE
>(
146 env
, g_SampleForTests_clazz
,
147 "packagePrivateJavaMethod",
152 &g_SampleForTests_packagePrivateJavaMethod
);
154 env
->CallVoidMethod(obj
,
156 base::android::CheckException(env
);
160 static base::subtle::AtomicWord g_SampleForTests_methodThatThrowsException
= 0;
161 static void Java_SampleForTests_methodThatThrowsException(JNIEnv
* env
, jobject
163 /* Must call RegisterNativesImpl() */
164 DCHECK(g_SampleForTests_clazz
);
165 jmethodID method_id
=
166 base::android::MethodID::LazyGet
<
167 base::android::MethodID::TYPE_INSTANCE
>(
168 env
, g_SampleForTests_clazz
,
169 "methodThatThrowsException",
174 &g_SampleForTests_methodThatThrowsException
);
176 env
->CallVoidMethod(obj
,
181 static base::subtle::AtomicWord g_InnerStructA_create
= 0;
182 static ScopedJavaLocalRef
<jobject
> Java_InnerStructA_create(JNIEnv
* env
, jlong
186 /* Must call RegisterNativesImpl() */
187 DCHECK(g_InnerStructA_clazz
);
188 jmethodID method_id
=
189 base::android::MethodID::LazyGet
<
190 base::android::MethodID::TYPE_STATIC
>(
191 env
, g_InnerStructA_clazz
,
199 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;",
200 &g_InnerStructA_create
);
203 env
->CallStaticObjectMethod(g_InnerStructA_clazz
,
205 base::android::CheckException(env
);
206 return ScopedJavaLocalRef
<jobject
>(env
, ret
);
209 static base::subtle::AtomicWord g_SampleForTests_addStructA
= 0;
210 static void Java_SampleForTests_addStructA(JNIEnv
* env
, jobject obj
, jobject a
)
212 /* Must call RegisterNativesImpl() */
213 DCHECK(g_SampleForTests_clazz
);
214 jmethodID method_id
=
215 base::android::MethodID::LazyGet
<
216 base::android::MethodID::TYPE_INSTANCE
>(
217 env
, g_SampleForTests_clazz
,
221 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;"
224 &g_SampleForTests_addStructA
);
226 env
->CallVoidMethod(obj
,
228 base::android::CheckException(env
);
232 static base::subtle::AtomicWord g_SampleForTests_iterateAndDoSomething
= 0;
233 static void Java_SampleForTests_iterateAndDoSomething(JNIEnv
* env
, jobject obj
)
235 /* Must call RegisterNativesImpl() */
236 DCHECK(g_SampleForTests_clazz
);
237 jmethodID method_id
=
238 base::android::MethodID::LazyGet
<
239 base::android::MethodID::TYPE_INSTANCE
>(
240 env
, g_SampleForTests_clazz
,
241 "iterateAndDoSomething",
246 &g_SampleForTests_iterateAndDoSomething
);
248 env
->CallVoidMethod(obj
,
250 base::android::CheckException(env
);
254 static base::subtle::AtomicWord g_InnerStructB_getKey
= 0;
255 static jlong
Java_InnerStructB_getKey(JNIEnv
* env
, jobject obj
) {
256 /* Must call RegisterNativesImpl() */
257 DCHECK(g_InnerStructB_clazz
);
258 jmethodID method_id
=
259 base::android::MethodID::LazyGet
<
260 base::android::MethodID::TYPE_INSTANCE
>(
261 env
, g_InnerStructB_clazz
,
267 &g_InnerStructB_getKey
);
270 env
->CallLongMethod(obj
,
272 base::android::CheckException(env
);
276 static base::subtle::AtomicWord g_InnerStructB_getValue
= 0;
277 static ScopedJavaLocalRef
<jstring
> Java_InnerStructB_getValue(JNIEnv
* env
,
279 /* Must call RegisterNativesImpl() */
280 DCHECK(g_InnerStructB_clazz
);
281 jmethodID method_id
=
282 base::android::MethodID::LazyGet
<
283 base::android::MethodID::TYPE_INSTANCE
>(
284 env
, g_InnerStructB_clazz
,
289 "Ljava/lang/String;",
290 &g_InnerStructB_getValue
);
293 static_cast<jstring
>(env
->CallObjectMethod(obj
,
295 base::android::CheckException(env
);
296 return ScopedJavaLocalRef
<jstring
>(env
, ret
);
299 // Step 3: RegisterNatives.
301 static bool RegisterNativesImpl(JNIEnv
* env
) {
303 g_InnerStructA_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
304 base::android::GetClass(env
, kInnerStructAClassPath
).obj()));
305 g_SampleForTests_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
306 base::android::GetClass(env
, kSampleForTestsClassPath
).obj()));
307 g_InnerStructB_clazz
= reinterpret_cast<jclass
>(env
->NewGlobalRef(
308 base::android::GetClass(env
, kInnerStructBClassPath
).obj()));
309 static const JNINativeMethod kMethodsSampleForTests
[] = {
314 "I", reinterpret_cast<void*>(Init
) },
319 "V", reinterpret_cast<void*>(Destroy
) },
320 { "nativeGetDoubleFunction",
323 "D", reinterpret_cast<void*>(GetDoubleFunction
) },
324 { "nativeGetFloatFunction",
327 "F", reinterpret_cast<void*>(GetFloatFunction
) },
328 { "nativeSetNonPODDatatype",
330 "Landroid/graphics/Rect;"
332 "V", reinterpret_cast<void*>(SetNonPODDatatype
) },
333 { "nativeGetNonPODDatatype",
336 "Ljava/lang/Object;", reinterpret_cast<void*>(GetNonPODDatatype
) },
341 "I", reinterpret_cast<void*>(Method
) },
342 { "nativeMethodOtherP0",
346 "D", reinterpret_cast<void*>(MethodOtherP0
) },
347 { "nativeAddStructB",
350 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructB;"
352 "V", reinterpret_cast<void*>(AddStructB
) },
353 { "nativeIterateAndDoSomethingWithStructB",
357 "V", reinterpret_cast<void*>(IterateAndDoSomethingWithStructB
) },
359 const int kMethodsSampleForTestsSize
= arraysize(kMethodsSampleForTests
);
361 if (env
->RegisterNatives(g_SampleForTests_clazz
,
362 kMethodsSampleForTests
,
363 kMethodsSampleForTestsSize
) < 0) {
364 LOG(ERROR
) << "RegisterNatives failed in " << __FILE__
;
370 } // namespace android
373 #endif // org_chromium_example_jni_generator_SampleForTests_JNI