[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / base / android / jni_generator / golden_sample_for_tests_jni.h
blobe982609c7e003c4e7e527e92a9115fb7cacec0c3
1 // Copyright 2014 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
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_generator/jni_generator_helper.h"
17 #include "base/android/jni_int_wrapper.h"
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 #define InnerStructA_clazz(env) g_InnerStructA_clazz
30 // Leaking this jclass as we cannot use LazyInstance from some threads.
31 jclass g_SampleForTests_clazz = NULL;
32 #define SampleForTests_clazz(env) g_SampleForTests_clazz
33 // Leaking this jclass as we cannot use LazyInstance from some threads.
34 jclass g_InnerStructB_clazz = NULL;
35 #define InnerStructB_clazz(env) g_InnerStructB_clazz
37 } // namespace
39 namespace base {
40 namespace android {
42 // Step 2: method stubs.
44 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller,
45 const JavaParamRef<jstring>& param);
47 static jlong
48 Java_org_chromium_example_jni_1generator_SampleForTests_nativeInit(JNIEnv*
49 env, jobject jcaller,
50 jstring param) {
51 return Init(env, JavaParamRef<jobject>(env, jcaller),
52 JavaParamRef<jstring>(env, param));
55 static void
56 Java_org_chromium_example_jni_1generator_SampleForTests_nativeDestroy(JNIEnv*
57 env,
58 jobject jcaller,
59 jlong nativeCPPClass) {
60 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
61 CHECK_NATIVE_PTR(env, jcaller, native, "Destroy");
62 return native->Destroy(env, JavaParamRef<jobject>(env, jcaller));
65 static jdouble GetDoubleFunction(JNIEnv* env, const JavaParamRef<jobject>&
66 jcaller);
68 static jdouble
69 Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetDoubleFunction(JNIEnv*
70 env, jobject jcaller) {
71 return GetDoubleFunction(env, JavaParamRef<jobject>(env, jcaller));
74 static jfloat GetFloatFunction(JNIEnv* env, const JavaParamRef<jclass>&
75 jcaller);
77 static jfloat
78 Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetFloatFunction(JNIEnv*
79 env, jclass jcaller) {
80 return GetFloatFunction(env, JavaParamRef<jclass>(env, jcaller));
83 static void SetNonPODDatatype(JNIEnv* env, const JavaParamRef<jobject>& jcaller,
84 const JavaParamRef<jobject>& rect);
86 static void
87 Java_org_chromium_example_jni_1generator_SampleForTests_nativeSetNonPODDatatype(JNIEnv*
88 env, jobject jcaller,
89 jobject rect) {
90 return SetNonPODDatatype(env, JavaParamRef<jobject>(env, jcaller),
91 JavaParamRef<jobject>(env, rect));
94 static ScopedJavaLocalRef<jobject> GetNonPODDatatype(JNIEnv* env, const
95 JavaParamRef<jobject>& jcaller);
97 static jobject
98 Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetNonPODDatatype(JNIEnv*
99 env, jobject jcaller) {
100 return GetNonPODDatatype(env, JavaParamRef<jobject>(env, jcaller)).Release();
103 static jint
104 Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod(JNIEnv*
105 env,
106 jobject jcaller,
107 jlong nativeCPPClass) {
108 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
109 CHECK_NATIVE_PTR(env, jcaller, native, "Method", 0);
110 return native->Method(env, JavaParamRef<jobject>(env, jcaller));
113 static jdouble
114 Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethodOtherP0(JNIEnv*
115 env,
116 jobject jcaller,
117 jlong nativePtr) {
118 CPPClass::InnerClass* native =
119 reinterpret_cast<CPPClass::InnerClass*>(nativePtr);
120 CHECK_NATIVE_PTR(env, jcaller, native, "MethodOtherP0", 0);
121 return native->MethodOtherP0(env, JavaParamRef<jobject>(env, jcaller));
124 static void
125 Java_org_chromium_example_jni_1generator_SampleForTests_nativeAddStructB(JNIEnv*
126 env,
127 jobject jcaller,
128 jlong nativeCPPClass,
129 jobject b) {
130 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
131 CHECK_NATIVE_PTR(env, jcaller, native, "AddStructB");
132 return native->AddStructB(env, JavaParamRef<jobject>(env, jcaller),
133 JavaParamRef<jobject>(env, b));
136 static void
137 Java_org_chromium_example_jni_1generator_SampleForTests_nativeIterateAndDoSomethingWithStructB(JNIEnv*
138 env,
139 jobject jcaller,
140 jlong nativeCPPClass) {
141 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
142 CHECK_NATIVE_PTR(env, jcaller, native, "IterateAndDoSomethingWithStructB");
143 return native->IterateAndDoSomethingWithStructB(env,
144 JavaParamRef<jobject>(env, jcaller));
147 static jstring
148 Java_org_chromium_example_jni_1generator_SampleForTests_nativeReturnAString(JNIEnv*
149 env,
150 jobject jcaller,
151 jlong nativeCPPClass) {
152 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
153 CHECK_NATIVE_PTR(env, jcaller, native, "ReturnAString", NULL);
154 return native->ReturnAString(env, JavaParamRef<jobject>(env,
155 jcaller)).Release();
158 static base::subtle::AtomicWord g_SampleForTests_javaMethod = 0;
159 static jint Java_SampleForTests_javaMethod(JNIEnv* env, jobject obj,
160 JniIntWrapper foo,
161 JniIntWrapper bar) {
162 /* Must call RegisterNativesImpl() */
163 CHECK_CLAZZ(env, obj,
164 SampleForTests_clazz(env), 0);
165 jmethodID method_id =
166 base::android::MethodID::LazyGet<
167 base::android::MethodID::TYPE_INSTANCE>(
168 env, SampleForTests_clazz(env),
169 "javaMethod",
175 "I",
176 &g_SampleForTests_javaMethod);
178 jint ret =
179 env->CallIntMethod(obj,
180 method_id, as_jint(foo), as_jint(bar));
181 jni_generator::CheckException(env);
182 return ret;
185 static base::subtle::AtomicWord g_SampleForTests_staticJavaMethod = 0;
186 static jboolean Java_SampleForTests_staticJavaMethod(JNIEnv* env) {
187 /* Must call RegisterNativesImpl() */
188 CHECK_CLAZZ(env, SampleForTests_clazz(env),
189 SampleForTests_clazz(env), false);
190 jmethodID method_id =
191 base::android::MethodID::LazyGet<
192 base::android::MethodID::TYPE_STATIC>(
193 env, SampleForTests_clazz(env),
194 "staticJavaMethod",
198 "Z",
199 &g_SampleForTests_staticJavaMethod);
201 jboolean ret =
202 env->CallStaticBooleanMethod(SampleForTests_clazz(env),
203 method_id);
204 jni_generator::CheckException(env);
205 return ret;
208 static base::subtle::AtomicWord g_SampleForTests_packagePrivateJavaMethod = 0;
209 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject
210 obj) {
211 /* Must call RegisterNativesImpl() */
212 CHECK_CLAZZ(env, obj,
213 SampleForTests_clazz(env));
214 jmethodID method_id =
215 base::android::MethodID::LazyGet<
216 base::android::MethodID::TYPE_INSTANCE>(
217 env, SampleForTests_clazz(env),
218 "packagePrivateJavaMethod",
222 "V",
223 &g_SampleForTests_packagePrivateJavaMethod);
225 env->CallVoidMethod(obj,
226 method_id);
227 jni_generator::CheckException(env);
231 static base::subtle::AtomicWord g_SampleForTests_methodThatThrowsException = 0;
232 static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject
233 obj) {
234 /* Must call RegisterNativesImpl() */
235 CHECK_CLAZZ(env, obj,
236 SampleForTests_clazz(env));
237 jmethodID method_id =
238 base::android::MethodID::LazyGet<
239 base::android::MethodID::TYPE_INSTANCE>(
240 env, SampleForTests_clazz(env),
241 "methodThatThrowsException",
245 "V",
246 &g_SampleForTests_methodThatThrowsException);
248 env->CallVoidMethod(obj,
249 method_id);
253 static base::subtle::AtomicWord g_InnerStructA_create = 0;
254 static ScopedJavaLocalRef<jobject> Java_InnerStructA_create(JNIEnv* env, jlong
256 JniIntWrapper i,
257 jstring s) {
258 /* Must call RegisterNativesImpl() */
259 CHECK_CLAZZ(env, InnerStructA_clazz(env),
260 InnerStructA_clazz(env), NULL);
261 jmethodID method_id =
262 base::android::MethodID::LazyGet<
263 base::android::MethodID::TYPE_STATIC>(
264 env, InnerStructA_clazz(env),
265 "create",
270 "Ljava/lang/String;"
272 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;",
273 &g_InnerStructA_create);
275 jobject ret =
276 env->CallStaticObjectMethod(InnerStructA_clazz(env),
277 method_id, l, as_jint(i), s);
278 jni_generator::CheckException(env);
279 return ScopedJavaLocalRef<jobject>(env, ret);
282 static base::subtle::AtomicWord g_SampleForTests_addStructA = 0;
283 static void Java_SampleForTests_addStructA(JNIEnv* env, jobject obj, jobject a)
285 /* Must call RegisterNativesImpl() */
286 CHECK_CLAZZ(env, obj,
287 SampleForTests_clazz(env));
288 jmethodID method_id =
289 base::android::MethodID::LazyGet<
290 base::android::MethodID::TYPE_INSTANCE>(
291 env, SampleForTests_clazz(env),
292 "addStructA",
295 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;"
297 "V",
298 &g_SampleForTests_addStructA);
300 env->CallVoidMethod(obj,
301 method_id, a);
302 jni_generator::CheckException(env);
306 static base::subtle::AtomicWord g_SampleForTests_iterateAndDoSomething = 0;
307 static void Java_SampleForTests_iterateAndDoSomething(JNIEnv* env, jobject obj)
309 /* Must call RegisterNativesImpl() */
310 CHECK_CLAZZ(env, obj,
311 SampleForTests_clazz(env));
312 jmethodID method_id =
313 base::android::MethodID::LazyGet<
314 base::android::MethodID::TYPE_INSTANCE>(
315 env, SampleForTests_clazz(env),
316 "iterateAndDoSomething",
320 "V",
321 &g_SampleForTests_iterateAndDoSomething);
323 env->CallVoidMethod(obj,
324 method_id);
325 jni_generator::CheckException(env);
329 static base::subtle::AtomicWord g_InnerStructB_getKey = 0;
330 static jlong Java_InnerStructB_getKey(JNIEnv* env, jobject obj) {
331 /* Must call RegisterNativesImpl() */
332 CHECK_CLAZZ(env, obj,
333 InnerStructB_clazz(env), 0);
334 jmethodID method_id =
335 base::android::MethodID::LazyGet<
336 base::android::MethodID::TYPE_INSTANCE>(
337 env, InnerStructB_clazz(env),
338 "getKey",
342 "J",
343 &g_InnerStructB_getKey);
345 jlong ret =
346 env->CallLongMethod(obj,
347 method_id);
348 jni_generator::CheckException(env);
349 return ret;
352 static base::subtle::AtomicWord g_InnerStructB_getValue = 0;
353 static ScopedJavaLocalRef<jstring> Java_InnerStructB_getValue(JNIEnv* env,
354 jobject obj) {
355 /* Must call RegisterNativesImpl() */
356 CHECK_CLAZZ(env, obj,
357 InnerStructB_clazz(env), NULL);
358 jmethodID method_id =
359 base::android::MethodID::LazyGet<
360 base::android::MethodID::TYPE_INSTANCE>(
361 env, InnerStructB_clazz(env),
362 "getValue",
366 "Ljava/lang/String;",
367 &g_InnerStructB_getValue);
369 jstring ret =
370 static_cast<jstring>(env->CallObjectMethod(obj,
371 method_id));
372 jni_generator::CheckException(env);
373 return ScopedJavaLocalRef<jstring>(env, ret);
376 // Step 3: RegisterNatives.
378 static const JNINativeMethod kMethodsSampleForTests[] = {
379 { "nativeInit",
381 "Ljava/lang/String;"
383 "J",
384 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeInit)
386 { "nativeDestroy",
390 "V",
391 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeDestroy)
393 { "nativeGetDoubleFunction",
396 "D",
397 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetDoubleFunction)
399 { "nativeGetFloatFunction",
402 "F",
403 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetFloatFunction)
405 { "nativeSetNonPODDatatype",
407 "Landroid/graphics/Rect;"
409 "V",
410 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeSetNonPODDatatype)
412 { "nativeGetNonPODDatatype",
415 "Ljava/lang/Object;",
416 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetNonPODDatatype)
418 { "nativeMethod",
422 "I",
423 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod)
425 { "nativeMethodOtherP0",
429 "D",
430 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethodOtherP0)
432 { "nativeAddStructB",
435 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructB;"
437 "V",
438 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeAddStructB)
440 { "nativeIterateAndDoSomethingWithStructB",
444 "V",
445 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeIterateAndDoSomethingWithStructB)
447 { "nativeReturnAString",
451 "Ljava/lang/String;",
452 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeReturnAString)
456 static bool RegisterNativesImpl(JNIEnv* env) {
458 g_InnerStructA_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
459 base::android::GetClass(env, kInnerStructAClassPath).obj()));
460 g_SampleForTests_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
461 base::android::GetClass(env, kSampleForTestsClassPath).obj()));
462 g_InnerStructB_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
463 base::android::GetClass(env, kInnerStructBClassPath).obj()));
465 const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests);
467 if (env->RegisterNatives(SampleForTests_clazz(env),
468 kMethodsSampleForTests,
469 kMethodsSampleForTestsSize) < 0) {
470 jni_generator::HandleRegistrationError(
471 env, SampleForTests_clazz(env), __FILE__);
472 return false;
475 return true;
478 } // namespace android
479 } // namespace base
481 #endif // org_chromium_example_jni_generator_SampleForTests_JNI