simplejsble 0.0.18 → 0.0.20

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.
Files changed (82) hide show
  1. package/NitroSimplejsble.podspec +22 -8
  2. package/dependencies/internal/include/simplejni/VM.hpp +0 -1
  3. package/lib/specs/Adapter.nitro.js +1 -1
  4. package/macos/CMakeLists.txt +21 -0
  5. package/macos/SimpleBLE-macos.xcframework/Info.plist +30 -0
  6. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/Adapter.h +102 -0
  7. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/AdapterSafe.h +58 -0
  8. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/Advanced.h +50 -0
  9. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/Characteristic.h +39 -0
  10. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/Config.h +64 -0
  11. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/Descriptor.h +30 -0
  12. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/Exceptions.h +72 -0
  13. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/Logging.h +73 -0
  14. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/Peripheral.h +82 -0
  15. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/PeripheralSafe.h +64 -0
  16. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/Service.h +34 -0
  17. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/SimpleBLE.h +8 -0
  18. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/Types.h +49 -0
  19. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/Utils.h +13 -0
  20. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/export.h +43 -0
  21. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/Headers/simpleble/kvn/kvn_bytearray.h +297 -0
  22. package/macos/SimpleBLE-macos.xcframework/macos-arm64_x86_64/libsimpleble.a +0 -0
  23. package/macos/build_simpleble.sh +61 -0
  24. package/macos/simpleble_macosx_arm64/include/simpleble/Adapter.h +102 -0
  25. package/macos/simpleble_macosx_arm64/include/simpleble/AdapterSafe.h +58 -0
  26. package/macos/simpleble_macosx_arm64/include/simpleble/Advanced.h +50 -0
  27. package/macos/simpleble_macosx_arm64/include/simpleble/Characteristic.h +39 -0
  28. package/macos/simpleble_macosx_arm64/include/simpleble/Config.h +64 -0
  29. package/macos/simpleble_macosx_arm64/include/simpleble/Descriptor.h +30 -0
  30. package/macos/simpleble_macosx_arm64/include/simpleble/Exceptions.h +72 -0
  31. package/macos/simpleble_macosx_arm64/include/simpleble/Logging.h +73 -0
  32. package/macos/simpleble_macosx_arm64/include/simpleble/Peripheral.h +82 -0
  33. package/macos/simpleble_macosx_arm64/include/simpleble/PeripheralSafe.h +64 -0
  34. package/macos/simpleble_macosx_arm64/include/simpleble/Service.h +34 -0
  35. package/macos/simpleble_macosx_arm64/include/simpleble/SimpleBLE.h +8 -0
  36. package/macos/simpleble_macosx_arm64/include/simpleble/Types.h +49 -0
  37. package/macos/simpleble_macosx_arm64/include/simpleble/Utils.h +13 -0
  38. package/macos/simpleble_macosx_arm64/include/simpleble/export.h +43 -0
  39. package/macos/simpleble_macosx_arm64/include/simpleble/kvn/kvn_bytearray.h +297 -0
  40. package/macos/simpleble_macosx_arm64/lib/cmake/simpleble/simpleble-config-release.cmake +19 -0
  41. package/macos/simpleble_macosx_arm64/lib/cmake/simpleble/simpleble-config.cmake +107 -0
  42. package/macos/simpleble_macosx_arm64/lib/libsimpleble.a +0 -0
  43. package/macos/simpleble_macosx_arm64/lib/pkgconfig/simpleble.pc +11 -0
  44. package/macos/simpleble_macosx_universal/include/simpleble/Adapter.h +102 -0
  45. package/macos/simpleble_macosx_universal/include/simpleble/AdapterSafe.h +58 -0
  46. package/macos/simpleble_macosx_universal/include/simpleble/Advanced.h +50 -0
  47. package/macos/simpleble_macosx_universal/include/simpleble/Characteristic.h +39 -0
  48. package/macos/simpleble_macosx_universal/include/simpleble/Config.h +64 -0
  49. package/macos/simpleble_macosx_universal/include/simpleble/Descriptor.h +30 -0
  50. package/macos/simpleble_macosx_universal/include/simpleble/Exceptions.h +72 -0
  51. package/macos/simpleble_macosx_universal/include/simpleble/Logging.h +73 -0
  52. package/macos/simpleble_macosx_universal/include/simpleble/Peripheral.h +82 -0
  53. package/macos/simpleble_macosx_universal/include/simpleble/PeripheralSafe.h +64 -0
  54. package/macos/simpleble_macosx_universal/include/simpleble/Service.h +34 -0
  55. package/macos/simpleble_macosx_universal/include/simpleble/SimpleBLE.h +8 -0
  56. package/macos/simpleble_macosx_universal/include/simpleble/Types.h +49 -0
  57. package/macos/simpleble_macosx_universal/include/simpleble/Utils.h +13 -0
  58. package/macos/simpleble_macosx_universal/include/simpleble/export.h +43 -0
  59. package/macos/simpleble_macosx_universal/include/simpleble/kvn/kvn_bytearray.h +297 -0
  60. package/macos/simpleble_macosx_universal/lib/libsimpleble.a +0 -0
  61. package/macos/simpleble_macosx_x86_64/include/simpleble/Adapter.h +102 -0
  62. package/macos/simpleble_macosx_x86_64/include/simpleble/AdapterSafe.h +58 -0
  63. package/macos/simpleble_macosx_x86_64/include/simpleble/Advanced.h +50 -0
  64. package/macos/simpleble_macosx_x86_64/include/simpleble/Characteristic.h +39 -0
  65. package/macos/simpleble_macosx_x86_64/include/simpleble/Config.h +64 -0
  66. package/macos/simpleble_macosx_x86_64/include/simpleble/Descriptor.h +30 -0
  67. package/macos/simpleble_macosx_x86_64/include/simpleble/Exceptions.h +72 -0
  68. package/macos/simpleble_macosx_x86_64/include/simpleble/Logging.h +73 -0
  69. package/macos/simpleble_macosx_x86_64/include/simpleble/Peripheral.h +82 -0
  70. package/macos/simpleble_macosx_x86_64/include/simpleble/PeripheralSafe.h +64 -0
  71. package/macos/simpleble_macosx_x86_64/include/simpleble/Service.h +34 -0
  72. package/macos/simpleble_macosx_x86_64/include/simpleble/SimpleBLE.h +8 -0
  73. package/macos/simpleble_macosx_x86_64/include/simpleble/Types.h +49 -0
  74. package/macos/simpleble_macosx_x86_64/include/simpleble/Utils.h +13 -0
  75. package/macos/simpleble_macosx_x86_64/include/simpleble/export.h +43 -0
  76. package/macos/simpleble_macosx_x86_64/include/simpleble/kvn/kvn_bytearray.h +297 -0
  77. package/macos/simpleble_macosx_x86_64/lib/cmake/simpleble/simpleble-config-release.cmake +19 -0
  78. package/macos/simpleble_macosx_x86_64/lib/cmake/simpleble/simpleble-config.cmake +107 -0
  79. package/macos/simpleble_macosx_x86_64/lib/libsimpleble.a +0 -0
  80. package/macos/simpleble_macosx_x86_64/lib/pkgconfig/simpleble.pc +11 -0
  81. package/package.json +5 -3
  82. package/react-native.config.js +4 -0
