diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-04-16 16:47:59 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-04-17 14:22:30 +0100 |
commit | 2d8622ea9cc7a45aefb47b147f8366e51b0a4f3e (patch) | |
tree | 9f30c3cc6f83d7b2dbf84cd46b0d39116ce25494 | |
parent | ede9973afacf9c1f08dc3e597a54fb05ab82b7b2 (diff) |
Communicate registrations to TpDBusPropertiesMixin via an internal header
We can't keep using _tp_dbus_object_get_object_path() if the
TpDBusPropertiesMixin moves to the -dbus library.
-rw-r--r-- | telepathy-glib/Makefile.am | 1 | ||||
-rw-r--r-- | telepathy-glib/dbus-internal.h | 3 | ||||
-rw-r--r-- | telepathy-glib/dbus-properties-mixin.c | 12 | ||||
-rw-r--r-- | telepathy-glib/dbus.c | 71 | ||||
-rw-r--r-- | telepathy-glib/object-registration-internal.h | 50 |
5 files changed, 70 insertions, 67 deletions
diff --git a/telepathy-glib/Makefile.am b/telepathy-glib/Makefile.am index 4a5cc36ad..d9d80e2cd 100644 --- a/telepathy-glib/Makefile.am +++ b/telepathy-glib/Makefile.am @@ -309,6 +309,7 @@ libtelepathy_glib_main_internal_handwritten_source = \ message-mixin.c \ observe-channel-context-internal.h \ observe-channel-context.c \ + object-registration-internal.h \ presence-mixin.c \ protocol.c \ protocol-internal.h \ diff --git a/telepathy-glib/dbus-internal.h b/telepathy-glib/dbus-internal.h index ad0405439..114c55d39 100644 --- a/telepathy-glib/dbus-internal.h +++ b/telepathy-glib/dbus-internal.h @@ -31,9 +31,6 @@ gboolean _tp_dbus_connection_get_name_owner (GDBusConnection *dbus_connection, gint timeout_ms, const gchar *well_known_name, gchar **unique_name, GError **error); -GDBusConnection *_tp_dbus_object_get_connection (gpointer object); -const gchar *_tp_dbus_object_get_object_path (gpointer object); - GStrv _tp_g_dbus_object_dup_interface_names (GDBusObject *obj, const gchar *skip_class, const gchar *skip_type); diff --git a/telepathy-glib/dbus-properties-mixin.c b/telepathy-glib/dbus-properties-mixin.c index 3723b47b6..24ee6ae72 100644 --- a/telepathy-glib/dbus-properties-mixin.c +++ b/telepathy-glib/dbus-properties-mixin.c @@ -33,6 +33,7 @@ #include <telepathy-glib/core-dbus-properties-mixin-internal.h> #include "telepathy-glib/dbus-internal.h" #include "telepathy-glib/debug-internal.h" +#include <telepathy-glib/object-registration-internal.h> /** * SECTION:dbus-properties-mixin @@ -937,7 +938,7 @@ tp_dbus_properties_mixin_emit_properties_changed ( GVariantDict changed_properties; GPtrArray *invalidated_properties; const gchar * const *prop_name; - GDBusConnection *dbus_connection; + TpDBusConnectionRegistration *r; g_return_if_fail (interface_name != NULL); iface_impl = _tp_dbus_properties_mixin_find_iface_impl (object, @@ -1002,12 +1003,13 @@ tp_dbus_properties_mixin_emit_properties_changed ( g_ptr_array_add (invalidated_properties, NULL); - dbus_connection = _tp_dbus_object_get_connection (object); - if (dbus_connection != NULL) + r = g_object_get_qdata (object, _tp_dbus_connection_registration_quark ()); + + if (r != NULL && r->conn != NULL) { - g_dbus_connection_emit_signal (dbus_connection, + g_dbus_connection_emit_signal (r->conn, NULL, /* broadcast */ - _tp_dbus_object_get_object_path (object), + r->object_path, "org.freedesktop.DBus.Properties", "PropertiesChanged", /* consume floating ref */ diff --git a/telepathy-glib/dbus.c b/telepathy-glib/dbus.c index 7310afbfa..3026ec58a 100644 --- a/telepathy-glib/dbus.c +++ b/telepathy-glib/dbus.c @@ -40,6 +40,7 @@ #include <telepathy-glib/errors.h> #include <telepathy-glib/gtypes.h> #include <telepathy-glib/interfaces.h> +#include <telepathy-glib/object-registration-internal.h> #include <telepathy-glib/proxy.h> #include <telepathy-glib/sliced-gvalue.h> #include <telepathy-glib/svc-generic.h> @@ -655,38 +656,12 @@ tp_dbus_connection_release_name (GDBusConnection *dbus_connection, } } -typedef struct _Registration Registration; - -struct _Registration { - /* (transfer full) */ - GDBusConnection *conn; - /* (transfer full) */ - gchar *object_path; - /* (transfer full) */ - GList *skeletons; - /* (transfer none), do not dereference */ - gpointer object; -}; - -static GQuark -registration_quark (void) -{ - static GQuark q = 0; - - if (G_UNLIKELY (q == 0)) - { - q = g_quark_from_static_string ("tp_dbus_connection_register_object"); - } - - return q; -} - static void tp_dbus_connection_registration_iface_added_cb (GDBusObject *object, GDBusInterface *iface, gpointer user_data) { - Registration *r = user_data; + TpDBusConnectionRegistration *r = user_data; GError *error = NULL; if (!G_IS_DBUS_INTERFACE_SKELETON (iface)) @@ -718,7 +693,7 @@ tp_dbus_connection_registration_iface_removed_cb (GDBusObject *object, GDBusInterface *iface, gpointer user_data) { - Registration *r = user_data; + TpDBusConnectionRegistration *r = user_data; GList *iface_link; iface_link = g_list_find (r->skeletons, iface); @@ -734,7 +709,7 @@ tp_dbus_connection_registration_iface_removed_cb (GDBusObject *object, static void tp_dbus_connection_registration_free (gpointer p) { - Registration *r = p; + TpDBusConnectionRegistration *r = p; GList *iter; DEBUG ("%s (r=%p)", r->object_path, r); @@ -763,7 +738,7 @@ tp_dbus_connection_registration_free (gpointer p) tp_dbus_connection_registration_iface_removed_cb, r); } - g_slice_free (Registration, r); + g_slice_free (TpDBusConnectionRegistration, r); } /** @@ -925,7 +900,7 @@ tp_dbus_connection_try_register_object (GDBusConnection *dbus_connection, GError **error) { GDBusConnection *conn; - Registration *r; + TpDBusConnectionRegistration *r; gboolean ret = FALSE; GHashTable *skeletons = NULL; GHashTableIter hash_iter; @@ -945,7 +920,7 @@ tp_dbus_connection_try_register_object (GDBusConnection *dbus_connection, !G_IS_DBUS_OBJECT (object), FALSE); conn = dbus_connection; - r = g_slice_new0 (Registration); + r = g_slice_new0 (TpDBusConnectionRegistration); r->conn = g_object_ref (conn); r->object = object; r->object_path = g_strdup (object_path); @@ -954,7 +929,8 @@ tp_dbus_connection_try_register_object (GDBusConnection *dbus_connection, DEBUG ("%p (r=%p) on %s (%p) at %s", object, r, g_dbus_connection_get_unique_name (conn), conn, object_path); - if (!g_object_replace_qdata (object, registration_quark (), + if (!g_object_replace_qdata (object, + _tp_dbus_connection_registration_quark (), NULL, /* if old value is NULL... */ r, /* ... replace it with r... */ tp_dbus_connection_registration_free, /* ... with this free-function... */ @@ -968,7 +944,8 @@ tp_dbus_connection_try_register_object (GDBusConnection *dbus_connection, * registrations on different connections or at different object * paths, though, in the hope that nobody actually does that. */ - r = g_object_get_qdata (object, registration_quark ()); + r = g_object_get_qdata (object, + _tp_dbus_connection_registration_quark ()); if (!tp_strdiff (r->object_path, object_path) && r->conn == conn) @@ -1062,31 +1039,7 @@ tp_dbus_connection_unregister_object (GDBusConnection *dbus_connection, /* The free-function for the qdata, tp_dbus_connection_registration_free(), * will automatically unregister the object (if registered) */ - g_object_set_qdata (object, registration_quark (), NULL); -} - -GDBusConnection * -_tp_dbus_object_get_connection (gpointer object) -{ - Registration *r; - - r = g_object_get_qdata (object, registration_quark ()); - if (r != NULL) - return r->conn; - - return NULL; -} - -const gchar * -_tp_dbus_object_get_object_path (gpointer object) -{ - Registration *r; - - r = g_object_get_qdata (object, registration_quark ()); - if (r != NULL) - return r->object_path; - - return NULL; + g_object_set_qdata (object, _tp_dbus_connection_registration_quark (), NULL); } GStrv diff --git a/telepathy-glib/object-registration-internal.h b/telepathy-glib/object-registration-internal.h new file mode 100644 index 000000000..c30153982 --- /dev/null +++ b/telepathy-glib/object-registration-internal.h @@ -0,0 +1,50 @@ +/*<private_header>*/ +/* + * Copyright © 2014 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* Not bothering with an include-once guard here because this is very much + * internal. + * + * The TpDBusPropertiesMixin and tp_dbus_connection_try_register_object() + * both use this. Please try not to use it elsewhere. */ + +typedef struct _TpDBusConnectionRegistration TpDBusConnectionRegistration; + +struct _TpDBusConnectionRegistration { + /* (transfer full) */ + GDBusConnection *conn; + /* (transfer full) */ + gchar *object_path; + /* (transfer full) */ + GList *skeletons; + /* (transfer none), do not dereference */ + gpointer object; +}; + +static GQuark +_tp_dbus_connection_registration_quark (void) +{ + static GQuark q = 0; + + if (G_UNLIKELY (q == 0)) + { + q = g_quark_from_static_string ("tp_dbus_connection_register_object"); + } + + return q; +} |