summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.co.uk>2012-05-29 13:27:21 +0200
committerXavier Claessens <xavier.claessens@collabora.co.uk>2012-06-28 13:50:00 +0200
commit78b16657eb08322a36816b05f60d68dc6bb2f754 (patch)
tree3efde878e6ff12d7c56acb5a72c47aa293a4b652
parent6b1bbb146e12426d3bda22b9281c83abbe4cc38a (diff)
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
-rw-r--r--telepathy-glib/contacts-mixin.c71
1 files changed, 51 insertions, 20 deletions
diff --git a/telepathy-glib/contacts-mixin.c b/telepathy-glib/contacts-mixin.c
index 9b95803cd..327ad8e60 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);
}
/**