@@ -10,33 +10,39 @@ Pod::Spec.new do |s|
10
10
  s.license = package["license"]
11
11
  s.authors = package["author"]
12
12
 
13
- s.platforms = { :ios => min_ios_version_supported, :visionos => 1.0 }
13
+ s.platforms = { :ios => min_ios_version_supported, :visionos => 1.0, :osx => '13.0' }
14
14
 
15
15
  s.source = { :path => "." }
16
16
 
17
17
  # Build SimpleBLE from source only if XCFramework doesn't exist
18
18
  # When installed from npm, the pre-built XCFramework is already included
19
19
  s.prepare_command = <<-CMD
20
+ # Build iOS XCFramework if not present
20
21
  if [ -d "ios/SimpleBLE.xcframework" ]; then
21
- echo "SimpleBLE.xcframework already exists, skipping build"
22
+ echo "SimpleBLE.xcframework (iOS) already exists, skipping build"
22
23
  else
23
24
  echo "Building SimpleBLE for iOS..."
24
25
  chmod +x ios/build_simpleble.sh
25
26
  ios/build_simpleble.sh
26
27
  fi
28
+
29
+ # Build macOS XCFramework if not present
30
+ if [ -d "macos/SimpleBLE-macos.xcframework" ]; then
31
+ echo "SimpleBLE-macos.xcframework already exists, skipping build"
32
+ else
33
+ echo "Building SimpleBLE for macOS..."
34
+ chmod +x macos/build_simpleble.sh
35
+ macos/build_simpleble.sh
36
+ fi
27
37
  CMD
