native_callbacks_jni.h 8.8 KB

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