2

I am planning to develop an application that will make use of DBus and connman, a wireless manager for embedded devices. From my understanding DBus exposes the methods used by a program, and allows developers to also make use of these methods in their own program.

I know Qt has the QtDbus module, and if my understanding is correct, the GetServices method under the net.connman.Manager interface shows the wireless networks available. Inspecting the output of the GetServices method from the qdbusviewer program, I can see that each wireless network has its own unique object path, an example would be /net/connman/service/wifi_00120ec15ba0_4c616964614d616774616c6173_managed_psk.

To use the Connect and Disconnect method under the net.connman.Services interface, I need the object path so that I can create a new interface that would allow me to call Connect/Disconnect. I am currently trying the methods outlined here How do I extract the returned data from QDBusMessage in a Qt DBus call?, but I only get a blank when I try to return the object path:

Here is my code to obtain the object path:

QDBusConnection bus = QDBusConnection::systemBus();
QDBusInterface *interface = new QDBusInterface("net.connman",
                                               "/",
                                               "net.connman.Manager",
                                               bus,                                              
                                               this);

QDBusMessage test = interface->call("GetServices");
QList<QVariant> outArgs = test.arguments();

QVariant first = outArgs.at(0);
qDebug() << first;

QDBusVariant dbvFirst = first.value<QDBusVariant>();

QVariant vFirst = dbvFirst.variant();
qDebug() << vFirst;

QDBusArgument dbusArgs = vFirst.value<QDBusArgument>();
qDebug() << "QDBusArgument current type is" << dbusArgs.currentType();

QDBusObjectPath path;
dbusArgs.beginArray();
while (!dbusArgs.atEnd())
{
     dbusArgs >> path;
}

dbusArgs.endArray();
qDebug() << path.path();

How do I extract the arguments and the object path returned by the GetService method? Has anyone done this correctly? I am new to Qt and programming, so any help would be appreciated.

Thanks

Philip Withnall
  • 5,293
  • 14
  • 28
Alvin Dizon
  • 1,855
  • 14
  • 34

1 Answers1

1

This might be late but hope this can help the others. I am not sure about the return type of your call (in dbus its a(oa{sv})), but I tried using QArrayOfPathProperties. So, using your code, the returned type from test.arguments() will be:

QArrayOfPathProperties outArg;

And extracting could be like this:

for (int row = 0; row < outArg.size(); ++row) {
     QMap<QString,QVariant> map = outArg.at(row).properties;
     // for example you can extract the value like this:
     auto serviceName = map.value("Name");     
}
impulse
  • 206
  • 2
  • 15
  • What is `QArrayOfPathProperties`? @benziv – bartlomiej.n Jun 17 '20 at 17:24
  • @bartlomiej.n, tbh, at the time I posted the answer, I assumed it was a Qt class/type.. turns out it isn't. Most likely it was a typedef from one of the classes used in my previous project.. like: https://searchcode.com/codesearch/view/27333999/ – impulse Nov 06 '20 at 03:39