28
38
 
29
39
  s.source_files = [
30
- # Implementation (Swift)
31
- "ios/**/*.{swift}",
32
- # Autolinking/Registration (Objective-C++)
33
- "ios/**/*.{m,mm}",
34
40
  # Implementation (C++ objects)
35
41
  "cpp/**/*.{hpp,cpp}",
36
42
  ]
37
43
 
38
44
  # Exclude CMakeLists.txt from source files
39
- s.exclude_files = ["ios/CMakeLists.txt"]
45
+ s.exclude_files = ["ios/CMakeLists.txt", "macos/CMakeLists.txt"]
40
46
 
41
47
  load 'nitrogen/generated/ios/NitroSimplejsble+autolinking.rb'
42
48
  add_nitrogen_files(s)
@@ -45,19 +51,27 @@ Pod::Spec.new do |s|
45
51
  s.dependency 'React-callinvoker'
46
52
  install_modules_dependencies(s)
47
53
 
48
- # Required frameworks for SimpleBLE iOS backend
54
+ # Required frameworks for SimpleBLE (shared by iOS and macOS)
49
55
  s.frameworks = ['Foundation', 'CoreBluetooth']
50
56
 
57
+ # macOS-specific frameworks (IOBluetooth/IOKit for USB dongle support)
58
+ s.osx.frameworks = ['Foundation', 'CoreBluetooth', 'IOBluetooth', 'IOKit']
59
+
51
60
  # Vendored XCFramework containing all architectures
52
61
  s.ios.vendored_frameworks = 'ios/SimpleBLE.xcframework'
62
+ s.osx.vendored_frameworks = 'macos/SimpleBLE-macos.xcframework'
53
63
 
54
64
  # Configure header search paths for SimpleBLE
55
65
  current_pod_target_xcconfig = s.attributes_hash['pod_target_xcconfig'] || {}
56
66
  s.pod_target_xcconfig = current_pod_target_xcconfig.merge({
57
67
  'HEADER_SEARCH_PATHS' => [
58
68
  '"$(inherited)"',
69
+ # iOS header paths
59
70
  '"$(PODS_TARGET_SRCROOT)/ios/simpleble_iphoneos_arm64/include"',
60
71
  '"$(PODS_TARGET_SRCROOT)/ios/simpleble_iphonesimulator_arm64/include"',
72
+ # macOS header paths
73
+ '"$(PODS_TARGET_SRCROOT)/macos/simpleble_macosx_arm64/include"',
74
+ '"$(PODS_TARGET_SRCROOT)/macos/simpleble_macosx_x86_64/include"',
61
75
  ].join(' '),
62
76
  })
63
77
  end
@@ -21,7 +21,6 @@ class VM {
21
21
  }
22
22
  instance._jvm = jvm_override;
