simplersble 0.11.0-dev24

The all-in-one Bluetooth library that makes it easy to add wireless connectivity to your projects.
Documentation
#include <simplebluez/custom/CustomRoot.h>

using namespace SimpleBluez;

CustomRoot::CustomRoot(std::shared_ptr<SimpleDBus::Connection> conn, const std::string& bus_name, const std::string& path)
    : Proxy(conn, bus_name, path) {}

void CustomRoot::on_registration() {
    _interfaces.emplace(std::make_pair("org.freedesktop.DBus.ObjectManager", std::make_shared<SimpleDBus::Interfaces::ObjectManager>(_conn, shared_from_this())));

    // Create the agent that will handle pairing.
    _agent = Proxy::create<Agent>(_conn, "org.bluez", "/agent");
    path_append_child("/agent", std::static_pointer_cast<SimpleDBus::Proxy>(_agent));
}

std::shared_ptr<Agent> CustomRoot::agent_add(const std::string& name) {
    const std::string agent_path = "/agent_" + name;
    auto agent = Proxy::create<Agent>(_conn, "org.bluez", agent_path);
    path_append_child(agent_path, std::static_pointer_cast<SimpleDBus::Proxy>(_agent));
    // TODO: Have the object manager send the InterfacesAdded signal.
    return agent;
}

std::shared_ptr<Agent> CustomRoot::agent_get(const std::string& name) {
    const std::string agent_path = "/agent_" + name;
    return std::dynamic_pointer_cast<Agent>(path_get(agent_path));
}

void CustomRoot::agent_remove(const std::string& name) {
    const std::string agent_path = "/agent_" + name;
    // TODO: Have the object manager send the InterfacesRemoved signal.
    path_remove_child(agent_path);
}

std::shared_ptr<Advertisement> CustomRoot::advertisement_add(const std::string& name) {
    const std::string advertisement_path = "/advertisement_" + name;
    auto advertisement = Proxy::create<Advertisement>(_conn, "org.bluez", advertisement_path);
    path_append_child(advertisement_path, std::static_pointer_cast<SimpleDBus::Proxy>(advertisement));
    // TODO: Have the object manager send the InterfacesAdded signal.
    return advertisement;
}

std::shared_ptr<Advertisement> CustomRoot::advertisement_get(const std::string& name) {
    const std::string advertisement_path = "/advertisement_" + name;
    return std::dynamic_pointer_cast<Advertisement>(path_get(advertisement_path));
}

void CustomRoot::advertisement_remove(const std::string& name) {
    const std::string advertisement_path = "/advertisement_" + name;
    // TODO: Have the object manager send the InterfacesRemoved signal.
    path_remove_child(advertisement_path);
}

std::shared_ptr<SimpleDBus::Interfaces::ObjectManager> CustomRoot::object_manager() {
    return std::dynamic_pointer_cast<SimpleDBus::Interfaces::ObjectManager>(interface_get("org.freedesktop.DBus.ObjectManager"));
}