diff options
author | Ross Burton <ross@burtonini.com> | 2007-03-30 17:54:58 +0100 |
---|---|---|
committer | Ross Burton <ross@burtonini.com> | 2007-03-30 17:54:58 +0100 |
commit | 25f056826336d4385b5488706f0f1ecc0843bf2f (patch) | |
tree | 3e29e4e5a888719308415735d3f71e8f97f09dc7 | |
parent | 0c46ca1a20eb8ba676ea2f1e829d039d5e3c383d (diff) |
Add dbus_connection_get_g_connection.
Add dbus_connection_get_g_connection, which is useful when you have a
DBusConnection which was originally a DBusGConnection, and want it back
again.
-rw-r--r-- | dbus/dbus-glib-lowlevel.h | 1 | ||||
-rw-r--r-- | dbus/dbus-glib.c | 24 | ||||
-rw-r--r-- | dbus/dbus-gmain.c | 12 |
3 files changed, 31 insertions, 6 deletions
diff --git a/dbus/dbus-glib-lowlevel.h b/dbus/dbus-glib-lowlevel.h index cb015cc..c996821 100644 --- a/dbus/dbus-glib-lowlevel.h +++ b/dbus/dbus-glib-lowlevel.h @@ -49,6 +49,7 @@ void dbus_g_proxy_send (DBusGProxy *proxy, dbus_uint32_t *client_serial); DBusConnection* dbus_g_connection_get_connection (DBusGConnection *gconnection); +DBusGConnection* dbus_connection_get_g_connection (DBusConnection *connection); DBusMessage* dbus_g_message_get_message (DBusGMessage *gmessage); /* dbus_g_pending_call_get_pending_call() deliberately skipped for now; diff --git a/dbus/dbus-glib.c b/dbus/dbus-glib.c index 4b467d3..e8c715e 100644 --- a/dbus/dbus-glib.c +++ b/dbus/dbus-glib.c @@ -305,9 +305,33 @@ dbus_g_message_get_g_type (void) DBusConnection* dbus_g_connection_get_connection (DBusGConnection *gconnection) { + g_return_val_if_fail (gconnection, NULL); return DBUS_CONNECTION_FROM_G_CONNECTION (gconnection); } +extern dbus_int32_t _dbus_gmain_connection_slot; + +/** + * dbus_connection_get_g_connection: + * @connection: a #DBusConnection + * + * Get the #DBusGConnection corresponding to this #DBusConnection. This only + * makes sense if the #DBusConnection was originally a #DBusGConnection that was + * registered with the GLib main loop. The return value does not have its + * refcount incremented. + * + * Returns: #DBusGConnection + */ +DBusGConnection* +dbus_connection_get_g_connection (DBusConnection *connection) +{ + g_return_val_if_fail (connection, NULL); + g_return_val_if_fail (dbus_connection_get_data (connection, _dbus_gmain_connection_slot), NULL); + + return DBUS_G_CONNECTION_FROM_CONNECTION (connection); +} + + /** * dbus_g_message_get_message: * @gmessage: a #DBusGMessage diff --git a/dbus/dbus-gmain.c b/dbus/dbus-gmain.c index 40f3314..3271b9b 100644 --- a/dbus/dbus-gmain.c +++ b/dbus/dbus-gmain.c @@ -129,7 +129,7 @@ typedef struct DBusTimeout *timeout; } TimeoutHandler; -static dbus_int32_t connection_slot = -1; +dbus_int32_t _dbus_gmain_connection_slot = -1; static dbus_int32_t server_slot = -1; static ConnectionSetup* @@ -560,8 +560,8 @@ dbus_connection_setup_with_g_main (DBusConnection *connection, /* FIXME we never free the slot, so its refcount just keeps growing, * which is kind of broken. */ - dbus_connection_allocate_data_slot (&connection_slot); - if (connection_slot < 0) + dbus_connection_allocate_data_slot (&_dbus_gmain_connection_slot); + if (_dbus_gmain_connection_slot < 0) goto nomem; if (context == NULL) @@ -569,7 +569,7 @@ dbus_connection_setup_with_g_main (DBusConnection *connection, cs = NULL; - old_setup = dbus_connection_get_data (connection, connection_slot); + old_setup = dbus_connection_get_data (connection, _dbus_gmain_connection_slot); if (old_setup != NULL) { if (old_setup->context == context) @@ -578,14 +578,14 @@ dbus_connection_setup_with_g_main (DBusConnection *connection, cs = connection_setup_new_from_old (context, old_setup); /* Nuke the old setup */ - dbus_connection_set_data (connection, connection_slot, NULL, NULL); + dbus_connection_set_data (connection, _dbus_gmain_connection_slot, NULL, NULL); old_setup = NULL; } if (cs == NULL) cs = connection_setup_new (context, connection); - if (!dbus_connection_set_data (connection, connection_slot, cs, + if (!dbus_connection_set_data (connection, _dbus_gmain_connection_slot, cs, (DBusFreeFunction)connection_setup_free)) goto nomem; |