Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / base / android / jni_generator / golden_sample_for_tests_jni.h
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.
4
5 // This file is autogenerated by
6 //     base/android/jni_generator/jni_generator.py
7 // For
8 //     org/chromium/example/jni_generator/SampleForTests
9
10 #ifndef org_chromium_example_jni_generator_SampleForTests_JNI
11 #define org_chromium_example_jni_generator_SampleForTests_JNI
12
13 #include <jni.h>
14
15 #include "base/android/jni_generator/jni_generator_helper.h"
16
17 #include "base/android/jni_int_wrapper.h"
18
19 // Step 1: forward declarations.
20 namespace {
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;
33
34 }  // namespace
35
36 namespace base {
37 namespace android {
38
39 static jlong Init(JNIEnv* env, jobject jcaller,
40     jstring param);
41
42 static jdouble GetDoubleFunction(JNIEnv* env, jobject jcaller);
43
44 static jfloat GetFloatFunction(JNIEnv* env, jclass jcaller);
45
46 static void SetNonPODDatatype(JNIEnv* env, jobject jcaller,
47     jobject rect);
48
49 static jobject GetNonPODDatatype(JNIEnv* env, jobject jcaller);
50
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);
57 }
58
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);
64 }
65
66 static jdouble MethodOtherP0(JNIEnv* env, jobject jcaller,
67     jlong nativePtr) {
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);
72 }
73
74 static void AddStructB(JNIEnv* env, jobject jcaller,
75     jlong nativeCPPClass,
76     jobject b) {
77   CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
78   CHECK_NATIVE_PTR(env, jcaller, native, "AddStructB");
79   return native->AddStructB(env, jcaller, b);
80 }
81
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);
87 }
88
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();
94 }
95
96 static base::subtle::AtomicWord g_SampleForTests_javaMethod = 0;
97 static jint Java_SampleForTests_javaMethod(JNIEnv* env, jobject obj,
98     JniIntWrapper foo,
99     JniIntWrapper bar) {
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,
107       "javaMethod",
108
109 "("
110 "I"
111 "I"
112 ")"
113 "I",
114       &g_SampleForTests_javaMethod);
115
116   jint ret =
117       env->CallIntMethod(obj,
118           method_id, as_jint(foo), as_jint(bar));
119   jni_generator::CheckException(env);
120   return ret;
121 }
122
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,
132       "staticJavaMethod",
133
134 "("
135 ")"
136 "Z",
137       &g_SampleForTests_staticJavaMethod);
138
139   jboolean ret =
140       env->CallStaticBooleanMethod(g_SampleForTests_clazz,
141           method_id);
142   jni_generator::CheckException(env);
143   return ret;
144 }
145
146 static base::subtle::AtomicWord g_SampleForTests_packagePrivateJavaMethod = 0;
147 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject
148     obj) {
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",
157
158 "("
159 ")"
160 "V",
161       &g_SampleForTests_packagePrivateJavaMethod);
162
163      env->CallVoidMethod(obj,
164           method_id);
165   jni_generator::CheckException(env);
166
167 }
168
169 static base::subtle::AtomicWord g_SampleForTests_methodThatThrowsException = 0;
170 static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject
171     obj) {
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",
180
181 "("
182 ")"
183 "V",
184       &g_SampleForTests_methodThatThrowsException);
185
186      env->CallVoidMethod(obj,
187           method_id);
188
189 }
190
191 static base::subtle::AtomicWord g_InnerStructA_create = 0;
192 static base::android::ScopedJavaLocalRef<jobject>
193     Java_InnerStructA_create(JNIEnv* env, jlong l,
194     JniIntWrapper i,
195     jstring s) {
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,
203       "create",
204
205 "("
206 "J"
207 "I"
208 "Ljava/lang/String;"
209 ")"
210 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;",
211       &g_InnerStructA_create);
212
213   jobject ret =
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);
218 }
219
220 static base::subtle::AtomicWord g_SampleForTests_addStructA = 0;
221 static void Java_SampleForTests_addStructA(JNIEnv* env, jobject obj, jobject a)
222     {
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,
230       "addStructA",
231
232 "("
233 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;"
234 ")"
235 "V",
236       &g_SampleForTests_addStructA);
237
238      env->CallVoidMethod(obj,
239           method_id, a);
240   jni_generator::CheckException(env);
241
242 }
243
244 static base::subtle::AtomicWord g_SampleForTests_iterateAndDoSomething = 0;
245 static void Java_SampleForTests_iterateAndDoSomething(JNIEnv* env, jobject obj)
246     {
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",
255
256 "("
257 ")"
258 "V",
259       &g_SampleForTests_iterateAndDoSomething);
260
261      env->CallVoidMethod(obj,
262           method_id);
263   jni_generator::CheckException(env);
264
265 }
266
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,
276       "getKey",
277
278 "("
279 ")"
280 "J",
281       &g_InnerStructB_getKey);
282
283   jlong ret =
284       env->CallLongMethod(obj,
285           method_id);
286   jni_generator::CheckException(env);
287   return ret;
288 }
289
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,
300       "getValue",
301
302 "("
303 ")"
304 "Ljava/lang/String;",
305       &g_InnerStructB_getValue);
306
307   jstring ret =
308       static_cast<jstring>(env->CallObjectMethod(obj,
309           method_id));
310   jni_generator::CheckException(env);
311   return base::android::ScopedJavaLocalRef<jstring>(env, ret);
312 }
313
314 // Step 3: RegisterNatives.
315
316 static const JNINativeMethod kMethodsSampleForTests[] = {
317     { "nativeInit",
318 "("
319 "Ljava/lang/String;"
320 ")"
321 "J", reinterpret_cast<void*>(Init) },
322     { "nativeDestroy",
323 "("
324 "J"
325 ")"
326 "V", reinterpret_cast<void*>(Destroy) },
327     { "nativeGetDoubleFunction",
328 "("
329 ")"
330 "D", reinterpret_cast<void*>(GetDoubleFunction) },
331     { "nativeGetFloatFunction",
332 "("
333 ")"
334 "F", reinterpret_cast<void*>(GetFloatFunction) },
335     { "nativeSetNonPODDatatype",
336 "("
337 "Landroid/graphics/Rect;"
338 ")"
339 "V", reinterpret_cast<void*>(SetNonPODDatatype) },
340     { "nativeGetNonPODDatatype",
341 "("
342 ")"
343 "Ljava/lang/Object;", reinterpret_cast<void*>(GetNonPODDatatype) },
344     { "nativeMethod",
345 "("
346 "J"
347 ")"
348 "I", reinterpret_cast<void*>(Method) },
349     { "nativeMethodOtherP0",
350 "("
351 "J"
352 ")"
353 "D", reinterpret_cast<void*>(MethodOtherP0) },
354     { "nativeAddStructB",
355 "("
356 "J"
357 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructB;"
358 ")"
359 "V", reinterpret_cast<void*>(AddStructB) },
360     { "nativeIterateAndDoSomethingWithStructB",
361 "("
362 "J"
363 ")"
364 "V", reinterpret_cast<void*>(IterateAndDoSomethingWithStructB) },
365     { "nativeReturnAString",
366 "("
367 "J"
368 ")"
369 "Ljava/lang/String;", reinterpret_cast<void*>(ReturnAString) },
370 };
371
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()));
379
380   const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests);
381
382   if (env->RegisterNatives(g_SampleForTests_clazz,
383                            kMethodsSampleForTests,
384                            kMethodsSampleForTestsSize) < 0) {
385     jni_generator::HandleRegistrationError(
386         env, g_SampleForTests_clazz, __FILE__);
387     return false;
388   }
389
390   return true;
391 }
392
393 }  // namespace android
394 }  // namespace base
395
396 #endif  // org_chromium_example_jni_generator_SampleForTests_JNI