dbus example

David Sommerseth dbus at lists.topphemmelig.net
Wed Aug 2 10:45:06 UTC 2017


On 01/08/17 09:53, Yubin Ruan wrote:
> 2017-08-01 15:44 GMT+08:00 Thiago Macieira <thiago at kde.org>:
>> On terça-feira, 1 de agosto de 2017 00:34:05 PDT Yubin Ruan wrote:
>>> 2017-08-01 15:23 GMT+08:00 Thiago Macieira <thiago at kde.org>:
>>>> On terça-feira, 1 de agosto de 2017 00:11:33 PDT Yubin Ruan wrote:
>>>>> Hi,
>>>>> I am wondering whether anyone can offer me a simple workable
>>>>> client-server example. I have finished reading the tutorials at dbus's
>>>>> website but cannot figure out how to use dbus in practice. All the
>>>>> examples there are too abstract and only describe interface and design
>>>>> pattern behind it.
>>>>>
>>>>> So it would be more easier for me to get start if anyone in this list
>>>>> can offer me an client-server example where client send messages to
>>>>> server using dbus as a communication tunnel.
>>>>
>>>> Do you have a preference for a D-Bus binding?
>>>
>>> Sorry I should have mentioned that a C/C++ binding would be
>>> preferable. But if you have examples in other bindings it is also OK.
>>
>> Any C++ binding will work? Then I can give you examples using QtDBus.
> 
> Yes. But please offer a workable example. Many thanks!

I learnt a lot by diving into the QtDBus API docs and examples there.
Pluss I tried the dbus-c++ library (which seems no longer maintained).

For my own C++ implementation requirements, I actually ended up wrapping
gdbus (from glib2) into a C++ wrapping.  The reason is that the Qt
versions officially supported on the platforms I was aiming at have very
limited C++11 support.  Qt is in many ways a reasonable framework to
work with.  But it drags along a lot of solutions to issues which have
been resolved in the C++11 and C++14 specs.  As I have a strict minimum
C++11 implementation requirement from my project lead, Qt was less ideal.

The D-Bus documentation is truly scarce.  The QtDBus docs are really
good though, and the glib2/gdbus docs are reasonable.

But I advice you to get a reasonable grip how D-Bus works first through
a simpler API (such as Python or perhaps Perl) and then look at how to
do this in C++.

And by all means, get to know both the qdbus and gdbus command line
tools.  They can be helpful when trying to get a confirmation you the
D-Bus service got implemented how you wanted it.  Other nice tools are
d-feet, qdbusviewer and dbus-send.


-- 
kind regards,

David Sommerseth


More information about the dbus mailing list