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,52 @@
1
+ #include <simpledbus/base/Logging.h>
2
+ #include "kvn/logfwd.hpp"
3
+
4
+ #ifndef SIMPLEDBUS_LOG_LEVEL
5
+ #warning "SIMPLEDBUS_LOG_LEVEL not defined, using default value: ERROR"
6
+ #define SIMPLEDBUS_LOG_LEVEL ERROR
7
+ #endif
8
+
9
+ static const logfwd::level log_level = logfwd::level::SIMPLEDBUS_LOG_LEVEL;
10
+
11
+ namespace SimpleDBus {
12
+
13
+ void log_fatal(const std::string& file, uint32_t line, const std::string& function, const std::string& message) {
14
+ if (log_level >= logfwd::level::FATAL) {
15
+ logfwd::receive(logfwd::level::FATAL, "SimpleDBus", file, line, function, message);
16
+ }
17
+ }
18
+
19
+ void log_error(const std::string& file, uint32_t line, const std::string& function, const std::string& message) {
20
+ if (log_level >= logfwd::level::ERROR) {
21
+ logfwd::receive(logfwd::level::ERROR, "SimpleDBus", file, line, function, message);
22
+ }
23
+ }
24
+
25
+ void log_warn(const std::string& file, uint32_t line, const std::string& function, const std::string& message) {
26
+ if (log_level >= logfwd::level::WARN) {
27
+ logfwd::receive(logfwd::level::WARN, "SimpleDBus", file, line, function, message);
28
+ }
29
+ }
30
+
31
+ void log_info(const std::string& file, uint32_t line, const std::string& function, const std::string& message) {
32
+ if (log_level >= logfwd::level::INFO) {
33
+ logfwd::receive(logfwd::level::INFO, "SimpleDBus", file, line, function, message);
34
+ }
35
+ }
36
+
37
+ void log_debug(const std::string& file, uint32_t line, const std::string& function, const std::string& message) {
38
+ if (log_level >= logfwd::level::DEBUG) {
39
+ logfwd::receive(logfwd::level::DEBUG, "SimpleDBus", file, line, function, message);
40
+ }
41
+ }
42
+
43
+ void log_verbose(const std::string& file, uint32_t line, const std::string& function, const std::string& message) {
44
+ if (log_level >= logfwd::level::VERBOSE) {
45
+ logfwd::receive(logfwd::level::VERBOSE, "SimpleDBus", file, line, function, message);
46
+ }
47
+ }
48
+
49
+ } // namespace SimpleDBus
50
+
51
+ __attribute__((weak)) void logfwd::receive(logfwd::level level, const std::string& module, const std::string& file,
52
+ uint32_t line, const std::string& function, const std::string& message) {}
@@ -0,0 +1,622 @@
1
+ #include <simpledbus/base/Message.h>
2
+
3
+ #include <sstream>
4
+
5
+ using namespace SimpleDBus;
6
+
7
+ #define MESSAGE_DICT_APPEND_KEY_NUM(key_sig, dict_contents) \
8
+ for (auto& [key, value] : dict_contents) { \
9
+ DBusMessageIter entry_iter; \
10
+ dbus_message_iter_open_container(&sub_iter, DBUS_TYPE_DICT_ENTRY, NULL, &entry_iter); \
11
+ dbus_message_iter_append_basic(&entry_iter, key_sig, &key); \
12
+ _append_argument(&entry_iter, value, value_sig); \
13
+ dbus_message_iter_close_container(&sub_iter, &entry_iter); \
14
+ }
15
+
16
+ #define MESSAGE_DICT_APPEND_KEY_STR(key_sig, dict_contents) \
17
+ for (auto& [key, value] : dict_contents) { \
18
+ const char* p_value = key.c_str(); \
19
+ DBusMessageIter entry_iter; \
20
+ dbus_message_iter_open_container(&sub_iter, DBUS_TYPE_DICT_ENTRY, NULL, &entry_iter); \
21
+ dbus_message_iter_append_basic(&entry_iter, key_sig, &p_value); \
22
+ _append_argument(&entry_iter, value, value_sig); \
23
+ dbus_message_iter_close_container(&sub_iter, &entry_iter); \
24
+ }
25
+
26
+ std::atomic_int32_t Message::_creation_counter = 0;
27
+
28
+ Message::Message() {}
29
+
30
+ Message::~Message() {
31
+ if (is_valid()) {
32
+ _safe_delete();
33
+ }
34
+ }
35
+
36
+ Message::Message(Message&& other) noexcept
37
+ : _indent(other._indent),
38
+ _unique_id(other._unique_id),
39
+ _iter(std::move(other._iter)),
40
+ _iter_initialized(other._iter_initialized),
41
+ _is_extracted(other._is_extracted),
42
+ _extracted(std::move(other._extracted)),
43
+ _msg(other._msg),
44
+ _arguments(std::move(other._arguments)) {
45
+ // Move constructor: Transfer ownership of resources from 'other' to this object.
46
+ // After the move, 'other' will be left in a valid but unspecified state.
47
+
48
+ // Invalidate the moved-from object
49
+ other._invalidate();
50
+ }
51
+
52
+ Message::Message(const Message& other)
53
+ : _indent(other._indent),
54
+ _unique_id(_creation_counter++),
55
+ _is_extracted(other._is_extracted),
56
+ _extracted(other._extracted),
57
+ _arguments(other._arguments) {
58
+ // Copy constructor: Create a new Message as a deep copy of 'other'.
59
+ // If 'other' is valid, all its contents are duplicated.
60
+
61
+ if (other._msg) {
62
+ _msg = dbus_message_copy(other._msg);
63
+ if (_msg == nullptr) {
64
+ throw std::runtime_error("Failed to copy DBusMessage in copy constructor");
65
+ }
66
+ } else {
67
+ _msg = nullptr;
68
+ }
69
+ }
70
+
71
+ Message& Message::operator=(Message&& other) noexcept {
72
+ // Move assignment operator: Transfer ownership of resources from 'other' to this object.
73
+ // Any existing resources in this object are safely deleted before the transfer.
74
+ // After the move, 'other' will be left in a valid but unspecified state.
75
+
76
+ if (this != &other) {
77
+ _safe_delete(); // Clean up existing resources
78
+
79
+ // Transfer ownership
80
+ _indent = other._indent;
81
+ _unique_id = other._unique_id;
82
+ _iter = other._iter;
83
+ _iter_initialized = other._iter_initialized;
84
+ _is_extracted = other._is_extracted;
85
+ _extracted = std::move(other._extracted);
86
+ _msg = other._msg;
87
+ _arguments = std::move(other._arguments);
88
+
89
+ // Invalidate the moved-from object
90
+ other._invalidate();
91
+ }
92
+ return *this;
93
+ }
94
+
95
+ Message& Message::operator=(const Message& other) {
96
+ // Copy assignment operator: Replace the contents of this Message with a deep copy of 'other'.
97
+ // Any existing resources in this object are safely deleted before the copy.
98
+ // If 'other' is valid, all its contents are duplicated.
99
+
100
+ if (this != &other) {
101
+ _safe_delete(); // Clean up existing resources
102
+
103
+ _indent = other._indent;
104
+ _unique_id = _creation_counter++;
105
+ _is_extracted = other._is_extracted;
106
+ _extracted = other._extracted;
107
+ _arguments = other._arguments;
108
+
109
+ if (other._msg) {
110
+ _msg = dbus_message_copy(other._msg);
111
+ if (_msg == nullptr) {
112
+ throw std::runtime_error("Failed to copy DBusMessage in copy assignment");
113
+ }
114
+ } else {
115
+ _msg = nullptr;
116
+ }
117
+ }
118
+ return *this;
119
+ }
120
+
121
+ Message::operator DBusMessage*() const { return _msg; }
122
+
123
+ bool Message::is_valid() const { return _msg != nullptr; }
124
+
125
+ void Message::_append_argument(DBusMessageIter* iter, const Holder& argument, const std::string& signature) {
126
+ switch (signature[0]) {
127
+ case DBUS_TYPE_BYTE: {
128
+ uint8_t value = argument.get_byte();
129
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, &value);
130
+ break;
131
+ }
132
+ case DBUS_TYPE_BOOLEAN: {
133
+ uint32_t value = static_cast<uint32_t>(argument.get_boolean());
134
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &value);
135
+ break;
136
+ }
137
+ case DBUS_TYPE_INT16: {
138
+ int16_t value = argument.get_int16();
139
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_INT16, &value);
140
+ break;
141
+ }
142
+ case DBUS_TYPE_UINT16: {
143
+ uint16_t value = argument.get_uint16();
144
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &value);
145
+ break;
146
+ }
147
+ case DBUS_TYPE_INT32: {
148
+ int32_t value = argument.get_int32();
149
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &value);
150
+ break;
151
+ }
152
+ case DBUS_TYPE_UINT32: {
153
+ uint32_t value = argument.get_uint32();
154
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &value);
155
+ break;
156
+ }
157
+ case DBUS_TYPE_INT64: {
158
+ int64_t value = argument.get_int64();
159
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_INT64, &value);
160
+ break;
161
+ }
162
+ case DBUS_TYPE_UINT64: {
163
+ uint64_t value = argument.get_uint64();
164
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, &value);
165
+ break;
166
+ }
167
+ case DBUS_TYPE_DOUBLE: {
168
+ double value = argument.get_double();
169
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_DOUBLE, &value);
170
+ break;
171
+ }
172
+ case DBUS_TYPE_STRING: {
173
+ std::string value = argument.get_string();
174
+ const char* p_value = value.c_str();
175
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &p_value);
176
+ break;
177
+ }
178
+ case DBUS_TYPE_OBJECT_PATH: {
179
+ std::string value = argument.get_object_path();
180
+ const char* p_value = value.c_str();
181
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &p_value);
182
+ break;
183
+ }
184
+ case DBUS_TYPE_SIGNATURE: {
185
+ std::string value = argument.get_signature();
186
+ const char* p_value = value.c_str();
187
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_SIGNATURE, &p_value);
188
+ break;
189
+ }
190
+ case DBUS_TYPE_VARIANT: {
191
+ DBusMessageIter sub_iter;
192
+ std::string signature = argument.signature();
193
+ dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, signature.c_str(), &sub_iter);
194
+ _append_argument(&sub_iter, argument, signature);
195
+ dbus_message_iter_close_container(iter, &sub_iter);
196
+ break;
197
+ }
198
+ case DBUS_TYPE_ARRAY: {
199
+ auto sig_next = signature.substr(1);
200
+ DBusMessageIter sub_iter;
201
+ dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, sig_next.c_str(), &sub_iter);
202
+ if (sig_next[0] != DBUS_DICT_ENTRY_BEGIN_CHAR) {
203
+ auto array_contents = argument.get_array();
204
+ for (auto elem : array_contents) {
205
+ _append_argument(&sub_iter, elem, sig_next);
206
+ }
207
+ } else {
208
+ sig_next = sig_next.substr(1, sig_next.length() - 2);
209
+ auto key_sig = sig_next[0];
210
+ auto value_sig = sig_next.substr(1);
211
+
212
+ switch (key_sig) {
213
+ case DBUS_TYPE_BYTE: {
214
+ auto dict_contents = argument.get_dict_uint8();
215
+ MESSAGE_DICT_APPEND_KEY_NUM(key_sig, dict_contents);
216
+ break;
217
+ }
218
+ case DBUS_TYPE_INT16: {
219
+ auto dict_contents = argument.get_dict_int16();
220
+ MESSAGE_DICT_APPEND_KEY_NUM(key_sig, dict_contents);
221
+ break;
222
+ }
223
+ case DBUS_TYPE_UINT16: {
224
+ auto dict_contents = argument.get_dict_uint16();
225
+ MESSAGE_DICT_APPEND_KEY_NUM(key_sig, dict_contents);
226
+ break;
227
+ }
228
+ case DBUS_TYPE_INT32: {
229
+ auto dict_contents = argument.get_dict_int32();
230
+ MESSAGE_DICT_APPEND_KEY_NUM(key_sig, dict_contents);
231
+ break;
232
+ }
233
+ case DBUS_TYPE_UINT32: {
234
+ auto dict_contents = argument.get_dict_uint32();
235
+ MESSAGE_DICT_APPEND_KEY_NUM(key_sig, dict_contents);
236
+ break;
237
+ }
238
+ case DBUS_TYPE_INT64: {
239
+ auto dict_contents = argument.get_dict_int64();
240
+ MESSAGE_DICT_APPEND_KEY_NUM(key_sig, dict_contents);
241
+ break;
242
+ }
243
+ case DBUS_TYPE_UINT64: {
244
+ auto dict_contents = argument.get_dict_uint64();
245
+ MESSAGE_DICT_APPEND_KEY_NUM(key_sig, dict_contents);
246
+ break;
247
+ }
248
+ case DBUS_TYPE_STRING: {
249
+ auto dict_contents = argument.get_dict_string();
250
+ MESSAGE_DICT_APPEND_KEY_STR(key_sig, dict_contents);
251
+ break;
252
+ }
253
+ case DBUS_TYPE_OBJECT_PATH: {
254
+ auto dict_contents = argument.get_dict_object_path();
255
+ MESSAGE_DICT_APPEND_KEY_STR(key_sig, dict_contents);
256
+ break;
257
+ }
258
+ case DBUS_TYPE_SIGNATURE: {
259
+ auto dict_contents = argument.get_dict_signature();
260
+ MESSAGE_DICT_APPEND_KEY_STR(key_sig, dict_contents);
261
+ break;
262
+ }
263
+ }
264
+ }
265
+ dbus_message_iter_close_container(iter, &sub_iter);
266
+ }
267
+ }
268
+ }
269
+
270
+ void Message::append_argument(const Holder& argument, const std::string& signature) {
271
+ dbus_message_iter_init_append(_msg, &_iter);
272
+ _append_argument(&_iter, argument, signature);
273
+ _arguments.push_back(argument);
274
+ }
275
+
276
+ uint32_t Message::get_ref_count() const {
277
+ // NOTE: This is a hack based on the DBusMessage structure documentation that says that
278
+ // the first 4 bytes of the DBusMessage structure is the ref count.
279
+ // https://dbus.freedesktop.org/doc/api/html/structDBusMessage.html#a324c5377e0be18dd84ac519ab2d23f0d
280
+ if (is_valid()) {
281
+ return *reinterpret_cast<uint32_t*>(this->_msg);
282
+ }
283
+ return 0;
284
+ }
285
+
286
+ int32_t Message::get_unique_id() const { return _unique_id; }
287
+
288
+ uint32_t Message::get_serial() const {
289
+ if (is_valid()) {
290
+ return dbus_message_get_serial(_msg);
291
+ }
292
+ return 0;
293
+ }
294
+
295
+ std::string Message::get_signature() {
296
+ if (is_valid() && _iter_initialized) {
297
+ return dbus_message_iter_get_signature(&_iter);
298
+ }
299
+ return "";
300
+ }
301
+
302
+ Message::Type Message::get_type() const {
303
+ if (is_valid()) {
304
+ return static_cast<Message::Type>(dbus_message_get_type(_msg));
305
+ }
306
+ return Message::Type::INVALID;
307
+ }
308
+
309
+ std::string Message::get_path() const {
310
+ if (is_valid() && (get_type() == Message::Type::SIGNAL || get_type() == Message::Type::METHOD_CALL)) {
311
+ return dbus_message_get_path(_msg);
312
+ }
313
+ return "";
314
+ }
315
+
316
+ std::string Message::get_interface() const {
317
+ if (is_valid()) {
318
+ return dbus_message_get_interface(_msg);
319
+ }
320
+ return "";
321
+ }
322
+
323
+ std::string Message::get_member() const {
324
+ if (is_valid() && get_type() == Message::Type::METHOD_CALL) {
325
+ return dbus_message_get_member(_msg);
326
+ }
327
+ return "";
328
+ }
329
+
330
+ bool Message::is_signal(const std::string& interface, const std::string& signal_name) const {
331
+ return is_valid() && dbus_message_is_signal(_msg, interface.c_str(), signal_name.c_str());
332
+ }
333
+
334
+ bool Message::is_method_call(const std::string& interface, const std::string& method) const {
335
+ return get_type() == Type::METHOD_CALL && get_interface() == interface && get_member() == method;
336
+ }
337
+
338
+ static const char* type_to_name(int message_type) {
339
+ switch (message_type) {
340
+ case DBUS_MESSAGE_TYPE_SIGNAL:
341
+ return "signal";
342
+ case DBUS_MESSAGE_TYPE_METHOD_CALL:
343
+ return "method call";
344
+ case DBUS_MESSAGE_TYPE_METHOD_RETURN:
345
+ return "method return";
346
+ case DBUS_MESSAGE_TYPE_ERROR:
347
+ return "error";
348
+ default:
349
+ return "(unknown message type)";
350
+ }
351
+ }
352
+
353
+ std::string Message::to_string(bool append_arguments) const {
354
+ if (!is_valid()) {
355
+ return "INVALID";
356
+ }
357
+
358
+ std::ostringstream oss;
359
+
360
+ const char* sender;
361
+ const char* destination;
362
+
363
+ sender = dbus_message_get_sender(_msg);
364
+ sender = sender ? sender : "(null)";
365
+ destination = dbus_message_get_destination(_msg);
366
+ destination = destination ? destination : "(null)";
367
+
368
+ oss << "[" << _unique_id << "] " << type_to_name(dbus_message_get_type(_msg));
369
+ oss << "[" << sender << "->" << destination << "] ";
370
+ oss << dbus_message_get_path(_msg) << " " << dbus_message_get_interface(_msg) << " "
371
+ << dbus_message_get_member(_msg);
372
+
373
+ if (get_type() == Message::Type::METHOD_CALL && append_arguments) {
374
+ oss << std::endl;
375
+ oss << "Arguments: " << std::endl;
376
+ for (const auto& arg : _arguments) {
377
+ oss << arg.represent();
378
+ }
379
+ }
380
+ return oss.str();
381
+ }
382
+
383
+ Holder Message::extract() {
384
+ if (!is_valid()) {
385
+ return Holder();
386
+ }
387
+
388
+ if (!_is_extracted) {
389
+ if (!_iter_initialized) {
390
+ extract_reset();
391
+ }
392
+ _extracted = _extract_generic(&_iter);
393
+ _is_extracted = true;
394
+ }
395
+ return _extracted;
396
+ }
397
+
398
+ void Message::extract_reset() {
399
+ if (is_valid()) {
400
+ dbus_message_iter_init(_msg, &_iter);
401
+ _iter_initialized = true;
402
+ }
403
+ }
404
+
405
+ bool Message::extract_has_next() { return _iter_initialized && dbus_message_iter_has_next(&_iter); }
406
+
407
+ void Message::extract_next() {
408
+ if (extract_has_next()) {
409
+ dbus_message_iter_next(&_iter);
410
+ _is_extracted = false;
411
+ }
412
+ }
413
+
414
+ Holder Message::_extract_bytearray(DBusMessageIter* iter) {
415
+ const unsigned char* bytes;
416
+ int len;
417
+ dbus_message_iter_get_fixed_array(iter, &bytes, &len);
418
+ Holder holder_array = Holder::create_array();
419
+ for (int i = 0; i < len; i++) {
420
+ holder_array.array_append(Holder::create_byte(bytes[i]));
421
+ }
422
+ return holder_array;
423
+ }
424
+
425
+ Holder Message::_extract_array(DBusMessageIter* iter) {
426
+ Holder holder_array = Holder::create_array();
427
+ _indent += 1;
428
+ int current_type = dbus_message_iter_get_arg_type(iter);
429
+ if (current_type == DBUS_TYPE_BYTE) {
430
+ holder_array = _extract_bytearray(iter);
431
+ } else {
432
+ while ((current_type = dbus_message_iter_get_arg_type(iter)) != DBUS_TYPE_INVALID) {
433
+ Holder h = _extract_generic(iter);
434
+ if (h.type() != Holder::NONE) {
435
+ holder_array.array_append(h);
436
+ }
437
+ dbus_message_iter_next(iter);
438
+ }
439
+ }
440
+ _indent -= 1;
441
+ return holder_array;
442
+ }
443
+
444
+ Holder Message::_extract_dict(DBusMessageIter* iter) {
445
+ bool holder_initialized = false;
446
+ Holder holder_dict;
447
+ _indent += 1;
448
+ int current_type;
449
+
450
+ // Loop through all dictionary entries.
451
+ while ((current_type = dbus_message_iter_get_arg_type(iter)) != DBUS_TYPE_INVALID) {
452
+ // Access the dictionary entry
453
+ DBusMessageIter sub;
454
+ dbus_message_iter_recurse(iter, &sub);
455
+
456
+ // Extract the data from the dictionary entry
457
+ Holder key = _extract_generic(&sub);
458
+ dbus_message_iter_next(&sub);
459
+ Holder value = _extract_generic(&sub);
460
+
461
+ // Add the data to the dictionary
462
+ if (!holder_initialized) {
463
+ holder_dict = Holder::create_dict();
464
+ holder_initialized = true;
465
+ }
466
+
467
+ holder_dict.dict_append(key.type(), key.get_contents(), value);
468
+ dbus_message_iter_next(iter);
469
+ }
470
+ _indent -= 1;
471
+ return holder_dict;
472
+ }
473
+
474
+ Holder Message::_extract_generic(DBusMessageIter* iter) {
475
+ int current_type = dbus_message_iter_get_arg_type(iter);
476
+ if (current_type != DBUS_TYPE_INVALID) {
477
+ switch (current_type) {
478
+ case DBUS_TYPE_BYTE: {
479
+ uint8_t contents;
480
+ dbus_message_iter_get_basic(iter, &contents);
481
+ return Holder::create_byte(contents);
482
+ }
483
+ case DBUS_TYPE_BOOLEAN: {
484
+ bool contents;
485
+ dbus_message_iter_get_basic(iter, &contents);
486
+ return Holder::create_boolean(contents);
487
+ }
488
+ case DBUS_TYPE_INT16: {
489
+ int16_t contents;
490
+ dbus_message_iter_get_basic(iter, &contents);
491
+ return Holder::create_int16(contents);
492
+ }
493
+ case DBUS_TYPE_UINT16: {
494
+ uint16_t contents;
495
+ dbus_message_iter_get_basic(iter, &contents);
496
+ return Holder::create_uint16(contents);
497
+ }
498
+ case DBUS_TYPE_INT32: {
499
+ int32_t contents;
500
+ dbus_message_iter_get_basic(iter, &contents);
501
+ return Holder::create_int32(contents);
502
+ }
503
+ case DBUS_TYPE_UINT32: {
504
+ uint32_t contents;
505
+ dbus_message_iter_get_basic(iter, &contents);
506
+ return Holder::create_uint32(contents);
507
+ }
508
+ case DBUS_TYPE_INT64: {
509
+ int64_t contents;
510
+ dbus_message_iter_get_basic(iter, &contents);
511
+ return Holder::create_int64(contents);
512
+ }
513
+ case DBUS_TYPE_UINT64: {
514
+ uint64_t contents;
515
+ dbus_message_iter_get_basic(iter, &contents);
516
+ return Holder::create_uint64(contents);
517
+ }
518
+ case DBUS_TYPE_DOUBLE: {
519
+ double contents;
520
+ dbus_message_iter_get_basic(iter, &contents);
521
+ return Holder::create_double(contents);
522
+ }
523
+ case DBUS_TYPE_STRING: {
524
+ char* contents;
525
+ dbus_message_iter_get_basic(iter, &contents);
526
+ return Holder::create_string(contents);
527
+ }
528
+ case DBUS_TYPE_OBJECT_PATH: {
529
+ char* contents;
530
+ dbus_message_iter_get_basic(iter, &contents);
531
+ return Holder::create_object_path(contents);
532
+ }
533
+ case DBUS_TYPE_SIGNATURE: {
534
+ char* contents;
535
+ dbus_message_iter_get_basic(iter, &contents);
536
+ return Holder::create_signature(contents);
537
+ }
538
+ case DBUS_TYPE_ARRAY: {
539
+ DBusMessageIter sub;
540
+ dbus_message_iter_recurse(iter, &sub);
541
+ int sub_type = dbus_message_iter_get_arg_type(&sub);
542
+ if (sub_type == DBUS_TYPE_DICT_ENTRY) {
543
+ return _extract_dict(&sub);
544
+ } else {
545
+ return _extract_array(&sub);
546
+ }
547
+ }
548
+ case DBUS_TYPE_VARIANT: {
549
+ DBusMessageIter sub;
550
+ dbus_message_iter_recurse(iter, &sub);
551
+ _indent += 1;
552
+ Holder h = _extract_generic(&sub);
553
+ _indent -= 1;
554
+ return h;
555
+ }
556
+ }
557
+ }
558
+ return Holder();
559
+ }
560
+
561
+ Message Message::from_retained(DBusMessage* msg) {
562
+ Message message;
563
+ if (msg) {
564
+ dbus_message_ref(msg);
565
+ message._msg = msg;
566
+ message._unique_id = _creation_counter++;
567
+ }
568
+ return message;
569
+ }
570
+
571
+ Message Message::from_acquired(DBusMessage* msg) {
572
+ Message message;
573
+ if (msg) {
574
+ message._msg = msg;
575
+ message._unique_id = _creation_counter++;
576
+ }
577
+ return message;
578
+ }
579
+
580
+ Message Message::create_method_call(const std::string& bus_name, const std::string& path, const std::string& interface,
581
+ const std::string& method) {
582
+ DBusMessage* msg = dbus_message_new_method_call(bus_name.c_str(), path.c_str(), interface.c_str(), method.c_str());
583
+ return Message::from_acquired(msg);
584
+ }
585
+
586
+ Message Message::create_method_return(const Message& msg) {
587
+ DBusMessage* msg_return = dbus_message_new_method_return(msg._msg);
588
+ return Message::from_acquired(msg_return);
589
+ }
590
+
591
+ Message Message::create_error(const Message& msg, const std::string& error_name, const std::string& error_message) {
592
+ DBusMessage* msg_error = dbus_message_new_error(msg._msg, error_name.c_str(), error_message.c_str());
593
+ return Message::from_acquired(msg_error);
594
+ }
595
+
596
+ Message Message::create_signal(const std::string& path, const std::string& interface, const std::string& signal) {
597
+ DBusMessage* msg_signal = dbus_message_new_signal(path.c_str(), interface.c_str(), signal.c_str());
598
+ return Message::from_acquired(msg_signal);
599
+ }
600
+
601
+ void Message::_invalidate() {
602
+ _unique_id = INVALID_UNIQUE_ID;
603
+ _msg = nullptr;
604
+ _iter_initialized = false;
605
+ _is_extracted = false;
606
+ _extracted = Holder();
607
+
608
+ #ifdef DBUS_MESSAGE_ITER_INIT_CLOSED
609
+ _iter = DBUS_MESSAGE_ITER_INIT_CLOSED;
610
+ #else
611
+ // For older versions of DBus, DBUS_MESSAGE_ITER_INIT_CLOSED is not defined.
612
+ _iter = DBusMessageIter();
613
+ #endif
614
+ _arguments.clear();
615
+ }
616
+
617
+ void Message::_safe_delete() {
618
+ if (is_valid()) {
619
+ dbus_message_unref(this->_msg);
620
+ _invalidate();
621
+ }
622
+ }