Hi, I am trying to understand how I could read out the values of a complex dbus reply
I want to access following
// org.freedesktop.DBus.ObjectManager.GetManagedObjects (out DICT<OBJPATH,DICT<STRING,DICT<STRING,VARIANT>>> objpath_interfaces_and_properties); https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces...
In my code I do
TQT_DBusConnection connection = TQT_DBusConnection::systemBus(); if (!connection.isConnected()) tqFatal("Failed to connect to system bus"); TQT_DBusProxy proxy(connection);
proxy.setService("org.bluez"); // who we work with proxy.setPath("/"); // which object inside the peer work with proxy.setInterface("org.freedesktop.DBus.ObjectManager");
if ( connection.isConnected() ) { if ( proxy.canSend() ) { TQValueList<TQT_DBusData> params; TQT_DBusMessage reply = proxy.sendWithReply("GetManagedObjects", params ); if ( reply.type() != 2 || reply.count() != 1 || reply[0].type() != TQT_DBusData::Map) tqFatal("GetManagedObjects failed");
kdDebug() << "TQT_DBusMessage: Reply " << reply.type() << endl; kdDebug() << "Type: TQT_DBusDataMap " << reply[0].type() << endl; kdDebug() << "Count : " << dict.count() << endl; TQT_DBusDataMap<TQT_DBusObjectPath> dict( reply[0] );
for (TQT_DBusDataMap<TQT_DBusObjectPath>::const_iterator it = dict.begin(); it != dict.end(); ++it) { kdDebug() << (*it).type() << endl; } } else tqFatal("proxy can not send messages"); } else tqFatal("manager is not connected");
result is ./bttest TQT_DBusMessage: Reply 2 Type: TQT_DBusDataMap 16 Count : 0
but when I run
gdbus call -y -d "org.bluez" -o "/" -m "org.freedesktop.DBus.ObjectManager.GetManagedObjects" ({objectpath '/org/bluez': {'org.freedesktop.DBus.Introspectable': @a{sv} {}, 'org.bluez.AgentManager1': {}, 'org.bluez.ProfileManager1': {}, 'org.bluez.Alert1': {}, 'org.bluez.HealthManager1': {}}},)
Thank you for being so helpful and supportive with this question ;-)
Here is an example code for the future generation
TQT_DBusConnection connection = TQT_DBusConnection::systemBus(); if (!connection.isConnected()) tqFatal("Failed to connect to session bus");
// create a proxy object for method calls TQT_DBusProxy proxy(connection); proxy.setService("org.bluez" ); // who we work with proxy.setPath("/"); // which object inside the peer work with proxy.setInterface ( "org.freedesktop.DBus.ObjectManager" ); // which of its interfaces we will use
TQValueList<TQT_DBusData> params; TQT_DBusMessage reply = proxy.sendWithReply("GetManagedObjects", params);
if (reply.type() != TQT_DBusMessage::ReplyMessage) tqFatal("Call failed");
if ( reply.type() != TQT_DBusMessage::ReplyMessage || reply.count() != 1 || reply[0].type() != TQT_DBusData::Map) tqFatal("Unexpected reply");
bool ok = false; TQT_DBusDataMap<TQT_DBusObjectPath> names = reply[0].toObjectPathKeyMap(&ok);
kdDebug() << "TQT_DBusMessage::ReplyMessage : " << reply.type() << endl; kdDebug() << "TQT_DBusData::Map : " << reply[0].type() << endl; kdDebug() << "Name1 : " << reply[0].typeName() << endl; kdDebug() << "Size1 : " << names.count() << endl; if (!ok) tqFatal("toTQStringList failed");
for (TQT_DBusDataMap<TQT_DBusObjectPath>::const_iterator it = names.begin(); it != names.end(); ++it) { kdDebug() << "Name2 : " << (*it).typeName() << endl; ok = false; TQT_DBusDataMap<TQString> names1 = (*it).toStringKeyMap(&ok); kdDebug() << "Size2 : " << names1.count() << endl; if (!ok) tqFatal("toTQStringList failed");
for (TQT_DBusDataMap<TQString>::const_iterator it1 = names1.begin(); it1 != names1.end(); ++it1) { ok = false; kdDebug() << "Name3 : " << (*it1).typeName() << endl; TQT_DBusDataMap<TQString> names2 = (*it1).toStringKeyMap(&ok); if (!ok) tqFatal("toTQStringList failed"); kdDebug() << "key : " << TQString(it1.key()) << endl; kdDebug() << "Size3 : " << names2.count() << endl;
} }