GLib DBus vs Python DBus

I’ve been experimenting with DBus a bit lately for some side projects im doing (more on that soon). Part of the project involves spawning a service via dbus. In python this is trivial and easily discoverable with a google query or two:

import dbus
bus = dbus.SessionBus()
bus.start_service_by_name('org.gnome.Rygel1') # org.gnome.Rygel1 = service name

Ridiculously easy, right? In C using the glib dbus library things are much more difficult. A bit of googling yielded almost nothing when searching for “start service by name c glib” or variants thereof. So I did the evil thing, I checked out the python source. start_service_by_name is turns out, is a wrapper to a normal proxy call to the org.freedesktop.dbus interface function StartServiceByName:

return (True, self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
'su', (bus_name, flags)))

Alright… so now how do we do this in C? We could fiddle with dbus_g_proxy_call for a while, or find out that Maemo actually gives us the answer.

DBusGConnection *connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);

DBusGProxy *proxy = dbus_g_proxy_new_for_name (connection,
int result;
dbus_g_proxy_call (proxy, "StartServiceByName", &error,
G_TYPE_UINT, &result,

Simple, right?

Leave a Reply

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