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,813 @@
|
|
1
|
+
#include <string>
|
2
|
+
#include <jni.h>
|
3
|
+
|
4
|
+
#include "android_utils.h"
|
5
|
+
#include <simpleble/SimpleBLE.h>
|
6
|
+
#include <simpleble/Logging.h>
|
7
|
+
#include <fmt/core.h>
|
8
|
+
#include <vector>
|
9
|
+
#include <map>
|
10
|
+
#include <unordered_map>
|
11
|
+
#include <vector>
|
12
|
+
#include <memory>
|
13
|
+
#include "ThreadRunner.h"
|
14
|
+
#include <android/log.h>
|
15
|
+
|
16
|
+
// TODO: Switch to using regular SimpleBLE classes with try/catch blocks.
|
17
|
+
|
18
|
+
static std::map<size_t, SimpleBLE::Safe::Adapter> cached_adapters;
|
19
|
+
static std::map<size_t, std::vector<jweak>> cached_adapter_callbacks;
|
20
|
+
|
21
|
+
static std::map<size_t, std::map<size_t, SimpleBLE::Safe::Peripheral>> cached_peripherals;
|
22
|
+
static std::map<size_t, std::map<size_t, std::vector<jweak>>> cached_peripheral_callbacks;
|
23
|
+
static std::map<size_t, std::map<size_t, std::map<size_t, jobject>>> cached_peripheral_data_callbacks;
|
24
|
+
static ThreadRunner threadRunner;
|
25
|
+
static JavaVM *jvm;
|
26
|
+
|
27
|
+
JNIEnv* get_env() {
|
28
|
+
JNIEnv *env;
|
29
|
+
jvm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6);
|
30
|
+
return env;
|
31
|
+
}
|
32
|
+
|
33
|
+
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
34
|
+
jvm = vm;
|
35
|
+
threadRunner.set_jvm(vm);
|
36
|
+
|
37
|
+
// // Find your class. JNI_OnLoad is called from the correct class loader context for this to work.
|
38
|
+
// jclass c = env->FindClass("com/example/app/package/MyClass");
|
39
|
+
// if (c == nullptr) return JNI_ERR;
|
40
|
+
|
41
|
+
SimpleBLE::Logging::Logger::get()->set_callback(
|
42
|
+
[](SimpleBLE::Logging::Level level, const std::string& module, const std::string& file, uint32_t line, const std::string& function, const std::string& message) {
|
43
|
+
std::string log_message = fmt::format("{}: {}:{} in {}: {}\n", module, file, line, function, message);
|
44
|
+
|
45
|
+
int android_log_level = ANDROID_LOG_UNKNOWN;
|
46
|
+
switch (level) {
|
47
|
+
case SimpleBLE::Logging::Level::Verbose:
|
48
|
+
android_log_level = ANDROID_LOG_VERBOSE;
|
49
|
+
break;
|
50
|
+
case SimpleBLE::Logging::Level::Debug:
|
51
|
+
android_log_level = ANDROID_LOG_DEBUG;
|
52
|
+
break;
|
53
|
+
case SimpleBLE::Logging::Level::Info:
|
54
|
+
android_log_level = ANDROID_LOG_INFO;
|
55
|
+
break;
|
56
|
+
case SimpleBLE::Logging::Level::Warn:
|
57
|
+
android_log_level = ANDROID_LOG_WARN;
|
58
|
+
break;
|
59
|
+
case SimpleBLE::Logging::Level::Error:
|
60
|
+
android_log_level = ANDROID_LOG_ERROR;
|
61
|
+
break;
|
62
|
+
case SimpleBLE::Logging::Level::Fatal:
|
63
|
+
android_log_level = ANDROID_LOG_FATAL;
|
64
|
+
break;
|
65
|
+
case SimpleBLE::Logging::Level::None:
|
66
|
+
android_log_level = ANDROID_LOG_UNKNOWN;
|
67
|
+
break;
|
68
|
+
}
|
69
|
+
|
70
|
+
__android_log_write(android_log_level, "SimpleBLE", log_message.c_str());
|
71
|
+
}
|
72
|
+
);
|
73
|
+
|
74
|
+
return JNI_VERSION_1_6;
|
75
|
+
}
|
76
|
+
|
77
|
+
extern "C"
|
78
|
+
JNIEXPORT void JNICALL
|
79
|
+
Java_org_simpleble_android_Adapter_nativeAdapterRegister(JNIEnv *env, jobject thiz, jlong adapter_id, jobject callback) {
|
80
|
+
// TODO: IDEA. We could store the callback object whenever the scan starts and then remove it when the scan stops,
|
81
|
+
// to avoid having extra references lying around.
|
82
|
+
|
83
|
+
// Create a weak global reference to the Java callback object
|
84
|
+
jweak weakCallbackRef = env->NewWeakGlobalRef(callback);
|
85
|
+
|
86
|
+
// Store the weak reference in the cached_adapter_callbacks map
|
87
|
+
cached_adapter_callbacks[adapter_id].push_back(weakCallbackRef);
|
88
|
+
|
89
|
+
// Retrieve the adapter from the cached_adapters map
|
90
|
+
auto adapter = cached_adapters.at(adapter_id);
|
91
|
+
|
92
|
+
// TODO: Remove any invalid objects before adding new ones.
|
93
|
+
|
94
|
+
adapter.set_callback_on_scan_start([adapter_id](){
|
95
|
+
threadRunner.enqueue([adapter_id](){
|
96
|
+
JNIEnv *env = get_env();
|
97
|
+
|
98
|
+
// Retrieve the weak references from the cached_adapter_callbacks map
|
99
|
+
std::vector<jweak> weakCallbackRefs = cached_adapter_callbacks[adapter_id];
|
100
|
+
|
101
|
+
// Iterate over the weak references
|
102
|
+
for (jweak weakCallbackRef : weakCallbackRefs) {
|
103
|
+
|
104
|
+
// Check if the weak reference is still valid
|
105
|
+
if (env->IsSameObject(weakCallbackRef, nullptr) == JNI_FALSE) {
|
106
|
+
// Retrieve the strong reference from the weak reference
|
107
|
+
jobject callbackRef = env->NewLocalRef(weakCallbackRef);
|
108
|
+
|
109
|
+
// Find the Java class and method to invoke
|
110
|
+
// TODO: We should cache the class and method IDs
|
111
|
+
jclass callbackClass = env->GetObjectClass(callbackRef);
|
112
|
+
jmethodID onScanStartMethod = env->GetMethodID(callbackClass, "onScanStart", "()V");
|
113
|
+
|
114
|
+
// Invoke the Java callback method
|
115
|
+
env->CallVoidMethod(callbackRef, onScanStartMethod);
|
116
|
+
|
117
|
+
// Delete the local reference
|
118
|
+
env->DeleteLocalRef(callbackRef);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
});
|
122
|
+
});
|
123
|
+
|
124
|
+
adapter.set_callback_on_scan_stop([adapter_id](){
|
125
|
+
threadRunner.enqueue([adapter_id](){
|
126
|
+
JNIEnv *env = get_env();
|
127
|
+
|
128
|
+
// Retrieve the weak references from the cached_adapter_callbacks map
|
129
|
+
std::vector<jweak> weakCallbackRefs = cached_adapter_callbacks[adapter_id];
|
130
|
+
|
131
|
+
// Iterate over the weak references
|
132
|
+
for (jweak weakCallbackRef : weakCallbackRefs) {
|
133
|
+
// Check if the weak reference is still valid
|
134
|
+
if (env->IsSameObject(weakCallbackRef, nullptr) == JNI_FALSE) {
|
135
|
+
// Retrieve the strong reference from the weak reference
|
136
|
+
jobject callbackRef = env->NewLocalRef(weakCallbackRef);
|
137
|
+
|
138
|
+
// Find the Java class and method to invoke
|
139
|
+
// TODO: We should cache the class and method IDs
|
140
|
+
jclass callbackClass = env->GetObjectClass(callbackRef);
|
141
|
+
jmethodID onScanStopMethod = env->GetMethodID(callbackClass, "onScanStop", "()V");
|
142
|
+
|
143
|
+
// Invoke the Java callback method
|
144
|
+
env->CallVoidMethod(callbackRef, onScanStopMethod);
|
145
|
+
|
146
|
+
// Delete the local reference
|
147
|
+
env->DeleteLocalRef(callbackRef);
|
148
|
+
}
|
149
|
+
}
|
150
|
+
});
|
151
|
+
});
|
152
|
+
|
153
|
+
adapter.set_callback_on_scan_found([adapter_id](SimpleBLE::Safe::Peripheral peripheral){
|
154
|
+
size_t peripheral_hash = std::hash<std::string>{}(peripheral.address().value_or("UNKNOWN"));
|
155
|
+
|
156
|
+
// Add to the cache if it doesn't exist
|
157
|
+
if (cached_peripherals[adapter_id].count(peripheral_hash) == 0) {
|
158
|
+
cached_peripherals[adapter_id].insert({peripheral_hash, peripheral});
|
159
|
+
}
|
160
|
+
|
161
|
+
threadRunner.enqueue([adapter_id, peripheral_hash](){
|
162
|
+
JNIEnv *env = get_env();
|
163
|
+
|
164
|
+
// Retrieve the weak references from the cached_adapter_callbacks map
|
165
|
+
std::vector<jweak> weakCallbackRefs = cached_adapter_callbacks[adapter_id];
|
166
|
+
|
167
|
+
// Iterate over the weak references
|
168
|
+
for (jweak weakCallbackRef : weakCallbackRefs) {
|
169
|
+
// Check if the weak reference is still valid
|
170
|
+
if (env->IsSameObject(weakCallbackRef, nullptr) == JNI_FALSE) {
|
171
|
+
|
172
|
+
// Retrieve the strong reference from the weak reference
|
173
|
+
jobject callbackRef = env->NewLocalRef(weakCallbackRef);
|
174
|
+
|
175
|
+
// Find the Java class and method to invoke
|
176
|
+
// TODO: We should cache the class and method IDs
|
177
|
+
jclass callbackClass = env->GetObjectClass(callbackRef);
|
178
|
+
jmethodID onScanFoundMethod = env->GetMethodID(callbackClass, "onScanFound","(J)V");
|
179
|
+
|
180
|
+
// Invoke the Java callback method
|
181
|
+
env->CallVoidMethod(callbackRef, onScanFoundMethod, peripheral_hash);
|
182
|
+
|
183
|
+
// Delete the local reference
|
184
|
+
env->DeleteLocalRef(callbackRef);
|
185
|
+
|
186
|
+
}
|
187
|
+
}
|
188
|
+
});
|
189
|
+
});
|
190
|
+
|
191
|
+
adapter.set_callback_on_scan_updated([adapter_id](SimpleBLE::Safe::Peripheral peripheral){
|
192
|
+
size_t peripheral_hash = std::hash<std::string>{}(peripheral.address().value_or("UNKNOWN"));
|
193
|
+
|
194
|
+
// Add to the cache if it doesn't exist
|
195
|
+
if (cached_peripherals[adapter_id].count(peripheral_hash) == 0) {
|
196
|
+
cached_peripherals[adapter_id].insert({peripheral_hash, peripheral});
|
197
|
+
}
|
198
|
+
|
199
|
+
threadRunner.enqueue([adapter_id, peripheral_hash](){
|
200
|
+
JNIEnv *env = get_env();
|
201
|
+
|
202
|
+
// Retrieve the weak references from the cached_adapter_callbacks map
|
203
|
+
std::vector<jweak> weakCallbackRefs = cached_adapter_callbacks[adapter_id];
|
204
|
+
|
205
|
+
// Iterate over the weak references
|
206
|
+
for (jweak weakCallbackRef : weakCallbackRefs) {
|
207
|
+
// Check if the weak reference is still valid
|
208
|
+
if (env->IsSameObject(weakCallbackRef, nullptr) == JNI_FALSE) {
|
209
|
+
|
210
|
+
// Retrieve the strong reference from the weak reference
|
211
|
+
jobject callbackRef = env->NewLocalRef(weakCallbackRef);
|
212
|
+
|
213
|
+
// Find the Java class and method to invoke
|
214
|
+
// TODO: We should cache the class and method IDs
|
215
|
+
jclass callbackClass = env->GetObjectClass(callbackRef);
|
216
|
+
jmethodID onScanFoundMethod = env->GetMethodID(callbackClass, "onScanUpdated", "(J)V");
|
217
|
+
|
218
|
+
// Invoke the Java callback method
|
219
|
+
env->CallVoidMethod(callbackRef, onScanFoundMethod, peripheral_hash);
|
220
|
+
|
221
|
+
// Delete the local reference
|
222
|
+
env->DeleteLocalRef(callbackRef);
|
223
|
+
|
224
|
+
}
|
225
|
+
}
|
226
|
+
});
|
227
|
+
});
|
228
|
+
}
|
229
|
+
|
230
|
+
extern "C"
|
231
|
+
JNIEXPORT jboolean JNICALL
|
232
|
+
Java_org_simpleble_android_Adapter_00024Companion_nativeIsBluetoothEnabled(JNIEnv *env, jobject thiz) {
|
233
|
+
return SimpleBLE::Safe::Adapter::bluetooth_enabled().value_or(false);
|
234
|
+
}
|
235
|
+
|
236
|
+
extern "C" JNIEXPORT jlongArray JNICALL Java_org_simpleble_android_Adapter_nativeGetAdapters(JNIEnv *env, jclass clazz) {
|
237
|
+
auto adapters = SimpleBLE::Safe::Adapter::get_adapters();
|
238
|
+
|
239
|
+
// If an error occurred, return an empty list.
|
240
|
+
if (!adapters.has_value()) return env->NewLongArray(0);
|
241
|
+
|
242
|
+
// Go over the results, cache whatever doesn't exist and return the full list.
|
243
|
+
jsize j_adapter_index = 0;
|
244
|
+
jlongArray j_adapter_result = env->NewLongArray(static_cast<int>(adapters.value().size()));
|
245
|
+
for (auto &adapter: adapters.value()) {
|
246
|
+
size_t adapter_hash = std::hash<std::string>{}(adapter.identifier().value_or("UNKNOWN"));
|
247
|
+
|
248
|
+
// Add to the cache if it doesn't exist
|
249
|
+
if (cached_adapters.count(adapter_hash) == 0) {
|
250
|
+
cached_adapters.insert({adapter_hash, adapter});
|
251
|
+
}
|
252
|
+
|
253
|
+
// Add to the results
|
254
|
+
jlong j_adapter_hash = adapter_hash;
|
255
|
+
env->SetLongArrayRegion(j_adapter_result, j_adapter_index, 1, &j_adapter_hash);
|
256
|
+
j_adapter_index++;
|
257
|
+
|
258
|
+
}
|
259
|
+
|
260
|
+
return j_adapter_result;
|
261
|
+
}
|
262
|
+
|
263
|
+
extern "C" JNIEXPORT jstring JNICALL Java_org_simpleble_android_Adapter_nativeAdapterIdentifier(JNIEnv *env, jobject thiz, jlong adapter_id) {
|
264
|
+
auto adapter = cached_adapters.at(adapter_id);
|
265
|
+
// TODO: Should throw exception in case of failure.
|
266
|
+
return to_jstring(env, adapter.identifier().value_or("Unknown"));
|
267
|
+
}
|
268
|
+
|
269
|
+
extern "C" JNIEXPORT jstring JNICALL Java_org_simpleble_android_Adapter_nativeAdapterAddress(JNIEnv *env, jobject thiz, jlong adapter_id) {
|
270
|
+
auto adapter = cached_adapters.at(adapter_id);
|
271
|
+
// TODO: Should throw exception in case of failure.
|
272
|
+
return to_jstring(env, adapter.address().value_or("Unknown"));
|
273
|
+
}
|
274
|
+
|
275
|
+
extern "C" JNIEXPORT void JNICALL Java_org_simpleble_android_Adapter_nativeAdapterScanStart(JNIEnv *env, jobject thiz, jlong adapter_id) {
|
276
|
+
auto adapter = cached_adapters.at(adapter_id);
|
277
|
+
bool success = adapter.scan_start();
|
278
|
+
|
279
|
+
if (!success) {
|
280
|
+
throw_exception(env, "Failed to start scan");
|
281
|
+
}
|
282
|
+
}
|
283
|
+
|
284
|
+
extern "C" JNIEXPORT void JNICALL Java_org_simpleble_android_Adapter_nativeAdapterScanStop(JNIEnv *env, jobject thiz, jlong adapter_id) {
|
285
|
+
auto adapter = cached_adapters.at(adapter_id);
|
286
|
+
bool success = adapter.scan_stop();
|
287
|
+
|
288
|
+
if (!success) {
|
289
|
+
throw_exception(env, "Failed to stop scan");
|
290
|
+
}
|
291
|
+
}
|
292
|
+
|
293
|
+
extern "C" JNIEXPORT void JNICALL Java_org_simpleble_android_Adapter_nativeAdapterScanFor(JNIEnv *env, jobject thiz, jlong adapter_id, jint timeout) {
|
294
|
+
auto adapter = cached_adapters.at(adapter_id);
|
295
|
+
bool success = adapter.scan_for(timeout);
|
296
|
+
|
297
|
+
if (!success) {
|
298
|
+
throw_exception(env, "Failed to scan for");
|
299
|
+
}
|
300
|
+
}
|
301
|
+
|
302
|
+
extern "C" JNIEXPORT jboolean JNICALL Java_org_simpleble_android_Adapter_nativeAdapterScanIsActive(JNIEnv *env, jobject thiz, jlong adapter_id) {
|
303
|
+
auto adapter = cached_adapters.at(adapter_id);
|
304
|
+
// TODO: Should throw exception in case of failure.
|
305
|
+
return adapter.scan_is_active().value_or(false);
|
306
|
+
}
|
307
|
+
|
308
|
+
extern "C" JNIEXPORT jlongArray JNICALL Java_org_simpleble_android_Adapter_nativeAdapterScanGetResults(JNIEnv *env, jobject thiz, jlong adapter_id) {
|
309
|
+
auto adapter = cached_adapters.at(adapter_id);
|
310
|
+
|
311
|
+
auto peripherals = adapter.scan_get_results();
|
312
|
+
|
313
|
+
// If an error occurred, return an empty list.
|
314
|
+
if (!peripherals.has_value()) return env->NewLongArray(0);
|
315
|
+
|
316
|
+
jsize j_peripheral_index = 0;
|
317
|
+
jlongArray j_peripheral_result = env->NewLongArray(static_cast<int>(peripherals.value().size()));
|
318
|
+
for (auto &peripheral: peripherals.value()) {
|
319
|
+
size_t peripheral_hash = std::hash<std::string>{}(peripheral.address().value_or("UNKNOWN"));
|
320
|
+
|
321
|
+
// Add to the cache if it doesn't exist
|
322
|
+
if (cached_peripherals[adapter_id].count(peripheral_hash) == 0) {
|
323
|
+
cached_peripherals[adapter_id].insert({peripheral_hash, peripheral});
|
324
|
+
}
|
325
|
+
|
326
|
+
// Add to the results
|
327
|
+
jlong j_peripheral_hash = peripheral_hash;
|
328
|
+
env->SetLongArrayRegion(j_peripheral_result, j_peripheral_index, 1, &j_peripheral_hash);
|
329
|
+
j_peripheral_index++;
|
330
|
+
}
|
331
|
+
|
332
|
+
return j_peripheral_result;
|
333
|
+
}
|
334
|
+
|
335
|
+
// PERIPHERAL
|
336
|
+
|
337
|
+
extern "C"
|
338
|
+
JNIEXPORT void JNICALL
|
339
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralRegister(JNIEnv *env, jobject thiz,
|
340
|
+
jlong adapter_id, jlong peripheral_id, jobject callback) {
|
341
|
+
// TODO: IDEA. We could store the callback object whenever the scan starts and then remove it when the scan stops,
|
342
|
+
// to avoid having extra references lying around.
|
343
|
+
|
344
|
+
// Create a weak global reference to the Java callback object
|
345
|
+
jweak weakCallbackRef = env->NewWeakGlobalRef(callback);
|
346
|
+
|
347
|
+
// Store the weak reference in the cached_adapter_callbacks map
|
348
|
+
cached_peripheral_callbacks[adapter_id][peripheral_id].push_back(weakCallbackRef);
|
349
|
+
|
350
|
+
auto peripheral = cached_peripherals[adapter_id].at(peripheral_id);
|
351
|
+
|
352
|
+
// TODO: Remove any invalid objects before adding new ones.
|
353
|
+
|
354
|
+
peripheral.set_callback_on_connected([adapter_id, peripheral_id](){
|
355
|
+
threadRunner.enqueue([adapter_id, peripheral_id](){
|
356
|
+
JNIEnv *env = get_env();
|
357
|
+
|
358
|
+
// Retrieve the weak references from the cached_adapter_callbacks map
|
359
|
+
std::vector<jweak> weakCallbackRefs = cached_peripheral_callbacks[adapter_id][peripheral_id];
|
360
|
+
|
361
|
+
// Iterate over the weak references
|
362
|
+
for (jweak weakCallbackRef : weakCallbackRefs) {
|
363
|
+
|
364
|
+
// Check if the weak reference is still valid
|
365
|
+
if (env->IsSameObject(weakCallbackRef, nullptr) == JNI_FALSE) {
|
366
|
+
// Retrieve the strong reference from the weak reference
|
367
|
+
jobject callbackRef = env->NewLocalRef(weakCallbackRef);
|
368
|
+
|
369
|
+
// Find the Java class and method to invoke
|
370
|
+
// TODO: We should cache the class and method IDs
|
371
|
+
jclass callbackClass = env->GetObjectClass(callbackRef);
|
372
|
+
jmethodID onConnectedMethod = env->GetMethodID(callbackClass, "onConnected", "()V");
|
373
|
+
|
374
|
+
// Invoke the Java callback method
|
375
|
+
env->CallVoidMethod(callbackRef, onConnectedMethod);
|
376
|
+
|
377
|
+
// Delete the local reference
|
378
|
+
env->DeleteLocalRef(callbackRef);
|
379
|
+
}
|
380
|
+
}
|
381
|
+
});
|
382
|
+
});
|
383
|
+
|
384
|
+
peripheral.set_callback_on_disconnected([adapter_id, peripheral_id](){
|
385
|
+
threadRunner.enqueue([adapter_id, peripheral_id](){
|
386
|
+
JNIEnv *env = get_env();
|
387
|
+
|
388
|
+
// Retrieve the weak references from the cached_adapter_callbacks map
|
389
|
+
std::vector<jweak> weakCallbackRefs = cached_peripheral_callbacks[adapter_id][peripheral_id];
|
390
|
+
|
391
|
+
// Iterate over the weak references
|
392
|
+
for (jweak weakCallbackRef : weakCallbackRefs) {
|
393
|
+
|
394
|
+
// Check if the weak reference is still valid
|
395
|
+
if (env->IsSameObject(weakCallbackRef, nullptr) == JNI_FALSE) {
|
396
|
+
// Retrieve the strong reference from the weak reference
|
397
|
+
jobject callbackRef = env->NewLocalRef(weakCallbackRef);
|
398
|
+
|
399
|
+
// Find the Java class and method to invoke
|
400
|
+
// TODO: We should cache the class and method IDs
|
401
|
+
jclass callbackClass = env->GetObjectClass(callbackRef);
|
402
|
+
jmethodID onConnectedMethod = env->GetMethodID(callbackClass, "onDisconnected", "()V");
|
403
|
+
|
404
|
+
// Invoke the Java callback method
|
405
|
+
env->CallVoidMethod(callbackRef, onConnectedMethod);
|
406
|
+
|
407
|
+
// Delete the local reference
|
408
|
+
env->DeleteLocalRef(callbackRef);
|
409
|
+
}
|
410
|
+
}
|
411
|
+
});
|
412
|
+
});
|
413
|
+
}
|
414
|
+
|
415
|
+
extern "C"
|
416
|
+
JNIEXPORT jstring JNICALL
|
417
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralIdentifier(JNIEnv *env, jobject thiz,
|
418
|
+
jlong adapter_id,
|
419
|
+
jlong peripheral_id) {
|
420
|
+
auto& peripheral = cached_peripherals[adapter_id].at(peripheral_id);
|
421
|
+
return to_jstring(env, peripheral.identifier().value_or("Unknown"));
|
422
|
+
}
|
423
|
+
|
424
|
+
extern "C"
|
425
|
+
JNIEXPORT jstring JNICALL
|
426
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralAddress(JNIEnv *env, jobject thiz,
|
427
|
+
jlong adapter_id, jlong peripheral_id) {
|
428
|
+
auto& peripheral = cached_peripherals[adapter_id].at(peripheral_id);
|
429
|
+
return to_jstring(env, peripheral.address().value_or("Unknown"));
|
430
|
+
}
|
431
|
+
|
432
|
+
extern "C"
|
433
|
+
JNIEXPORT jint JNICALL
|
434
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralAddressType(JNIEnv *env, jobject thiz,
|
435
|
+
jlong adapter_id,
|
436
|
+
jlong peripheral_id) {
|
437
|
+
auto& peripheral = cached_peripherals[adapter_id].at(peripheral_id);
|
438
|
+
return peripheral.address_type().value_or(SimpleBLE::BluetoothAddressType::UNSPECIFIED);
|
439
|
+
}
|
440
|
+
|
441
|
+
extern "C"
|
442
|
+
JNIEXPORT jint JNICALL
|
443
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralRssi(JNIEnv *env, jobject thiz,
|
444
|
+
jlong adapter_id, jlong peripheral_id) {
|
445
|
+
auto& peripheral = cached_peripherals[adapter_id].at(peripheral_id);
|
446
|
+
return peripheral.rssi().value_or(INT16_MIN);
|
447
|
+
}
|
448
|
+
|
449
|
+
extern "C"
|
450
|
+
JNIEXPORT jint JNICALL
|
451
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralTxPower(JNIEnv *env, jobject thiz,
|
452
|
+
jlong adapter_id, jlong peripheral_id) {
|
453
|
+
auto& peripheral = cached_peripherals[adapter_id].at(peripheral_id);
|
454
|
+
return peripheral.tx_power().value_or(INT16_MIN);
|
455
|
+
}
|
456
|
+
|
457
|
+
extern "C"
|
458
|
+
JNIEXPORT jint JNICALL
|
459
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralMtu(JNIEnv *env, jobject thiz,
|
460
|
+
jlong adapter_id, jlong peripheral_id) {
|
461
|
+
auto& peripheral = cached_peripherals[adapter_id].at(peripheral_id);
|
462
|
+
return peripheral.mtu().value_or(UINT16_MAX);
|
463
|
+
}
|
464
|
+
|
465
|
+
extern "C"
|
466
|
+
JNIEXPORT void JNICALL
|
467
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralConnect(JNIEnv *env, jobject thiz,
|
468
|
+
jlong adapter_id, jlong peripheral_id) {
|
469
|
+
auto peripheral = cached_peripherals[adapter_id].at(peripheral_id);
|
470
|
+
|
471
|
+
bool success = peripheral.connect();
|
472
|
+
if (!success) {
|
473
|
+
throw_exception(env, "Failed to connect");
|
474
|
+
}
|
475
|
+
}
|
476
|
+
|
477
|
+
extern "C"
|
478
|
+
JNIEXPORT void JNICALL
|
479
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralDisconnect(JNIEnv *env, jobject thiz,
|
480
|
+
jlong adapter_id,
|
481
|
+
jlong peripheral_id) {
|
482
|
+
auto& peripheral = cached_peripherals[adapter_id].at(peripheral_id);
|
483
|
+
peripheral.disconnect();
|
484
|
+
}
|
485
|
+
|
486
|
+
extern "C"
|
487
|
+
JNIEXPORT void JNICALL
|
488
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralNotify(JNIEnv *env, jobject thiz,
|
489
|
+
jlong adapter_id, jlong peripheral_id,
|
490
|
+
jstring j_service,
|
491
|
+
jstring j_characteristic,
|
492
|
+
jobject callback) {
|
493
|
+
|
494
|
+
std::string service = from_jstring(env, j_service);
|
495
|
+
std::string characteristic = from_jstring(env, j_characteristic);
|
496
|
+
std::string service_characteristic = service + "_" + characteristic;
|
497
|
+
size_t service_characteristic_hash = std::hash<std::string>{}(service_characteristic);
|
498
|
+
|
499
|
+
jobject callbackRef = env->NewGlobalRef(callback);
|
500
|
+
// TODO: Check if there is a callback already registered for this service_characteristic_hash
|
501
|
+
cached_peripheral_data_callbacks[adapter_id][peripheral_id].insert({service_characteristic_hash, callbackRef});
|
502
|
+
|
503
|
+
auto peripheral = cached_peripherals[adapter_id].at(peripheral_id);
|
504
|
+
bool success = peripheral.notify(service, characteristic, [adapter_id, peripheral_id, service_characteristic_hash](SimpleBLE::ByteArray payload){
|
505
|
+
|
506
|
+
std::string payload_contents;
|
507
|
+
for (int i = 0; i < payload.size(); i++) {
|
508
|
+
payload_contents += fmt::format("{:02X}", (int)(payload[i]));
|
509
|
+
}
|
510
|
+
|
511
|
+
log_info("Received payload: " + payload_contents);
|
512
|
+
|
513
|
+
threadRunner.enqueue([adapter_id, peripheral_id, service_characteristic_hash, payload]() {
|
514
|
+
JNIEnv *env = get_env();
|
515
|
+
|
516
|
+
// Retrieve the weak references from the cached_adapter_callbacks map
|
517
|
+
jobject callbackRef = cached_peripheral_data_callbacks[adapter_id][peripheral_id].at(service_characteristic_hash);
|
518
|
+
jbyteArray j_payload = to_jbyteArray(env, payload);
|
519
|
+
|
520
|
+
// TODO: We should cache the class and method IDs
|
521
|
+
jclass callbackClass = env->GetObjectClass(callbackRef);
|
522
|
+
jmethodID onDataReceivedMethod = env->GetMethodID(callbackClass, "onDataReceived", "([B)V");
|
523
|
+
|
524
|
+
// Invoke the Java callback method
|
525
|
+
env->CallVoidMethod(callbackRef, onDataReceivedMethod, j_payload);
|
526
|
+
|
527
|
+
});
|
528
|
+
});
|
529
|
+
|
530
|
+
if (!success) {
|
531
|
+
throw_exception(env, "Failed to notify");
|
532
|
+
}
|
533
|
+
}
|
534
|
+
|
535
|
+
|
536
|
+
extern "C"
|
537
|
+
JNIEXPORT void JNICALL
|
538
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralIndicate(JNIEnv *env, jobject thiz,
|
539
|
+
jlong adapter_id, jlong peripheral_id,
|
540
|
+
jstring j_service,
|
541
|
+
jstring j_characteristic,
|
542
|
+
jobject callback) {
|
543
|
+
|
544
|
+
std::string service = from_jstring(env, j_service);
|
545
|
+
std::string characteristic = from_jstring(env, j_characteristic);
|
546
|
+
std::string service_characteristic = service + "_" + characteristic;
|
547
|
+
size_t service_characteristic_hash = std::hash<std::string>{}(service_characteristic);
|
548
|
+
|
549
|
+
jobject callbackRef = env->NewGlobalRef(callback);
|
550
|
+
// TODO: Check if there is a callback already registered for this service_characteristic_hash
|
551
|
+
cached_peripheral_data_callbacks[adapter_id][peripheral_id].insert({service_characteristic_hash, callbackRef});
|
552
|
+
|
553
|
+
auto peripheral = cached_peripherals[adapter_id].at(peripheral_id);
|
554
|
+
bool success = peripheral.indicate(service, characteristic, [adapter_id, peripheral_id, service_characteristic_hash](SimpleBLE::ByteArray payload){
|
555
|
+
|
556
|
+
std::string payload_contents;
|
557
|
+
for (int i = 0; i < payload.size(); i++) {
|
558
|
+
payload_contents += fmt::format("{:02X}", (int)(payload[i]));
|
559
|
+
}
|
560
|
+
|
561
|
+
log_info("Received payload: " + payload_contents);
|
562
|
+
|
563
|
+
threadRunner.enqueue([adapter_id, peripheral_id, service_characteristic_hash, payload]() {
|
564
|
+
JNIEnv *env = get_env();
|
565
|
+
|
566
|
+
// Retrieve the weak references from the cached_adapter_callbacks map
|
567
|
+
jobject callbackRef = cached_peripheral_data_callbacks[adapter_id][peripheral_id].at(service_characteristic_hash);
|
568
|
+
jbyteArray j_payload = to_jbyteArray(env, payload);
|
569
|
+
|
570
|
+
// TODO: We should cache the class and method IDs
|
571
|
+
jclass callbackClass = env->GetObjectClass(callbackRef);
|
572
|
+
jmethodID onDataReceivedMethod = env->GetMethodID(callbackClass, "onDataReceived", "([B)V");
|
573
|
+
|
574
|
+
// Invoke the Java callback method
|
575
|
+
env->CallVoidMethod(callbackRef, onDataReceivedMethod, j_payload);
|
576
|
+
|
577
|
+
});
|
578
|
+
});
|
579
|
+
|
580
|
+
if (!success) {
|
581
|
+
throw_exception(env, "Failed to notify");
|
582
|
+
}
|
583
|
+
}
|
584
|
+
extern "C"
|
585
|
+
JNIEXPORT void JNICALL
|
586
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralUnsubscribe(JNIEnv *env, jobject thiz,
|
587
|
+
jlong adapter_id,
|
588
|
+
jlong peripheral_id,
|
589
|
+
jstring j_service,
|
590
|
+
jstring j_characteristic) {
|
591
|
+
std::string service = from_jstring(env, j_service);
|
592
|
+
std::string characteristic = from_jstring(env, j_characteristic);
|
593
|
+
std::string service_characteristic = service + "_" + characteristic;
|
594
|
+
size_t service_characteristic_hash = std::hash<std::string>{}(service_characteristic);
|
595
|
+
|
596
|
+
auto peripheral = cached_peripherals[adapter_id].at(peripheral_id);
|
597
|
+
bool success = peripheral.unsubscribe(service, characteristic);
|
598
|
+
|
599
|
+
if (!success) {
|
600
|
+
throw_exception(env, "Failed to unsubscribe");
|
601
|
+
}
|
602
|
+
|
603
|
+
jobject callbackRef = cached_peripheral_data_callbacks[adapter_id][peripheral_id].at(service_characteristic_hash);
|
604
|
+
|
605
|
+
// TODO: Should some check be done here to see if the callbackRef is still valid?
|
606
|
+
env->DeleteGlobalRef(callbackRef);
|
607
|
+
cached_peripheral_data_callbacks[adapter_id][peripheral_id].erase(service_characteristic_hash);
|
608
|
+
}
|
609
|
+
|
610
|
+
extern "C"
|
611
|
+
JNIEXPORT jboolean JNICALL
|
612
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralIsConnected(JNIEnv *env, jobject thiz,
|
613
|
+
jlong adapter_id,
|
614
|
+
jlong instance_id) {
|
615
|
+
auto& peripheral = cached_peripherals[adapter_id].at(instance_id);
|
616
|
+
return peripheral.is_connected().value_or(false);
|
617
|
+
}
|
618
|
+
|
619
|
+
extern "C"
|
620
|
+
JNIEXPORT jboolean JNICALL
|
621
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralIsConnectable(JNIEnv *env, jobject thiz,
|
622
|
+
jlong adapter_id,
|
623
|
+
jlong instance_id) {
|
624
|
+
auto& peripheral = cached_peripherals[adapter_id].at(instance_id);
|
625
|
+
return peripheral.is_connectable().value_or(false);
|
626
|
+
}
|
627
|
+
|
628
|
+
extern "C"
|
629
|
+
JNIEXPORT jboolean JNICALL
|
630
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralIsPaired(JNIEnv *env, jobject thiz,
|
631
|
+
jlong adapter_id,
|
632
|
+
jlong instance_id) {
|
633
|
+
auto& peripheral = cached_peripherals[adapter_id].at(instance_id);
|
634
|
+
return peripheral.is_paired().value_or(false);
|
635
|
+
}
|
636
|
+
|
637
|
+
extern "C"
|
638
|
+
JNIEXPORT void JNICALL
|
639
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralUnpair(JNIEnv *env, jobject thiz,
|
640
|
+
jlong adapter_id, jlong instance_id) {
|
641
|
+
auto& peripheral = cached_peripherals[adapter_id].at(instance_id);
|
642
|
+
peripheral.unpair();
|
643
|
+
}
|
644
|
+
|
645
|
+
extern "C"
|
646
|
+
JNIEXPORT jobject JNICALL
|
647
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralServices(JNIEnv* env, jobject thiz,
|
648
|
+
jlong adapter_id,
|
649
|
+
jlong peripheral_id) {
|
650
|
+
auto& peripheral = cached_peripherals[adapter_id].at(peripheral_id);
|
651
|
+
auto services = peripheral.services().value_or(std::vector<SimpleBLE::Service>{});
|
652
|
+
|
653
|
+
jclass serviceClass = env->FindClass("org/simpleble/android/Service");
|
654
|
+
jclass characteristicClass = env->FindClass("org/simpleble/android/Characteristic");
|
655
|
+
jclass descriptorClass = env->FindClass("org/simpleble/android/Descriptor");
|
656
|
+
|
657
|
+
jmethodID serviceConstructor = env->GetMethodID(serviceClass, "<init>", "(Ljava/lang/String;Ljava/util/List;)V");
|
658
|
+
jmethodID characteristicConstructor = env->GetMethodID(characteristicClass, "<init>", "(Ljava/lang/String;Ljava/util/List;ZZZZZ)V");
|
659
|
+
jmethodID descriptorConstructor = env->GetMethodID(descriptorClass, "<init>", "(Ljava/lang/String;)V");
|
660
|
+
|
661
|
+
jobject serviceArray = jarraylist_new(env);
|
662
|
+
|
663
|
+
for (auto service : services) {
|
664
|
+
jstring serviceUUID = to_jstring(env, service.uuid());
|
665
|
+
jobject charList = jarraylist_new(env);
|
666
|
+
|
667
|
+
for (auto characteristic : service.characteristics()) {
|
668
|
+
jstring charUUID = to_jstring(env, characteristic.uuid());
|
669
|
+
jobject descList = jarraylist_new(env);
|
670
|
+
|
671
|
+
for (auto descriptor : characteristic.descriptors()) {
|
672
|
+
jstring descUUID = to_jstring(env, descriptor.uuid());
|
673
|
+
jobject jDescriptor = env->NewObject(descriptorClass, descriptorConstructor, descUUID);
|
674
|
+
jarraylist_add(env, descList, jDescriptor);
|
675
|
+
}
|
676
|
+
|
677
|
+
jobject jCharacteristic = env->NewObject(characteristicClass, characteristicConstructor,
|
678
|
+
charUUID, descList,
|
679
|
+
characteristic.can_read(),
|
680
|
+
characteristic.can_write_request(),
|
681
|
+
characteristic.can_write_command(),
|
682
|
+
characteristic.can_notify(),
|
683
|
+
characteristic.can_indicate());
|
684
|
+
jarraylist_add(env, charList, jCharacteristic);
|
685
|
+
}
|
686
|
+
|
687
|
+
jobject jService = env->NewObject(serviceClass, serviceConstructor, serviceUUID, charList);
|
688
|
+
jarraylist_add(env, serviceArray, jService);
|
689
|
+
}
|
690
|
+
|
691
|
+
return serviceArray;
|
692
|
+
}
|
693
|
+
|
694
|
+
// Utility function to create a new HashMap and return it
|
695
|
+
jobject NewHashMap(JNIEnv* env) {
|
696
|
+
jclass hashMapClass = env->FindClass("java/util/HashMap");
|
697
|
+
if (hashMapClass == nullptr) {
|
698
|
+
return nullptr; // Class not found
|
699
|
+
}
|
700
|
+
jmethodID hashMapConstructor = env->GetMethodID(hashMapClass, "<init>", "()V");
|
701
|
+
if (hashMapConstructor == nullptr) {
|
702
|
+
return nullptr; // Constructor method not found
|
703
|
+
}
|
704
|
+
jobject hashMap = env->NewObject(hashMapClass, hashMapConstructor);
|
705
|
+
return hashMap;
|
706
|
+
}
|
707
|
+
|
708
|
+
// Utility function to add an entry to a HashMap
|
709
|
+
void HashMapPut(JNIEnv* env, jobject hashMap, jobject key, jobject value) {
|
710
|
+
jclass hashMapClass = env->GetObjectClass(hashMap);
|
711
|
+
if (hashMapClass == nullptr) {
|
712
|
+
return; // Class not found
|
713
|
+
}
|
714
|
+
jmethodID hashMapPut = env->GetMethodID(hashMapClass, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
|
715
|
+
if (hashMapPut == nullptr) {
|
716
|
+
return; // Method not found
|
717
|
+
}
|
718
|
+
env->CallObjectMethod(hashMap, hashMapPut, key, value);
|
719
|
+
}
|
720
|
+
|
721
|
+
|
722
|
+
// Convert a C++ int to a Java Integer
|
723
|
+
jobject to_jInteger(JNIEnv* env, jint value) {
|
724
|
+
jclass integerClass = env->FindClass("java/lang/Integer");
|
725
|
+
if (!integerClass) return nullptr; // Class not found
|
726
|
+
|
727
|
+
jmethodID integerConstructor = env->GetMethodID(integerClass, "<init>", "(I)V");
|
728
|
+
if (!integerConstructor) return nullptr; // Constructor method not found
|
729
|
+
|
730
|
+
jobject integerObject = env->NewObject(integerClass, integerConstructor, value);
|
731
|
+
return integerObject;
|
732
|
+
}
|
733
|
+
|
734
|
+
// JNI function implementation
|
735
|
+
extern "C"
|
736
|
+
JNIEXPORT jobject JNICALL
|
737
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralManufacturerData(JNIEnv* env, jobject thiz, jlong adapter_id, jlong instance_id) {
|
738
|
+
auto& peripheral = cached_peripherals[adapter_id].at(instance_id);
|
739
|
+
auto manufacturer_data = peripheral.manufacturer_data().value();
|
740
|
+
|
741
|
+
jobject hashMap = NewHashMap(env);
|
742
|
+
if (!hashMap) return nullptr; // Error creating HashMap
|
743
|
+
|
744
|
+
for (const auto& data : manufacturer_data) {
|
745
|
+
jobject key = to_jInteger(env, static_cast<jint>(data.first));
|
746
|
+
jbyteArray value = to_jbyteArray(env, data.second);
|
747
|
+
|
748
|
+
HashMapPut(env, hashMap, key, value);
|
749
|
+
|
750
|
+
env->DeleteLocalRef(key);
|
751
|
+
env->DeleteLocalRef(value);
|
752
|
+
}
|
753
|
+
|
754
|
+
return hashMap;
|
755
|
+
}
|
756
|
+
|
757
|
+
extern "C"
|
758
|
+
JNIEXPORT jbyteArray JNICALL
|
759
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralRead(JNIEnv *env, jobject thiz,
|
760
|
+
jlong adapter_id, jlong peripheral_id,
|
761
|
+
jstring j_service,
|
762
|
+
jstring j_characteristic) {
|
763
|
+
std::string service = from_jstring(env, j_service);
|
764
|
+
std::string characteristic = from_jstring(env, j_characteristic);
|
765
|
+
|
766
|
+
auto peripheral = cached_peripherals[adapter_id].at(peripheral_id);
|
767
|
+
SimpleBLE::ByteArray result = peripheral.read(service, characteristic).value_or("");
|
768
|
+
|
769
|
+
return to_jbyteArray(env, result);
|
770
|
+
}
|
771
|
+
extern "C"
|
772
|
+
JNIEXPORT void JNICALL
|
773
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralWriteRequest(JNIEnv *env, jobject thiz,
|
774
|
+
jlong adapter_id,
|
775
|
+
jlong instance_id,
|
776
|
+
jstring service,
|
777
|
+
jstring characteristic,
|
778
|
+
jbyteArray data) {
|
779
|
+
// TODO: implement nativePeripheralWriteRequest()
|
780
|
+
}
|
781
|
+
extern "C"
|
782
|
+
JNIEXPORT void JNICALL
|
783
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralWriteCommand(JNIEnv *env, jobject thiz,
|
784
|
+
jlong adapter_id,
|
785
|
+
jlong instance_id,
|
786
|
+
jstring service,
|
787
|
+
jstring characteristic,
|
788
|
+
jbyteArray data) {
|
789
|
+
// TODO: implement nativePeripheralWriteCommand()
|
790
|
+
}
|
791
|
+
extern "C"
|
792
|
+
JNIEXPORT jbyteArray JNICALL
|
793
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralDescriptorRead(JNIEnv *env, jobject thiz,
|
794
|
+
jlong adapter_id,
|
795
|
+
jlong instance_id,
|
796
|
+
jstring service,
|
797
|
+
jstring characteristic,
|
798
|
+
jstring descriptor) {
|
799
|
+
// TODO: implement nativePeripheralDescriptorRead()
|
800
|
+
jbyteArray j_data = env->NewByteArray(0);
|
801
|
+
return j_data;
|
802
|
+
}
|
803
|
+
extern "C"
|
804
|
+
JNIEXPORT void JNICALL
|
805
|
+
Java_org_simpleble_android_Peripheral_nativePeripheralDescriptorWrite(JNIEnv *env, jobject thiz,
|
806
|
+
jlong adapter_id,
|
807
|
+
jlong instance_id,
|
808
|
+
jstring service,
|
809
|
+
jstring characteristic,
|
810
|
+
jstring descriptor,
|
811
|
+
jbyteArray data) {
|
812
|
+
// TODO: implement nativePeripheralDescriptorWrite()
|
813
|
+
}
|