Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1480)

Side by Side Diff: base/android/jni_generator/golden_sample_for_tests_jni.h

Issue 9384011: Chrome on Android: adds jni_generator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Wraps python and .h output at 80cols. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5
6 // This file is autogenerated by
7 // base/android/jni_generator/jni_generator_tests.py
8 // For
9 // org/chromium/example/jni_generator/SampleForTests
10
11 #ifndef org_chromium_example_jni_generator_SampleForTests_JNI
12 #define org_chromium_example_jni_generator_SampleForTests_JNI
13
14 #include <jni.h>
15
16 #include "base/android/jni_android.h"
17 #include "base/android/scoped_java_ref.h"
18 #include "base/basictypes.h"
19 #include "base/logging.h"
20
21 using base::android::ScopedJavaLocalRef;
22
23 // Step 1: forward declarations.
24 namespace {
25 const char* const kInnerClassClassPath =
26 "org/chromium/example/jni_generator/SampleForTests$InnerClass";
27 const char* const kSampleForTestsClassPath =
28 "org/chromium/example/jni_generator/SampleForTests";
29 // Leaking this JavaRef as we cannot use LazyInstance from some threads.
30 base::android::ScopedJavaGlobalRef<jclass>&
31 g_InnerClass_clazz =
32 *(new base::android::ScopedJavaGlobalRef<jclass>());
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
38
39 static jint Init(JNIEnv* env, jobject obj);
40
41
42 static jdouble GetDoubleFunction(JNIEnv* env, jobject obj);
43
44
45 static jfloat GetFloatFunction(JNIEnv* env, jclass clazz);
46
47
48 static void SetNonPODDatatype(JNIEnv* env, jobject obj,
49 jobject rect);
50
51
52 static jobject GetNonPODDatatype(JNIEnv* env, jobject obj);
53
54
55 static jint InnerFunction(JNIEnv* env, jclass clazz);
56
57
58 // Step 2: method stubs.
59 static void Destroy(JNIEnv* env, jobject obj,
60 jint nativeCPPClass) {
61 DCHECK(nativeCPPClass) << "Destroy";
62 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
63 return native->Destroy(env, obj);
64 }
65
66 static jint Method(JNIEnv* env, jobject obj,
67 jint nativeCPPClass) {
68 DCHECK(nativeCPPClass) << "Method";
69 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
70 return native->Method(env, obj);
71 }
72
73 static jdouble MethodOtherP0(JNIEnv* env, jobject obj,
74 jint nativeCPPClass) {
75 DCHECK(nativeCPPClass) << "MethodOtherP0";
76 cpp_namespace::CPPClass* native =
77 reinterpret_cast<cpp_namespace::CPPClass*>(nativeCPPClass);
78 return native->MethodOtherP0(env, obj);
79 }
80
81 static jstring InnerMethod(JNIEnv* env, jobject obj,
82 jint nativeCPPClass) {
83 DCHECK(nativeCPPClass) << "InnerMethod";
84 CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass);
85 return native->InnerMethod(env, obj).Release();
86 }
87
88
89 static jmethodID g_SampleForTests_javaMethod = 0;
90 static jint Java_SampleForTests_javaMethod(JNIEnv* env, jobject obj, jint foo,
91 jint bar) {
92 /* Must call RegisterNativesImpl() */
93 DCHECK(!g_SampleForTests_clazz.is_null());
94 DCHECK(g_SampleForTests_javaMethod);
95 jint ret =
96 env->CallIntMethod(obj,
97 g_SampleForTests_javaMethod, foo, bar);
98 base::android::CheckException(env);
99 return ret;
100 }
101
102 static jmethodID g_SampleForTests_staticJavaMethod = 0;
103 static jboolean Java_SampleForTests_staticJavaMethod(JNIEnv* env) {
104 /* Must call RegisterNativesImpl() */
105 DCHECK(!g_SampleForTests_clazz.is_null());
106 DCHECK(g_SampleForTests_staticJavaMethod);
107 jboolean ret =
108 env->CallStaticBooleanMethod(g_SampleForTests_clazz.obj(),
109 g_SampleForTests_staticJavaMethod);
110 base::android::CheckException(env);
111 return ret;
112 }
113
114 static jmethodID g_SampleForTests_packagePrivateJavaMethod = 0;
115 static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject
116 obj) {
117 /* Must call RegisterNativesImpl() */
118 DCHECK(!g_SampleForTests_clazz.is_null());
119 DCHECK(g_SampleForTests_packagePrivateJavaMethod);
120
121 env->CallVoidMethod(obj,
122 g_SampleForTests_packagePrivateJavaMethod);
123 base::android::CheckException(env);
124
125 }
126
127 static jmethodID g_SampleForTests_methodThatThrowsException = 0;
128 static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject
129 obj) {
130 /* Must call RegisterNativesImpl() */
131 DCHECK(!g_SampleForTests_clazz.is_null());
132 DCHECK(g_SampleForTests_methodThatThrowsException);
133
134 env->CallVoidMethod(obj,
135 g_SampleForTests_methodThatThrowsException);
136
137
138 }
139
140 static jmethodID g_InnerClass_JavaInnerMethod = 0;
141 static jfloat Java_InnerClass_JavaInnerMethod(JNIEnv* env, jobject obj) {
142 /* Must call RegisterNativesImpl() */
143 DCHECK(!g_InnerClass_clazz.is_null());
144 DCHECK(g_InnerClass_JavaInnerMethod);
145 jfloat ret =
146 env->CallFloatMethod(obj,
147 g_InnerClass_JavaInnerMethod);
148 base::android::CheckException(env);
149 return ret;
150 }
151
152 static jmethodID g_InnerClass_javaInnerFunction = 0;
153 static void Java_InnerClass_javaInnerFunction(JNIEnv* env) {
154 /* Must call RegisterNativesImpl() */
155 DCHECK(!g_InnerClass_clazz.is_null());
156 DCHECK(g_InnerClass_javaInnerFunction);
157
158 env->CallStaticVoidMethod(g_InnerClass_clazz.obj(),
159 g_InnerClass_javaInnerFunction);
160 base::android::CheckException(env);
161
162 }
163
164 // Step 3: GetMethodIDs and RegisterNatives.
165
166
167 static void GetMethodIDsImpl(JNIEnv* env) {
168 g_InnerClass_clazz.Reset(
169 base::android::GetClass(env, kInnerClassClassPath));
170 g_SampleForTests_clazz.Reset(
171 base::android::GetClass(env, kSampleForTestsClassPath));
172 g_SampleForTests_javaMethod = base::android::GetMethodID(
173 env, g_SampleForTests_clazz,
174 "javaMethod",
175
176 "("
177 "I"
178 "I"
179 ")"
180 "I");
181
182 g_SampleForTests_staticJavaMethod = base::android::GetStaticMethodID(
183 env, g_SampleForTests_clazz,
184 "staticJavaMethod",
185
186 "("
187 ")"
188 "Z");
189
190 g_SampleForTests_packagePrivateJavaMethod = base::android::GetMethodID(
191 env, g_SampleForTests_clazz,
192 "packagePrivateJavaMethod",
193
194 "("
195 ")"
196 "V");
197
198 g_SampleForTests_methodThatThrowsException = base::android::GetMethodID(
199 env, g_SampleForTests_clazz,
200 "methodThatThrowsException",
201
202 "("
203 ")"
204 "V");
205
206 g_InnerClass_JavaInnerMethod = base::android::GetMethodID(
207 env, g_InnerClass_clazz,
208 "JavaInnerMethod",
209
210 "("
211 ")"
212 "F");
213
214 g_InnerClass_javaInnerFunction = base::android::GetStaticMethodID(
215 env, g_InnerClass_clazz,
216 "javaInnerFunction",
217
218 "("
219 ")"
220 "V");
221
222 }
223
224 static bool RegisterNativesImpl(JNIEnv* env) {
225 GetMethodIDsImpl(env);
226
227 static const JNINativeMethod kMethodsInnerClass[] = {
228 { "nativeInnerFunction",
229 "("
230 ")"
231 "I", reinterpret_cast<void*>(InnerFunction) },
232 { "nativeInnerMethod",
233 "("
234 "I"
235 ")"
236 "Ljava/lang/String;", reinterpret_cast<void*>(InnerMethod) },
237 };
238 const int kMethodsInnerClassSize = arraysize(kMethodsInnerClass);
239
240 if (env->RegisterNatives(g_InnerClass_clazz.obj(),
241 kMethodsInnerClass,
242 kMethodsInnerClassSize) < 0) {
243 LOG(ERROR) << "RegisterNatives failed in " << __FILE__;
244 return false;
245 }
246
247 static const JNINativeMethod kMethodsSampleForTests[] = {
248 { "nativeInit",
249 "("
250 ")"
251 "I", reinterpret_cast<void*>(Init) },
252 { "nativeDestroy",
253 "("
254 "I"
255 ")"
256 "V", reinterpret_cast<void*>(Destroy) },
257 { "nativeGetDoubleFunction",
258 "("
259 ")"
260 "D", reinterpret_cast<void*>(GetDoubleFunction) },
261 { "nativeGetFloatFunction",
262 "("
263 ")"
264 "F", reinterpret_cast<void*>(GetFloatFunction) },
265 { "nativeSetNonPODDatatype",
266 "("
267 "Landroid/graphics/Rect;"
268 ")"
269 "V", reinterpret_cast<void*>(SetNonPODDatatype) },
270 { "nativeGetNonPODDatatype",
271 "("
272 ")"
273 "Ljava/lang/Object;", reinterpret_cast<void*>(GetNonPODDatatype) },
274 { "nativeMethod",
275 "("
276 "I"
277 ")"
278 "I", reinterpret_cast<void*>(Method) },
279 { "nativeMethodOtherP0",
280 "("
281 "I"
282 ")"
283 "D", reinterpret_cast<void*>(MethodOtherP0) },
284 };
285 const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests);
286
287 if (env->RegisterNatives(g_SampleForTests_clazz.obj(),
288 kMethodsSampleForTests,
289 kMethodsSampleForTestsSize) < 0) {
290 LOG(ERROR) << "RegisterNatives failed in " << __FILE__;
291 return false;
292 }
293
294 return true;
295 }
296
297 #endif // org_chromium_example_jni_generator_SampleForTests_JNI
OLDNEW
« no previous file with comments | « base/android/jni_generator/SampleForTests.java ('k') | base/android/jni_generator/jni_generator.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698