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.
5 // This file is autogenerated by
6 // base/android/jni_generator/jni_generator.py
8 // org/chromium/example/jni_generator/SampleForTests
10 #ifndef org_chromium_example_jni_generator_SampleForTests_JNI
11 #define org_chromium_example_jni_generator_SampleForTests_JNI
15 #include "base/android/jni_generator/jni_generator_helper.h"
17 #include "base/android/jni_int_wrapper.h"
19 // Step 1: forward declarations.
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, kSampleForTestsClassPath, &g_SampleForTests_clazz)
29 // Step 2: method stubs.
30 extern "C" __attribute__((visibility("default")))
32 Java_org_chromium_example_jni_1generator_SampleForTests_nativeStaticMethod(JNIEnv*
37 Test* native = reinterpret_cast<Test*>(nativeTest);
38 CHECK_NATIVE_PTR(env, jcaller, native, "StaticMethod", 0);
39 return native->StaticMethod(env, JavaParamRef<jobject>(env, jcaller), arg1);
42 extern "C" __attribute__((visibility("default")))
44 Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod(JNIEnv*
49 Test* native = reinterpret_cast<Test*>(nativeTest);
50 CHECK_NATIVE_PTR(env, jcaller, native, "Method", 0);
51 return native->Method(env, JavaParamRef<jobject>(env, jcaller), arg1);
54 static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller);
56 extern "C" __attribute__((visibility("default")))
58 Java_org_chromium_example_jni_1generator_SampleForTests_00024MyInnerClass_nativeInit(JNIEnv*
59 env, jobject jcaller) {
60 return Init(env, JavaParamRef<jobject>(env, jcaller));
63 static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller);
65 extern "C" __attribute__((visibility("default")))
67 Java_org_chromium_example_jni_1generator_SampleForTests_00024MyOtherInnerClass_nativeInit(JNIEnv*
68 env, jobject jcaller) {
69 return Init(env, JavaParamRef<jobject>(env, jcaller));
72 static base::subtle::AtomicWord g_SampleForTests_testMethodWithParam = 0;
73 static void Java_SampleForTests_testMethodWithParam(JNIEnv* env, jobject obj,
74 JniIntWrapper iParam) {
75 /* Must call RegisterNativesImpl() */
77 SampleForTests_clazz(env));
79 base::android::MethodID::LazyGet<
80 base::android::MethodID::TYPE_INSTANCE>(
81 env, SampleForTests_clazz(env),
82 "testMethodWithParam",
88 &g_SampleForTests_testMethodWithParam);
90 env->CallVoidMethod(obj,
91 method_id, as_jint(iParam));
92 jni_generator::CheckException(env);
96 static base::subtle::AtomicWord g_SampleForTests_testMethodWithParamAndReturn =
98 static ScopedJavaLocalRef<jstring>
99 Java_SampleForTests_testMethodWithParamAndReturn(JNIEnv* env, jobject obj,
100 JniIntWrapper iParam) {
101 /* Must call RegisterNativesImpl() */
102 CHECK_CLAZZ(env, obj,
103 SampleForTests_clazz(env), NULL);
104 jmethodID method_id =
105 base::android::MethodID::LazyGet<
106 base::android::MethodID::TYPE_INSTANCE>(
107 env, SampleForTests_clazz(env),
108 "testMethodWithParamAndReturn",
113 "Ljava/lang/String;",
114 &g_SampleForTests_testMethodWithParamAndReturn);
117 static_cast<jstring>(env->CallObjectMethod(obj,
118 method_id, as_jint(iParam)));
119 jni_generator::CheckException(env);
120 return ScopedJavaLocalRef<jstring>(env, ret);
123 static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithParam = 0;
124 static jint Java_SampleForTests_testStaticMethodWithParam(JNIEnv* env,
125 JniIntWrapper iParam) {
126 /* Must call RegisterNativesImpl() */
127 CHECK_CLAZZ(env, SampleForTests_clazz(env),
128 SampleForTests_clazz(env), 0);
129 jmethodID method_id =
130 base::android::MethodID::LazyGet<
131 base::android::MethodID::TYPE_STATIC>(
132 env, SampleForTests_clazz(env),
133 "testStaticMethodWithParam",
139 &g_SampleForTests_testStaticMethodWithParam);
142 env->CallStaticIntMethod(SampleForTests_clazz(env),
143 method_id, as_jint(iParam));
144 jni_generator::CheckException(env);
148 static base::subtle::AtomicWord g_SampleForTests_testMethodWithNoParam = 0;
149 static jdouble Java_SampleForTests_testMethodWithNoParam(JNIEnv* env) {
150 /* Must call RegisterNativesImpl() */
151 CHECK_CLAZZ(env, SampleForTests_clazz(env),
152 SampleForTests_clazz(env), 0);
153 jmethodID method_id =
154 base::android::MethodID::LazyGet<
155 base::android::MethodID::TYPE_STATIC>(
156 env, SampleForTests_clazz(env),
157 "testMethodWithNoParam",
162 &g_SampleForTests_testMethodWithNoParam);
165 env->CallStaticDoubleMethod(SampleForTests_clazz(env),
167 jni_generator::CheckException(env);
171 static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithNoParam =
173 static ScopedJavaLocalRef<jstring>
174 Java_SampleForTests_testStaticMethodWithNoParam(JNIEnv* env) {
175 /* Must call RegisterNativesImpl() */
176 CHECK_CLAZZ(env, SampleForTests_clazz(env),
177 SampleForTests_clazz(env), NULL);
178 jmethodID method_id =
179 base::android::MethodID::LazyGet<
180 base::android::MethodID::TYPE_STATIC>(
181 env, SampleForTests_clazz(env),
182 "testStaticMethodWithNoParam",
186 "Ljava/lang/String;",
187 &g_SampleForTests_testStaticMethodWithNoParam);
190 static_cast<jstring>(env->CallStaticObjectMethod(SampleForTests_clazz(env),
192 jni_generator::CheckException(env);
193 return ScopedJavaLocalRef<jstring>(env, ret);
196 // Step 3: RegisterNatives.
198 static const JNINativeMethod kMethodsMyOtherInnerClass[] = {
203 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_00024MyOtherInnerClass_nativeInit)
207 static const JNINativeMethod kMethodsMyInnerClass[] = {
212 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_00024MyInnerClass_nativeInit)
216 static const JNINativeMethod kMethodsSampleForTests[] = {
217 { "nativeStaticMethod",
223 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeStaticMethod)
231 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod)
235 static bool RegisterNativesImpl(JNIEnv* env, jclass clazz) {
236 if (base::android::IsManualJniRegistrationDisabled()) return true;
238 base::subtle::Release_Store(&g_SampleForTests_clazz,
239 static_cast<base::subtle::AtomicWord>(env->NewWeakGlobalRef(clazz));
241 const int kMethodsMyOtherInnerClassSize =
242 arraysize(kMethodsMyOtherInnerClass);
244 if (env->RegisterNatives(MyOtherInnerClass_clazz(env),
245 kMethodsMyOtherInnerClass,
246 kMethodsMyOtherInnerClassSize) < 0) {
247 jni_generator::HandleRegistrationError(
248 env, MyOtherInnerClass_clazz(env), __FILE__);
252 const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass);
254 if (env->RegisterNatives(MyInnerClass_clazz(env),
255 kMethodsMyInnerClass,
256 kMethodsMyInnerClassSize) < 0) {
257 jni_generator::HandleRegistrationError(
258 env, MyInnerClass_clazz(env), __FILE__);
262 const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests);
264 if (env->RegisterNatives(SampleForTests_clazz(env),
265 kMethodsSampleForTests,
266 kMethodsSampleForTestsSize) < 0) {
267 jni_generator::HandleRegistrationError(
268 env, SampleForTests_clazz(env), __FILE__);
275 extern "C" JNIEXPORT bool JNICALL
276 Java_org_chromium_example_jni_1generator_SampleForTests_nativeInitNativeClass(JNIEnv*
278 return RegisterNativesImpl(env, clazz);
281 #endif // org_chromium_example_jni_generator_SampleForTests_JNI