| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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.py | 6 // base/android/jni_generator/jni_generator.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_generator/jni_generator_helper.h" | 15 #include "base/android/jni_generator/jni_generator_helper.h" |
| 16 | 16 |
| 17 #include "base/android/jni_int_wrapper.h" | 17 #include "base/android/jni_int_wrapper.h" |
| 18 | 18 |
| 19 // Step 1: forward declarations. | 19 // Step 1: forward declarations. |
| 20 namespace { | 20 namespace { |
| 21 const char kSampleForTestsClassPath[] = | 21 const char kSampleForTestsClassPath[] = |
| 22 "org/chromium/example/jni_generator/SampleForTests"; | 22 "org/chromium/example/jni_generator/SampleForTests"; |
| 23 // Leaking this jclass as we cannot use LazyInstance from some threads. | 23 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 24 jclass g_SampleForTests_clazz = NULL; | 24 base::subtle::AtomicWord g_SampleForTests_clazz = 0; |
| 25 jclass SampleForTests_clazz(JNIEnv* env) { |
| 26 return base::android::LazyGetClass(env, kSampleForTestsClassPath, |
| 27 &g_SampleForTests_clazz); |
| 28 } |
| 25 | 29 |
| 26 } // namespace | 30 } // namespace |
| 27 | 31 |
| 28 extern "C" { | 32 extern "C" { |
| 29 | 33 |
| 30 static jint Init(JNIEnv* env, jobject jcaller); | 34 static jint Init(JNIEnv* env, jobject jcaller); |
| 31 | 35 |
| 32 __attribute__((visibility("default"))) | 36 __attribute__((visibility("default"))) |
| 33 jint | 37 jint |
| 34 Java_org_chromium_example_jni_1generator_SampleForTests_00024MyInnerClass_na
tiveInit(JNIEnv* | 38 Java_org_chromium_example_jni_1generator_SampleForTests_00024MyInnerClass_na
tiveInit(JNIEnv* |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 Test* native = reinterpret_cast<Test*>(nativeTest); | 76 Test* native = reinterpret_cast<Test*>(nativeTest); |
| 73 CHECK_NATIVE_PTR(env, jcaller, native, "Method", 0); | 77 CHECK_NATIVE_PTR(env, jcaller, native, "Method", 0); |
| 74 return native->Method(env, jcaller, arg1); | 78 return native->Method(env, jcaller, arg1); |
| 75 } | 79 } |
| 76 | 80 |
| 77 static base::subtle::AtomicWord g_SampleForTests_testMethodWithParam = 0; | 81 static base::subtle::AtomicWord g_SampleForTests_testMethodWithParam = 0; |
| 78 static void Java_SampleForTests_testMethodWithParam(JNIEnv* env, jobject obj, | 82 static void Java_SampleForTests_testMethodWithParam(JNIEnv* env, jobject obj, |
| 79 JniIntWrapper iParam) { | 83 JniIntWrapper iParam) { |
| 80 /* Must call RegisterNativesImpl() */ | 84 /* Must call RegisterNativesImpl() */ |
| 81 CHECK_CLAZZ(env, obj, | 85 CHECK_CLAZZ(env, obj, |
| 82 g_SampleForTests_clazz); | 86 SampleForTests_clazz(env)); |
| 83 jmethodID method_id = | 87 jmethodID method_id = |
| 84 base::android::MethodID::LazyGet< | 88 base::android::MethodID::LazyGet< |
| 85 base::android::MethodID::TYPE_INSTANCE>( | 89 base::android::MethodID::TYPE_INSTANCE>( |
| 86 env, g_SampleForTests_clazz, | 90 env, SampleForTests_clazz(env), |
| 87 "testMethodWithParam", | 91 "testMethodWithParam", |
| 88 | 92 |
| 89 "(" | 93 "(" |
| 90 "I" | 94 "I" |
| 91 ")" | 95 ")" |
| 92 "V", | 96 "V", |
| 93 &g_SampleForTests_testMethodWithParam); | 97 &g_SampleForTests_testMethodWithParam); |
| 94 | 98 |
| 95 env->CallVoidMethod(obj, | 99 env->CallVoidMethod(obj, |
| 96 method_id, as_jint(iParam)); | 100 method_id, as_jint(iParam)); |
| 97 jni_generator::CheckException(env); | 101 jni_generator::CheckException(env); |
| 98 | 102 |
| 99 } | 103 } |
| 100 | 104 |
| 101 static base::subtle::AtomicWord g_SampleForTests_testMethodWithParamAndReturn = | 105 static base::subtle::AtomicWord g_SampleForTests_testMethodWithParamAndReturn = |
| 102 0; | 106 0; |
| 103 static base::android::ScopedJavaLocalRef<jstring> | 107 static base::android::ScopedJavaLocalRef<jstring> |
| 104 Java_SampleForTests_testMethodWithParamAndReturn(JNIEnv* env, jobject obj, | 108 Java_SampleForTests_testMethodWithParamAndReturn(JNIEnv* env, jobject obj, |
| 105 JniIntWrapper iParam) { | 109 JniIntWrapper iParam) { |
| 106 /* Must call RegisterNativesImpl() */ | 110 /* Must call RegisterNativesImpl() */ |
| 107 CHECK_CLAZZ(env, obj, | 111 CHECK_CLAZZ(env, obj, |
| 108 g_SampleForTests_clazz, NULL); | 112 SampleForTests_clazz(env), NULL); |
| 109 jmethodID method_id = | 113 jmethodID method_id = |
| 110 base::android::MethodID::LazyGet< | 114 base::android::MethodID::LazyGet< |
| 111 base::android::MethodID::TYPE_INSTANCE>( | 115 base::android::MethodID::TYPE_INSTANCE>( |
| 112 env, g_SampleForTests_clazz, | 116 env, SampleForTests_clazz(env), |
| 113 "testMethodWithParamAndReturn", | 117 "testMethodWithParamAndReturn", |
| 114 | 118 |
| 115 "(" | 119 "(" |
| 116 "I" | 120 "I" |
| 117 ")" | 121 ")" |
| 118 "Ljava/lang/String;", | 122 "Ljava/lang/String;", |
| 119 &g_SampleForTests_testMethodWithParamAndReturn); | 123 &g_SampleForTests_testMethodWithParamAndReturn); |
| 120 | 124 |
| 121 jstring ret = | 125 jstring ret = |
| 122 static_cast<jstring>(env->CallObjectMethod(obj, | 126 static_cast<jstring>(env->CallObjectMethod(obj, |
| 123 method_id, as_jint(iParam))); | 127 method_id, as_jint(iParam))); |
| 124 jni_generator::CheckException(env); | 128 jni_generator::CheckException(env); |
| 125 return base::android::ScopedJavaLocalRef<jstring>(env, ret); | 129 return base::android::ScopedJavaLocalRef<jstring>(env, ret); |
| 126 } | 130 } |
| 127 | 131 |
| 128 static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithParam = 0; | 132 static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithParam = 0; |
| 129 static jint Java_SampleForTests_testStaticMethodWithParam(JNIEnv* env, | 133 static jint Java_SampleForTests_testStaticMethodWithParam(JNIEnv* env, |
| 130 JniIntWrapper iParam) { | 134 JniIntWrapper iParam) { |
| 131 /* Must call RegisterNativesImpl() */ | 135 /* Must call RegisterNativesImpl() */ |
| 132 CHECK_CLAZZ(env, g_SampleForTests_clazz, | 136 CHECK_CLAZZ(env, SampleForTests_clazz(env), |
| 133 g_SampleForTests_clazz, 0); | 137 SampleForTests_clazz(env), 0); |
| 134 jmethodID method_id = | 138 jmethodID method_id = |
| 135 base::android::MethodID::LazyGet< | 139 base::android::MethodID::LazyGet< |
| 136 base::android::MethodID::TYPE_STATIC>( | 140 base::android::MethodID::TYPE_STATIC>( |
| 137 env, g_SampleForTests_clazz, | 141 env, SampleForTests_clazz(env), |
| 138 "testStaticMethodWithParam", | 142 "testStaticMethodWithParam", |
| 139 | 143 |
| 140 "(" | 144 "(" |
| 141 "I" | 145 "I" |
| 142 ")" | 146 ")" |
| 143 "I", | 147 "I", |
| 144 &g_SampleForTests_testStaticMethodWithParam); | 148 &g_SampleForTests_testStaticMethodWithParam); |
| 145 | 149 |
| 146 jint ret = | 150 jint ret = |
| 147 env->CallStaticIntMethod(g_SampleForTests_clazz, | 151 env->CallStaticIntMethod(SampleForTests_clazz(env), |
| 148 method_id, as_jint(iParam)); | 152 method_id, as_jint(iParam)); |
| 149 jni_generator::CheckException(env); | 153 jni_generator::CheckException(env); |
| 150 return ret; | 154 return ret; |
| 151 } | 155 } |
| 152 | 156 |
| 153 static base::subtle::AtomicWord g_SampleForTests_testMethodWithNoParam = 0; | 157 static base::subtle::AtomicWord g_SampleForTests_testMethodWithNoParam = 0; |
| 154 static jdouble Java_SampleForTests_testMethodWithNoParam(JNIEnv* env) { | 158 static jdouble Java_SampleForTests_testMethodWithNoParam(JNIEnv* env) { |
| 155 /* Must call RegisterNativesImpl() */ | 159 /* Must call RegisterNativesImpl() */ |
| 156 CHECK_CLAZZ(env, g_SampleForTests_clazz, | 160 CHECK_CLAZZ(env, SampleForTests_clazz(env), |
| 157 g_SampleForTests_clazz, 0); | 161 SampleForTests_clazz(env), 0); |
| 158 jmethodID method_id = | 162 jmethodID method_id = |
| 159 base::android::MethodID::LazyGet< | 163 base::android::MethodID::LazyGet< |
| 160 base::android::MethodID::TYPE_STATIC>( | 164 base::android::MethodID::TYPE_STATIC>( |
| 161 env, g_SampleForTests_clazz, | 165 env, SampleForTests_clazz(env), |
| 162 "testMethodWithNoParam", | 166 "testMethodWithNoParam", |
| 163 | 167 |
| 164 "(" | 168 "(" |
| 165 ")" | 169 ")" |
| 166 "D", | 170 "D", |
| 167 &g_SampleForTests_testMethodWithNoParam); | 171 &g_SampleForTests_testMethodWithNoParam); |
| 168 | 172 |
| 169 jdouble ret = | 173 jdouble ret = |
| 170 env->CallStaticDoubleMethod(g_SampleForTests_clazz, | 174 env->CallStaticDoubleMethod(SampleForTests_clazz(env), |
| 171 method_id); | 175 method_id); |
| 172 jni_generator::CheckException(env); | 176 jni_generator::CheckException(env); |
| 173 return ret; | 177 return ret; |
| 174 } | 178 } |
| 175 | 179 |
| 176 static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithNoParam = | 180 static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithNoParam = |
| 177 0; | 181 0; |
| 178 static base::android::ScopedJavaLocalRef<jstring> | 182 static base::android::ScopedJavaLocalRef<jstring> |
| 179 Java_SampleForTests_testStaticMethodWithNoParam(JNIEnv* env) { | 183 Java_SampleForTests_testStaticMethodWithNoParam(JNIEnv* env) { |
| 180 /* Must call RegisterNativesImpl() */ | 184 /* Must call RegisterNativesImpl() */ |
| 181 CHECK_CLAZZ(env, g_SampleForTests_clazz, | 185 CHECK_CLAZZ(env, SampleForTests_clazz(env), |
| 182 g_SampleForTests_clazz, NULL); | 186 SampleForTests_clazz(env), NULL); |
| 183 jmethodID method_id = | 187 jmethodID method_id = |
| 184 base::android::MethodID::LazyGet< | 188 base::android::MethodID::LazyGet< |
| 185 base::android::MethodID::TYPE_STATIC>( | 189 base::android::MethodID::TYPE_STATIC>( |
| 186 env, g_SampleForTests_clazz, | 190 env, SampleForTests_clazz(env), |
| 187 "testStaticMethodWithNoParam", | 191 "testStaticMethodWithNoParam", |
| 188 | 192 |
| 189 "(" | 193 "(" |
| 190 ")" | 194 ")" |
| 191 "Ljava/lang/String;", | 195 "Ljava/lang/String;", |
| 192 &g_SampleForTests_testStaticMethodWithNoParam); | 196 &g_SampleForTests_testStaticMethodWithNoParam); |
| 193 | 197 |
| 194 jstring ret = | 198 jstring ret = |
| 195 static_cast<jstring>(env->CallStaticObjectMethod(g_SampleForTests_clazz, | 199 static_cast<jstring>(env->CallStaticObjectMethod(SampleForTests_clazz(env), |
| 196 method_id)); | 200 method_id)); |
| 197 jni_generator::CheckException(env); | 201 jni_generator::CheckException(env); |
| 198 return base::android::ScopedJavaLocalRef<jstring>(env, ret); | 202 return base::android::ScopedJavaLocalRef<jstring>(env, ret); |
| 199 } | 203 } |
| 200 }; // extern "C" | 204 }; // extern "C" |
| 201 | 205 |
| 202 // Step 3: RegisterNatives. | 206 // Step 3: RegisterNatives. |
| 203 | 207 |
| 204 static bool RegisterNativesImpl(JNIEnv* env, jclass clazz) { | 208 static bool RegisterNativesImpl(JNIEnv* env, jclass clazz) { |
| 205 g_SampleForTests_clazz = static_cast<jclass>(env->NewWeakGlobalRef(clazz)); | 209 base::subtle::Release_Store(&g_SampleForTests_clazz, |
| 210 static_cast<base::subtle::AtomicWord>(env->NewWeakGlobalRef(clazz)); |
| 206 | 211 |
| 207 return true; | 212 return true; |
| 208 } | 213 } |
| 209 | 214 |
| 210 extern "C" JNIEXPORT bool JNICALL | 215 extern "C" JNIEXPORT bool JNICALL |
| 211 Java_org_chromium_example_jni_1generator_SampleForTests_nativeInitNativeClass(JN
IEnv* | 216 Java_org_chromium_example_jni_1generator_SampleForTests_nativeInitNativeClass(JN
IEnv* |
| 212 env, jclass clazz) { | 217 env, jclass clazz) { |
| 213 return RegisterNativesImpl(env, clazz); | 218 return RegisterNativesImpl(env, clazz); |
| 214 } | 219 } |
| 215 | 220 |
| 216 #endif // org_chromium_example_jni_generator_SampleForTests_JNI | 221 #endif // org_chromium_example_jni_generator_SampleForTests_JNI |
| OLD | NEW |