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,487 @@
1
+ // This weird pragma is required for the compiler to properly include the necessary namespaces.
2
+ #pragma comment(lib, "windowsapp")
3
+
4
+ #include "PeripheralWindows.h"
5
+ #include "CommonUtils.h"
6
+ #include "Utils.h"
7
+ #include "MtaManager.h"
8
+
9
+ #include "../common/CharacteristicBase.h"
10
+ #include "../common/DescriptorBase.h"
11
+ #include "../common/ServiceBase.h"
12
+ #include "simpleble/Characteristic.h"
13
+ #include "simpleble/Descriptor.h"
14
+ #include "simpleble/Service.h"
15
+
16
+ #include <simpleble/Exceptions.h>
17
+
18
+ #include "winrt/Windows.Foundation.Collections.h"
19
+ #include "winrt/Windows.Foundation.h"
20
+ #include "winrt/Windows.Storage.Streams.h"
21
+ #include "winrt/base.h"
22
+
23
+ #include <iostream>
24
+
25
+ using namespace SimpleBLE;
26
+ using namespace SimpleBLE::WinRT;
27
+ using namespace std::chrono_literals;
28
+
29
+ PeripheralWindows::PeripheralWindows(BluetoothLEDevice device) {
30
+ device_ = device;
31
+ identifier_ = winrt::to_string(device.Name());
32
+ address_ = _mac_address_to_str(device.BluetoothAddress());
33
+ address_type_ = BluetoothAddressType::PUBLIC;
34
+
35
+ // NOTE: We're assuming that the device is connectable, as this constructor is only called
36
+ // when the device has paired in the past.
37
+ connectable_ = true;
38
+ }
39
+
40
+ PeripheralWindows::PeripheralWindows(advertising_data_t advertising_data) {
41
+ address_type_ = advertising_data.address_type;
42
+ identifier_ = advertising_data.identifier;
43
+ address_ = advertising_data.mac_address;
44
+ rssi_ = advertising_data.rssi;
45
+ tx_power_ = advertising_data.tx_power;
46
+ manufacturer_data_ = advertising_data.manufacturer_data;
47
+ service_data_ = advertising_data.service_data;
48
+ connectable_ = advertising_data.connectable;
49
+ }
50
+
51
+ PeripheralWindows::~PeripheralWindows() {
52
+ if (connection_status_changed_token_ && device_ != nullptr) {
53
+ MtaManager::get().execute_sync([this]() {
54
+ device_.ConnectionStatusChanged(connection_status_changed_token_);
55
+ });
56
+ }
57
+ }
58
+
59
+ void* PeripheralWindows::underlying() const {
60
+ return reinterpret_cast<void*>(const_cast<BluetoothLEDevice*>(&device_));
61
+ }
62
+
63
+ SimpleBLE::BluetoothAddressType PeripheralWindows::address_type() { return address_type_; }
64
+
65
+ std::string PeripheralWindows::identifier() { return identifier_; }
66
+
67
+ BluetoothAddress PeripheralWindows::address() { return address_; }
68
+
69
+ int16_t PeripheralWindows::rssi() { return rssi_; }
70
+
71
+ int16_t PeripheralWindows::tx_power() { return tx_power_; }
72
+
73
+ uint16_t PeripheralWindows::mtu() {
74
+ if (!is_connected()) return 0;
75
+
76
+ // The value provided by the MaxPduSize includes an extra 3 bytes from the GATT header
77
+ // which needs to be removed.
78
+ return mtu_ - 3;
79
+ }
80
+
81
+ void PeripheralWindows::update_advertising_data(advertising_data_t advertising_data) {
82
+ if (advertising_data.identifier != "") {
83
+ identifier_ = advertising_data.identifier;
84
+ }
85
+ rssi_ = advertising_data.rssi;
86
+ tx_power_ = advertising_data.tx_power;
87
+ address_type_ = advertising_data.address_type;
88
+ manufacturer_data_ = advertising_data.manufacturer_data;
89
+
90
+ advertising_data.service_data.merge(service_data_);
91
+ service_data_ = advertising_data.service_data;
92
+ }
93
+
94
+ void PeripheralWindows::connect() {
95
+ MtaManager::get().execute_sync([this]() {
96
+ device_ = async_get(BluetoothLEDevice::FromBluetoothAddressAsync(_str_to_mac_address(address_)));
97
+ });
98
+
99
+ // Attempt to connect to the device.
100
+ for (size_t i = 0; i < 3; i++) {
101
+ if (_attempt_connect()) {
102
+ break;
103
+ }
104
+ }
105
+
106
+ if (is_connected()) {
107
+ MtaManager::get().execute_sync([this]() {
108
+ connection_status_changed_token_ = device_.ConnectionStatusChanged(
109
+ [this](const BluetoothLEDevice device, const auto args) {
110
+ if (device.ConnectionStatus() == BluetoothConnectionStatus::Disconnected) {
111
+ this->disconnection_cv_.notify_all();
112
+
113
+ SAFE_CALLBACK_CALL(this->callback_on_disconnected_);
114
+ }
115
+ });
116
+ });
117
+
118
+ SAFE_CALLBACK_CALL(this->callback_on_connected_);
119
+ } else {
120
+ throw SimpleBLE::Exception::OperationFailed("Failed to connect to device.");
121
+ }
122
+ }
123
+
124
+ void PeripheralWindows::disconnect() {
125
+ gatt_map_.clear();
126
+ if (device_ != nullptr) {
127
+ MtaManager::get().execute_sync([this]() {
128
+ device_.Close();
129
+ });
130
+
131
+ std::unique_lock<std::mutex> lock(disconnection_mutex_);
132
+ if (disconnection_cv_.wait_for(lock, 10s, [this] { return !this->is_connected(); })) {
133
+ // Disconnection successful
134
+ } else {
135
+ SIMPLEBLE_LOG_ERROR("Disconnection failed");
136
+ throw SimpleBLE::Exception::OperationFailed("Disconnection attempt was not acknowledged.");
137
+ }
138
+
139
+ device_ = nullptr;
140
+ }
141
+ }
142
+
143
+ bool PeripheralWindows::is_connected() {
144
+ if (device_ == nullptr) return false;
145
+
146
+ return MtaManager::get().execute_sync<bool>([this]() {
147
+ return device_.ConnectionStatus() == BluetoothConnectionStatus::Connected;
148
+ });
149
+ }
150
+
151
+ bool PeripheralWindows::is_connectable() { return connectable_; }
152
+
153
+ bool PeripheralWindows::is_paired() { throw Exception::OperationNotSupported(); }
154
+
155
+ void PeripheralWindows::unpair() { throw Exception::OperationNotSupported(); }
156
+
157
+ SharedPtrVector<ServiceBase> PeripheralWindows::available_services() {
158
+ SharedPtrVector<ServiceBase> service_list;
159
+ for (auto& [service_uuid, service] : gatt_map_) {
160
+ // Build the list of characteristics for the service.
161
+ SharedPtrVector<CharacteristicBase> characteristic_list;
162
+ for (auto& [characteristic_uuid, characteristic] : service.characteristics) {
163
+ // Build the list of descriptors for the characteristic.
164
+ SharedPtrVector<DescriptorBase> descriptor_list;
165
+ for (auto& [descriptor_uuid, descriptor] : characteristic.descriptors) {
166
+ descriptor_list.push_back(std::make_shared<DescriptorBase>(descriptor_uuid));
167
+ }
168
+
169
+ uint32_t properties = MtaManager::get().execute_sync<uint32_t>([&characteristic]() {
170
+ return (uint32_t)characteristic.obj.CharacteristicProperties();
171
+ });
172
+
173
+ bool can_read = (properties & (uint32_t)GattCharacteristicProperties::Read) != 0;
174
+ bool can_write_request = (properties & (uint32_t)GattCharacteristicProperties::Write) != 0;
175
+ bool can_write_command = (properties & (uint32_t)GattCharacteristicProperties::WriteWithoutResponse) != 0;
176
+ bool can_notify = (properties & (uint32_t)GattCharacteristicProperties::Notify) != 0;
177
+ bool can_indicate = (properties & (uint32_t)GattCharacteristicProperties::Indicate) != 0;
178
+
179
+ characteristic_list.push_back(
180
+ std::make_shared<CharacteristicBase>(characteristic_uuid, descriptor_list, can_read, can_write_request,
181
+ can_write_command, can_notify, can_indicate));
182
+ }
183
+ service_list.push_back(std::make_shared<ServiceBase>(service_uuid, characteristic_list));
184
+ }
185
+
186
+ return service_list;
187
+ }
188
+
189
+ SharedPtrVector<ServiceBase> PeripheralWindows::advertised_services() {
190
+ SharedPtrVector<ServiceBase> service_list;
191
+ for (auto& [service_uuid, data] : service_data_) {
192
+ service_list.push_back(std::make_shared<ServiceBase>(service_uuid, data));
193
+ }
194
+
195
+ return service_list;
196
+ }
197
+
198
+ std::map<uint16_t, ByteArray> PeripheralWindows::manufacturer_data() { return manufacturer_data_; }
199
+
200
+ ByteArray PeripheralWindows::read(BluetoothUUID const& service, BluetoothUUID const& characteristic) {
201
+ GattCharacteristic gatt_characteristic = _fetch_characteristic(service, characteristic).obj;
202
+
203
+ return MtaManager::get().execute_sync<ByteArray>([this, &gatt_characteristic]() {
204
+ // Validate that the operation can be performed.
205
+ uint32_t gatt_characteristic_prop = (uint32_t)gatt_characteristic.CharacteristicProperties();
206
+ if ((gatt_characteristic_prop & (uint32_t)GattCharacteristicProperties::Read) == 0) {
207
+ throw SimpleBLE::Exception::OperationNotSupported();
208
+ }
209
+
210
+ // Read the value.
211
+ auto result = async_get(gatt_characteristic.ReadValueAsync(Devices::Bluetooth::BluetoothCacheMode::Uncached));
212
+ if (result.Status() != GenericAttributeProfile::GattCommunicationStatus::Success) {
213
+ throw SimpleBLE::Exception::OperationFailed();
214
+ }
215
+ return ibuffer_to_bytearray(result.Value());
216
+ });
217
+ }
218
+
219
+ void PeripheralWindows::write_request(BluetoothUUID const& service, BluetoothUUID const& characteristic,
220
+ ByteArray const& data) {
221
+ GattCharacteristic gatt_characteristic = _fetch_characteristic(service, characteristic).obj;
222
+
223
+ MtaManager::get().execute_sync([this, &gatt_characteristic, &data]() {
224
+ // Validate that the operation can be performed.
225
+ uint32_t gatt_characteristic_prop = (uint32_t)gatt_characteristic.CharacteristicProperties();
226
+ if ((gatt_characteristic_prop & (uint32_t)GattCharacteristicProperties::Write) == 0) {
227
+ throw SimpleBLE::Exception::OperationNotSupported();
228
+ }
229
+
230
+ // Convert the request data to a buffer.
231
+ winrt::Windows::Storage::Streams::IBuffer buffer = bytearray_to_ibuffer(data);
232
+
233
+ // Write the value.
234
+ auto result = async_get(gatt_characteristic.WriteValueAsync(buffer, GattWriteOption::WriteWithResponse));
235
+ if (result != GenericAttributeProfile::GattCommunicationStatus::Success) {
236
+ throw SimpleBLE::Exception::OperationFailed();
237
+ }
238
+ });
239
+ }
240
+
241
+ void PeripheralWindows::write_command(BluetoothUUID const& service, BluetoothUUID const& characteristic,
242
+ ByteArray const& data) {
243
+ GattCharacteristic gatt_characteristic = _fetch_characteristic(service, characteristic).obj;
244
+
245
+ MtaManager::get().execute_sync([this, &gatt_characteristic, &data]() {
246
+ // Validate that the operation can be performed.
247
+ uint32_t gatt_characteristic_prop = (uint32_t)gatt_characteristic.CharacteristicProperties();
248
+ if ((gatt_characteristic_prop & (uint32_t)GattCharacteristicProperties::WriteWithoutResponse) == 0) {
249
+ throw SimpleBLE::Exception::OperationNotSupported();
250
+ }
251
+
252
+ // Convert the request data to a buffer.
253
+ winrt::Windows::Storage::Streams::IBuffer buffer = bytearray_to_ibuffer(data);
254
+
255
+ // Write the value.
256
+ auto result = async_get(gatt_characteristic.WriteValueAsync(buffer, GattWriteOption::WriteWithoutResponse));
257
+ if (result != GenericAttributeProfile::GattCommunicationStatus::Success) {
258
+ throw SimpleBLE::Exception::OperationFailed();
259
+ }
260
+ });
261
+ }
262
+
263
+ void PeripheralWindows::notify(BluetoothUUID const& service, BluetoothUUID const& characteristic,
264
+ std::function<void(ByteArray payload)> callback) {
265
+ _subscribe(service, characteristic, std::move(callback), GattCharacteristicProperties::Notify,
266
+ GattClientCharacteristicConfigurationDescriptorValue::Notify);
267
+ }
268
+
269
+ void PeripheralWindows::indicate(BluetoothUUID const& service, BluetoothUUID const& characteristic,
270
+ std::function<void(ByteArray payload)> callback) {
271
+ _subscribe(service, characteristic, std::move(callback), GattCharacteristicProperties::Indicate,
272
+ GattClientCharacteristicConfigurationDescriptorValue::Indicate);
273
+ }
274
+
275
+ void PeripheralWindows::unsubscribe(BluetoothUUID const& service, BluetoothUUID const& characteristic) {
276
+ gatt_characteristic_t& gatt_characteristic_holder = _fetch_characteristic(service, characteristic);
277
+ GattCharacteristic gatt_characteristic = gatt_characteristic_holder.obj;
278
+
279
+ MtaManager::get().execute_sync([this, &gatt_characteristic, &gatt_characteristic_holder]() {
280
+ if (gatt_characteristic_holder.value_changed_token) {
281
+ // Unregister the callback.
282
+ gatt_characteristic.ValueChanged(gatt_characteristic_holder.value_changed_token);
283
+ gatt_characteristic_holder.value_changed_token = {0};
284
+ }
285
+
286
+ // Start the indication.
287
+ auto result = async_get(gatt_characteristic.WriteClientCharacteristicConfigurationDescriptorWithResultAsync(
288
+ GattClientCharacteristicConfigurationDescriptorValue::None));
289
+
290
+ if (result.Status() != GenericAttributeProfile::GattCommunicationStatus::Success) {
291
+ throw SimpleBLE::Exception::OperationFailed();
292
+ }
293
+ });
294
+ }
295
+
296
+ ByteArray PeripheralWindows::read(BluetoothUUID const& service, BluetoothUUID const& characteristic,
297
+ BluetoothUUID const& descriptor) {
298
+ GattDescriptor gatt_descriptor = _fetch_descriptor(service, characteristic, descriptor);
299
+
300
+ return MtaManager::get().execute_sync<ByteArray>([this, &gatt_descriptor]() {
301
+ // Read the value.
302
+ auto result = async_get(gatt_descriptor.ReadValueAsync(Devices::Bluetooth::BluetoothCacheMode::Uncached));
303
+ if (result.Status() != GenericAttributeProfile::GattCommunicationStatus::Success) {
304
+ throw SimpleBLE::Exception::OperationFailed();
305
+ }
306
+ return ibuffer_to_bytearray(result.Value());
307
+ });
308
+ }
309
+
310
+ void PeripheralWindows::write(BluetoothUUID const& service, BluetoothUUID const& characteristic,
311
+ BluetoothUUID const& descriptor, ByteArray const& data) {
312
+ GattDescriptor gatt_descriptor = _fetch_descriptor(service, characteristic, descriptor);
313
+
314
+ MtaManager::get().execute_sync([this, &gatt_descriptor, &data]() {
315
+ // Convert the request data to a buffer.
316
+ winrt::Windows::Storage::Streams::IBuffer buffer = bytearray_to_ibuffer(data);
317
+
318
+ // Write the value.
319
+ auto result = async_get(gatt_descriptor.WriteValueWithResultAsync(buffer));
320
+ if (result.Status() != GenericAttributeProfile::GattCommunicationStatus::Success) {
321
+ throw SimpleBLE::Exception::OperationFailed();
322
+ }
323
+ });
324
+ }
325
+
326
+ void PeripheralWindows::set_callback_on_connected(std::function<void()> on_connected) {
327
+ if (on_connected) {
328
+ callback_on_connected_.load(std::move(on_connected));
329
+ } else {
330
+ callback_on_connected_.unload();
331
+ }
332
+ }
333
+
334
+ void PeripheralWindows::set_callback_on_disconnected(std::function<void()> on_disconnected) {
335
+ if (on_disconnected) {
336
+ callback_on_disconnected_.load(std::move(on_disconnected));
337
+ } else {
338
+ callback_on_disconnected_.unload();
339
+ }
340
+ }
341
+
342
+ // Private methods
343
+
344
+ void PeripheralWindows::_subscribe(BluetoothUUID const& service, BluetoothUUID const& characteristic,
345
+ std::function<void(ByteArray payload)> callback,
346
+ GattCharacteristicProperties property,
347
+ GattClientCharacteristicConfigurationDescriptorValue descriptor_value) {
348
+ gatt_characteristic_t& gatt_characteristic_holder = _fetch_characteristic(service, characteristic);
349
+ GattCharacteristic gatt_characteristic = gatt_characteristic_holder.obj;
350
+
351
+ MtaManager::get().execute_sync([this, &gatt_characteristic, &gatt_characteristic_holder, callback, property, descriptor_value]() {
352
+ // Validate that the operation can be performed.
353
+ uint32_t gatt_characteristic_prop = (uint32_t)gatt_characteristic.CharacteristicProperties();
354
+ if ((gatt_characteristic_prop & (uint32_t)property) == 0) {
355
+ throw SimpleBLE::Exception::OperationNotSupported();
356
+ }
357
+
358
+ // If a notification for the given characteristic is already in progress, swap the callbacks.
359
+ if (gatt_characteristic_holder.value_changed_token) {
360
+ SIMPLEBLE_LOG_WARN("A notification for the given characteristic is already in progress. Swapping callbacks.");
361
+ // Unregister the callback.
362
+ gatt_characteristic.ValueChanged(gatt_characteristic_holder.value_changed_token);
363
+ gatt_characteristic_holder.value_changed_token = {0};
364
+ }
365
+
366
+ gatt_characteristic_holder.value_changed_callback = [=](const GattCharacteristic& sender,
367
+ const GattValueChangedEventArgs& args) {
368
+ // Convert the payload to a ByteArray.
369
+ ByteArray payload = ibuffer_to_bytearray(args.CharacteristicValue());
370
+ callback(payload);
371
+ };
372
+
373
+ // Register the callback.
374
+ gatt_characteristic_holder.value_changed_token = gatt_characteristic.ValueChanged(
375
+ gatt_characteristic_holder.value_changed_callback);
376
+
377
+ // Start the notification.
378
+ auto result = async_get(
379
+ gatt_characteristic.WriteClientCharacteristicConfigurationDescriptorWithResultAsync(descriptor_value));
380
+
381
+ if (result.Status() != GenericAttributeProfile::GattCommunicationStatus::Success) {
382
+ throw SimpleBLE::Exception::OperationFailed();
383
+ }
384
+ });
385
+ }
386
+
387
+ bool PeripheralWindows::_attempt_connect() {
388
+ gatt_map_.clear();
389
+
390
+ return MtaManager::get().execute_sync<bool>([this]() {
391
+ // We need to cache all services, characteristics and descriptors in the class, else
392
+ // the underlying objects will be garbage collected.
393
+ auto services_result = async_get(device_.GetGattServicesAsync(BluetoothCacheMode::Uncached));
394
+ if (services_result.Status() != GattCommunicationStatus::Success) {
395
+ return false;
396
+ }
397
+
398
+ auto gatt_services = services_result.Services();
399
+ for (GattDeviceService&& service : gatt_services) {
400
+ // For each service...
401
+ gatt_service_t gatt_service;
402
+ gatt_service.obj = service;
403
+
404
+ // Save the MTU size
405
+ mtu_ = service.Session().MaxPduSize();
406
+
407
+ // Fetch the service UUID
408
+ std::string service_uuid = guid_to_uuid(service.Uuid());
409
+
410
+ // Fetch the service characteristics
411
+ auto characteristics_result = async_get(service.GetCharacteristicsAsync(BluetoothCacheMode::Uncached));
412
+ if (characteristics_result.Status() != GattCommunicationStatus::Success) {
413
+ return false;
414
+ }
415
+
416
+ // Load the characteristics into the service
417
+ auto gatt_characteristics = characteristics_result.Characteristics();
418
+ for (GattCharacteristic&& characteristic : gatt_characteristics) {
419
+ // For each characteristic...
420
+ gatt_characteristic_t gatt_characteristic;
421
+ gatt_characteristic.obj = characteristic;
422
+
423
+ // Fetch the characteristic UUID
424
+ std::string characteristic_uuid = guid_to_uuid(characteristic.Uuid());
425
+
426
+ // Fetch the characteristic descriptors
427
+ auto descriptors_result = async_get(characteristic.GetDescriptorsAsync(BluetoothCacheMode::Uncached));
428
+ if (descriptors_result.Status() != GattCommunicationStatus::Success) {
429
+ return false;
430
+ }
431
+
432
+ // Load the descriptors into the characteristic
433
+ auto gatt_descriptors = descriptors_result.Descriptors();
434
+ for (GattDescriptor&& descriptor : gatt_descriptors) {
435
+ // For each descriptor...
436
+ gatt_descriptor_t gatt_descriptor;
437
+ gatt_descriptor.obj = descriptor;
438
+
439
+ // Fetch the descriptor UUID.
440
+ std::string descriptor_uuid = guid_to_uuid(descriptor.Uuid());
441
+
442
+ // Append the descriptor to the characteristic.
443
+ gatt_characteristic.descriptors.emplace(descriptor_uuid, std::move(gatt_descriptor));
444
+ }
445
+
446
+ // Append the characteristic to the service.
447
+ gatt_service.characteristics.emplace(characteristic_uuid, std::move(gatt_characteristic));
448
+ }
449
+
450
+ // Append the service to the map.
451
+ gatt_map_.emplace(service_uuid, std::move(gatt_service));
452
+ }
453
+
454
+ return true;
455
+ });
456
+ }
457
+
458
+ gatt_characteristic_t& PeripheralWindows::_fetch_characteristic(const BluetoothUUID& service_uuid,
459
+ const BluetoothUUID& characteristic_uuid) {
460
+ if (gatt_map_.count(service_uuid) == 0) {
461
+ throw SimpleBLE::Exception::ServiceNotFound(service_uuid);
462
+ }
463
+
464
+ if (gatt_map_[service_uuid].characteristics.count(characteristic_uuid) == 0) {
465
+ throw SimpleBLE::Exception::CharacteristicNotFound(characteristic_uuid);
466
+ }
467
+
468
+ return gatt_map_[service_uuid].characteristics.at(characteristic_uuid);
469
+ }
470
+
471
+ GattDescriptor PeripheralWindows::_fetch_descriptor(const BluetoothUUID& service_uuid,
472
+ const BluetoothUUID& characteristic_uuid,
473
+ const BluetoothUUID& descriptor_uuid) {
474
+ if (gatt_map_.count(service_uuid) == 0) {
475
+ throw SimpleBLE::Exception::ServiceNotFound(service_uuid);
476
+ }
477
+
478
+ if (gatt_map_[service_uuid].characteristics.count(characteristic_uuid) == 0) {
479
+ throw SimpleBLE::Exception::CharacteristicNotFound(characteristic_uuid);
480
+ }
481
+
482
+ if (gatt_map_[service_uuid].characteristics[characteristic_uuid].descriptors.count(descriptor_uuid) == 0) {
483
+ throw SimpleBLE::Exception::DescriptorNotFound(descriptor_uuid);
484
+ }
485
+
486
+ return gatt_map_[service_uuid].characteristics[characteristic_uuid].descriptors.at(descriptor_uuid).obj;
487
+ }
@@ -0,0 +1,129 @@
1
+ #pragma once
2
+
3
+ #include <simpleble/Exceptions.h>
4
+ #include <simpleble/Service.h>
5
+ #include <simpleble/Types.h>
6
+
7
+ #include "AdapterBaseTypes.h"
8
+ #include "PeripheralBase.h"
9
+
10
+ #include <kvn_safe_callback.hpp>
11
+
12
+ #include "winrt/Windows.Devices.Bluetooth.GenericAttributeProfile.h"
13
+ #include "winrt/Windows.Devices.Bluetooth.h"
14
+
15
+ #include <condition_variable>
16
+ #include <functional>
17
+ #include <map>
18
+ #include <memory>
19
+
20
+ using namespace winrt::Windows::Devices::Bluetooth;
21
+ using namespace winrt::Windows::Devices::Bluetooth::GenericAttributeProfile;
22
+
23
+ namespace SimpleBLE {
24
+
25
+ struct gatt_descriptor_t {
26
+ GattDescriptor obj = nullptr;
27
+ };
28
+
29
+ struct gatt_characteristic_t {
30
+ GattCharacteristic obj = nullptr;
31
+ winrt::event_token value_changed_token;
32
+ std::function<void(const GattCharacteristic& sender, const GattValueChangedEventArgs& args)> value_changed_callback;
33
+ std::map<BluetoothUUID, gatt_descriptor_t> descriptors;
34
+ };
35
+
36
+ struct gatt_service_t {
37
+ GattDeviceService obj = nullptr;
38
+ std::map<BluetoothUUID, gatt_characteristic_t> characteristics;
39
+ };
40
+
41
+ class PeripheralWindows : public PeripheralBase {
42
+ public:
43
+ PeripheralWindows(BluetoothLEDevice device);
44
+ PeripheralWindows(advertising_data_t advertising_data);
45
+ virtual ~PeripheralWindows();
46
+
47
+ virtual void* underlying() const override;
48
+
49
+ virtual std::string identifier() override;
50
+ virtual BluetoothAddress address() override;
51
+ virtual SimpleBLE::BluetoothAddressType address_type() override;
52
+ virtual int16_t rssi() override;
53
+ virtual int16_t tx_power() override;
54
+ virtual uint16_t mtu() override;
55
+
56
+ virtual void connect() override;
57
+ virtual void disconnect() override;
58
+ virtual bool is_connected() override;
59
+ virtual bool is_connectable() override;
60
+ virtual bool is_paired() override;
61
+ virtual void unpair() override;
62
+
63
+ virtual std::vector<std::shared_ptr<ServiceBase>> available_services() override;
64
+ virtual std::vector<std::shared_ptr<ServiceBase>> advertised_services() override;
65
+ virtual std::map<uint16_t, ByteArray> manufacturer_data() override;
66
+
67
+ // clang-format off
68
+ virtual ByteArray read(BluetoothUUID const& service, BluetoothUUID const& characteristic) override;
69
+ virtual void write_request(BluetoothUUID const& service, BluetoothUUID const& characteristic, ByteArray const& data) override;
70
+ virtual void write_command(BluetoothUUID const& service, BluetoothUUID const& characteristic, ByteArray const& data) override;
71
+ virtual void notify(BluetoothUUID const& service, BluetoothUUID const& characteristic, std::function<void(ByteArray payload)> callback) override;
72
+ virtual void indicate(BluetoothUUID const& service, BluetoothUUID const& characteristic, std::function<void(ByteArray payload)> callback) override;
73
+ virtual void unsubscribe(BluetoothUUID const& service, BluetoothUUID const& characteristic) override;
74
+
75
+ virtual ByteArray read(BluetoothUUID const& service, BluetoothUUID const& characteristic, BluetoothUUID const& descriptor) override;
76
+ virtual void write(BluetoothUUID const& service, BluetoothUUID const& characteristic, BluetoothUUID const& descriptor, ByteArray const& data) override;
77
+ // clang-format on
78
+
79
+ virtual void set_callback_on_connected(std::function<void()> on_connected) override;
80
+ virtual void set_callback_on_disconnected(std::function<void()> on_disconnected) override;
81
+
82
+ // Internal methods not exposed to the user.
83
+
84
+ void update_advertising_data(advertising_data_t advertising_data);
85
+
86
+ private:
87
+ BluetoothLEDevice device_{nullptr};
88
+
89
+ // NOTE: Calling device_.Name() or device_.BluetoothAddress() might
90
+ // cause a crash on some devices.
91
+ // This is because any operation on the object before it is connected will
92
+ // initiate a connection, which can then cause further cascading failures.
93
+ // See:
94
+ // https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.bluetoothledevice.frombluetoothaddressasync
95
+
96
+ std::string identifier_;
97
+ BluetoothAddress address_;
98
+ SimpleBLE::BluetoothAddressType address_type_;
99
+ int16_t rssi_ = INT16_MIN;
100
+ int16_t tx_power_ = INT16_MIN;
101
+ uint16_t mtu_;
102
+ bool connectable_;
103
+ winrt::event_token connection_status_changed_token_;
104
+
105
+ std::condition_variable disconnection_cv_;
106
+ std::mutex disconnection_mutex_;
107
+
108
+ std::map<BluetoothUUID, gatt_service_t> gatt_map_;
109
+
110
+ kvn::safe_callback<void()> callback_on_connected_;
111
+ kvn::safe_callback<void()> callback_on_disconnected_;
112
+
113
+ std::map<uint16_t, SimpleBLE::ByteArray> manufacturer_data_;
114
+ std::map<BluetoothUUID, SimpleBLE::ByteArray> service_data_;
115
+
116
+ bool _attempt_connect();
117
+
118
+ gatt_characteristic_t& _fetch_characteristic(const BluetoothUUID& service_uuid,
119
+ const BluetoothUUID& characteristic_uuid);
120
+
121
+ GattDescriptor _fetch_descriptor(const BluetoothUUID& service_uuid, const BluetoothUUID& characteristic_uuid,
122
+ const BluetoothUUID& descriptor_uuid);
123
+
124
+ void _subscribe(BluetoothUUID const& service, BluetoothUUID const& characteristic,
125
+ std::function<void(ByteArray payload)> callback, GattCharacteristicProperties property,
126
+ GattClientCharacteristicConfigurationDescriptorValue descriptor_value);
127
+ };
128
+
129
+ } // namespace SimpleBLE