My C++ wrapper for D-BUS

David Eriksson twogood at users.sourceforge.net
Tue Aug 9 22:06:01 EST 2005


Hi,

As Paul Durante were also doing his own C++ bindings for D-BUS instead
of using the Freedesktop-sponsored C++ bindings [1], I might just as
well confess I was hit my by the NIH syndrome [2] and also wrote a C++
wrapper for the D-BUS API. It's not finished yet but it contains enough
for my needs at the moment.

Comments are welcome!


Example code for a method call:

  dbus::Connection_ptr dbus_connection(
      dbus::Bus::Get(DBUS_BUS_SYSTEM));

  dbus::Message_ptr method_call(
      dbus::Message::NewMethodCall(
        "service",
        "path",
        "interface",
        "method")
      );

  DBusMessageIter iter;
  method_call->IterInit(iter);

  // [Adding parameters to iterator]

  dbus::Message_ptr reply(
      dbus_connection->SendWithReplyAndBlock(method_call)
      );

  DBusMessageIter reply_iter;
  reply->IterInit(reply_iter);

  // [Getting return values from reply iterator]



Implementation notes:

- Written for D-BUS 0.23 (Using D-BUS 0.23.4 on Ubuntu 5.04)

- Any C++ users who for various reasons are not using Boost [3] might
not like my bindings because I depend on boost::shared_ptr.

- Many API calls are not wrapped; most notably iterators. 

- I plan to write an iostream-like wrapper for iterators

- Poorly documented

- No unit tests


View the source code at the URLs below. (Remove .html from the URLs
above to get the plain text files.)

http://www.2good.nu/blandat/dbus-wrapper.hh.html
http://www.2good.nu/blandat/dbus-wrapper.cc.html
http://www.2good.nu/blandat/dbus-filter.hh.html
http://www.2good.nu/blandat/dbus-object.hh.html

If anyone wants to use my C++ wrapper, I hereby release it according to
the the MIT license [4]. 


[1] http://freedesktop.org/wiki/Software_2fdbus_2dcpp

[2] http://en.wikipedia.org/wiki/Not_Invented_Here

[3] http://boost.org

[4] http://opensource.org/licenses/mit-license.php

-- 
Regards,
               -\- David Eriksson -/-

        SynCE - http://synce.sourceforge.net
      ScummVM - http://scummvm.sourceforge.net
     Desquirr - http://desquirr.sourceforge.net



More information about the dbus mailing list