diff options
author | Stian Skjelstad <stian@nixia.no> | 2009-09-18 14:01:00 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2009-09-18 14:03:50 -0400 |
commit | 980b46870aa0e44a04ad1191d7af1d0601577501 (patch) | |
tree | ffe94d7b54c9970d8aa21991a66bb5a0865bb24c | |
parent | c993494ad463ffe55b8603e58aa5ecb6dd731144 (diff) | |
download | dbus-glib-980b46870aa0e44a04ad1191d7af1d0601577501.tar.gz |
Bug 19623 - Add dbus_g_bus_get_private
Useful for cases where you have to get a private connection, among
them to work around threading issues.
Signed-off-by: Colin Walters <walters@verbum.org>
-rw-r--r-- | dbus/dbus-glib.h | 3 | ||||
-rw-r--r-- | dbus/dbus-gmain.c | 41 |
2 files changed, 44 insertions, 0 deletions
diff --git a/dbus/dbus-glib.h b/dbus/dbus-glib.h index 8f2ed28..d96989c 100644 --- a/dbus/dbus-glib.h +++ b/dbus/dbus-glib.h @@ -105,6 +105,9 @@ DBusGConnection* dbus_g_connection_open (const gchar *address, GError **error); DBusGConnection* dbus_g_bus_get (DBusBusType type, GError **error); +DBusGConnection* dbus_g_bus_get_private (DBusBusType type, + GError **error); + typedef struct _DBusGObjectInfo DBusGObjectInfo; typedef struct _DBusGMethodInfo DBusGMethodInfo; diff --git a/dbus/dbus-gmain.c b/dbus/dbus-gmain.c index 6a64601..ca66f73 100644 --- a/dbus/dbus-gmain.c +++ b/dbus/dbus-gmain.c @@ -765,6 +765,47 @@ dbus_g_bus_get (DBusBusType type, return DBUS_G_CONNECTION_FROM_CONNECTION (connection); } +/** + * dbus_g_bus_get_private: + * @type: bus type + * @error: address where an error can be returned. + * + * Returns a connection to the given bus. The connection will be a private + * non-shared connection and should be closed when usage is complete. + * + * Internally this function calls dbus_bus_get_private() then calls + * dbus_connection_setup_with_g_main() on the result; see the documentation + * of the former function for more information on private connections. + * + * Returns: a DBusConnection + */ +DBusGConnection* +dbus_g_bus_get_private (DBusBusType type, + GError **error) +{ + DBusConnection *connection; + DBusError derror; + + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + + _dbus_g_value_types_init (); + + dbus_error_init (&derror); + + connection = dbus_bus_get_private (type, &derror); + if (connection == NULL) + { + dbus_set_g_error (error, &derror); + dbus_error_free (&derror); + return NULL; + } + + /* does nothing if it's already been done */ + dbus_connection_setup_with_g_main (connection, NULL); + + return DBUS_G_CONNECTION_FROM_CONNECTION (connection); +} + /** @} */ /* end of public API */ #ifdef DBUS_BUILD_TESTS |