[next] telepathy-glib: tp_base_connection_dup_contact_attributes: take a TpHandleSet

Simon McVittie smcv at kemper.freedesktop.org
Wed Sep 17 05:39:48 PDT 2014


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

Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date:   Mon May 19 10:08:53 2014 +0200

tp_base_connection_dup_contact_attributes: take a TpHandleSet

It was either that or a GVariant. I took this path as
tp_base_contact_list_dup_contacts() returns a TpHandleSet as well.

https://bugs.freedesktop.org/show_bug.cgi?id=77773

---

 telepathy-glib/base-connection.c   |   51 ++++++++++++++++++------------------
 telepathy-glib/base-connection.h   |    2 +-
 telepathy-glib/base-contact-list.c |    6 ++---
 3 files changed, 28 insertions(+), 31 deletions(-)

diff --git a/telepathy-glib/base-connection.c b/telepathy-glib/base-connection.c
index 1ed86eb..5d58185 100644
--- a/telepathy-glib/base-connection.c
+++ b/telepathy-glib/base-connection.c
@@ -2709,7 +2709,7 @@ static const gchar * const contacts_always_included_interfaces[] = {
 /**
  * tp_base_connection_dup_contact_attributes:
  * @self: A connection instance. The connection must be connected.
- * @handles: (element-type guint32): List of handles to retrieve contacts for.
+ * @handles: List of handles to retrieve contacts for.
  *  Any invalid handles will be dropped from the returned mapping.
  * @interfaces: (allow-none) (array zero-terminated=1) (element-type utf8): an
  *  array of user-requested interfaces
@@ -2729,7 +2729,7 @@ static const gchar * const contacts_always_included_interfaces[] = {
  */
 GVariant *
 tp_base_connection_dup_contact_attributes (TpBaseConnection *self,
-    const GArray *handles,
+    TpHandleSet *handles,
     const gchar * const *interfaces,
     const gchar * const *assumed_interfaces)
 {
@@ -2737,12 +2737,18 @@ tp_base_connection_dup_contact_attributes (TpBaseConnection *self,
   TpHandleRepoIface *contact_repo;
   GVariantBuilder builder;
   guint i;
+  gchar *tmp;
+  TpIntset *intset;
+  TpIntsetFastIter iter;
+  TpHandle h;
 
   g_return_val_if_fail (TP_IS_BASE_CONNECTION (self), NULL);
   g_return_val_if_fail (tp_base_connection_check_connected (self, NULL), NULL);
   g_return_val_if_fail (klass->fill_contact_attributes != NULL, NULL);
 
-  DEBUG ("%u contact(s)", handles->len);
+  tmp = tp_handle_set_dump (handles);
+  DEBUG ("Contacts: %s", tmp);
+  g_free (tmp);
 
   for (i = 0; assumed_interfaces != NULL && assumed_interfaces[i] != NULL; i++)
     {
@@ -2757,9 +2763,12 @@ tp_base_connection_dup_contact_attributes (TpBaseConnection *self,
   contact_repo = tp_base_connection_get_handles (self, TP_ENTITY_TYPE_CONTACT);
   g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ua{sv}}"));
 
-  for (i = 0; i < handles->len; i++)
+  intset = tp_handle_set_peek (handles);
+
+  tp_intset_fast_iter_init (&iter, intset);
+
+  while (tp_intset_fast_iter_next (&iter, &h))
     {
-      TpHandle h = g_array_index (handles, TpHandle, i);
       GVariantDict dict;
       guint j;
 
@@ -2798,32 +2807,22 @@ contacts_get_contact_attributes_impl (_TpGDBusConnection *skeleton,
   const gchar * const *interfaces,
   TpBaseConnection *conn)
 {
-  const TpHandle *c_array;
-  GArray *array;
-  gsize n;
+  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn,
+      TP_ENTITY_TYPE_CONTACT);
+  TpHandleSet *set;
   GVariant *result;
-  /* In principle C does not guarantee that TpHandle (which is an
-   * unsigned int) is exactly 32 bits. In practice, int is 32-bit on
-   * every relevant platform.
-   *
-   * If this assertion fails, the g_variant_get_fixed_array() call
-   * will fail at runtime too, and we'll have to change the code to copy
-   * handles into @array one at a time. */
-  G_STATIC_ASSERT (sizeof (TpHandle) == sizeof (guint32));
 
   _TP_GDBUS_ERROR_IF_NOT_CONNECTED (conn, context);
 
-  c_array = g_variant_get_fixed_array (handles, &n, sizeof (TpHandle));
-  array = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), n);
-  g_array_append_vals (array, c_array, n);
+  set = tp_handle_set_new_from_variant (contact_repo, handles);
 
   result = tp_base_connection_dup_contact_attributes (conn,
-      array, interfaces, contacts_always_included_interfaces);
+      set, interfaces, contacts_always_included_interfaces);
 
   _tp_gdbus_connection_complete_get_contact_attributes (skeleton, context,
       result);
 
-  g_array_unref (array);
+  tp_handle_set_destroy (set);
   g_variant_unref (result);
 
   return TRUE;
@@ -2845,7 +2844,7 @@ ensure_handle_cb (GObject *source,
   GetContactByIdData *data = user_data;
   TpBaseConnection *self = data->conn;
   TpHandle handle;
-  GArray *handles;
+  TpHandleSet *set;
   GVariant *attributes;
   GVariant *ret;
   TpHandle ret_handle;
@@ -2859,11 +2858,11 @@ ensure_handle_cb (GObject *source,
       goto out;
     }
 
-  handles = g_array_new (FALSE, FALSE, sizeof (TpHandle));
-  g_array_append_val (handles, handle);
+  set = tp_handle_set_new (contact_repo);
+  tp_handle_set_add (set, handle);
 
   attributes = tp_base_connection_dup_contact_attributes (self,
-      handles, (const gchar * const *) data->interfaces,
+      set, (const gchar * const *) data->interfaces,
       contacts_always_included_interfaces);
   g_variant_get_child (attributes, 0, "{u at a{sv}}", &ret_handle, &ret);
   g_assert (ret_handle == handle);
@@ -2871,8 +2870,8 @@ ensure_handle_cb (GObject *source,
   _tp_gdbus_connection_complete_get_contact_by_id (
       self->priv->connection_skeleton, data->context, handle, ret);
 
-  g_array_unref (handles);
   g_variant_unref (attributes);
+  tp_handle_set_destroy (set);
 
 out:
   g_object_unref (data->conn);
diff --git a/telepathy-glib/base-connection.h b/telepathy-glib/base-connection.h
index 1b9c722..8a3164c 100644
--- a/telepathy-glib/base-connection.h
+++ b/telepathy-glib/base-connection.h
@@ -205,7 +205,7 @@ const gchar *tp_base_connection_get_account_path_suffix (
     TpBaseConnection *self);
 
 GVariant *tp_base_connection_dup_contact_attributes (TpBaseConnection *self,
-    const GArray *handles,
+    TpHandleSet *handles,
     const gchar * const *interfaces,
     const gchar * const *assumed_interfaces);
 
diff --git a/telepathy-glib/base-contact-list.c b/telepathy-glib/base-contact-list.c
index 809701d..d6286b4 100644
--- a/telepathy-glib/base-contact-list.c
+++ b/telepathy-glib/base-contact-list.c
@@ -3688,20 +3688,18 @@ tp_base_contact_list_mixin_get_contact_list_attributes (
   else
     {
       TpHandleSet *set;
-      GArray *contacts;
       const gchar *assumed[] = { TP_IFACE_CONNECTION,
           TP_IFACE_CONNECTION_INTERFACE_CONTACT_LIST1, NULL };
       GVariant *result;
 
       set = tp_base_contact_list_dup_contacts (self);
-      contacts = _tp_handle_set_to_array (set);
+
       result = tp_base_connection_dup_contact_attributes (
-          self->priv->conn, contacts, interfaces, assumed);
+          self->priv->conn, set, interfaces, assumed);
 
       _tp_gdbus_connection_interface_contact_list1_complete_get_contact_list_attributes (
           skeleton, context, result);
 
-      g_array_unref (contacts);
       tp_handle_set_destroy (set);
       g_variant_unref (result);
     }



More information about the telepathy-commits mailing list