Home | History | Annotate | Download | only in jni_generator
      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.
      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 #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
     36 
     37 }  // namespace
     38 
     39 namespace base {
     40 namespace android {
     41 
     42 // Step 2: method stubs.
     43 
     44 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller,
     45     const JavaParamRef<jstring>& param);
     46 
     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));
     53 }
     54 
     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));
     63 }
     64 
     65 static jdouble GetDoubleFunction(JNIEnv* env, const JavaParamRef<jobject>&
     66     jcaller);
     67 
     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));
     72 }
     73 
     74 static jfloat GetFloatFunction(JNIEnv* env, const JavaParamRef<jclass>&
     75     jcaller);
     76 
     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));
     81 }
     82 
     83 static void SetNonPODDatatype(JNIEnv* env, const JavaParamRef<jobject>& jcaller,
     84     const JavaParamRef<jobject>& rect);
     85 
     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));
     92 }
     93 
     94 static ScopedJavaLocalRef<jobject> GetNonPODDatatype(JNIEnv* env, const
     95     JavaParamRef<jobject>& jcaller);
     96 
     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();
    101 }
    102 
    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));
    111 }
    112 
    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));
    122 }
    123 
    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));
    134 }
    135 
    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));
    145 }
    146 
    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();
    156 }
    157 
    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",
    170 
    171 "("
    172 "I"
    173 "I"
    174 ")"
    175 "I",
    176       &g_SampleForTests_javaMethod);
    177 
    178   jint ret =
    179       env->CallIntMethod(obj,
    180           method_id, as_jint(foo), as_jint(bar));
    181   jni_generator::CheckException(env);
    182   return ret;
    183 }
    184 
    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",
    195 
    196 "("
    197 ")"
    198 "Z",
    199       &g_SampleForTests_staticJavaMethod);
    200 
    201   jboolean ret =
    202       env->CallStaticBooleanMethod(SampleForTests_clazz(env),
    203           method_id);
    204   jni_generator::CheckException(env);
    205   return ret;
    206 }
    207 
    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",
    219 
    220 "("
    221 ")"
    222 "V",
    223       &g_SampleForTests_packagePrivateJavaMethod);
    224 
    225      env->CallVoidMethod(obj,
    226           method_id);
    227   jni_generator::CheckException(env);
    228 
    229 }
    230 
    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",
    242 
    243 "("
    244 ")"
    245 "V",
    246       &g_SampleForTests_methodThatThrowsException);
    247 
    248      env->CallVoidMethod(obj,
    249           method_id);
    250 
    251 }
    252 
    253 static base::subtle::AtomicWord g_InnerStructA_create = 0;
    254 static ScopedJavaLocalRef<jobject> Java_InnerStructA_create(JNIEnv* env, jlong
    255     l,
    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",
    266 
    267 "("
    268 "J"
    269 "I"
    270 "Ljava/lang/String;"
    271 ")"
    272 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;",
    273       &g_InnerStructA_create);
    274 
    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);
    280 }
    281 
    282 static base::subtle::AtomicWord g_SampleForTests_addStructA = 0;
    283 static void Java_SampleForTests_addStructA(JNIEnv* env, jobject obj, jobject a)
    284     {
    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",
    293 
    294 "("
    295 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;"
    296 ")"
    297 "V",
    298       &g_SampleForTests_addStructA);
    299 
    300      env->CallVoidMethod(obj,
    301           method_id, a);
    302   jni_generator::CheckException(env);
    303 
    304 }
    305 
    306 static base::subtle::AtomicWord g_SampleForTests_iterateAndDoSomething = 0;
    307 static void Java_SampleForTests_iterateAndDoSomething(JNIEnv* env, jobject obj)
    308     {
    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",
    317 
    318 "("
    319 ")"
    320 "V",
    321       &g_SampleForTests_iterateAndDoSomething);
    322 
    323      env->CallVoidMethod(obj,
    324           method_id);
    325   jni_generator::CheckException(env);
    326 
    327 }
    328 
    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",
    339 
    340 "("
    341 ")"
    342 "J",
    343       &g_InnerStructB_getKey);
    344 
    345   jlong ret =
    346       env->CallLongMethod(obj,
    347           method_id);
    348   jni_generator::CheckException(env);
    349   return ret;
    350 }
    351 
    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",
    363 
    364 "("
    365 ")"
    366 "Ljava/lang/String;",
    367       &g_InnerStructB_getValue);
    368 
    369   jstring ret =
    370       static_cast<jstring>(env->CallObjectMethod(obj,
    371           method_id));
    372   jni_generator::CheckException(env);
    373   return ScopedJavaLocalRef<jstring>(env, ret);
    374 }
    375 
    376 // Step 3: RegisterNatives.
    377 
    378 static const JNINativeMethod kMethodsSampleForTests[] = {
    379     { "nativeInit",
    380 "("
    381 "Ljava/lang/String;"
    382 ")"
    383 "J",
    384     reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeInit)
    385     },
    386     { "nativeDestroy",
    387 "("
    388 "J"
    389 ")"
    390 "V",
    391     reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeDestroy)
    392     },
    393     { "nativeGetDoubleFunction",
    394 "("
    395 ")"
    396 "D",
    397     reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetDoubleFunction)
    398     },
    399     { "nativeGetFloatFunction",
    400 "("
    401 ")"
    402 "F",
    403     reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetFloatFunction)
    404     },
    405     { "nativeSetNonPODDatatype",
    406 "("
    407 "Landroid/graphics/Rect;"
    408 ")"
    409 "V",
    410     reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeSetNonPODDatatype)
    411     },
    412     { "nativeGetNonPODDatatype",
    413 "("
    414 ")"
    415 "Ljava/lang/Object;",
    416     reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetNonPODDatatype)
    417     },
    418     { "nativeMethod",
    419 "("
    420 "J"
    421 ")"
    422 "I",
    423     reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod)
    424     },
    425     { "nativeMethodOtherP0",
    426 "("
    427 "J"
    428 ")"
    429 "D",
    430     reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethodOtherP0)
    431     },
    432     { "nativeAddStructB",
    433 "("
    434 "J"
    435 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructB;"
    436 ")"
    437 "V",
    438     reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeAddStructB)
    439     },
    440     { "nativeIterateAndDoSomethingWithStructB",
    441 "("
    442 "J"
    443 ")"
    444 "V",
    445     reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeIterateAndDoSomethingWithStructB)
    446     },
    447     { "nativeReturnAString",
    448 "("
    449 "J"
    450 ")"
    451 "Ljava/lang/String;",
    452     reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeReturnAString)
    453     },
    454 };
    455 
    456 static bool RegisterNativesImpl(JNIEnv* env) {
    457 
    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()));
    464 
    465   const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests);
    466 
    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;
    473   }
    474 
    475   return true;
    476 }
    477 
    478 }  // namespace android
    479 }  // namespace base
    480 
    481 #endif  // org_chromium_example_jni_generator_SampleForTests_JNI
    482