I’ve started playing around with DBus a little. It’s somewhat cute, I was able to quickly write a script that monitors my wireless network connection going up and down, and after some searching for useful documentation, I’m now able to tell gaim to disconnect when my wireless goes down and reconnect when it comes back. All with just a few lines of Python.

While searching for some docs on the Gaim API, I stumbled upon the Skype DBus API. But it’s crap. Evil stuff. (And not working, from what I can tell; I read somewhere they’re using a totally outdated DBus version, and to use it you have to downgrade and break lots of other stuff).

They’ve totally bastardized DBus. First of all, the trace of a DBus API I’ve found is on a system level, not a user/session level. It should be per-session; you especially don’t want others to mess with your Skype.

Instead of offering an API with sane methods to invoke, they offer a single method, called “Invoke”, and a single callback called “Notify”. Ouch. With these methods you’re expected to do a ascii protocol something like this:

-> NAME UltimateProgram
<- OK
-> PROTOCOL 5
<- PROTOCOL 5

Note that the name choice is up to the connecting application; so you can cloak yourself as a different application; it will be displayed to the user when asking for confirmation, apparently.

Another example how crappy Skype dbus is: their “dbus example in C” links to the Python example and the other way round. The C example consists of 2.4 MB precompiled example and about 100k source code (the example of course is a graphical client).

For comparison, this is a complete example on how to reconnect all your Gaim accounts via python-dbus:

import gobject, time, dbus, dbus.glib
# get DBus inteface
sesbus = dbus.SessionBus()
gaim_obj = sesbus.get_object("net.sf.gaim.GaimService", "/net/sf/gaim/GaimObject")
gaim = dbus.Interface(gaim_obj, "net.sf.gaim.GaimInterface")

for account in gaim.GaimAccountsGetAllActive():
  gaim.GaimAccountDisconnect(account)
time.sleep(5)
for account in gaim.GaimAccountsGetAllActive():
  gaim.GaimAccountConnect(account)