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 @@
1
+ #include <AvailabilityMacros.h>
@@ -0,0 +1,43 @@
1
+
2
+ #ifndef SIMPLECBLE_EXPORT_H
3
+ #define SIMPLECBLE_EXPORT_H
4
+
5
+ #ifdef SIMPLECBLE_STATIC_DEFINE
6
+ # define SIMPLECBLE_EXPORT
7
+ # define SIMPLECBLE_NO_EXPORT
8
+ #else
9
+ # ifndef SIMPLECBLE_EXPORT
10
+ # ifdef simpleble_EXPORTS
11
+ /* We are building this library */
12
+ # define SIMPLECBLE_EXPORT
13
+ # else
14
+ /* We are using this library */
15
+ # define SIMPLECBLE_EXPORT
16
+ # endif
17
+ # endif
18
+
19
+ # ifndef SIMPLECBLE_NO_EXPORT
20
+ # define SIMPLECBLE_NO_EXPORT
21
+ # endif
22
+ #endif
23
+
24
+ #ifndef SIMPLECBLE_DEPRECATED
25
+ # define SIMPLECBLE_DEPRECATED __attribute__ ((__deprecated__))
26
+ #endif
27
+
28
+ #ifndef SIMPLECBLE_DEPRECATED_EXPORT
29
+ # define SIMPLECBLE_DEPRECATED_EXPORT SIMPLECBLE_EXPORT SIMPLECBLE_DEPRECATED
30
+ #endif
31
+
32
+ #ifndef SIMPLECBLE_DEPRECATED_NO_EXPORT
33
+ # define SIMPLECBLE_DEPRECATED_NO_EXPORT SIMPLECBLE_NO_EXPORT SIMPLECBLE_DEPRECATED
34
+ #endif
35
+
36
+ /* NOLINTNEXTLINE(readability-avoid-unconditional-preprocessor-if) */
37
+ #if 0 /* DEFINE_NO_DEPRECATED */
38
+ # ifndef SIMPLECBLE_NO_DEPRECATED
39
+ # define SIMPLECBLE_NO_DEPRECATED
40
+ # endif
41
+ #endif
42
+
43
+ #endif /* SIMPLECBLE_EXPORT_H */
@@ -0,0 +1,43 @@
1
+
2
+ #ifndef SIMPLEBLE_EXPORT_H
3
+ #define SIMPLEBLE_EXPORT_H
4
+
5
+ #ifdef SIMPLEBLE_STATIC_DEFINE
6
+ # define SIMPLEBLE_EXPORT
7
+ # define SIMPLEBLE_NO_EXPORT
8
+ #else
9
+ # ifndef SIMPLEBLE_EXPORT
10
+ # ifdef simpleble_EXPORTS
11
+ /* We are building this library */
12
+ # define SIMPLEBLE_EXPORT
13
+ # else
14
+ /* We are using this library */
15
+ # define SIMPLEBLE_EXPORT
16
+ # endif
17
+ # endif
18
+
19
+ # ifndef SIMPLEBLE_NO_EXPORT
20
+ # define SIMPLEBLE_NO_EXPORT
21
+ # endif
22
+ #endif
23
+
24
+ #ifndef SIMPLEBLE_DEPRECATED
25
+ # define SIMPLEBLE_DEPRECATED __attribute__ ((__deprecated__))
26
+ #endif
27
+
28
+ #ifndef SIMPLEBLE_DEPRECATED_EXPORT
29
+ # define SIMPLEBLE_DEPRECATED_EXPORT SIMPLEBLE_EXPORT SIMPLEBLE_DEPRECATED
30
+ #endif
31
+
32
+ #ifndef SIMPLEBLE_DEPRECATED_NO_EXPORT
33
+ # define SIMPLEBLE_DEPRECATED_NO_EXPORT SIMPLEBLE_NO_EXPORT SIMPLEBLE_DEPRECATED
34
+ #endif
35
+
36
+ /* NOLINTNEXTLINE(readability-avoid-unconditional-preprocessor-if) */
37
+ #if 0 /* DEFINE_NO_DEPRECATED */
38
+ # ifndef SIMPLEBLE_NO_DEPRECATED
39
+ # define SIMPLEBLE_NO_DEPRECATED
40
+ # endif
41
+ #endif
42
+
43
+ #endif /* SIMPLEBLE_EXPORT_H */
@@ -0,0 +1,222 @@
1
+ #ifndef KVN_BYTEARRAY_H
2
+ #define KVN_BYTEARRAY_H
3
+
4
+ #include <cstdint>
5
+ #include <cstring>
6
+ #include <iomanip>
7
+ #include <iostream>
8
+ #include <memory>
9
+ #include <sstream>
10
+ #include <stdexcept>
11
+ #include <vector>
12
+
13
+ namespace kvn {
14
+
15
+ /**
16
+ * @class bytearray
17
+ * @brief A class to handle byte arrays and their conversion from/to hex strings.
18
+ */
19
+ class bytearray {
20
+ public:
21
+ /**
22
+ * @brief Default constructor.
23
+ */
24
+ bytearray() = default;
25
+
26
+ /**
27
+ * @brief Constructs byte array from a vector of uint8_t.
28
+ * @param vec A vector of uint8_t.
29
+ */
30
+ bytearray(const std::vector<uint8_t>& vec) : data_(vec) {}
31
+
32
+ /**
33
+ * @brief Constructs byte array from a raw pointer and size.
34
+ * @param ptr A pointer to uint8_t data.
35
+ * @param size The size of the data.
36
+ */
37
+ bytearray(const uint8_t* ptr, size_t size) : data_(ptr, ptr + size) {}
38
+
39
+ /**
40
+ * @brief Constructs byte array from iterators.
41
+ * @tparam InputIt Iterator type.
42
+ * @param first Iterator to the first element.
43
+ * @param last Iterator to one past the last element.
44
+ */
45
+ template <typename InputIt>
46
+ bytearray(InputIt first, InputIt last) : data_(first, last) {}
47
+
48
+ /**
49
+ * @brief Constructs byte array from a std::string.
50
+ * @param byteArr A string containing byte data.
51
+ */
52
+ bytearray(const std::string& byteArr) : data_(byteArr.begin(), byteArr.end()) {}
53
+
54
+ /**
55
+ * @brief Constructs byte array from a C-style string and size.
56
+ * @param byteArr A C-style string.
57
+ * @param size The size of the string.
58
+ */
59
+ bytearray(const char* byteArr, size_t size) : bytearray(std::string(byteArr, size)) {}
60
+
61
+ /**
62
+ * @brief Constructs byte array from a C-style string.
63
+ * @param byteArr A C-style string.
64
+ */
65
+ bytearray(const char* byteArr) : bytearray(std::string(byteArr)) {}
66
+
67
+ /**
68
+ * @brief Constructs a byte array of specified size, initialized with zeros.
69
+ * @param size The number of bytes to allocate.
70
+ */
71
+ explicit bytearray(size_t size) : data_(size) {}
72
+
73
+ /**
74
+ * @brief Creates a ByteArray from a hex string.
75
+ *
76
+ * Case is ignored and the string may have a '0x' hex prefix or not.
77
+ *
78
+ * @param hexStr A string containing hex data.
79
+ * @return A ByteArray object.
80
+ * @throws std::invalid_argument If the hex string contains non-hexadecimal characters.
81
+ * @throws std::length_error If the hex string length is not even.
82
+ */
83
+ static bytearray fromHex(const std::string& hexStr) {
84
+ std::string cleanString(hexStr);
85
+
86
+ // Check and skip the '0x' prefix if present
87
+ if (cleanString.size() >= 2 && cleanString.substr(0, 2) == "0x") {
88
+ cleanString = cleanString.substr(2);
89
+ }
90
+
91
+ size_t size = cleanString.size();
92
+ if (size % 2 != 0) {
93
+ throw std::length_error("Hex string length must be even.");
94
+ }
95
+
96
+ bytearray byteArray;
97
+ byteArray.data_.reserve(size / 2);
98
+
99
+ for (size_t i = 0; i < size; i += 2) {
100
+ uint8_t byte = static_cast<uint8_t>(std::stoi(cleanString.substr(i, 2), nullptr, 16));
101
+ byteArray.data_.push_back(byte);
102
+ }
103
+
104
+ return byteArray;
105
+ }
106
+
107
+ /**
108
+ * @overload
109
+ */
110
+ static bytearray fromHex(const char* byteArr) { return fromHex(std::string(byteArr)); }
111
+
112
+ /**
113
+ * @overload
114
+ */
115
+ static bytearray fromHex(const char* byteArr, size_t size) { return fromHex(std::string(byteArr, size)); }
116
+
117
+ /**
118
+ * @brief Converts the byte array to a lowercase hex string without '0x' prefix.
119
+ * @param spacing Whether to include spaces between bytes.
120
+ *
121
+ * @return A hex string representation of the byte array.
122
+ */
123
+ std::string toHex(bool spacing = false) const {
124
+ std::ostringstream oss;
125
+ for (auto byte : data_) {
126
+ oss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte);
127
+ if (spacing) {
128
+ oss << " ";
129
+ }
130
+ }
131
+ return oss.str();
132
+ }
133
+
134
+ /**
135
+ * @brief Slices the byte array from a specified start index to an end index.
136
+ *
137
+ * This method creates a new byte array containing bytes from the specified range.
138
+ * The start index is inclusive, while the end index is exclusive.
139
+ *
140
+ * @param start The starting index from which to begin slicing.
141
+ * @param end The ending index up to which to slice (exclusive).
142
+ * @return byte array A new byte array containing the sliced segment.
143
+ * @throws std::out_of_range If the start index is greater than the end index or if the end index is out of bounds.
144
+ */
145
+ bytearray slice(size_t start, size_t end) const {
146
+ if (start > end || end > data_.size()) {
147
+ throw std::out_of_range("Invalid slice range");
148
+ }
149
+ return bytearray(std::vector<uint8_t>(data_.begin() + start, data_.begin() + end));
150
+ }
151
+
152
+ /**
153
+ * @brief Slices the byte array from a specified start index to the end of the array.
154
+ *
155
+ * This method creates a new byte array containing all bytes from the specified start index to the end of the
156
+ * byte array.
157
+ *
158
+ * @param start The starting index from which to begin slicing.
159
+ * @return byte array A new byte array containing the sliced segment from the start index to the end.
160
+ * @throws std::out_of_range If the start index is out of the bounds of the byte array.
161
+ */
162
+ bytearray slice_from(size_t start) const { return slice(start, data_.size()); }
163
+
164
+ /**
165
+ * @brief Slices the byte array from the beginning to a specified end index.
166
+ *
167
+ * This method creates a new byte array containing all bytes from the beginning of the byte array to the specified
168
+ * end index.
169
+ *
170
+ * @param end The ending index up to which to slice (exclusive).
171
+ * @return byte array A new byte array containing the sliced segment from the beginning to the end index.
172
+ * @throws std::out_of_range If the end index is out of the bounds of the byte array.
173
+ */
174
+ bytearray slice_to(size_t end) const { return slice(0, end); }
175
+
176
+ /**
177
+ * @brief Overloaded stream insertion operator for byte array.
178
+ * @param os The output stream.
179
+ * @param byteArray The byte array object.
180
+ * @return The output stream.
181
+ */
182
+ friend std::ostream& operator<<(std::ostream& os, const bytearray& byteArray) {
183
+ os << byteArray.toHex(true);
184
+ return os;
185
+ }
186
+
187
+ /**
188
+ * @brief Conversion operator to convert byte array to std::string.
189
+ *
190
+ * @note This is provided to support code that relies on byte array
191
+ * being representd as a string.
192
+ * @return String containing the raw bytes of the byte array
193
+ */
194
+ operator std::string() const { return std::string(data_.begin(), data_.end()); }
195
+
196
+ /**
197
+ * @brief Conversion operator to convert byte array to std::vector<uint8_t>.
198
+ * @return Vector containing the raw bytes of the byte array
199
+ */
200
+ operator std::vector<uint8_t>() const { return data_; }
201
+
202
+ //! @cond Doxygen_Suppress
203
+ // Expose vector-like functionality
204
+ size_t size() const { return data_.size(); }
205
+ const uint8_t* data() const { return data_.data(); }
206
+ uint8_t* data() { return data_.data(); }
207
+ bool empty() const { return data_.empty(); }
208
+ void clear() { data_.clear(); }
209
+ uint8_t& operator[](size_t index) { return data_[index]; }
210
+ const uint8_t& operator[](size_t index) const { return data_[index]; }
211
+ void push_back(uint8_t byte) { data_.push_back(byte); }
212
+ auto begin() const { return data_.begin(); }
213
+ auto end() const { return data_.end(); }
214
+ //! @endcond
215
+
216
+ private:
217
+ std::vector<uint8_t> data_;
218
+ };
219
+
220
+ } // namespace kvn
221
+
222
+ #endif // KVN_BYTEARRAY_H
@@ -0,0 +1,66 @@
1
+ /*
2
+ * SPDX-FileCopyrightText: 2022 Kevin Dewald <kevin@dewald.me>
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+
7
+ #ifndef KVN_SAFE_CALLBACK_HPP
8
+ #define KVN_SAFE_CALLBACK_HPP
9
+
10
+ #include <atomic>
11
+ #include <functional>
12
+ #include <memory>
13
+ #include <mutex>
14
+
15
+ namespace kvn {
16
+
17
+ template <typename _Signature>
18
+ class safe_callback;
19
+
20
+ template <class _Res, class... _ArgTypes>
21
+ class safe_callback<_Res(_ArgTypes...)> {
22
+ public:
23
+ safe_callback() = default;
24
+
25
+ // Remove copy constructor and copy assignment
26
+ safe_callback(const safe_callback&) = delete;
27
+ safe_callback& operator=(const safe_callback&) = delete;
28
+
29
+ virtual ~safe_callback() { unload(); };
30
+
31
+ void load(std::function<_Res(_ArgTypes...)> callback) {
32
+ if (callback == nullptr) return;
33
+
34
+ std::scoped_lock lock(_mutex);
35
+ _callback = std::move(callback);
36
+ _is_loaded = true;
37
+ }
38
+
39
+ void unload() {
40
+ std::scoped_lock lock(_mutex);
41
+ _callback = nullptr;
42
+ _is_loaded = false;
43
+ }
44
+
45
+ bool is_loaded() const { return _is_loaded; }
46
+
47
+ explicit operator bool() const { return is_loaded(); }
48
+
49
+ _Res operator()(_ArgTypes... arguments) {
50
+ std::scoped_lock lock(_mutex);
51
+ if (_is_loaded) {
52
+ return _callback(std::forward<_ArgTypes&&>(arguments)...);
53
+ } else {
54
+ return _Res();
55
+ }
56
+ }
57
+
58
+ protected:
59
+ std::atomic_bool _is_loaded{false};
60
+ std::function<_Res(_ArgTypes...)> _callback;
61
+ std::recursive_mutex _mutex;
62
+ };
63
+
64
+ } // namespace kvn
65
+
66
+ #endif // KVN_SAFE_CALLBACK_HPP
@@ -0,0 +1,35 @@
1
+ #ifndef LOGFWD_HPP
2
+ #define LOGFWD_HPP
3
+
4
+ #include <string>
5
+
6
+ namespace logfwd {
7
+
8
+ enum level : int {
9
+ NONE = 0,
10
+ FATAL,
11
+ ERROR,
12
+ WARN,
13
+ INFO,
14
+ #pragma push_macro("DEBUG")
15
+ #undef DEBUG
16
+ DEBUG,
17
+ #pragma pop_macro("DEBUG")
18
+ VERBOSE,
19
+ };
20
+
21
+ // clang-format off
22
+
23
+ void receive(
24
+ level level,
25
+ const std::string& module,
26
+ const std::string& file,
27
+ uint32_t line,
28
+ const std::string& function,
29
+ const std::string& message);
30
+
31
+ // clang-format on
32
+
33
+ } // namespace logfwd
34
+
35
+ #endif // LOGFWD_HPP
@@ -0,0 +1,220 @@
1
+ // Formatting library for C++ - dynamic argument lists
2
+ //
3
+ // Copyright (c) 2012 - present, Victor Zverovich
4
+ // All rights reserved.
5
+ //
6
+ // For the license information refer to format.h.
7
+
8
+ #ifndef FMT_ARGS_H_
9
+ #define FMT_ARGS_H_
10
+
11
+ #ifndef FMT_MODULE
12
+ # include <functional> // std::reference_wrapper
13
+ # include <memory> // std::unique_ptr
14
+ # include <vector>
15
+ #endif
16
+
17
+ #include "format.h" // std_string_view
18
+
19
+ FMT_BEGIN_NAMESPACE
20
+ namespace detail {
21
+
22
+ template <typename T> struct is_reference_wrapper : std::false_type {};
23
+ template <typename T>
24
+ struct is_reference_wrapper<std::reference_wrapper<T>> : std::true_type {};
25
+
26
+ template <typename T> auto unwrap(const T& v) -> const T& { return v; }
27
+ template <typename T>
28
+ auto unwrap(const std::reference_wrapper<T>& v) -> const T& {
29
+ return static_cast<const T&>(v);
30
+ }
31
+
32
+ // node is defined outside dynamic_arg_list to workaround a C2504 bug in MSVC
33
+ // 2022 (v17.10.0).
34
+ //
35
+ // Workaround for clang's -Wweak-vtables. Unlike for regular classes, for
36
+ // templates it doesn't complain about inability to deduce single translation
37
+ // unit for placing vtable. So node is made a fake template.
38
+ template <typename = void> struct node {
39
+ virtual ~node() = default;
40
+ std::unique_ptr<node<>> next;
41
+ };
42
+
43
+ class dynamic_arg_list {
44
+ template <typename T> struct typed_node : node<> {
45
+ T value;
46
+
47
+ template <typename Arg>
48
+ FMT_CONSTEXPR typed_node(const Arg& arg) : value(arg) {}
49
+
50
+ template <typename Char>
51
+ FMT_CONSTEXPR typed_node(const basic_string_view<Char>& arg)
52
+ : value(arg.data(), arg.size()) {}
53
+ };
54
+
55
+ std::unique_ptr<node<>> head_;
56
+
57
+ public:
58
+ template <typename T, typename Arg> auto push(const Arg& arg) -> const T& {
59
+ auto new_node = std::unique_ptr<typed_node<T>>(new typed_node<T>(arg));
60
+ auto& value = new_node->value;
61
+ new_node->next = std::move(head_);
62
+ head_ = std::move(new_node);
63
+ return value;
64
+ }
65
+ };
66
+ } // namespace detail
67
+
68
+ /**
69
+ * A dynamic list of formatting arguments with storage.
70
+ *
71
+ * It can be implicitly converted into `fmt::basic_format_args` for passing
72
+ * into type-erased formatting functions such as `fmt::vformat`.
73
+ */
74
+ template <typename Context> class dynamic_format_arg_store {
75
+ private:
76
+ using char_type = typename Context::char_type;
77
+
78
+ template <typename T> struct need_copy {
79
+ static constexpr detail::type mapped_type =
80
+ detail::mapped_type_constant<T, char_type>::value;
81
+
82
+ enum {
83
+ value = !(detail::is_reference_wrapper<T>::value ||
84
+ std::is_same<T, basic_string_view<char_type>>::value ||
85
+ std::is_same<T, detail::std_string_view<char_type>>::value ||
86
+ (mapped_type != detail::type::cstring_type &&
87
+ mapped_type != detail::type::string_type &&
88
+ mapped_type != detail::type::custom_type))
89
+ };
90
+ };
91
+
92
+ template <typename T>
93
+ using stored_t = conditional_t<
94
+ std::is_convertible<T, std::basic_string<char_type>>::value &&
95
+ !detail::is_reference_wrapper<T>::value,
96
+ std::basic_string<char_type>, T>;
97
+
98
+ // Storage of basic_format_arg must be contiguous.
99
+ std::vector<basic_format_arg<Context>> data_;
100
+ std::vector<detail::named_arg_info<char_type>> named_info_;
101
+
102
+ // Storage of arguments not fitting into basic_format_arg must grow
103
+ // without relocation because items in data_ refer to it.
104
+ detail::dynamic_arg_list dynamic_args_;
105
+
106
+ friend class basic_format_args<Context>;
107
+
108
+ auto data() const -> const basic_format_arg<Context>* {
109
+ return named_info_.empty() ? data_.data() : data_.data() + 1;
110
+ }
111
+
112
+ template <typename T> void emplace_arg(const T& arg) {
113
+ data_.emplace_back(arg);
114
+ }
115
+
116
+ template <typename T>
117
+ void emplace_arg(const detail::named_arg<char_type, T>& arg) {
118
+ if (named_info_.empty())
119
+ data_.insert(data_.begin(), basic_format_arg<Context>(nullptr, 0));
120
+ data_.emplace_back(detail::unwrap(arg.value));
121
+ auto pop_one = [](std::vector<basic_format_arg<Context>>* data) {
122
+ data->pop_back();
123
+ };
124
+ std::unique_ptr<std::vector<basic_format_arg<Context>>, decltype(pop_one)>
125
+ guard{&data_, pop_one};
126
+ named_info_.push_back({arg.name, static_cast<int>(data_.size() - 2u)});
127
+ data_[0] = {named_info_.data(), named_info_.size()};
128
+ guard.release();
129
+ }
130
+
131
+ public:
132
+ constexpr dynamic_format_arg_store() = default;
133
+
134
+ operator basic_format_args<Context>() const {
135
+ return basic_format_args<Context>(data(), static_cast<int>(data_.size()),
136
+ !named_info_.empty());
137
+ }
138
+
139
+ /**
140
+ * Adds an argument into the dynamic store for later passing to a formatting
141
+ * function.
142
+ *
143
+ * Note that custom types and string types (but not string views) are copied
144
+ * into the store dynamically allocating memory if necessary.
145
+ *
146
+ * **Example**:
147
+ *
148
+ * fmt::dynamic_format_arg_store<fmt::format_context> store;
149
+ * store.push_back(42);
150
+ * store.push_back("abc");
151
+ * store.push_back(1.5f);
152
+ * std::string result = fmt::vformat("{} and {} and {}", store);
153
+ */
154
+ template <typename T> void push_back(const T& arg) {
155
+ if (detail::const_check(need_copy<T>::value))
156
+ emplace_arg(dynamic_args_.push<stored_t<T>>(arg));
157
+ else
158
+ emplace_arg(detail::unwrap(arg));
159
+ }
160
+
161
+ /**
162
+ * Adds a reference to the argument into the dynamic store for later passing
163
+ * to a formatting function.
164
+ *
165
+ * **Example**:
166
+ *
167
+ * fmt::dynamic_format_arg_store<fmt::format_context> store;
168
+ * char band[] = "Rolling Stones";
169
+ * store.push_back(std::cref(band));
170
+ * band[9] = 'c'; // Changing str affects the output.
171
+ * std::string result = fmt::vformat("{}", store);
172
+ * // result == "Rolling Scones"
173
+ */
174
+ template <typename T> void push_back(std::reference_wrapper<T> arg) {
175
+ static_assert(
176
+ need_copy<T>::value,
177
+ "objects of built-in types and string views are always copied");
178
+ emplace_arg(arg.get());
179
+ }
180
+
181
+ /**
182
+ * Adds named argument into the dynamic store for later passing to a
183
+ * formatting function. `std::reference_wrapper` is supported to avoid
184
+ * copying of the argument. The name is always copied into the store.
185
+ */
186
+ template <typename T>
187
+ void push_back(const detail::named_arg<char_type, T>& arg) {
188
+ const char_type* arg_name =
189
+ dynamic_args_.push<std::basic_string<char_type>>(arg.name).c_str();
190
+ if (detail::const_check(need_copy<T>::value)) {
191
+ emplace_arg(
192
+ fmt::arg(arg_name, dynamic_args_.push<stored_t<T>>(arg.value)));
193
+ } else {
194
+ emplace_arg(fmt::arg(arg_name, arg.value));
195
+ }
196
+ }
197
+
198
+ /// Erase all elements from the store.
199
+ void clear() {
200
+ data_.clear();
201
+ named_info_.clear();
202
+ dynamic_args_ = {};
203
+ }
204
+
205
+ /// Reserves space to store at least `new_cap` arguments including
206
+ /// `new_cap_named` named arguments.
207
+ void reserve(size_t new_cap, size_t new_cap_named) {
208
+ FMT_ASSERT(new_cap >= new_cap_named,
209
+ "set of arguments includes set of named arguments");
210
+ data_.reserve(new_cap);
211
+ named_info_.reserve(new_cap_named);
212
+ }
213
+
214
+ /// Returns the number of elements in the store.
215
+ size_t size() const noexcept { return data_.size(); }
216
+ };
217
+
218
+ FMT_END_NAMESPACE
219
+
220
+ #endif // FMT_ARGS_H_