From 5bca59a054ca58370b1d5160bb183f13e515618c Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Tue, 29 May 2012 13:27:21 +0200 Subject: [PATCH] TpContactsMixin: use tp_handle_ensure_async() in GetContactByID The identifier is most probably provided by the user, it could need server-side normalization. https://bugs.freedesktop.org/show_bug.cgi?id=50341 --- telepathy-glib/contacts-mixin.c | 71 ++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/telepathy-glib/contacts-mixin.c b/telepathy-glib/contacts-mixin.c index 90cadc6..d7c6b7c 100644 --- a/telepathy-glib/contacts-mixin.c +++ b/telepathy-glib/contacts-mixin.c @@ -379,46 +379,77 @@ tp_contacts_mixin_get_contact_attributes_impl ( g_hash_table_unref (result); } +typedef struct +{ + TpBaseConnection *conn; + GStrv interfaces; + DBusGMethodInvocation *context; +} GetContactByIdData; + static void -tp_contacts_mixin_get_contact_by_id_impl ( - TpSvcConnectionInterfaceContacts *iface, - const gchar *id, - const gchar **interfaces, - DBusGMethodInvocation *context) +ensure_handle_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) { - TpBaseConnection *conn = TP_BASE_CONNECTION (iface); - TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn, - TP_HANDLE_TYPE_CONTACT); + TpHandleRepoIface *contact_repo = (TpHandleRepoIface *) source; + GetContactByIdData *data = user_data; TpHandle handle; GArray *handles; GHashTable *attributes; - GHashTable *result; + GHashTable *ret; GError *error = NULL; - TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (conn, context); - - handle = tp_handle_ensure (contact_repo, id, NULL, &error); + handle = tp_handle_ensure_finish (contact_repo, result, &error); if (handle == 0) { - dbus_g_method_return_error (context, error); + dbus_g_method_return_error (data->context, error); g_clear_error (&error); - return; + goto out; } handles = g_array_new (FALSE, FALSE, sizeof (TpHandle)); g_array_append_val (handles, handle); - attributes = tp_contacts_mixin_get_contact_attributes (G_OBJECT (conn), - handles, interfaces, always_included_interfaces, NULL); + attributes = tp_contacts_mixin_get_contact_attributes (G_OBJECT (data->conn), + handles, (const gchar **) data->interfaces, always_included_interfaces, + NULL); - result = g_hash_table_lookup (attributes, GUINT_TO_POINTER (handle)); - g_assert (result != NULL); + ret = g_hash_table_lookup (attributes, GUINT_TO_POINTER (handle)); + g_assert (ret != NULL); - tp_svc_connection_interface_contacts_return_from_get_contact_by_id (context, - handle, result); + tp_svc_connection_interface_contacts_return_from_get_contact_by_id ( + data->context, handle, ret); g_array_unref (handles); g_hash_table_unref (attributes); + +out: + g_object_unref (data->conn); + g_strfreev (data->interfaces); + g_slice_free (GetContactByIdData, data); +} + +static void +tp_contacts_mixin_get_contact_by_id_impl ( + TpSvcConnectionInterfaceContacts *iface, + const gchar *id, + const gchar **interfaces, + DBusGMethodInvocation *context) +{ + TpBaseConnection *conn = TP_BASE_CONNECTION (iface); + TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn, + TP_HANDLE_TYPE_CONTACT); + GetContactByIdData *data; + + TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (conn, context); + + data = g_slice_new0 (GetContactByIdData); + data->conn = g_object_ref (conn); + data->interfaces = g_strdupv ((gchar **) interfaces); + data->context = context; + + tp_handle_ensure_async (contact_repo, conn, id, NULL, + ensure_handle_cb, data); } /** -- 1.7.9.5