«

»

Nov 28

The dbus-cpp Library, introduction

While working on a bluetooth based embedded device, I needed to deal with the somehow infamous dbus.

DBus and Bluez5 have a very steep learning curve, and if you are don't have access to either Qt framework or glib framework, you have indeed a problem.

Glib are very complex C libraries that mimick some of the built-in feature of the C++ language, while on the other hand, Qt are very vast and sometime a big overkill. The stunning news is that it seems there aren't many options if you need a C++ only lightweight solution.

It is not true, indeed. Somehow well hidden in the creases of the web, I found an awesome alternative that is at the same time elegant, very well designed, modern and lightweight. The library is named DBUS-CPP.

Be warned: there are two other c++ libraries, one called dbus-c++ and another with the same name. But both are old and unmaintained. You could also try to use the low-level api, through libdbus, but the documentation itself discourage from using it. Before finding the actual solution, I spent some week trying to implement my code this way, and believe in me, even the most obvious operations are long, complex, repetitive, boring and error prone. 

The dbus-cpp library I want to introduce is homed on launchpad, at this url: https://launchpad.net/dbus-cpp

The library is written in pure c++11, it is mostly based on template metaprogramming and for this reason his learning curve is not gentle. But once the basic ideas behind the library are clear, you can appreciate his elegance. Unfortunately there is no documentation and no tutorials, but the developers make great use of unit testing, so there are a lot of test code that can be studied. There are 3 or 4 examples, but they only provide example on how to access a dbus service as client, not on how to implement dbus services.

This post is the first of a series. They are the result of my personal studies and applications on the embedded project. My idea is to fill the gap and provide people some ideas on how to start. dbus-cpp is difficult to find on the web, but the efficiency that can be reached with it makes me think it deserve much more visibility. 

I want to thank the development team leader, Thomas Voß, and his team, for the library and for the time he dedicated me to answer my questions and clarify my doubts. I hope these articles could be a significant contribution.

Later note: linux distributions usually provide earlier version of dbus-cpp. For example, Ubuntu 14.04 LTE provides dbus-cpp 2.0. The latest version available from the sources are 5.0. I strongly suggest to download the latest version from the source repository (they use bazaar) and compile it. They use CMake as a building tool, so compiling and installing is very easy. On the other hand, Ubuntu 15.10 provides the latest version.

 

Permanent link to this article: http://www.studiofuga.com/2015/11/28/the-dbus-cpp-library-introduction/

4 comments

Skip to comment form

  1. Kiran

    It would be really helpful if you could go on with this series – especially the dbus server part.

  2. Kiran

    To add, the dbus-c++ library also appears to have commits recently in late 2016. Confused on which one to choose.

    [1] https://github.com/andreas-volz/dbus-cplusplus/commits/master
    [2] http://bazaar.launchpad.net/~phablet-team/dbus-cpp/trunk/changes/103?start_revid=103

  3. Kiran

    Personally, I found class based dbus-c++ easier to learn and use. Templates are hard.

  4. f.fuga

    Hi Kiran, thank you for your comments!
    At the moment I have very few moments to update the blog. I would be glad to share some interesting experience with dbus-c++, I wrote some “proof of concept” snippet, but due to many bugs in bluez code when dealing with Low Energy, my customer decided to switch to another bt technology (a serial dongle) and I have abandoned the code for this library.
    So I am not sure I’ll be able to update the series soon. Perhaps I’ll post some code.
    About the version to use, I personally used that one on launchpad. But OTOH, I found some bug, provided the patch to the upstream, but it wasn’t yet published (this happened about one year ago).
    I agree with you that templatized code is much harder to understand, but it also deals much better with types checking and once you have a working skeleton, it is much easier to extend and maintain. I personally tried many different libraries , and frankly dbus-cpp convinced me. It misses documentation and tutorials, and this is his biggest limit. The authors know this (we exchanged some mail one year ago) and this serie should have helped for this purpose, but… you know. 🙂

    Thank you again for your visit.

    Federico

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

%d bloggers like this: