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 // This file is autogenerated by | 5 // This file is autogenerated by |
6 // base/android/jni_generator/jni_generator_tests.py | 6 // base/android/jni_generator/jni_generator_tests.py |
7 // For | 7 // For |
8 // org/chromium/example/jni_generator/SampleForTests | 8 // org/chromium/example/jni_generator/SampleForTests |
9 | 9 |
10 #ifndef org_chromium_example_jni_generator_SampleForTests_JNI | 10 #ifndef org_chromium_example_jni_generator_SampleForTests_JNI |
11 #define org_chromium_example_jni_generator_SampleForTests_JNI | 11 #define org_chromium_example_jni_generator_SampleForTests_JNI |
12 | 12 |
13 #include <jni.h> | 13 #include <jni.h> |
14 | 14 |
15 #include "base/android/jni_android.h" | 15 #include "base/android/jni_android.h" |
16 #include "base/android/jni_method_id.h" | |
16 #include "base/android/scoped_java_ref.h" | 17 #include "base/android/scoped_java_ref.h" |
17 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 | 20 |
20 using base::android::ScopedJavaLocalRef; | 21 using base::android::ScopedJavaLocalRef; |
joth
2012/10/03 17:31:52
(OT for this CL, but note this is a bug: shouldn't
| |
21 | 22 |
22 // Step 1: forward declarations. | 23 // Step 1: forward declarations. |
23 namespace { | 24 namespace { |
24 const char kInnerClassClassPath[] = | 25 const char kInnerClassClassPath[] = |
25 "org/chromium/example/jni_generator/SampleForTests$InnerClass"; | 26 "org/chromium/example/jni_generator/SampleForTests$InnerClass"; |
26 const char kSampleForTestsClassPath[] = | 27 const char kSampleForTestsClassPath[] = |
27 "org/chromium/example/jni_generator/SampleForTests"; | 28 "org/chromium/example/jni_generator/SampleForTests"; |
28 // Leaking this jclass as we cannot use LazyInstance from some threads. | 29 // Leaking this jclass as we cannot use LazyInstance from some threads. |
29 jclass g_InnerClass_clazz = NULL; | 30 jclass g_InnerClass_clazz = NULL; |
30 // Leaking this jclass as we cannot use LazyInstance from some threads. | 31 // Leaking this jclass as we cannot use LazyInstance from some threads. |
(...skipping 28 matching lines...) Expand all Loading... | |
59 jint nativeCPPClass) { | 60 jint nativeCPPClass) { |
60 DCHECK(nativeCPPClass) << "Method"; | 61 DCHECK(nativeCPPClass) << "Method"; |
61 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); | 62 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); |
62 return native->Method(env, obj); | 63 return native->Method(env, obj); |
63 } | 64 } |
64 | 65 |
65 static jdouble MethodOtherP0(JNIEnv* env, jobject obj, | 66 static jdouble MethodOtherP0(JNIEnv* env, jobject obj, |
66 jint nativePtr) { | 67 jint nativePtr) { |
67 DCHECK(nativePtr) << "MethodOtherP0"; | 68 DCHECK(nativePtr) << "MethodOtherP0"; |
68 CPPClass::InnerClass* native = | 69 CPPClass::InnerClass* native = |
69 reinterpret_cast<CPPClass::InnerClass*>(nativePtr); | 70 reinterpret_cast<CPPClass::InnerClass*>(nativePtr); |
70 return native->MethodOtherP0(env, obj); | 71 return native->MethodOtherP0(env, obj); |
71 } | 72 } |
72 | 73 |
73 static jstring InnerMethod(JNIEnv* env, jobject obj, | 74 static jstring InnerMethod(JNIEnv* env, jobject obj, |
74 jint nativeCPPClass) { | 75 jint nativeCPPClass) { |
75 DCHECK(nativeCPPClass) << "InnerMethod"; | 76 DCHECK(nativeCPPClass) << "InnerMethod"; |
76 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); | 77 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); |
77 return native->InnerMethod(env, obj).Release(); | 78 return native->InnerMethod(env, obj).Release(); |
78 } | 79 } |
79 | 80 |
80 static jmethodID g_SampleForTests_javaMethod = 0; | 81 static base::subtle::AtomicWord g_SampleForTests_javaMethod = 0; |
81 static jint Java_SampleForTests_javaMethod(JNIEnv* env, jobject obj, jint foo, | 82 static jint Java_SampleForTests_javaMethod(JNIEnv* env, jobject obj, jint foo, |
82 jint bar) { | 83 jint bar) { |
83 /* Must call RegisterNativesImpl() */ | 84 /* Must call RegisterNativesImpl() */ |
84 DCHECK(g_SampleForTests_clazz); | 85 DCHECK(g_SampleForTests_clazz); |
85 DCHECK(g_SampleForTests_javaMethod); | 86 jmethodID id = |
86 jint ret = | |
87 env->CallIntMethod(obj, | |
88 g_SampleForTests_javaMethod, foo, bar); | |
89 base::android::CheckException(env); | |
90 return ret; | |
91 } | |
92 | 87 |
93 static jmethodID g_SampleForTests_staticJavaMethod = 0; | 88 base::android::MethodID::LazyGet< |
94 static jboolean Java_SampleForTests_staticJavaMethod(JNIEnv* env) { | 89 base::android::MethodID::METHODTYPE_NORMAL, |
95 /* Must call RegisterNativesImpl() */ | 90 base::android::MethodID::EXCEPTIONCHECK_YES>( |
96 DCHECK(g_SampleForTests_clazz); | 91 env, g_SampleForTests_clazz, |
97 DCHECK(g_SampleForTests_staticJavaMethod); | 92 "javaMethod", |
98 jboolean ret = | |
99 env->CallStaticBooleanMethod(g_SampleForTests_clazz, | |
100 g_SampleForTests_staticJavaMethod); | |
101 base::android::CheckException(env); | |
102 return ret; | |
103 } | |
104 | |
105 static jmethodID g_SampleForTests_packagePrivateJavaMethod = 0; | |
106 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject | |
107 obj) { | |
108 /* Must call RegisterNativesImpl() */ | |
109 DCHECK(g_SampleForTests_clazz); | |
110 DCHECK(g_SampleForTests_packagePrivateJavaMethod); | |
111 | |
112 env->CallVoidMethod(obj, | |
113 g_SampleForTests_packagePrivateJavaMethod); | |
114 base::android::CheckException(env); | |
115 | |
116 } | |
117 | |
118 static jmethodID g_SampleForTests_methodThatThrowsException = 0; | |
119 static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject | |
120 obj) { | |
121 /* Must call RegisterNativesImpl() */ | |
122 DCHECK(g_SampleForTests_clazz); | |
123 DCHECK(g_SampleForTests_methodThatThrowsException); | |
124 | |
125 env->CallVoidMethod(obj, | |
126 g_SampleForTests_methodThatThrowsException); | |
127 | |
128 } | |
129 | |
130 static jmethodID g_InnerClass_JavaInnerMethod = 0; | |
131 static jfloat Java_InnerClass_JavaInnerMethod(JNIEnv* env, jobject obj) { | |
132 /* Must call RegisterNativesImpl() */ | |
133 DCHECK(g_InnerClass_clazz); | |
134 DCHECK(g_InnerClass_JavaInnerMethod); | |
135 jfloat ret = | |
136 env->CallFloatMethod(obj, | |
137 g_InnerClass_JavaInnerMethod); | |
138 base::android::CheckException(env); | |
139 return ret; | |
140 } | |
141 | |
142 static jmethodID g_InnerClass_javaInnerFunction = 0; | |
143 static void Java_InnerClass_javaInnerFunction(JNIEnv* env) { | |
144 /* Must call RegisterNativesImpl() */ | |
145 DCHECK(g_InnerClass_clazz); | |
146 DCHECK(g_InnerClass_javaInnerFunction); | |
147 | |
148 env->CallStaticVoidMethod(g_InnerClass_clazz, | |
149 g_InnerClass_javaInnerFunction); | |
150 base::android::CheckException(env); | |
151 | |
152 } | |
153 | |
154 // Step 3: GetMethodIDs and RegisterNatives. | |
155 static void GetMethodIDsImpl(JNIEnv* env) { | |
156 g_InnerClass_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
157 base::android::GetUnscopedClass(env, kInnerClassClassPath))); | |
158 g_SampleForTests_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
159 base::android::GetUnscopedClass(env, kSampleForTestsClassPath))); | |
160 g_SampleForTests_javaMethod = | |
161 base::android::GetMethodID( | |
162 env, g_SampleForTests_clazz, | |
163 "javaMethod", | |
164 | 93 |
165 "(" | 94 "(" |
166 "I" | 95 "I" |
167 "I" | 96 "I" |
168 ")" | 97 ")" |
169 "I"); | 98 "I", |
99 &g_SampleForTests_javaMethod); | |
170 | 100 |
171 g_SampleForTests_staticJavaMethod = | 101 jint ret = |
172 base::android::GetStaticMethodID( | 102 env->CallIntMethod(obj, |
173 env, g_SampleForTests_clazz, | 103 id, foo, bar); |
174 "staticJavaMethod", | 104 base::android::CheckException(env); |
105 return ret; | |
106 } | |
107 | |
108 static base::subtle::AtomicWord g_SampleForTests_staticJavaMethod = 0; | |
109 static jboolean Java_SampleForTests_staticJavaMethod(JNIEnv* env) { | |
110 /* Must call RegisterNativesImpl() */ | |
111 DCHECK(g_SampleForTests_clazz); | |
112 jmethodID id = | |
113 | |
114 base::android::MethodID::LazyGet< | |
joth
2012/10/03 17:31:52
nit: can this go on the same line as "jmethodID id
| |
115 base::android::MethodID::METHODTYPE_STATIC, | |
116 base::android::MethodID::EXCEPTIONCHECK_YES>( | |
117 env, g_SampleForTests_clazz, | |
118 "staticJavaMethod", | |
175 | 119 |
176 "(" | 120 "(" |
177 ")" | 121 ")" |
178 "Z"); | 122 "Z", |
123 &g_SampleForTests_staticJavaMethod); | |
179 | 124 |
180 g_SampleForTests_packagePrivateJavaMethod = | 125 jboolean ret = |
181 base::android::GetMethodID( | 126 env->CallStaticBooleanMethod(g_SampleForTests_clazz, |
182 env, g_SampleForTests_clazz, | 127 id); |
183 "packagePrivateJavaMethod", | 128 base::android::CheckException(env); |
129 return ret; | |
130 } | |
131 | |
132 static base::subtle::AtomicWord g_SampleForTests_packagePrivateJavaMethod = 0; | |
133 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject | |
134 obj) { | |
135 /* Must call RegisterNativesImpl() */ | |
136 DCHECK(g_SampleForTests_clazz); | |
137 jmethodID id = | |
138 | |
139 base::android::MethodID::LazyGet< | |
140 base::android::MethodID::METHODTYPE_NORMAL, | |
141 base::android::MethodID::EXCEPTIONCHECK_YES>( | |
142 env, g_SampleForTests_clazz, | |
143 "packagePrivateJavaMethod", | |
184 | 144 |
185 "(" | 145 "(" |
186 ")" | 146 ")" |
187 "V"); | 147 "V", |
148 &g_SampleForTests_packagePrivateJavaMethod); | |
188 | 149 |
189 g_SampleForTests_methodThatThrowsException = | 150 env->CallVoidMethod(obj, |
190 base::android::GetMethodID( | 151 id); |
191 env, g_SampleForTests_clazz, | 152 base::android::CheckException(env); |
192 "methodThatThrowsException", | 153 |
154 } | |
155 | |
156 static base::subtle::AtomicWord g_SampleForTests_methodThatThrowsException = 0; | |
157 static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject | |
158 obj) { | |
159 /* Must call RegisterNativesImpl() */ | |
160 DCHECK(g_SampleForTests_clazz); | |
161 jmethodID id = | |
162 | |
163 base::android::MethodID::LazyGet< | |
164 base::android::MethodID::METHODTYPE_NORMAL, | |
165 base::android::MethodID::EXCEPTIONCHECK_YES>( | |
166 env, g_SampleForTests_clazz, | |
167 "methodThatThrowsException", | |
193 | 168 |
194 "(" | 169 "(" |
195 ")" | 170 ")" |
196 "V"); | 171 "V", |
172 &g_SampleForTests_methodThatThrowsException); | |
197 | 173 |
198 g_InnerClass_JavaInnerMethod = | 174 env->CallVoidMethod(obj, |
199 base::android::GetMethodID( | 175 id); |
200 env, g_InnerClass_clazz, | 176 |
201 "JavaInnerMethod", | 177 } |
178 | |
179 static base::subtle::AtomicWord g_InnerClass_JavaInnerMethod = 0; | |
180 static jfloat Java_InnerClass_JavaInnerMethod(JNIEnv* env, jobject obj) { | |
181 /* Must call RegisterNativesImpl() */ | |
182 DCHECK(g_InnerClass_clazz); | |
183 jmethodID id = | |
184 | |
185 base::android::MethodID::LazyGet< | |
186 base::android::MethodID::METHODTYPE_NORMAL, | |
187 base::android::MethodID::EXCEPTIONCHECK_YES>( | |
188 env, g_InnerClass_clazz, | |
189 "JavaInnerMethod", | |
202 | 190 |
203 "(" | 191 "(" |
204 ")" | 192 ")" |
205 "F"); | 193 "F", |
194 &g_InnerClass_JavaInnerMethod); | |
206 | 195 |
207 g_InnerClass_javaInnerFunction = | 196 jfloat ret = |
208 base::android::GetStaticMethodID( | 197 env->CallFloatMethod(obj, |
209 env, g_InnerClass_clazz, | 198 id); |
210 "javaInnerFunction", | 199 base::android::CheckException(env); |
200 return ret; | |
201 } | |
202 | |
203 static base::subtle::AtomicWord g_InnerClass_javaInnerFunction = 0; | |
204 static void Java_InnerClass_javaInnerFunction(JNIEnv* env) { | |
205 /* Must call RegisterNativesImpl() */ | |
206 DCHECK(g_InnerClass_clazz); | |
207 jmethodID id = | |
208 | |
209 base::android::MethodID::LazyGet< | |
210 base::android::MethodID::METHODTYPE_STATIC, | |
211 base::android::MethodID::EXCEPTIONCHECK_YES>( | |
212 env, g_InnerClass_clazz, | |
213 "javaInnerFunction", | |
211 | 214 |
212 "(" | 215 "(" |
213 ")" | 216 ")" |
214 "V"); | 217 "V", |
218 &g_InnerClass_javaInnerFunction); | |
219 | |
220 env->CallStaticVoidMethod(g_InnerClass_clazz, | |
221 id); | |
222 base::android::CheckException(env); | |
215 | 223 |
216 } | 224 } |
217 | 225 |
226 // Step 3: RegisterNatives. | |
227 | |
218 static bool RegisterNativesImpl(JNIEnv* env) { | 228 static bool RegisterNativesImpl(JNIEnv* env) { |
219 GetMethodIDsImpl(env); | |
220 | 229 |
230 g_InnerClass_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
231 base::android::GetUnscopedClass(env, kInnerClassClassPath))); | |
232 g_SampleForTests_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
233 base::android::GetUnscopedClass(env, kSampleForTestsClassPath))); | |
221 static const JNINativeMethod kMethodsInnerClass[] = { | 234 static const JNINativeMethod kMethodsInnerClass[] = { |
222 { "nativeInnerFunction", | 235 { "nativeInnerFunction", |
223 "(" | 236 "(" |
224 ")" | 237 ")" |
225 "I", reinterpret_cast<void*>(InnerFunction) }, | 238 "I", reinterpret_cast<void*>(InnerFunction) }, |
226 { "nativeInnerMethod", | 239 { "nativeInnerMethod", |
227 "(" | 240 "(" |
228 "I" | 241 "I" |
229 ")" | 242 ")" |
230 "Ljava/lang/String;", reinterpret_cast<void*>(InnerMethod) }, | 243 "Ljava/lang/String;", reinterpret_cast<void*>(InnerMethod) }, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | 297 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
285 return false; | 298 return false; |
286 } | 299 } |
287 | 300 |
288 return true; | 301 return true; |
289 } | 302 } |
290 } // namespace android | 303 } // namespace android |
291 } // namespace base | 304 } // namespace base |
292 | 305 |
293 #endif // org_chromium_example_jni_generator_SampleForTests_JNI | 306 #endif // org_chromium_example_jni_generator_SampleForTests_JNI |
OLD | NEW |