OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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/Test |
| 9 |
| 10 #ifndef org_chromium_example_jni_generator_Test_JNI |
| 11 #define org_chromium_example_jni_generator_Test_JNI |
| 12 |
| 13 #include <jni.h> |
| 14 |
| 15 #include "base/android/jni_generator/jni_generator_helper.h" |
| 16 |
| 17 // Step 1: forward declarations. |
| 18 namespace { |
| 19 const char kTestClassPath[] = "org/chromium/example/jni_generator/Test"; |
| 20 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 21 jclass g_Test_clazz = NULL; |
| 22 jmethodID g_Test_testMethodWithParam = NULL; |
| 23 jmethodID g_Test_testStaticMethodWithParam = NULL; |
| 24 jmethodID g_Test_testMethodWithNoParam = NULL; |
| 25 jmethodID g_Test_testStaticMethodWithNoParam = NULL; |
| 26 } // namespace |
| 27 |
| 28 // Step 2: method stubs. |
| 29 static jint Method(JNIEnv* env, jobject obj, |
| 30 jint nativeTest, |
| 31 jint arg1) { |
| 32 Test* native = reinterpret_cast<Test*>(nativeTest); |
| 33 DCHECK_NATIVE_PTR(native, "Method", 0); |
| 34 return native->Method(env, obj, arg1); |
| 35 } |
| 36 |
| 37 namespace { |
| 38 |
| 39 static void testMethodWithParam(JNIEnv* env, jobject obj, jint iParam) { |
| 40 env->CallVoidMethod(obj, |
| 41 g_Test_testMethodWithParam, iParam); |
| 42 |
| 43 } |
| 44 |
| 45 static jint testStaticMethodWithParam(JNIEnv* env, jint iParam) { |
| 46 jint ret = env->CallStaticIntMethod(g_Test_clazz, |
| 47 g_Test_testStaticMethodWithParam, iParam); |
| 48 return ret; |
| 49 } |
| 50 |
| 51 static jdouble testMethodWithNoParam(JNIEnv* env) { |
| 52 jdouble ret = env->CallStaticDoubleMethod(g_Test_clazz, |
| 53 g_Test_testMethodWithNoParam); |
| 54 return ret; |
| 55 } |
| 56 |
| 57 static base::android::ScopedJavaLocalRef<jstring> |
| 58 testStaticMethodWithNoParam(JNIEnv* env) { |
| 59 jstring ret = static_cast<jstring>(env->CallStaticObjectMethod(g_Test_clazz, |
| 60 g_Test_testStaticMethodWithNoParam)); |
| 61 return base::android::ScopedJavaLocalRef<jstring>(env, ret); |
| 62 } |
| 63 } // namespace |
| 64 |
| 65 // Step 3: RegisterNatives. |
| 66 |
| 67 static const JNINativeMethod kMethodsTest[] = { |
| 68 { "nativeMethod", |
| 69 "(" |
| 70 "I" |
| 71 "I" |
| 72 ")" |
| 73 "I", reinterpret_cast<void*>(Method) }, |
| 74 }; |
| 75 |
| 76 static bool RegisterNativesImpl(JNIEnv* env, jclass clazz) { |
| 77 g_Test_clazz = static_cast<jclass>(env->NewWeakGlobalRef(clazz)); |
| 78 |
| 79 const int kMethodsTestSize = arraysize(kMethodsTest); |
| 80 |
| 81 if (env->RegisterNatives(g_Test_clazz, |
| 82 kMethodsTest, |
| 83 kMethodsTestSize) < 0) { |
| 84 jni_generator::HandleRegistrationError( |
| 85 env, g_Test_clazz, __FILE__); |
| 86 return false; |
| 87 } |
| 88 |
| 89 g_Test_testMethodWithParam = env->GetMethodID( |
| 90 g_Test_clazz, |
| 91 "testMethodWithParam", |
| 92 "(" |
| 93 "I" |
| 94 ")" |
| 95 "V"); |
| 96 if (g_Test_testMethodWithParam == NULL) { |
| 97 return false; |
| 98 } |
| 99 |
| 100 g_Test_testStaticMethodWithParam = env->GetStaticMethodID( |
| 101 g_Test_clazz, |
| 102 "testStaticMethodWithParam", |
| 103 "(" |
| 104 "I" |
| 105 ")" |
| 106 "I"); |
| 107 if (g_Test_testStaticMethodWithParam == NULL) { |
| 108 return false; |
| 109 } |
| 110 |
| 111 g_Test_testMethodWithNoParam = env->GetStaticMethodID( |
| 112 g_Test_clazz, |
| 113 "testMethodWithNoParam", |
| 114 "(" |
| 115 ")" |
| 116 "D"); |
| 117 if (g_Test_testMethodWithNoParam == NULL) { |
| 118 return false; |
| 119 } |
| 120 |
| 121 g_Test_testStaticMethodWithNoParam = env->GetStaticMethodID( |
| 122 g_Test_clazz, |
| 123 "testStaticMethodWithNoParam", |
| 124 "(" |
| 125 ")" |
| 126 "Ljava/lang/String;"); |
| 127 if (g_Test_testStaticMethodWithNoParam == NULL) { |
| 128 return false; |
| 129 } |
| 130 |
| 131 return true; |
| 132 } |
| 133 |
| 134 extern "C" JNIEXPORT bool JNICALL |
| 135 Java_org_chromium_example_jni_generator_Test_initNativeClass(JNIEnv* env, jclass |
| 136 clazz) { |
| 137 return RegisterNativesImpl(env, clazz); |
| 138 } |
| 139 |
| 140 #endif // org_chromium_example_jni_generator_Test_JNI |
OLD | NEW |