| 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 kMyOtherInnerClassClassPath[] = | |
| 22 "org/chromium/example/jni_generator/SampleForTests$MyOtherInnerClass"; | |
| 23 const char kMyInnerClassClassPath[] = | |
| 24 "org/chromium/example/jni_generator/SampleForTests$MyInnerClass"; | |
| 25 const char kSampleForTestsClassPath[] = | |
| 26 "org/chromium/example/jni_generator/SampleForTests"; | |
| 27 // Leaking this jclass as we cannot use LazyInstance from some threads. | |
| 28 base::subtle::AtomicWord g_MyOtherInnerClass_clazz __attribute__((unused)) = 0; | |
| 29 #define MyOtherInnerClass_clazz(env) base::android::LazyGetClass(env, kMyOtherIn
nerClassClassPath, &g_MyOtherInnerClass_clazz) | |
| 30 // Leaking this jclass as we cannot use LazyInstance from some threads. | |
| 31 base::subtle::AtomicWord g_MyInnerClass_clazz __attribute__((unused)) = 0; | |
| 32 #define MyInnerClass_clazz(env) base::android::LazyGetClass(env, kMyInnerClassCl
assPath, &g_MyInnerClass_clazz) | |
| 33 // Leaking this jclass as we cannot use LazyInstance from some threads. | |
| 34 base::subtle::AtomicWord g_SampleForTests_clazz __attribute__((unused)) = 0; | |
| 35 #define SampleForTests_clazz(env) base::android::LazyGetClass(env, kSampleForTes
tsClassPath, &g_SampleForTests_clazz) | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 39 // Step 2: method stubs. | |
| 40 extern "C" __attribute__((visibility("default"))) | |
| 41 jint | |
| 42 Java_org_chromium_example_jni_1generator_SampleForTests_nativeStaticMethod(J
NIEnv* | |
| 43 env, | |
| 44 jobject jcaller, | |
| 45 jlong nativeTest, | |
| 46 jint arg1) { | |
| 47 Test* native = reinterpret_cast<Test*>(nativeTest); | |
| 48 CHECK_NATIVE_PTR(env, jcaller, native, "StaticMethod", 0); | |
| 49 return native->StaticMethod(env, JavaParamRef<jobject>(env, jcaller), arg1); | |
| 50 } | |
| 51 | |
| 52 extern "C" __attribute__((visibility("default"))) | |
| 53 jint | |
| 54 Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod(JNIEnv* | |
| 55 env, | |
| 56 jobject jcaller, | |
| 57 jlong nativeTest, | |
| 58 jint arg1) { | |
| 59 Test* native = reinterpret_cast<Test*>(nativeTest); | |
| 60 CHECK_NATIVE_PTR(env, jcaller, native, "Method", 0); | |
| 61 return native->Method(env, JavaParamRef<jobject>(env, jcaller), arg1); | |
| 62 } | |
| 63 | |
| 64 static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller); | |
| 65 | |
| 66 extern "C" __attribute__((visibility("default"))) | |
| 67 jint | |
| 68 Java_org_chromium_example_jni_1generator_SampleForTests_00024MyInnerClass_na
tiveInit(JNIEnv* | |
| 69 env, jobject jcaller) { | |
| 70 return Init(env, JavaParamRef<jobject>(env, jcaller)); | |
| 71 } | |
| 72 | |
| 73 static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller); | |
| 74 | |
| 75 extern "C" __attribute__((visibility("default"))) | |
| 76 jint | |
| 77 Java_org_chromium_example_jni_1generator_SampleForTests_00024MyOtherInnerCla
ss_nativeInit(JNIEnv* | |
| 78 env, jobject jcaller) { | |
| 79 return Init(env, JavaParamRef<jobject>(env, jcaller)); | |
| 80 } | |
| 81 | |
| 82 static base::subtle::AtomicWord g_SampleForTests_testMethodWithParam = 0; | |
| 83 static void Java_SampleForTests_testMethodWithParam(JNIEnv* env, jobject obj, | |
| 84 JniIntWrapper iParam) { | |
| 85 /* Must call RegisterNativesImpl() */ | |
| 86 CHECK_CLAZZ(env, obj, | |
| 87 SampleForTests_clazz(env)); | |
| 88 jmethodID method_id = | |
| 89 base::android::MethodID::LazyGet< | |
| 90 base::android::MethodID::TYPE_INSTANCE>( | |
| 91 env, SampleForTests_clazz(env), | |
| 92 "testMethodWithParam", | |
| 93 | |
| 94 "(" | |
| 95 "I" | |
| 96 ")" | |
| 97 "V", | |
| 98 &g_SampleForTests_testMethodWithParam); | |
| 99 | |
| 100 env->CallVoidMethod(obj, | |
| 101 method_id, as_jint(iParam)); | |
| 102 jni_generator::CheckException(env); | |
| 103 | |
| 104 } | |
| 105 | |
| 106 static base::subtle::AtomicWord g_SampleForTests_testMethodWithParamAndReturn = | |
| 107 0; | |
| 108 static ScopedJavaLocalRef<jstring> | |
| 109 Java_SampleForTests_testMethodWithParamAndReturn(JNIEnv* env, jobject obj, | |
| 110 JniIntWrapper iParam) { | |
| 111 /* Must call RegisterNativesImpl() */ | |
| 112 CHECK_CLAZZ(env, obj, | |
| 113 SampleForTests_clazz(env), NULL); | |
| 114 jmethodID method_id = | |
| 115 base::android::MethodID::LazyGet< | |
| 116 base::android::MethodID::TYPE_INSTANCE>( | |
| 117 env, SampleForTests_clazz(env), | |
| 118 "testMethodWithParamAndReturn", | |
| 119 | |
| 120 "(" | |
| 121 "I" | |
| 122 ")" | |
| 123 "Ljava/lang/String;", | |
| 124 &g_SampleForTests_testMethodWithParamAndReturn); | |
| 125 | |
| 126 jstring ret = | |
| 127 static_cast<jstring>(env->CallObjectMethod(obj, | |
| 128 method_id, as_jint(iParam))); | |
| 129 jni_generator::CheckException(env); | |
| 130 return ScopedJavaLocalRef<jstring>(env, ret); | |
| 131 } | |
| 132 | |
| 133 static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithParam = 0; | |
| 134 static jint Java_SampleForTests_testStaticMethodWithParam(JNIEnv* env, | |
| 135 JniIntWrapper iParam) { | |
| 136 /* Must call RegisterNativesImpl() */ | |
| 137 CHECK_CLAZZ(env, SampleForTests_clazz(env), | |
| 138 SampleForTests_clazz(env), 0); | |
| 139 jmethodID method_id = | |
| 140 base::android::MethodID::LazyGet< | |
| 141 base::android::MethodID::TYPE_STATIC>( | |
| 142 env, SampleForTests_clazz(env), | |
| 143 "testStaticMethodWithParam", | |
| 144 | |
| 145 "(" | |
| 146 "I" | |
| 147 ")" | |
| 148 "I", | |
| 149 &g_SampleForTests_testStaticMethodWithParam); | |
| 150 | |
| 151 jint ret = | |
| 152 env->CallStaticIntMethod(SampleForTests_clazz(env), | |
| 153 method_id, as_jint(iParam)); | |
| 154 jni_generator::CheckException(env); | |
| 155 return ret; | |
| 156 } | |
| 157 | |
| 158 static base::subtle::AtomicWord g_SampleForTests_testMethodWithNoParam = 0; | |
| 159 static jdouble Java_SampleForTests_testMethodWithNoParam(JNIEnv* env) { | |
| 160 /* Must call RegisterNativesImpl() */ | |
| 161 CHECK_CLAZZ(env, SampleForTests_clazz(env), | |
| 162 SampleForTests_clazz(env), 0); | |
| 163 jmethodID method_id = | |
| 164 base::android::MethodID::LazyGet< | |
| 165 base::android::MethodID::TYPE_STATIC>( | |
| 166 env, SampleForTests_clazz(env), | |
| 167 "testMethodWithNoParam", | |
| 168 | |
| 169 "(" | |
| 170 ")" | |
| 171 "D", | |
| 172 &g_SampleForTests_testMethodWithNoParam); | |
| 173 | |
| 174 jdouble ret = | |
| 175 env->CallStaticDoubleMethod(SampleForTests_clazz(env), | |
| 176 method_id); | |
| 177 jni_generator::CheckException(env); | |
| 178 return ret; | |
| 179 } | |
| 180 | |
| 181 static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithNoParam = | |
| 182 0; | |
| 183 static ScopedJavaLocalRef<jstring> | |
| 184 Java_SampleForTests_testStaticMethodWithNoParam(JNIEnv* env) { | |
| 185 /* Must call RegisterNativesImpl() */ | |
| 186 CHECK_CLAZZ(env, SampleForTests_clazz(env), | |
| 187 SampleForTests_clazz(env), NULL); | |
| 188 jmethodID method_id = | |
| 189 base::android::MethodID::LazyGet< | |
| 190 base::android::MethodID::TYPE_STATIC>( | |
| 191 env, SampleForTests_clazz(env), | |
| 192 "testStaticMethodWithNoParam", | |
| 193 | |
| 194 "(" | |
| 195 ")" | |
| 196 "Ljava/lang/String;", | |
| 197 &g_SampleForTests_testStaticMethodWithNoParam); | |
| 198 | |
| 199 jstring ret = | |
| 200 static_cast<jstring>(env->CallStaticObjectMethod(SampleForTests_clazz(env), | |
| 201 method_id)); | |
| 202 jni_generator::CheckException(env); | |
| 203 return ScopedJavaLocalRef<jstring>(env, ret); | |
| 204 } | |
| 205 | |
| 206 // Step 3: RegisterNatives. | |
| 207 | |
| 208 static const JNINativeMethod kMethodsMyOtherInnerClass[] = { | |
| 209 { "nativeInit", | |
| 210 "(" | |
| 211 ")" | |
| 212 "I", | |
| 213 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTe
sts_00024MyOtherInnerClass_nativeInit) | |
| 214 }, | |
| 215 }; | |
| 216 | |
| 217 static const JNINativeMethod kMethodsMyInnerClass[] = { | |
| 218 { "nativeInit", | |
| 219 "(" | |
| 220 ")" | |
| 221 "I", | |
| 222 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTe
sts_00024MyInnerClass_nativeInit) | |
| 223 }, | |
| 224 }; | |
| 225 | |
| 226 static const JNINativeMethod kMethodsSampleForTests[] = { | |
| 227 { "nativeStaticMethod", | |
| 228 "(" | |
| 229 "J" | |
| 230 "I" | |
| 231 ")" | |
| 232 "I", | |
| 233 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTe
sts_nativeStaticMethod) | |
| 234 }, | |
| 235 { "nativeMethod", | |
| 236 "(" | |
| 237 "J" | |
| 238 "I" | |
| 239 ")" | |
| 240 "I", | |
| 241 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTe
sts_nativeMethod) | |
| 242 }, | |
| 243 }; | |
| 244 | |
| 245 static bool RegisterNativesImpl(JNIEnv* env) { | |
| 246 if (base::android::IsManualJniRegistrationDisabled()) return true; | |
| 247 | |
| 248 const int kMethodsMyOtherInnerClassSize = | |
| 249 arraysize(kMethodsMyOtherInnerClass); | |
| 250 | |
| 251 if (env->RegisterNatives(MyOtherInnerClass_clazz(env), | |
| 252 kMethodsMyOtherInnerClass, | |
| 253 kMethodsMyOtherInnerClassSize) < 0) { | |
| 254 jni_generator::HandleRegistrationError( | |
| 255 env, MyOtherInnerClass_clazz(env), __FILE__); | |
| 256 return false; | |
| 257 } | |
| 258 | |
| 259 const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); | |
| 260 | |
| 261 if (env->RegisterNatives(MyInnerClass_clazz(env), | |
| 262 kMethodsMyInnerClass, | |
| 263 kMethodsMyInnerClassSize) < 0) { | |
| 264 jni_generator::HandleRegistrationError( | |
| 265 env, MyInnerClass_clazz(env), __FILE__); | |
| 266 return false; | |
| 267 } | |
| 268 | |
| 269 const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests); | |
| 270 | |
| 271 if (env->RegisterNatives(SampleForTests_clazz(env), | |
| 272 kMethodsSampleForTests, | |
| 273 kMethodsSampleForTestsSize) < 0) { | |
| 274 jni_generator::HandleRegistrationError( | |
| 275 env, SampleForTests_clazz(env), __FILE__); | |
| 276 return false; | |
| 277 } | |
| 278 | |
| 279 return true; | |
| 280 } | |
| 281 | |
| 282 #endif // org_chromium_example_jni_generator_SampleForTests_JNI | |
| OLD | NEW |