Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 // This file is autogenerated by | 6 // This file is autogenerated by |
| 7 // base/android/jni_generator/jni_generator_tests.py | 7 // base/android/jni_generator/jni_generator_tests.py |
| 8 // For | 8 // For |
| 9 // org/chromium/example/jni_generator/SampleForTests | 9 // org/chromium/example/jni_generator/SampleForTests |
| 10 | 10 |
| 11 #ifndef org_chromium_example_jni_generator_SampleForTests_JNI | 11 #ifndef org_chromium_example_jni_generator_SampleForTests_JNI |
| 12 #define org_chromium_example_jni_generator_SampleForTests_JNI | 12 #define org_chromium_example_jni_generator_SampleForTests_JNI |
| 13 | 13 |
| 14 #include <jni.h> | 14 #include <jni.h> |
| 15 | 15 |
| 16 #include "base/android/jni_android.h" | 16 #include "base/android/jni_android.h" |
| 17 #include "base/android/scoped_java_ref.h" | 17 #include "base/android/scoped_java_ref.h" |
| 18 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 | 20 |
| 21 using base::android::ScopedJavaLocalRef; | 21 using base::android::ScopedJavaLocalRef; |
| 22 | 22 |
| 23 // Step 1: forward declarations. | 23 // Step 1: forward declarations. |
| 24 namespace { | 24 namespace { |
| 25 const char* const kInnerClassClassPath = | 25 static const char kInnerClassClassPath[] = |
|
Mark Mentovai
2012/02/28 14:44:30
Drop the “static,” which has no effect in this cas
bulach
2012/02/28 15:11:36
done. yes, it always generates in an anon namespac
| |
| 26 "org/chromium/example/jni_generator/SampleForTests$InnerClass"; | 26 "org/chromium/example/jni_generator/SampleForTests$InnerClass"; |
| 27 const char* const kSampleForTestsClassPath = | 27 static const char kSampleForTestsClassPath[] = |
|
Mark Mentovai
2012/02/28 14:44:30
Same here.
bulach
2012/02/28 15:11:36
Done.
| |
| 28 "org/chromium/example/jni_generator/SampleForTests"; | 28 "org/chromium/example/jni_generator/SampleForTests"; |
| 29 // Leaking this JavaRef as we cannot use LazyInstance from some threads. | 29 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 30 base::android::ScopedJavaGlobalRef<jclass>& | 30 jclass g_InnerClass_clazz = NULL; |
| 31 g_InnerClass_clazz = | 31 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 32 *(new base::android::ScopedJavaGlobalRef<jclass>()); | 32 jclass g_SampleForTests_clazz = NULL; |
| 33 // Leaking this JavaRef as we cannot use LazyInstance from some threads. | |
| 34 base::android::ScopedJavaGlobalRef<jclass>& | |
| 35 g_SampleForTests_clazz = | |
| 36 *(new base::android::ScopedJavaGlobalRef<jclass>()); | |
| 37 } // namespace | 33 } // namespace |
| 38 | 34 |
| 39 static jint Init(JNIEnv* env, jobject obj); | 35 static jint Init(JNIEnv* env, jobject obj); |
| 40 | 36 |
| 41 | 37 |
| 42 static jdouble GetDoubleFunction(JNIEnv* env, jobject obj); | 38 static jdouble GetDoubleFunction(JNIEnv* env, jobject obj); |
| 43 | 39 |
| 44 | 40 |
| 45 static jfloat GetFloatFunction(JNIEnv* env, jclass clazz); | 41 static jfloat GetFloatFunction(JNIEnv* env, jclass clazz); |
| 46 | 42 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 jint nativeCPPClass) { | 78 jint nativeCPPClass) { |
| 83 DCHECK(nativeCPPClass) << "InnerMethod"; | 79 DCHECK(nativeCPPClass) << "InnerMethod"; |
| 84 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); | 80 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); |
| 85 return native->InnerMethod(env, obj).Release(); | 81 return native->InnerMethod(env, obj).Release(); |
| 86 } | 82 } |
| 87 | 83 |
| 88 | 84 |
| 89 static jmethodID g_SampleForTests_javaMethod = 0; | 85 static jmethodID g_SampleForTests_javaMethod = 0; |
| 90 static jint Java_SampleForTests_javaMethod(JNIEnv* env, jobject obj, jint foo, | 86 static jint Java_SampleForTests_javaMethod(JNIEnv* env, jobject obj, jint foo, |
| 91 jint bar) { | 87 jint bar) { |
| 92 /* Must call RegisterNativesImpl() */ | 88 /* Must call RegisterNativesImpl() */ |
|
Mark Mentovai
2012/02/28 14:44:30
Would it be helpful to have these make any “regist
bulach
2012/02/28 15:11:36
hmm.. this "Register" calls are required at startu
| |
| 93 DCHECK(!g_SampleForTests_clazz.is_null()); | 89 DCHECK(g_SampleForTests_clazz); |
| 94 DCHECK(g_SampleForTests_javaMethod); | 90 DCHECK(g_SampleForTests_javaMethod); |
| 95 jint ret = | 91 jint ret = |
| 96 env->CallIntMethod(obj, | 92 env->CallIntMethod(obj, |
| 97 g_SampleForTests_javaMethod, foo, bar); | 93 g_SampleForTests_javaMethod, foo, bar); |
| 98 base::android::CheckException(env); | 94 base::android::CheckException(env); |
| 99 return ret; | 95 return ret; |
| 100 } | 96 } |
| 101 | 97 |
| 102 static jmethodID g_SampleForTests_staticJavaMethod = 0; | 98 static jmethodID g_SampleForTests_staticJavaMethod = 0; |
| 103 static jboolean Java_SampleForTests_staticJavaMethod(JNIEnv* env) { | 99 static jboolean Java_SampleForTests_staticJavaMethod(JNIEnv* env) { |
| 104 /* Must call RegisterNativesImpl() */ | 100 /* Must call RegisterNativesImpl() */ |
| 105 DCHECK(!g_SampleForTests_clazz.is_null()); | 101 DCHECK(g_SampleForTests_clazz); |
| 106 DCHECK(g_SampleForTests_staticJavaMethod); | 102 DCHECK(g_SampleForTests_staticJavaMethod); |
| 107 jboolean ret = | 103 jboolean ret = |
| 108 env->CallStaticBooleanMethod(g_SampleForTests_clazz.obj(), | 104 env->CallStaticBooleanMethod(g_SampleForTests_clazz, |
| 109 g_SampleForTests_staticJavaMethod); | 105 g_SampleForTests_staticJavaMethod); |
| 110 base::android::CheckException(env); | 106 base::android::CheckException(env); |
| 111 return ret; | 107 return ret; |
| 112 } | 108 } |
| 113 | 109 |
| 114 static jmethodID g_SampleForTests_packagePrivateJavaMethod = 0; | 110 static jmethodID g_SampleForTests_packagePrivateJavaMethod = 0; |
| 115 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject | 111 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject |
| 116 obj) { | 112 obj) { |
| 117 /* Must call RegisterNativesImpl() */ | 113 /* Must call RegisterNativesImpl() */ |
| 118 DCHECK(!g_SampleForTests_clazz.is_null()); | 114 DCHECK(g_SampleForTests_clazz); |
| 119 DCHECK(g_SampleForTests_packagePrivateJavaMethod); | 115 DCHECK(g_SampleForTests_packagePrivateJavaMethod); |
| 120 | 116 |
| 121 env->CallVoidMethod(obj, | 117 env->CallVoidMethod(obj, |
| 122 g_SampleForTests_packagePrivateJavaMethod); | 118 g_SampleForTests_packagePrivateJavaMethod); |
| 123 base::android::CheckException(env); | 119 base::android::CheckException(env); |
| 124 | 120 |
| 125 } | 121 } |
| 126 | 122 |
| 127 static jmethodID g_SampleForTests_methodThatThrowsException = 0; | 123 static jmethodID g_SampleForTests_methodThatThrowsException = 0; |
| 128 static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject | 124 static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject |
| 129 obj) { | 125 obj) { |
| 130 /* Must call RegisterNativesImpl() */ | 126 /* Must call RegisterNativesImpl() */ |
| 131 DCHECK(!g_SampleForTests_clazz.is_null()); | 127 DCHECK(g_SampleForTests_clazz); |
| 132 DCHECK(g_SampleForTests_methodThatThrowsException); | 128 DCHECK(g_SampleForTests_methodThatThrowsException); |
| 133 | 129 |
| 134 env->CallVoidMethod(obj, | 130 env->CallVoidMethod(obj, |
| 135 g_SampleForTests_methodThatThrowsException); | 131 g_SampleForTests_methodThatThrowsException); |
| 136 | 132 |
| 137 | 133 |
| 138 } | 134 } |
| 139 | 135 |
| 140 static jmethodID g_InnerClass_JavaInnerMethod = 0; | 136 static jmethodID g_InnerClass_JavaInnerMethod = 0; |
| 141 static jfloat Java_InnerClass_JavaInnerMethod(JNIEnv* env, jobject obj) { | 137 static jfloat Java_InnerClass_JavaInnerMethod(JNIEnv* env, jobject obj) { |
| 142 /* Must call RegisterNativesImpl() */ | 138 /* Must call RegisterNativesImpl() */ |
| 143 DCHECK(!g_InnerClass_clazz.is_null()); | 139 DCHECK(g_InnerClass_clazz); |
| 144 DCHECK(g_InnerClass_JavaInnerMethod); | 140 DCHECK(g_InnerClass_JavaInnerMethod); |
| 145 jfloat ret = | 141 jfloat ret = |
| 146 env->CallFloatMethod(obj, | 142 env->CallFloatMethod(obj, |
| 147 g_InnerClass_JavaInnerMethod); | 143 g_InnerClass_JavaInnerMethod); |
| 148 base::android::CheckException(env); | 144 base::android::CheckException(env); |
| 149 return ret; | 145 return ret; |
| 150 } | 146 } |
| 151 | 147 |
| 152 static jmethodID g_InnerClass_javaInnerFunction = 0; | 148 static jmethodID g_InnerClass_javaInnerFunction = 0; |
| 153 static void Java_InnerClass_javaInnerFunction(JNIEnv* env) { | 149 static void Java_InnerClass_javaInnerFunction(JNIEnv* env) { |
| 154 /* Must call RegisterNativesImpl() */ | 150 /* Must call RegisterNativesImpl() */ |
| 155 DCHECK(!g_InnerClass_clazz.is_null()); | 151 DCHECK(g_InnerClass_clazz); |
| 156 DCHECK(g_InnerClass_javaInnerFunction); | 152 DCHECK(g_InnerClass_javaInnerFunction); |
| 157 | 153 |
| 158 env->CallStaticVoidMethod(g_InnerClass_clazz.obj(), | 154 env->CallStaticVoidMethod(g_InnerClass_clazz, |
| 159 g_InnerClass_javaInnerFunction); | 155 g_InnerClass_javaInnerFunction); |
| 160 base::android::CheckException(env); | 156 base::android::CheckException(env); |
| 161 | 157 |
| 162 } | 158 } |
| 163 | 159 |
| 164 // Step 3: GetMethodIDs and RegisterNatives. | 160 // Step 3: GetMethodIDs and RegisterNatives. |
| 165 | 161 |
| 166 | 162 |
| 167 static void GetMethodIDsImpl(JNIEnv* env) { | 163 static void GetMethodIDsImpl(JNIEnv* env) { |
| 168 g_InnerClass_clazz.Reset( | 164 g_InnerClass_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 169 base::android::GetClass(env, kInnerClassClassPath)); | 165 base::android::GetUnscopedClass(env, kInnerClassClassPath))); |
| 170 g_SampleForTests_clazz.Reset( | 166 g_SampleForTests_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 171 base::android::GetClass(env, kSampleForTestsClassPath)); | 167 base::android::GetUnscopedClass(env, kSampleForTestsClassPath))); |
| 172 g_SampleForTests_javaMethod = base::android::GetMethodID( | 168 g_SampleForTests_javaMethod = |
| 173 env, g_SampleForTests_clazz, | 169 base::android::GetMethodID( |
| 174 "javaMethod", | 170 env, g_SampleForTests_clazz, |
| 171 "javaMethod", | |
| 175 | 172 |
| 176 "(" | 173 "(" |
| 177 "I" | 174 "I" |
| 178 "I" | 175 "I" |
| 179 ")" | 176 ")" |
| 180 "I"); | 177 "I"); |
| 181 | 178 |
| 182 g_SampleForTests_staticJavaMethod = base::android::GetStaticMethodID( | 179 g_SampleForTests_staticJavaMethod = |
| 183 env, g_SampleForTests_clazz, | 180 base::android::GetStaticMethodID( |
| 184 "staticJavaMethod", | 181 env, g_SampleForTests_clazz, |
| 182 "staticJavaMethod", | |
| 185 | 183 |
| 186 "(" | 184 "(" |
| 187 ")" | 185 ")" |
| 188 "Z"); | 186 "Z"); |
| 189 | 187 |
| 190 g_SampleForTests_packagePrivateJavaMethod = base::android::GetMethodID( | 188 g_SampleForTests_packagePrivateJavaMethod = |
| 191 env, g_SampleForTests_clazz, | 189 base::android::GetMethodID( |
| 192 "packagePrivateJavaMethod", | 190 env, g_SampleForTests_clazz, |
| 191 "packagePrivateJavaMethod", | |
| 193 | 192 |
| 194 "(" | 193 "(" |
| 195 ")" | 194 ")" |
| 196 "V"); | 195 "V"); |
| 197 | 196 |
| 198 g_SampleForTests_methodThatThrowsException = base::android::GetMethodID( | 197 g_SampleForTests_methodThatThrowsException = |
| 199 env, g_SampleForTests_clazz, | 198 base::android::GetMethodID( |
| 200 "methodThatThrowsException", | 199 env, g_SampleForTests_clazz, |
| 200 "methodThatThrowsException", | |
| 201 | 201 |
| 202 "(" | 202 "(" |
| 203 ")" | 203 ")" |
| 204 "V"); | 204 "V"); |
| 205 | 205 |
| 206 g_InnerClass_JavaInnerMethod = base::android::GetMethodID( | 206 g_InnerClass_JavaInnerMethod = |
| 207 env, g_InnerClass_clazz, | 207 base::android::GetMethodID( |
| 208 "JavaInnerMethod", | 208 env, g_InnerClass_clazz, |
| 209 "JavaInnerMethod", | |
| 209 | 210 |
| 210 "(" | 211 "(" |
| 211 ")" | 212 ")" |
| 212 "F"); | 213 "F"); |
| 213 | 214 |
| 214 g_InnerClass_javaInnerFunction = base::android::GetStaticMethodID( | 215 g_InnerClass_javaInnerFunction = |
| 215 env, g_InnerClass_clazz, | 216 base::android::GetStaticMethodID( |
| 216 "javaInnerFunction", | 217 env, g_InnerClass_clazz, |
| 218 "javaInnerFunction", | |
| 217 | 219 |
| 218 "(" | 220 "(" |
| 219 ")" | 221 ")" |
| 220 "V"); | 222 "V"); |
| 221 | 223 |
| 222 } | 224 } |
| 223 | 225 |
| 224 static bool RegisterNativesImpl(JNIEnv* env) { | 226 static bool RegisterNativesImpl(JNIEnv* env) { |
| 225 GetMethodIDsImpl(env); | 227 GetMethodIDsImpl(env); |
| 226 | 228 |
| 227 static const JNINativeMethod kMethodsInnerClass[] = { | 229 static const JNINativeMethod kMethodsInnerClass[] = { |
| 228 { "nativeInnerFunction", | 230 { "nativeInnerFunction", |
| 229 "(" | 231 "(" |
| 230 ")" | 232 ")" |
| 231 "I", reinterpret_cast<void*>(InnerFunction) }, | 233 "I", reinterpret_cast<void*>(InnerFunction) }, |
| 232 { "nativeInnerMethod", | 234 { "nativeInnerMethod", |
| 233 "(" | 235 "(" |
| 234 "I" | 236 "I" |
| 235 ")" | 237 ")" |
| 236 "Ljava/lang/String;", reinterpret_cast<void*>(InnerMethod) }, | 238 "Ljava/lang/String;", reinterpret_cast<void*>(InnerMethod) }, |
| 237 }; | 239 }; |
| 238 const int kMethodsInnerClassSize = arraysize(kMethodsInnerClass); | 240 const int kMethodsInnerClassSize = arraysize(kMethodsInnerClass); |
| 239 | 241 |
| 240 if (env->RegisterNatives(g_InnerClass_clazz.obj(), | 242 if (env->RegisterNatives(g_InnerClass_clazz, |
| 241 kMethodsInnerClass, | 243 kMethodsInnerClass, |
| 242 kMethodsInnerClassSize) < 0) { | 244 kMethodsInnerClassSize) < 0) { |
| 243 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | 245 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
| 244 return false; | 246 return false; |
| 245 } | 247 } |
| 246 | 248 |
| 247 static const JNINativeMethod kMethodsSampleForTests[] = { | 249 static const JNINativeMethod kMethodsSampleForTests[] = { |
| 248 { "nativeInit", | 250 { "nativeInit", |
| 249 "(" | 251 "(" |
| 250 ")" | 252 ")" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 277 ")" | 279 ")" |
| 278 "I", reinterpret_cast<void*>(Method) }, | 280 "I", reinterpret_cast<void*>(Method) }, |
| 279 { "nativeMethodOtherP0", | 281 { "nativeMethodOtherP0", |
| 280 "(" | 282 "(" |
| 281 "I" | 283 "I" |
| 282 ")" | 284 ")" |
| 283 "D", reinterpret_cast<void*>(MethodOtherP0) }, | 285 "D", reinterpret_cast<void*>(MethodOtherP0) }, |
| 284 }; | 286 }; |
| 285 const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests); | 287 const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests); |
| 286 | 288 |
| 287 if (env->RegisterNatives(g_SampleForTests_clazz.obj(), | 289 if (env->RegisterNatives(g_SampleForTests_clazz, |
| 288 kMethodsSampleForTests, | 290 kMethodsSampleForTests, |
| 289 kMethodsSampleForTestsSize) < 0) { | 291 kMethodsSampleForTestsSize) < 0) { |
| 290 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | 292 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
| 291 return false; | 293 return false; |
| 292 } | 294 } |
| 293 | 295 |
| 294 return true; | 296 return true; |
| 295 } | 297 } |
| 296 | 298 |
| 297 #endif // org_chromium_example_jni_generator_SampleForTests_JNI | 299 #endif // org_chromium_example_jni_generator_SampleForTests_JNI |
| OLD | NEW |