[next] telepathy-glib: TpContactsMixin: use tp_handle_ensure_async() in GetContactByID

Xavier Claessens xclaesse at kemper.freedesktop.org
Fri Jun 29 06:37:51 PDT 2012


Module: telepathy-glib
Branch: next
Commit: 78b16657eb08322a36816b05f60d68dc6bb2f754
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=78b16657eb08322a36816b05f60d68dc6bb2f754

Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date:   Tue May 29 13:27:21 2012 +0200

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 files changed, 51 insertions(+), 20 deletions(-)

diff --git a/telepathy-glib/contacts-mixin.c b/telepathy-glib/contacts-mixin.c
index 9b95803..327ad8e 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);
 }
 
 /**



More information about the telepathy-commits mailing list