Skip to content

Commit

Permalink
Exposed bonded devices
Browse files Browse the repository at this point in the history
  • Loading branch information
kdewald committed Nov 14, 2024
1 parent 4bc5a19 commit 1802ce2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/simplebluez/incoming/incoming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ int main(int argc, char* argv[]) {
for (auto& device : paired_devices) {
std::cout << "Paired device: " << device->name() << " [" << device->address() << "]" << std::endl;
}

auto bonded_devices = adapter->device_bonded_get();
for (auto& device : bonded_devices) {
std::cout << "Bonded device: " << device->name() << " [" << device->address() << "]" << std::endl;
}
}

// TODO: Handle connection events.
Expand Down
2 changes: 2 additions & 0 deletions simplebluez/include/simplebluez/Adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class Adapter : public SimpleDBus::Proxy {
std::shared_ptr<Device> device_get(const std::string& path);
void device_remove(const std::string& path);
void device_remove(const std::shared_ptr<Device>& device);

std::vector<std::shared_ptr<Device>> device_paired_get();
std::vector<std::shared_ptr<Device>> device_bonded_get();

void set_on_device_updated(std::function<void(std::shared_ptr<Device> device)> callback);
void clear_on_device_updated();
Expand Down
16 changes: 16 additions & 0 deletions simplebluez/src/Adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ std::vector<std::shared_ptr<Device>> Adapter::device_paired_get() {
return paired_devices;
}

std::vector<std::shared_ptr<Device>> Adapter::device_bonded_get() {
// Traverse all child paths and return only those that are bonded.
std::vector<std::shared_ptr<Device>> bonded_devices;

for (auto& [path, child] : _children) {
if (!child->valid()) continue;

std::shared_ptr<Device> device = std::dynamic_pointer_cast<Device>(child);
if (device->bonded()) {
bonded_devices.push_back(device);
}
}

return bonded_devices;
}

void Adapter::register_advertisement(const std::shared_ptr<CustomAdvertisement>& advertisement) {
if (supported_advertisement_instances() == 0) {
throw std::runtime_error("No available advertisement instances");
Expand Down

0 comments on commit 1802ce2

Please sign in to comment.