diff --git a/examples/simplebluez/incoming/incoming.cpp b/examples/simplebluez/incoming/incoming.cpp index a63bfa80..3460c585 100644 --- a/examples/simplebluez/incoming/incoming.cpp +++ b/examples/simplebluez/incoming/incoming.cpp @@ -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. diff --git a/simplebluez/include/simplebluez/Adapter.h b/simplebluez/include/simplebluez/Adapter.h index 77b78797..e3e0dee5 100644 --- a/simplebluez/include/simplebluez/Adapter.h +++ b/simplebluez/include/simplebluez/Adapter.h @@ -34,7 +34,9 @@ class Adapter : public SimpleDBus::Proxy { std::shared_ptr device_get(const std::string& path); void device_remove(const std::string& path); void device_remove(const std::shared_ptr& device); + std::vector> device_paired_get(); + std::vector> device_bonded_get(); void set_on_device_updated(std::function device)> callback); void clear_on_device_updated(); diff --git a/simplebluez/src/Adapter.cpp b/simplebluez/src/Adapter.cpp index 8ea4757e..1b573d03 100644 --- a/simplebluez/src/Adapter.cpp +++ b/simplebluez/src/Adapter.cpp @@ -88,6 +88,22 @@ std::vector> Adapter::device_paired_get() { return paired_devices; } +std::vector> Adapter::device_bonded_get() { + // Traverse all child paths and return only those that are bonded. + std::vector> bonded_devices; + + for (auto& [path, child] : _children) { + if (!child->valid()) continue; + + std::shared_ptr device = std::dynamic_pointer_cast(child); + if (device->bonded()) { + bonded_devices.push_back(device); + } + } + + return bonded_devices; +} + void Adapter::register_advertisement(const std::shared_ptr& advertisement) { if (supported_advertisement_instances() == 0) { throw std::runtime_error("No available advertisement instances");