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