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