simplejsble 0.0.4 → 0.0.5
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/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,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2022 Kevin Dewald <kevin@dewald.me>
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#ifndef KVN_SAFE_CALLBACK_HPP
|
|
8
|
+
#define KVN_SAFE_CALLBACK_HPP
|
|
9
|
+
|
|
10
|
+
#include <atomic>
|
|
11
|
+
#include <functional>
|
|
12
|
+
#include <memory>
|
|
13
|
+
#include <mutex>
|
|
14
|
+
|
|
15
|
+
namespace kvn {
|
|
16
|
+
|
|
17
|
+
template <typename _Signature>
|
|
18
|
+
class safe_callback;
|
|
19
|
+
|
|
20
|
+
template <class _Res, class... _ArgTypes>
|
|
21
|
+
class safe_callback<_Res(_ArgTypes...)> {
|
|
22
|
+
public:
|
|
23
|
+
safe_callback() = default;
|
|
24
|
+
|
|
25
|
+
// Remove copy constructor and copy assignment
|
|
26
|
+
safe_callback(const safe_callback&) = delete;
|
|
27
|
+
safe_callback& operator=(const safe_callback&) = delete;
|
|
28
|
+
|
|
29
|
+
virtual ~safe_callback() { unload(); };
|
|
30
|
+
|
|
31
|
+
void load(std::function<_Res(_ArgTypes...)> callback) {
|
|
32
|
+
if (callback == nullptr) return;
|
|
33
|
+
|
|
34
|
+
std::scoped_lock lock(_mutex);
|
|
35
|
+
_callback = std::move(callback);
|
|
36
|
+
_is_loaded = true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
void unload() {
|
|
40
|
+
std::scoped_lock lock(_mutex);
|
|
41
|
+
_callback = nullptr;
|
|
42
|
+
_is_loaded = false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
bool is_loaded() const { return _is_loaded; }
|
|
46
|
+
|
|
47
|
+
explicit operator bool() const { return is_loaded(); }
|
|
48
|
+
|
|
49
|
+
_Res operator()(_ArgTypes... arguments) {
|
|
50
|
+
std::scoped_lock lock(_mutex);
|
|
51
|
+
if (_is_loaded) {
|
|
52
|
+
return _callback(std::forward<_ArgTypes&&>(arguments)...);
|
|
53
|
+
} else {
|
|
54
|
+
return _Res();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
protected:
|
|
59
|
+
std::atomic_bool _is_loaded{false};
|
|
60
|
+
std::function<_Res(_ArgTypes...)> _callback;
|
|
61
|
+
std::recursive_mutex _mutex;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
} // namespace kvn
|
|
65
|
+
|
|
66
|
+
#endif // KVN_SAFE_CALLBACK_HPP
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#ifndef LOGFWD_HPP
|
|
2
|
+
#define LOGFWD_HPP
|
|
3
|
+
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
namespace logfwd {
|
|
7
|
+
|
|
8
|
+
enum level : int {
|
|
9
|
+
NONE = 0,
|
|
10
|
+
FATAL,
|
|
11
|
+
ERROR,
|
|
12
|
+
WARN,
|
|
13
|
+
INFO,
|
|
14
|
+
#pragma push_macro("DEBUG")
|
|
15
|
+
#undef DEBUG
|
|
16
|
+
DEBUG,
|
|
17
|
+
#pragma pop_macro("DEBUG")
|
|
18
|
+
VERBOSE,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// clang-format off
|
|
22
|
+
|
|
23
|
+
void receive(
|
|
24
|
+
level level,
|
|
25
|
+
const std::string& module,
|
|
26
|
+
const std::string& file,
|
|
27
|
+
uint32_t line,
|
|
28
|
+
const std::string& function,
|
|
29
|
+
const std::string& message);
|
|
30
|
+
|
|
31
|
+
// clang-format on
|
|
32
|
+
|
|
33
|
+
} // namespace logfwd
|
|
34
|
+
|
|
35
|
+
#endif // LOGFWD_HPP
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Copyright (c) 2012 - present, Victor Zverovich and {fmt} contributors
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
--- Optional exception to the license ---
|
|
23
|
+
|
|
24
|
+
As an exception, if, as a result of your compiling your source code, portions
|
|
25
|
+
of this Software are embedded into a machine-executable object form of such
|
|
26
|
+
source code, you may redistribute such embedded portions in such object form
|
|
27
|
+
without including the above copyright and permission notices.
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// Formatting library for C++ - dynamic argument lists
|
|
2
|
+
//
|
|
3
|
+
// Copyright (c) 2012 - present, Victor Zverovich
|
|
4
|
+
// All rights reserved.
|
|
5
|
+
//
|
|
6
|
+
// For the license information refer to format.h.
|
|
7
|
+
|
|
8
|
+
#ifndef FMT_ARGS_H_
|
|
9
|
+
#define FMT_ARGS_H_
|
|
10
|
+
|
|
11
|
+
#ifndef FMT_MODULE
|
|
12
|
+
# include <functional> // std::reference_wrapper
|
|
13
|
+
# include <memory> // std::unique_ptr
|
|
14
|
+
# include <vector>
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
#include "format.h" // std_string_view
|
|
18
|
+
|
|
19
|
+
FMT_BEGIN_NAMESPACE
|
|
20
|
+
namespace detail {
|
|
21
|
+
|
|
22
|
+
template <typename T> struct is_reference_wrapper : std::false_type {};
|
|
23
|
+
template <typename T>
|
|
24
|
+
struct is_reference_wrapper<std::reference_wrapper<T>> : std::true_type {};
|
|
25
|
+
|
|
26
|
+
template <typename T> auto unwrap(const T& v) -> const T& { return v; }
|
|
27
|
+
template <typename T>
|
|
28
|
+
auto unwrap(const std::reference_wrapper<T>& v) -> const T& {
|
|
29
|
+
return static_cast<const T&>(v);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// node is defined outside dynamic_arg_list to workaround a C2504 bug in MSVC
|
|
33
|
+
// 2022 (v17.10.0).
|
|
34
|
+
//
|
|
35
|
+
// Workaround for clang's -Wweak-vtables. Unlike for regular classes, for
|
|
36
|
+
// templates it doesn't complain about inability to deduce single translation
|
|
37
|
+
// unit for placing vtable. So node is made a fake template.
|
|
38
|
+
template <typename = void> struct node {
|
|
39
|
+
virtual ~node() = default;
|
|
40
|
+
std::unique_ptr<node<>> next;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
class dynamic_arg_list {
|
|
44
|
+
template <typename T> struct typed_node : node<> {
|
|
45
|
+
T value;
|
|
46
|
+
|
|
47
|
+
template <typename Arg>
|
|
48
|
+
FMT_CONSTEXPR typed_node(const Arg& arg) : value(arg) {}
|
|
49
|
+
|
|
50
|
+
template <typename Char>
|
|
51
|
+
FMT_CONSTEXPR typed_node(const basic_string_view<Char>& arg)
|
|
52
|
+
: value(arg.data(), arg.size()) {}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
std::unique_ptr<node<>> head_;
|
|
56
|
+
|
|
57
|
+
public:
|
|
58
|
+
template <typename T, typename Arg> auto push(const Arg& arg) -> const T& {
|
|
59
|
+
auto new_node = std::unique_ptr<typed_node<T>>(new typed_node<T>(arg));
|
|
60
|
+
auto& value = new_node->value;
|
|
61
|
+
new_node->next = std::move(head_);
|
|
62
|
+
head_ = std::move(new_node);
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
} // namespace detail
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A dynamic list of formatting arguments with storage.
|
|
70
|
+
*
|
|
71
|
+
* It can be implicitly converted into `fmt::basic_format_args` for passing
|
|
72
|
+
* into type-erased formatting functions such as `fmt::vformat`.
|
|
73
|
+
*/
|
|
74
|
+
template <typename Context> class dynamic_format_arg_store {
|
|
75
|
+
private:
|
|
76
|
+
using char_type = typename Context::char_type;
|
|
77
|
+
|
|
78
|
+
template <typename T> struct need_copy {
|
|
79
|
+
static constexpr detail::type mapped_type =
|
|
80
|
+
detail::mapped_type_constant<T, char_type>::value;
|
|
81
|
+
|
|
82
|
+
enum {
|
|
83
|
+
value = !(detail::is_reference_wrapper<T>::value ||
|
|
84
|
+
std::is_same<T, basic_string_view<char_type>>::value ||
|
|
85
|
+
std::is_same<T, detail::std_string_view<char_type>>::value ||
|
|
86
|
+
(mapped_type != detail::type::cstring_type &&
|
|
87
|
+
mapped_type != detail::type::string_type &&
|
|
88
|
+
mapped_type != detail::type::custom_type))
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
template <typename T>
|
|
93
|
+
using stored_t = conditional_t<
|
|
94
|
+
std::is_convertible<T, std::basic_string<char_type>>::value &&
|
|
95
|
+
!detail::is_reference_wrapper<T>::value,
|
|
96
|
+
std::basic_string<char_type>, T>;
|
|
97
|
+
|
|
98
|
+
// Storage of basic_format_arg must be contiguous.
|
|
99
|
+
std::vector<basic_format_arg<Context>> data_;
|
|
100
|
+
std::vector<detail::named_arg_info<char_type>> named_info_;
|
|
101
|
+
|
|
102
|
+
// Storage of arguments not fitting into basic_format_arg must grow
|
|
103
|
+
// without relocation because items in data_ refer to it.
|
|
104
|
+
detail::dynamic_arg_list dynamic_args_;
|
|
105
|
+
|
|
106
|
+
friend class basic_format_args<Context>;
|
|
107
|
+
|
|
108
|
+
auto data() const -> const basic_format_arg<Context>* {
|
|
109
|
+
return named_info_.empty() ? data_.data() : data_.data() + 1;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
template <typename T> void emplace_arg(const T& arg) {
|
|
113
|
+
data_.emplace_back(arg);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
template <typename T>
|
|
117
|
+
void emplace_arg(const detail::named_arg<char_type, T>& arg) {
|
|
118
|
+
if (named_info_.empty())
|
|
119
|
+
data_.insert(data_.begin(), basic_format_arg<Context>(nullptr, 0));
|
|
120
|
+
data_.emplace_back(detail::unwrap(arg.value));
|
|
121
|
+
auto pop_one = [](std::vector<basic_format_arg<Context>>* data) {
|
|
122
|
+
data->pop_back();
|
|
123
|
+
};
|
|
124
|
+
std::unique_ptr<std::vector<basic_format_arg<Context>>, decltype(pop_one)>
|
|
125
|
+
guard{&data_, pop_one};
|
|
126
|
+
named_info_.push_back({arg.name, static_cast<int>(data_.size() - 2u)});
|
|
127
|
+
data_[0] = {named_info_.data(), named_info_.size()};
|
|
128
|
+
guard.release();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public:
|
|
132
|
+
constexpr dynamic_format_arg_store() = default;
|
|
133
|
+
|
|
134
|
+
operator basic_format_args<Context>() const {
|
|
135
|
+
return basic_format_args<Context>(data(), static_cast<int>(data_.size()),
|
|
136
|
+
!named_info_.empty());
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Adds an argument into the dynamic store for later passing to a formatting
|
|
141
|
+
* function.
|
|
142
|
+
*
|
|
143
|
+
* Note that custom types and string types (but not string views) are copied
|
|
144
|
+
* into the store dynamically allocating memory if necessary.
|
|
145
|
+
*
|
|
146
|
+
* **Example**:
|
|
147
|
+
*
|
|
148
|
+
* fmt::dynamic_format_arg_store<fmt::format_context> store;
|
|
149
|
+
* store.push_back(42);
|
|
150
|
+
* store.push_back("abc");
|
|
151
|
+
* store.push_back(1.5f);
|
|
152
|
+
* std::string result = fmt::vformat("{} and {} and {}", store);
|
|
153
|
+
*/
|
|
154
|
+
template <typename T> void push_back(const T& arg) {
|
|
155
|
+
if (detail::const_check(need_copy<T>::value))
|
|
156
|
+
emplace_arg(dynamic_args_.push<stored_t<T>>(arg));
|
|
157
|
+
else
|
|
158
|
+
emplace_arg(detail::unwrap(arg));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Adds a reference to the argument into the dynamic store for later passing
|
|
163
|
+
* to a formatting function.
|
|
164
|
+
*
|
|
165
|
+
* **Example**:
|
|
166
|
+
*
|
|
167
|
+
* fmt::dynamic_format_arg_store<fmt::format_context> store;
|
|
168
|
+
* char band[] = "Rolling Stones";
|
|
169
|
+
* store.push_back(std::cref(band));
|
|
170
|
+
* band[9] = 'c'; // Changing str affects the output.
|
|
171
|
+
* std::string result = fmt::vformat("{}", store);
|
|
172
|
+
* // result == "Rolling Scones"
|
|
173
|
+
*/
|
|
174
|
+
template <typename T> void push_back(std::reference_wrapper<T> arg) {
|
|
175
|
+
static_assert(
|
|
176
|
+
need_copy<T>::value,
|
|
177
|
+
"objects of built-in types and string views are always copied");
|
|
178
|
+
emplace_arg(arg.get());
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Adds named argument into the dynamic store for later passing to a
|
|
183
|
+
* formatting function. `std::reference_wrapper` is supported to avoid
|
|
184
|
+
* copying of the argument. The name is always copied into the store.
|
|
185
|
+
*/
|
|
186
|
+
template <typename T>
|
|
187
|
+
void push_back(const detail::named_arg<char_type, T>& arg) {
|
|
188
|
+
const char_type* arg_name =
|
|
189
|
+
dynamic_args_.push<std::basic_string<char_type>>(arg.name).c_str();
|
|
190
|
+
if (detail::const_check(need_copy<T>::value)) {
|
|
191
|
+
emplace_arg(
|
|
192
|
+
fmt::arg(arg_name, dynamic_args_.push<stored_t<T>>(arg.value)));
|
|
193
|
+
} else {
|
|
194
|
+
emplace_arg(fmt::arg(arg_name, arg.value));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/// Erase all elements from the store.
|
|
199
|
+
void clear() {
|
|
200
|
+
data_.clear();
|
|
201
|
+
named_info_.clear();
|
|
202
|
+
dynamic_args_ = {};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/// Reserves space to store at least `new_cap` arguments including
|
|
206
|
+
/// `new_cap_named` named arguments.
|
|
207
|
+
void reserve(size_t new_cap, size_t new_cap_named) {
|
|
208
|
+
FMT_ASSERT(new_cap >= new_cap_named,
|
|
209
|
+
"set of arguments includes set of named arguments");
|
|
210
|
+
data_.reserve(new_cap);
|
|
211
|
+
named_info_.reserve(new_cap_named);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/// Returns the number of elements in the store.
|
|
215
|
+
size_t size() const noexcept { return data_.size(); }
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
FMT_END_NAMESPACE
|
|
219
|
+
|
|
220
|
+
#endif // FMT_ARGS_H_
|