| OLD | NEW |
| (Empty) |
| 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 static jlong Init(JNIEnv* env, jobject jcaller, | |
| 43 jstring param); | |
| 44 | |
| 45 static jdouble GetDoubleFunction(JNIEnv* env, jobject jcaller); | |
| 46 | |
| 47 static jfloat GetFloatFunction(JNIEnv* env, jclass jcaller); | |
| 48 | |
| 49 static void SetNonPODDatatype(JNIEnv* env, jobject jcaller, | |
| 50 jobject rect); | |
| 51 | |
| 52 static jobject GetNonPODDatatype(JNIEnv* env, jobject jcaller); | |
| 53 | |
| 54 // Step 2: method stubs. | |
| 55 static void Destroy(JNIEnv* env, jobject jcaller, | |
| 56 jlong nativeCPPClass) { | |
| 57 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); | |
| 58 CHECK_NATIVE_PTR(env, jcaller, native, "Destroy"); | |
| 59 return native->Destroy(env, jcaller); | |
| 60 } | |
| 61 | |
| 62 static jint Method(JNIEnv* env, jobject jcaller, | |
| 63 jlong nativeCPPClass) { | |
| 64 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); | |
| 65 CHECK_NATIVE_PTR(env, jcaller, native, "Method", 0); | |
| 66 return native->Method(env, jcaller); | |
| 67 } | |
| 68 | |
| 69 static jdouble MethodOtherP0(JNIEnv* env, jobject jcaller, | |
| 70 jlong nativePtr) { | |
| 71 CPPClass::InnerClass* native = | |
| 72 reinterpret_cast<CPPClass::InnerClass*>(nativePtr); | |
| 73 CHECK_NATIVE_PTR(env, jcaller, native, "MethodOtherP0", 0); | |
| 74 return native->MethodOtherP0(env, jcaller); | |
| 75 } | |
| 76 | |
| 77 static void AddStructB(JNIEnv* env, jobject jcaller, | |
| 78 jlong nativeCPPClass, | |
| 79 jobject b) { | |
| 80 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); | |
| 81 CHECK_NATIVE_PTR(env, jcaller, native, "AddStructB"); | |
| 82 return native->AddStructB(env, jcaller, b); | |
| 83 } | |
| 84 | |
| 85 static void IterateAndDoSomethingWithStructB(JNIEnv* env, jobject jcaller, | |
| 86 jlong nativeCPPClass) { | |
| 87 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); | |
| 88 CHECK_NATIVE_PTR(env, jcaller, native, "IterateAndDoSomethingWithStructB"); | |
| 89 return native->IterateAndDoSomethingWithStructB(env, jcaller); | |
| 90 } | |
| 91 | |
| 92 static jstring ReturnAString(JNIEnv* env, jobject jcaller, | |
| 93 jlong nativeCPPClass) { | |
| 94 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); | |
| 95 CHECK_NATIVE_PTR(env, jcaller, native, "ReturnAString", NULL); | |
| 96 return native->ReturnAString(env, jcaller).Release(); | |
| 97 } | |
| 98 | |
| 99 static base::subtle::AtomicWord g_SampleForTests_javaMethod = 0; | |
| 100 static jint Java_SampleForTests_javaMethod(JNIEnv* env, jobject obj, | |
| 101 JniIntWrapper foo, | |
| 102 JniIntWrapper bar) { | |
| 103 /* Must call RegisterNativesImpl() */ | |
| 104 CHECK_CLAZZ(env, obj, | |
| 105 SampleForTests_clazz(env), 0); | |
| 106 jmethodID method_id = | |
| 107 base::android::MethodID::LazyGet< | |
| 108 base::android::MethodID::TYPE_INSTANCE>( | |
| 109 env, SampleForTests_clazz(env), | |
| 110 "javaMethod", | |
| 111 | |
| 112 "(" | |
| 113 "I" | |
| 114 "I" | |
| 115 ")" | |
| 116 "I", | |
| 117 &g_SampleForTests_javaMethod); | |
| 118 | |
| 119 jint ret = | |
| 120 env->CallIntMethod(obj, | |
| 121 method_id, as_jint(foo), as_jint(bar)); | |
| 122 jni_generator::CheckException(env); | |
| 123 return ret; | |
| 124 } | |
| 125 | |
| 126 static base::subtle::AtomicWord g_SampleForTests_staticJavaMethod = 0; | |
| 127 static jboolean Java_SampleForTests_staticJavaMethod(JNIEnv* env) { | |
| 128 /* Must call RegisterNativesImpl() */ | |
| 129 CHECK_CLAZZ(env, SampleForTests_clazz(env), | |
| 130 SampleForTests_clazz(env), false); | |
| 131 jmethodID method_id = | |
| 132 base::android::MethodID::LazyGet< | |
| 133 base::android::MethodID::TYPE_STATIC>( | |
| 134 env, SampleForTests_clazz(env), | |
| 135 "staticJavaMethod", | |
| 136 | |
| 137 "(" | |
| 138 ")" | |
| 139 "Z", | |
| 140 &g_SampleForTests_staticJavaMethod); | |
| 141 | |
| 142 jboolean ret = | |
| 143 env->CallStaticBooleanMethod(SampleForTests_clazz(env), | |
| 144 method_id); | |
| 145 jni_generator::CheckException(env); | |
| 146 return ret; | |
| 147 } | |
| 148 | |
| 149 static base::subtle::AtomicWord g_SampleForTests_packagePrivateJavaMethod = 0; | |
| 150 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject | |
| 151 obj) { | |
| 152 /* Must call RegisterNativesImpl() */ | |
| 153 CHECK_CLAZZ(env, obj, | |
| 154 SampleForTests_clazz(env)); | |
| 155 jmethodID method_id = | |
| 156 base::android::MethodID::LazyGet< | |
| 157 base::android::MethodID::TYPE_INSTANCE>( | |
| 158 env, SampleForTests_clazz(env), | |
| 159 "packagePrivateJavaMethod", | |
| 160 | |
| 161 "(" | |
| 162 ")" | |
| 163 "V", | |
| 164 &g_SampleForTests_packagePrivateJavaMethod); | |
| 165 | |
| 166 env->CallVoidMethod(obj, | |
| 167 method_id); | |
| 168 jni_generator::CheckException(env); | |
| 169 | |
| 170 } | |
| 171 | |
| 172 static base::subtle::AtomicWord g_SampleForTests_methodThatThrowsException = 0; | |
| 173 static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject | |
| 174 obj) { | |
| 175 /* Must call RegisterNativesImpl() */ | |
| 176 CHECK_CLAZZ(env, obj, | |
| 177 SampleForTests_clazz(env)); | |
| 178 jmethodID method_id = | |
| 179 base::android::MethodID::LazyGet< | |
| 180 base::android::MethodID::TYPE_INSTANCE>( | |
| 181 env, SampleForTests_clazz(env), | |
| 182 "methodThatThrowsException", | |
| 183 | |
| 184 "(" | |
| 185 ")" | |
| 186 "V", | |
| 187 &g_SampleForTests_methodThatThrowsException); | |
| 188 | |
| 189 env->CallVoidMethod(obj, | |
| 190 method_id); | |
| 191 | |
| 192 } | |
| 193 | |
| 194 static base::subtle::AtomicWord g_InnerStructA_create = 0; | |
| 195 static base::android::ScopedJavaLocalRef<jobject> | |
| 196 Java_InnerStructA_create(JNIEnv* env, jlong l, | |
| 197 JniIntWrapper i, | |
| 198 jstring s) { | |
| 199 /* Must call RegisterNativesImpl() */ | |
| 200 CHECK_CLAZZ(env, InnerStructA_clazz(env), | |
| 201 InnerStructA_clazz(env), NULL); | |
| 202 jmethodID method_id = | |
| 203 base::android::MethodID::LazyGet< | |
| 204 base::android::MethodID::TYPE_STATIC>( | |
| 205 env, InnerStructA_clazz(env), | |
| 206 "create", | |
| 207 | |
| 208 "(" | |
| 209 "J" | |
| 210 "I" | |
| 211 "Ljava/lang/String;" | |
| 212 ")" | |
| 213 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;", | |
| 214 &g_InnerStructA_create); | |
| 215 | |
| 216 jobject ret = | |
| 217 env->CallStaticObjectMethod(InnerStructA_clazz(env), | |
| 218 method_id, l, as_jint(i), s); | |
| 219 jni_generator::CheckException(env); | |
| 220 return base::android::ScopedJavaLocalRef<jobject>(env, ret); | |
| 221 } | |
| 222 | |
| 223 static base::subtle::AtomicWord g_SampleForTests_addStructA = 0; | |
| 224 static void Java_SampleForTests_addStructA(JNIEnv* env, jobject obj, jobject a) | |
| 225 { | |
| 226 /* Must call RegisterNativesImpl() */ | |
| 227 CHECK_CLAZZ(env, obj, | |
| 228 SampleForTests_clazz(env)); | |
| 229 jmethodID method_id = | |
| 230 base::android::MethodID::LazyGet< | |
| 231 base::android::MethodID::TYPE_INSTANCE>( | |
| 232 env, SampleForTests_clazz(env), | |
| 233 "addStructA", | |
| 234 | |
| 235 "(" | |
| 236 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;" | |
| 237 ")" | |
| 238 "V", | |
| 239 &g_SampleForTests_addStructA); | |
| 240 | |
| 241 env->CallVoidMethod(obj, | |
| 242 method_id, a); | |
| 243 jni_generator::CheckException(env); | |
| 244 | |
| 245 } | |
| 246 | |
| 247 static base::subtle::AtomicWord g_SampleForTests_iterateAndDoSomething = 0; | |
| 248 static void Java_SampleForTests_iterateAndDoSomething(JNIEnv* env, jobject obj) | |
| 249 { | |
| 250 /* Must call RegisterNativesImpl() */ | |
| 251 CHECK_CLAZZ(env, obj, | |
| 252 SampleForTests_clazz(env)); | |
| 253 jmethodID method_id = | |
| 254 base::android::MethodID::LazyGet< | |
| 255 base::android::MethodID::TYPE_INSTANCE>( | |
| 256 env, SampleForTests_clazz(env), | |
| 257 "iterateAndDoSomething", | |
| 258 | |
| 259 "(" | |
| 260 ")" | |
| 261 "V", | |
| 262 &g_SampleForTests_iterateAndDoSomething); | |
| 263 | |
| 264 env->CallVoidMethod(obj, | |
| 265 method_id); | |
| 266 jni_generator::CheckException(env); | |
| 267 | |
| 268 } | |
| 269 | |
| 270 static base::subtle::AtomicWord g_InnerStructB_getKey = 0; | |
| 271 static jlong Java_InnerStructB_getKey(JNIEnv* env, jobject obj) { | |
| 272 /* Must call RegisterNativesImpl() */ | |
| 273 CHECK_CLAZZ(env, obj, | |
| 274 InnerStructB_clazz(env), 0); | |
| 275 jmethodID method_id = | |
| 276 base::android::MethodID::LazyGet< | |
| 277 base::android::MethodID::TYPE_INSTANCE>( | |
| 278 env, InnerStructB_clazz(env), | |
| 279 "getKey", | |
| 280 | |
| 281 "(" | |
| 282 ")" | |
| 283 "J", | |
| 284 &g_InnerStructB_getKey); | |
| 285 | |
| 286 jlong ret = | |
| 287 env->CallLongMethod(obj, | |
| 288 method_id); | |
| 289 jni_generator::CheckException(env); | |
| 290 return ret; | |
| 291 } | |
| 292 | |
| 293 static base::subtle::AtomicWord g_InnerStructB_getValue = 0; | |
| 294 static base::android::ScopedJavaLocalRef<jstring> | |
| 295 Java_InnerStructB_getValue(JNIEnv* env, jobject obj) { | |
| 296 /* Must call RegisterNativesImpl() */ | |
| 297 CHECK_CLAZZ(env, obj, | |
| 298 InnerStructB_clazz(env), NULL); | |
| 299 jmethodID method_id = | |
| 300 base::android::MethodID::LazyGet< | |
| 301 base::android::MethodID::TYPE_INSTANCE>( | |
| 302 env, InnerStructB_clazz(env), | |
| 303 "getValue", | |
| 304 | |
| 305 "(" | |
| 306 ")" | |
| 307 "Ljava/lang/String;", | |
| 308 &g_InnerStructB_getValue); | |
| 309 | |
| 310 jstring ret = | |
| 311 static_cast<jstring>(env->CallObjectMethod(obj, | |
| 312 method_id)); | |
| 313 jni_generator::CheckException(env); | |
| 314 return base::android::ScopedJavaLocalRef<jstring>(env, ret); | |
| 315 } | |
| 316 | |
| 317 // Step 3: RegisterNatives. | |
| 318 | |
| 319 static const JNINativeMethod kMethodsSampleForTests[] = { | |
| 320 { "nativeInit", | |
| 321 "(" | |
| 322 "Ljava/lang/String;" | |
| 323 ")" | |
| 324 "J", reinterpret_cast<void*>(Init) }, | |
| 325 { "nativeDestroy", | |
| 326 "(" | |
| 327 "J" | |
| 328 ")" | |
| 329 "V", reinterpret_cast<void*>(Destroy) }, | |
| 330 { "nativeGetDoubleFunction", | |
| 331 "(" | |
| 332 ")" | |
| 333 "D", reinterpret_cast<void*>(GetDoubleFunction) }, | |
| 334 { "nativeGetFloatFunction", | |
| 335 "(" | |
| 336 ")" | |
| 337 "F", reinterpret_cast<void*>(GetFloatFunction) }, | |
| 338 { "nativeSetNonPODDatatype", | |
| 339 "(" | |
| 340 "Landroid/graphics/Rect;" | |
| 341 ")" | |
| 342 "V", reinterpret_cast<void*>(SetNonPODDatatype) }, | |
| 343 { "nativeGetNonPODDatatype", | |
| 344 "(" | |
| 345 ")" | |
| 346 "Ljava/lang/Object;", reinterpret_cast<void*>(GetNonPODDatatype) }, | |
| 347 { "nativeMethod", | |
| 348 "(" | |
| 349 "J" | |
| 350 ")" | |
| 351 "I", reinterpret_cast<void*>(Method) }, | |
| 352 { "nativeMethodOtherP0", | |
| 353 "(" | |
| 354 "J" | |
| 355 ")" | |
| 356 "D", reinterpret_cast<void*>(MethodOtherP0) }, | |
| 357 { "nativeAddStructB", | |
| 358 "(" | |
| 359 "J" | |
| 360 "Lorg/chromium/example/jni_generator/SampleForTests$InnerStructB;" | |
| 361 ")" | |
| 362 "V", reinterpret_cast<void*>(AddStructB) }, | |
| 363 { "nativeIterateAndDoSomethingWithStructB", | |
| 364 "(" | |
| 365 "J" | |
| 366 ")" | |
| 367 "V", reinterpret_cast<void*>(IterateAndDoSomethingWithStructB) }, | |
| 368 { "nativeReturnAString", | |
| 369 "(" | |
| 370 "J" | |
| 371 ")" | |
| 372 "Ljava/lang/String;", reinterpret_cast<void*>(ReturnAString) }, | |
| 373 }; | |
| 374 | |
| 375 static bool RegisterNativesImpl(JNIEnv* env) { | |
| 376 | |
| 377 g_InnerStructA_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
| 378 base::android::GetClass(env, kInnerStructAClassPath).obj())); | |
| 379 g_SampleForTests_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
| 380 base::android::GetClass(env, kSampleForTestsClassPath).obj())); | |
| 381 g_InnerStructB_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
| 382 base::android::GetClass(env, kInnerStructBClassPath).obj())); | |
| 383 | |
| 384 const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests); | |
| 385 | |
| 386 if (env->RegisterNatives(SampleForTests_clazz(env), | |
| 387 kMethodsSampleForTests, | |
| 388 kMethodsSampleForTestsSize) < 0) { | |
| 389 jni_generator::HandleRegistrationError( | |
| 390 env, SampleForTests_clazz(env), __FILE__); | |
| 391 return false; | |
| 392 } | |
| 393 | |
| 394 return true; | |
| 395 } | |
| 396 | |
| 397 } // namespace android | |
| 398 } // namespace base | |
| 399 | |
| 400 #endif // org_chromium_example_jni_generator_SampleForTests_JNI | |
| OLD | NEW |