23
23
  } else if (instance._jvm == nullptr) {
24
- throw std::runtime_error("JavaVM not set. Call set_jvm() in JNI_OnLoad first.");
25
24
  jsize count;
26
25
  if (JNI_GetCreatedJavaVMs(&instance._jvm, 1, &count) != JNI_OK || count == 0) {
27
26
  throw std::runtime_error("Failed to retrieve the Java Virtual Machine");
@@ -1 +1 @@
1
- import {} from 'react-native-nitro-modules';
1
+ export {};
@@ -0,0 +1,21 @@
1
+ cmake_minimum_required(VERSION 3.21)
2
+
3
+ # Path: packages/simplejsble/macos → ../../../.. → repo root (where simpleble/ lives)
4
+ set(PROJECT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
5
+ set(BUILD_SHARED_LIBS OFF) # Static library for macOS
6
+
7
+ include(${PROJECT_ROOT_DIR}/cmake/prelude.cmake)
8
+
9
+ project(simpleble-macos VERSION ${SIMPLEBLE_VERSION_BASE} LANGUAGES CXX C OBJCXX)
10
+
11
+ include(${PROJECT_ROOT_DIR}/cmake/epilogue.cmake)
12
+
13
+ add_subdirectory(${PROJECT_ROOT_DIR}/simpleble ${CMAKE_BINARY_DIR}/simpleble)
14
+
15
+ # Install library
16
+ install(TARGETS simpleble ARCHIVE DESTINATION lib)
17
+
18
+ # Install headers (including generated export.h)
19
+ install(DIRECTORY ${PROJECT_ROOT_DIR}/simpleble/include/simpleble/ DESTINATION include/simpleble)
20
+ install(DIRECTORY ${CMAKE_BINARY_DIR}/simpleble/export/simpleble/ DESTINATION include/simpleble)
21
+ install(FILES ${PROJECT_ROOT_DIR}/dependencies/external/kvn/kvn_bytearray.h DESTINATION include/simpleble/kvn)
@@ -0,0 +1,30 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>AvailableLibraries</key>
6
+ <array>
7
+ <dict>
8
+ <key>BinaryPath</key>
9
+ <string>libsimpleble.a</string>
10
+ <key>HeadersPath</key>
11
+ <string>Headers</string>
12
+ <key>LibraryIdentifier</key>
13
+ <string>macos-arm64_x86_64</string>
14
+ <key>LibraryPath</key>
15
+ <string>libsimpleble.a</string>
16
+ <key>SupportedArchitectures</key>
17
+ <array>
18
+ <string>arm64</string>
19
+ <string>x86_64</string>
20
+ </array>
21
+ <key>SupportedPlatform</key>
22
+ <string>macos</string>
23
+ </dict>
24
+ </array>
25
+ <key>CFBundlePackageType</key>
26
+ <string>XFWK</string>
27
+ <key>XCFrameworkFormatVersion</key>
28
+ <string>1.0</string>
29
+ </dict>
30
+ </plist>
@@ -0,0 +1,102 @@
1
+ #pragma once
2
+
3
+ #include <functional>
4
+ #include <memory>
5
+ #include <string>
6
+ #include <vector>
7
+
8
+ #include <simpleble/export.h>
9
+
10
+ #include <simpleble/Exceptions.h>
11
+ #include <simpleble/Peripheral.h>
12
+ #include <simpleble/Types.h>
13
+
14
+ namespace SimpleBLE {
15
+
16
+ class AdapterBase;
17
+
18
+ /**
19
+ * Bluetooth Adapter.
20
+ *
21
+ * A default-constructed Adapter object is not initialized. Calling any method
22
+ * other than `initialized()` on an uninitialized Adapter will throw an exception
23
+ * of type `SimpleBLE::NotInitialized`.
24
+ *
25
+ * NOTE: This class is intended to be used by the user only. Library developers
26
+ * should use shared pointers to `AdapterBase` instead.
27
+ */
28
+ class SIMPLEBLE_EXPORT Adapter {
29
+ public:
30
+ Adapter() = default;
31
+ virtual ~Adapter() = default;
32
+
33
+ bool initialized() const;
34
+
35
+ /**
36
+ * Retrieve the underlying OS object/handle.
37
+ *
38
+ * For certain compatibility with external libraries, we sometimes need to
39
+ * expose the actual OS handle to the user. This is particularly important
40
+ * for MacOS right now.
41
+ */
42
+ void* underlying() const;
43
+
44
+ std::string identifier();
45
+ BluetoothAddress address();
46
+
47
+ /**
48
+ * Control the power state of the adapter.
49
+ *
50
+ * NOTE: The power on/off functionality is only supported on Windows and Linux (implementation pending).
51
+ * On other platforms, this method will do nothing.
52
+ * NOTE: Callbacks are currently a placeholder for future implementation.
53
+ */
54
+ void power_on();
55
+ void power_off();
56
+ bool is_powered();
57
+ void set_callback_on_power_on(std::function<void()> on_power_on);
58
+ void set_callback_on_power_off(std::function<void()> on_power_off);
59
+
60
+ void scan_start();
61
+ void scan_stop();
62
+ void scan_for(int timeout_ms);
63
+ bool scan_is_active();
64
+ std::vector<Peripheral> scan_get_results();
65
+
66
+ void set_callback_on_scan_start(std::function<void()> on_scan_start);
67
+ void set_callback_on_scan_stop(std::function<void()> on_scan_stop);
68
+ void set_callback_on_scan_updated(std::function<void(Peripheral)> on_scan_updated);
69
+ void set_callback_on_scan_found(std::function<void(Peripheral)> on_scan_found);
70
+
71
+ /**
72
+ * Retrieve a list of all paired peripherals.
73
+ *
74
+ * NOTE:This method is currently only supported by the Linux, Windows and Android backends.
75
+ */
76
+ std::vector<Peripheral> get_paired_peripherals();
77
+
78
+ /**
79
+ * Retrieve a list of all connected peripherals.
80
+ *
81
+ * NOTE: This method is currently only supported by the Windows backend. (More backends coming soon.)
82
+ */
83
+ std::vector<Peripheral> get_connected_peripherals();
84
+
85
+ static bool bluetooth_enabled();
86
+
87
+ /**
88
+ * Fetches a list of all available adapters from all available backends.
89
+ *
90
+ * This will cause backends to be instantiated/initialized and adapters
91
+ * too.
92
+ */
93
+ static std::vector<Adapter> get_adapters();
94
+
95
+ protected:
96
+ AdapterBase* operator->();
97
+ const AdapterBase* operator->() const;
98
+
99
+ std::shared_ptr<AdapterBase> internal_;
100
+ };
101
+
102
+ } // namespace SimpleBLE
@@ -0,0 +1,58 @@
1
+ #pragma once
2
+
3
+ #include <simpleble/export.h>
4
+
5
+ #include <simpleble/Adapter.h>
6
+ #include <simpleble/PeripheralSafe.h>
7
+ #include <memory>
8
+ #include <optional>
9
+ #include <vector>
10
+
11
+ namespace SimpleBLE {
12
+
13
+ namespace Safe {
14
+
15
+ /**
16
+ * Wrapper around the Adapter class that provides a noexcept interface.
17
+ *
18
+ * We use instances of this class directly and not through shared_ptr because
19
+ * this is just a wrapper around the Adapter class, which is already managed by
20
+ * shared_ptr.
21
+ */
22
+ class SIMPLEBLE_EXPORT Adapter {
23
+ public:
24
+ Adapter(SimpleBLE::Adapter& adapter);
25
+ Adapter(SimpleBLE::Adapter&& adapter);
26
+ virtual ~Adapter() = default;
27
+
28
+ std::optional<std::string> identifier() noexcept;
29
+ std::optional<BluetoothAddress> address() noexcept;
30
+
31
+ bool scan_start() noexcept;
32
+ bool scan_stop() noexcept;
33
+ bool scan_for(int timeout_ms) noexcept;
34
+ std::optional<bool> scan_is_active() noexcept;
35
+ std::optional<std::vector<SimpleBLE::Safe::Peripheral>> scan_get_results() noexcept;
36
+
37
+ bool set_callback_on_scan_start(std::function<void()> on_scan_start) noexcept;
38
+ bool set_callback_on_scan_stop(std::function<void()> on_scan_stop) noexcept;
39
+ bool set_callback_on_scan_updated(std::function<void(SimpleBLE::Safe::Peripheral)> on_scan_updated) noexcept;
40
+ bool set_callback_on_scan_found(std::function<void(SimpleBLE::Safe::Peripheral)> on_scan_found) noexcept;
41
+
42
+ std::optional<std::vector<SimpleBLE::Safe::Peripheral>> get_paired_peripherals() noexcept;
43
+
44
+ static std::optional<bool> bluetooth_enabled() noexcept;
45
+ static std::optional<std::vector<SimpleBLE::Safe::Adapter>> get_adapters() noexcept;
46
+
47
+ /**
48
+ * Cast to the underlying adapter object.
49
+ */
50
+ operator SimpleBLE::Adapter() const noexcept;
51
+
52
+ protected:
53
+ SimpleBLE::Adapter internal_;
54
+ };
55
+
56
+ } // namespace Safe
57
+
58
+ } // namespace SimpleBLE
@@ -0,0 +1,50 @@
1
+ #pragma once
2
+
3
+ #include <simpleble/export.h>
4
+
5
+ #if __APPLE__
6
+ #include "TargetConditionals.h"
7
+ #endif
8
+
9
+ /**
10
+ * Advanced Features
11
+ *
12
+ * The functions presented in this namespace are OS-specific backdoors that are
13
+ * not part of the standard SimpleBLE API, which allow the user to access
14
+ * low-level details of the implementation for advanced use cases.
15
+ *
16
+ * These functions should be used with caution.
17
+ */
18
+
19
+ #if defined(_WIN32)
20
+ namespace SimpleBLE::Advanced::Windows {}
21
+
22
+ #endif
23
+
24
+ #if TARGET_OS_OSX
25
+ namespace SimpleBLE::Advanced::MacOS {}
26
+
27
+ #endif
28
+
29
+ #if TARGET_OS_IOS
30
+ namespace SimpleBLE::Advanced::iOS {}
31
+
32
+ #endif
33
+
34
+ #if defined(__ANDROID__)
35
+
36
+ #include <jni.h>
37
+
38
+ namespace SimpleBLE::Advanced::Android {
39
+
40
+ JavaVM* SIMPLEBLE_EXPORT get_jvm();
41
+ void SIMPLEBLE_EXPORT set_jvm(JavaVM* jvm);
42
+
43
+ } // namespace SimpleBLE::Advanced::Android
44
+
45
+ #endif
46
+
47
+ #if defined(__linux__) && !defined(__ANDROID__)
48
+ namespace SimpleBLE::Advanced::Linux {}
49
+
50
+ #endif
@@ -0,0 +1,39 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+
5
+ #include <simpleble/export.h>
6
+
7
+ #include <simpleble/Descriptor.h>
8
+ #include <simpleble/Exceptions.h>
9
+ #include <simpleble/Types.h>
10
+
11
+ namespace SimpleBLE {
12
+
13
+ class CharacteristicBase;
14
+
15
+ class SIMPLEBLE_EXPORT Characteristic {
16
+ public:
17
+ Characteristic() = default;
18
+ virtual ~Characteristic() = default;
19
+
20
+ bool initialized() const;
21
+
22
+ BluetoothUUID uuid();
23
+ std::vector<Descriptor> descriptors();
24
+ std::vector<std::string> capabilities();
25
+
26
+ bool can_read();
27
+ bool can_write_request();
28
+ bool can_write_command();
29
+ bool can_notify();
30
+ bool can_indicate();
31
+
32
+ protected:
33
+ CharacteristicBase* operator->();
34
+ const CharacteristicBase* operator->() const;
35
+
36
+ std::shared_ptr<CharacteristicBase> internal_;
37
+ };
38
+
39
+ } // namespace SimpleBLE
@@ -0,0 +1,64 @@
1
+ #pragma once
2
+ #include <chrono>
3
+
4
+ namespace SimpleBLE {
5
+ namespace Config {
6
+ namespace SimpleBluez {
7
+ extern bool use_legacy_bluez_backend;
8
+ extern std::chrono::steady_clock::duration connection_timeout;
9
+ extern std::chrono::steady_clock::duration disconnection_timeout;
10
+
11
+ static void reset() {
12
+ use_legacy_bluez_backend = true;
13
+ connection_timeout = std::chrono::seconds(2);
14
+ disconnection_timeout = std::chrono::seconds(1);
15
+ }
16
+ }
17
+
18
+ namespace WinRT {
19
+ extern bool experimental_use_own_mta_apartment;
20
+ extern bool experimental_reinitialize_winrt_apartment_on_main_thread;
21
+
22
+ static void reset() {
23
+ experimental_use_own_mta_apartment = true;
24
+ experimental_reinitialize_winrt_apartment_on_main_thread = false;
25
+ }
26
+ }
27
+
28
+ namespace CoreBluetooth {
29
+ static void reset() {}
30
+ }
31
+
32
+ namespace Android {
33
+ enum class ConnectionPriorityRequest {
34
+ DISABLED = -1,
35
+ BALANCED = 0,
36
+ HIGH = 1,
37
+ LOW_POWER = 2,
38
+ DCK = 3
39
+ };
40
+
41
+ extern ConnectionPriorityRequest connection_priority_request;
42
+
43
+ static void reset() {
44
+ connection_priority_request = ConnectionPriorityRequest::DISABLED;
45
+ }
46
+ }
47
+
48
+ namespace Dongl {
49
+ extern bool use_dongl_backend;
50
+ static void reset() {
51
+ use_dongl_backend = false;
52
+ }
53
+ }
54
+
55
+ namespace Base {
56
+ static void reset_all() {
57
+ SimpleBluez::reset();
58
+ WinRT::reset();
59
+ CoreBluetooth::reset();
60
+ Android::reset();
61
+ }
62
+ }
63
+ } // namespace Config
64
+ } // namespace SimpleBLE
@@ -0,0 +1,30 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+
5
+ #include <simpleble/export.h>
6
+
7
+ #include <simpleble/Exceptions.h>
8
+ #include <simpleble/Types.h>
9
+
10
+ namespace SimpleBLE {
11
+
12
+ class DescriptorBase;
13
+
14
+ class SIMPLEBLE_EXPORT Descriptor {
15
+ public:
16
+ Descriptor() = default;
17
+ virtual ~Descriptor() = default;
18
+
19
+ bool initialized() const;
20
+
21
+ BluetoothUUID uuid();
22
+
23
+ protected:
24
+ DescriptorBase* operator->();
25
+ const DescriptorBase* operator->() const;
26
+
27
+ std::shared_ptr<DescriptorBase> internal_;
28
+ };
29
+
30
+ } // namespace SimpleBLE
@@ -0,0 +1,72 @@
1
+ #pragma once
2
+
3
+ #include <stdexcept>
4
+ #include <string>
5
+
6
+ #include <simpleble/export.h>
7
+
8
+ #include "Types.h"
9
+
10
+ namespace SimpleBLE {
11
+
12
+ namespace Exception {
13
+
14
+ class SIMPLEBLE_EXPORT BaseException : public std::runtime_error {
15
+ public:
16
+ BaseException(const std::string& __arg) : std::runtime_error(__arg) {}
17
+ };
18
+
19
+ class SIMPLEBLE_EXPORT NotInitialized : public BaseException {
20
+ public:
21
+ NotInitialized();
22
+ };
23
+
24
+ class SIMPLEBLE_EXPORT NotConnected : public BaseException {
25
+ public:
26
+ NotConnected();
27
+ };
28
+
29
+ class SIMPLEBLE_EXPORT InvalidReference : public BaseException {
30
+ public:
31
+ InvalidReference();
32
+ };
33
+
34
+ class SIMPLEBLE_EXPORT ServiceNotFound : public BaseException {
35
+ public:
36
+ ServiceNotFound(BluetoothUUID uuid);
37
+ };
38
+
39
+ class SIMPLEBLE_EXPORT CharacteristicNotFound : public BaseException {
40
+ public:
41
+ CharacteristicNotFound(BluetoothUUID uuid);
42
+ };
43
+
44
+ class SIMPLEBLE_EXPORT DescriptorNotFound : public BaseException {
45
+ public:
46
+ DescriptorNotFound(BluetoothUUID uuid);
47
+ };
48
+
49
+ class SIMPLEBLE_EXPORT OperationNotSupported : public BaseException {
50
+ public:
51
+ OperationNotSupported();
52
+ };
53
+
54
+ class SIMPLEBLE_EXPORT OperationFailed : public BaseException {
55
+ public:
56
+ OperationFailed();
57
+ OperationFailed(const std::string& err_msg);
58
+ };
59
+
60
+ class SIMPLEBLE_EXPORT WinRTException : public BaseException {
61
+ public:
62
+ WinRTException(int32_t err_code, const std::string& err_msg);
63
+ };
64
+
65
+ class SIMPLEBLE_EXPORT CoreBluetoothException : public BaseException {
66
+ public:
67
+ CoreBluetoothException(const std::string& err_msg);
68
+ };
69
+
70
+ } // namespace Exception
71
+
72
+ } // namespace SimpleBLE
@@ -0,0 +1,73 @@
1
+ #pragma once
2
+
3
+ #include <cstdint>
4
+ #include <functional>
5
+ #include <mutex>
6
+ #include <string>
7
+
8
+ #include <simpleble/export.h>
9
+
10
+ namespace SimpleBLE {
11
+
12
+ namespace Logging {
13
+
14
+ enum Level : int {
15
+ None = 0,
16
+ Fatal,
17
+ Error,
18
+ Warn,
19
+ Info,
20
+ Debug,
21
+ Verbose,
22
+ };
23
+
24
+ // clang-format off
25
+ using Callback = std::function<void(
26
+ Level,
27
+ const std::string& module,
28
+ const std::string& file,
29
+ uint32_t line,
30
+ const std::string& function,
31
+ const std::string& message)>;
32
+ // clang-format on
33
+
34
+ class SIMPLEBLE_EXPORT Logger {
35
+ public:
36
+ static Logger* get();
37
+
38
+ void set_level(Level level);
39
+ Level get_level();
40
+
41
+ void set_callback(Callback callback);
42
+ bool has_callback();
43
+
44
+ void log_default_stdout();
45
+ void log_default_file();
46
+ void log_default_file(const std::string path);
47
+
48
+ // clang-format off
49
+ void log(
50
+ Level level,
51
+ const std::string& module,
52
+ const std::string& file,
53
+ uint32_t line,
54
+ const std::string& function,
55
+ const std::string& message);
56
+ // clang-format on
57
+
58
+ private:
59
+ Logger();
60
+ ~Logger();
61
+ Logger(Logger& other) = delete; // Remove copy constructor
62
+ void operator=(const Logger&) = delete; // Remove copy assignment
63
+
64
+ static std::string level_to_str(Level level);
65
+
66
+ Level level_{Level::Info};
67
+ Callback callback_{nullptr};
68
+ std::recursive_mutex mutex_;
69
+ };
70
+
71
+ } // namespace Logging
72
+
73
+ } // namespace SimpleBLE