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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +88 -0
- data/LICENSE.txt +21 -0
- data/README.md +350 -0
- data/ext/simpleble/extconf.rb +57 -0
- data/ext/simpleble/simpleble_ruby.c +682 -0
- data/lib/simpleble/adapter.rb +10 -0
- data/lib/simpleble/characteristic.rb +36 -0
- data/lib/simpleble/descriptor.rb +8 -0
- data/lib/simpleble/exceptions.rb +25 -0
- data/lib/simpleble/peripheral.rb +64 -0
- data/lib/simpleble/service.rb +16 -0
- data/lib/simpleble/version.rb +3 -0
- data/lib/simpleble.rb +40 -0
- data/vendor/simpleble/build_simplecble/CMakeFiles/4.0.3/CompilerIdCXX/CMakeCXXCompilerId.cpp +920 -0
- data/vendor/simpleble/build_simplecble/CMakeFiles/4.0.3/CompilerIdCXX/apple-sdk.cpp +1 -0
- data/vendor/simpleble/build_simplecble/CMakeFiles/4.1.0/CompilerIdCXX/CMakeCXXCompilerId.cpp +949 -0
- data/vendor/simpleble/build_simplecble/CMakeFiles/4.1.0/CompilerIdCXX/apple-sdk.cpp +1 -0
- data/vendor/simpleble/build_simplecble/export/simplecble/export.h +43 -0
- data/vendor/simpleble/build_simplecble/simpleble/export/simpleble/export.h +43 -0
- data/vendor/simpleble/dependencies/external/kvn/kvn_bytearray.h +222 -0
- data/vendor/simpleble/dependencies/external/kvn/kvn_safe_callback.hpp +66 -0
- data/vendor/simpleble/dependencies/external/kvn/logfwd.hpp +35 -0
- data/vendor/simpleble/dependencies/internal/fmt/args.h +220 -0
- data/vendor/simpleble/dependencies/internal/fmt/base.h +2962 -0
- data/vendor/simpleble/dependencies/internal/fmt/chrono.h +2338 -0
- data/vendor/simpleble/dependencies/internal/fmt/color.h +610 -0
- data/vendor/simpleble/dependencies/internal/fmt/compile.h +539 -0
- data/vendor/simpleble/dependencies/internal/fmt/core.h +5 -0
- data/vendor/simpleble/dependencies/internal/fmt/format-inl.h +1949 -0
- data/vendor/simpleble/dependencies/internal/fmt/format.h +4244 -0
- data/vendor/simpleble/dependencies/internal/fmt/os.h +427 -0
- data/vendor/simpleble/dependencies/internal/fmt/ostream.h +166 -0
- data/vendor/simpleble/dependencies/internal/fmt/printf.h +633 -0
- data/vendor/simpleble/dependencies/internal/fmt/ranges.h +850 -0
- data/vendor/simpleble/dependencies/internal/fmt/std.h +726 -0
- data/vendor/simpleble/dependencies/internal/fmt/xchar.h +373 -0
- data/vendor/simpleble/dependencies/internal/simplejni/Common.hpp +579 -0
- data/vendor/simpleble/dependencies/internal/simplejni/References.hpp +151 -0
- data/vendor/simpleble/dependencies/internal/simplejni/Registry.hpp +183 -0
- data/vendor/simpleble/dependencies/internal/simplejni/VM.hpp +88 -0
- data/vendor/simpleble/examples/simpleble/src/connect.cpp +67 -0
- data/vendor/simpleble/examples/simpleble/src/connect_safe.cpp +91 -0
- data/vendor/simpleble/examples/simpleble/src/list_adapters.cpp +22 -0
- data/vendor/simpleble/examples/simpleble/src/list_adapters_safe.cpp +33 -0
- data/vendor/simpleble/examples/simpleble/src/list_paired.cpp +27 -0
- data/vendor/simpleble/examples/simpleble/src/multiconnect.cpp +60 -0
- data/vendor/simpleble/examples/simpleble/src/notify.cpp +85 -0
- data/vendor/simpleble/examples/simpleble/src/notify_multi.cpp +101 -0
- data/vendor/simpleble/examples/simpleble/src/power_cycle.cpp +43 -0
- data/vendor/simpleble/examples/simpleble/src/read.cpp +82 -0
- data/vendor/simpleble/examples/simpleble/src/scan.cpp +62 -0
- data/vendor/simpleble/examples/simpleble/src/utils.cpp +59 -0
- data/vendor/simpleble/examples/simpleble/src/utils.hpp +27 -0
- data/vendor/simpleble/examples/simpleble/src/write.cpp +81 -0
- data/vendor/simpleble/examples/simplebluez/ble_nus/ble_nus.cpp +138 -0
- data/vendor/simpleble/examples/simplebluez/connect/connect.cpp +119 -0
- data/vendor/simpleble/examples/simplebluez/list_adapters/list_adapters.cpp +44 -0
- data/vendor/simpleble/examples/simplebluez/list_paired/list_paired.cpp +48 -0
- data/vendor/simpleble/examples/simplebluez/notify/notify.cpp +145 -0
- data/vendor/simpleble/examples/simplebluez/pair/pair.cpp +181 -0
- data/vendor/simpleble/examples/simplebluez/read/read.cpp +141 -0
- data/vendor/simpleble/examples/simplebluez/scan/scan.cpp +85 -0
- data/vendor/simpleble/examples/simplecble/c/connect.c +163 -0
- data/vendor/simpleble/examples/simplecble/c/notify.c +217 -0
- data/vendor/simpleble/examples/simplecble/c/scan.c +164 -0
- data/vendor/simpleble/examples/simpledbus/notification.cpp +24 -0
- data/vendor/simpleble/hitl/src/test_sanity.cpp +48 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Adapter.h +102 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/AdapterSafe.h +58 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Advanced.h +50 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Characteristic.h +39 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Config.h +55 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Descriptor.h +30 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Exceptions.h +72 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Logging.h +73 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Peripheral.h +82 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/PeripheralSafe.h +64 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Service.h +34 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/SimpleBLE.h +8 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Types.h +49 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Utils.h +13 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/export.h +43 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/kvn/kvn_bytearray.h +222 -0
- data/vendor/simpleble/install_simplecble/include/simplecble/adapter.h +188 -0
- data/vendor/simpleble/install_simplecble/include/simplecble/logging.h +37 -0
- data/vendor/simpleble/install_simplecble/include/simplecble/peripheral.h +304 -0
- data/vendor/simpleble/install_simplecble/include/simplecble/simpleble.h +21 -0
- data/vendor/simpleble/install_simplecble/include/simplecble/types.h +73 -0
- data/vendor/simpleble/install_simplecble/include/simplecble/utils.h +27 -0
- data/vendor/simpleble/simpleble/include/simpleble/Adapter.h +102 -0
- data/vendor/simpleble/simpleble/include/simpleble/AdapterSafe.h +58 -0
- data/vendor/simpleble/simpleble/include/simpleble/Characteristic.h +39 -0
- data/vendor/simpleble/simpleble/include/simpleble/Config.h +55 -0
- data/vendor/simpleble/simpleble/include/simpleble/Descriptor.h +30 -0
- data/vendor/simpleble/simpleble/include/simpleble/Exceptions.h +72 -0
- data/vendor/simpleble/simpleble/include/simpleble/Logging.h +73 -0
- data/vendor/simpleble/simpleble/include/simpleble/Peripheral.h +82 -0
- data/vendor/simpleble/simpleble/include/simpleble/PeripheralSafe.h +64 -0
- data/vendor/simpleble/simpleble/include/simpleble/Service.h +34 -0
- data/vendor/simpleble/simpleble/include/simpleble/SimpleBLE.h +8 -0
- data/vendor/simpleble/simpleble/include/simpleble/Types.h +49 -0
- data/vendor/simpleble/simpleble/include/simpleble/Utils.h +13 -0
- data/vendor/simpleble/simpleble/include/simpleble_c/adapter.h +188 -0
- data/vendor/simpleble/simpleble/include/simpleble_c/logging.h +37 -0
- data/vendor/simpleble/simpleble/include/simpleble_c/peripheral.h +304 -0
- data/vendor/simpleble/simpleble/include/simpleble_c/simpleble.h +21 -0
- data/vendor/simpleble/simpleble/include/simpleble_c/types.h +73 -0
- data/vendor/simpleble/simpleble/include/simpleble_c/utils.h +27 -0
- data/vendor/simpleble/simpleble/src/CommonUtils.h +63 -0
- data/vendor/simpleble/simpleble/src/Exceptions.cpp +31 -0
- data/vendor/simpleble/simpleble/src/Logging.cpp +136 -0
- data/vendor/simpleble/simpleble/src/LoggingInternal.h +85 -0
- data/vendor/simpleble/simpleble/src/Utils.cpp +24 -0
- data/vendor/simpleble/simpleble/src/backends/android/AdapterAndroid.cpp +101 -0
- data/vendor/simpleble/simpleble/src/backends/android/AdapterAndroid.h +70 -0
- data/vendor/simpleble/simpleble/src/backends/android/BackendAndroid.cpp +40 -0
- data/vendor/simpleble/simpleble/src/backends/android/BackendAndroid.h +20 -0
- data/vendor/simpleble/simpleble/src/backends/android/PeripheralAndroid.cpp +365 -0
- data/vendor/simpleble/simpleble/src/backends/android/PeripheralAndroid.h +90 -0
- data/vendor/simpleble/simpleble/src/backends/android/bridge/BluetoothGattCallback.cpp +432 -0
- data/vendor/simpleble/simpleble/src/backends/android/bridge/BluetoothGattCallback.h +102 -0
- data/vendor/simpleble/simpleble/src/backends/android/bridge/ScanCallback.cpp +142 -0
- data/vendor/simpleble/simpleble/src/backends/android/bridge/ScanCallback.h +55 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothAdapter.cpp +107 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothAdapter.h +55 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothDevice.cpp +68 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothDevice.h +54 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGatt.cpp +115 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGatt.h +75 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattCharacteristic.cpp +142 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattCharacteristic.h +66 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattDescriptor.cpp +67 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattDescriptor.h +46 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattService.cpp +106 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattService.h +47 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/BluetoothScanner.cpp +47 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/BluetoothScanner.h +37 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanRecord.cpp +69 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanRecord.h +41 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanResult.cpp +63 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanResult.h +42 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/os/ParcelUUID.cpp +32 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/os/ParcelUUID.h +30 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/util/SparseArray.cpp +54 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/util/SparseArray.h +37 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Iterator.cpp +36 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Iterator.h +28 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/List.cpp +29 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/List.h +27 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Set.cpp +33 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Set.h +28 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/UUID.cpp +26 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/UUID.h +29 -0
- data/vendor/simpleble/simpleble/src/backends/common/AdapterBase.cpp +53 -0
- data/vendor/simpleble/simpleble/src/backends/common/AdapterBase.h +81 -0
- data/vendor/simpleble/simpleble/src/backends/common/AdapterBaseTypes.h +22 -0
- data/vendor/simpleble/simpleble/src/backends/common/BackendBase.h +20 -0
- data/vendor/simpleble/simpleble/src/backends/common/BackendUtils.h +33 -0
- data/vendor/simpleble/simpleble/src/backends/common/CharacteristicBase.cpp +28 -0
- data/vendor/simpleble/simpleble/src/backends/common/CharacteristicBase.h +38 -0
- data/vendor/simpleble/simpleble/src/backends/common/DescriptorBase.cpp +7 -0
- data/vendor/simpleble/simpleble/src/backends/common/DescriptorBase.h +19 -0
- data/vendor/simpleble/simpleble/src/backends/common/PeripheralBase.h +82 -0
- data/vendor/simpleble/simpleble/src/backends/common/ServiceBase.cpp +18 -0
- data/vendor/simpleble/simpleble/src/backends/common/ServiceBase.h +28 -0
- data/vendor/simpleble/simpleble/src/backends/linux/AdapterLinux.cpp +102 -0
- data/vendor/simpleble/simpleble/src/backends/linux/AdapterLinux.h +55 -0
- data/vendor/simpleble/simpleble/src/backends/linux/BackendBluez.cpp +87 -0
- data/vendor/simpleble/simpleble/src/backends/linux/PeripheralLinux.cpp +376 -0
- data/vendor/simpleble/simpleble/src/backends/linux/PeripheralLinux.h +90 -0
- data/vendor/simpleble/simpleble/src/backends/macos/AdapterBaseMacOS.h +29 -0
- data/vendor/simpleble/simpleble/src/backends/macos/AdapterMac.h +78 -0
- data/vendor/simpleble/simpleble/src/backends/macos/PeripheralBaseMacOS.h +49 -0
- data/vendor/simpleble/simpleble/src/backends/macos/PeripheralMac.h +81 -0
- data/vendor/simpleble/simpleble/src/backends/macos/Utils.h +9 -0
- data/vendor/simpleble/simpleble/src/backends/plain/AdapterPlain.cpp +65 -0
- data/vendor/simpleble/simpleble/src/backends/plain/AdapterPlain.h +49 -0
- data/vendor/simpleble/simpleble/src/backends/plain/BackendPlain.cpp +30 -0
- data/vendor/simpleble/simpleble/src/backends/plain/PeripheralPlain.cpp +159 -0
- data/vendor/simpleble/simpleble/src/backends/plain/PeripheralPlain.h +72 -0
- data/vendor/simpleble/simpleble/src/backends/windows/AdapterWindows.cpp +330 -0
- data/vendor/simpleble/simpleble/src/backends/windows/AdapterWindows.h +89 -0
- data/vendor/simpleble/simpleble/src/backends/windows/BackendWinRT.cpp +67 -0
- data/vendor/simpleble/simpleble/src/backends/windows/BackendWinRT.h +18 -0
- data/vendor/simpleble/simpleble/src/backends/windows/MtaManager.cpp +49 -0
- data/vendor/simpleble/simpleble/src/backends/windows/MtaManager.h +90 -0
- data/vendor/simpleble/simpleble/src/backends/windows/PeripheralWindows.cpp +487 -0
- data/vendor/simpleble/simpleble/src/backends/windows/PeripheralWindows.h +129 -0
- data/vendor/simpleble/simpleble/src/backends/windows/Utils.cpp +146 -0
- data/vendor/simpleble/simpleble/src/backends/windows/Utils.h +47 -0
- data/vendor/simpleble/simpleble/src/builders/BuildVec.h +32 -0
- data/vendor/simpleble/simpleble/src/builders/BuilderBase.h +87 -0
- data/vendor/simpleble/simpleble/src/external/TaskRunner.hpp +99 -0
- data/vendor/simpleble/simpleble/src/external/ThreadRunner.h +52 -0
- data/vendor/simpleble/simpleble/src/external/kvn_safe_callback.hpp +66 -0
- data/vendor/simpleble/simpleble/src/external/kvn_safe_map.hpp +94 -0
- data/vendor/simpleble/simpleble/src/external/kvn_threadrunner.hpp +70 -0
- data/vendor/simpleble/simpleble/src/external/logfwd.hpp +35 -0
- data/vendor/simpleble/simpleble/src/frontends/base/Adapter.cpp +111 -0
- data/vendor/simpleble/simpleble/src/frontends/base/Backend.cpp +83 -0
- data/vendor/simpleble/simpleble/src/frontends/base/Backend.h +76 -0
- data/vendor/simpleble/simpleble/src/frontends/base/Characteristic.cpp +56 -0
- data/vendor/simpleble/simpleble/src/frontends/base/Descriptor.cpp +21 -0
- data/vendor/simpleble/simpleble/src/frontends/base/Peripheral.cpp +113 -0
- data/vendor/simpleble/simpleble/src/frontends/base/Service.cpp +26 -0
- data/vendor/simpleble/simpleble/src/frontends/safe/AdapterSafe.cpp +158 -0
- data/vendor/simpleble/simpleble/src/frontends/safe/PeripheralSafe.cpp +219 -0
- data/vendor/simpleble/simpleble/src_c/adapter.cpp +204 -0
- data/vendor/simpleble/simpleble/src_c/logging.cpp +19 -0
- data/vendor/simpleble/simpleble/src_c/peripheral.cpp +444 -0
- data/vendor/simpleble/simpleble/src_c/simpleble.cpp +5 -0
- data/vendor/simpleble/simpleble/src_c/utils.cpp +15 -0
- data/vendor/simpleble/simpleble/test/src/main.cpp +8 -0
- data/vendor/simpleble/simpleble/test/src/test_bytearray.cpp +246 -0
- data/vendor/simpleble/simpleble/test/src/test_utils.cpp +24 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Adapter.h +46 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Agent.h +52 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Bluez.h +37 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/BluezOrg.h +22 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/BluezOrgBluez.h +26 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/BluezRoot.h +32 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Characteristic.h +46 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Descriptor.h +33 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Device.h +64 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Exceptions.h +43 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Service.h +27 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Types.h +9 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Adapter1.h +49 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Agent1.h +100 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/AgentManager1.h +24 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Battery1.h +32 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Device1.h +62 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattCharacteristic1.h +48 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattDescriptor1.h +41 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattService1.h +28 -0
- data/vendor/simpleble/simplebluez/src/Adapter.cpp +78 -0
- data/vendor/simpleble/simplebluez/src/Agent.cpp +72 -0
- data/vendor/simpleble/simplebluez/src/Bluez.cpp +45 -0
- data/vendor/simpleble/simplebluez/src/BluezOrg.cpp +20 -0
- data/vendor/simpleble/simplebluez/src/BluezOrgBluez.cpp +23 -0
- data/vendor/simpleble/simplebluez/src/BluezRoot.cpp +44 -0
- data/vendor/simpleble/simplebluez/src/Characteristic.cpp +64 -0
- data/vendor/simpleble/simplebluez/src/Descriptor.cpp +27 -0
- data/vendor/simpleble/simplebluez/src/Device.cpp +104 -0
- data/vendor/simpleble/simplebluez/src/Exceptions.cpp +29 -0
- data/vendor/simpleble/simplebluez/src/Logging.cpp +52 -0
- data/vendor/simpleble/simplebluez/src/Logging.h +57 -0
- data/vendor/simpleble/simplebluez/src/Service.cpp +33 -0
- data/vendor/simpleble/simplebluez/src/interfaces/Adapter1.cpp +123 -0
- data/vendor/simpleble/simplebluez/src/interfaces/Agent1.cpp +143 -0
- data/vendor/simpleble/simplebluez/src/interfaces/AgentManager1.cpp +34 -0
- data/vendor/simpleble/simplebluez/src/interfaces/Battery1.cpp +30 -0
- data/vendor/simpleble/simplebluez/src/interfaces/Device1.cpp +170 -0
- data/vendor/simpleble/simplebluez/src/interfaces/GattCharacteristic1.cpp +118 -0
- data/vendor/simpleble/simplebluez/src/interfaces/GattDescriptor1.cpp +78 -0
- data/vendor/simpleble/simplebluez/src/interfaces/GattService1.cpp +28 -0
- data/vendor/simpleble/simplebluez/test/src/helpers/PythonRunner.cpp +53 -0
- data/vendor/simpleble/simplebluez/test/src/helpers/PythonRunner.h +24 -0
- data/vendor/simpleble/simplebluez/test/src/main.cpp +16 -0
- data/vendor/simpleble/simplecble/include/simplecble/adapter.h +188 -0
- data/vendor/simpleble/simplecble/include/simplecble/logging.h +37 -0
- data/vendor/simpleble/simplecble/include/simplecble/peripheral.h +304 -0
- data/vendor/simpleble/simplecble/include/simplecble/simpleble.h +21 -0
- data/vendor/simpleble/simplecble/include/simplecble/types.h +73 -0
- data/vendor/simpleble/simplecble/include/simplecble/utils.h +27 -0
- data/vendor/simpleble/simplecble/src/adapter.cpp +204 -0
- data/vendor/simpleble/simplecble/src/logging.cpp +19 -0
- data/vendor/simpleble/simplecble/src/peripheral.cpp +444 -0
- data/vendor/simpleble/simplecble/src/simpleble.cpp +5 -0
- data/vendor/simpleble/simplecble/src/utils.cpp +15 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/advanced/Interface.h +67 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/advanced/InterfaceRegistry.h +64 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/advanced/Proxy.h +117 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/base/Connection.h +50 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/base/Exceptions.h +56 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/base/Holder.h +147 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/base/Logging.h +57 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/base/Message.h +89 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/base/Path.h +24 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/interfaces/ObjectManager.h +26 -0
- data/vendor/simpleble/simpledbus/src/advanced/Interface.cpp +155 -0
- data/vendor/simpleble/simpledbus/src/advanced/Proxy.cpp +375 -0
- data/vendor/simpleble/simpledbus/src/base/Connection.cpp +222 -0
- data/vendor/simpleble/simpledbus/src/base/Exceptions.cpp +39 -0
- data/vendor/simpleble/simpledbus/src/base/Holder.cpp +739 -0
- data/vendor/simpleble/simpledbus/src/base/Logging.cpp +52 -0
- data/vendor/simpleble/simpledbus/src/base/Message.cpp +622 -0
- data/vendor/simpleble/simpledbus/src/base/Path.cpp +129 -0
- data/vendor/simpleble/simpledbus/src/interfaces/ObjectManager.cpp +58 -0
- data/vendor/simpleble/simpledbus/test/src/helpers/PythonRunner.cpp +53 -0
- data/vendor/simpleble/simpledbus/test/src/helpers/PythonRunner.h +24 -0
- data/vendor/simpleble/simpledbus/test/src/main.cpp +16 -0
- data/vendor/simpleble/simpledbus/test/src/test_holder.cpp +184 -0
- data/vendor/simpleble/simpledbus/test/src/test_message.cpp +397 -0
- data/vendor/simpleble/simpledbus/test/src/test_path.cpp +76 -0
- data/vendor/simpleble/simpledbus/test/src/test_proxy_children.cpp +109 -0
- data/vendor/simpleble/simpledbus/test/src/test_proxy_interfaces.cpp +102 -0
- data/vendor/simpleble/simpledbus/test/src/test_proxy_lifetime.cpp +18 -0
- data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/ThreadRunner.h +89 -0
- data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/android_utils.cpp +55 -0
- data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/android_utils.h +18 -0
- data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/simpleble_android.cpp +813 -0
- data/vendor/simpleble/simplejavable/cpp/src/core/AdapterWrapper.cpp +37 -0
- data/vendor/simpleble/simplejavable/cpp/src/core/AdapterWrapper.h +23 -0
- data/vendor/simpleble/simplejavable/cpp/src/core/Cache.cpp +58 -0
- data/vendor/simpleble/simplejavable/cpp/src/core/Cache.h +34 -0
- data/vendor/simpleble/simplejavable/cpp/src/core/PeripheralWrapper.cpp +17 -0
- data/vendor/simpleble/simplejavable/cpp/src/core/PeripheralWrapper.h +19 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/ArrayList.cpp +257 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/ArrayList.h +78 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/HashMap.cpp +96 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/HashMap.h +54 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/Integer.cpp +93 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/Integer.h +49 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/Iterator.cpp +85 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/Iterator.h +48 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/AdapterCallback.cpp +91 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/AdapterCallback.h +90 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Characteristic.cpp +35 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Characteristic.h +60 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/DataCallback.cpp +33 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/DataCallback.h +45 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Descriptor.cpp +30 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Descriptor.h +49 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/PeripheralCallback.cpp +41 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/PeripheralCallback.h +51 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Service.cpp +33 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Service.h +54 -0
- data/vendor/simpleble/simplejavable/cpp/src/simplejavable.cpp +361 -0
- data/vendor/simpleble/simplepyble/src/main.cpp +55 -0
- data/vendor/simpleble/simplepyble/src/wrap_adapter.cpp +106 -0
- data/vendor/simpleble/simplepyble/src/wrap_characteristic.cpp +56 -0
- data/vendor/simpleble/simplepyble/src/wrap_config.cpp +136 -0
- data/vendor/simpleble/simplepyble/src/wrap_descriptor.cpp +21 -0
- data/vendor/simpleble/simplepyble/src/wrap_peripheral.cpp +217 -0
- data/vendor/simpleble/simplepyble/src/wrap_service.cpp +32 -0
- data/vendor/simpleble/simplepyble/src/wrap_types.cpp +21 -0
- data/vendor/simpleble/simplersble/src/bindings/Bindings.cpp +338 -0
- data/vendor/simpleble/simplersble/src/bindings/Bindings.hpp +178 -0
- metadata +430 -0
@@ -0,0 +1,146 @@
|
|
1
|
+
#include "Utils.h"
|
2
|
+
|
3
|
+
#include <iomanip>
|
4
|
+
#include <iostream>
|
5
|
+
#include <sstream>
|
6
|
+
|
7
|
+
#include <roapi.h>
|
8
|
+
#include <sdkddkver.h>
|
9
|
+
|
10
|
+
#include "LoggingInternal.h"
|
11
|
+
|
12
|
+
#if WDK_NTDDI_VERSION < NTDDI_WIN10_VB
|
13
|
+
#error "Windows SDK version before 10.0.19041.0 is not supported"
|
14
|
+
#elif WDK_NTDDI_VERSION == NTDDI_WIN10_VB
|
15
|
+
// For Windows SDK version before 10.0.19041.0, remap functions to post-10.0.19041.0 versions
|
16
|
+
#define WINRT_IMPL_CoGetApartmentType WINRT_CoGetApartmentType
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#define MAC_ADDRESS_STR_LENGTH (size_t)17 // Two chars per byte, 5 chars for colon
|
20
|
+
|
21
|
+
namespace SimpleBLE {
|
22
|
+
|
23
|
+
void initialize_winrt() {
|
24
|
+
static bool initialized = false;
|
25
|
+
if (initialized) return;
|
26
|
+
initialized = true;
|
27
|
+
|
28
|
+
int32_t cotype = APTTYPE_NA;
|
29
|
+
int32_t qualifier = APTTYPEQUALIFIER_NONE;
|
30
|
+
winrt::hresult get_apartment_result = WINRT_IMPL_CoGetApartmentType(&cotype, &qualifier);
|
31
|
+
|
32
|
+
SIMPLEBLE_LOG_DEBUG(fmt::format("CoGetApartmentType: cotype={}, qualifier={}, result={:X}", cotype, qualifier,
|
33
|
+
(uint32_t)get_apartment_result));
|
34
|
+
|
35
|
+
if (cotype == APTTYPE_STA || cotype == APTTYPE_MAINSTA) {
|
36
|
+
SIMPLEBLE_LOG_WARN("Single-threaded apartment detected, uninitializing.");
|
37
|
+
RoUninitialize();
|
38
|
+
}
|
39
|
+
|
40
|
+
winrt::hresult result = RoInitialize(RO_INIT_MULTITHREADED);
|
41
|
+
std::string result_str = hresult_to_string(result);
|
42
|
+
if (FAILED(result)) {
|
43
|
+
SIMPLEBLE_LOG_ERROR(fmt::format("RoInitialize failed: {}", result_str));
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
std::string _mac_address_to_str(uint64_t mac_address) {
|
48
|
+
uint8_t* mac_ptr = (uint8_t*)&mac_address;
|
49
|
+
char mac_str[MAC_ADDRESS_STR_LENGTH + 1] = {0}; // Include null terminator.
|
50
|
+
|
51
|
+
snprintf(mac_str, MAC_ADDRESS_STR_LENGTH + 1, "%02x:%02x:%02x:%02x:%02x:%02x", mac_ptr[5], mac_ptr[4], mac_ptr[3],
|
52
|
+
mac_ptr[2], mac_ptr[1], mac_ptr[0]);
|
53
|
+
return std::string(mac_str);
|
54
|
+
}
|
55
|
+
|
56
|
+
uint64_t _str_to_mac_address(std::string mac_str) {
|
57
|
+
// TODO: Validate input - Expected Format: XX:XX:XX:XX:XX:XX
|
58
|
+
uint64_t mac_address_number = 0;
|
59
|
+
uint8_t* mac_ptr = (uint8_t*)&mac_address_number;
|
60
|
+
sscanf(mac_str.c_str(), "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac_ptr[5], &mac_ptr[4], &mac_ptr[3],
|
61
|
+
&mac_ptr[2], &mac_ptr[1], &mac_ptr[0]);
|
62
|
+
return mac_address_number;
|
63
|
+
}
|
64
|
+
|
65
|
+
winrt::guid uuid_to_guid(const std::string& uuid) {
|
66
|
+
// TODO: Add proper cleanup / validation
|
67
|
+
std::stringstream helper;
|
68
|
+
for (int i = 0; i < uuid.length(); i++) {
|
69
|
+
if (uuid[i] != '-') {
|
70
|
+
helper << uuid[i];
|
71
|
+
}
|
72
|
+
}
|
73
|
+
std::string clean_uuid = helper.str();
|
74
|
+
winrt::guid guid;
|
75
|
+
uint64_t* data4_ptr = (uint64_t*)guid.Data4;
|
76
|
+
|
77
|
+
guid.Data1 = static_cast<uint32_t>(std::strtoul(clean_uuid.substr(0, 8).c_str(), nullptr, 16));
|
78
|
+
guid.Data2 = static_cast<uint16_t>(std::strtoul(clean_uuid.substr(8, 4).c_str(), nullptr, 16));
|
79
|
+
guid.Data3 = static_cast<uint16_t>(std::strtoul(clean_uuid.substr(12, 4).c_str(), nullptr, 16));
|
80
|
+
*data4_ptr = _byteswap_uint64(std::strtoull(clean_uuid.substr(16, 16).c_str(), nullptr, 16));
|
81
|
+
|
82
|
+
return guid;
|
83
|
+
}
|
84
|
+
|
85
|
+
std::string guid_to_uuid(const winrt::guid& guid) {
|
86
|
+
std::stringstream helper;
|
87
|
+
// TODO: It might be cleaner to use snprintf instead of string streams.
|
88
|
+
|
89
|
+
for (uint32_t i = 0; i < 4; i++) {
|
90
|
+
// * NOTE: We're performing a byte swap!
|
91
|
+
helper << std::hex << std::setw(2) << std::setfill('0') << (int)((uint8_t*)&guid.Data1)[3 - i];
|
92
|
+
}
|
93
|
+
helper << '-';
|
94
|
+
for (uint32_t i = 0; i < 2; i++) {
|
95
|
+
// * NOTE: We're performing a byte swap!
|
96
|
+
helper << std::hex << std::setw(2) << std::setfill('0') << (int)((uint8_t*)&guid.Data2)[1 - i];
|
97
|
+
}
|
98
|
+
helper << '-';
|
99
|
+
for (uint32_t i = 0; i < 2; i++) {
|
100
|
+
// * NOTE: We're performing a byte swap!
|
101
|
+
helper << std::hex << std::setw(2) << std::setfill('0') << (int)((uint8_t*)&guid.Data3)[1 - i];
|
102
|
+
}
|
103
|
+
helper << '-';
|
104
|
+
for (uint32_t i = 0; i < 2; i++) {
|
105
|
+
helper << std::hex << std::setw(2) << std::setfill('0') << (int)guid.Data4[i];
|
106
|
+
}
|
107
|
+
helper << '-';
|
108
|
+
for (uint32_t i = 0; i < 6; i++) {
|
109
|
+
helper << std::hex << std::setw(2) << std::setfill('0') << (int)guid.Data4[2 + i];
|
110
|
+
}
|
111
|
+
return helper.str();
|
112
|
+
}
|
113
|
+
|
114
|
+
ByteArray ibuffer_to_bytearray(const IBuffer& buffer) { return ByteArray((const char*)buffer.data(), buffer.Length()); }
|
115
|
+
|
116
|
+
IBuffer bytearray_to_ibuffer(const ByteArray& array) {
|
117
|
+
DataWriter writer;
|
118
|
+
for (auto& byte : array) {
|
119
|
+
writer.WriteByte(byte);
|
120
|
+
}
|
121
|
+
return writer.DetachBuffer();
|
122
|
+
}
|
123
|
+
|
124
|
+
std::string hresult_to_string(winrt::hresult hr) {
|
125
|
+
if (SUCCEEDED(hr)) {
|
126
|
+
if (hr == S_OK) return "S_OK";
|
127
|
+
if (hr == S_FALSE) return "S_FALSE";
|
128
|
+
// Other success codes are possible but less common here.
|
129
|
+
return fmt::format("Success ({:#08x})", (uint32_t)hr);
|
130
|
+
} else {
|
131
|
+
try {
|
132
|
+
// Attempt to get the system message for the error.
|
133
|
+
winrt::check_hresult(hr);
|
134
|
+
} catch (const winrt::hresult_error& e) {
|
135
|
+
// Use fmt::format for consistent formatting
|
136
|
+
return fmt::format("Error ({:#08x}): {}", (uint32_t)hr, winrt::to_string(e.message()));
|
137
|
+
} catch (...) {
|
138
|
+
// Fallback for unexpected exceptions during error handling
|
139
|
+
return fmt::format("Unknown Error ({:#08x})", (uint32_t)hr);
|
140
|
+
}
|
141
|
+
// Should not be reached if hr is an error and check_hresult behaved as expected
|
142
|
+
return fmt::format("Error ({:#08x})", (uint32_t)hr);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
} // namespace SimpleBLE
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <cstdint>
|
4
|
+
#include <exception>
|
5
|
+
#include <string>
|
6
|
+
|
7
|
+
#include <simpleble/Exceptions.h>
|
8
|
+
#include <simpleble/Types.h>
|
9
|
+
|
10
|
+
#include "winrt/Windows.Foundation.h"
|
11
|
+
#include "winrt/Windows.Storage.Streams.h"
|
12
|
+
#include "winrt/base.h"
|
13
|
+
|
14
|
+
using namespace winrt::Windows;
|
15
|
+
using namespace winrt::Windows::Storage::Streams;
|
16
|
+
|
17
|
+
constexpr uint32_t TEN_SECONDS_IN_MSECS = 10000;
|
18
|
+
|
19
|
+
namespace SimpleBLE {
|
20
|
+
void initialize_winrt();
|
21
|
+
|
22
|
+
std::string _mac_address_to_str(uint64_t mac_address);
|
23
|
+
uint64_t _str_to_mac_address(std::string mac_address);
|
24
|
+
|
25
|
+
winrt::guid uuid_to_guid(const std::string& uuid);
|
26
|
+
std::string guid_to_uuid(const winrt::guid& guid);
|
27
|
+
|
28
|
+
ByteArray ibuffer_to_bytearray(const IBuffer& buffer);
|
29
|
+
IBuffer bytearray_to_ibuffer(const ByteArray& array);
|
30
|
+
|
31
|
+
std::string hresult_to_string(winrt::hresult hr);
|
32
|
+
|
33
|
+
template <typename async_t>
|
34
|
+
static auto async_get(async_t const& async) {
|
35
|
+
if (async.Status() == Foundation::AsyncStatus::Started) {
|
36
|
+
wait_for_completed(async, TEN_SECONDS_IN_MSECS);
|
37
|
+
}
|
38
|
+
try {
|
39
|
+
return async.GetResults();
|
40
|
+
} catch (const winrt::hresult_error& err) {
|
41
|
+
throw SimpleBLE::Exception::WinRTException(err.code().value, winrt::to_string(err.message()));
|
42
|
+
} catch (const std::exception& err) {
|
43
|
+
throw SimpleBLE::Exception::BaseException(err.what());
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
} // namespace SimpleBLE
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "BuilderBase.h"
|
4
|
+
|
5
|
+
namespace SimpleBLE::Factory {
|
6
|
+
|
7
|
+
template <typename V1>
|
8
|
+
struct BuildVecDeduce {
|
9
|
+
template <typename T>
|
10
|
+
operator T() && {
|
11
|
+
T vec;
|
12
|
+
vec.reserve(objs.size());
|
13
|
+
for (auto& obj : objs) {
|
14
|
+
vec.push_back(build(std::move(obj)));
|
15
|
+
}
|
16
|
+
return vec;
|
17
|
+
}
|
18
|
+
|
19
|
+
V1 objs;
|
20
|
+
};
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Build a vector of objects which are not directly constructible.
|
24
|
+
*
|
25
|
+
* This calls `Factory::build()` for each object in the input vector.
|
26
|
+
*/
|
27
|
+
template <typename V1>
|
28
|
+
auto vector(V1 objs) {
|
29
|
+
return BuildVecDeduce<V1>{std::move(objs)};
|
30
|
+
}
|
31
|
+
|
32
|
+
} // namespace SimpleBLE::Factory
|
@@ -0,0 +1,87 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <memory>
|
4
|
+
#include <tuple>
|
5
|
+
#include <type_traits>
|
6
|
+
#include <utility>
|
7
|
+
|
8
|
+
namespace SimpleBLE::Factory {
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Generic builder class for PIMP classes that have an "internal_" member variable.
|
12
|
+
*
|
13
|
+
* Normally, the base class's non-default constructor will not exist or will be
|
14
|
+
* protected, so that the user cannot directly initialize the class (i.e. set
|
15
|
+
* the "internal_" member variable to non-null).
|
16
|
+
*
|
17
|
+
* Additionally, this builder class allows for the construction of pointer-to
|
18
|
+
* object directly in the constructor.
|
19
|
+
*
|
20
|
+
* It is possible to specialize this class for classes that are constructed
|
21
|
+
* differently.
|
22
|
+
*/
|
23
|
+
template <typename T>
|
24
|
+
struct Builder : public T {
|
25
|
+
using T::internal_;
|
26
|
+
using PtrT = decltype(Builder::internal_);
|
27
|
+
|
28
|
+
Builder() { this->internal_ = std::make_shared<InternalT>(); }
|
29
|
+
using InternalT = typename std::remove_reference<decltype(*(Builder::internal_))>::type;
|
30
|
+
|
31
|
+
Builder(PtrT&& internal) { this->internal_ = std::move(internal); }
|
32
|
+
|
33
|
+
template <typename dPtr>
|
34
|
+
Builder(dPtr&& internal) {
|
35
|
+
this->internal_ = internal;
|
36
|
+
}
|
37
|
+
|
38
|
+
template <typename... ARG>
|
39
|
+
Builder(ARG&&... args) {
|
40
|
+
using InternalT = typename std::remove_reference<decltype(*(Builder::internal_))>::type;
|
41
|
+
this->internal_ = std::make_shared<InternalT>(std::forward<ARG>(args)...);
|
42
|
+
}
|
43
|
+
};
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Helper class to deduce the return type of the build function.
|
47
|
+
*/
|
48
|
+
template <typename ARG>
|
49
|
+
struct BuildDeduce {
|
50
|
+
template <typename T>
|
51
|
+
operator T() && {
|
52
|
+
return Builder<T>(std::move(arg));
|
53
|
+
}
|
54
|
+
|
55
|
+
ARG arg;
|
56
|
+
};
|
57
|
+
|
58
|
+
struct BuildDeduce0 {
|
59
|
+
template <typename T>
|
60
|
+
operator T() && {
|
61
|
+
return Builder<T>();
|
62
|
+
}
|
63
|
+
};
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Build a new object which is not directly constructible.
|
67
|
+
*
|
68
|
+
* The target class must have a default constructor and must have a protected
|
69
|
+
* "internal_" member variable.
|
70
|
+
*/
|
71
|
+
template <typename ARG>
|
72
|
+
auto build(ARG x) {
|
73
|
+
return BuildDeduce<ARG>{std::move(x)};
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Build a new object whose "internal_" type can be default-constructed.
|
78
|
+
*
|
79
|
+
* For example, for Adapter, calling `Adapter a = Factory::build();` is equivalent to
|
80
|
+
* `Adapter a = Build<Adapter>(std::make_shared<AdapterBase>());`.
|
81
|
+
*/
|
82
|
+
template <typename = void>
|
83
|
+
auto build() {
|
84
|
+
return BuildDeduce0{};
|
85
|
+
}
|
86
|
+
|
87
|
+
} // namespace SimpleBLE::Factory
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <chrono>
|
4
|
+
#include <functional>
|
5
|
+
#include <future>
|
6
|
+
#include <mutex>
|
7
|
+
#include <optional>
|
8
|
+
#include <queue>
|
9
|
+
#include <thread>
|
10
|
+
|
11
|
+
class TaskRunner {
|
12
|
+
private:
|
13
|
+
using Clock = std::chrono::steady_clock;
|
14
|
+
using TimePoint = Clock::time_point;
|
15
|
+
using Duration = Clock::duration;
|
16
|
+
using Task = std::function<std::optional<Duration>()>;
|
17
|
+
|
18
|
+
struct ScheduledTask {
|
19
|
+
TimePoint executionTime;
|
20
|
+
Task task;
|
21
|
+
|
22
|
+
bool operator>(const ScheduledTask& other) const { return executionTime > other.executionTime; }
|
23
|
+
};
|
24
|
+
|
25
|
+
std::priority_queue<ScheduledTask, std::vector<ScheduledTask>, std::greater<ScheduledTask>> taskQueue;
|
26
|
+
std::mutex taskQueueMutex;
|
27
|
+
std::condition_variable taskQueueCV;
|
28
|
+
bool running = false;
|
29
|
+
std::thread workerThread;
|
30
|
+
|
31
|
+
public:
|
32
|
+
TaskRunner() = default;
|
33
|
+
|
34
|
+
~TaskRunner() { stop(); }
|
35
|
+
|
36
|
+
void start() {
|
37
|
+
if (!running) {
|
38
|
+
running = true;
|
39
|
+
workerThread = std::thread(&TaskRunner::workerLoop, this);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
void stop() {
|
44
|
+
if (running) {
|
45
|
+
{
|
46
|
+
std::unique_lock<std::mutex> lock(taskQueueMutex);
|
47
|
+
running = false;
|
48
|
+
taskQueueCV.notify_one();
|
49
|
+
}
|
50
|
+
workerThread.join();
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
void dispatch(Task task, Duration delay) {
|
55
|
+
TimePoint executionTime = Clock::now() + delay;
|
56
|
+
{
|
57
|
+
std::unique_lock<std::mutex> lock(taskQueueMutex);
|
58
|
+
taskQueue.push({executionTime, std::move(task)});
|
59
|
+
taskQueueCV.notify_one();
|
60
|
+
}
|
61
|
+
if (!running) {
|
62
|
+
start();
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
private:
|
67
|
+
void workerLoop() {
|
68
|
+
while (true) {
|
69
|
+
std::unique_lock<std::mutex> lock(taskQueueMutex);
|
70
|
+
taskQueueCV.wait(lock, [this] { return !running || !taskQueue.empty(); });
|
71
|
+
|
72
|
+
if (!running) {
|
73
|
+
break;
|
74
|
+
}
|
75
|
+
|
76
|
+
if (taskQueue.empty()) {
|
77
|
+
continue;
|
78
|
+
}
|
79
|
+
|
80
|
+
// NOTE: If a new task is added to the queue with a shorter delay than the current top task, the worker
|
81
|
+
// thread will not wake up until the top task's execution time is reached. This is not ideal, but it's good
|
82
|
+
// enough for this simple implementation.
|
83
|
+
|
84
|
+
auto now = Clock::now();
|
85
|
+
if (taskQueue.top().executionTime > now) {
|
86
|
+
taskQueueCV.wait_until(lock, taskQueue.top().executionTime);
|
87
|
+
}
|
88
|
+
|
89
|
+
auto task = std::move(taskQueue.top().task);
|
90
|
+
taskQueue.pop();
|
91
|
+
lock.unlock();
|
92
|
+
|
93
|
+
auto result = task();
|
94
|
+
if (result.has_value()) {
|
95
|
+
dispatch(std::move(task), *result);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
};
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <condition_variable>
|
4
|
+
#include <functional>
|
5
|
+
#include <mutex>
|
6
|
+
#include <queue>
|
7
|
+
#include <thread>
|
8
|
+
|
9
|
+
class ThreadRunner {
|
10
|
+
public:
|
11
|
+
ThreadRunner() : _stop(false) { _thread = std::thread(&ThreadRunner::threadFunc, this); }
|
12
|
+
|
13
|
+
~ThreadRunner() {
|
14
|
+
{
|
15
|
+
std::unique_lock<std::mutex> lock(_mutex);
|
16
|
+
_stop = true;
|
17
|
+
_cv.notify_one();
|
18
|
+
}
|
19
|
+
_thread.join();
|
20
|
+
}
|
21
|
+
|
22
|
+
void enqueue(std::function<void()> func) {
|
23
|
+
{
|
24
|
+
std::unique_lock<std::mutex> lock(_mutex);
|
25
|
+
_queue.push(std::move(func));
|
26
|
+
_cv.notify_one();
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
private:
|
31
|
+
void threadFunc() {
|
32
|
+
while (true) {
|
33
|
+
std::function<void()> func;
|
34
|
+
{
|
35
|
+
std::unique_lock<std::mutex> lock(_mutex);
|
36
|
+
_cv.wait(lock, [this] { return _stop || !_queue.empty(); });
|
37
|
+
if (_stop && _queue.empty()) {
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
func = std::move(_queue.front());
|
41
|
+
_queue.pop();
|
42
|
+
}
|
43
|
+
func();
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
std::thread _thread;
|
48
|
+
std::mutex _mutex;
|
49
|
+
std::condition_variable _cv;
|
50
|
+
std::queue<std::function<void()>> _queue;
|
51
|
+
bool _stop;
|
52
|
+
};
|
@@ -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,94 @@
|
|
1
|
+
/*
|
2
|
+
* Thread-safe map implementation with custom comparator support
|
3
|
+
*/
|
4
|
+
#ifndef KVN_SAFE_MAP_HPP
|
5
|
+
#define KVN_SAFE_MAP_HPP
|
6
|
+
|
7
|
+
#include <map>
|
8
|
+
#include <memory>
|
9
|
+
#include <mutex>
|
10
|
+
#include <optional>
|
11
|
+
|
12
|
+
namespace kvn {
|
13
|
+
|
14
|
+
template <typename _Key, typename _Value, typename _Compare = std::less<_Key>>
|
15
|
+
class safe_map {
|
16
|
+
public:
|
17
|
+
safe_map() = default;
|
18
|
+
explicit safe_map(const _Compare& comp) : _map(comp) {}
|
19
|
+
|
20
|
+
// Remove copy constructor and copy assignment
|
21
|
+
safe_map(const safe_map&) = delete;
|
22
|
+
safe_map& operator=(const safe_map&) = delete;
|
23
|
+
|
24
|
+
// Move operations
|
25
|
+
safe_map(safe_map&&) noexcept = default;
|
26
|
+
safe_map& operator=(safe_map&&) noexcept = default;
|
27
|
+
|
28
|
+
// Add this inside the safe_map class
|
29
|
+
_Value& operator[](const _Key& key) {
|
30
|
+
std::scoped_lock lock(_mutex);
|
31
|
+
return _map[key];
|
32
|
+
}
|
33
|
+
|
34
|
+
const _Value& operator[](const _Key& key) const {
|
35
|
+
std::scoped_lock lock(_mutex);
|
36
|
+
return _map[key];
|
37
|
+
}
|
38
|
+
|
39
|
+
void insert(const _Key& key, const _Value& value) {
|
40
|
+
std::scoped_lock lock(_mutex);
|
41
|
+
_map.insert_or_assign(key, value);
|
42
|
+
}
|
43
|
+
|
44
|
+
void insert(_Key&& key, _Value&& value) {
|
45
|
+
std::scoped_lock lock(_mutex);
|
46
|
+
_map.insert_or_assign(std::move(key), std::move(value));
|
47
|
+
}
|
48
|
+
|
49
|
+
bool erase(const _Key& key) {
|
50
|
+
std::scoped_lock lock(_mutex);
|
51
|
+
return _map.erase(key) > 0;
|
52
|
+
}
|
53
|
+
|
54
|
+
std::optional<_Value> get(const _Key& key) const {
|
55
|
+
std::scoped_lock lock(_mutex);
|
56
|
+
auto it = _map.find(key);
|
57
|
+
if (it != _map.end()) {
|
58
|
+
return it->second;
|
59
|
+
}
|
60
|
+
return std::nullopt;
|
61
|
+
}
|
62
|
+
|
63
|
+
bool contains(const _Key& key) const {
|
64
|
+
std::scoped_lock lock(_mutex);
|
65
|
+
return _map.contains(key);
|
66
|
+
}
|
67
|
+
|
68
|
+
size_t size() const {
|
69
|
+
std::scoped_lock lock(_mutex);
|
70
|
+
return _map.size();
|
71
|
+
}
|
72
|
+
|
73
|
+
void clear() {
|
74
|
+
std::scoped_lock lock(_mutex);
|
75
|
+
_map.clear();
|
76
|
+
}
|
77
|
+
|
78
|
+
template <typename _Func>
|
79
|
+
void atomic_update(const _Key& key, _Func update_func) {
|
80
|
+
std::scoped_lock lock(_mutex);
|
81
|
+
auto it = _map.find(key);
|
82
|
+
if (it != _map.end()) {
|
83
|
+
update_func(it->second);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
protected:
|
88
|
+
mutable std::recursive_mutex _mutex;
|
89
|
+
std::map<_Key, _Value, _Compare> _map;
|
90
|
+
};
|
91
|
+
|
92
|
+
} // namespace kvn
|
93
|
+
|
94
|
+
#endif // KVN_SAFE_MAP_HPP
|
@@ -0,0 +1,70 @@
|
|
1
|
+
/*
|
2
|
+
* SPDX-FileCopyrightText: 2025 Kevin Dewald <kevin@dewald.me>
|
3
|
+
*
|
4
|
+
* SPDX-License-Identifier: MIT
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifndef KVN_THREADRUNNER_HPP
|
8
|
+
#define KVN_THREADRUNNER_HPP
|
9
|
+
|
10
|
+
#include <condition_variable>
|
11
|
+
#include <functional>
|
12
|
+
#include <mutex>
|
13
|
+
#include <queue>
|
14
|
+
#include <thread>
|
15
|
+
|
16
|
+
namespace kvn {
|
17
|
+
|
18
|
+
class thread_runner {
|
19
|
+
public:
|
20
|
+
thread_runner() : _stop(false) { _thread = std::thread(&thread_runner::thread_func, this); }
|
21
|
+
|
22
|
+
// Remove copy constructor and copy assignment
|
23
|
+
thread_runner(const thread_runner&) = delete;
|
24
|
+
thread_runner& operator=(const thread_runner&) = delete;
|
25
|
+
|
26
|
+
virtual ~thread_runner() {
|
27
|
+
{
|
28
|
+
std::unique_lock<std::mutex> lock(_mutex);
|
29
|
+
_stop = true;
|
30
|
+
_cv.notify_one();
|
31
|
+
}
|
32
|
+
_thread.join();
|
33
|
+
}
|
34
|
+
|
35
|
+
void enqueue(std::function<void()> func) {
|
36
|
+
{
|
37
|
+
std::unique_lock<std::mutex> lock(_mutex);
|
38
|
+
_queue.push(std::move(func));
|
39
|
+
lock.unlock(); // Unlock before notify
|
40
|
+
_cv.notify_one();
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
protected:
|
45
|
+
void thread_func() {
|
46
|
+
while (true) {
|
47
|
+
std::function<void()> func;
|
48
|
+
{
|
49
|
+
std::unique_lock<std::mutex> lock(_mutex);
|
50
|
+
_cv.wait(lock, [this] { return _stop || !_queue.empty(); });
|
51
|
+
if (_stop && _queue.empty()) {
|
52
|
+
return;
|
53
|
+
}
|
54
|
+
func = std::move(_queue.front());
|
55
|
+
_queue.pop();
|
56
|
+
}
|
57
|
+
func();
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
std::thread _thread;
|
62
|
+
std::mutex _mutex;
|
63
|
+
std::condition_variable _cv;
|
64
|
+
std::queue<std::function<void()>> _queue;
|
65
|
+
bool _stop;
|
66
|
+
};
|
67
|
+
|
68
|
+
} // namespace kvn
|
69
|
+
|
70
|
+
#endif // KVN_THREADRUNNER_HPP
|