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 = 0; 25 #define SampleForTests_clazz(env) base::android::LazyGetClass(env, kSampleForTestsClassPath, &g_SampleForTests_clazz) 26 27 } // namespace 28 29 extern "C" { 30 31 static jint Init(JNIEnv* env, jobject jcaller); 32 33 __attribute__((visibility("default"))) 34 jint 35 Java_org_chromium_example_jni_1generator_SampleForTests_00024MyInnerClass_nativeInit(JNIEnv* 36 env, jobject jcaller) { 37 return Init(env, jcaller); 38 } 39 40 static jint Init(JNIEnv* env, jobject jcaller); 41 42 __attribute__((visibility("default"))) 43 jint 44 Java_org_chromium_example_jni_1generator_SampleForTests_00024MyOtherInnerClass_nativeInit(JNIEnv* 45 env, jobject jcaller) { 46 return Init(env, jcaller); 47 } 48 49 }; // extern "C" 50 51 // Step 2: method stubs. 52 53 extern "C" { 54 __attribute__((visibility("default"))) 55 jint 56 Java_org_chromium_example_jni_1generator_SampleForTests_nativeStaticMethod(JNIEnv* 57 env, 58 jobject jcaller, 59 jlong nativeTest, 60 jint arg1) { 61 Test* native = reinterpret_cast<Test*>(nativeTest); 62 CHECK_NATIVE_PTR(env, jcaller, native, "StaticMethod", 0); 63 return native->StaticMethod(env, jcaller, arg1); 64 } 65 66 __attribute__((visibility("default"))) 67 jint 68 Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod(JNIEnv* 69 env, 70 jobject jcaller, 71 jlong nativeTest, 72 jint arg1) { 73 Test* native = reinterpret_cast<Test*>(nativeTest); 74 CHECK_NATIVE_PTR(env, jcaller, native, "Method", 0); 75 return native->Method(env, jcaller, arg1); 76 } 77 78 static base::subtle::AtomicWord g_SampleForTests_testMethodWithParam = 0; 79 static void Java_SampleForTests_testMethodWithParam(JNIEnv* env, jobject obj, 80 JniIntWrapper iParam) { 81 /* Must call RegisterNativesImpl() */ 82 CHECK_CLAZZ(env, obj, 83 SampleForTests_clazz(env)); 84 jmethodID method_id = 85 base::android::MethodID::LazyGet< 86 base::android::MethodID::TYPE_INSTANCE>( 87 env, SampleForTests_clazz(env), 88 "testMethodWithParam", 89 90 "(" 91 "I" 92 ")" 93 "V", 94 &g_SampleForTests_testMethodWithParam); 95 96 env->CallVoidMethod(obj, 97 method_id, as_jint(iParam)); 98 jni_generator::CheckException(env); 99 100 } 101 102 static base::subtle::AtomicWord g_SampleForTests_testMethodWithParamAndReturn = 103 0; 104 static base::android::ScopedJavaLocalRef<jstring> 105 Java_SampleForTests_testMethodWithParamAndReturn(JNIEnv* env, jobject obj, 106 JniIntWrapper iParam) { 107 /* Must call RegisterNativesImpl() */ 108 CHECK_CLAZZ(env, obj, 109 SampleForTests_clazz(env), NULL); 110 jmethodID method_id = 111 base::android::MethodID::LazyGet< 112 base::android::MethodID::TYPE_INSTANCE>( 113 env, SampleForTests_clazz(env), 114 "testMethodWithParamAndReturn", 115 116 "(" 117 "I" 118 ")" 119 "Ljava/lang/String;", 120 &g_SampleForTests_testMethodWithParamAndReturn); 121 122 jstring ret = 123 static_cast<jstring>(env->CallObjectMethod(obj, 124 method_id, as_jint(iParam))); 125 jni_generator::CheckException(env); 126 return base::android::ScopedJavaLocalRef<jstring>(env, ret); 127 } 128 129 static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithParam = 0; 130 static jint Java_SampleForTests_testStaticMethodWithParam(JNIEnv* env, 131 JniIntWrapper iParam) { 132 /* Must call RegisterNativesImpl() */ 133 CHECK_CLAZZ(env, SampleForTests_clazz(env), 134 SampleForTests_clazz(env), 0); 135 jmethodID method_id = 136 base::android::MethodID::LazyGet< 137 base::android::MethodID::TYPE_STATIC>( 138 env, SampleForTests_clazz(env), 139 "testStaticMethodWithParam", 140 141 "(" 142 "I" 143 ")" 144 "I", 145 &g_SampleForTests_testStaticMethodWithParam); 146 147 jint ret = 148 env->CallStaticIntMethod(SampleForTests_clazz(env), 149 method_id, as_jint(iParam)); 150 jni_generator::CheckException(env); 151 return ret; 152 } 153 154 static base::subtle::AtomicWord g_SampleForTests_testMethodWithNoParam = 0; 155 static jdouble Java_SampleForTests_testMethodWithNoParam(JNIEnv* env) { 156 /* Must call RegisterNativesImpl() */ 157 CHECK_CLAZZ(env, SampleForTests_clazz(env), 158 SampleForTests_clazz(env), 0); 159 jmethodID method_id = 160 base::android::MethodID::LazyGet< 161 base::android::MethodID::TYPE_STATIC>( 162 env, SampleForTests_clazz(env), 163 "testMethodWithNoParam", 164 165 "(" 166 ")" 167 "D", 168 &g_SampleForTests_testMethodWithNoParam); 169 170 jdouble ret = 171 env->CallStaticDoubleMethod(SampleForTests_clazz(env), 172 method_id); 173 jni_generator::CheckException(env); 174 return ret; 175 } 176 177 static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithNoParam = 178 0; 179 static base::android::ScopedJavaLocalRef<jstring> 180 Java_SampleForTests_testStaticMethodWithNoParam(JNIEnv* env) { 181 /* Must call RegisterNativesImpl() */ 182 CHECK_CLAZZ(env, SampleForTests_clazz(env), 183 SampleForTests_clazz(env), NULL); 184 jmethodID method_id = 185 base::android::MethodID::LazyGet< 186 base::android::MethodID::TYPE_STATIC>( 187 env, SampleForTests_clazz(env), 188 "testStaticMethodWithNoParam", 189 190 "(" 191 ")" 192 "Ljava/lang/String;", 193 &g_SampleForTests_testStaticMethodWithNoParam); 194 195 jstring ret = 196 static_cast<jstring>(env->CallStaticObjectMethod(SampleForTests_clazz(env), 197 method_id)); 198 jni_generator::CheckException(env); 199 return base::android::ScopedJavaLocalRef<jstring>(env, ret); 200 } 201 }; // extern "C" 202 203 // Step 3: RegisterNatives. 204 205 static bool RegisterNativesImpl(JNIEnv* env, jclass clazz) { 206 base::subtle::Release_Store(&g_SampleForTests_clazz, 207 static_cast<base::subtle::AtomicWord>(env->NewWeakGlobalRef(clazz)); 208 209 return true; 210 } 211 212 extern "C" JNIEXPORT bool JNICALL 213 Java_org_chromium_example_jni_1generator_SampleForTests_nativeInitNativeClass(JNIEnv* 214 env, jclass clazz) { 215 return RegisterNativesImpl(env, clazz); 216 } 217 218 #endif // org_chromium_example_jni_generator_SampleForTests_JNI 219