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,151 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <jni.h>
|
4
|
+
|
5
|
+
#include "VM.hpp"
|
6
|
+
|
7
|
+
namespace SimpleJNI {
|
8
|
+
|
9
|
+
template <typename T>
|
10
|
+
class GlobalRef {
|
11
|
+
public:
|
12
|
+
GlobalRef() = default;
|
13
|
+
|
14
|
+
explicit GlobalRef(T obj) : _obj(obj ? static_cast<T>(VM::env()->NewGlobalRef(obj)) : nullptr) {}
|
15
|
+
|
16
|
+
~GlobalRef() {
|
17
|
+
if (_obj && VM::is_jvm_alive()) VM::env()->DeleteGlobalRef(_obj);
|
18
|
+
}
|
19
|
+
|
20
|
+
// Copy constructor
|
21
|
+
GlobalRef(const GlobalRef& other)
|
22
|
+
: _obj(other._obj ? static_cast<T>(VM::env()->NewGlobalRef(other._obj)) : nullptr) {}
|
23
|
+
|
24
|
+
// Copy assignment operator
|
25
|
+
GlobalRef& operator=(const GlobalRef& other) {
|
26
|
+
if (this != &other) {
|
27
|
+
if (_obj) VM::env()->DeleteGlobalRef(_obj);
|
28
|
+
_obj = other._obj ? static_cast<T>(VM::env()->NewGlobalRef(other._obj)) : nullptr;
|
29
|
+
}
|
30
|
+
return *this;
|
31
|
+
}
|
32
|
+
|
33
|
+
// Move constructor
|
34
|
+
GlobalRef(GlobalRef&& other) noexcept : _obj(other._obj) { other._obj = nullptr; }
|
35
|
+
|
36
|
+
// Move assignment operator
|
37
|
+
GlobalRef& operator=(GlobalRef&& other) noexcept {
|
38
|
+
if (this != &other) {
|
39
|
+
if (_obj) VM::env()->DeleteGlobalRef(_obj);
|
40
|
+
_obj = other._obj;
|
41
|
+
other._obj = nullptr;
|
42
|
+
}
|
43
|
+
return *this;
|
44
|
+
}
|
45
|
+
|
46
|
+
T get() const { return _obj; }
|
47
|
+
|
48
|
+
protected:
|
49
|
+
T _obj = nullptr;
|
50
|
+
};
|
51
|
+
|
52
|
+
template <typename T>
|
53
|
+
class LocalRef {
|
54
|
+
public:
|
55
|
+
LocalRef() = default;
|
56
|
+
|
57
|
+
explicit LocalRef(T obj) : _obj(obj ? static_cast<T>(VM::env()->NewLocalRef(obj)) : nullptr) {}
|
58
|
+
|
59
|
+
~LocalRef() {
|
60
|
+
if (_obj) VM::env()->DeleteLocalRef(_obj);
|
61
|
+
}
|
62
|
+
|
63
|
+
// Copy constructor
|
64
|
+
LocalRef(const LocalRef& other) : _obj(other._obj ? static_cast<T>(VM::env()->NewLocalRef(other._obj)) : nullptr) {}
|
65
|
+
|
66
|
+
// Copy assignment operator
|
67
|
+
LocalRef& operator=(const LocalRef& other) {
|
68
|
+
if (this != &other) {
|
69
|
+
if (_obj) VM::env()->DeleteLocalRef(_obj);
|
70
|
+
_obj = other._obj ? static_cast<T>(VM::env()->NewLocalRef(other._obj)) : nullptr;
|
71
|
+
}
|
72
|
+
return *this;
|
73
|
+
}
|
74
|
+
|
75
|
+
// Move constructor
|
76
|
+
LocalRef(LocalRef&& other) noexcept : _obj(other._obj) { other._obj = nullptr; }
|
77
|
+
|
78
|
+
// Move assignment operator
|
79
|
+
LocalRef& operator=(LocalRef&& other) noexcept {
|
80
|
+
if (this != &other) {
|
81
|
+
if (_obj) VM::env()->DeleteLocalRef(_obj);
|
82
|
+
_obj = other._obj;
|
83
|
+
other._obj = nullptr;
|
84
|
+
}
|
85
|
+
return *this;
|
86
|
+
}
|
87
|
+
|
88
|
+
T get() const { return _obj; }
|
89
|
+
|
90
|
+
protected:
|
91
|
+
T _obj = nullptr;
|
92
|
+
};
|
93
|
+
|
94
|
+
// A type for references intended to be returned to JNI
|
95
|
+
template <typename T>
|
96
|
+
class ReleasableLocalRef : public LocalRef<T> {
|
97
|
+
public:
|
98
|
+
using LocalRef<T>::LocalRef;
|
99
|
+
T release() noexcept {
|
100
|
+
T obj = this->_obj;
|
101
|
+
this->_obj = nullptr;
|
102
|
+
return obj;
|
103
|
+
}
|
104
|
+
};
|
105
|
+
|
106
|
+
template <typename T>
|
107
|
+
class WeakRef {
|
108
|
+
public:
|
109
|
+
WeakRef() = default;
|
110
|
+
|
111
|
+
explicit WeakRef(T obj) : _obj(obj ? static_cast<T>(VM::env()->NewWeakGlobalRef(obj)) : nullptr) {}
|
112
|
+
|
113
|
+
~WeakRef() {
|
114
|
+
if (_obj && VM::is_jvm_alive()) VM::env()->DeleteWeakGlobalRef(_obj);
|
115
|
+
}
|
116
|
+
|
117
|
+
// Copy constructor
|
118
|
+
WeakRef(const WeakRef& other)
|
119
|
+
: _obj(other._obj ? static_cast<T>(VM::env()->NewWeakGlobalRef(other._obj)) : nullptr) {}
|
120
|
+
|
121
|
+
// Copy assignment operator
|
122
|
+
WeakRef& operator=(const WeakRef& other) {
|
123
|
+
if (this != &other) {
|
124
|
+
if (_obj) VM::env()->DeleteWeakGlobalRef(_obj);
|
125
|
+
_obj = other._obj ? static_cast<T>(VM::env()->NewWeakGlobalRef(other._obj)) : nullptr;
|
126
|
+
}
|
127
|
+
return *this;
|
128
|
+
}
|
129
|
+
|
130
|
+
// Move constructor
|
131
|
+
WeakRef(WeakRef&& other) noexcept : _obj(other._obj) { other._obj = nullptr; }
|
132
|
+
|
133
|
+
// Move assignment operator
|
134
|
+
WeakRef& operator=(WeakRef&& other) noexcept {
|
135
|
+
if (this != &other) {
|
136
|
+
if (_obj) VM::env()->DeleteWeakGlobalRef(_obj);
|
137
|
+
_obj = other._obj;
|
138
|
+
other._obj = nullptr;
|
139
|
+
}
|
140
|
+
return *this;
|
141
|
+
}
|
142
|
+
|
143
|
+
T get() const { return _obj; }
|
144
|
+
|
145
|
+
bool is_valid() const { return _obj && !VM::env()->IsSameObject(_obj, nullptr); }
|
146
|
+
|
147
|
+
protected:
|
148
|
+
T _obj = nullptr;
|
149
|
+
};
|
150
|
+
|
151
|
+
} // namespace SimpleJNI
|
@@ -0,0 +1,183 @@
|
|
1
|
+
#pragma once
|
2
|
+
#include <string>
|
3
|
+
#include <vector>
|
4
|
+
#include "Common.hpp"
|
5
|
+
|
6
|
+
namespace SimpleJNI {
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @brief Descriptor for a single Java method to be preloaded.
|
10
|
+
*
|
11
|
+
* This struct holds the metadata for a method that a Java class needs to expose to C++.
|
12
|
+
* It links a method name and signature to a jmethodID pointer where the resolved ID will
|
13
|
+
* be stored during JNI_OnLoad.
|
14
|
+
*/
|
15
|
+
struct MethodDescriptor {
|
16
|
+
std::string name; ///< Name of the Java method (e.g., "startScan").
|
17
|
+
std::string signature; ///< JNI signature of the method (e.g., "(Landroid/bluetooth/le/ScanCallback;)V").
|
18
|
+
jmethodID* target = nullptr; ///< Pointer to where the resolved jmethodID will be stored.
|
19
|
+
|
20
|
+
MethodDescriptor(const std::string& n, const std::string& sig, jmethodID* tgt)
|
21
|
+
: name(n), signature(sig), target(tgt) {}
|
22
|
+
};
|
23
|
+
|
24
|
+
/**
|
25
|
+
* @brief Descriptor for a Java class and its methods to be preloaded.
|
26
|
+
*
|
27
|
+
* This struct defines a Java class by its fully qualified name and a list of methods
|
28
|
+
* that need JNI access. It ties the class and its methods to storage locations
|
29
|
+
* (GlobalRef<jclass> and jmethodID pointers) that will be populated during preloading.
|
30
|
+
*/
|
31
|
+
struct JNIDescriptor {
|
32
|
+
std::string class_name; ///< Fully qualified Java class name (e.g., "android/bluetooth/le/BluetoothLeScanner").
|
33
|
+
SimpleJNI::GlobalRef<jclass>* class_target; ///< Pointer to where the resolved jclass will be stored.
|
34
|
+
std::vector<MethodDescriptor> methods; ///< List of methods to preload for this class.
|
35
|
+
|
36
|
+
JNIDescriptor(const std::string& name, SimpleJNI::GlobalRef<jclass>* cls_target,
|
37
|
+
std::initializer_list<MethodDescriptor> meths)
|
38
|
+
: class_name(name), class_target(cls_target), methods(meths) {}
|
39
|
+
};
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @brief Descriptor for a Java class and its static methods to be preloaded.
|
43
|
+
*
|
44
|
+
* This struct defines a Java class by its fully qualified name and a list of static methods
|
45
|
+
* that need JNI access. It ties the class and its static methods to storage locations
|
46
|
+
* (GlobalRef<jclass> and jmethodID pointers) that will be populated during preloading.
|
47
|
+
*/
|
48
|
+
struct StaticJNIDescriptor {
|
49
|
+
std::string class_name; ///< Fully qualified Java class name (e.g., "android/bluetooth/le/BluetoothLeScanner").
|
50
|
+
SimpleJNI::GlobalRef<jclass>* class_target; ///< Pointer to where the resolved jclass will be stored.
|
51
|
+
std::vector<MethodDescriptor> static_methods; ///< List of static methods to preload for this class.
|
52
|
+
|
53
|
+
StaticJNIDescriptor(const std::string& name, SimpleJNI::GlobalRef<jclass>* cls_target,
|
54
|
+
std::initializer_list<MethodDescriptor> meths)
|
55
|
+
: class_name(name), class_target(cls_target), static_methods(meths) {}
|
56
|
+
};
|
57
|
+
|
58
|
+
/**
|
59
|
+
* @brief Singleton registrar for collecting and preloading JNI class descriptors.
|
60
|
+
*
|
61
|
+
* The Registrar collects JNIDescriptor and StaticJNIDescriptor instances at compile-time
|
62
|
+
* (via static initialization) and preloads their JNI resources (jclass and jmethodID)
|
63
|
+
* during JNI_OnLoad. This ensures all necessary JNI metadata is resolved early on the
|
64
|
+
* correct thread, avoiding runtime ClassLoader or thread-context issues.
|
65
|
+
*/
|
66
|
+
class Registrar {
|
67
|
+
public:
|
68
|
+
/// @brief Get the singleton instance of the Registrar.
|
69
|
+
static Registrar& get() {
|
70
|
+
static Registrar instance;
|
71
|
+
return instance;
|
72
|
+
}
|
73
|
+
|
74
|
+
/**
|
75
|
+
* @brief Register a JNIDescriptor for preloading.
|
76
|
+
*
|
77
|
+
* Called automatically by AutoRegister during static initialization. Adds the descriptor
|
78
|
+
* to an internal list that will be processed in preload().
|
79
|
+
* @param descriptor Pointer to the JNIDescriptor to register.
|
80
|
+
*/
|
81
|
+
void register_descriptor(const JNIDescriptor* descriptor) { descriptors.push_back(descriptor); }
|
82
|
+
|
83
|
+
/**
|
84
|
+
* @brief Register a StaticJNIDescriptor for preloading.
|
85
|
+
*
|
86
|
+
* Called automatically by AutoRegister during static initialization. Adds the descriptor
|
87
|
+
* to an internal list that will be processed in preload().
|
88
|
+
* @param descriptor Pointer to the StaticJNIDescriptor to register.
|
89
|
+
*/
|
90
|
+
void register_static_descriptor(const StaticJNIDescriptor* descriptor) {
|
91
|
+
static_descriptors.push_back(descriptor);
|
92
|
+
}
|
93
|
+
|
94
|
+
/**
|
95
|
+
* @brief Preload all registered JNI resources.
|
96
|
+
*
|
97
|
+
* Called from JNI_OnLoad to resolve jclass and jmethodID for all registered descriptors.
|
98
|
+
* Uses the provided JNIEnv to perform JNI lookups on the thread that loads the library,
|
99
|
+
* ensuring access to the correct ClassLoader context (e.g., system classes on Android).
|
100
|
+
* @param env JNIEnv pointer from JNI_OnLoad.
|
101
|
+
* @throws std::runtime_error if a class or method cannot be resolved.
|
102
|
+
*/
|
103
|
+
void preload(JNIEnv* env) {
|
104
|
+
// Preload instance method descriptors
|
105
|
+
for (const JNIDescriptor* desc : descriptors) {
|
106
|
+
// Load the Java class
|
107
|
+
jclass local_cls = env->FindClass(desc->class_name.c_str());
|
108
|
+
if (!local_cls) {
|
109
|
+
throw std::runtime_error("Failed to load class: " + desc->class_name);
|
110
|
+
}
|
111
|
+
*desc->class_target = SimpleJNI::GlobalRef<jclass>(local_cls);
|
112
|
+
env->DeleteLocalRef(local_cls); // Clean up the local reference
|
113
|
+
|
114
|
+
// Load each method
|
115
|
+
for (const MethodDescriptor& method : desc->methods) {
|
116
|
+
*method.target = env->GetMethodID(desc->class_target->get(), method.name.c_str(),
|
117
|
+
method.signature.c_str());
|
118
|
+
if (!*method.target) {
|
119
|
+
throw std::runtime_error("Failed to get method: " + desc->class_name + "." + method.name);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
// Preload static method descriptors
|
125
|
+
for (const StaticJNIDescriptor* desc : static_descriptors) {
|
126
|
+
// Load the Java class
|
127
|
+
jclass local_cls = env->FindClass(desc->class_name.c_str());
|
128
|
+
if (!local_cls) {
|
129
|
+
throw std::runtime_error("Failed to load class: " + desc->class_name);
|
130
|
+
}
|
131
|
+
*desc->class_target = SimpleJNI::GlobalRef<jclass>(local_cls);
|
132
|
+
env->DeleteLocalRef(local_cls); // Clean up the local reference
|
133
|
+
|
134
|
+
// Load each static method
|
135
|
+
for (const MethodDescriptor& method : desc->static_methods) {
|
136
|
+
*method.target = env->GetStaticMethodID(desc->class_target->get(), method.name.c_str(),
|
137
|
+
method.signature.c_str());
|
138
|
+
if (!*method.target) {
|
139
|
+
throw std::runtime_error("Failed to get static method: " + desc->class_name + "." + method.name);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
private:
|
146
|
+
Registrar() = default;
|
147
|
+
~Registrar() = default;
|
148
|
+
Registrar(const Registrar&) = delete;
|
149
|
+
Registrar& operator=(const Registrar&) = delete;
|
150
|
+
|
151
|
+
std::vector<const JNIDescriptor*> descriptors; ///< List of registered descriptors.
|
152
|
+
std::vector<const StaticJNIDescriptor*> static_descriptors; ///< List of registered static descriptors.
|
153
|
+
};
|
154
|
+
|
155
|
+
/**
|
156
|
+
* @brief Helper to automatically register JNI descriptors at compile time.
|
157
|
+
*
|
158
|
+
* This template class uses static initialization to register descriptors with the Registrar
|
159
|
+
* when the program loads. The constructor runs before main() or JNI_OnLoad, ensuring all
|
160
|
+
* classes are registered without manual intervention. It supports registering non-static methods,
|
161
|
+
* static methods, or both.
|
162
|
+
* @tparam T The class type (e.g., BluetoothScanner) that owns the descriptor.
|
163
|
+
*/
|
164
|
+
template <typename T>
|
165
|
+
struct AutoRegister {
|
166
|
+
// Constructor for non-static methods only
|
167
|
+
AutoRegister(const JNIDescriptor* desc) {
|
168
|
+
Registrar::get().register_descriptor(desc);
|
169
|
+
}
|
170
|
+
|
171
|
+
// Constructor for static methods only
|
172
|
+
AutoRegister(const StaticJNIDescriptor* static_desc) {
|
173
|
+
Registrar::get().register_static_descriptor(static_desc);
|
174
|
+
}
|
175
|
+
|
176
|
+
// Constructor for both non-static and static methods
|
177
|
+
AutoRegister(const JNIDescriptor* desc, const StaticJNIDescriptor* static_desc) {
|
178
|
+
Registrar::get().register_descriptor(desc);
|
179
|
+
Registrar::get().register_static_descriptor(static_desc);
|
180
|
+
}
|
181
|
+
};
|
182
|
+
|
183
|
+
} // namespace SimpleJNI
|
@@ -0,0 +1,88 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <jni.h>
|
4
|
+
|
5
|
+
#include <mutex>
|
6
|
+
|
7
|
+
namespace SimpleJNI {
|
8
|
+
|
9
|
+
// Generic class to handle the Java Virtual Machine (JVM)
|
10
|
+
class VM {
|
11
|
+
public:
|
12
|
+
// TODO: Make the VM class transparent to the JavaVM pointer.
|
13
|
+
static JavaVM* jvm() {
|
14
|
+
static std::mutex get_mutex; // Static mutex to ensure thread safety when accessing the VM
|
15
|
+
static VM instance; // Static instance of the VM to ensure proper lifecycle management
|
16
|
+
|
17
|
+
if (instance._jvm == nullptr) {
|
18
|
+
std::scoped_lock lock(get_mutex); // Unlock the mutex on function return
|
19
|
+
jsize count;
|
20
|
+
if (JNI_GetCreatedJavaVMs(&instance._jvm, 1, &count) != JNI_OK || count == 0) {
|
21
|
+
throw std::runtime_error("Failed to get the Java Virtual Machine");
|
22
|
+
}
|
23
|
+
}
|
24
|
+
return instance._jvm;
|
25
|
+
}
|
26
|
+
|
27
|
+
static bool is_jvm_alive() {
|
28
|
+
JavaVM* jvm = VM::jvm();
|
29
|
+
if (!jvm) return false;
|
30
|
+
JNIEnv* env = nullptr;
|
31
|
+
return jvm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) == JNI_OK;
|
32
|
+
}
|
33
|
+
|
34
|
+
static JNIEnv* env() {
|
35
|
+
JNIEnv* env = nullptr;
|
36
|
+
JavaVM* jvm = VM::jvm();
|
37
|
+
|
38
|
+
auto getEnvResult = jvm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
|
39
|
+
switch (getEnvResult) {
|
40
|
+
case JNI_OK:
|
41
|
+
break;
|
42
|
+
case JNI_EDETACHED: {
|
43
|
+
#ifdef __ANDROID__
|
44
|
+
auto result = jvm->AttachCurrentThread(&env, nullptr);
|
45
|
+
#else
|
46
|
+
auto result = jvm->AttachCurrentThread(reinterpret_cast<void**>(&env), nullptr);
|
47
|
+
#endif
|
48
|
+
if (result != JNI_OK) {
|
49
|
+
throw std::runtime_error("Failed to attach the current thread to the JVM");
|
50
|
+
}
|
51
|
+
break;
|
52
|
+
}
|
53
|
+
case JNI_EVERSION:
|
54
|
+
throw std::runtime_error("Failed to get the JNIEnv, JNI version not supported");
|
55
|
+
default:
|
56
|
+
throw std::runtime_error("Failed to get the JNIEnv, unknown error");
|
57
|
+
}
|
58
|
+
return env;
|
59
|
+
}
|
60
|
+
|
61
|
+
static void attach() {
|
62
|
+
JNIEnv* env = nullptr;
|
63
|
+
JavaVM* jvm = VM::jvm();
|
64
|
+
#ifdef __ANDROID__
|
65
|
+
auto result = jvm->AttachCurrentThread(&env, nullptr);
|
66
|
+
#else
|
67
|
+
auto result = jvm->AttachCurrentThread(reinterpret_cast<void**>(&env), nullptr);
|
68
|
+
#endif
|
69
|
+
if (result != JNI_OK) {
|
70
|
+
throw std::runtime_error("Failed to attach the current thread to the JVM");
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
static void detach() {
|
75
|
+
JavaVM* jvm = VM::jvm();
|
76
|
+
jvm->DetachCurrentThread();
|
77
|
+
}
|
78
|
+
|
79
|
+
private:
|
80
|
+
VM() = default;
|
81
|
+
virtual ~VM() = default;
|
82
|
+
VM(VM& other) = delete; // Remove the copy constructor
|
83
|
+
void operator=(const VM&) = delete; // Remove the copy assignment
|
84
|
+
|
85
|
+
JavaVM* _jvm = nullptr;
|
86
|
+
};
|
87
|
+
|
88
|
+
} // namespace SimpleJNI
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#include <iostream>
|
2
|
+
#include <vector>
|
3
|
+
|
4
|
+
#include "utils.hpp"
|
5
|
+
|
6
|
+
#include "simpleble/SimpleBLE.h"
|
7
|
+
|
8
|
+
int main() {
|
9
|
+
auto adapter_optional = Utils::getAdapter();
|
10
|
+
|
11
|
+
if (!adapter_optional.has_value()) {
|
12
|
+
return EXIT_FAILURE;
|
13
|
+
}
|
14
|
+
|
15
|
+
auto adapter = adapter_optional.value();
|
16
|
+
|
17
|
+
std::vector<SimpleBLE::Peripheral> peripherals;
|
18
|
+
|
19
|
+
adapter.set_callback_on_scan_found([&](SimpleBLE::Peripheral peripheral) {
|
20
|
+
std::cout << "Found device: " << peripheral.identifier() << " [" << peripheral.address() << "]" << std::endl;
|
21
|
+
if (peripheral.is_connectable()) {
|
22
|
+
peripherals.push_back(peripheral);
|
23
|
+
}
|
24
|
+
});
|
25
|
+
|
26
|
+
adapter.set_callback_on_scan_start([]() { std::cout << "Scan started." << std::endl; });
|
27
|
+
adapter.set_callback_on_scan_stop([]() { std::cout << "Scan stopped." << std::endl; });
|
28
|
+
// Scan for 5 seconds and return.
|
29
|
+
adapter.scan_for(5000);
|
30
|
+
|
31
|
+
std::cout << "The following connectable devices were found:" << std::endl;
|
32
|
+
for (size_t i = 0; i < peripherals.size(); i++) {
|
33
|
+
std::cout << "[" << i << "] " << peripherals[i].identifier() << " [" << peripherals[i].address() << "]"
|
34
|
+
<< std::endl;
|
35
|
+
}
|
36
|
+
|
37
|
+
auto selection = Utils::getUserInputInt("Please select a device to connect to", peripherals.size() - 1);
|
38
|
+
if (!selection.has_value()) {
|
39
|
+
return EXIT_FAILURE;
|
40
|
+
}
|
41
|
+
|
42
|
+
auto peripheral = peripherals[selection.value()];
|
43
|
+
std::cout << "Connecting to " << peripheral.identifier() << " [" << peripheral.address() << "]" << std::endl;
|
44
|
+
peripheral.connect();
|
45
|
+
|
46
|
+
std::cout << "Successfully connected." << std::endl;
|
47
|
+
std::cout << "MTU: " << peripheral.mtu() << std::endl;
|
48
|
+
for (auto& service : peripheral.services()) {
|
49
|
+
std::cout << "Service: " << service.uuid() << std::endl;
|
50
|
+
|
51
|
+
for (auto& characteristic : service.characteristics()) {
|
52
|
+
std::cout << " Characteristic: " << characteristic.uuid() << std::endl;
|
53
|
+
|
54
|
+
std::cout << " Capabilities: ";
|
55
|
+
for (auto& capability : characteristic.capabilities()) {
|
56
|
+
std::cout << capability << " ";
|
57
|
+
}
|
58
|
+
std::cout << std::endl;
|
59
|
+
|
60
|
+
for (auto& descriptor : characteristic.descriptors()) {
|
61
|
+
std::cout << " Descriptor: " << descriptor.uuid() << std::endl;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
peripheral.disconnect();
|
66
|
+
return EXIT_SUCCESS;
|
67
|
+
}
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#include <iostream>
|
2
|
+
#include <vector>
|
3
|
+
|
4
|
+
#include "utils.hpp"
|
5
|
+
|
6
|
+
#include "simpleble/SimpleBLE.h"
|
7
|
+
|
8
|
+
int main() {
|
9
|
+
auto adapter_list = SimpleBLE::Safe::Adapter::get_adapters();
|
10
|
+
|
11
|
+
if (!adapter_list.has_value()) {
|
12
|
+
std::cout << "Failed to list adapters" << std::endl;
|
13
|
+
return EXIT_FAILURE;
|
14
|
+
}
|
15
|
+
|
16
|
+
if (adapter_list->empty()) {
|
17
|
+
std::cout << "No adapter was found." << std::endl;
|
18
|
+
return EXIT_FAILURE;
|
19
|
+
}
|
20
|
+
|
21
|
+
std::cout << "Available adapters: \n";
|
22
|
+
int i = 0;
|
23
|
+
for (auto& adapter : *adapter_list) {
|
24
|
+
std::cout << "[" << i++ << "] " << adapter.identifier().value() << " [" << adapter.address().value() << "]"
|
25
|
+
<< std::endl;
|
26
|
+
}
|
27
|
+
|
28
|
+
auto adapter_selection = Utils::getUserInputInt("Please select an adapter", adapter_list->size() - 1);
|
29
|
+
if (!adapter_selection.has_value()) {
|
30
|
+
return EXIT_FAILURE;
|
31
|
+
}
|
32
|
+
|
33
|
+
SimpleBLE::Safe::Adapter& adapter = adapter_list->at(adapter_selection.value());
|
34
|
+
|
35
|
+
std::vector<SimpleBLE::Safe::Peripheral> peripherals;
|
36
|
+
|
37
|
+
adapter.set_callback_on_scan_found([&](SimpleBLE::Safe::Peripheral peripheral) {
|
38
|
+
std::cout << "Found device: " << peripheral.identifier().value_or("UNKNOWN") << " ["
|
39
|
+
<< peripheral.address().value_or("UNKNOWN") << "]" << std::endl;
|
40
|
+
peripherals.push_back(peripheral);
|
41
|
+
});
|
42
|
+
|
43
|
+
adapter.set_callback_on_scan_start([]() { std::cout << "Scan started." << std::endl; });
|
44
|
+
adapter.set_callback_on_scan_stop([]() { std::cout << "Scan stopped." << std::endl; });
|
45
|
+
// Scan for 5 seconds and return.
|
46
|
+
adapter.scan_for(5000);
|
47
|
+
|
48
|
+
std::cout << "The following devices were found:" << std::endl;
|
49
|
+
for (size_t i = 0; i < peripherals.size(); i++) {
|
50
|
+
std::cout << "[" << i << "] " << peripherals[i].identifier().value_or("UNKNOWN") << " ["
|
51
|
+
<< peripherals[i].address().value_or("UNKNOWN") << "]" << std::endl;
|
52
|
+
}
|
53
|
+
|
54
|
+
auto selection = Utils::getUserInputInt("Please select a device to connect to", peripherals.size() - 1);
|
55
|
+
if (!selection.has_value()) {
|
56
|
+
return EXIT_FAILURE;
|
57
|
+
}
|
58
|
+
|
59
|
+
auto peripheral = peripherals[selection.value()];
|
60
|
+
std::cout << "Connecting to " << peripheral.identifier().value_or("UNKNOWN") << " ["
|
61
|
+
<< peripheral.address().value_or("UNKNOWN") << "]" << std::endl;
|
62
|
+
|
63
|
+
// If the connection wasn't successful, no exception will be thrown.
|
64
|
+
bool connect_was_successful = peripheral.connect();
|
65
|
+
if (!connect_was_successful) {
|
66
|
+
std::cout << "Failed to connect to " << peripheral.identifier().value_or("UNKNOWN") << " ["
|
67
|
+
<< peripheral.address().value_or("UNKNOWN") << "]" << std::endl;
|
68
|
+
return EXIT_FAILURE;
|
69
|
+
}
|
70
|
+
|
71
|
+
std::cout << "Successfully connected, listing services." << std::endl;
|
72
|
+
auto services = peripheral.services();
|
73
|
+
|
74
|
+
if (!services.has_value()) {
|
75
|
+
std::cout << "Failed to list services." << std::endl;
|
76
|
+
return EXIT_FAILURE;
|
77
|
+
}
|
78
|
+
|
79
|
+
for (auto service : *services) {
|
80
|
+
std::cout << "Service: " << service.uuid() << std::endl;
|
81
|
+
for (auto characteristic : service.characteristics()) {
|
82
|
+
std::cout << " Characteristic: " << characteristic.uuid() << std::endl;
|
83
|
+
|
84
|
+
for (auto& descriptor : characteristic.descriptors()) {
|
85
|
+
std::cout << " Descriptor: " << descriptor.uuid() << std::endl;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
peripheral.disconnect();
|
90
|
+
return EXIT_SUCCESS;
|
91
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#include <iostream>
|
2
|
+
|
3
|
+
#include "simpleble/Adapter.h"
|
4
|
+
#include "simpleble/Utils.h"
|
5
|
+
|
6
|
+
int main() {
|
7
|
+
std::cout << "Using SimpleBLE version: " << SimpleBLE::get_simpleble_version() << std::endl;
|
8
|
+
std::cout << "Bluetooth enabled: " << SimpleBLE::Adapter::bluetooth_enabled() << std::endl;
|
9
|
+
|
10
|
+
auto adapter_list = SimpleBLE::Adapter::get_adapters();
|
11
|
+
|
12
|
+
if (adapter_list.empty()) {
|
13
|
+
std::cout << "No adapter found" << std::endl;
|
14
|
+
return EXIT_FAILURE;
|
15
|
+
}
|
16
|
+
|
17
|
+
for (auto& adapter : adapter_list) {
|
18
|
+
std::cout << "Adapter: " << adapter.identifier() << " [" << adapter.address() << "]" << std::endl;
|
19
|
+
}
|
20
|
+
|
21
|
+
return EXIT_SUCCESS;
|
22
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#include <iostream>
|
2
|
+
|
3
|
+
#include "simpleble/AdapterSafe.h"
|
4
|
+
|
5
|
+
int main() {
|
6
|
+
auto bluetooth_enabled = SimpleBLE::Safe::Adapter::bluetooth_enabled();
|
7
|
+
|
8
|
+
if (!bluetooth_enabled.has_value()) {
|
9
|
+
std::cout << "Failed to determine Bluetooth status" << std::endl;
|
10
|
+
return EXIT_FAILURE;
|
11
|
+
}
|
12
|
+
|
13
|
+
std::cout << "Bluetooth enabled: " << bluetooth_enabled.value() << std::endl;
|
14
|
+
|
15
|
+
auto adapter_list = SimpleBLE::Safe::Adapter::get_adapters();
|
16
|
+
|
17
|
+
if (!adapter_list.has_value()) {
|
18
|
+
std::cout << "Failed to list adapters" << std::endl;
|
19
|
+
return EXIT_FAILURE;
|
20
|
+
}
|
21
|
+
|
22
|
+
if (adapter_list->empty()) {
|
23
|
+
std::cout << "No adapter found" << std::endl;
|
24
|
+
return EXIT_FAILURE;
|
25
|
+
}
|
26
|
+
|
27
|
+
for (auto& adapter : *adapter_list) {
|
28
|
+
std::cout << "Adapter: " << adapter.identifier().value() << " [" << adapter.address().value() << "]"
|
29
|
+
<< std::endl;
|
30
|
+
}
|
31
|
+
|
32
|
+
return EXIT_SUCCESS;
|
33
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#include <iostream>
|
2
|
+
|
3
|
+
#include "simpleble/Adapter.h"
|
4
|
+
#include "simpleble/Utils.h"
|
5
|
+
|
6
|
+
int main() {
|
7
|
+
std::cout << "Using SimpleBLE version: " << SimpleBLE::get_simpleble_version() << std::endl;
|
8
|
+
std::cout << "Bluetooth enabled: " << SimpleBLE::Adapter::bluetooth_enabled() << std::endl;
|
9
|
+
|
10
|
+
auto adapter_list = SimpleBLE::Adapter::get_adapters();
|
11
|
+
|
12
|
+
if (adapter_list.empty()) {
|
13
|
+
std::cout << "No adapter found" << std::endl;
|
14
|
+
return EXIT_FAILURE;
|
15
|
+
}
|
16
|
+
|
17
|
+
for (auto& adapter : adapter_list) {
|
18
|
+
std::cout << "Adapter: " << adapter.identifier() << " [" << adapter.address() << "]" << std::endl;
|
19
|
+
|
20
|
+
auto peripherals = adapter.get_paired_peripherals();
|
21
|
+
for (auto& peripheral : peripherals) {
|
22
|
+
std::cout << " Peripheral: " << peripheral.identifier() << " [" << peripheral.address() << "]" << std::endl;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
return EXIT_SUCCESS;
|
27
|
+
}
|