Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / base / android / jni_generator / golden_sample_for_tests_jni.h
blob2c5f6c00255596c4e46090a340c08aeb8762ed94
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
7 // For
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
13 #include <jni.h>
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.
23 namespace {
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;
36 } // namespace
38 namespace base {
39 namespace android {
41 static jint Init(JNIEnv* env, jobject obj,
42 jstring param);
44 static jdouble GetDoubleFunction(JNIEnv* env, jobject obj);
46 static jfloat GetFloatFunction(JNIEnv* env, jclass clazz);
48 static void SetNonPODDatatype(JNIEnv* env, jobject obj,
49 jobject rect);
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,
69 jint nativePtr) {
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,
77 jint nativeCPPClass,
78 jobject b) {
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,
93 jint bar) {
94 /* Must call RegisterNativesImpl() */
95 DCHECK(g_SampleForTests_clazz);
96 jmethodID method_id =
97 base::android::MethodID::LazyGet<
98 base::android::MethodID::TYPE_INSTANCE>(
99 env, g_SampleForTests_clazz,
100 "javaMethod",
106 "I",
107 &g_SampleForTests_javaMethod);
109 jint ret =
110 env->CallIntMethod(obj,
111 method_id, foo, bar);
112 base::android::CheckException(env);
113 return ret;
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,
124 "staticJavaMethod",
128 "Z",
129 &g_SampleForTests_staticJavaMethod);
131 jboolean ret =
132 env->CallStaticBooleanMethod(g_SampleForTests_clazz,
133 method_id);
134 base::android::CheckException(env);
135 return ret;
138 static base::subtle::AtomicWord g_SampleForTests_packagePrivateJavaMethod = 0;
139 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject
140 obj) {
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",
151 "V",
152 &g_SampleForTests_packagePrivateJavaMethod);
154 env->CallVoidMethod(obj,
155 method_id);
156 base::android::CheckException(env);
160 static base::subtle::AtomicWord g_SampleForTests_methodThatThrowsException = 0;
161 static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject
162 obj) {
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",
173 "V",
174 &g_SampleForTests_methodThatThrowsException);
176 env->CallVoidMethod(obj,
177 method_id);
181 static base::subtle::AtomicWord g_InnerStructA_create = 0;
182 static ScopedJavaLocalRef<jobject> Java_InnerStructA_create(JNIEnv* env, jlong
184 jint i,
185 jstring s) {
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,
192 "create",
197 "Ljava/lang/String;"
199 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;",
200 &g_InnerStructA_create);
202 jobject ret =
203 env->CallStaticObjectMethod(g_InnerStructA_clazz,
204 method_id, l, i, s);
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,
218 "addStructA",
221 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;"
223 "V",
224 &g_SampleForTests_addStructA);
226 env->CallVoidMethod(obj,
227 method_id, a);
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",
245 "V",
246 &g_SampleForTests_iterateAndDoSomething);
248 env->CallVoidMethod(obj,
249 method_id);
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,
262 "getKey",
266 "J",
267 &g_InnerStructB_getKey);
269 jlong ret =
270 env->CallLongMethod(obj,
271 method_id);
272 base::android::CheckException(env);
273 return ret;
276 static base::subtle::AtomicWord g_InnerStructB_getValue = 0;
277 static ScopedJavaLocalRef<jstring> Java_InnerStructB_getValue(JNIEnv* env,
278 jobject obj) {
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,
285 "getValue",
289 "Ljava/lang/String;",
290 &g_InnerStructB_getValue);
292 jstring ret =
293 static_cast<jstring>(env->CallObjectMethod(obj,
294 method_id));
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[] = {
310 { "nativeInit",
312 "Ljava/lang/String;"
314 "I", reinterpret_cast<void*>(Init) },
315 { "nativeDestroy",
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) },
337 { "nativeMethod",
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__;
365 return false;
368 return true;
370 } // namespace android
371 } // namespace base
373 #endif // org_chromium_example_jni_generator_SampleForTests_JNI