Results 1 to 4 of 4

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

  1. #1
    Join Date
    Mar 2015
    Posts
    8
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Extract arguments and object path from net.connman.Manager's GetService DBus method

    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/...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:

    Qt Code:
    1. QDBusConnection bus = QDBusConnection::systemBus();
    2. QDBusInterface *interface = new QDBusInterface("net.connman",
    3. "/",
    4. "net.connman.Manager",
    5. bus,
    6. this);
    7.  
    8. QDBusMessage test = interface->call("GetServices");
    9. QList<QVariant> outArgs = test.arguments();
    10.  
    11. QVariant first = outArgs.at(0);
    12. qDebug() << first;
    13.  
    14. QDBusVariant dbvFirst = first.value<QDBusVariant>();
    15.  
    16. QVariant vFirst = dbvFirst.variant();
    17. qDebug() << vFirst;
    18.  
    19. QDBusArgument dbusArgs = vFirst.value<QDBusArgument>();
    20. qDebug() << "QDBusArgument current type is" << dbusArgs.currentType();
    21.  
    22. dbusArgs.beginArray();
    23. while (!dbusArgs.atEnd())
    24. {
    25. dbusArgs >> path;
    26. // append path to a vector here if you want to keep it
    27. }
    28.  
    29. dbusArgs.endArray();
    30. qDebug() << path.path();
    To copy to clipboard, switch view to plain text mode 


    How do I extract the arguments and the object path returned by the GetService method? Has anyone done this correctly?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Extract arguments and object path from net.connman.Manager's GetService DBus met

    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,
    _

  3. #3
    Join Date
    Mar 2015
    Posts
    8
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Extract arguments and object path from net.connman.Manager's GetService DBus met

    Quote Originally Posted by anda_skoa View Post
    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

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Extract arguments and object path from net.connman.Manager's GetService DBus met

    Quote Originally Posted by admd91 View Post
    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...us/CustomTypes

    Quote Originally Posted by admd91 View Post
    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,
    _

Similar Threads

  1. Replies: 6
    Last Post: 25th January 2014, 10:12
  2. Multi output parameters with DBUS-Method
    By mecland in forum Qt Programming
    Replies: 2
    Last Post: 31st December 2013, 12:41
  3. TypeError: Object [object Object] has no method 'sendData'
    By TheIndependentAquarius in forum Qt Quick
    Replies: 2
    Last Post: 30th November 2013, 05:54
  4. Replies: 5
    Last Post: 7th January 2010, 10:42
  5. Extract method on plaintext with QRegExp
    By jlbrd in forum Qt Programming
    Replies: 1
    Last Post: 2nd July 2006, 13:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.