Skip to content

Example (proof of concept) of passing custom object from dbus service

Notifications You must be signed in to change notification settings

cc-michaelu/dbus-sandbox

Repository files navigation

DBus Sandbox

Overview

This repo contains example code of how to pass a custom data type from a DBus service and consume it on the client. There are two sub-projects included:

complex-dbus-service

This is the DBus service which exposes a function getCustomData() which returns data in a custom class named customData. This class is defined in the common/inc/customdata.h file. It includes a static function which registers its type with the Qt Dbus type system.

complex-dbus-client

This is the DBus client which simply calls the getCustomData() method and displays the results returned.

Sample output

$ ./build/complex-dbus-client/complex-dbus-client
Calling getCustomData()
Name = "michael"
Value = 50
Calling getCustomDataList()
{ "michael", 50 }
{ "dale", 50 }
{ "frank", 50 }
{ "oner", 50 }
Calling getStringList()
{ Peter, Paul, Mary, Bob }
Calling setStringList()
Calling getListOfMaps()
"age" : "50"
"name" : "michael"
"age" : "45"
"name" : "ritesh"

Build Instructions

git clone [email protected]:cc-michaelu/dbus-sandbox.git
cd dbus-sandbox
mkdir build
cd build
cmake ..
make

Notes

The com.cana.complex.xml file is hand-modified to include the following XML nodes:

    <method name="getCustomData">
      <arg type="a{sv}" direction="out" />
      <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="customData" />
    </method>
    <method name="getCustomDataList">
      <arg type="av" direction="out" />
    </method>

As a result the generation of the Adaptor and Proxy classes does not involve the qdbusxml2cpp step (converting the C++ interface class to xml).

The Adaptor class is modified:

complexAdaptor.h

  public Q_SLOTS: // METHODS
    customData getCustomData();
    QList<customData> getCustomDataList();

complexAdaptor.cpp

customData ComplexAdaptor::getCustomData() {
    // handle method call com.cana.complex.getCustomData
    customData out0;
    QMetaObject::invokeMethod(parent(), "getCustomData",
                              Q_RETURN_ARG(customData, out0));
    return out0;
}

QList<customData> ComplexAdaptor::getCustomDataList() {
    // handle method call com.cana.complex.getCustomDataList
    QList<customData> out0;
    QMetaObject::invokeMethod(parent(), "getCustomDataList",
                              Q_RETURN_ARG(QList<customData>, out0));
    return out0;
}

About

Example (proof of concept) of passing custom object from dbus service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published