File tree Expand file tree Collapse file tree 10 files changed +23
-19
lines changed Expand file tree Collapse file tree 10 files changed +23
-19
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -132,6 +132,7 @@ target_link_libraries(${SIMPLEBLE-C} PRIVATE simpleble)
132
132
if (NOT SIMPLEBLE_LOG_LEVEL )
133
133
set (SIMPLEBLE_LOG_LEVEL "INFO" )
134
134
endif ()
135
+ list (APPEND PRIVATE_COMPILE_DEFINITIONS SIMPLEBLE_LOG_LEVEL=SIMPLEBLE_LOG_LEVEL_${SIMPLEBLE_LOG_LEVEL} )
135
136
136
137
append_sanitize_options ("${SIMPLEBLE_SANITIZE} " )
137
138
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ class SIMPLEBLE_EXPORT Adapter {
39
39
40
40
std::vector<Peripheral> get_paired_peripherals ();
41
41
42
- static bool bluetooth_enabled () noexcept ;
42
+ static bool bluetooth_enabled ();
43
43
44
44
/* *
45
45
* Fetches a list of all available adapters.
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ class SIMPLEBLE_EXPORT Adapter : public SimpleBLE::Adapter {
30
30
31
31
std::optional<std::vector<SimpleBLE::Safe::Peripheral>> get_paired_peripherals () noexcept ;
32
32
33
+ static std::optional<bool > bluetooth_enabled () noexcept ;
33
34
static std::optional<std::vector<SimpleBLE::Safe::Adapter>> get_adapters () noexcept ;
34
35
};
35
36
Original file line number Diff line number Diff line change @@ -18,17 +18,7 @@ std::vector<Adapter> Adapter::get_adapters() {
18
18
return available_adapters;
19
19
}
20
20
21
- bool Adapter::bluetooth_enabled () noexcept {
22
- try {
23
- return AdapterBase::bluetooth_enabled ();
24
- } catch (const std::exception& e) {
25
- SIMPLEBLE_LOG_ERROR (fmt::format (" Failed to check if bluetooth is enabled: {}" , e.what ()));
26
- return false ;
27
- } catch (...) {
28
- SIMPLEBLE_LOG_ERROR (" Failed to check if bluetooth is enabled: Unknown error" );
29
- return false ;
30
- }
31
- }
21
+ bool Adapter::bluetooth_enabled () { return AdapterBase::bluetooth_enabled (); }
32
22
33
23
bool Adapter::initialized () const { return internal_ != nullptr ; }
34
24
Original file line number Diff line number Diff line change @@ -121,6 +121,14 @@ bool SimpleBLE::Safe::Adapter::set_callback_on_scan_found(
121
121
}
122
122
}
123
123
124
+ std::optional<bool > SimpleBLE::Safe::Adapter::bluetooth_enabled () noexcept {
125
+ try {
126
+ return SimpleBLE::Adapter::bluetooth_enabled ();
127
+ } catch (...) {
128
+ return std::nullopt;
129
+ }
130
+ }
131
+
124
132
std::optional<std::vector<SimpleBLE::Safe::Adapter>> SimpleBLE::Safe::Adapter::get_adapters () noexcept {
125
133
try {
126
134
auto adapters = SimpleBLE::Adapter::get_adapters ();
Original file line number Diff line number Diff line change 4
4
5
5
#include < cstring>
6
6
7
- bool simpleble_adapter_is_bluetooth_enabled (void ) { return SimpleBLE::Safe::Adapter::bluetooth_enabled (); }
7
+ bool simpleble_adapter_is_bluetooth_enabled (void ) {
8
+ return SimpleBLE::Safe::Adapter::bluetooth_enabled ().value_or (false );
9
+ }
8
10
9
11
size_t simpleble_adapter_get_count (void ) {
10
12
return SimpleBLE::Safe::Adapter::get_adapters ().value_or (std::vector<SimpleBLE::Safe::Adapter>()).size ();
Original file line number Diff line number Diff line change @@ -16,7 +16,11 @@ Bluez::Bluez() : Proxy(std::make_shared<SimpleDBus::Connection>(DBUS_BUS_SYSTEM)
16
16
};
17
17
}
18
18
19
- Bluez::~Bluez () { _conn->remove_match (" type='signal',sender='org.bluez'" ); }
19
+ Bluez::~Bluez () {
20
+ if (_conn->is_initialized ()) {
21
+ _conn->remove_match (" type='signal',sender='org.bluez'" );
22
+ }
23
+ }
20
24
21
25
void Bluez::init () {
22
26
_conn->init ();
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ class Connection {
15
15
16
16
void init ();
17
17
void uninit ();
18
+ bool is_initialized ();
18
19
19
20
void add_match (std::string rule);
20
21
void remove_match (std::string rule);
Original file line number Diff line number Diff line change @@ -56,6 +56,8 @@ void Connection::uninit() {
56
56
_initialized = false ;
57
57
}
58
58
59
+ bool Connection::is_initialized () { return _initialized; }
60
+
59
61
void Connection::add_match (std::string rule) {
60
62
if (!_initialized) {
61
63
throw Exception::NotInitialized ();
You can’t perform that action at this time.
0 commit comments