PDA

View Full Version : Extract arguments and object path from net.connman.Manager's GetService DBus method



admd91
11th March 2015, 05:22
Hello everyone,

I am planning to develop an application that will make use of DBus and connman, a wireless manager. 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 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_manag ed_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 https://stackoverflow.com/questions/20206376/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;
// append path to a vector here if you want to keep it
}

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?

Thanks

anda_skoa
11th March 2015, 08:01
The easiest way to work with a D-Bus service is to get the introspection data for the interface and then let qdbusxml2cpp generate a proxy object for you.

In either case you need at least knowledge about the method signature, i.e. what type it is returning.

Cheers,
_

admd91
13th March 2015, 09:59
The easiest way to work with a D-Bus service is to get the introspection data for the interface and then let qdbusxml2cpp generate a proxy object for you.

In either case you need at least knowledge about the method signature, i.e. what type it is returning.

Cheers,
_

Hello,

I have generated the .h and .cpp files from the .xml file for net.connman.Services using qdbusxml2cpp, but admittedly I am having a hard time figuring out how to use them in my project. I have included them in my project, but I do not understand how to use the methods defined in the generated files.

Since I need to use other interfaces (the ones corresponding to a wireless network), do I also need to generate a proxy code for those interfaces aside from the ones from net.connman.Manager? Also if you have some tutorials for Qt D-Bus that you can point to it would be a great help?

Thanks

anda_skoa
13th March 2015, 15:09
I have generated the .h and .cpp files from the .xml file for net.connman.Services using qdbusxml2cpp, but admittedly I am having a hard time figuring out how to use them in my project. I have included them in my project, but I do not understand how to use the methods defined in the generated files.

An instance of generated Interface class can be used like a proxy to the service-side exported object.
I.e. any call to a method will result in a call on the server side, if the server emits a signal, the proxy object will emit its signal.

So the usage is more or less:
- create instance of generated class, passing service name, object path and D-Bus connection
- call methods on that object

For complex argument or result types it is possible to provide custom data types, the generated code can then use these to make the experience even closer to calling a local object.
https://techbase.kde.org/Development/Tutorials/D-Bus/CustomTypes



Since I need to use other interfaces (the ones corresponding to a wireless network), do I also need to generate a proxy code for those interfaces aside from the ones from net.connman.Manager?

The proxy object approach is usually the easiest, but you can always use plan QDBusInterface if you want to.

Cheers,
_