summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2010-01-27 13:01:29 -0500
committerColin Walters <walters@verbum.org>2010-01-27 13:46:40 -0500
commitf1c3f7bf585d6010c84491372b0a6f0ae3b1432a (patch)
tree317f57ca9917f4044ff83692d00b02c3a90024e5
parent87c645ed17d6fef350e8c26e322ecde566a27d42 (diff)
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.
-rw-r--r--dbus/dbus-glib.h1
-rw-r--r--dbus/dbus-gmain.c4
-rw-r--r--test/core/test-dbus-glib.c21
3 files changed, 25 insertions, 1 deletions
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));