July 8th, 2006

  • evan

dbus activation, bmpx

D-BUS is an emerging standard negotiated by the Gnome and KDE people to allow interprocess calls. It's based on KDE's DCOP but it's used by a lot of recent Gnome software as well, to great effect. For example, Growl on OS X is mirrored by Galago on Gnome.

One of the interesting things about DBUS that I didn't appreciate when I first read about it is that it supports service "activation". For example, I can send a message to a music-playing service (services are identified by well-known and namespaced strings), and if the daemon behind the service isn't running, DBUS will bring it up and then send it the message. (If you're on a recent Gnome machine, you probably have a /usr/share/dbus-1/services/notification-daemon.service that provides org.freedesktop.Notifications.)

You can prod that service to life by sending a message its way:
% dbus-send --session --dest=org.freedesktop.Notifications --print-reply / org.freedesktop.DBus.Introspectable.Introspect
but from there, you're better off using dbus-viewer, which is a GUI frontend to the introspection APIs.

I mentioned a music-playing service: the one I've discovered is BMPx, which is a rewrite of beep-media-player (itself a fork of XMMS). It's a bit excessively complicated, as music players tend to be (it's an mp3 player with skins -- wait, no, it's a media player -- wait, no, it's a media streaming framework -- wait, no, it's a generalized media library management system hooked up to a framework -- wait, no it's a media-playing daemon ...). But it does have a DBUS interface as well, with the sorts of sorts of calls you'd expect.
  • evan

dbus bindings for haskell, api design

That last post was intended as background for announcing my preliminary Haskell DBUS bindings.

The code is here, and the API docs are here. It's not much, but it's enough to make blocking calls to BMPx's volume-control APIs.

Reading the DBUS API docs is very interesting, because it reminds me of how much effort the Cairo folks have put into their API. It's very difficult (I think especially difficult when you're intimate with the code) to figure out the simplest point to delineate library-internal from library-external, and for every function they've added to Cairo there's been a discussion of whether that's the right place for it, what effect it'll have on language bindings, etc., etc. The DBUS docs, by contrast, feel pretty overwhelming and feel somewhat incoherent.

With each project like this I learn something more, which is always the point. The two goals of this one are understanding DBUS better and (obviously) Haskell. So far the most noteworthy piece is how dynamic exceptions work, which I've long wondered about and still don't quite understand. In O'Caml, exceptions are specially handled by the langauge (with an exn keyword, as I recall), but in Haskell (of course) it's just some functions and some fancy typing. I'd explain more but I doubt there's even one reader of this who cares. :P