From bbef196c3424e5cf9fe799c7135d0b6441ac8098 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 5 Mar 2012 14:25:35 +0000 Subject: [PATCH 3/4] tp_list_connection_managers: use tp_proxy_prepare_async We're about to deprecate call_when_ready, so let's not call it. --- telepathy-glib/connection-manager.c | 40 ++++++++++++++++++++++++++-------- 1 files changed, 30 insertions(+), 10 deletions(-) diff --git a/telepathy-glib/connection-manager.c b/telepathy-glib/connection-manager.c index 03b21b4..c2ae7b3 100644 --- a/telepathy-glib/connection-manager.c +++ b/telepathy-glib/connection-manager.c @@ -1671,11 +1671,13 @@ typedef struct TpConnectionManagerListCb callback; gpointer user_data; GDestroyNotify destroy; + gpointer weak_object; TpProxyPendingCall *pending_call; size_t base_len; gsize refcount; gsize cms_to_ready; unsigned getting_names:1; + unsigned had_weak_object:1; } _ListContext; static void @@ -1686,6 +1688,10 @@ list_context_unref (_ListContext *list_context) if (--list_context->refcount > 0) return; + if (list_context->weak_object != NULL) + g_object_remove_weak_pointer (list_context->weak_object, + &list_context->weak_object); + if (list_context->destroy != NULL) list_context->destroy (list_context->user_data); @@ -1707,14 +1713,13 @@ list_context_unref (_ListContext *list_context) } static void -tp_list_connection_managers_cm_ready (TpConnectionManager *cm, - const GError *error, - gpointer user_data, - GObject *weak_object) +tp_list_connection_managers_cm_prepared (GObject *source G_GNUC_UNUSED, + GAsyncResult *result G_GNUC_UNUSED, + gpointer user_data) { _ListContext *list_context = user_data; - /* ignore errors here - all we guarantee is that the CM is ready + /* ignore the result here - all we guarantee is that the CM is ready * *if possible* */ if ((--list_context->cms_to_ready) == 0) @@ -1727,10 +1732,16 @@ tp_list_connection_managers_cm_ready (TpConnectionManager *cm, g_ptr_array_add (list_context->arr, NULL); cms = (TpConnectionManager **) list_context->arr->pdata; - list_context->callback (cms, n_cms, NULL, list_context->user_data, - weak_object); + if (!list_context->had_weak_object || list_context->weak_object != NULL) + { + list_context->callback (cms, n_cms, NULL, list_context->user_data, + list_context->weak_object); + } + list_context->callback = NULL; } + + list_context_unref (list_context); } static void @@ -1743,6 +1754,9 @@ tp_list_connection_managers_got_names (TpDBusDaemon *bus_daemon, _ListContext *list_context = user_data; const gchar * const *name_iter; + /* The TpProxy APIs we use guarantee this */ + g_assert (weak_object != NULL || !list_context->had_weak_object); + if (error != NULL) { list_context->callback (NULL, 0, error, list_context->user_data, @@ -1788,9 +1802,8 @@ tp_list_connection_managers_got_names (TpDBusDaemon *bus_daemon, { TpConnectionManager *cm = g_ptr_array_index (list_context->arr, i); - tp_connection_manager_call_when_ready (cm, - tp_list_connection_managers_cm_ready, list_context, - (GDestroyNotify) list_context_unref, weak_object); + tp_proxy_prepare_async (cm, NULL, + tp_list_connection_managers_cm_prepared, list_context); } } else @@ -1846,6 +1859,13 @@ tp_list_connection_managers (TpDBusDaemon *bus_daemon, list_context->arr = NULL; list_context->cms_to_ready = 0; + if (weak_object != NULL) + { + list_context->weak_object = weak_object; + list_context->had_weak_object = TRUE; + g_object_add_weak_pointer (weak_object, &list_context->weak_object); + } + tp_dbus_daemon_list_activatable_names (bus_daemon, 2000, tp_list_connection_managers_got_names, list_context, (GDestroyNotify) list_context_unref, weak_object); -- 1.7.9.1