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,26 @@
1
+ #pragma once
2
+
3
+ #include <simpledbus/advanced/Interface.h>
4
+ #include <simpledbus/advanced/InterfaceRegistry.h>
5
+
6
+ #include <functional>
7
+
8
+ namespace SimpleDBus {
9
+
10
+ class ObjectManager : public Interface {
11
+ public:
12
+ ObjectManager(std::shared_ptr<Connection> conn, std::string bus_name, std::string path);
13
+ virtual ~ObjectManager() = default;
14
+
15
+ // Names are made matching the ones from the DBus specification
16
+ Holder GetManagedObjects(bool use_callbacks = false);
17
+ std::function<void(std::string path, Holder options)> InterfacesAdded;
18
+ std::function<void(std::string path, Holder options)> InterfacesRemoved;
19
+
20
+ void message_handle(Message& msg) override;
21
+
22
+ private:
23
+ static const SimpleDBus::AutoRegisterInterface<ObjectManager> registry;
24
+ };
25
+
26
+ } // namespace SimpleDBus
@@ -0,0 +1,155 @@
1
+ #include <simpledbus/advanced/Interface.h>
2
+ #include <simpledbus/base/Exceptions.h>
3
+
4
+ using namespace SimpleDBus;
5
+
6
+ Interface::Interface(std::shared_ptr<Connection> conn, const std::string& bus_name, const std::string& path,
7
+ const std::string& interface_name)
8
+ : _conn(conn), _bus_name(bus_name), _path(path), _interface_name(interface_name), _loaded(true) {}
9
+
10
+ // ----- LIFE CYCLE -----
11
+
12
+ void Interface::load(Holder options) {
13
+ _property_update_mutex.lock();
14
+ auto changed_options = options.get_dict_string();
15
+ for (auto& [name, value] : changed_options) {
16
+ _properties[name] = value;
17
+ _property_valid_map[name] = true;
18
+ }
19
+ _property_update_mutex.unlock();
20
+
21
+ // Notify the user of all properties that have been created.
22
+ for (auto& [name, value] : changed_options) {
23
+ property_changed(name);
24
+ }
25
+
26
+ _loaded = true;
27
+ }
28
+
29
+ void Interface::unload() { _loaded = false; }
30
+
31
+ bool Interface::is_loaded() const { return _loaded; }
32
+
33
+ // ----- METHODS -----
34
+
35
+ Message Interface::create_method_call(const std::string& method_name) {
36
+ return Message::create_method_call(_bus_name, _path, _interface_name, method_name);
37
+ }
38
+
39
+ // ----- PROPERTIES -----
40
+
41
+ Holder Interface::property_collect() {
42
+ std::scoped_lock lock(_property_update_mutex);
43
+ SimpleDBus::Holder properties = SimpleDBus::Holder::create_dict();
44
+ for (const auto& [key, value] : _properties) {
45
+ properties.dict_append(SimpleDBus::Holder::Type::STRING, key, value);
46
+ }
47
+ return properties;
48
+ }
49
+
50
+ Holder Interface::property_collect_single(const std::string& property_name) {
51
+ std::scoped_lock lock(_property_update_mutex);
52
+ // TODO: Check if property exists
53
+ return _properties[property_name];
54
+ }
55
+
56
+ void Interface::property_modify(const std::string& property_name, const Holder& value) {
57
+ std::scoped_lock lock(_property_update_mutex);
58
+ _properties[property_name] = value;
59
+ property_changed(property_name);
60
+ }
61
+
62
+ Holder Interface::property_get_all() {
63
+ Message query_msg = Message::create_method_call(_bus_name, _path, "org.freedesktop.DBus.Properties", "GetAll");
64
+
65
+ Holder h_interface = Holder::create_string(_interface_name);
66
+ query_msg.append_argument(h_interface, "s");
67
+
68
+ Message reply_msg = _conn->send_with_reply_and_block(query_msg);
69
+ Holder result = reply_msg.extract();
70
+ return result;
71
+ }
72
+
73
+ Holder Interface::property_get(const std::string& property_name) {
74
+ Message query_msg = Message::create_method_call(_bus_name, _path, "org.freedesktop.DBus.Properties", "Get");
75
+
76
+ Holder h_interface = Holder::create_string(_interface_name);
77
+ query_msg.append_argument(h_interface, "s");
78
+
79
+ Holder h_name = Holder::create_string(property_name);
80
+ query_msg.append_argument(h_name, "s");
81
+
82
+ Message reply_msg = _conn->send_with_reply_and_block(query_msg);
83
+ Holder result = reply_msg.extract();
84
+ return result;
85
+ }
86
+
87
+ void Interface::property_set(const std::string& property_name, const Holder& value) {
88
+ Message query_msg = Message::create_method_call(_bus_name, _path, "org.freedesktop.DBus.Properties", "Set");
89
+
90
+ Holder h_interface = Holder::create_string(_interface_name);
91
+ query_msg.append_argument(h_interface, "s");
92
+
93
+ Holder h_name = Holder::create_string(property_name);
94
+ query_msg.append_argument(h_name, "s");
95
+
96
+ query_msg.append_argument(value, "v");
97
+
98
+ _conn->send_with_reply_and_block(query_msg);
99
+ }
100
+
101
+ void Interface::property_refresh(const std::string& property_name) {
102
+ if (!_loaded || !_property_valid_map[property_name]) {
103
+ return;
104
+ }
105
+
106
+ bool cb_property_changed_required = false;
107
+ _property_update_mutex.lock();
108
+ try {
109
+ // NOTE: Due to the way Bluez handles underlying devices and the fact that
110
+ // they can be removed before the callback reaches back (race condition),
111
+ // `property_get` can sometimes fail. Because of this, the update
112
+ // statement is surrounded by a try-catch statement.
113
+ Holder property_latest = property_get(property_name);
114
+ _property_valid_map[property_name] = true;
115
+ if (_properties[property_name] != property_latest) {
116
+ _properties[property_name] = property_latest;
117
+ cb_property_changed_required = true;
118
+ }
119
+ } catch (const Exception::SendFailed& e) {
120
+ _property_valid_map[property_name] = true;
121
+ }
122
+ _property_update_mutex.unlock();
123
+
124
+ if (cb_property_changed_required) {
125
+ property_changed(property_name);
126
+ }
127
+ }
128
+
129
+ void Interface::property_changed(std::string option_name) {}
130
+
131
+ // ----- SIGNALS -----
132
+
133
+ void Interface::signal_property_changed(Holder changed_properties, Holder invalidated_properties) {
134
+ _property_update_mutex.lock();
135
+ auto changed_options = changed_properties.get_dict_string();
136
+ for (auto& [name, value] : changed_options) {
137
+ _properties[name] = value;
138
+ _property_valid_map[name] = true;
139
+ }
140
+
141
+ auto removed_options = invalidated_properties.get_array();
142
+ for (auto& removed_option : removed_options) {
143
+ _property_valid_map[removed_option.get_string()] = false;
144
+ }
145
+ _property_update_mutex.unlock();
146
+
147
+ // Once all properties have been updated, notify the user.
148
+ for (auto& [name, value] : changed_options) {
149
+ property_changed(name);
150
+ }
151
+ }
152
+
153
+ // ----- MESSAGES -----
154
+
155
+ void Interface::message_handle(Message& msg) {}
@@ -0,0 +1,375 @@
1
+ #include "simpledbus/advanced/Proxy.h"
2
+
3
+ #include <simpledbus/advanced/InterfaceRegistry.h>
4
+ #include <simpledbus/base/Exceptions.h>
5
+ #include <simpledbus/base/Logging.h>
6
+ #include <simpledbus/base/Path.h>
7
+ #include <algorithm>
8
+
9
+ // #include <simpledbus/interfaces/Properties.h>
10
+
11
+ using namespace SimpleDBus;
12
+
13
+ Proxy::Proxy(std::shared_ptr<Connection> conn, const std::string& bus_name, const std::string& path)
14
+ : _conn(conn), _bus_name(bus_name), _path(path), _valid(true), _registered(false) {
15
+ // TODO: UNCOMMENT THIS WHEN MIGRATING TO NEW PROXY FORWARDING LOGIC
16
+ // register_object_path();
17
+
18
+ //_interfaces.emplace(std::make_pair("org.freedesktop.DBus.Properties", std::make_shared<Properties>(conn, bus_name,
19
+ //path)));
20
+ }
21
+
22
+ Proxy::~Proxy() {
23
+ // TODO: UNCOMMENT THIS WHEN MIGRATING TO NEW PROXY FORWARDING LOGIC
24
+ // unregister_object_path();
25
+ on_child_created.unload();
26
+ on_signal_received.unload();
27
+ }
28
+
29
+ std::shared_ptr<Proxy> Proxy::path_create(const std::string& path) {
30
+ return std::make_shared<Proxy>(_conn, _bus_name, path);
31
+ }
32
+
33
+ bool Proxy::valid() const { return _valid; }
34
+
35
+ void Proxy::invalidate() {
36
+ _valid = false;
37
+ // TODO: UNCOMMENT THIS WHEN MIGRATING TO NEW PROXY FORWARDING LOGIC
38
+ // unregister_object_path();
39
+ }
40
+
41
+ std::string Proxy::path() const { return _path; }
42
+
43
+ std::string Proxy::bus_name() const { return _bus_name; }
44
+
45
+ const std::map<std::string, std::shared_ptr<Proxy>>& Proxy::children() { return _children; }
46
+
47
+ const std::map<std::string, std::shared_ptr<Interface>>& Proxy::interfaces() { return _interfaces; }
48
+
49
+ // ----- PATH HANDLING -----
50
+
51
+ void Proxy::register_object_path() {
52
+ if (!_registered && _conn &&
53
+ _conn->register_object_path(_path, [this](Message& msg) { this->message_handle(msg); })) {
54
+ _registered = true;
55
+ }
56
+ }
57
+
58
+ void Proxy::unregister_object_path() {
59
+ if (_registered && _conn && _conn->unregister_object_path(_path)) {
60
+ _registered = false;
61
+ }
62
+ }
63
+
64
+ // ----- INTROSPECTION -----
65
+
66
+ std::string Proxy::introspect() {
67
+ auto query_msg = Message::create_method_call(_bus_name, _path, "org.freedesktop.DBus.Introspectable", "Introspect");
68
+ auto reply_msg = _conn->send_with_reply_and_block(query_msg);
69
+ return reply_msg.extract().get_string();
70
+ }
71
+
72
+ // ----- INTERFACE HANDLING -----
73
+
74
+ bool Proxy::interface_exists(const std::string& name) {
75
+ std::scoped_lock lock(_interface_access_mutex);
76
+ return _interfaces.find(name) != _interfaces.end();
77
+ }
78
+
79
+ std::shared_ptr<Interface> Proxy::interface_get(const std::string& name) {
80
+ std::scoped_lock lock(_interface_access_mutex);
81
+ if (!interface_exists(name)) {
82
+ throw Exception::InterfaceNotFoundException(_path, name);
83
+ }
84
+ return _interfaces[name];
85
+ }
86
+
87
+ size_t Proxy::interfaces_count() {
88
+ size_t count = 0;
89
+ std::scoped_lock lock(_interface_access_mutex);
90
+ for (auto& [iface_name, interface] : _interfaces) {
91
+ if (interface->is_loaded()) {
92
+ count++;
93
+ }
94
+ }
95
+ return count;
96
+ }
97
+
98
+ void Proxy::interfaces_load(Holder managed_interfaces) {
99
+ auto managed_interface = managed_interfaces.get_dict_string();
100
+
101
+ std::scoped_lock lock(_interface_access_mutex);
102
+ for (auto& [iface_name, options] : managed_interface) {
103
+ // If the interface has not been loaded, load it
104
+ if (!interface_exists(iface_name)) {
105
+ if (InterfaceRegistry::getInstance().isRegistered(iface_name)) {
106
+ _interfaces.emplace(std::make_pair(
107
+ iface_name, InterfaceRegistry::getInstance().create(iface_name, _conn, _bus_name, _path, options)));
108
+ } else {
109
+ LOG_WARN("Interface {} not registered within SimpleDBus", iface_name);
110
+ }
111
+ } else {
112
+ _interfaces[iface_name]->load(options);
113
+ }
114
+ }
115
+ }
116
+
117
+ void Proxy::interfaces_reload(Holder managed_interfaces) {
118
+ std::scoped_lock lock(_interface_access_mutex);
119
+ for (auto& [iface_name, interface] : _interfaces) {
120
+ interface->unload();
121
+ }
122
+
123
+ interfaces_load(managed_interfaces);
124
+ }
125
+
126
+ void Proxy::interfaces_unload(SimpleDBus::Holder removed_interfaces) {
127
+ std::scoped_lock lock(_interface_access_mutex);
128
+ for (auto& option : removed_interfaces.get_array()) {
129
+ std::string iface_name = option.get_string();
130
+ if (interface_exists(iface_name)) {
131
+ _interfaces[iface_name]->unload();
132
+ }
133
+ }
134
+ }
135
+
136
+ bool Proxy::interfaces_loaded() {
137
+ std::scoped_lock lock(_interface_access_mutex);
138
+ for (auto& [iface_name, interface] : _interfaces) {
139
+ if (interface->is_loaded()) {
140
+ return true;
141
+ }
142
+ }
143
+ return false;
144
+ }
145
+
146
+ // ----- CHILD HANDLING -----
147
+
148
+ bool Proxy::path_exists(const std::string& path) {
149
+ std::scoped_lock lock(_child_access_mutex);
150
+ return _children.find(path) != _children.end();
151
+ }
152
+
153
+ std::shared_ptr<Proxy> Proxy::path_get(const std::string& path) {
154
+ std::scoped_lock lock(_child_access_mutex);
155
+ if (!path_exists(path)) {
156
+ throw Exception::PathNotFoundException(_path, path);
157
+ }
158
+ return _children[path];
159
+ }
160
+
161
+ void Proxy::path_add(const std::string& path, SimpleDBus::Holder managed_interfaces) {
162
+ // If the path is not a child of the current path, then we can't add it.
163
+ if (!Path::is_descendant(_path, path)) {
164
+ // TODO: Should an exception be thrown here?
165
+ return;
166
+ }
167
+
168
+ // If the path is already in the map, perform a reload of all interfaces.
169
+ if (path_exists(path)) {
170
+ path_get(path)->interfaces_load(managed_interfaces);
171
+ return;
172
+ }
173
+
174
+ // As children will be extensively accessed, we need to lock the child access mutex.
175
+ std::scoped_lock lock(_child_access_mutex);
176
+
177
+ if (Path::is_child(_path, path)) {
178
+ // If the path is a direct child of the proxy path, create a new proxy for it.
179
+ std::shared_ptr<Proxy> child = path_create(path);
180
+ child->interfaces_load(managed_interfaces);
181
+ _children.emplace(std::make_pair(path, child));
182
+ on_child_created(path);
183
+ } else {
184
+ // If the new path is for a descendant of the current proxy, check if there is a child proxy for it.
185
+ auto child_result = std::find_if(
186
+ _children.begin(), _children.end(),
187
+ [path](const std::pair<std::string, std::shared_ptr<Proxy>>& child_data) -> bool {
188
+ return Path::is_descendant(child_data.first, path);
189
+ });
190
+
191
+ if (child_result != _children.end()) {
192
+ // If there is a child proxy for the new path, forward it to that child proxy.
193
+ child_result->second->path_add(path, managed_interfaces);
194
+ } else {
195
+ // If there is no child proxy for the new path, create the child and forward the path to it.
196
+ // This path will be taken if an empty proxy object needs to be created for an intermediate path.
197
+ std::string child_path = Path::next_child(_path, path);
198
+ std::shared_ptr<Proxy> child = path_create(child_path);
199
+ _children.emplace(std::make_pair(child_path, child));
200
+ child->path_add(path, managed_interfaces);
201
+ on_child_created(child_path);
202
+ }
203
+ }
204
+ }
205
+
206
+ bool Proxy::path_remove(const std::string& path, SimpleDBus::Holder options) {
207
+ // `options` contains an array of strings of the interfaces that need to be removed.
208
+
209
+ if (path == _path) {
210
+ invalidate();
211
+ interfaces_unload(options);
212
+ return path_prune();
213
+ }
214
+
215
+ // If the path is not the current path nor a descendant, then there's nothing to do
216
+ if (!Path::is_descendant(_path, path)) {
217
+ return false;
218
+ }
219
+
220
+ // As children will be extensively accessed, we need to lock the child access mutex.
221
+ std::scoped_lock lock(_child_access_mutex);
222
+
223
+ // If the path is a direct child of the proxy path, forward the request to the child proxy.
224
+ std::string child_path = Path::next_child(_path, path);
225
+ if (path_exists(child_path)) {
226
+ bool must_erase = _children.at(child_path)->path_remove(path, options);
227
+
228
+ // if the child proxy is no longer needed and there is only one active instance of the child proxy,
229
+ // then remove it.
230
+ if (must_erase && _children.at(child_path).use_count() == 1) {
231
+ _children.erase(child_path);
232
+ }
233
+ }
234
+
235
+ return false;
236
+ }
237
+
238
+ bool Proxy::path_prune() {
239
+ // As children will be extensively accessed, we need to lock the child access mutex.
240
+ std::scoped_lock lock(_child_access_mutex);
241
+
242
+ // For each child proxy, check if it can be pruned.
243
+ std::vector<std::string> to_remove;
244
+ for (auto& [child_path, child] : _children) {
245
+ if (child->path_prune() && _children.at(child_path).use_count() == 1) {
246
+ to_remove.push_back(child_path);
247
+ }
248
+ }
249
+ for (auto& child_path : to_remove) {
250
+ _children.erase(child_path);
251
+ }
252
+
253
+ // For self to be pruned, the following conditions must be met:
254
+ // 1. The proxy has no children
255
+ // 2. The proxy has no interfaces or all interfaces are disabled.
256
+ if (_children.empty() && !interfaces_loaded()) {
257
+ return true;
258
+ }
259
+
260
+ return false;
261
+ }
262
+
263
+ Holder Proxy::path_collect() {
264
+ SimpleDBus::Holder result = SimpleDBus::Holder::create_dict();
265
+ SimpleDBus::Holder interfaces = SimpleDBus::Holder::create_dict();
266
+
267
+ for (const auto& [interface_name, interface_ptr] : _interfaces) {
268
+ SimpleDBus::Holder properties = interface_ptr->property_collect();
269
+ interfaces.dict_append(SimpleDBus::Holder::Type::STRING, interface_name, std::move(properties));
270
+ }
271
+
272
+ if (!interfaces.get_dict_string().empty()) {
273
+ result.dict_append(SimpleDBus::Holder::Type::OBJ_PATH, _path, std::move(interfaces));
274
+ }
275
+
276
+ for (const auto& [child_path, child] : _children) {
277
+ SimpleDBus::Holder child_result = child->path_collect();
278
+ // Merge child_result into result
279
+ for (auto&& [path, child_interfaces] : child_result.get_dict_object_path()) {
280
+ result.dict_append(SimpleDBus::Holder::Type::OBJ_PATH, std::move(path), std::move(child_interfaces));
281
+ }
282
+ }
283
+ return std::move(result);
284
+ }
285
+
286
+ // ----- MANUAL CHILD HANDLING -----
287
+
288
+ void Proxy::path_append_child(const std::string& path, std::shared_ptr<Proxy> child) {
289
+ // ! This function is used to manually add children to the proxy.
290
+
291
+ // If the provided path is not a child of the current path, return silently.
292
+ if (!Path::is_child(_path, path)) {
293
+ // TODO: Should an exception be thrown here?
294
+ return;
295
+ }
296
+
297
+ // As children will be extensively accessed, we need to lock the child access mutex.
298
+ std::scoped_lock lock(_child_access_mutex);
299
+ _children.emplace(std::make_pair(path, child));
300
+ }
301
+
302
+ void Proxy::path_remove_child(const std::string& path) {
303
+ // ! This function is used to manually add children to the proxy.
304
+
305
+ // If the provided path is not a child of the current path, return silently.
306
+ if (!Path::is_child(_path, path)) {
307
+ // TODO: Should an exception be thrown here?
308
+ return;
309
+ }
310
+
311
+ std::scoped_lock lock(_child_access_mutex);
312
+ _children.erase(path);
313
+ }
314
+
315
+ // ----- MESSAGE HANDLING -----
316
+
317
+ void Proxy::message_forward(Message& msg) {
318
+ // If the message is for the current proxy, then forward it to the message handler.
319
+ if (msg.get_path() == _path) {
320
+ // If the message is involves a property change, forward it to the correct interface.
321
+ if (msg.is_signal("org.freedesktop.DBus.Properties", "PropertiesChanged")) {
322
+ Holder interface_h = msg.extract();
323
+ std::string iface_name = interface_h.get_string();
324
+ msg.extract_next();
325
+ Holder changed_properties = msg.extract();
326
+ msg.extract_next();
327
+ Holder invalidated_properties = msg.extract();
328
+
329
+ // If the interface is not loaded, then ignore the message.
330
+ if (!interface_exists(iface_name)) {
331
+ return;
332
+ }
333
+
334
+ interface_get(iface_name)->signal_property_changed(changed_properties, invalidated_properties);
335
+
336
+ } else if (interface_exists(msg.get_interface())) {
337
+ interface_get(msg.get_interface())->message_handle(msg);
338
+ }
339
+
340
+ return;
341
+ }
342
+
343
+ // If the message is for a child proxy or a descendant, forward it to that child proxy.
344
+ for (auto& [child_path, child] : _children) {
345
+ if (child_path == msg.get_path()) {
346
+ child->message_forward(msg);
347
+
348
+ if (msg.get_type() == Message::Type::SIGNAL) {
349
+ child->on_signal_received();
350
+ }
351
+
352
+ return;
353
+ } else if (Path::is_descendant(child_path, msg.get_path())) {
354
+ child->message_forward(msg);
355
+ return;
356
+ }
357
+ }
358
+ }
359
+
360
+ void Proxy::message_handle(Message& msg) {
361
+ bool handled = false;
362
+
363
+ if (interface_exists(msg.get_interface())) {
364
+ interface_get(msg.get_interface())->message_handle(msg);
365
+ handled = true;
366
+ }
367
+
368
+ if (msg.get_type() == Message::Type::SIGNAL) {
369
+ on_signal_received();
370
+ }
371
+
372
+ if (!handled) {
373
+ LOG_ERROR("Unhandled message: {}", msg.to_string());
374
+ }
375
+ }