simpleble 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +88 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +350 -0
  5. data/ext/simpleble/extconf.rb +57 -0
  6. data/ext/simpleble/simpleble_ruby.c +682 -0
  7. data/lib/simpleble/adapter.rb +10 -0
  8. data/lib/simpleble/characteristic.rb +36 -0
  9. data/lib/simpleble/descriptor.rb +8 -0
  10. data/lib/simpleble/exceptions.rb +25 -0
  11. data/lib/simpleble/peripheral.rb +64 -0
  12. data/lib/simpleble/service.rb +16 -0
  13. data/lib/simpleble/version.rb +3 -0
  14. data/lib/simpleble.rb +40 -0
  15. data/vendor/simpleble/build_simplecble/CMakeFiles/4.0.3/CompilerIdCXX/CMakeCXXCompilerId.cpp +920 -0
  16. data/vendor/simpleble/build_simplecble/CMakeFiles/4.0.3/CompilerIdCXX/apple-sdk.cpp +1 -0
  17. data/vendor/simpleble/build_simplecble/CMakeFiles/4.1.0/CompilerIdCXX/CMakeCXXCompilerId.cpp +949 -0
  18. data/vendor/simpleble/build_simplecble/CMakeFiles/4.1.0/CompilerIdCXX/apple-sdk.cpp +1 -0
  19. data/vendor/simpleble/build_simplecble/export/simplecble/export.h +43 -0
  20. data/vendor/simpleble/build_simplecble/simpleble/export/simpleble/export.h +43 -0
  21. data/vendor/simpleble/dependencies/external/kvn/kvn_bytearray.h +222 -0
  22. data/vendor/simpleble/dependencies/external/kvn/kvn_safe_callback.hpp +66 -0
  23. data/vendor/simpleble/dependencies/external/kvn/logfwd.hpp +35 -0
  24. data/vendor/simpleble/dependencies/internal/fmt/args.h +220 -0
  25. data/vendor/simpleble/dependencies/internal/fmt/base.h +2962 -0
  26. data/vendor/simpleble/dependencies/internal/fmt/chrono.h +2338 -0
  27. data/vendor/simpleble/dependencies/internal/fmt/color.h +610 -0
  28. data/vendor/simpleble/dependencies/internal/fmt/compile.h +539 -0
  29. data/vendor/simpleble/dependencies/internal/fmt/core.h +5 -0
  30. data/vendor/simpleble/dependencies/internal/fmt/format-inl.h +1949 -0
  31. data/vendor/simpleble/dependencies/internal/fmt/format.h +4244 -0
  32. data/vendor/simpleble/dependencies/internal/fmt/os.h +427 -0
  33. data/vendor/simpleble/dependencies/internal/fmt/ostream.h +166 -0
  34. data/vendor/simpleble/dependencies/internal/fmt/printf.h +633 -0
  35. data/vendor/simpleble/dependencies/internal/fmt/ranges.h +850 -0
  36. data/vendor/simpleble/dependencies/internal/fmt/std.h +726 -0
  37. data/vendor/simpleble/dependencies/internal/fmt/xchar.h +373 -0
  38. data/vendor/simpleble/dependencies/internal/simplejni/Common.hpp +579 -0
  39. data/vendor/simpleble/dependencies/internal/simplejni/References.hpp +151 -0
  40. data/vendor/simpleble/dependencies/internal/simplejni/Registry.hpp +183 -0
  41. data/vendor/simpleble/dependencies/internal/simplejni/VM.hpp +88 -0
  42. data/vendor/simpleble/examples/simpleble/src/connect.cpp +67 -0
  43. data/vendor/simpleble/examples/simpleble/src/connect_safe.cpp +91 -0
  44. data/vendor/simpleble/examples/simpleble/src/list_adapters.cpp +22 -0
  45. data/vendor/simpleble/examples/simpleble/src/list_adapters_safe.cpp +33 -0
  46. data/vendor/simpleble/examples/simpleble/src/list_paired.cpp +27 -0
  47. data/vendor/simpleble/examples/simpleble/src/multiconnect.cpp +60 -0
  48. data/vendor/simpleble/examples/simpleble/src/notify.cpp +85 -0
  49. data/vendor/simpleble/examples/simpleble/src/notify_multi.cpp +101 -0
  50. data/vendor/simpleble/examples/simpleble/src/power_cycle.cpp +43 -0
  51. data/vendor/simpleble/examples/simpleble/src/read.cpp +82 -0
  52. data/vendor/simpleble/examples/simpleble/src/scan.cpp +62 -0
  53. data/vendor/simpleble/examples/simpleble/src/utils.cpp +59 -0
  54. data/vendor/simpleble/examples/simpleble/src/utils.hpp +27 -0
  55. data/vendor/simpleble/examples/simpleble/src/write.cpp +81 -0
  56. data/vendor/simpleble/examples/simplebluez/ble_nus/ble_nus.cpp +138 -0
  57. data/vendor/simpleble/examples/simplebluez/connect/connect.cpp +119 -0
  58. data/vendor/simpleble/examples/simplebluez/list_adapters/list_adapters.cpp +44 -0
  59. data/vendor/simpleble/examples/simplebluez/list_paired/list_paired.cpp +48 -0
  60. data/vendor/simpleble/examples/simplebluez/notify/notify.cpp +145 -0
  61. data/vendor/simpleble/examples/simplebluez/pair/pair.cpp +181 -0
  62. data/vendor/simpleble/examples/simplebluez/read/read.cpp +141 -0
  63. data/vendor/simpleble/examples/simplebluez/scan/scan.cpp +85 -0
  64. data/vendor/simpleble/examples/simplecble/c/connect.c +163 -0
  65. data/vendor/simpleble/examples/simplecble/c/notify.c +217 -0
  66. data/vendor/simpleble/examples/simplecble/c/scan.c +164 -0
  67. data/vendor/simpleble/examples/simpledbus/notification.cpp +24 -0
  68. data/vendor/simpleble/hitl/src/test_sanity.cpp +48 -0
  69. data/vendor/simpleble/install_simplecble/include/simpleble/Adapter.h +102 -0
  70. data/vendor/simpleble/install_simplecble/include/simpleble/AdapterSafe.h +58 -0
  71. data/vendor/simpleble/install_simplecble/include/simpleble/Advanced.h +50 -0
  72. data/vendor/simpleble/install_simplecble/include/simpleble/Characteristic.h +39 -0
  73. data/vendor/simpleble/install_simplecble/include/simpleble/Config.h +55 -0
  74. data/vendor/simpleble/install_simplecble/include/simpleble/Descriptor.h +30 -0
  75. data/vendor/simpleble/install_simplecble/include/simpleble/Exceptions.h +72 -0
  76. data/vendor/simpleble/install_simplecble/include/simpleble/Logging.h +73 -0
  77. data/vendor/simpleble/install_simplecble/include/simpleble/Peripheral.h +82 -0
  78. data/vendor/simpleble/install_simplecble/include/simpleble/PeripheralSafe.h +64 -0
  79. data/vendor/simpleble/install_simplecble/include/simpleble/Service.h +34 -0
  80. data/vendor/simpleble/install_simplecble/include/simpleble/SimpleBLE.h +8 -0
  81. data/vendor/simpleble/install_simplecble/include/simpleble/Types.h +49 -0
  82. data/vendor/simpleble/install_simplecble/include/simpleble/Utils.h +13 -0
  83. data/vendor/simpleble/install_simplecble/include/simpleble/export.h +43 -0
  84. data/vendor/simpleble/install_simplecble/include/simpleble/kvn/kvn_bytearray.h +222 -0
  85. data/vendor/simpleble/install_simplecble/include/simplecble/adapter.h +188 -0
  86. data/vendor/simpleble/install_simplecble/include/simplecble/logging.h +37 -0
  87. data/vendor/simpleble/install_simplecble/include/simplecble/peripheral.h +304 -0
  88. data/vendor/simpleble/install_simplecble/include/simplecble/simpleble.h +21 -0
  89. data/vendor/simpleble/install_simplecble/include/simplecble/types.h +73 -0
  90. data/vendor/simpleble/install_simplecble/include/simplecble/utils.h +27 -0
  91. data/vendor/simpleble/simpleble/include/simpleble/Adapter.h +102 -0
  92. data/vendor/simpleble/simpleble/include/simpleble/AdapterSafe.h +58 -0
  93. data/vendor/simpleble/simpleble/include/simpleble/Characteristic.h +39 -0
  94. data/vendor/simpleble/simpleble/include/simpleble/Config.h +55 -0
  95. data/vendor/simpleble/simpleble/include/simpleble/Descriptor.h +30 -0
  96. data/vendor/simpleble/simpleble/include/simpleble/Exceptions.h +72 -0
  97. data/vendor/simpleble/simpleble/include/simpleble/Logging.h +73 -0
  98. data/vendor/simpleble/simpleble/include/simpleble/Peripheral.h +82 -0
  99. data/vendor/simpleble/simpleble/include/simpleble/PeripheralSafe.h +64 -0
  100. data/vendor/simpleble/simpleble/include/simpleble/Service.h +34 -0
  101. data/vendor/simpleble/simpleble/include/simpleble/SimpleBLE.h +8 -0
  102. data/vendor/simpleble/simpleble/include/simpleble/Types.h +49 -0
  103. data/vendor/simpleble/simpleble/include/simpleble/Utils.h +13 -0
  104. data/vendor/simpleble/simpleble/include/simpleble_c/adapter.h +188 -0
  105. data/vendor/simpleble/simpleble/include/simpleble_c/logging.h +37 -0
  106. data/vendor/simpleble/simpleble/include/simpleble_c/peripheral.h +304 -0
  107. data/vendor/simpleble/simpleble/include/simpleble_c/simpleble.h +21 -0
  108. data/vendor/simpleble/simpleble/include/simpleble_c/types.h +73 -0
  109. data/vendor/simpleble/simpleble/include/simpleble_c/utils.h +27 -0
  110. data/vendor/simpleble/simpleble/src/CommonUtils.h +63 -0
  111. data/vendor/simpleble/simpleble/src/Exceptions.cpp +31 -0
  112. data/vendor/simpleble/simpleble/src/Logging.cpp +136 -0
  113. data/vendor/simpleble/simpleble/src/LoggingInternal.h +85 -0
  114. data/vendor/simpleble/simpleble/src/Utils.cpp +24 -0
  115. data/vendor/simpleble/simpleble/src/backends/android/AdapterAndroid.cpp +101 -0
  116. data/vendor/simpleble/simpleble/src/backends/android/AdapterAndroid.h +70 -0
  117. data/vendor/simpleble/simpleble/src/backends/android/BackendAndroid.cpp +40 -0
  118. data/vendor/simpleble/simpleble/src/backends/android/BackendAndroid.h +20 -0
  119. data/vendor/simpleble/simpleble/src/backends/android/PeripheralAndroid.cpp +365 -0
  120. data/vendor/simpleble/simpleble/src/backends/android/PeripheralAndroid.h +90 -0
  121. data/vendor/simpleble/simpleble/src/backends/android/bridge/BluetoothGattCallback.cpp +432 -0
  122. data/vendor/simpleble/simpleble/src/backends/android/bridge/BluetoothGattCallback.h +102 -0
  123. data/vendor/simpleble/simpleble/src/backends/android/bridge/ScanCallback.cpp +142 -0
  124. data/vendor/simpleble/simpleble/src/backends/android/bridge/ScanCallback.h +55 -0
  125. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothAdapter.cpp +107 -0
  126. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothAdapter.h +55 -0
  127. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothDevice.cpp +68 -0
  128. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothDevice.h +54 -0
  129. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGatt.cpp +115 -0
  130. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGatt.h +75 -0
  131. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattCharacteristic.cpp +142 -0
  132. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattCharacteristic.h +66 -0
  133. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattDescriptor.cpp +67 -0
  134. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattDescriptor.h +46 -0
  135. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattService.cpp +106 -0
  136. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattService.h +47 -0
  137. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/BluetoothScanner.cpp +47 -0
  138. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/BluetoothScanner.h +37 -0
  139. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanRecord.cpp +69 -0
  140. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanRecord.h +41 -0
  141. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanResult.cpp +63 -0
  142. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanResult.h +42 -0
  143. data/vendor/simpleble/simpleble/src/backends/android/types/android/os/ParcelUUID.cpp +32 -0
  144. data/vendor/simpleble/simpleble/src/backends/android/types/android/os/ParcelUUID.h +30 -0
  145. data/vendor/simpleble/simpleble/src/backends/android/types/android/util/SparseArray.cpp +54 -0
  146. data/vendor/simpleble/simpleble/src/backends/android/types/android/util/SparseArray.h +37 -0
  147. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Iterator.cpp +36 -0
  148. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Iterator.h +28 -0
  149. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/List.cpp +29 -0
  150. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/List.h +27 -0
  151. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Set.cpp +33 -0
  152. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Set.h +28 -0
  153. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/UUID.cpp +26 -0
  154. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/UUID.h +29 -0
  155. data/vendor/simpleble/simpleble/src/backends/common/AdapterBase.cpp +53 -0
  156. data/vendor/simpleble/simpleble/src/backends/common/AdapterBase.h +81 -0
  157. data/vendor/simpleble/simpleble/src/backends/common/AdapterBaseTypes.h +22 -0
  158. data/vendor/simpleble/simpleble/src/backends/common/BackendBase.h +20 -0
  159. data/vendor/simpleble/simpleble/src/backends/common/BackendUtils.h +33 -0
  160. data/vendor/simpleble/simpleble/src/backends/common/CharacteristicBase.cpp +28 -0
  161. data/vendor/simpleble/simpleble/src/backends/common/CharacteristicBase.h +38 -0
  162. data/vendor/simpleble/simpleble/src/backends/common/DescriptorBase.cpp +7 -0
  163. data/vendor/simpleble/simpleble/src/backends/common/DescriptorBase.h +19 -0
  164. data/vendor/simpleble/simpleble/src/backends/common/PeripheralBase.h +82 -0
  165. data/vendor/simpleble/simpleble/src/backends/common/ServiceBase.cpp +18 -0
  166. data/vendor/simpleble/simpleble/src/backends/common/ServiceBase.h +28 -0
  167. data/vendor/simpleble/simpleble/src/backends/linux/AdapterLinux.cpp +102 -0
  168. data/vendor/simpleble/simpleble/src/backends/linux/AdapterLinux.h +55 -0
  169. data/vendor/simpleble/simpleble/src/backends/linux/BackendBluez.cpp +87 -0
  170. data/vendor/simpleble/simpleble/src/backends/linux/PeripheralLinux.cpp +376 -0
  171. data/vendor/simpleble/simpleble/src/backends/linux/PeripheralLinux.h +90 -0
  172. data/vendor/simpleble/simpleble/src/backends/macos/AdapterBaseMacOS.h +29 -0
  173. data/vendor/simpleble/simpleble/src/backends/macos/AdapterMac.h +78 -0
  174. data/vendor/simpleble/simpleble/src/backends/macos/PeripheralBaseMacOS.h +49 -0
  175. data/vendor/simpleble/simpleble/src/backends/macos/PeripheralMac.h +81 -0
  176. data/vendor/simpleble/simpleble/src/backends/macos/Utils.h +9 -0
  177. data/vendor/simpleble/simpleble/src/backends/plain/AdapterPlain.cpp +65 -0
  178. data/vendor/simpleble/simpleble/src/backends/plain/AdapterPlain.h +49 -0
  179. data/vendor/simpleble/simpleble/src/backends/plain/BackendPlain.cpp +30 -0
  180. data/vendor/simpleble/simpleble/src/backends/plain/PeripheralPlain.cpp +159 -0
  181. data/vendor/simpleble/simpleble/src/backends/plain/PeripheralPlain.h +72 -0
  182. data/vendor/simpleble/simpleble/src/backends/windows/AdapterWindows.cpp +330 -0
  183. data/vendor/simpleble/simpleble/src/backends/windows/AdapterWindows.h +89 -0
  184. data/vendor/simpleble/simpleble/src/backends/windows/BackendWinRT.cpp +67 -0
  185. data/vendor/simpleble/simpleble/src/backends/windows/BackendWinRT.h +18 -0
  186. data/vendor/simpleble/simpleble/src/backends/windows/MtaManager.cpp +49 -0
  187. data/vendor/simpleble/simpleble/src/backends/windows/MtaManager.h +90 -0
  188. data/vendor/simpleble/simpleble/src/backends/windows/PeripheralWindows.cpp +487 -0
  189. data/vendor/simpleble/simpleble/src/backends/windows/PeripheralWindows.h +129 -0
  190. data/vendor/simpleble/simpleble/src/backends/windows/Utils.cpp +146 -0
  191. data/vendor/simpleble/simpleble/src/backends/windows/Utils.h +47 -0
  192. data/vendor/simpleble/simpleble/src/builders/BuildVec.h +32 -0
  193. data/vendor/simpleble/simpleble/src/builders/BuilderBase.h +87 -0
  194. data/vendor/simpleble/simpleble/src/external/TaskRunner.hpp +99 -0
  195. data/vendor/simpleble/simpleble/src/external/ThreadRunner.h +52 -0
  196. data/vendor/simpleble/simpleble/src/external/kvn_safe_callback.hpp +66 -0
  197. data/vendor/simpleble/simpleble/src/external/kvn_safe_map.hpp +94 -0
  198. data/vendor/simpleble/simpleble/src/external/kvn_threadrunner.hpp +70 -0
  199. data/vendor/simpleble/simpleble/src/external/logfwd.hpp +35 -0
  200. data/vendor/simpleble/simpleble/src/frontends/base/Adapter.cpp +111 -0
  201. data/vendor/simpleble/simpleble/src/frontends/base/Backend.cpp +83 -0
  202. data/vendor/simpleble/simpleble/src/frontends/base/Backend.h +76 -0
  203. data/vendor/simpleble/simpleble/src/frontends/base/Characteristic.cpp +56 -0
  204. data/vendor/simpleble/simpleble/src/frontends/base/Descriptor.cpp +21 -0
  205. data/vendor/simpleble/simpleble/src/frontends/base/Peripheral.cpp +113 -0
  206. data/vendor/simpleble/simpleble/src/frontends/base/Service.cpp +26 -0
  207. data/vendor/simpleble/simpleble/src/frontends/safe/AdapterSafe.cpp +158 -0
  208. data/vendor/simpleble/simpleble/src/frontends/safe/PeripheralSafe.cpp +219 -0
  209. data/vendor/simpleble/simpleble/src_c/adapter.cpp +204 -0
  210. data/vendor/simpleble/simpleble/src_c/logging.cpp +19 -0
  211. data/vendor/simpleble/simpleble/src_c/peripheral.cpp +444 -0
  212. data/vendor/simpleble/simpleble/src_c/simpleble.cpp +5 -0
  213. data/vendor/simpleble/simpleble/src_c/utils.cpp +15 -0
  214. data/vendor/simpleble/simpleble/test/src/main.cpp +8 -0
  215. data/vendor/simpleble/simpleble/test/src/test_bytearray.cpp +246 -0
  216. data/vendor/simpleble/simpleble/test/src/test_utils.cpp +24 -0
  217. data/vendor/simpleble/simplebluez/include/simplebluez/Adapter.h +46 -0
  218. data/vendor/simpleble/simplebluez/include/simplebluez/Agent.h +52 -0
  219. data/vendor/simpleble/simplebluez/include/simplebluez/Bluez.h +37 -0
  220. data/vendor/simpleble/simplebluez/include/simplebluez/BluezOrg.h +22 -0
  221. data/vendor/simpleble/simplebluez/include/simplebluez/BluezOrgBluez.h +26 -0
  222. data/vendor/simpleble/simplebluez/include/simplebluez/BluezRoot.h +32 -0
  223. data/vendor/simpleble/simplebluez/include/simplebluez/Characteristic.h +46 -0
  224. data/vendor/simpleble/simplebluez/include/simplebluez/Descriptor.h +33 -0
  225. data/vendor/simpleble/simplebluez/include/simplebluez/Device.h +64 -0
  226. data/vendor/simpleble/simplebluez/include/simplebluez/Exceptions.h +43 -0
  227. data/vendor/simpleble/simplebluez/include/simplebluez/Service.h +27 -0
  228. data/vendor/simpleble/simplebluez/include/simplebluez/Types.h +9 -0
  229. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Adapter1.h +49 -0
  230. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Agent1.h +100 -0
  231. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/AgentManager1.h +24 -0
  232. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Battery1.h +32 -0
  233. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Device1.h +62 -0
  234. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattCharacteristic1.h +48 -0
  235. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattDescriptor1.h +41 -0
  236. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattService1.h +28 -0
  237. data/vendor/simpleble/simplebluez/src/Adapter.cpp +78 -0
  238. data/vendor/simpleble/simplebluez/src/Agent.cpp +72 -0
  239. data/vendor/simpleble/simplebluez/src/Bluez.cpp +45 -0
  240. data/vendor/simpleble/simplebluez/src/BluezOrg.cpp +20 -0
  241. data/vendor/simpleble/simplebluez/src/BluezOrgBluez.cpp +23 -0
  242. data/vendor/simpleble/simplebluez/src/BluezRoot.cpp +44 -0
  243. data/vendor/simpleble/simplebluez/src/Characteristic.cpp +64 -0
  244. data/vendor/simpleble/simplebluez/src/Descriptor.cpp +27 -0
  245. data/vendor/simpleble/simplebluez/src/Device.cpp +104 -0
  246. data/vendor/simpleble/simplebluez/src/Exceptions.cpp +29 -0
  247. data/vendor/simpleble/simplebluez/src/Logging.cpp +52 -0
  248. data/vendor/simpleble/simplebluez/src/Logging.h +57 -0
  249. data/vendor/simpleble/simplebluez/src/Service.cpp +33 -0
  250. data/vendor/simpleble/simplebluez/src/interfaces/Adapter1.cpp +123 -0
  251. data/vendor/simpleble/simplebluez/src/interfaces/Agent1.cpp +143 -0
  252. data/vendor/simpleble/simplebluez/src/interfaces/AgentManager1.cpp +34 -0
  253. data/vendor/simpleble/simplebluez/src/interfaces/Battery1.cpp +30 -0
  254. data/vendor/simpleble/simplebluez/src/interfaces/Device1.cpp +170 -0
  255. data/vendor/simpleble/simplebluez/src/interfaces/GattCharacteristic1.cpp +118 -0
  256. data/vendor/simpleble/simplebluez/src/interfaces/GattDescriptor1.cpp +78 -0
  257. data/vendor/simpleble/simplebluez/src/interfaces/GattService1.cpp +28 -0
  258. data/vendor/simpleble/simplebluez/test/src/helpers/PythonRunner.cpp +53 -0
  259. data/vendor/simpleble/simplebluez/test/src/helpers/PythonRunner.h +24 -0
  260. data/vendor/simpleble/simplebluez/test/src/main.cpp +16 -0
  261. data/vendor/simpleble/simplecble/include/simplecble/adapter.h +188 -0
  262. data/vendor/simpleble/simplecble/include/simplecble/logging.h +37 -0
  263. data/vendor/simpleble/simplecble/include/simplecble/peripheral.h +304 -0
  264. data/vendor/simpleble/simplecble/include/simplecble/simpleble.h +21 -0
  265. data/vendor/simpleble/simplecble/include/simplecble/types.h +73 -0
  266. data/vendor/simpleble/simplecble/include/simplecble/utils.h +27 -0
  267. data/vendor/simpleble/simplecble/src/adapter.cpp +204 -0
  268. data/vendor/simpleble/simplecble/src/logging.cpp +19 -0
  269. data/vendor/simpleble/simplecble/src/peripheral.cpp +444 -0
  270. data/vendor/simpleble/simplecble/src/simpleble.cpp +5 -0
  271. data/vendor/simpleble/simplecble/src/utils.cpp +15 -0
  272. data/vendor/simpleble/simpledbus/include/simpledbus/advanced/Interface.h +67 -0
  273. data/vendor/simpleble/simpledbus/include/simpledbus/advanced/InterfaceRegistry.h +64 -0
  274. data/vendor/simpleble/simpledbus/include/simpledbus/advanced/Proxy.h +117 -0
  275. data/vendor/simpleble/simpledbus/include/simpledbus/base/Connection.h +50 -0
  276. data/vendor/simpleble/simpledbus/include/simpledbus/base/Exceptions.h +56 -0
  277. data/vendor/simpleble/simpledbus/include/simpledbus/base/Holder.h +147 -0
  278. data/vendor/simpleble/simpledbus/include/simpledbus/base/Logging.h +57 -0
  279. data/vendor/simpleble/simpledbus/include/simpledbus/base/Message.h +89 -0
  280. data/vendor/simpleble/simpledbus/include/simpledbus/base/Path.h +24 -0
  281. data/vendor/simpleble/simpledbus/include/simpledbus/interfaces/ObjectManager.h +26 -0
  282. data/vendor/simpleble/simpledbus/src/advanced/Interface.cpp +155 -0
  283. data/vendor/simpleble/simpledbus/src/advanced/Proxy.cpp +375 -0
  284. data/vendor/simpleble/simpledbus/src/base/Connection.cpp +222 -0
  285. data/vendor/simpleble/simpledbus/src/base/Exceptions.cpp +39 -0
  286. data/vendor/simpleble/simpledbus/src/base/Holder.cpp +739 -0
  287. data/vendor/simpleble/simpledbus/src/base/Logging.cpp +52 -0
  288. data/vendor/simpleble/simpledbus/src/base/Message.cpp +622 -0
  289. data/vendor/simpleble/simpledbus/src/base/Path.cpp +129 -0
  290. data/vendor/simpleble/simpledbus/src/interfaces/ObjectManager.cpp +58 -0
  291. data/vendor/simpleble/simpledbus/test/src/helpers/PythonRunner.cpp +53 -0
  292. data/vendor/simpleble/simpledbus/test/src/helpers/PythonRunner.h +24 -0
  293. data/vendor/simpleble/simpledbus/test/src/main.cpp +16 -0
  294. data/vendor/simpleble/simpledbus/test/src/test_holder.cpp +184 -0
  295. data/vendor/simpleble/simpledbus/test/src/test_message.cpp +397 -0
  296. data/vendor/simpleble/simpledbus/test/src/test_path.cpp +76 -0
  297. data/vendor/simpleble/simpledbus/test/src/test_proxy_children.cpp +109 -0
  298. data/vendor/simpleble/simpledbus/test/src/test_proxy_interfaces.cpp +102 -0
  299. data/vendor/simpleble/simpledbus/test/src/test_proxy_lifetime.cpp +18 -0
  300. data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/ThreadRunner.h +89 -0
  301. data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/android_utils.cpp +55 -0
  302. data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/android_utils.h +18 -0
  303. data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/simpleble_android.cpp +813 -0
  304. data/vendor/simpleble/simplejavable/cpp/src/core/AdapterWrapper.cpp +37 -0
  305. data/vendor/simpleble/simplejavable/cpp/src/core/AdapterWrapper.h +23 -0
  306. data/vendor/simpleble/simplejavable/cpp/src/core/Cache.cpp +58 -0
  307. data/vendor/simpleble/simplejavable/cpp/src/core/Cache.h +34 -0
  308. data/vendor/simpleble/simplejavable/cpp/src/core/PeripheralWrapper.cpp +17 -0
  309. data/vendor/simpleble/simplejavable/cpp/src/core/PeripheralWrapper.h +19 -0
  310. data/vendor/simpleble/simplejavable/cpp/src/java/lang/ArrayList.cpp +257 -0
  311. data/vendor/simpleble/simplejavable/cpp/src/java/lang/ArrayList.h +78 -0
  312. data/vendor/simpleble/simplejavable/cpp/src/java/lang/HashMap.cpp +96 -0
  313. data/vendor/simpleble/simplejavable/cpp/src/java/lang/HashMap.h +54 -0
  314. data/vendor/simpleble/simplejavable/cpp/src/java/lang/Integer.cpp +93 -0
  315. data/vendor/simpleble/simplejavable/cpp/src/java/lang/Integer.h +49 -0
  316. data/vendor/simpleble/simplejavable/cpp/src/java/lang/Iterator.cpp +85 -0
  317. data/vendor/simpleble/simplejavable/cpp/src/java/lang/Iterator.h +48 -0
  318. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/AdapterCallback.cpp +91 -0
  319. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/AdapterCallback.h +90 -0
  320. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Characteristic.cpp +35 -0
  321. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Characteristic.h +60 -0
  322. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/DataCallback.cpp +33 -0
  323. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/DataCallback.h +45 -0
  324. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Descriptor.cpp +30 -0
  325. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Descriptor.h +49 -0
  326. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/PeripheralCallback.cpp +41 -0
  327. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/PeripheralCallback.h +51 -0
  328. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Service.cpp +33 -0
  329. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Service.h +54 -0
  330. data/vendor/simpleble/simplejavable/cpp/src/simplejavable.cpp +361 -0
  331. data/vendor/simpleble/simplepyble/src/main.cpp +55 -0
  332. data/vendor/simpleble/simplepyble/src/wrap_adapter.cpp +106 -0
  333. data/vendor/simpleble/simplepyble/src/wrap_characteristic.cpp +56 -0
  334. data/vendor/simpleble/simplepyble/src/wrap_config.cpp +136 -0
  335. data/vendor/simpleble/simplepyble/src/wrap_descriptor.cpp +21 -0
  336. data/vendor/simpleble/simplepyble/src/wrap_peripheral.cpp +217 -0
  337. data/vendor/simpleble/simplepyble/src/wrap_service.cpp +32 -0
  338. data/vendor/simpleble/simplepyble/src/wrap_types.cpp +21 -0
  339. data/vendor/simpleble/simplersble/src/bindings/Bindings.cpp +338 -0
  340. data/vendor/simpleble/simplersble/src/bindings/Bindings.hpp +178 -0
  341. metadata +430 -0
