From f1c3f7bf585d6010c84491372b0a6f0ae3b1432a Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 27 Jan 2010 13:01:29 -0500 Subject: Add GMainContext to dbus_g_bus_get_private, add a test case To even sort of work with threads right now, a common workaround is to open a private connection. This patch more explicitly supports creating a private connection, associating it with the GMainContext which will be used for a thread. Also, add a (very simple) test case which just uses a private connection for the default main context. --- dbus/dbus-glib.h | 1 + dbus/dbus-gmain.c | 4 +++- test/core/test-dbus-glib.c | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/dbus/dbus-glib.h b/dbus/dbus-glib.h index 66eebba..d2d2046 100644 --- a/dbus/dbus-glib.h +++ b/dbus/dbus-glib.h @@ -106,6 +106,7 @@ DBusGConnection* dbus_g_connection_open (const gchar *address, DBusGConnection* dbus_g_bus_get (DBusBusType type, GError **error); DBusGConnection* dbus_g_bus_get_private (DBusBusType type, + GMainContext *context, GError **error); diff --git a/dbus/dbus-gmain.c b/dbus/dbus-gmain.c index 25a9742..7496c65 100644 --- a/dbus/dbus-gmain.c +++ b/dbus/dbus-gmain.c @@ -768,6 +768,7 @@ dbus_g_bus_get (DBusBusType type, /** * dbus_g_bus_get_private: * @type: bus type + * @context: Mainloop context to attach to * @error: address where an error can be returned. * * Returns a connection to the given bus. The connection will be a private @@ -781,6 +782,7 @@ dbus_g_bus_get (DBusBusType type, */ DBusGConnection* dbus_g_bus_get_private (DBusBusType type, + GMainContext *context, GError **error) { DBusConnection *connection; @@ -801,7 +803,7 @@ dbus_g_bus_get_private (DBusBusType type, } /* does nothing if it's already been done */ - dbus_connection_setup_with_g_main (connection, NULL); + dbus_connection_setup_with_g_main (connection, context); return DBUS_G_CONNECTION_FROM_CONNECTION (connection); } diff --git a/test/core/test-dbus-glib.c b/test/core/test-dbus-glib.c index 288606f..0e3c12f 100644 --- a/test/core/test-dbus-glib.c +++ b/test/core/test-dbus-glib.c @@ -2123,6 +2123,27 @@ main (int argc, char **argv) lose ("Duplicate proxy wasn'tdestroyed"); g_print ("Proxy and duplicate destroyed successfully\n"); + + g_print ("Beginning private connection tests\n"); + + { + DBusGConnection *privconn = dbus_g_bus_get_private (DBUS_BUS_SESSION, NULL, &error); + + if (privconn == NULL) + lose_gerror ("Failed to open private connection to bus", error); + g_assert (privconn != connection); + + proxy = dbus_g_proxy_new_for_name (privconn, + "org.freedesktop.DBus.GLib.TestService", + "/org/freedesktop/DBus/GLib/Tests/MyTestObject", + "org.freedesktop.DBus.GLib.Tests.MyObject"); + + g_print ("[private connection] Calling (wrapped) do_nothing\n"); + if (!org_freedesktop_DBus_GLib_Tests_MyObject_do_nothing (proxy, &error)) + lose_gerror ("Failed to complete (wrapped) DoNothing call", error); + + g_object_unref (G_OBJECT (proxy)); + } g_object_unref (G_OBJECT (driver)); -- cgit v1.2.3