DBusGConnection attached to two difrent contexts

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Sep 18 06:37:47 PDT 2012

On 18/09/12 14:09, bogdanul2003 wrote:
> executes in another thread

You can't do that with dbus-glib. dbus-glib is not thread-safe and
cannot be used outside your main thread.

> During the execution of a dbus callback method I need to start a 10
> seconds timer to make some aditional checks and after those 10
> seconds I can exit the callback.

You probably want to implement the method asynchronously instead:
receive parameters including a DBusGMethodInvocation, go back to your
main loop, and 10 seconds later (or whenever you find out what the
result should be), call dbus_g_method_return() or
dbus_g_method_return_error(). To do this with the dbus-glib code
generation, you need to mark the method as asynchronous in the input
XML. Have a look at the AsyncIncrement and AsyncThrowError methods in
test/core/test-service-glib.xml, in dbus-glib's source tree.

For methods implemented like this "in real life", see any Telepathy
connection manager. src/conn-aliasing.c in telepathy-gabble, for
instance, implements D-Bus methods like RequestAliases that make network

Alternatively, use GDBus (which *is* thread-safe), and use APIs that use
the GDBusMethodInvocation struct, which is analogous to


More information about the dbus mailing list