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 of the same format as file that generated by
6 //     base/android/jni_generator/jni_generator.py
7 // For
8 //     com/google/vr/internal/controller/NativeCallbacks
9 
10 // Local modification includes:
11 // 1. Remove all implementaiton, only keep definition.
12 // 2. Use absolute path instead of relative path.
13 // 3. Removed all helper functions such as: Create.
14 // 4. Removed external functions that don't have implementation in shim file.
15 // 5. Replace all nativeHandle to handle. This is because jni_generator.py
16 // require jni functions start with "native" prefix. So we add the prefix to
17 // generate the file. But the real jni functions in the static library
18 // doesn't have the prefix.
19 // 6. Added function RegisterNativeCallbacksNatives at the end of this file.
20 
21 #ifndef com_google_vr_internal_controller_NativeCallbacks_JNI
22 #define com_google_vr_internal_controller_NativeCallbacks_JNI
23 
24 #include "base/android/jni_android.h"
25 // ----------------------------------------------------------------------------
26 // Native JNI methods
27 // ----------------------------------------------------------------------------
28 #include <jni.h>
29 #include <atomic>
30 #include <type_traits>
31 
32 #include "base/android/jni_generator/jni_generator_helper.h"
33 #include "base/android/jni_int_wrapper.h"
34 
35 // Step 1: forward declarations.
36 namespace {
37 const char kNativeCallbacksClassPath[] =
38     "com/google/vr/internal/controller/NativeCallbacks";
39 // Leaking this jclass as we cannot use LazyInstance from some threads.
40 std::atomic<jclass> g_NativeCallbacks_clazz __attribute__((unused)) (nullptr);
41 #define NativeCallbacks_clazz(env)                            \
42   base::android::LazyGetClass(env, kNativeCallbacksClassPath, \
43                               &g_NativeCallbacks_clazz)
44 
45 }  // namespace
46 
47 namespace NativeCallbacks {
48 // Step 2: method stubs.
49 
50 JNI_GENERATOR_EXPORT void
51 Java_com_google_vr_internal_controller_NativeCallbacks_handleStateChanged(
52     JNIEnv* env,
53     jobject jcaller,
54     jlong userData,
55     jint controllerIndex,
56     jint newState);
57 
58 JNI_GENERATOR_EXPORT void
59 Java_com_google_vr_internal_controller_NativeCallbacks_handleControllerRecentered(
60     JNIEnv* env,
61     jobject jcaller,
62     jlong userData,
63     jint controllerIndex,
64     jlong timestampNanos,
65     jfloat qx,
66     jfloat qy,
67     jfloat qz,
68     jfloat qw);
69 
70 JNI_GENERATOR_EXPORT void
71 Java_com_google_vr_internal_controller_NativeCallbacks_handleTouchEvent(
72     JNIEnv* env,
73     jobject jcaller,
74     jlong userData,
75     jint controllerIndex,
76     jlong timestampNanos,
77     jint action,
78     jfloat x,
79     jfloat y);
80 
81 JNI_GENERATOR_EXPORT void
82 Java_com_google_vr_internal_controller_NativeCallbacks_handleOrientationEvent(
83     JNIEnv* env,
84     jobject jcaller,
85     jlong userData,
86     jint controllerIndex,
87     jlong timestampNanos,
88     jfloat qx,
89     jfloat qy,
90     jfloat qz,
91     jfloat qw);
92 
93 JNI_GENERATOR_EXPORT void
94 Java_com_google_vr_internal_controller_NativeCallbacks_handleButtonEvent(
95     JNIEnv* env,
96     jobject jcaller,
97     jlong userData,
98     jint controllerIndex,
99     jlong timestampNanos,
100     jint buttonCode,
101     jboolean down);
102 
103 JNI_GENERATOR_EXPORT void
104 Java_com_google_vr_internal_controller_NativeCallbacks_handleAccelEvent(
105     JNIEnv* env,
106     jobject jcaller,
107     jlong userData,
108     jint controllerIndex,
109     jlong timestampNanos,
110     jfloat x,
111     jfloat y,
112     jfloat z);
113 
114 JNI_GENERATOR_EXPORT void
115 Java_com_google_vr_internal_controller_NativeCallbacks_handleGyroEvent(
116     JNIEnv* env,
117     jobject jcaller,
118     jlong userData,
119     jint controllerIndex,
120     jlong timestampNanos,
121     jfloat x,
122     jfloat y,
123     jfloat z);
124 
125 JNI_GENERATOR_EXPORT void
126 Java_com_google_vr_internal_controller_NativeCallbacks_handlePositionEvent(
127     JNIEnv* env,
128     jobject jcaller,
129     jlong userData,
130     jint controllerIndex,
131     jlong timestampNanos,
132     jfloat x,
133     jfloat y,
134     jfloat z);
135 
136 JNI_GENERATOR_EXPORT void
137 Java_com_google_vr_internal_controller_NativeCallbacks_handleBatteryEvent(
138     JNIEnv* env,
139     jobject jcaller,
140     jlong userData,
141     jint controllerIndex,
142     jlong timestampNanos,
143     jboolean isCharging,
144     jint batteryLevelBucket);
145 
146 JNI_GENERATOR_EXPORT void
147 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceInitFailed(
148     JNIEnv* env,
149     jobject jcaller,
150     jlong userData,
151     jint failureReason);
152 
153 JNI_GENERATOR_EXPORT void
154 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceFailed(
155     JNIEnv* env,
156     jobject jcaller,
157     jlong userData);
158 
159 JNI_GENERATOR_EXPORT void
160 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceUnavailable(
161     JNIEnv* env,
162     jobject jcaller,
163     jlong userData);
164 
165 JNI_GENERATOR_EXPORT void
166 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceConnected(
167     JNIEnv* env,
168     jobject jcaller,
169     jlong userData,
170     jint flags);
171 
172 JNI_GENERATOR_EXPORT void
173 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceDisconnected(
174     JNIEnv* env,
175     jobject jcaller,
176     jlong userData);
177 
178 // Step 3: RegisterNatives.
179 
180 static const JNINativeMethod kMethodsNativeCallbacks[] = {
181     {"handleStateChanged",
182      "("
183      "J"
184      "I"
185      "I"
186      ")"
187      "V",
188      reinterpret_cast<void*>(
189          Java_com_google_vr_internal_controller_NativeCallbacks_handleStateChanged)},
190     {"handleControllerRecentered",
191      "("
192      "J"
193      "I"
194      "J"
195      "F"
196      "F"
197      "F"
198      "F"
199      ")"
200      "V",
201      reinterpret_cast<void*>(
202          Java_com_google_vr_internal_controller_NativeCallbacks_handleControllerRecentered)},
203     {"handleTouchEvent",
204      "("
205      "J"
206      "I"
207      "J"
208      "I"
209      "F"
210      "F"
211      ")"
212      "V",
213      reinterpret_cast<void*>(
214          Java_com_google_vr_internal_controller_NativeCallbacks_handleTouchEvent)},
215     {"handleOrientationEvent",
216      "("
217      "J"
218      "I"
219      "J"
220      "F"
221      "F"
222      "F"
223      "F"
224      ")"
225      "V",
226      reinterpret_cast<void*>(
227          Java_com_google_vr_internal_controller_NativeCallbacks_handleOrientationEvent)},
228     {"handleButtonEvent",
229      "("
230      "J"
231      "I"
232      "J"
233      "I"
234      "Z"
235      ")"
236      "V",
237      reinterpret_cast<void*>(
238          Java_com_google_vr_internal_controller_NativeCallbacks_handleButtonEvent)},
239     {"handleAccelEvent",
240      "("
241      "J"
242      "I"
243      "J"
244      "F"
245      "F"
246      "F"
247      ")"
248      "V",
249      reinterpret_cast<void*>(
250          Java_com_google_vr_internal_controller_NativeCallbacks_handleAccelEvent)},
251     {"handleGyroEvent",
252      "("
253      "J"
254      "I"
255      "J"
256      "F"
257      "F"
258      "F"
259      ")"
260      "V",
261      reinterpret_cast<void*>(
262          Java_com_google_vr_internal_controller_NativeCallbacks_handleGyroEvent)},
263     {"handlePositionEvent",
264      "("
265      "J"
266      "I"
267      "J"
268      "F"
269      "F"
270      "F"
271      ")"
272      "V",
273      reinterpret_cast<void*>(
274          Java_com_google_vr_internal_controller_NativeCallbacks_handlePositionEvent)},
275     {"handleBatteryEvent",
276      "("
277      "J"
278      "I"
279      "J"
280      "Z"
281      "I"
282      ")"
283      "V",
284      reinterpret_cast<void*>(
285          Java_com_google_vr_internal_controller_NativeCallbacks_handleBatteryEvent)},
286     {"handleServiceInitFailed",
287      "("
288      "J"
289      "I"
290      ")"
291      "V",
292      reinterpret_cast<void*>(
293          Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceInitFailed)},
294     {"handleServiceFailed",
295      "("
296      "J"
297      ")"
298      "V",
299      reinterpret_cast<void*>(
300          Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceFailed)},
301     {"handleServiceUnavailable",
302      "("
303      "J"
304      ")"
305      "V",
306      reinterpret_cast<void*>(
307          Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceUnavailable)},
308     {"handleServiceConnected",
309      "("
310      "J"
311      "I"
312      ")"
313      "V",
314      reinterpret_cast<void*>(
315          Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceConnected)},
316     {"handleServiceDisconnected",
317      "("
318      "J"
319      ")"
320      "V",
321      reinterpret_cast<void*>(
322          Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceDisconnected)},
323 };
324 
RegisterNativesImpl(JNIEnv * env)325 static bool RegisterNativesImpl(JNIEnv* env) {
326   if (base::android::IsSelectiveJniRegistrationEnabled(env))
327     return true;
328 
329   const int kMethodsNativeCallbacksSize =
330       std::extent<decltype(kMethodsNativeCallbacks)>();
331 
332   if (env->RegisterNatives(NativeCallbacks_clazz(env), kMethodsNativeCallbacks,
333                            kMethodsNativeCallbacksSize) < 0) {
334     jni_generator::HandleRegistrationError(env, NativeCallbacks_clazz(env),
335                                            __FILE__);
336     return false;
337   }
338 
339   return true;
340 }
341 
RegisterNativeCallbacksNatives(JNIEnv * env)342 static bool RegisterNativeCallbacksNatives(JNIEnv* env) {
343   return RegisterNativesImpl(env);
344 }
345 
346 }  // namespace NativeCallbacks
347 
348 #endif  // com_google_vr_internal_controller_NativeCallbacks_JNI
349