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