trinity-devel@lists.pearsoncomputing.net

Message: previous - next
Month: December 2016

Re: how to read out the values of a complex dbus reply

From: deloptes <deloptes@...>
Date: Mon, 12 Dec 2016 21:43:37 +0100
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;

                }
        }