From f9056cf5fe5ce67ad0b530c9af1977860231dde2 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Sun, 7 Oct 2012 11:09:10 -0500 Subject: Add dbus_g_connection_open_private() for private D-Bus sockets Like dbus_g_connection_open() but for private bus sockets, calling dbus_connection_open_private() and ensuring the dbus-glib types are initialized. Reviewed-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=55730 --- dbus/dbus-glib.h | 3 +++ dbus/dbus-gmain.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/dbus/dbus-glib.h b/dbus/dbus-glib.h index 9a2076f..bd5784c 100644 --- a/dbus/dbus-glib.h +++ b/dbus/dbus-glib.h @@ -103,6 +103,9 @@ void dbus_g_thread_init (void); DBusGConnection* dbus_g_connection_open (const gchar *address, GError **error); +DBusGConnection* dbus_g_connection_open_private (const gchar *address, + GMainContext *context, + GError **error); DBusGConnection* dbus_g_bus_get (DBusBusType type, GError **error); DBusGConnection* dbus_g_bus_get_private (DBusBusType type, diff --git a/dbus/dbus-gmain.c b/dbus/dbus-gmain.c index e6ce52b..dec199d 100644 --- a/dbus/dbus-gmain.c +++ b/dbus/dbus-gmain.c @@ -704,6 +704,49 @@ dbus_g_connection_open (const gchar *address, return DBUS_G_CONNECTION_FROM_CONNECTION (connection); } +/** + * dbus_g_connection_open_private: + * @address: address of the connection to open + * @context: the #GMainContext or %NULL for default context + * @error: address where an error can be returned. + * + * Returns a private connection to the given address; this + * connection does not talk to a bus daemon and thus the caller + * must set up any authentication by itself. If the address + * refers to a message bus, the caller must call dbus_bus_register(). + * + * (Internally, calls dbus_connection_open_private() then calls + * dbus_connection_setup_with_g_main() on the result.) + * + * Returns: (transfer full): a #DBusGConnection + */ +DBusGConnection * +dbus_g_connection_open_private (const gchar *address, + GMainContext *context, + 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_connection_open_private (address, &derror); + if (connection == NULL) + { + dbus_set_g_error (error, &derror); + dbus_error_free (&derror); + return NULL; + } + + dbus_connection_setup_with_g_main (connection, context); + + return DBUS_G_CONNECTION_FROM_CONNECTION (connection); +} + /** * dbus_g_bus_get: * @type: bus type -- cgit v1.2.1