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,330 @@
1
+ // This weird pragma is required for the compiler to properly include the necessary namespaces.
2
+ #pragma comment(lib, "windowsapp")
3
+ #include "AdapterWindows.h"
4
+ #include "BackendWinRT.h"
5
+
6
+ #include "BuilderBase.h"
7
+ #include "CommonUtils.h"
8
+ #include "LoggingInternal.h"
9
+ #include "PeripheralWindows.h"
10
+ #include "Utils.h"
11
+ #include "MtaManager.h"
12
+
13
+ #include "winrt/Windows.Devices.Bluetooth.h"
14
+ #include "winrt/Windows.Devices.Radios.h"
15
+ #include "winrt/Windows.Devices.Enumeration.h"
16
+ #include "winrt/Windows.Foundation.Collections.h"
17
+ #include "winrt/Windows.Foundation.h"
18
+ #include "winrt/base.h"
19
+
20
+ #include <algorithm>
21
+ #include <iostream>
22
+ #include <iterator>
23
+ #include <memory>
24
+ #include <sstream>
25
+ #include <string>
26
+ #include <utility>
27
+ #include <vector>
28
+
29
+ using namespace SimpleBLE;
30
+ using namespace SimpleBLE::WinRT;
31
+ using namespace std::chrono_literals;
32
+
33
+ AdapterWindows::AdapterWindows(std::string device_id)
34
+ : adapter_(async_get(BluetoothAdapter::FromIdAsync(winrt::to_hstring(device_id)))),
35
+ radio_(async_get(adapter_.GetRadioAsync())) {
36
+ // IMPORTANT NOTE: This function must be executed in the MTA context. In this case, this is managed by the BackendWinRT class.
37
+ auto device_information = async_get(
38
+ Devices::Enumeration::DeviceInformation::CreateFromIdAsync(winrt::to_hstring(device_id)));
39
+ identifier_ = winrt::to_string(device_information.Name());
40
+
41
+ // Configure the scanner object
42
+ scanner_ = Advertisement::BluetoothLEAdvertisementWatcher();
43
+
44
+ // Register member functions directly as callback handlers
45
+ radio_state_changed_token_ = radio_.StateChanged({this, &AdapterWindows::on_power_state_changed});
46
+ scanner_stopped_token_ = scanner_.Stopped({this, &AdapterWindows::_on_scanner_stopped});
47
+ scanner_received_token_ = scanner_.Received({this, &AdapterWindows::_on_scanner_received});
48
+ }
49
+
50
+ AdapterWindows::~AdapterWindows() {
51
+ _callback_on_scan_stop.unload();
52
+
53
+ MtaManager::get().execute_sync([this]() {
54
+ scanner_.Stop();
55
+
56
+ if (scanner_received_token_) {
57
+ scanner_.Received(scanner_received_token_);
58
+ }
59
+
60
+ if (scanner_stopped_token_) {
61
+ scanner_.Stopped(scanner_stopped_token_);
62
+ }
63
+ });
64
+ }
65
+
66
+ // FIXME: this should return wether this particular adapter is enabled, not if any adapter is enabled.
67
+ bool AdapterWindows::bluetooth_enabled() { return BackendWinRT::get()->bluetooth_enabled(); }
68
+
69
+ void* AdapterWindows::underlying() const { return reinterpret_cast<void*>(const_cast<BluetoothAdapter*>(&adapter_)); }
70
+
71
+ std::string AdapterWindows::identifier() { return identifier_; }
72
+
73
+ BluetoothAddress AdapterWindows::address() {
74
+ return MtaManager::get().execute_sync<BluetoothAddress>([this]() {
75
+ return _mac_address_to_str(adapter_.BluetoothAddress());
76
+ });
77
+ }
78
+
79
+ void AdapterWindows::power_on() {
80
+ MtaManager::get().execute_sync([this]() { async_get(radio_.SetStateAsync(RadioState::On)); });
81
+ }
82
+
83
+ void AdapterWindows::power_off() {
84
+ MtaManager::get().execute_sync([this]() { async_get(radio_.SetStateAsync(RadioState::Off)); });
85
+ }
86
+
87
+ bool AdapterWindows::is_powered() {
88
+ return MtaManager::get().execute_sync<bool>([this]() { return radio_.State() == RadioState::On; });
89
+ }
90
+
91
+ void AdapterWindows::scan_start() {
92
+ this->seen_peripherals_.clear();
93
+
94
+ MtaManager::get().execute_sync([this]() {
95
+ scanner_.ScanningMode(Advertisement::BluetoothLEScanningMode::Active);
96
+ scan_is_active_ = true;
97
+ scanner_.Start();
98
+ });
99
+
100
+ SAFE_CALLBACK_CALL(this->_callback_on_scan_start);
101
+ }
102
+
103
+ void AdapterWindows::scan_stop() {
104
+ MtaManager::get().execute_sync([this]() {
105
+ scanner_.Stop();
106
+ });
107
+
108
+ std::unique_lock<std::mutex> lock(scan_stop_mutex_);
109
+ if (scan_stop_cv_.wait_for(lock, 1s, [this] { return !this->scan_is_active_; })) {
110
+ // Scan stopped
111
+ } else {
112
+ // Scan did not stop, this can be because some other process
113
+ // is using the adapter.
114
+ }
115
+ }
116
+
117
+ void AdapterWindows::scan_for(int timeout_ms) {
118
+ scan_start();
119
+ std::this_thread::sleep_for(std::chrono::milliseconds(timeout_ms));
120
+ scan_stop();
121
+ }
122
+
123
+ bool AdapterWindows::scan_is_active() { return scan_is_active_; }
124
+
125
+ SharedPtrVector<PeripheralBase> AdapterWindows::scan_get_results() { return Util::values(seen_peripherals_); }
126
+
127
+ SharedPtrVector<PeripheralBase> AdapterWindows::get_paired_peripherals() {
128
+ return MtaManager::get().execute_sync<SharedPtrVector<PeripheralBase>>([this]() {
129
+ SharedPtrVector<PeripheralBase> peripherals;
130
+ winrt::hstring aqs_filter = BluetoothLEDevice::GetDeviceSelectorFromPairingState(true);
131
+ auto dev_info_collection = async_get(Devices::Enumeration::DeviceInformation::FindAllAsync(aqs_filter));
132
+
133
+ for (const auto& dev_info : dev_info_collection) {
134
+ try {
135
+ BluetoothLEDevice device = async_get(BluetoothLEDevice::FromIdAsync(dev_info.Id()));
136
+ if (device == nullptr) {
137
+ SIMPLEBLE_LOG_WARN(fmt::format("Could not get BluetoothLEDevice for paired device ID: {}", winrt::to_string(dev_info.Id())));
138
+ continue;
139
+ }
140
+
141
+ BluetoothAddress address = _mac_address_to_str(device.BluetoothAddress());
142
+ if (this->peripherals_.count(address) == 0) {
143
+ // If the peripheral has never been seen before, create and save a reference to it.
144
+ auto base_peripheral = std::make_shared<PeripheralWindows>(device);
145
+ this->peripherals_.insert(std::make_pair(address, base_peripheral));
146
+ }
147
+
148
+ peripherals.push_back(this->peripherals_.at(address));
149
+ } catch (const winrt::hresult_error& e) {
150
+ SIMPLEBLE_LOG_ERROR(fmt::format("WinRT error processing paired device {} : {}", winrt::to_string(dev_info.Id()), winrt::to_string(e.message())));
151
+ throw Exception::WinRTException(e.code().value, winrt::to_string(e.message()));
152
+ }
153
+ }
154
+ return peripherals;
155
+ });
156
+ }
157
+
158
+ SharedPtrVector<PeripheralBase> AdapterWindows::get_connected_peripherals() {
159
+ return MtaManager::get().execute_sync<SharedPtrVector<PeripheralBase>>([this]() {
160
+ SharedPtrVector<PeripheralBase> peripherals;
161
+ winrt::hstring aqs_filter = BluetoothLEDevice::GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus::Connected);
162
+ auto dev_info_collection = async_get(Devices::Enumeration::DeviceInformation::FindAllAsync(aqs_filter));
163
+
164
+ for (const auto& dev_info : dev_info_collection) {
165
+ try {
166
+ BluetoothLEDevice device = async_get(BluetoothLEDevice::FromIdAsync(dev_info.Id()));
167
+ if (device == nullptr) {
168
+ SIMPLEBLE_LOG_WARN(fmt::format("Could not get BluetoothLEDevice for connected device ID: {}", winrt::to_string(dev_info.Id())));
169
+ continue;
170
+ }
171
+
172
+ BluetoothAddress address = _mac_address_to_str(device.BluetoothAddress());
173
+ if (this->peripherals_.count(address) == 0) {
174
+ // If the peripheral has never been seen before, create and save a reference to it.
175
+ auto base_peripheral = std::make_shared<PeripheralWindows>(device);
176
+ this->peripherals_.insert(std::make_pair(address, base_peripheral));
177
+ }
178
+
179
+ peripherals.push_back(this->peripherals_.at(address));
180
+ } catch (const winrt::hresult_error& e) {
181
+ SIMPLEBLE_LOG_ERROR(fmt::format("WinRT error processing connected device {} : {}", winrt::to_string(dev_info.Id()), winrt::to_string(e.message())));
182
+ throw Exception::WinRTException(e.code().value, winrt::to_string(e.message()));
183
+ }
184
+ }
185
+ return peripherals;
186
+ });
187
+ }
188
+
189
+ // Private functions
190
+
191
+ void AdapterWindows::_scan_stopped_callback() {
192
+ std::lock_guard<std::mutex> lock(scan_update_mutex_);
193
+ scan_is_active_ = false;
194
+ scan_stop_cv_.notify_all();
195
+
196
+ SAFE_CALLBACK_CALL(this->_callback_on_scan_stop);
197
+ }
198
+
199
+ void AdapterWindows::_scan_received_callback(advertising_data_t data) {
200
+ if (this->peripherals_.count(data.mac_address) == 0) {
201
+ // If the incoming peripheral has never been seen before, create and save a reference to it.
202
+ auto base_peripheral = std::make_shared<PeripheralWindows>(data);
203
+ this->peripherals_.insert(std::make_pair(data.mac_address, base_peripheral));
204
+ }
205
+
206
+ // Update the received advertising data.
207
+ auto base_peripheral = this->peripherals_.at(data.mac_address);
208
+ base_peripheral->update_advertising_data(data);
209
+
210
+ // Convert the base object into an external-facing Peripheral object
211
+ Peripheral peripheral = Factory::build(base_peripheral);
212
+
213
+ // Check if the device has been seen before, to forward the correct call to the user.
214
+ if (this->seen_peripherals_.count(data.mac_address) == 0) {
215
+ // Store it in our table of seen peripherals
216
+ this->seen_peripherals_.insert(std::make_pair(data.mac_address, base_peripheral));
217
+ SAFE_CALLBACK_CALL(this->_callback_on_scan_found, peripheral);
218
+ } else {
219
+ SAFE_CALLBACK_CALL(this->_callback_on_scan_updated, peripheral);
220
+ }
221
+ }
222
+
223
+ void AdapterWindows::on_power_state_changed(Radio const& sender, Foundation::IInspectable const&) {
224
+ auto state = sender.State();
225
+ if (state == RadioState::On) {
226
+ SAFE_CALLBACK_CALL(this->_callback_on_power_on);
227
+ } else if (state == RadioState::Off) {
228
+ SAFE_CALLBACK_CALL(this->_callback_on_power_off);
229
+ }
230
+ }
231
+
232
+ void AdapterWindows::_on_scanner_stopped(
233
+ const Advertisement::BluetoothLEAdvertisementWatcher& watcher,
234
+ const Advertisement::BluetoothLEAdvertisementWatcherStoppedEventArgs args) {
235
+ // This callback is already in the MTA context as it's called by WinRT
236
+ SAFE_CALLBACK_CALL(this->_callback_on_scan_stop);
237
+ }
238
+
239
+ void AdapterWindows::_on_scanner_received(
240
+ const Advertisement::BluetoothLEAdvertisementWatcher& watcher,
241
+ const Advertisement::BluetoothLEAdvertisementReceivedEventArgs args) {
242
+ // This callback is already in the MTA context as it's called by WinRT
243
+ std::lock_guard<std::mutex> lock(this->scan_update_mutex_);
244
+ if (!this->scan_is_active_) return;
245
+
246
+ advertising_data_t data;
247
+ data.mac_address = _mac_address_to_str(args.BluetoothAddress());
248
+ Bluetooth::BluetoothAddressType addr_type_enum = args.BluetoothAddressType();
249
+ switch (addr_type_enum) {
250
+ case Bluetooth::BluetoothAddressType::Public:
251
+ data.address_type = SimpleBLE::BluetoothAddressType::PUBLIC;
252
+ break;
253
+
254
+ case Bluetooth::BluetoothAddressType::Random:
255
+ data.address_type = SimpleBLE::BluetoothAddressType::RANDOM;
256
+ break;
257
+
258
+ case Bluetooth::BluetoothAddressType::Unspecified:
259
+ data.address_type = SimpleBLE::BluetoothAddressType::UNSPECIFIED;
260
+ break;
261
+ }
262
+
263
+ data.identifier = winrt::to_string(args.Advertisement().LocalName());
264
+ data.connectable = args.IsConnectable();
265
+ data.rssi = args.RawSignalStrengthInDBm();
266
+
267
+ if (args.TransmitPowerLevelInDBm()) {
268
+ data.tx_power = args.TransmitPowerLevelInDBm().Value();
269
+ } else {
270
+ data.tx_power = INT16_MIN;
271
+ }
272
+
273
+ // Parse manufacturer data
274
+ const auto manufacturer_data = args.Advertisement().ManufacturerData();
275
+ for (const auto& item : manufacturer_data) {
276
+ uint16_t company_id = item.CompanyId();
277
+ ByteArray manufacturer_data_buffer = ibuffer_to_bytearray(item.Data());
278
+ data.manufacturer_data[company_id] = manufacturer_data_buffer;
279
+ }
280
+
281
+ // Parse service data.
282
+ const auto& sections = args.Advertisement().DataSections();
283
+ for (const auto& section : sections) {
284
+ ByteArray section_data_buffer = ibuffer_to_bytearray(section.Data());
285
+
286
+ std::string service_uuid;
287
+ ByteArray service_data;
288
+
289
+ if (section.DataType() == Advertisement::BluetoothLEAdvertisementDataTypes::ServiceData128BitUuids()) {
290
+ service_uuid = fmt::format(
291
+ "{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-"
292
+ "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
293
+ (uint8_t)section_data_buffer[15], (uint8_t)section_data_buffer[14],
294
+ (uint8_t)section_data_buffer[13], (uint8_t)section_data_buffer[12],
295
+ (uint8_t)section_data_buffer[11], (uint8_t)section_data_buffer[10],
296
+ (uint8_t)section_data_buffer[9], (uint8_t)section_data_buffer[8],
297
+ (uint8_t)section_data_buffer[7], (uint8_t)section_data_buffer[6],
298
+ (uint8_t)section_data_buffer[5], (uint8_t)section_data_buffer[4],
299
+ (uint8_t)section_data_buffer[3], (uint8_t)section_data_buffer[2],
300
+ (uint8_t)section_data_buffer[1], (uint8_t)section_data_buffer[0]);
301
+ service_data = section_data_buffer.slice_from(16);
302
+ }
303
+
304
+ else if (section.DataType() ==
305
+ Advertisement::BluetoothLEAdvertisementDataTypes::ServiceData32BitUuids()) {
306
+ service_uuid = fmt::format("{:02x}{:02x}{:02x}{:02x}-0000-1000-8000-00805f9b34fb",
307
+ (uint8_t)section_data_buffer[3], (uint8_t)section_data_buffer[2],
308
+ (uint8_t)section_data_buffer[1], (uint8_t)section_data_buffer[0]);
309
+ service_data = section_data_buffer.slice_from(4);
310
+ } else if (section.DataType() ==
311
+ Advertisement::BluetoothLEAdvertisementDataTypes::ServiceData16BitUuids()) {
312
+ service_uuid = fmt::format("0000{:02x}{:02x}-0000-1000-8000-00805f9b34fb",
313
+ (uint8_t)section_data_buffer[1], (uint8_t)section_data_buffer[0]);
314
+ service_data = section_data_buffer.slice_from(2);
315
+ } else {
316
+ continue;
317
+ }
318
+
319
+ data.service_data.emplace(std::make_pair(service_uuid, service_data));
320
+ }
321
+
322
+ // Parse service uuids
323
+ const auto service_data = args.Advertisement().ServiceUuids();
324
+ for (const auto& service_guid : service_data) {
325
+ std::string service_uuid = guid_to_uuid(service_guid);
326
+ data.service_data.emplace(std::make_pair(service_uuid, ByteArray()));
327
+ }
328
+
329
+ this->_scan_received_callback(data);
330
+ }
@@ -0,0 +1,89 @@
1
+ #pragma once
2
+
3
+ #include <simpleble/Exceptions.h>
4
+ #include <simpleble/Peripheral.h>
5
+ #include <simpleble/Types.h>
6
+
7
+ #include "AdapterBase.h"
8
+ #include "AdapterBaseTypes.h"
9
+
10
+ #include <kvn_safe_callback.hpp>
11
+
12
+ #include "winrt/Windows.Devices.Bluetooth.Advertisement.h"
13
+ #include "winrt/Windows.Devices.Bluetooth.h"
14
+
15
+ #include <atomic>
16
+ #include <condition_variable>
17
+ #include <functional>
18
+ #include <memory>
19
+ #include <string>
20
+ #include <vector>
21
+
22
+ using namespace winrt::Windows;
23
+ using namespace winrt::Windows::Devices;
24
+ using namespace winrt::Windows::Devices::Bluetooth;
25
+ using namespace winrt::Windows::Devices::Radios;
26
+
27
+ namespace SimpleBLE {
28
+
29
+ class PeripheralWindows;
30
+ class PeripheralBase;
31
+
32
+ class AdapterWindows : public AdapterBase {
33
+ public:
34
+ AdapterWindows(std::string device_id);
35
+ virtual ~AdapterWindows();
36
+
37
+ virtual void* underlying() const override;
38
+
39
+ virtual std::string identifier() override;
40
+ virtual BluetoothAddress address() override;
41
+
42
+ virtual void power_on() override;
43
+ virtual void power_off() override;
44
+ virtual bool is_powered() override;
45
+
46
+ virtual void scan_start() override;
47
+ virtual void scan_stop() override;
48
+ virtual void scan_for(int timeout_ms) override;
49
+ virtual bool scan_is_active() override;
50
+ virtual std::vector<std::shared_ptr<PeripheralBase>> scan_get_results() override;
51
+
52
+ virtual std::vector<std::shared_ptr<PeripheralBase>> get_paired_peripherals() override;
53
+ virtual std::vector<std::shared_ptr<PeripheralBase>> get_connected_peripherals() override;
54
+
55
+ virtual bool bluetooth_enabled() override;
56
+
57
+ private:
58
+ BluetoothAdapter adapter_;
59
+ std::string identifier_;
60
+
61
+ struct Advertisement::BluetoothLEAdvertisementWatcher scanner_;
62
+ winrt::event_token scanner_received_token_;
63
+ winrt::event_token scanner_stopped_token_;
64
+
65
+ Radio radio_;
66
+ winrt::event_token radio_state_changed_token_;
67
+
68
+ std::atomic_bool scan_is_active_{false};
69
+ std::condition_variable scan_stop_cv_;
70
+ std::mutex scan_stop_mutex_;
71
+ std::mutex scan_update_mutex_;
72
+ std::map<BluetoothAddress, std::shared_ptr<PeripheralWindows>> peripherals_;
73
+ std::map<BluetoothAddress, std::shared_ptr<PeripheralBase>> seen_peripherals_;
74
+
75
+ void on_power_state_changed(Radio const& sender, Foundation::IInspectable const&);
76
+
77
+ void _on_scanner_stopped(
78
+ const Advertisement::BluetoothLEAdvertisementWatcher& watcher,
79
+ const Advertisement::BluetoothLEAdvertisementWatcherStoppedEventArgs args);
80
+
81
+ void _on_scanner_received(
82
+ const Advertisement::BluetoothLEAdvertisementWatcher& watcher,
83
+ const Advertisement::BluetoothLEAdvertisementReceivedEventArgs args);
84
+
85
+ void _scan_stopped_callback();
86
+ void _scan_received_callback(advertising_data_t data);
87
+ };
88
+
89
+ } // namespace SimpleBLE
@@ -0,0 +1,67 @@
1
+ #include "BackendWinRT.h"
2
+
3
+ #include "AdapterWindows.h"
4
+ #include "CommonUtils.h"
5
+
6
+ #include "winrt/Windows.Devices.Bluetooth.h"
7
+ #include "winrt/Windows.Devices.Enumeration.h"
8
+ #include "winrt/Windows.Devices.Radios.h"
9
+ #include "winrt/Windows.Foundation.Collections.h"
10
+
11
+ #include "simpleble/Config.h"
12
+ #include "Utils.h"
13
+ #include "MtaManager.h"
14
+
15
+ namespace SimpleBLE {
16
+
17
+ using namespace SimpleBLE::WinRT;
18
+
19
+ std::shared_ptr<BackendBase> BACKEND_WINDOWS() { return BackendWinRT::get(); }
20
+
21
+ BackendWinRT::BackendWinRT(buildToken) {
22
+ if (Config::WinRT::experimental_reinitialize_winrt_apartment_on_main_thread) {
23
+ initialize_winrt();
24
+ }
25
+ }
26
+
27
+ bool BackendWinRT::bluetooth_enabled() {
28
+ return MtaManager::get().execute_sync<bool>([this]() {
29
+ bool enabled = false;
30
+ auto radio_collection = async_get(Radio::GetRadiosAsync());
31
+ for (uint32_t i = 0; i < radio_collection.Size(); i++) {
32
+ auto radio = radio_collection.GetAt(i);
33
+
34
+ // Skip non-bluetooth radios
35
+ if (radio.Kind() != RadioKind::Bluetooth) {
36
+ continue;
37
+ }
38
+
39
+ // Assume that bluetooth is enabled if any of the radios are enabled
40
+ if (radio.State() == RadioState::On) {
41
+ enabled = true;
42
+ break;
43
+ }
44
+ }
45
+
46
+ return enabled;
47
+ });
48
+ }
49
+
50
+ SharedPtrVector<AdapterBase> BackendWinRT::get_adapters() {
51
+ return MtaManager::get().execute_sync<SharedPtrVector<AdapterBase>>([this]() {
52
+ auto device_selector = BluetoothAdapter::GetDeviceSelector();
53
+ auto device_information_collection = async_get(
54
+ Devices::Enumeration::DeviceInformation::FindAllAsync(device_selector));
55
+
56
+ SharedPtrVector<AdapterBase> adapter_list;
57
+ for (uint32_t i = 0; i < device_information_collection.Size(); i++) {
58
+ auto dev_info = device_information_collection.GetAt(i);
59
+ adapter_list.push_back(std::make_shared<AdapterWindows>(winrt::to_string(dev_info.Id())));
60
+ }
61
+ return adapter_list;
62
+ });
63
+ }
64
+
65
+ std::string BackendWinRT::name() const noexcept { return "WinRT"; }
66
+
67
+ }; // namespace SimpleBLE
@@ -0,0 +1,18 @@
1
+ #pragma once
2
+
3
+ #include "../common/BackendBase.h"
4
+ #include "../common/BackendUtils.h"
5
+
6
+ namespace SimpleBLE {
7
+
8
+ class BackendWinRT : public BackendSingleton<BackendWinRT> {
9
+ public:
10
+ BackendWinRT(buildToken);
11
+ virtual ~BackendWinRT() = default;
12
+
13
+ virtual std::vector<std::shared_ptr<AdapterBase>> get_adapters() override;
14
+ virtual bool bluetooth_enabled() override;
15
+ virtual std::string name() const noexcept override;
16
+ };
17
+
18
+ } // namespace SimpleBLE
@@ -0,0 +1,49 @@
1
+ #include "MtaManager.h"
2
+
3
+ namespace SimpleBLE {
4
+ namespace WinRT {
5
+
6
+ MtaManager::MtaManager() {
7
+ mta_thread_ = std::thread(&MtaManager::mta_thread_func, this);
8
+ }
9
+
10
+ MtaManager::~MtaManager() {
11
+ stop();
12
+ if (mta_thread_.joinable()) {
13
+ mta_thread_.join();
14
+ }
15
+ }
16
+
17
+ void MtaManager::submit_task(std::function<void()> task) {
18
+ {
19
+ std::lock_guard<std::mutex> lock(task_mutex_);
20
+ task_queue_.push(std::move(task));
21
+ }
22
+ task_cv_.notify_one();
23
+ }
24
+
25
+ void MtaManager::stop() {
26
+ {
27
+ std::lock_guard<std::mutex> lock(task_mutex_);
28
+ running_ = false;
29
+ }
30
+ task_cv_.notify_one();
31
+ }
32
+
33
+ void MtaManager::mta_thread_func() {
34
+ winrt::init_apartment(winrt::apartment_type::multi_threaded);
35
+ while (running_) {
36
+ std::function<void()> task;
37
+ {
38
+ std::unique_lock<std::mutex> lock(task_mutex_);
39
+ task_cv_.wait(lock, [this] { return !task_queue_.empty() || !running_; });
40
+ if (!running_ && task_queue_.empty()) break;
41
+ task = std::move(task_queue_.front());
42
+ task_queue_.pop();
43
+ }
44
+ if (task) task();
45
+ }
46
+ }
47
+
48
+ } // namespace WinRT
49
+ } // namespace SimpleBLE
@@ -0,0 +1,90 @@
1
+ #pragma once
2
+
3
+ #include <winrt/base.h>
4
+ #include <atomic>
5
+ #include <condition_variable>
6
+ #include <functional>
7
+ #include <future>
8
+ #include <mutex>
9
+ #include <queue>
10
+ #include <thread>
11
+ #include <simpleble/Config.h>
12
+
13
+ namespace SimpleBLE {
14
+ namespace WinRT {
15
+ class MtaManager {
16
+ public:
17
+ static MtaManager& get() {
18
+ static MtaManager instance;
19
+ return instance;
20
+ }
21
+
22
+ void submit_task(std::function<void()> task);
23
+ void stop();
24
+
25
+ template<typename T>
26
+ T execute_sync(std::function<T()> task) {
27
+ // When flag is disabled, run in calling thread
28
+ if (!Config::WinRT::experimental_use_own_mta_apartment) {
29
+ try {
30
+ return task();
31
+ } catch (...) {
32
+ throw;
33
+ }
34
+ }
35
+
36
+ // Move the promise into the lambda to extend its lifetime
37
+ auto result_promise = std::make_shared<std::promise<T>>(); // Use shared_ptr to manage lifetime
38
+ auto result_future = result_promise->get_future();
39
+ submit_task([promise = std::move(result_promise), task]() {
40
+ try {
41
+ T result = task();
42
+ promise->set_value(result);
43
+ } catch (...) {
44
+ promise->set_exception(std::current_exception());
45
+ }
46
+ });
47
+ return result_future.get();
48
+ }
49
+
50
+ void execute_sync(std::function<void()> task) {
51
+ // When flag is disabled, run in calling thread
52
+ if (!Config::WinRT::experimental_use_own_mta_apartment) {
53
+ try {
54
+ task();
55
+ return;
56
+ } catch (...) {
57
+ throw;
58
+ }
59
+ }
60
+
61
+ // Move the promise into the lambda to extend its lifetime
62
+ auto result_promise = std::make_shared<std::promise<void>>(); // Use shared_ptr to manage lifetime
63
+ auto result_future = result_promise->get_future();
64
+ submit_task([promise = std::move(result_promise), task]() {
65
+ try {
66
+ task();
67
+ promise->set_value();
68
+ } catch (...) {
69
+ promise->set_exception(std::current_exception());
70
+ }
71
+ });
72
+ result_future.get();
73
+ }
74
+
75
+ private:
76
+ MtaManager();
77
+ ~MtaManager();
78
+ MtaManager(const MtaManager&) = delete;
79
+ MtaManager& operator=(const MtaManager&) = delete;
80
+
81
+ std::thread mta_thread_;
82
+ std::mutex task_mutex_;
83
+ std::condition_variable task_cv_;
84
+ std::queue<std::function<void()>> task_queue_;
85
+ std::atomic<bool> running_{true};
86
+
87
+ void mta_thread_func();
88
+ };
89
+ } // namespace WinRT
90
+ } // namespace SimpleBLE