1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This file is of the same format as file that generated by
6 // third_party/jni_zero/jni_zero.py
8 // com/google/vr/internal/controller/NativeCallbacks
10 // Local modification includes:
11 // 1. Remove all implementation, 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 // 7. Added "vr" as an argument to base::android::LazyGetClass.
22 #ifndef com_google_vr_internal_controller_NativeCallbacks_JNI
23 #define com_google_vr_internal_controller_NativeCallbacks_JNI
25 #include "base/android/jni_android.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
31 #include <type_traits>
33 #include "third_party/jni_zero/jni_int_wrapper.h"
34 #include "third_party/jni_zero/jni_zero_helper.h"
36 // Step 1: forward declarations.
38 const char kNativeCallbacksClassPath[] =
39 "com/google/vr/internal/controller/NativeCallbacks";
40 // Leaking this jclass as we cannot use LazyInstance from some threads.
41 std::atomic<jclass> g_NativeCallbacks_clazz __attribute__((unused)) (nullptr);
42 #define NativeCallbacks_clazz(env) \
43 base::android::LazyGetClass(env, kNativeCallbacksClassPath, "vr", \
44 &g_NativeCallbacks_clazz)
48 namespace NativeCallbacks {
49 // Step 2: method stubs.
51 JNI_BOUNDARY_EXPORT void
52 Java_com_google_vr_internal_controller_NativeCallbacks_handleStateChanged(
59 JNI_BOUNDARY_EXPORT void
60 Java_com_google_vr_internal_controller_NativeCallbacks_handleControllerRecentered(
71 JNI_BOUNDARY_EXPORT void
72 Java_com_google_vr_internal_controller_NativeCallbacks_handleTouchEvent(
82 JNI_BOUNDARY_EXPORT void
83 Java_com_google_vr_internal_controller_NativeCallbacks_handleOrientationEvent(
94 JNI_BOUNDARY_EXPORT void
95 Java_com_google_vr_internal_controller_NativeCallbacks_handleButtonEvent(
100 jlong timestampNanos,
104 JNI_BOUNDARY_EXPORT void
105 Java_com_google_vr_internal_controller_NativeCallbacks_handleAccelEvent(
109 jint controllerIndex,
110 jlong timestampNanos,
115 JNI_BOUNDARY_EXPORT void
116 Java_com_google_vr_internal_controller_NativeCallbacks_handleGyroEvent(
120 jint controllerIndex,
121 jlong timestampNanos,
126 JNI_BOUNDARY_EXPORT void
127 Java_com_google_vr_internal_controller_NativeCallbacks_handlePositionEvent(
131 jint controllerIndex,
132 jlong timestampNanos,
137 JNI_BOUNDARY_EXPORT void
138 Java_com_google_vr_internal_controller_NativeCallbacks_handleBatteryEvent(
142 jint controllerIndex,
143 jlong timestampNanos,
145 jint batteryLevelBucket);
147 JNI_BOUNDARY_EXPORT void
148 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceInitFailed(
154 JNI_BOUNDARY_EXPORT void
155 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceFailed(
160 JNI_BOUNDARY_EXPORT void
161 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceUnavailable(
166 JNI_BOUNDARY_EXPORT void
167 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceConnected(
173 JNI_BOUNDARY_EXPORT void
174 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceDisconnected(
179 // Step 3: RegisterNatives.
181 static const JNINativeMethod kMethodsNativeCallbacks[] = {
182 {"handleStateChanged",
189 reinterpret_cast<void*>(
190 Java_com_google_vr_internal_controller_NativeCallbacks_handleStateChanged)},
191 {"handleControllerRecentered",
202 reinterpret_cast<void*>(
203 Java_com_google_vr_internal_controller_NativeCallbacks_handleControllerRecentered)},
214 reinterpret_cast<void*>(
215 Java_com_google_vr_internal_controller_NativeCallbacks_handleTouchEvent)},
216 {"handleOrientationEvent",
227 reinterpret_cast<void*>(
228 Java_com_google_vr_internal_controller_NativeCallbacks_handleOrientationEvent)},
229 {"handleButtonEvent",
238 reinterpret_cast<void*>(
239 Java_com_google_vr_internal_controller_NativeCallbacks_handleButtonEvent)},
250 reinterpret_cast<void*>(
251 Java_com_google_vr_internal_controller_NativeCallbacks_handleAccelEvent)},
262 reinterpret_cast<void*>(
263 Java_com_google_vr_internal_controller_NativeCallbacks_handleGyroEvent)},
264 {"handlePositionEvent",
274 reinterpret_cast<void*>(
275 Java_com_google_vr_internal_controller_NativeCallbacks_handlePositionEvent)},
276 {"handleBatteryEvent",
285 reinterpret_cast<void*>(
286 Java_com_google_vr_internal_controller_NativeCallbacks_handleBatteryEvent)},
287 {"handleServiceInitFailed",
293 reinterpret_cast<void*>(
294 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceInitFailed)},
295 {"handleServiceFailed",
300 reinterpret_cast<void*>(
301 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceFailed)},
302 {"handleServiceUnavailable",
307 reinterpret_cast<void*>(
308 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceUnavailable)},
309 {"handleServiceConnected",
315 reinterpret_cast<void*>(
316 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceConnected)},
317 {"handleServiceDisconnected",
322 reinterpret_cast<void*>(
323 Java_com_google_vr_internal_controller_NativeCallbacks_handleServiceDisconnected)},
326 static bool RegisterNativesImpl(JNIEnv* env) {
327 const int kMethodsNativeCallbacksSize =
328 std::extent<decltype(kMethodsNativeCallbacks)>();
330 if (env->RegisterNatives(NativeCallbacks_clazz(env), kMethodsNativeCallbacks,
331 kMethodsNativeCallbacksSize) < 0) {
332 jni_generator::HandleRegistrationError(env, NativeCallbacks_clazz(env),
340 static bool RegisterNativeCallbacksNatives(JNIEnv* env) {
341 return RegisterNativesImpl(env);
344 } // namespace NativeCallbacks
346 #endif // com_google_vr_internal_controller_NativeCallbacks_JNI