simplejsble 0.0.4 → 0.0.6
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.
- package/VERSION +1 -0
- package/android/CMakeLists.txt +62 -20
- package/cmake/epilogue.cmake +81 -0
- package/cmake/find/FindDBus1.cmake +20 -0
- package/cmake/find/Findfmt.cmake +41 -0
- package/cmake/find/Findgoogletest.cmake +18 -0
- package/cmake/parse_version.cmake +45 -0
- package/cmake/prelude.cmake +8 -0
- package/dependencies/README +4 -0
- package/dependencies/external/kvn/kvn_bytearray.h +297 -0
- package/dependencies/external/kvn/kvn_safe_callback.hpp +66 -0
- package/dependencies/external/kvn/logfwd.hpp +35 -0
- package/dependencies/internal/include/fmt/LICENSE +27 -0
- package/dependencies/internal/include/fmt/args.h +220 -0
- package/dependencies/internal/include/fmt/base.h +2962 -0
- package/dependencies/internal/include/fmt/chrono.h +2338 -0
- package/dependencies/internal/include/fmt/color.h +610 -0
- package/dependencies/internal/include/fmt/compile.h +539 -0
- package/dependencies/internal/include/fmt/core.h +5 -0
- package/dependencies/internal/include/fmt/format-inl.h +1949 -0
- package/dependencies/internal/include/fmt/format.h +4244 -0
- package/dependencies/internal/include/fmt/os.h +427 -0
- package/dependencies/internal/include/fmt/ostream.h +166 -0
- package/dependencies/internal/include/fmt/printf.h +633 -0
- package/dependencies/internal/include/fmt/ranges.h +850 -0
- package/dependencies/internal/include/fmt/std.h +726 -0
- package/dependencies/internal/include/fmt/xchar.h +373 -0
- package/dependencies/internal/include/nanopb/pb.h +948 -0
- package/dependencies/internal/include/nanopb/pb_common.h +49 -0
- package/dependencies/internal/include/nanopb/pb_decode.h +204 -0
- package/dependencies/internal/include/nanopb/pb_encode.h +195 -0
- package/dependencies/internal/include/simplejni/Common.hpp +598 -0
- package/dependencies/internal/include/simplejni/References.hpp +151 -0
- package/dependencies/internal/include/simplejni/Registry.hpp +249 -0
- package/dependencies/internal/include/simplejni/VM.hpp +93 -0
- package/dependencies/internal/src/nanopb/pb_common.c +388 -0
- package/dependencies/internal/src/nanopb/pb_decode.c +1763 -0
- package/dependencies/internal/src/nanopb/pb_encode.c +1009 -0
- package/dependencies/internal/src/simplejni/Common.cpp +4 -0
- package/package.json +5 -1
- package/simpleble/CMakeLists.txt +519 -0
- package/simpleble/cmake/simpleble.pc.in +11 -0
- package/simpleble/include/simpleble/Adapter.h +102 -0
- package/simpleble/include/simpleble/AdapterSafe.h +58 -0
- package/simpleble/include/simpleble/Advanced.h +50 -0
- package/simpleble/include/simpleble/Characteristic.h +39 -0
- package/simpleble/include/simpleble/Config.h +64 -0
- package/simpleble/include/simpleble/Descriptor.h +30 -0
- package/simpleble/include/simpleble/Exceptions.h +72 -0
- package/simpleble/include/simpleble/Logging.h +73 -0
- package/simpleble/include/simpleble/Peripheral.h +82 -0
- package/simpleble/include/simpleble/PeripheralSafe.h +64 -0
- package/simpleble/include/simpleble/Service.h +34 -0
- package/simpleble/include/simpleble/SimpleBLE.h +8 -0
- package/simpleble/include/simpleble/Types.h +49 -0
- package/simpleble/include/simpleble/Utils.h +13 -0
- package/simpleble/include/simpleble_c/DEPRECATED +2 -0
- package/simpleble/include/simpleble_c/adapter.h +188 -0
- package/simpleble/include/simpleble_c/logging.h +37 -0
- package/simpleble/include/simpleble_c/peripheral.h +304 -0
- package/simpleble/include/simpleble_c/simpleble.h +21 -0
- package/simpleble/include/simpleble_c/types.h +73 -0
- package/simpleble/include/simpleble_c/utils.h +27 -0
- package/simpleble/src/CommonUtils.h +63 -0
- package/simpleble/src/Config.cpp +25 -0
- package/simpleble/src/Exceptions.cpp +31 -0
- package/simpleble/src/Logging.cpp +136 -0
- package/simpleble/src/LoggingInternal.h +85 -0
- package/simpleble/src/Utils.cpp +24 -0
- package/simpleble/src/backends/android/AdapterAndroid.cpp +101 -0
- package/simpleble/src/backends/android/AdapterAndroid.h +67 -0
- package/simpleble/src/backends/android/BackendAndroid.cpp +41 -0
- package/simpleble/src/backends/android/BackendAndroid.h +26 -0
- package/simpleble/src/backends/android/PeripheralAndroid.cpp +365 -0
- package/simpleble/src/backends/android/PeripheralAndroid.h +90 -0
- package/simpleble/src/backends/android/bridge/BluetoothGattCallback.cpp +432 -0
- package/simpleble/src/backends/android/bridge/BluetoothGattCallback.h +102 -0
- package/simpleble/src/backends/android/bridge/ScanCallback.cpp +142 -0
- package/simpleble/src/backends/android/bridge/ScanCallback.h +55 -0
- package/simpleble/src/backends/android/types/android/bluetooth/BluetoothAdapter.cpp +107 -0
- package/simpleble/src/backends/android/types/android/bluetooth/BluetoothAdapter.h +55 -0
- package/simpleble/src/backends/android/types/android/bluetooth/BluetoothDevice.cpp +68 -0
- package/simpleble/src/backends/android/types/android/bluetooth/BluetoothDevice.h +54 -0
- package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGatt.cpp +115 -0
- package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGatt.h +75 -0
- package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattCharacteristic.cpp +142 -0
- package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattCharacteristic.h +66 -0
- package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattDescriptor.cpp +67 -0
- package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattDescriptor.h +46 -0
- package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattService.cpp +106 -0
- package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattService.h +47 -0
- package/simpleble/src/backends/android/types/android/bluetooth/le/BluetoothScanner.cpp +47 -0
- package/simpleble/src/backends/android/types/android/bluetooth/le/BluetoothScanner.h +37 -0
- package/simpleble/src/backends/android/types/android/bluetooth/le/ScanRecord.cpp +69 -0
- package/simpleble/src/backends/android/types/android/bluetooth/le/ScanRecord.h +41 -0
- package/simpleble/src/backends/android/types/android/bluetooth/le/ScanResult.cpp +63 -0
- package/simpleble/src/backends/android/types/android/bluetooth/le/ScanResult.h +42 -0
- package/simpleble/src/backends/android/types/android/os/ParcelUUID.cpp +32 -0
- package/simpleble/src/backends/android/types/android/os/ParcelUUID.h +30 -0
- package/simpleble/src/backends/android/types/android/util/SparseArray.cpp +54 -0
- package/simpleble/src/backends/android/types/android/util/SparseArray.h +37 -0
- package/simpleble/src/backends/android/types/java/util/Iterator.cpp +36 -0
- package/simpleble/src/backends/android/types/java/util/Iterator.h +28 -0
- package/simpleble/src/backends/android/types/java/util/List.cpp +29 -0
- package/simpleble/src/backends/android/types/java/util/List.h +27 -0
- package/simpleble/src/backends/android/types/java/util/Set.cpp +33 -0
- package/simpleble/src/backends/android/types/java/util/Set.h +28 -0
- package/simpleble/src/backends/android/types/java/util/UUID.cpp +26 -0
- package/simpleble/src/backends/android/types/java/util/UUID.h +29 -0
- package/simpleble/src/backends/common/AdapterBase.cpp +53 -0
- package/simpleble/src/backends/common/AdapterBase.h +81 -0
- package/simpleble/src/backends/common/AdapterBaseTypes.h +22 -0
- package/simpleble/src/backends/common/BackendBase.h +20 -0
- package/simpleble/src/backends/common/BackendUtils.h +33 -0
- package/simpleble/src/backends/common/CharacteristicBase.cpp +28 -0
- package/simpleble/src/backends/common/CharacteristicBase.h +38 -0
- package/simpleble/src/backends/common/DescriptorBase.cpp +7 -0
- package/simpleble/src/backends/common/DescriptorBase.h +19 -0
- package/simpleble/src/backends/common/PeripheralBase.h +82 -0
- package/simpleble/src/backends/common/ServiceBase.cpp +18 -0
- package/simpleble/src/backends/common/ServiceBase.h +28 -0
- package/simpleble/src/backends/dongl/AdapterBaseTypes.h +22 -0
- package/simpleble/src/backends/dongl/AdapterDongl.cpp +369 -0
- package/simpleble/src/backends/dongl/AdapterDongl.h +60 -0
- package/simpleble/src/backends/dongl/BackendDongl.cpp +35 -0
- package/simpleble/src/backends/dongl/PeripheralDongl.cpp +562 -0
- package/simpleble/src/backends/dongl/PeripheralDongl.h +136 -0
- package/simpleble/src/backends/dongl/protocol/basic.pb.c +33 -0
- package/simpleble/src/backends/dongl/protocol/basic.pb.h +172 -0
- package/simpleble/src/backends/dongl/protocol/d2h.pb.c +18 -0
- package/simpleble/src/backends/dongl/protocol/d2h.pb.h +118 -0
- package/simpleble/src/backends/dongl/protocol/h2d.pb.c +12 -0
- package/simpleble/src/backends/dongl/protocol/h2d.pb.h +69 -0
- package/simpleble/src/backends/dongl/protocol/simpleble.pb.c +123 -0
- package/simpleble/src/backends/dongl/protocol/simpleble.pb.h +908 -0
- package/simpleble/src/backends/dongl/protocol/softdevice.pb.c +18 -0
- package/simpleble/src/backends/dongl/protocol/softdevice.pb.h +815 -0
- package/simpleble/src/backends/dongl/protocol/softdevice_gap.pb.c +339 -0
- package/simpleble/src/backends/dongl/protocol/softdevice_gap.pb.h +2086 -0
- package/simpleble/src/backends/dongl/protocol/softdevice_gattc.pb.c +114 -0
- package/simpleble/src/backends/dongl/protocol/softdevice_gattc.pb.h +772 -0
- package/simpleble/src/backends/dongl/protocol/softdevice_gatts.pb.c +117 -0
- package/simpleble/src/backends/dongl/protocol/softdevice_gatts.pb.h +766 -0
- package/simpleble/src/backends/dongl/protocol/softdevice_types.pb.c +207 -0
- package/simpleble/src/backends/dongl/protocol/softdevice_types.pb.h +1686 -0
- package/simpleble/src/backends/dongl/serial/Protocol.cpp +887 -0
- package/simpleble/src/backends/dongl/serial/Protocol.h +117 -0
- package/simpleble/src/backends/dongl/serial/ProtocolBase.cpp +95 -0
- package/simpleble/src/backends/dongl/serial/ProtocolBase.h +54 -0
- package/simpleble/src/backends/dongl/serial/Wire.cpp +133 -0
- package/simpleble/src/backends/dongl/serial/Wire.h +116 -0
- package/simpleble/src/backends/dongl/usb/UsbHelper.cpp +53 -0
- package/simpleble/src/backends/dongl/usb/UsbHelper.h +32 -0
- package/simpleble/src/backends/dongl/usb/UsbHelperApple.cpp +266 -0
- package/simpleble/src/backends/dongl/usb/UsbHelperApple.h +34 -0
- package/simpleble/src/backends/dongl/usb/UsbHelperImpl.h +29 -0
- package/simpleble/src/backends/dongl/usb/UsbHelperLinux.cpp +21 -0
- package/simpleble/src/backends/dongl/usb/UsbHelperLinux.h +22 -0
- package/simpleble/src/backends/dongl/usb/UsbHelperNull.cpp +21 -0
- package/simpleble/src/backends/dongl/usb/UsbHelperNull.h +22 -0
- package/simpleble/src/backends/dongl/usb/UsbHelperWindows.cpp +21 -0
- package/simpleble/src/backends/dongl/usb/UsbHelperWindows.h +22 -0
- package/simpleble/src/backends/linux/AdapterLinux.cpp +102 -0
- package/simpleble/src/backends/linux/AdapterLinux.h +55 -0
- package/simpleble/src/backends/linux/BackendBluez.cpp +90 -0
- package/simpleble/src/backends/linux/PeripheralLinux.cpp +394 -0
- package/simpleble/src/backends/linux/PeripheralLinux.h +90 -0
- package/simpleble/src/backends/linux_legacy/AdapterLinuxLegacy.cpp +102 -0
- package/simpleble/src/backends/linux_legacy/AdapterLinuxLegacy.h +55 -0
- package/simpleble/src/backends/linux_legacy/BackendBluezLegacy.cpp +87 -0
- package/simpleble/src/backends/linux_legacy/PeripheralLinuxLegacy.cpp +376 -0
- package/simpleble/src/backends/linux_legacy/PeripheralLinuxLegacy.h +90 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Adapter.h +46 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Agent.h +52 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Bluez.h +37 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/BluezOrg.h +22 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/BluezOrgBluez.h +26 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/BluezRoot.h +32 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Characteristic.h +47 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Descriptor.h +33 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Device.h +64 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Exceptions.h +43 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Service.h +27 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Types.h +9 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/Adapter1.h +49 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/Agent1.h +100 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/AgentManager1.h +24 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/Battery1.h +32 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/Device1.h +62 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/GattCharacteristic1.h +48 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/GattDescriptor1.h +41 -0
- package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/GattService1.h +28 -0
- package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/advanced/Interface.h +67 -0
- package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/advanced/InterfaceRegistry.h +62 -0
- package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/advanced/Proxy.h +117 -0
- package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/base/Connection.h +50 -0
- package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/base/Exceptions.h +56 -0
- package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/base/Holder.h +147 -0
- package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/base/Logging.h +57 -0
- package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/base/Message.h +89 -0
- package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/base/Path.h +24 -0
- package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/interfaces/ObjectManager.h +26 -0
- package/simpleble/src/backends/linux_legacy/src/Adapter.cpp +78 -0
- package/simpleble/src/backends/linux_legacy/src/Agent.cpp +72 -0
- package/simpleble/src/backends/linux_legacy/src/Bluez.cpp +45 -0
- package/simpleble/src/backends/linux_legacy/src/BluezOrg.cpp +20 -0
- package/simpleble/src/backends/linux_legacy/src/BluezOrgBluez.cpp +23 -0
- package/simpleble/src/backends/linux_legacy/src/BluezRoot.cpp +44 -0
- package/simpleble/src/backends/linux_legacy/src/Characteristic.cpp +64 -0
- package/simpleble/src/backends/linux_legacy/src/Descriptor.cpp +27 -0
- package/simpleble/src/backends/linux_legacy/src/Device.cpp +104 -0
- package/simpleble/src/backends/linux_legacy/src/Exceptions.cpp +29 -0
- package/simpleble/src/backends/linux_legacy/src/Service.cpp +33 -0
- package/simpleble/src/backends/linux_legacy/src/advanced/Interface.cpp +155 -0
- package/simpleble/src/backends/linux_legacy/src/advanced/Proxy.cpp +374 -0
- package/simpleble/src/backends/linux_legacy/src/base/Connection.cpp +219 -0
- package/simpleble/src/backends/linux_legacy/src/base/Exceptions.cpp +39 -0
- package/simpleble/src/backends/linux_legacy/src/base/Holder.cpp +739 -0
- package/simpleble/src/backends/linux_legacy/src/base/Message.cpp +622 -0
- package/simpleble/src/backends/linux_legacy/src/base/Path.cpp +129 -0
- package/simpleble/src/backends/linux_legacy/src/interfaces/Adapter1.cpp +123 -0
- package/simpleble/src/backends/linux_legacy/src/interfaces/Agent1.cpp +143 -0
- package/simpleble/src/backends/linux_legacy/src/interfaces/AgentManager1.cpp +34 -0
- package/simpleble/src/backends/linux_legacy/src/interfaces/Battery1.cpp +30 -0
- package/simpleble/src/backends/linux_legacy/src/interfaces/Device1.cpp +170 -0
- package/simpleble/src/backends/linux_legacy/src/interfaces/GattCharacteristic1.cpp +118 -0
- package/simpleble/src/backends/linux_legacy/src/interfaces/GattDescriptor1.cpp +78 -0
- package/simpleble/src/backends/linux_legacy/src/interfaces/GattService1.cpp +28 -0
- package/simpleble/src/backends/linux_legacy/src/interfaces/ObjectManager.cpp +58 -0
- package/simpleble/src/backends/macos/AdapterBaseMacOS.h +29 -0
- package/simpleble/src/backends/macos/AdapterBaseMacOS.mm +235 -0
- package/simpleble/src/backends/macos/AdapterMac.h +78 -0
- package/simpleble/src/backends/macos/AdapterMac.mm +156 -0
- package/simpleble/src/backends/macos/BackendCoreBluetooth.mm +45 -0
- package/simpleble/src/backends/macos/PeripheralBaseMacOS.h +49 -0
- package/simpleble/src/backends/macos/PeripheralBaseMacOS.mm +714 -0
- package/simpleble/src/backends/macos/PeripheralMac.h +81 -0
- package/simpleble/src/backends/macos/PeripheralMac.mm +229 -0
- package/simpleble/src/backends/macos/Utils.h +9 -0
- package/simpleble/src/backends/macos/Utils.mm +23 -0
- package/simpleble/src/backends/plain/AdapterPlain.cpp +65 -0
- package/simpleble/src/backends/plain/AdapterPlain.h +49 -0
- package/simpleble/src/backends/plain/BackendPlain.cpp +30 -0
- package/simpleble/src/backends/plain/PeripheralPlain.cpp +159 -0
- package/simpleble/src/backends/plain/PeripheralPlain.h +72 -0
- package/simpleble/src/backends/windows/AdapterWindows.cpp +338 -0
- package/simpleble/src/backends/windows/AdapterWindows.h +89 -0
- package/simpleble/src/backends/windows/BackendWinRT.cpp +67 -0
- package/simpleble/src/backends/windows/BackendWinRT.h +18 -0
- package/simpleble/src/backends/windows/MtaManager.cpp +49 -0
- package/simpleble/src/backends/windows/MtaManager.h +90 -0
- package/simpleble/src/backends/windows/PeripheralWindows.cpp +487 -0
- package/simpleble/src/backends/windows/PeripheralWindows.h +129 -0
- package/simpleble/src/backends/windows/Utils.cpp +146 -0
- package/simpleble/src/backends/windows/Utils.h +47 -0
- package/simpleble/src/builders/BuildVec.h +32 -0
- package/simpleble/src/builders/BuilderBase.h +87 -0
- package/simpleble/src/external/TaskRunner.hpp +99 -0
- package/simpleble/src/external/ThreadRunner.h +52 -0
- package/simpleble/src/external/kvn_safe_callback.hpp +66 -0
- package/simpleble/src/external/kvn_safe_map.hpp +94 -0
- package/simpleble/src/external/kvn_threadrunner.hpp +70 -0
- package/simpleble/src/external/logfwd.hpp +35 -0
- package/simpleble/src/frontends/base/Adapter.cpp +111 -0
- package/simpleble/src/frontends/base/Advanced.cpp +34 -0
- package/simpleble/src/frontends/base/Backend.cpp +95 -0
- package/simpleble/src/frontends/base/Backend.h +76 -0
- package/simpleble/src/frontends/base/Characteristic.cpp +56 -0
- package/simpleble/src/frontends/base/Descriptor.cpp +21 -0
- package/simpleble/src/frontends/base/Peripheral.cpp +113 -0
- package/simpleble/src/frontends/base/Service.cpp +26 -0
- package/simpleble/src/frontends/safe/AdapterSafe.cpp +158 -0
- package/simpleble/src/frontends/safe/PeripheralSafe.cpp +219 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#include "simplebluezlegacy/interfaces/GattCharacteristic1.h"
|
|
2
|
+
|
|
3
|
+
using namespace SimpleBluezLegacy;
|
|
4
|
+
|
|
5
|
+
const SimpleDBusLegacy::AutoRegisterInterface<GattCharacteristic1> GattCharacteristic1::registry{
|
|
6
|
+
"org.bluez.GattCharacteristic1",
|
|
7
|
+
// clang-format off
|
|
8
|
+
[](std::shared_ptr<SimpleDBusLegacy::Connection> conn, const std::string& bus_name, const std::string& path, const SimpleDBusLegacy::Holder& options) -> std::shared_ptr<SimpleDBusLegacy::Interface> {
|
|
9
|
+
return std::static_pointer_cast<SimpleDBusLegacy::Interface>(std::make_shared<GattCharacteristic1>(conn, path));
|
|
10
|
+
}
|
|
11
|
+
// clang-format on
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
GattCharacteristic1::GattCharacteristic1(std::shared_ptr<SimpleDBusLegacy::Connection> conn, std::string path)
|
|
15
|
+
: SimpleDBusLegacy::Interface(conn, "org.bluez", path, "org.bluez.GattCharacteristic1") {}
|
|
16
|
+
|
|
17
|
+
GattCharacteristic1::~GattCharacteristic1() { OnValueChanged.unload(); }
|
|
18
|
+
|
|
19
|
+
void GattCharacteristic1::StartNotify() {
|
|
20
|
+
auto msg = create_method_call("StartNotify");
|
|
21
|
+
_conn->send_with_reply_and_block(msg);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
void GattCharacteristic1::StopNotify() {
|
|
25
|
+
auto msg = create_method_call("StopNotify");
|
|
26
|
+
_conn->send_with_reply_and_block(msg);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
void GattCharacteristic1::WriteValue(const ByteArray& value, WriteType type) {
|
|
30
|
+
SimpleDBusLegacy::Holder value_data = SimpleDBusLegacy::Holder::create_array();
|
|
31
|
+
for (size_t i = 0; i < value.size(); i++) {
|
|
32
|
+
value_data.array_append(SimpleDBusLegacy::Holder::create_byte(value[i]));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
SimpleDBusLegacy::Holder options = SimpleDBusLegacy::Holder::create_dict();
|
|
36
|
+
if (type == WriteType::REQUEST) {
|
|
37
|
+
options.dict_append(SimpleDBusLegacy::Holder::Type::STRING, "type", SimpleDBusLegacy::Holder::create_string("request"));
|
|
38
|
+
} else if (type == WriteType::COMMAND) {
|
|
39
|
+
options.dict_append(SimpleDBusLegacy::Holder::Type::STRING, "type", SimpleDBusLegacy::Holder::create_string("command"));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
auto msg = create_method_call("WriteValue");
|
|
43
|
+
msg.append_argument(value_data, "ay");
|
|
44
|
+
msg.append_argument(options, "a{sv}");
|
|
45
|
+
_conn->send_with_reply_and_block(msg);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
ByteArray GattCharacteristic1::ReadValue() {
|
|
49
|
+
auto msg = create_method_call("ReadValue");
|
|
50
|
+
|
|
51
|
+
// NOTE: ReadValue requires an additional argument, which currently is not supported
|
|
52
|
+
SimpleDBusLegacy::Holder options = SimpleDBusLegacy::Holder::create_dict();
|
|
53
|
+
msg.append_argument(options, "a{sv}");
|
|
54
|
+
|
|
55
|
+
SimpleDBusLegacy::Message reply_msg = _conn->send_with_reply_and_block(msg);
|
|
56
|
+
SimpleDBusLegacy::Holder value = reply_msg.extract();
|
|
57
|
+
update_value(value);
|
|
58
|
+
|
|
59
|
+
return Value();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
std::string GattCharacteristic1::UUID() {
|
|
63
|
+
// As the UUID property doesn't change, we can cache it
|
|
64
|
+
std::scoped_lock lock(_property_update_mutex);
|
|
65
|
+
return _uuid;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
ByteArray GattCharacteristic1::Value() {
|
|
69
|
+
std::scoped_lock lock(_property_update_mutex);
|
|
70
|
+
return _value;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
std::vector<std::string> GattCharacteristic1::Flags() {
|
|
74
|
+
std::scoped_lock lock(_property_update_mutex);
|
|
75
|
+
|
|
76
|
+
std::vector<std::string> flags;
|
|
77
|
+
for (SimpleDBusLegacy::Holder& flag : _properties["Flags"].get_array()) {
|
|
78
|
+
flags.push_back(flag.get_string());
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return flags;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
uint16_t GattCharacteristic1::MTU() {
|
|
85
|
+
std::scoped_lock lock(_property_update_mutex);
|
|
86
|
+
return _properties["MTU"].get_uint16();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
bool GattCharacteristic1::Notifying(bool refresh) {
|
|
90
|
+
if (refresh) {
|
|
91
|
+
property_refresh("Notifying");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
std::scoped_lock lock(_property_update_mutex);
|
|
95
|
+
return _properties["Notifying"].get_boolean();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
void GattCharacteristic1::property_changed(std::string option_name) {
|
|
99
|
+
if (option_name == "UUID") {
|
|
100
|
+
std::scoped_lock lock(_property_update_mutex);
|
|
101
|
+
_uuid = _properties["UUID"].get_string();
|
|
102
|
+
} else if (option_name == "Value") {
|
|
103
|
+
update_value(_properties["Value"]);
|
|
104
|
+
OnValueChanged();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
void GattCharacteristic1::update_value(SimpleDBusLegacy::Holder& new_value) {
|
|
109
|
+
std::scoped_lock lock(_property_update_mutex);
|
|
110
|
+
auto value_array = new_value.get_array();
|
|
111
|
+
|
|
112
|
+
char* value_data = new char[value_array.size()];
|
|
113
|
+
for (std::size_t i = 0; i < value_array.size(); i++) {
|
|
114
|
+
value_data[i] = value_array[i].get_byte();
|
|
115
|
+
}
|
|
116
|
+
_value = ByteArray(value_data, value_array.size());
|
|
117
|
+
delete[] value_data;
|
|
118
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#include "simplebluezlegacy/interfaces/GattDescriptor1.h"
|
|
2
|
+
|
|
3
|
+
using namespace SimpleBluezLegacy;
|
|
4
|
+
|
|
5
|
+
const SimpleDBusLegacy::AutoRegisterInterface<GattDescriptor1> GattDescriptor1::registry{
|
|
6
|
+
"org.bluez.GattDescriptor1",
|
|
7
|
+
// clang-format off
|
|
8
|
+
[](std::shared_ptr<SimpleDBusLegacy::Connection> conn, const std::string& bus_name, const std::string& path, const SimpleDBusLegacy::Holder& options) -> std::shared_ptr<SimpleDBusLegacy::Interface> {
|
|
9
|
+
return std::static_pointer_cast<SimpleDBusLegacy::Interface>(std::make_shared<GattDescriptor1>(conn, path));
|
|
10
|
+
}
|
|
11
|
+
// clang-format on
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
GattDescriptor1::GattDescriptor1(std::shared_ptr<SimpleDBusLegacy::Connection> conn, std::string path)
|
|
15
|
+
: SimpleDBusLegacy::Interface(conn, "org.bluez", path, "org.bluez.GattDescriptor1") {}
|
|
16
|
+
|
|
17
|
+
GattDescriptor1::~GattDescriptor1() { OnValueChanged.unload(); }
|
|
18
|
+
|
|
19
|
+
void GattDescriptor1::WriteValue(const ByteArray& value) {
|
|
20
|
+
SimpleDBusLegacy::Holder value_data = SimpleDBusLegacy::Holder::create_array();
|
|
21
|
+
for (size_t i = 0; i < value.size(); i++) {
|
|
22
|
+
value_data.array_append(SimpleDBusLegacy::Holder::create_byte(value[i]));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
SimpleDBusLegacy::Holder options = SimpleDBusLegacy::Holder::create_dict();
|
|
26
|
+
|
|
27
|
+
auto msg = create_method_call("WriteValue");
|
|
28
|
+
msg.append_argument(value_data, "ay");
|
|
29
|
+
msg.append_argument(options, "a{sv}");
|
|
30
|
+
_conn->send_with_reply_and_block(msg);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
ByteArray GattDescriptor1::ReadValue() {
|
|
34
|
+
auto msg = create_method_call("ReadValue");
|
|
35
|
+
|
|
36
|
+
// NOTE: ReadValue requires an additional argument, which currently is not supported
|
|
37
|
+
SimpleDBusLegacy::Holder options = SimpleDBusLegacy::Holder::create_dict();
|
|
38
|
+
msg.append_argument(options, "a{sv}");
|
|
39
|
+
|
|
40
|
+
SimpleDBusLegacy::Message reply_msg = _conn->send_with_reply_and_block(msg);
|
|
41
|
+
SimpleDBusLegacy::Holder value = reply_msg.extract();
|
|
42
|
+
update_value(value);
|
|
43
|
+
|
|
44
|
+
return Value();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
std::string GattDescriptor1::UUID() {
|
|
48
|
+
// As the UUID property doesn't change, we can cache it
|
|
49
|
+
std::scoped_lock lock(_property_update_mutex);
|
|
50
|
+
return _uuid;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
ByteArray GattDescriptor1::Value() {
|
|
54
|
+
std::scoped_lock lock(_property_update_mutex);
|
|
55
|
+
return _value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
void GattDescriptor1::property_changed(std::string option_name) {
|
|
59
|
+
if (option_name == "UUID") {
|
|
60
|
+
std::scoped_lock lock(_property_update_mutex);
|
|
61
|
+
_uuid = _properties["UUID"].get_string();
|
|
62
|
+
} else if (option_name == "Value") {
|
|
63
|
+
update_value(_properties["Value"]);
|
|
64
|
+
OnValueChanged();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void GattDescriptor1::update_value(SimpleDBusLegacy::Holder& new_value) {
|
|
69
|
+
std::scoped_lock lock(_property_update_mutex);
|
|
70
|
+
auto value_array = new_value.get_array();
|
|
71
|
+
|
|
72
|
+
char* value_data = new char[value_array.size()];
|
|
73
|
+
for (std::size_t i = 0; i < value_array.size(); i++) {
|
|
74
|
+
value_data[i] = value_array[i].get_byte();
|
|
75
|
+
}
|
|
76
|
+
_value = ByteArray(value_data, value_array.size());
|
|
77
|
+
delete[] value_data;
|
|
78
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#include "simplebluezlegacy/interfaces/GattService1.h"
|
|
2
|
+
|
|
3
|
+
using namespace SimpleBluezLegacy;
|
|
4
|
+
|
|
5
|
+
const SimpleDBusLegacy::AutoRegisterInterface<GattService1> GattService1::registry{
|
|
6
|
+
"org.bluez.GattService1",
|
|
7
|
+
// clang-format off
|
|
8
|
+
[](std::shared_ptr<SimpleDBusLegacy::Connection> conn, const std::string& bus_name, const std::string& path, const SimpleDBusLegacy::Holder& options) -> std::shared_ptr<SimpleDBusLegacy::Interface> {
|
|
9
|
+
return std::static_pointer_cast<SimpleDBusLegacy::Interface>(std::make_shared<GattService1>(conn, path));
|
|
10
|
+
}
|
|
11
|
+
// clang-format on
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
GattService1::GattService1(std::shared_ptr<SimpleDBusLegacy::Connection> conn, std::string path)
|
|
15
|
+
: SimpleDBusLegacy::Interface(conn, "org.bluez", path, "org.bluez.GattService1") {}
|
|
16
|
+
|
|
17
|
+
std::string GattService1::UUID() {
|
|
18
|
+
// As the UUID property doesn't change, we can cache it
|
|
19
|
+
std::scoped_lock lock(_property_update_mutex);
|
|
20
|
+
return _uuid;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void GattService1::property_changed(std::string option_name) {
|
|
24
|
+
if (option_name == "UUID") {
|
|
25
|
+
std::scoped_lock lock(_property_update_mutex);
|
|
26
|
+
_uuid = _properties["UUID"].get_string();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#include <simpledbuslegacy/interfaces/ObjectManager.h>
|
|
2
|
+
|
|
3
|
+
using namespace SimpleDBusLegacy;
|
|
4
|
+
|
|
5
|
+
const AutoRegisterInterface<ObjectManager> ObjectManager::registry{
|
|
6
|
+
"org.freedesktop.DBus.ObjectManager",
|
|
7
|
+
// clang-format off
|
|
8
|
+
[](std::shared_ptr<Connection> conn, const std::string& bus_name, const std::string& path, const Holder& options) -> std::shared_ptr<SimpleDBusLegacy::Interface> {
|
|
9
|
+
return std::static_pointer_cast<SimpleDBusLegacy::Interface>(std::make_shared<ObjectManager>(conn, bus_name, path));
|
|
10
|
+
}
|
|
11
|
+
// clang-format on
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
ObjectManager::ObjectManager(std::shared_ptr<Connection> conn, std::string bus_name, std::string path)
|
|
15
|
+
: Interface(conn, bus_name, path, "org.freedesktop.DBus.ObjectManager") {}
|
|
16
|
+
|
|
17
|
+
Holder ObjectManager::GetManagedObjects(bool use_callbacks) {
|
|
18
|
+
Message query_msg = Message::create_method_call(_bus_name, _path, _interface_name, "GetManagedObjects");
|
|
19
|
+
Message reply_msg = _conn->send_with_reply_and_block(query_msg);
|
|
20
|
+
Holder managed_objects = reply_msg.extract();
|
|
21
|
+
// TODO: Remove immediate callback support.
|
|
22
|
+
if (use_callbacks) {
|
|
23
|
+
auto managed_object = managed_objects.get_dict_object_path();
|
|
24
|
+
for (auto& [path, options] : managed_object) {
|
|
25
|
+
if (InterfacesAdded) {
|
|
26
|
+
InterfacesAdded(path, options);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return managed_objects;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
void ObjectManager::message_handle(Message& msg) {
|
|
34
|
+
if (msg.is_signal(_interface_name, "InterfacesAdded")) {
|
|
35
|
+
std::string path = msg.extract().get_string();
|
|
36
|
+
msg.extract_next();
|
|
37
|
+
Holder options = msg.extract();
|
|
38
|
+
if (InterfacesAdded) {
|
|
39
|
+
InterfacesAdded(path, options);
|
|
40
|
+
}
|
|
41
|
+
} else if (msg.is_signal(_interface_name, "InterfacesRemoved")) {
|
|
42
|
+
std::string path = msg.extract().get_string();
|
|
43
|
+
msg.extract_next();
|
|
44
|
+
Holder options = msg.extract();
|
|
45
|
+
if (InterfacesRemoved) {
|
|
46
|
+
InterfacesRemoved(path, options);
|
|
47
|
+
}
|
|
48
|
+
// TODO: Make a call directly to the proxy to do this?
|
|
49
|
+
|
|
50
|
+
} else if (msg.is_method_call(_interface_name, "GetManagedObjects")) {
|
|
51
|
+
// TODO: Implement this.
|
|
52
|
+
// SimpleDBus::Holder result = _proxy->path_collect();
|
|
53
|
+
|
|
54
|
+
// SimpleDBus::Message reply = SimpleDBus::Message::create_method_return(msg);
|
|
55
|
+
// reply.append_argument(result, "a{oa{sa{sv}}}");
|
|
56
|
+
// _conn->send(reply);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#import <CoreBluetooth/CoreBluetooth.h>
|
|
4
|
+
#import <Foundation/Foundation.h>
|
|
5
|
+
|
|
6
|
+
#include <functional>
|
|
7
|
+
#import "AdapterMac.h"
|
|
8
|
+
|
|
9
|
+
@interface AdapterBaseMacOS : NSObject<CBCentralManagerDelegate>
|
|
10
|
+
|
|
11
|
+
@property NSString* uuid;
|
|
12
|
+
|
|
13
|
+
- (bool)isBluetoothEnabled;
|
|
14
|
+
|
|
15
|
+
- (instancetype)init:(SimpleBLE::AdapterMac*)adapter;
|
|
16
|
+
|
|
17
|
+
- (void*)underlying;
|
|
18
|
+
|
|
19
|
+
- (void)powerOn;
|
|
20
|
+
- (void)powerOff;
|
|
21
|
+
- (bool)isPowered;
|
|
22
|
+
|
|
23
|
+
- (void)scanStart;
|
|
24
|
+
- (void)scanStop;
|
|
25
|
+
- (bool)scanIsActive;
|
|
26
|
+
|
|
27
|
+
- (NSString*)address;
|
|
28
|
+
|
|
29
|
+
@end
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
#import "AdapterBaseMacOS.h"
|
|
2
|
+
#import "TargetConditionals.h"
|
|
3
|
+
|
|
4
|
+
#import <fmt/core.h>
|
|
5
|
+
#import <simpleble/Exceptions.h>
|
|
6
|
+
#import "LoggingInternal.h"
|
|
7
|
+
#import "Utils.h"
|
|
8
|
+
|
|
9
|
+
#define WAIT_UNTIL_FALSE(obj, var) \
|
|
10
|
+
do { \
|
|
11
|
+
BOOL _tmpVar = YES; \
|
|
12
|
+
while (_tmpVar) { \
|
|
13
|
+
[NSThread sleepForTimeInterval:0.01]; \
|
|
14
|
+
@synchronized(obj) { \
|
|
15
|
+
_tmpVar = (var); \
|
|
16
|
+
} \
|
|
17
|
+
} \
|
|
18
|
+
} while (0)
|
|
19
|
+
|
|
20
|
+
#define WAIT_UNTIL_FALSE_WITH_TIMEOUT(obj, var, timeout) \
|
|
21
|
+
do { \
|
|
22
|
+
BOOL _tmpVar = YES; \
|
|
23
|
+
NSDate* endDate = [NSDate dateWithTimeInterval:timeout sinceDate:NSDate.now]; \
|
|
24
|
+
while (_tmpVar && [NSDate.now compare:endDate] == NSOrderedAscending) { \
|
|
25
|
+
[NSThread sleepForTimeInterval:0.01]; \
|
|
26
|
+
@synchronized(obj) { \
|
|
27
|
+
_tmpVar = (var); \
|
|
28
|
+
} \
|
|
29
|
+
} \
|
|
30
|
+
} while (0)
|
|
31
|
+
|
|
32
|
+
#if TARGET_OS_OSX
|
|
33
|
+
extern "C" {
|
|
34
|
+
// Credit to the Chromium project for finding and documenting this undocumented API.
|
|
35
|
+
//
|
|
36
|
+
// Undocumented IOBluetooth Preference API [1]. Used by `blueutil` [2] and
|
|
37
|
+
// `Karabiner` [3] to programmatically control the Bluetooth state. Calling the
|
|
38
|
+
// method with `1` powers the adapter on, calling it with `0` powers it off.
|
|
39
|
+
// Using this API has the same effect as turning Bluetooth on or off using the
|
|
40
|
+
// macOS System Preferences [4], and will effect all adapters.
|
|
41
|
+
//
|
|
42
|
+
// [1] https://goo.gl/Gbjm1x
|
|
43
|
+
// [2] http://www.frederikseiffert.de/blueutil/
|
|
44
|
+
// [3] https://pqrs.org/osx/karabiner/
|
|
45
|
+
// [4] https://support.apple.com/kb/PH25091
|
|
46
|
+
void IOBluetoothPreferenceSetControllerPowerState(int state);
|
|
47
|
+
}
|
|
48
|
+
#endif
|
|
49
|
+
@interface AdapterBaseMacOS () {
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Private properties
|
|
53
|
+
@property() SimpleBLE::AdapterMac* adapter;
|
|
54
|
+
@property(strong) dispatch_queue_t centralManagerQueue;
|
|
55
|
+
@property(strong) CBCentralManager* centralManager;
|
|
56
|
+
|
|
57
|
+
@end
|
|
58
|
+
|
|
59
|
+
@implementation AdapterBaseMacOS
|
|
60
|
+
|
|
61
|
+
- (bool)isBluetoothEnabled {
|
|
62
|
+
return CBCentralManager.authorization == CBManagerAuthorizationAllowedAlways && _centralManager.state == CBManagerStatePoweredOn;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
- (instancetype)init:(SimpleBLE::AdapterMac*)adapter {
|
|
66
|
+
self = [super init];
|
|
67
|
+
if (self) {
|
|
68
|
+
_adapter = adapter;
|
|
69
|
+
_uuid = @"39a76676-2788-46c9-afa0-f0c0c31e6fd9";
|
|
70
|
+
|
|
71
|
+
// Use a high-priority queue to ensure that events are processed immediately.
|
|
72
|
+
dispatch_queue_attr_t qos = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INITIATED, -1);
|
|
73
|
+
_centralManagerQueue = dispatch_queue_create("AdapterBaseMacOS.centralManagerQueue", qos);
|
|
74
|
+
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:_centralManagerQueue options:nil];
|
|
75
|
+
|
|
76
|
+
// Wait for the central manager state to be updated for up to 5 seconds.
|
|
77
|
+
NSDate* endDate = [NSDate dateWithTimeInterval:5.0 sinceDate:NSDate.now];
|
|
78
|
+
while (_centralManager.state == CBManagerStateUnknown && [NSDate.now compare:endDate] == NSOrderedAscending) {
|
|
79
|
+
[NSThread sleepForTimeInterval:0.01];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return self;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
- (void*)underlying {
|
|
86
|
+
return (__bridge void*)self.centralManager;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
- (void)powerOn {
|
|
90
|
+
#if TARGET_OS_OSX
|
|
91
|
+
IOBluetoothPreferenceSetControllerPowerState(1);
|
|
92
|
+
|
|
93
|
+
// Wait for the central manager state to be updated for up to 5 seconds.
|
|
94
|
+
NSDate* endDate = [NSDate dateWithTimeInterval:5.0 sinceDate:NSDate.now];
|
|
95
|
+
while (_centralManager.state != CBManagerStatePoweredOn && [NSDate.now compare:endDate] == NSOrderedAscending) {
|
|
96
|
+
[NSThread sleepForTimeInterval:0.01];
|
|
97
|
+
}
|
|
98
|
+
#endif
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
- (void)powerOff {
|
|
102
|
+
#if TARGET_OS_OSX
|
|
103
|
+
IOBluetoothPreferenceSetControllerPowerState(0);
|
|
104
|
+
|
|
105
|
+
// Wait for the central manager state to be updated for up to 5 seconds.
|
|
106
|
+
NSDate* endDate = [NSDate dateWithTimeInterval:5.0 sinceDate:NSDate.now];
|
|
107
|
+
while (_centralManager.state != CBManagerStatePoweredOff && [NSDate.now compare:endDate] == NSOrderedAscending) {
|
|
108
|
+
[NSThread sleepForTimeInterval:0.01];
|
|
109
|
+
}
|
|
110
|
+
#endif
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
- (bool)isPowered {
|
|
114
|
+
return self.centralManager.state == CBManagerStatePoweredOn;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
- (void)scanStart {
|
|
118
|
+
[self.centralManager scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey : @YES}];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
- (void)scanStop {
|
|
122
|
+
[self.centralManager stopScan];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
- (bool)scanIsActive {
|
|
126
|
+
return [self.centralManager isScanning];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
- (NSString*)address {
|
|
130
|
+
return self.uuid;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
#pragma mark - CBCentralManagerDelegate
|
|
134
|
+
|
|
135
|
+
- (void)centralManagerDidUpdateState:(CBCentralManager*)central {
|
|
136
|
+
switch (central.state) {
|
|
137
|
+
case CBManagerStateUnknown:
|
|
138
|
+
// NSLog(@"CBManagerStateUnknown!\n");
|
|
139
|
+
break;
|
|
140
|
+
case CBManagerStateResetting:
|
|
141
|
+
// NSLog(@"CBManagerStateResetting!\n");
|
|
142
|
+
break;
|
|
143
|
+
case CBManagerStateUnsupported:
|
|
144
|
+
// NSLog(@"CBManagerStateUnsupported!\n");
|
|
145
|
+
break;
|
|
146
|
+
case CBManagerStateUnauthorized:
|
|
147
|
+
// NSLog(@"CBManagerStateUnauthorized!\n");
|
|
148
|
+
break;
|
|
149
|
+
case CBManagerStatePoweredOff:
|
|
150
|
+
// NSLog(@"CBManagerStatePoweredOff!\n");
|
|
151
|
+
// NOTE: Notify the user that the Bluetooth adapter is turned off.
|
|
152
|
+
break;
|
|
153
|
+
case CBManagerStatePoweredOn:
|
|
154
|
+
// NSLog(@"CBManagerStatePoweredOn!\n");
|
|
155
|
+
// NOTE: This state is required to be able to operate CoreBluetooth.
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
- (void)centralManager:(CBCentralManager*)central
|
|
161
|
+
didDiscoverPeripheral:(CBPeripheral*)peripheral
|
|
162
|
+
advertisementData:(NSDictionary<NSString*, id>*)advertisementData
|
|
163
|
+
RSSI:(NSNumber*)RSSI {
|
|
164
|
+
SimpleBLE::advertising_data_t advertisingData;
|
|
165
|
+
|
|
166
|
+
// Parse advertisementData to extract all relevant information
|
|
167
|
+
|
|
168
|
+
// TODO: Do we need to extract the name as well?
|
|
169
|
+
// NSString* advertisingName = advertisementData[CBAdvertisementDataLocalNameKey];
|
|
170
|
+
|
|
171
|
+
// Check if the peripheral is connectable
|
|
172
|
+
NSNumber* isConnectable = advertisementData[CBAdvertisementDataIsConnectable];
|
|
173
|
+
advertisingData.connectable = isConnectable != nil && isConnectable.boolValue == YES;
|
|
174
|
+
|
|
175
|
+
// Extract RSSI
|
|
176
|
+
advertisingData.rssi = [RSSI shortValue];
|
|
177
|
+
|
|
178
|
+
// Extract Tx Power
|
|
179
|
+
NSNumber* txPower = [advertisementData objectForKey:CBAdvertisementDataTxPowerLevelKey];
|
|
180
|
+
if (txPower == nil) {
|
|
181
|
+
advertisingData.tx_power = INT16_MIN;
|
|
182
|
+
} else {
|
|
183
|
+
advertisingData.tx_power = [txPower shortValue];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Extract Manufacturer Data
|
|
187
|
+
NSData* rawManufacturerData = advertisementData[CBAdvertisementDataManufacturerDataKey];
|
|
188
|
+
if (rawManufacturerData != nil) {
|
|
189
|
+
const char* manufacturerDataBytes = (const char*)rawManufacturerData.bytes;
|
|
190
|
+
|
|
191
|
+
uint16_t manufacturerID = *((uint16_t*)manufacturerDataBytes);
|
|
192
|
+
SimpleBLE::ByteArray manufacturerData = SimpleBLE::ByteArray(&manufacturerDataBytes[2], (size_t)(rawManufacturerData.length - 2));
|
|
193
|
+
advertisingData.manufacturer_data[manufacturerID] = manufacturerData;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Extract Service Data
|
|
197
|
+
NSDictionary* rawServiceDataDict = advertisementData[CBAdvertisementDataServiceDataKey];
|
|
198
|
+
for (CBUUID* serviceUuid in rawServiceDataDict) {
|
|
199
|
+
NSData* rawServiceData = rawServiceDataDict[serviceUuid];
|
|
200
|
+
const char* rawServiceDataBytes = (const char*)rawServiceData.bytes;
|
|
201
|
+
size_t rawServiceDataLength = (size_t)rawServiceData.length;
|
|
202
|
+
SimpleBLE::ByteArray serviceData = SimpleBLE::ByteArray(rawServiceDataBytes, rawServiceDataLength);
|
|
203
|
+
advertisingData.service_data[uuidToSimpleBLE(serviceUuid)] = serviceData;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Extract Service UUIDs
|
|
207
|
+
NSArray* services = advertisementData[CBAdvertisementDataServiceUUIDsKey];
|
|
208
|
+
if (services != nil) {
|
|
209
|
+
for (CBUUID* serviceUuid in services) {
|
|
210
|
+
advertisingData.service_data[uuidToSimpleBLE(serviceUuid)] = SimpleBLE::ByteArray();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
_adapter->delegate_did_discover_peripheral((__bridge void*)peripheral, (__bridge void*)self.centralManager, advertisingData);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
- (void)centralManager:(CBCentralManager*)central didConnectPeripheral:(CBPeripheral*)peripheral {
|
|
218
|
+
_adapter->delegate_did_connect_peripheral((__bridge void*)peripheral);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
- (void)centralManager:(CBCentralManager*)central didDisconnectPeripheral:(CBPeripheral*)peripheral error:(NSError*)error {
|
|
222
|
+
// NSLog(@"didDisconnectPeripheral (A): %@, error: %@", peripheral, error);
|
|
223
|
+
_adapter->delegate_did_disconnect_peripheral((__bridge void*)peripheral, (__bridge void*)error);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
- (void)centralManager:(CBCentralManager*)central didFailToConnectPeripheral:(CBPeripheral*)peripheral error:(NSError*)error {
|
|
227
|
+
_adapter->delegate_did_fail_to_connect_peripheral((__bridge void*)peripheral, (__bridge void*)error);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
- (void)centralManager:(CBCentralManager*)central didDisconnectPeripheral:(CBPeripheral*)peripheral timestamp:(CFAbsoluteTime)timestamp isReconnecting:(BOOL)isReconnecting error:(NSError*)error {
|
|
231
|
+
// NSLog(@"didDisconnectPeripheral (B): %@, error: %@", peripheral, error);
|
|
232
|
+
_adapter->delegate_did_disconnect_peripheral((__bridge void*)peripheral, (__bridge void*)error);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
@end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <simpleble/Exceptions.h>
|
|
4
|
+
#include <simpleble/Types.h>
|
|
5
|
+
|
|
6
|
+
#include "AdapterBase.h"
|
|
7
|
+
#include "AdapterBaseTypes.h"
|
|
8
|
+
|
|
9
|
+
#include <kvn_safe_callback.hpp>
|
|
10
|
+
|
|
11
|
+
#include <functional>
|
|
12
|
+
#include <map>
|
|
13
|
+
#include <memory>
|
|
14
|
+
#include <string>
|
|
15
|
+
#include <vector>
|
|
16
|
+
|
|
17
|
+
namespace SimpleBLE {
|
|
18
|
+
|
|
19
|
+
class Peripheral;
|
|
20
|
+
class PeripheralBase;
|
|
21
|
+
class PeripheralMac;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
This class definition acts as an abstraction layer between C++ and Objective-C.
|
|
25
|
+
If Objective-C headers are included here, everything blows up.
|
|
26
|
+
*/
|
|
27
|
+
class AdapterMac : public AdapterBase {
|
|
28
|
+
public:
|
|
29
|
+
AdapterMac();
|
|
30
|
+
virtual ~AdapterMac();
|
|
31
|
+
|
|
32
|
+
virtual void* underlying() const override;
|
|
33
|
+
|
|
34
|
+
virtual std::string identifier() override;
|
|
35
|
+
virtual BluetoothAddress address() override;
|
|
36
|
+
|
|
37
|
+
virtual void power_on() override;
|
|
38
|
+
virtual void power_off() override;
|
|
39
|
+
virtual bool is_powered() override;
|
|
40
|
+
|
|
41
|
+
virtual void scan_start() override;
|
|
42
|
+
virtual void scan_stop() override;
|
|
43
|
+
virtual void scan_for(int timeout_ms) override;
|
|
44
|
+
virtual bool scan_is_active() override;
|
|
45
|
+
virtual std::vector<std::shared_ptr<PeripheralBase>> scan_get_results() override;
|
|
46
|
+
|
|
47
|
+
virtual std::vector<std::shared_ptr<PeripheralBase>> get_paired_peripherals() override;
|
|
48
|
+
|
|
49
|
+
virtual bool bluetooth_enabled() override;
|
|
50
|
+
|
|
51
|
+
void delegate_did_discover_peripheral(void* opaque_peripheral, void* opaque_adapter,
|
|
52
|
+
advertising_data_t advertising_data);
|
|
53
|
+
void delegate_did_connect_peripheral(void* opaque_peripheral);
|
|
54
|
+
void delegate_did_fail_to_connect_peripheral(void* opaque_peripheral, void* opaque_error);
|
|
55
|
+
void delegate_did_disconnect_peripheral(void* opaque_peripheral, void* opaque_error);
|
|
56
|
+
|
|
57
|
+
protected:
|
|
58
|
+
/**
|
|
59
|
+
* Holds a pointer to the Objective-C representation of this object.
|
|
60
|
+
*/
|
|
61
|
+
void* opaque_internal_;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Holds a map of objective-c peripheral objects to their corresponding C++ objects.
|
|
65
|
+
*
|
|
66
|
+
* Whenever some sort of event happens on a peripheral, we need to find
|
|
67
|
+
* the corresponding PeripheralBase object. The PeripheralBase objects
|
|
68
|
+
* can be wrapped in disposable Peripheral objects, so there is no need
|
|
69
|
+
* be careful with them.
|
|
70
|
+
*/
|
|
71
|
+
std::map<void*, std::shared_ptr<PeripheralMac>> peripherals_;
|
|
72
|
+
std::map<void*, std::shared_ptr<PeripheralMac>> seen_peripherals_;
|
|
73
|
+
|
|
74
|
+
private:
|
|
75
|
+
BluetoothAddress address() const;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
} // namespace SimpleBLE
|