Sep 1, 2012

Using QtDbus

Hello everyone! Our application consists of client and server parts. So for their communication we decided to use IPC(inter-process communication) system – Dbus, specifically QtDbus, because we already are using Qt in our project. To implement QtDbus in project you need to follow several steps:
  1.         Write the class, with slots, signals and properties using custom types.
  2.      Convert this class to xml file using qdbuscpp2xml.
  3.            Generate Adaptor and Interface from your xml file using qdbusxml2cpp.

        qdbusxml2cpp FileName.xml -a AdaptorName

       qdbusxml2cpp FileName.xml -p InterfaceName


After this you need to write your client and server parts. Writing client is pretty simple. You need to  include to client generated interface .cpp and .h files, and create interface that is described in .h file.
For example in our project it looks like


                DriverAssistant::DynamicPoi (SERVICE_NAME, PATH, QDBusConnection::sessionBus());


Now about server part, let’s divide it into simple steps.
  1.         Include generated adaptor .cpp and .h files.
  2.             Include class just like you wrote for generating .xml file with function realization.
  3.             Create an instance of the class and “feed” it to adaptor class constructor.
And don’t forget about adding CONFIG += qdbus in .pro files and #include <QtDBus/QtDBus> in client and server.

P.S. There are not as many examples as it should be, but we recommend you to see this.
Especially "ping-pong" as the smallest and the simplest one.


2 comments:

  1. RPC(remote procedure call ) is an IPC(inter-process communication) that allows a computer program to cause a subroutine or procedure to execute in another address space without the programmer explicitly coding the details for this remote interaction. (с)wiki

    ReplyDelete