Skip to content

Commit

Permalink
Exposed trusted property
Browse files Browse the repository at this point in the history
  • Loading branch information
kdewald committed Dec 2, 2024
1 parent fd3504f commit 8eef23d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions simplebluez/include/simplebluez/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Device : public SimpleDBus::Proxy {

bool paired(bool refresh = true);
bool bonded(bool refresh = true);
bool trusted();
void trusted(bool trusted);
bool connected(bool refresh = true);
bool services_resolved(bool refresh = true);

Expand Down
2 changes: 2 additions & 0 deletions simplebluez/include/simplebluez/interfaces/Device1.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Device1 : public SimpleDBus::Interface {
std::map<std::string, ByteArray> ServiceData(bool refresh = true);
bool Paired(bool refresh = true);
bool Bonded(bool refresh = true);
bool Trusted();
void Trusted(bool trusted);
bool Connected(bool refresh = true);
bool ServicesResolved(bool refresh = true);

Expand Down
4 changes: 4 additions & 0 deletions simplebluez/src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ bool Device::paired(bool refresh) { return device1()->Paired(refresh); }

bool Device::bonded(bool refresh) { return device1()->Bonded(refresh); }

bool Device::trusted() { return device1()->Trusted(); }

void Device::trusted(bool trusted) { device1()->Trusted(trusted); }

bool Device::connected(bool refresh) { return device1()->Connected(refresh); }

bool Device::services_resolved(bool refresh) { return device1()->ServicesResolved(refresh); }
Expand Down
1 change: 0 additions & 1 deletion simplebluez/src/interfaces/Agent1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Agent1::Agent1(std::shared_ptr<SimpleDBus::Connection> conn, SimpleDBus::Proxy*
: SimpleDBus::Interface(conn, proxy, "org.bluez.Agent1") {}

void Agent1::message_handle(SimpleDBus::Message& msg) {
std::cout << "Agent1::message_handle()\n" << msg.to_string() << std::endl;

if (msg.get_type() == SimpleDBus::Message::Type::METHOD_CALL) {
// To minimize the amount of repeated code, create a method return object that will be
Expand Down
22 changes: 22 additions & 0 deletions simplebluez/src/interfaces/Device1.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "simplebluez/interfaces/Device1.h"
#include "simpledbus/interfaces/Properties.h"
#include "simpledbus/advanced/Proxy.h"

using namespace SimpleBluez;

Expand Down Expand Up @@ -111,6 +113,26 @@ bool Device1::Bonded(bool refresh) {
return _properties["Bonded"].get_boolean();
}

bool Device1::Trusted() {
std::scoped_lock lock(_property_update_mutex);
return _properties["Trusted"].get_boolean();
}

void Device1::Trusted(bool trusted) {
SimpleDBus::Holder value_array = SimpleDBus::Holder::create_boolean(trusted);

{
std::scoped_lock lock(_property_update_mutex);
_properties["Trusted"] = value_array;
}

std::map<std::string, SimpleDBus::Holder> changed_properties;
changed_properties["Trusted"] = value_array;

std::shared_ptr<SimpleDBus::Properties> properties = std::dynamic_pointer_cast<SimpleDBus::Properties>(_proxy->interface_get("org.freedesktop.DBus.Properties"));
properties->PropertiesChanged("org.bluez.Device1", changed_properties);
}

bool Device1::Connected(bool refresh) {
if (refresh) {
property_refresh("Connected");
Expand Down

0 comments on commit 8eef23d

Please sign in to comment.