Skip to content

Commit e8d83d3

Browse files
authored
update simpleble (#608)
* update simpleble Signed-off-by: Andrey Parfenov <[email protected]>
1 parent 926f012 commit e8d83d3

File tree

10 files changed

+23
-19
lines changed

10 files changed

+23
-19
lines changed

lgtm.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

third_party/SimpleBLE/simpleble/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ target_link_libraries(${SIMPLEBLE-C} PRIVATE simpleble)
132132
if(NOT SIMPLEBLE_LOG_LEVEL)
133133
set(SIMPLEBLE_LOG_LEVEL "INFO")
134134
endif()
135+
list(APPEND PRIVATE_COMPILE_DEFINITIONS SIMPLEBLE_LOG_LEVEL=SIMPLEBLE_LOG_LEVEL_${SIMPLEBLE_LOG_LEVEL})
135136

136137
append_sanitize_options("${SIMPLEBLE_SANITIZE}")
137138

third_party/SimpleBLE/simpleble/include/simpleble/Adapter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SIMPLEBLE_EXPORT Adapter {
3939

4040
std::vector<Peripheral> get_paired_peripherals();
4141

42-
static bool bluetooth_enabled() noexcept;
42+
static bool bluetooth_enabled();
4343

4444
/**
4545
* Fetches a list of all available adapters.

third_party/SimpleBLE/simpleble/include/simpleble/AdapterSafe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class SIMPLEBLE_EXPORT Adapter : public SimpleBLE::Adapter {
3030

3131
std::optional<std::vector<SimpleBLE::Safe::Peripheral>> get_paired_peripherals() noexcept;
3232

33+
static std::optional<bool> bluetooth_enabled() noexcept;
3334
static std::optional<std::vector<SimpleBLE::Safe::Adapter>> get_adapters() noexcept;
3435
};
3536

third_party/SimpleBLE/simpleble/src/frontends/base/Adapter.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,7 @@ std::vector<Adapter> Adapter::get_adapters() {
1818
return available_adapters;
1919
}
2020

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(); }
3222

3323
bool Adapter::initialized() const { return internal_ != nullptr; }
3424

third_party/SimpleBLE/simpleble/src/frontends/safe/AdapterSafe.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ bool SimpleBLE::Safe::Adapter::set_callback_on_scan_found(
121121
}
122122
}
123123

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+
124132
std::optional<std::vector<SimpleBLE::Safe::Adapter>> SimpleBLE::Safe::Adapter::get_adapters() noexcept {
125133
try {
126134
auto adapters = SimpleBLE::Adapter::get_adapters();

third_party/SimpleBLE/simpleble/src_c/adapter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
#include <cstring>
66

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+
}
810

911
size_t simpleble_adapter_get_count(void) {
1012
return SimpleBLE::Safe::Adapter::get_adapters().value_or(std::vector<SimpleBLE::Safe::Adapter>()).size();

third_party/SimpleBLE/simplebluez/src/Bluez.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ Bluez::Bluez() : Proxy(std::make_shared<SimpleDBus::Connection>(DBUS_BUS_SYSTEM)
1616
};
1717
}
1818

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+
}
2024

2125
void Bluez::init() {
2226
_conn->init();

third_party/SimpleBLE/simpledbus/include/simpledbus/base/Connection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Connection {
1515

1616
void init();
1717
void uninit();
18+
bool is_initialized();
1819

1920
void add_match(std::string rule);
2021
void remove_match(std::string rule);

third_party/SimpleBLE/simpledbus/src/base/Connection.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ void Connection::uninit() {
5656
_initialized = false;
5757
}
5858

59+
bool Connection::is_initialized() { return _initialized; }
60+
5961
void Connection::add_match(std::string rule) {
6062
if (!_initialized) {
6163
throw Exception::NotInitialized();

0 commit comments

Comments
 (0)