@@ -0,0 +1,579 @@
1
+ #pragma once
2
+
3
+ #include <jni.h>
4
+ #include <condition_variable>
5
+ #include <cstdint>
6
+ #include <functional>
7
+ #include <mutex>
8
+ #include <queue>
9
+ #include <string>
10
+ #include <thread>
11
+ #include <type_traits>
12
+ #include <vector>
13
+
14
+ #include "References.hpp"
15
+ #include "VM.hpp"
16
+ #include "kvn/kvn_bytearray.h"
17
+
18
+ namespace SimpleJNI {
19
+
20
+ // TODO: Implement a base class that handles common functionality of complicated Objects (see the ones in
21
+ // org/simplejavable)
22
+
23
+ class Exception : public std::runtime_error {
24
+ public:
25
+ Exception(jthrowable obj) : std::runtime_error("Java Exception"), _ref(), _cls() {
26
+ _ref = LocalRef<jthrowable>(obj);
27
+
28
+ JNIEnv* env = SimpleJNI::VM::env();
29
+ _cls = LocalRef<jclass>(env->GetObjectClass(_ref.get()));
30
+
31
+ jmethodID method_get_name = env->GetMethodID(_cls.get(), "getName", "()Ljava/lang/String;");
32
+ jmethodID method_get_message = env->GetMethodID(_cls.get(), "getMessage", "()Ljava/lang/String;");
33
+
34
+ std::string exception_name = call_string_method(env, _ref.get(), method_get_name);
35
+ std::string exception_message = call_string_method(env, _ref.get(), method_get_message);
36
+
37
+ _what = "Java Exception: " + exception_name + ": " + exception_message;
38
+ }
39
+
40
+ const char* what() const noexcept override { return _what.c_str(); }
41
+
42
+ private:
43
+ std::string _what;
44
+ LocalRef<jthrowable> _ref;
45
+ LocalRef<jclass> _cls;
46
+
47
+ static std::string call_string_method(JNIEnv* env, jthrowable obj, jmethodID method) {
48
+ auto jstr = static_cast<jstring>(env->CallObjectMethod(obj, method));
49
+ if (!jstr) return "";
50
+ const char* c_str = env->GetStringUTFChars(jstr, nullptr);
51
+ std::string result(c_str);
52
+ env->ReleaseStringUTFChars(jstr, c_str);
53
+ return result;
54
+ }
55
+ };
56
+
57
+ template <template <typename> class RefType, typename JniType = jobject>
58
+ class Object {
59
+ public:
60
+ Object() = default;
61
+
62
+ explicit Object(JniType obj) : _ref(obj) {
63
+ if (obj) {
64
+ JNIEnv* env = VM::env();
65
+ _cls = RefType<jclass>(env->GetObjectClass(_ref.get()));
66
+ }
67
+ }
68
+
69
+ // Constructor with pre-fetched jclass
70
+ Object(JniType obj, jclass cls) : _ref(obj), _cls(cls) {}
71
+
72
+ // Move semantics
73
+ Object(Object&& other) noexcept : _ref(std::move(other._ref)), _cls(std::move(other._cls)) {}
74
+ Object& operator=(Object&& other) noexcept {
75
+ if (this != &other) {
76
+ _ref = std::move(other._ref);
77
+ _cls = std::move(other._cls);
78
+ }
79
+ return *this;
80
+ }
81
+
82
+ // Copying depends on RefType's behavior (enabled by default)
83
+ Object(const Object&) = default;
84
+ Object& operator=(const Object&) = default;
85
+
86
+ // Template constructor for converting between different RefType templates
87
+ template <template <typename> class OtherRefType>
88
+ Object(const Object<OtherRefType, JniType>& other) {
89
+ if (other.get()) {
90
+ JNIEnv* env = VM::env();
91
+ _ref = RefType<JniType>(other.get());
92
+ _cls = RefType<jclass>(env->GetObjectClass(_ref.get()));
93
+ }
94
+ }
95
+
96
+ // Template assignment operator for converting between different RefType templates
97
+ template <template <typename> class OtherRefType>
98
+ Object& operator=(const Object<OtherRefType, JniType>& other) {
99
+ // Don't use pointer comparison for different template types
100
+ // Instead, check if the underlying JNI objects are the same
101
+ JNIEnv* env = VM::env();
102
+
103
+ // Only proceed with assignment if the objects are different
104
+ // or if other is null (in which case we reset this object)
105
+ if (!other.get() || !_ref.get() || !env->IsSameObject(_ref.get(), other.get())) {
106
+ if (other.get()) {
107
+ _ref = RefType<JniType>(other.get());
108
+ _cls = RefType<jclass>(env->GetObjectClass(_ref.get()));
109
+ } else {
110
+ _ref = RefType<JniType>();
111
+ _cls = RefType<jclass>();
112
+ }
113
+ }
114
+ return *this;
115
+ }
116
+
117
+ // Conversion methods
118
+ Object<LocalRef, JniType> to_local() const {
119
+ if (!*this) return Object<LocalRef, JniType>();
120
+ JNIEnv* env = VM::env();
121
+ return Object<LocalRef, JniType>(_ref.get(), _cls.get());
122
+ }
123
+
124
+ Object<GlobalRef, JniType> to_global() const {
125
+ if (!*this) return Object<GlobalRef, JniType>();
126
+ JNIEnv* env = VM::env();
127
+ return Object<GlobalRef, JniType>(_ref.get(), _cls.get());
128
+ }
129
+
130
+ Object<WeakRef, jweak> to_weak() const {
131
+ if (!*this) return Object<WeakRef, jweak>();
132
+ JNIEnv* env = VM::env();
133
+ return Object<WeakRef, jweak>(WeakRef<jweak>(_ref.get()));
134
+ }
135
+
136
+ // Access raw jobject
137
+ JniType get() const { return _ref.get(); }
138
+
139
+ // Release ownership of the underlying reference
140
+ JniType release() noexcept { return _ref.release(); }
141
+
142
+ explicit operator bool() const { return _ref.get() != nullptr; }
143
+
144
+ bool is_valid() const { return _ref.is_valid(); }
145
+
146
+ jmethodID get_method(const char* name, const char* signature) const {
147
+ JNIEnv* env = VM::env();
148
+ jmethodID method = env->GetMethodID(_cls.get(), name, signature);
149
+ check_exception(env);
150
+ return method;
151
+ }
152
+
153
+ template <typename... Args>
154
+ Object<LocalRef, JniType> call_object_method(jmethodID method, Args&&... args) const {
155
+ JNIEnv* env = VM::env();
156
+ JniType result = env->CallObjectMethod(_ref.get(), method, std::forward<Args>(args)...);
157
+ check_exception(env);
158
+ return Object<LocalRef, JniType>(result);
159
+ }
160
+
161
+ template <typename... Args>
162
+ void call_void_method(jmethodID method, Args&&... args) const {
163
+ JNIEnv* env = VM::env();
164
+ env->CallVoidMethod(_ref.get(), method, std::forward<Args>(args)...);
165
+ check_exception(env);
166
+ }
167
+
168
+ template <typename... Args>
169
+ bool call_boolean_method(jmethodID method, Args&&... args) const {
170
+ JNIEnv* env = VM::env();
171
+ bool result = env->CallBooleanMethod(_ref.get(), method, std::forward<Args>(args)...);
172
+ check_exception(env);
173
+ return result;
174
+ }
175
+
176
+ template <typename... Args>
177
+ int call_int_method(jmethodID method, Args&&... args) const {
178
+ JNIEnv* env = VM::env();
179
+ int result = env->CallIntMethod(_ref.get(), method, std::forward<Args>(args)...);
180
+ check_exception(env);
181
+ return result;
182
+ }
183
+
184
+ template <typename... Args>
185
+ std::string call_string_method(jmethodID method, Args&&... args) const {
186
+ JNIEnv* env = VM::env();
187
+ auto jstr = static_cast<jstring>(env->CallObjectMethod(_ref.get(), method, std::forward<Args>(args)...));
188
+ if (!jstr) return "";
189
+ const char* c_str = env->GetStringUTFChars(jstr, nullptr);
190
+ std::string result(c_str);
191
+ env->ReleaseStringUTFChars(jstr, c_str);
192
+ return result;
193
+ }
194
+
195
+ template <typename... Args>
196
+ kvn::bytearray call_byte_array_method(jmethodID method, Args&&... args) const {
197
+ JNIEnv* env = VM::env();
198
+ auto jarr = static_cast<jbyteArray>(env->CallObjectMethod(_ref.get(), method, std::forward<Args>(args)...));
199
+ check_exception(env);
200
+ if (!jarr) return {};
201
+ jsize len = env->GetArrayLength(jarr);
202
+ jbyte* arr = env->GetByteArrayElements(jarr, nullptr);
203
+ kvn::bytearray result(arr, arr + len);
204
+ env->ReleaseByteArrayElements(jarr, arr, JNI_ABORT);
205
+ return result;
206
+ }
207
+
208
+ template <typename... Args>
209
+ static Object<LocalRef, JniType> call_new_object(jclass cls, jmethodID method, Args&&... args) {
210
+ JNIEnv* env = VM::env();
211
+ JniType result = env->NewObject(cls, method, std::forward<Args>(args)...);
212
+ check_exception(env);
213
+ return Object<LocalRef, JniType>(result);
214
+ }
215
+
216
+ static void check_exception(JNIEnv* env) {
217
+ if (env->ExceptionCheck()) {
218
+ Object<LocalRef, jthrowable> exception(env->ExceptionOccurred());
219
+ env->ExceptionClear();
220
+ throw Exception(exception.get());
221
+ }
222
+ }
223
+
224
+ protected:
225
+ RefType<JniType> _ref; // Holds LocalRef<JniType> or GlobalRef<JniType>
226
+ RefType<jclass> _cls; // Holds LocalRef<jclass> or GlobalRef<jclass>
227
+ };
228
+
229
+ template <template <typename> class RefType>
230
+ class ByteArray : public Object<RefType, jbyteArray> {
231
+ public:
232
+ ByteArray() = default;
233
+
234
+ // NOTE: The user is responsible for ensuring that the jobject is a jbyteArray
235
+ explicit ByteArray(jobject obj) : Object<RefType, jbyteArray>(static_cast<jbyteArray>(obj)) {}
236
+
237
+ explicit ByteArray(jbyteArray obj) : Object<RefType, jbyteArray>(obj) {}
238
+
239
+ ByteArray(const kvn::bytearray& data) : Object<RefType, jbyteArray>() {
240
+ JNIEnv* env = VM::env();
241
+ jbyteArray jarr = env->NewByteArray(data.size());
242
+ env->SetByteArrayRegion(jarr, 0, data.size(), reinterpret_cast<const jbyte*>(data.data()));
243
+
244
+ this->_ref = RefType<jbyteArray>(jarr);
245
+ this->_cls = RefType<jclass>(env->FindClass("java/lang/Object"));
246
+ }
247
+
248
+ template <template <typename> class OtherRefType>
249
+ ByteArray(const Object<OtherRefType, jbyteArray>& obj) : Object<RefType, jbyteArray>(obj.get()) {}
250
+
251
+ // Add implicit conversion to Object<RefType, jobject>
252
+ operator Object<RefType, jobject>() const {
253
+ return Object<RefType, jobject>(static_cast<jobject>(this->get()), this->_cls.get());
254
+ }
255
+
256
+ // Conversion methods
257
+ ByteArray<LocalRef> to_local() const {
258
+ if (!*this) return ByteArray<LocalRef>();
259
+ return ByteArray<LocalRef>(this->get());
260
+ }
261
+
262
+ ByteArray<GlobalRef> to_global() const {
263
+ if (!*this) return ByteArray<GlobalRef>();
264
+ return ByteArray<GlobalRef>(this->get());
265
+ }
266
+
267
+ // Get the raw byte array data
268
+ kvn::bytearray bytes() const {
269
+ JNIEnv* env = VM::env();
270
+ jbyteArray jarr = this->get();
271
+
272
+ if (jarr == nullptr) {
273
+ return {};
274
+ }
275
+
276
+ jsize len = env->GetArrayLength(jarr);
277
+ kvn::bytearray result(len);
278
+
279
+ env->GetByteArrayRegion(jarr, 0, len, reinterpret_cast<jbyte*>(result.data()));
280
+
281
+ return result;
282
+ }
283
+
284
+ // Get the length of the byte array
285
+ size_t length() const {
286
+ JNIEnv* env = VM::env();
287
+ return env->GetArrayLength(this->get());
288
+ }
289
+ };
290
+
291
+ template <template <typename> class RefType>
292
+ class LongArray : public Object<RefType, jlongArray> {
293
+ public:
294
+ LongArray() = default;
295
+
296
+ explicit LongArray(jlongArray obj) : Object<RefType, jlongArray>(obj) {}
297
+
298
+ LongArray(const std::vector<int64_t>& data) : Object<RefType, jlongArray>() {
299
+ JNIEnv* env = VM::env();
300
+ jlongArray jarr = env->NewLongArray(data.size());
301
+ env->SetLongArrayRegion(jarr, 0, data.size(), reinterpret_cast<const jlong*>(data.data()));
302
+
303
+ this->_ref = RefType<jlongArray>(jarr);
304
+ this->_cls = RefType<jclass>(env->FindClass("java/lang/Object"));
305
+ }
306
+
307
+ template <template <typename> class OtherRefType>
308
+ LongArray(const Object<OtherRefType, jlongArray>& obj) : Object<RefType, jlongArray>(obj.get()) {}
309
+
310
+ // Add implicit conversion to Object<RefType, jobject>
311
+ operator Object<RefType, jobject>() const {
312
+ return Object<RefType, jobject>(static_cast<jobject>(this->get()), this->_cls.get());
313
+ }
314
+
315
+ // Conversion methods
316
+ LongArray<LocalRef> to_local() const {
317
+ if (!*this) return LongArray<LocalRef>();
318
+ return LongArray<LocalRef>(this->get());
319
+ }
320
+
321
+ LongArray<GlobalRef> to_global() const {
322
+ if (!*this) return LongArray<GlobalRef>();
323
+ return LongArray<GlobalRef>(this->get());
324
+ }
325
+
326
+ // Get the raw long array data
327
+ std::vector<int64_t> longs() const {
328
+ JNIEnv* env = VM::env();
329
+ jlongArray jarr = this->get();
330
+
331
+ if (jarr == nullptr) {
332
+ return {};
333
+ }
334
+
335
+ jsize len = env->GetArrayLength(jarr);
336
+ std::vector<int64_t> result(len);
337
+
338
+ env->GetLongArrayRegion(jarr, 0, len, reinterpret_cast<jlong*>(result.data()));
339
+
340
+ return result;
341
+ }
342
+
343
+ // Get the length of the long array
344
+ size_t length() const {
345
+ JNIEnv* env = VM::env();
346
+ jlongArray jarr = this->get();
347
+
348
+ if (jarr == nullptr) {
349
+ return 0; // Return 0 for null arrays
350
+ }
351
+
352
+ return env->GetArrayLength(jarr);
353
+ }
354
+ };
355
+
356
+ template <template <typename> class RefType>
357
+ class String : public Object<RefType, jstring> {
358
+ public:
359
+ String() = default;
360
+
361
+ explicit String(jstring obj) : Object<RefType, jstring>(obj) {}
362
+
363
+ String(const std::string& data) : Object<RefType, jstring>() {
364
+ JNIEnv* env = VM::env();
365
+ jstring jstr = env->NewStringUTF(data.c_str());
366
+
367
+ this->_ref = RefType<jstring>(jstr);
368
+ this->_cls = RefType<jclass>(env->FindClass("java/lang/Object"));
369
+ }
370
+
371
+ template <template <typename> class OtherRefType>
372
+ String(const Object<OtherRefType, jstring>& obj) : Object<RefType, jstring>(obj.get()) {}
373
+
374
+ // Add implicit conversion to Object<RefType, jobject>
375
+ operator Object<RefType, jobject>() const {
376
+ return Object<RefType, jobject>(static_cast<jobject>(this->get()), this->_cls.get());
377
+ }
378
+
379
+ // Conversion methods
380
+ String<LocalRef> to_local() const {
381
+ if (!*this) return String<LocalRef>();
382
+ return String<LocalRef>(this->get());
383
+ }
384
+
385
+ String<GlobalRef> to_global() const {
386
+ if (!*this) return String<GlobalRef>();
387
+ return String<GlobalRef>(this->get());
388
+ }
389
+
390
+ // Get the raw string data
391
+ std::string str() const {
392
+ JNIEnv* env = VM::env();
393
+ jstring jstr = this->get();
394
+
395
+ if (jstr == nullptr) {
396
+ return {};
397
+ }
398
+
399
+ const char* c_str = env->GetStringUTFChars(jstr, nullptr);
400
+ std::string result(c_str);
401
+ env->ReleaseStringUTFChars(jstr, c_str);
402
+
403
+ return result;
404
+ }
405
+
406
+ // Get the length of the string
407
+ size_t length() const {
408
+ JNIEnv* env = VM::env();
409
+ return env->GetStringUTFLength(this->get());
410
+ }
411
+ };
412
+
413
+ class Env {
414
+ public:
415
+ Env() { _env = VM::env(); }
416
+ virtual ~Env() = default;
417
+ Env(Env& other) = delete; // Remove the copy constructor
418
+ void operator=(const Env&) = delete; // Remove the copy assignment
419
+
420
+ JNIEnv* operator->() { return _env; }
421
+
422
+ operator JNIEnv*() { return _env; }
423
+
424
+ // Class find_class(const std::string& name) {
425
+ // jclass jcls = _env->FindClass(name.c_str());
426
+ // if (jcls == nullptr) {
427
+ // throw std::runtime_error("Failed to find class: " + name);
428
+ // }
429
+ // Class cls(jcls);
430
+ // _env->DeleteLocalRef(jcls);
431
+ // return cls;
432
+ // }
433
+
434
+ private:
435
+ JNIEnv* _env = nullptr;
436
+ };
437
+
438
+ class Runner {
439
+ public:
440
+ // Delete copy constructor and assignment
441
+ Runner(const Runner&) = delete;
442
+ Runner& operator=(const Runner&) = delete;
443
+
444
+ static Runner& get() {
445
+ static Runner instance;
446
+ return instance;
447
+ }
448
+
449
+ virtual ~Runner() {
450
+ {
451
+ std::unique_lock<std::mutex> lock(_mutex);
452
+ _stop = true;
453
+ _cv.notify_one();
454
+ }
455
+ _thread.join();
456
+ }
457
+
458
+ void enqueue(std::function<void()> func) {
459
+ {
460
+ std::unique_lock<std::mutex> lock(_mutex);
461
+ _queue.push(std::move(func));
462
+ lock.unlock();
463
+ _cv.notify_one();
464
+ }
465
+ }
466
+
467
+ protected:
468
+ void thread_func() {
469
+ VM::attach();
470
+ while (true) {
471
+ std::function<void()> func;
472
+ {
473
+ std::unique_lock<std::mutex> lock(_mutex);
474
+ _cv.wait(lock, [this] { return _stop || !_queue.empty(); });
475
+ if (_stop && _queue.empty()) {
476
+ break;
477
+ }
478
+ func = std::move(_queue.front());
479
+ _queue.pop();
480
+ }
481
+ func();
482
+ }
483
+ VM::detach();
484
+ }
485
+
486
+ private:
487
+ // Move constructor to private
488
+ Runner() : _stop(false) { _thread = std::thread(&Runner::thread_func, this); }
489
+
490
+ std::thread _thread;
491
+ std::mutex _mutex;
492
+ std::condition_variable _cv;
493
+ std::queue<std::function<void()>> _queue;
494
+ bool _stop;
495
+ };
496
+
497
+ // // TODO: Move these to their own namespace
498
+
499
+ // struct JObjectComparator {
500
+ // // TODO: Lazy initialize jclass and jmethodID objects.
501
+
502
+ // bool operator()(const jobject& lhs, const jobject& rhs) const {
503
+ // if (lhs == nullptr && rhs == nullptr) {
504
+ // return false; // Both are null, considered equal
505
+ // }
506
+ // if (lhs == nullptr) {
507
+ // return true; // lhs is null, rhs is not null, lhs < rhs
508
+ // }
509
+ // if (rhs == nullptr) {
510
+ // return false; // rhs is null, lhs is not null, lhs > rhs
511
+ // }
512
+
513
+ // JNIEnv* env = VM::env();
514
+ // if (env->IsSameObject(lhs, rhs)) {
515
+ // return false; // Both objects are the same
516
+ // }
517
+
518
+ // // Use hashCode method to establish a consistent ordering
519
+ // // TODO: Cache all references statically for this class!
520
+ // jclass objectClass = env->FindClass("java/lang/Object");
521
+ // jmethodID hashCodeMethod = env->GetMethodID(objectClass, "hashCode", "()I");
522
+
523
+ // const jobject lhsObject = lhs;
524
+ // const jobject rhsObject = rhs;
525
+
526
+ // jint lhsHashCode = env->CallIntMethod(lhsObject, hashCodeMethod);
527
+ // jint rhsHashCode = env->CallIntMethod(rhsObject, hashCodeMethod);
528
+
529
+ // return lhsHashCode < rhsHashCode;
530
+
531
+ // // Use a unique identifier or a pointer value as the final comparison for non-equal objects
532
+ // return lhs < rhs; // This can still be used for consistent ordering
533
+ // }
534
+ // };
535
+
536
+ template <template <typename> class RefType, typename JniType = jobject>
537
+ struct ObjectComparator {
538
+ // TODO: Use the Registry to get the jclass and jmethodID objects.
539
+ // TODO: Move to a separate file.
540
+
541
+ bool operator()(const Object<RefType, JniType>& lhs, const Object<RefType, JniType>& rhs) const {
542
+ // Handle null object comparisons
543
+ if (!lhs && !rhs) {
544
+ return false; // Both are null, considered equal
545
+ }
546
+ if (!lhs) {
547
+ return true; // lhs is null, rhs is not, lhs < rhs
548
+ }
549
+ if (!rhs) {
550
+ return false; // rhs is null, lhs is not, lhs > rhs
551
+ }
552
+
553
+ JNIEnv* env = VM::env();
554
+
555
+ // Access the underlying jobject handles from Object instances
556
+ JniType lhsObject = lhs.get();
557
+ JniType rhsObject = rhs.get();
558
+
559
+ // Check if both jobject handles refer to the same object
560
+ if (env->IsSameObject(lhsObject, rhsObject)) {
561
+ return false; // Both objects are the same
562
+ }
563
+
564
+ // Use hashCode method to establish a consistent ordering
565
+ jclass objectClass = env->FindClass("java/lang/Object");
566
+ jmethodID hashCodeMethod = env->GetMethodID(objectClass, "hashCode", "()I");
567
+
568
+ jint lhsHashCode = env->CallIntMethod(lhsObject, hashCodeMethod);
569
+ jint rhsHashCode = env->CallIntMethod(rhsObject, hashCodeMethod);
570
+
571
+ if (lhsHashCode != rhsHashCode) {
572
+ return lhsHashCode < rhsHashCode; // Use hash code for initial comparison
573
+ }
574
+
575
+ // Use a direct pointer comparison as a fallback for objects with identical hash codes
576
+ return lhsObject < rhsObject; // This comparison is consistent within the same execution
577
+ }
578
+ };
579
+ } // namespace SimpleJNI