Skip to content

Commit

Permalink
update simpleble (#608)
Browse files Browse the repository at this point in the history
* update simpleble

Signed-off-by: Andrey Parfenov <a1994ndrey@gmail.com>
  • Loading branch information
Andrey1994 committed Feb 12, 2023
1 parent 926f012 commit e8d83d3
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 19 deletions.
5 changes: 0 additions & 5 deletions lgtm.yml

This file was deleted.

1 change: 1 addition & 0 deletions third_party/SimpleBLE/simpleble/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ target_link_libraries(${SIMPLEBLE-C} PRIVATE simpleble)
if(NOT SIMPLEBLE_LOG_LEVEL)
set(SIMPLEBLE_LOG_LEVEL "INFO")
endif()
list(APPEND PRIVATE_COMPILE_DEFINITIONS SIMPLEBLE_LOG_LEVEL=SIMPLEBLE_LOG_LEVEL_${SIMPLEBLE_LOG_LEVEL})

append_sanitize_options("${SIMPLEBLE_SANITIZE}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SIMPLEBLE_EXPORT Adapter {

std::vector<Peripheral> get_paired_peripherals();

static bool bluetooth_enabled() noexcept;
static bool bluetooth_enabled();

/**
* Fetches a list of all available adapters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SIMPLEBLE_EXPORT Adapter : public SimpleBLE::Adapter {

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

static std::optional<bool> bluetooth_enabled() noexcept;
static std::optional<std::vector<SimpleBLE::Safe::Adapter>> get_adapters() noexcept;
};

Expand Down
12 changes: 1 addition & 11 deletions third_party/SimpleBLE/simpleble/src/frontends/base/Adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@ std::vector<Adapter> Adapter::get_adapters() {
return available_adapters;
}

bool Adapter::bluetooth_enabled() noexcept {
try {
return AdapterBase::bluetooth_enabled();
} catch (const std::exception& e) {
SIMPLEBLE_LOG_ERROR(fmt::format("Failed to check if bluetooth is enabled: {}", e.what()));
return false;
} catch (...) {
SIMPLEBLE_LOG_ERROR("Failed to check if bluetooth is enabled: Unknown error");
return false;
}
}
bool Adapter::bluetooth_enabled() { return AdapterBase::bluetooth_enabled(); }

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ bool SimpleBLE::Safe::Adapter::set_callback_on_scan_found(
}
}

std::optional<bool> SimpleBLE::Safe::Adapter::bluetooth_enabled() noexcept {
try {
return SimpleBLE::Adapter::bluetooth_enabled();
} catch (...) {
return std::nullopt;
}
}

std::optional<std::vector<SimpleBLE::Safe::Adapter>> SimpleBLE::Safe::Adapter::get_adapters() noexcept {
try {
auto adapters = SimpleBLE::Adapter::get_adapters();
Expand Down
4 changes: 3 additions & 1 deletion third_party/SimpleBLE/simpleble/src_c/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include <cstring>

bool simpleble_adapter_is_bluetooth_enabled(void) { return SimpleBLE::Safe::Adapter::bluetooth_enabled(); }
bool simpleble_adapter_is_bluetooth_enabled(void) {
return SimpleBLE::Safe::Adapter::bluetooth_enabled().value_or(false);
}

size_t simpleble_adapter_get_count(void) {
return SimpleBLE::Safe::Adapter::get_adapters().value_or(std::vector<SimpleBLE::Safe::Adapter>()).size();
Expand Down
6 changes: 5 additions & 1 deletion third_party/SimpleBLE/simplebluez/src/Bluez.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ Bluez::Bluez() : Proxy(std::make_shared<SimpleDBus::Connection>(DBUS_BUS_SYSTEM)
};
}

Bluez::~Bluez() { _conn->remove_match("type='signal',sender='org.bluez'"); }
Bluez::~Bluez() {
if (_conn->is_initialized()) {
_conn->remove_match("type='signal',sender='org.bluez'");
}
}

void Bluez::init() {
_conn->init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Connection {

void init();
void uninit();
bool is_initialized();

void add_match(std::string rule);
void remove_match(std::string rule);
Expand Down
2 changes: 2 additions & 0 deletions third_party/SimpleBLE/simpledbus/src/base/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ void Connection::uninit() {
_initialized = false;
}

bool Connection::is_initialized() { return _initialized; }

void Connection::add_match(std::string rule) {
if (!_initialized) {
throw Exception::NotInitialized();
Expand Down

0 comments on commit e8d83d3

Please sign in to comment.