- add sources.
[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_android.h"
16 #include "base/android/scoped_java_ref.h"
17 #include "base/basictypes.h"
18 #include "base/logging.h"
19
20 using base::android::ScopedJavaLocalRef;
21
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
37
38 namespace base {
39 namespace android {
40
41 static jint Init(JNIEnv* env, jobject obj,
42     jstring param);
43
44 static jdouble GetDoubleFunction(JNIEnv* env, jobject obj);
45
46 static jfloat GetFloatFunction(JNIEnv* env, jclass clazz);
47
48 static void SetNonPODDatatype(JNIEnv* env, jobject obj,
49     jobject rect);
50
51 static jobject GetNonPODDatatype(JNIEnv* env, jobject obj);
52
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);
59 }
60
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);
66 }
67
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);
74 }
75
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);
82 }
83
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);
89 }
90
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",
101
102 "("
103 "I"
104 "I"
105 ")"
106 "I",
107       &g_SampleForTests_javaMethod);
108
109   jint ret =
110     env->CallIntMethod(obj,
111       method_id, foo, bar);
112   base::android::CheckException(env);
113   return ret;
114 }
115
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",
125
126 "("
127 ")"
128 "Z",
129       &g_SampleForTests_staticJavaMethod);
130
131   jboolean ret =
132     env->CallStaticBooleanMethod(g_SampleForTests_clazz,
133       method_id);
134   base::android::CheckException(env);
135   return ret;
136 }
137
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",
148
149 "("
150 ")"
151 "V",
152       &g_SampleForTests_packagePrivateJavaMethod);
153
154   env->CallVoidMethod(obj,
155       method_id);
156   base::android::CheckException(env);
157
158 }
159
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",
170
171 "("
172 ")"
173 "V",
174       &g_SampleForTests_methodThatThrowsException);
175
176   env->CallVoidMethod(obj,
177       method_id);
178
179 }
180
181 static base::subtle::AtomicWord g_InnerStructA_create = 0;
182 static ScopedJavaLocalRef<jobject> Java_InnerStructA_create(JNIEnv* env, jlong
183     l,
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",
193
194 "("
195 "J"
196 "I"
197 "Ljava/lang/String;"
198 ")"
199 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;",
200       &g_InnerStructA_create);
201
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);
207 }
208
209 static base::subtle::AtomicWord g_SampleForTests_addStructA = 0;
210 static void Java_SampleForTests_addStructA(JNIEnv* env, jobject obj, jobject a)
211     {
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",
219
220 "("
221 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;"
222 ")"
223 "V",
224       &g_SampleForTests_addStructA);
225
226   env->CallVoidMethod(obj,
227       method_id, a);
228   base::android::CheckException(env);
229
230 }
231
232 static base::subtle::AtomicWord g_SampleForTests_iterateAndDoSomething = 0;
233 static void Java_SampleForTests_iterateAndDoSomething(JNIEnv* env, jobject obj)
234     {
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",
242
243 "("
244 ")"
245 "V",
246       &g_SampleForTests_iterateAndDoSomething);
247
248   env->CallVoidMethod(obj,
249       method_id);
250   base::android::CheckException(env);
251
252 }
253
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",
263
264 "("
265 ")"
266 "J",
267       &g_InnerStructB_getKey);
268
269   jlong ret =
270     env->CallLongMethod(obj,
271       method_id);
272   base::android::CheckException(env);
273   return ret;
274 }
275
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",
286
287 "("
288 ")"
289 "Ljava/lang/String;",
290       &g_InnerStructB_getValue);
291
292   jstring ret =
293     static_cast<jstring>(env->CallObjectMethod(obj,
294       method_id));
295   base::android::CheckException(env);
296   return ScopedJavaLocalRef<jstring>(env, ret);
297 }
298
299 // Step 3: RegisterNatives.
300
301 static bool RegisterNativesImpl(JNIEnv* env) {
302
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",
311 "("
312 "Ljava/lang/String;"
313 ")"
314 "I", reinterpret_cast<void*>(Init) },
315     { "nativeDestroy",
316 "("
317 "I"
318 ")"
319 "V", reinterpret_cast<void*>(Destroy) },
320     { "nativeGetDoubleFunction",
321 "("
322 ")"
323 "D", reinterpret_cast<void*>(GetDoubleFunction) },
324     { "nativeGetFloatFunction",
325 "("
326 ")"
327 "F", reinterpret_cast<void*>(GetFloatFunction) },
328     { "nativeSetNonPODDatatype",
329 "("
330 "Landroid/graphics/Rect;"
331 ")"
332 "V", reinterpret_cast<void*>(SetNonPODDatatype) },
333     { "nativeGetNonPODDatatype",
334 "("
335 ")"
336 "Ljava/lang/Object;", reinterpret_cast<void*>(GetNonPODDatatype) },
337     { "nativeMethod",
338 "("
339 "I"
340 ")"
341 "I", reinterpret_cast<void*>(Method) },
342     { "nativeMethodOtherP0",
343 "("
344 "I"
345 ")"
346 "D", reinterpret_cast<void*>(MethodOtherP0) },
347     { "nativeAddStructB",
348 "("
349 "I"
350 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructB;"
351 ")"
352 "V", reinterpret_cast<void*>(AddStructB) },
353     { "nativeIterateAndDoSomethingWithStructB",
354 "("
355 "I"
356 ")"
357 "V", reinterpret_cast<void*>(IterateAndDoSomethingWithStructB) },
358   };
359   const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests);
360
361   if (env->RegisterNatives(g_SampleForTests_clazz,
362                            kMethodsSampleForTests,
363                            kMethodsSampleForTestsSize) < 0) {
364     LOG(ERROR) << "RegisterNatives failed in " << __FILE__;
365     return false;
366   }
367
368   return true;
369 }
370 }  // namespace android
371 }  // namespace base
372
373 #endif  // org_chromium_example_jni_generator_SampleForTests_JNI