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. 20namespace { 21const char kSampleForTestsClassPath[] = 22 "org/chromium/example/jni_generator/SampleForTests"; 23// Leaking this jclass as we cannot use LazyInstance from some threads. 24base::subtle::AtomicWord g_SampleForTests_clazz __attribute__((unused)) = 0; 25#define SampleForTests_clazz(env) base::android::LazyGetClass(env, kSampleForTestsClassPath, &g_SampleForTests_clazz) 26 27} // namespace 28 29// Step 2: method stubs. 30extern "C" __attribute__((visibility("default"))) 31jint 32 Java_org_chromium_example_jni_1generator_SampleForTests_nativeStaticMethod(JNIEnv* 33 env, 34 jobject jcaller, 35 jlong nativeTest, 36 jint arg1) { 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); 40} 41 42extern "C" __attribute__((visibility("default"))) 43jint 44 Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod(JNIEnv* 45 env, 46 jobject jcaller, 47 jlong nativeTest, 48 jint arg1) { 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); 52} 53 54static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller); 55 56extern "C" __attribute__((visibility("default"))) 57jint 58 Java_org_chromium_example_jni_1generator_SampleForTests_00024MyInnerClass_nativeInit(JNIEnv* 59 env, jobject jcaller) { 60 return Init(env, JavaParamRef<jobject>(env, jcaller)); 61} 62 63static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller); 64 65extern "C" __attribute__((visibility("default"))) 66jint 67 Java_org_chromium_example_jni_1generator_SampleForTests_00024MyOtherInnerClass_nativeInit(JNIEnv* 68 env, jobject jcaller) { 69 return Init(env, JavaParamRef<jobject>(env, jcaller)); 70} 71 72static base::subtle::AtomicWord g_SampleForTests_testMethodWithParam = 0; 73static void Java_SampleForTests_testMethodWithParam(JNIEnv* env, jobject obj, 74 JniIntWrapper iParam) { 75 /* Must call RegisterNativesImpl() */ 76 CHECK_CLAZZ(env, obj, 77 SampleForTests_clazz(env)); 78 jmethodID method_id = 79 base::android::MethodID::LazyGet< 80 base::android::MethodID::TYPE_INSTANCE>( 81 env, SampleForTests_clazz(env), 82 "testMethodWithParam", 83 84"(" 85"I" 86")" 87"V", 88 &g_SampleForTests_testMethodWithParam); 89 90 env->CallVoidMethod(obj, 91 method_id, as_jint(iParam)); 92 jni_generator::CheckException(env); 93 94} 95 96static base::subtle::AtomicWord g_SampleForTests_testMethodWithParamAndReturn = 97 0; 98static 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", 109 110"(" 111"I" 112")" 113"Ljava/lang/String;", 114 &g_SampleForTests_testMethodWithParamAndReturn); 115 116 jstring ret = 117 static_cast<jstring>(env->CallObjectMethod(obj, 118 method_id, as_jint(iParam))); 119 jni_generator::CheckException(env); 120 return ScopedJavaLocalRef<jstring>(env, ret); 121} 122 123static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithParam = 0; 124static 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", 134 135"(" 136"I" 137")" 138"I", 139 &g_SampleForTests_testStaticMethodWithParam); 140 141 jint ret = 142 env->CallStaticIntMethod(SampleForTests_clazz(env), 143 method_id, as_jint(iParam)); 144 jni_generator::CheckException(env); 145 return ret; 146} 147 148static base::subtle::AtomicWord g_SampleForTests_testMethodWithNoParam = 0; 149static 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", 158 159"(" 160")" 161"D", 162 &g_SampleForTests_testMethodWithNoParam); 163 164 jdouble ret = 165 env->CallStaticDoubleMethod(SampleForTests_clazz(env), 166 method_id); 167 jni_generator::CheckException(env); 168 return ret; 169} 170 171static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithNoParam = 172 0; 173static 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", 183 184"(" 185")" 186"Ljava/lang/String;", 187 &g_SampleForTests_testStaticMethodWithNoParam); 188 189 jstring ret = 190static_cast<jstring>(env->CallStaticObjectMethod(SampleForTests_clazz(env), 191 method_id)); 192 jni_generator::CheckException(env); 193 return ScopedJavaLocalRef<jstring>(env, ret); 194} 195 196// Step 3: RegisterNatives. 197 198static const JNINativeMethod kMethodsMyOtherInnerClass[] = { 199 { "nativeInit", 200"(" 201")" 202"I", 203 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_00024MyOtherInnerClass_nativeInit) 204 }, 205}; 206 207static const JNINativeMethod kMethodsMyInnerClass[] = { 208 { "nativeInit", 209"(" 210")" 211"I", 212 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_00024MyInnerClass_nativeInit) 213 }, 214}; 215 216static const JNINativeMethod kMethodsSampleForTests[] = { 217 { "nativeStaticMethod", 218"(" 219"J" 220"I" 221")" 222"I", 223 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeStaticMethod) 224 }, 225 { "nativeMethod", 226"(" 227"J" 228"I" 229")" 230"I", 231 reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod) 232 }, 233}; 234 235static bool RegisterNativesImpl(JNIEnv* env) { 236 if (base::android::IsManualJniRegistrationDisabled()) return true; 237 238 const int kMethodsMyOtherInnerClassSize = 239 arraysize(kMethodsMyOtherInnerClass); 240 241 if (env->RegisterNatives(MyOtherInnerClass_clazz(env), 242 kMethodsMyOtherInnerClass, 243 kMethodsMyOtherInnerClassSize) < 0) { 244 jni_generator::HandleRegistrationError( 245 env, MyOtherInnerClass_clazz(env), __FILE__); 246 return false; 247 } 248 249 const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); 250 251 if (env->RegisterNatives(MyInnerClass_clazz(env), 252 kMethodsMyInnerClass, 253 kMethodsMyInnerClassSize) < 0) { 254 jni_generator::HandleRegistrationError( 255 env, MyInnerClass_clazz(env), __FILE__); 256 return false; 257 } 258 259 const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests); 260 261 if (env->RegisterNatives(SampleForTests_clazz(env), 262 kMethodsSampleForTests, 263 kMethodsSampleForTestsSize) < 0) { 264 jni_generator::HandleRegistrationError( 265 env, SampleForTests_clazz(env), __FILE__); 266 return false; 267 } 268 269 return true; 270} 271 272#endif // org_chromium_example_jni_generator_SampleForTests_JNI 273