OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/foo/Foo | 8 // org/chromium/foo/Foo |
9 | 9 |
10 #ifndef org_chromium_foo_Foo_JNI | 10 #ifndef org_chromium_foo_Foo_JNI |
11 #define org_chromium_foo_Foo_JNI | 11 #define org_chromium_foo_Foo_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 kFooClassPath[] = "org/chromium/foo/Foo"; | 21 const char kFooClassPath[] = "org/chromium/foo/Foo"; |
22 #if __clang__ | |
23 #pragma clang diagnostic push | |
24 #pragma clang diagnostic ignored "-Wunused-function" | |
25 #endif | |
26 // Leaking this jclass as we cannot use LazyInstance from some threads. | 22 // Leaking this jclass as we cannot use LazyInstance from some threads. |
27 jclass g_Foo_clazz = NULL; | 23 jclass g_Foo_clazz = NULL; |
28 jclass Foo_clazz(JNIEnv*) { return g_Foo_clazz; } | |
29 #if __clang__ | |
30 #pragma clang diagnostic pop | |
31 #endif | |
32 | 24 |
33 } // namespace | 25 } // namespace |
34 | 26 |
35 static void DoSomething(JNIEnv* env, jclass jcaller, | 27 static void DoSomething(JNIEnv* env, jclass jcaller, |
36 jobject callback); | 28 jobject callback); |
37 | 29 |
38 // Step 2: method stubs. | 30 // Step 2: method stubs. |
39 | 31 |
40 static base::subtle::AtomicWord g_Foo_calledByNative = 0; | 32 static base::subtle::AtomicWord g_Foo_calledByNative = 0; |
41 static void Java_Foo_calledByNative(JNIEnv* env, jobject callback) { | 33 static void Java_Foo_calledByNative(JNIEnv* env, jobject callback) { |
42 /* Must call RegisterNativesImpl() */ | 34 /* Must call RegisterNativesImpl() */ |
43 CHECK_CLAZZ(env, Foo_clazz(env), | 35 CHECK_CLAZZ(env, g_Foo_clazz, |
44 Foo_clazz(env)); | 36 g_Foo_clazz); |
45 jmethodID method_id = | 37 jmethodID method_id = |
46 base::android::MethodID::LazyGet< | 38 base::android::MethodID::LazyGet< |
47 base::android::MethodID::TYPE_STATIC>( | 39 base::android::MethodID::TYPE_STATIC>( |
48 env, Foo_clazz(env), | 40 env, g_Foo_clazz, |
49 "calledByNative", | 41 "calledByNative", |
50 | 42 |
51 "(" | 43 "(" |
52 "Lorg/chromium/foo/Bar$Callback;" | 44 "Lorg/chromium/foo/Bar$Callback;" |
53 ")" | 45 ")" |
54 "V", | 46 "V", |
55 &g_Foo_calledByNative); | 47 &g_Foo_calledByNative); |
56 | 48 |
57 env->CallStaticVoidMethod(Foo_clazz(env), | 49 env->CallStaticVoidMethod(g_Foo_clazz, |
58 method_id, callback); | 50 method_id, callback); |
59 jni_generator::CheckException(env); | 51 jni_generator::CheckException(env); |
60 | 52 |
61 } | 53 } |
62 | 54 |
63 // Step 3: RegisterNatives. | 55 // Step 3: RegisterNatives. |
64 | 56 |
65 static const JNINativeMethod kMethodsFoo[] = { | 57 static const JNINativeMethod kMethodsFoo[] = { |
66 { "nativeDoSomething", | 58 { "nativeDoSomething", |
67 "(" | 59 "(" |
68 "Lorg/chromium/foo/Bar$Callback;" | 60 "Lorg/chromium/foo/Bar$Callback;" |
69 ")" | 61 ")" |
70 "V", reinterpret_cast<void*>(DoSomething) }, | 62 "V", reinterpret_cast<void*>(DoSomething) }, |
71 }; | 63 }; |
72 | 64 |
73 static bool RegisterNativesImpl(JNIEnv* env) { | 65 static bool RegisterNativesImpl(JNIEnv* env) { |
74 g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | 66 g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
75 base::android::GetClass(env, kFooClassPath).obj())); | 67 base::android::GetClass(env, kFooClassPath).obj())); |
76 | 68 |
77 const int kMethodsFooSize = arraysize(kMethodsFoo); | 69 const int kMethodsFooSize = arraysize(kMethodsFoo); |
78 | 70 |
79 if (env->RegisterNatives(Foo_clazz(env), | 71 if (env->RegisterNatives(g_Foo_clazz, |
80 kMethodsFoo, | 72 kMethodsFoo, |
81 kMethodsFooSize) < 0) { | 73 kMethodsFooSize) < 0) { |
82 jni_generator::HandleRegistrationError( | 74 jni_generator::HandleRegistrationError( |
83 env, Foo_clazz(env), __FILE__); | 75 env, g_Foo_clazz, __FILE__); |
84 return false; | 76 return false; |
85 } | 77 } |
86 | 78 |
87 return true; | 79 return true; |
88 } | 80 } |
89 | 81 |
90 #endif // org_chromium_foo_Foo_JNI | 82 #endif // org_chromium_foo_Foo_JNI |
OLD | NEW |