[Telepathy-commits] [telepathy-glib/master] TpConnection: fetch ContactAttributeInterfaces before becoming ready

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Oct 1 10:02:06 PDT 2008


If we support Contacts, then in practice we're going to want to know this, and
it doesn't require binding to any signals (it's an immutable property).
This will allow the contact factory code to check which interfaces we
support in a synchronous way.
---
 telepathy-glib/connection.c |  106 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 105 insertions(+), 1 deletions(-)

diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c
index 6785bbb..1ba958d 100644
--- a/telepathy-glib/connection.c
+++ b/telepathy-glib/connection.c
@@ -117,8 +117,12 @@ struct _TpConnectionPrivate {
 
     TpConnectionStatus status;
     TpConnectionStatusReason status_reason;
+
     TpConnectionAliasFlags alias_flags;
 
+    /* GArray of GQuark */
+    GArray *contact_attribute_interfaces;
+
     gboolean ready:1;
 };
 
@@ -214,6 +218,76 @@ introspect_aliasing (TpConnection *self)
 }
 
 static void
+got_contact_attribute_interfaces (TpProxy *proxy,
+                                  const GValue *value,
+                                  const GError *error,
+                                  gpointer user_data G_GNUC_UNUSED,
+                                  GObject *weak_object G_GNUC_UNUSED)
+{
+  TpConnection *self = TP_CONNECTION (proxy);
+
+  if (error == NULL)
+    {
+      if (G_VALUE_HOLDS (value, G_TYPE_STRV))
+        {
+          GArray *arr;
+          guint i = 0;
+          gchar **interfaces = g_value_get_boxed (value);
+          gchar **iter;
+
+          if (interfaces != NULL)
+            {
+              for (iter = interfaces; *iter != NULL; iter++)
+                i++;
+            }
+
+          arr = g_array_sized_new (FALSE, FALSE, sizeof (GQuark), i);
+
+          if (interfaces != NULL)
+            {
+              for (iter = interfaces; *iter != NULL; iter++)
+                {
+                  if (tp_dbus_check_valid_interface_name (*iter, NULL))
+                    {
+                      GQuark q = g_quark_from_string (*iter);
+
+                      DEBUG ("%p: ContactAttributeInterfaces has %s", self,
+                          *iter);
+                      g_array_append_val (arr, q);
+                    }
+                  else
+                    {
+                      DEBUG ("%p: ignoring invalid interface: %s", self,
+                          *iter);
+                    }
+                }
+            }
+
+          g_assert (self->priv->contact_attribute_interfaces == NULL);
+          self->priv->contact_attribute_interfaces = arr;
+        }
+    }
+  else
+    {
+      DEBUG ("%p: Get(Contacts, ContactAttributeInterfaces) failed with "
+          "%s %d: %s", self, g_quark_to_string (error->domain), error->code,
+          error->message);
+    }
+
+  tp_connection_continue_introspection (self);
+}
+
+static void
+introspect_contacts (TpConnection *self)
+{
+  g_assert (self->priv->introspect_needed != NULL);
+
+  tp_cli_dbus_properties_call_get (self, -1,
+       TP_IFACE_CONNECTION_INTERFACE_CONTACTS, "ContactAttributeInterfaces",
+       got_contact_attribute_interfaces, NULL, NULL, NULL);
+}
+
+static void
 tp_connection_got_interfaces_cb (TpConnection *self,
                                  const gchar **interfaces,
                                  const GError *error,
@@ -246,7 +320,13 @@ tp_connection_got_interfaces_cb (TpConnection *self,
               tp_proxy_add_interface_by_id ((TpProxy *) self,
                   g_quark_from_string (*iter));
 
-              if (q == TP_IFACE_QUARK_CONNECTION_INTERFACE_ALIASING)
+              if (q == TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACTS)
+                {
+                  TpConnectionProc func = introspect_contacts;
+
+                  g_array_append_val (self->priv->introspect_needed, func);
+                }
+              else if (q == TP_IFACE_QUARK_CONNECTION_INTERFACE_ALIASING)
                 {
                   /* call GetAliasFlags */
                   TpConnectionProc func = introspect_aliasing;
@@ -397,6 +477,29 @@ tp_connection_init (TpConnection *self)
 }
 
 static void
+tp_connection_finalize (GObject *object)
+{
+  TpConnection *self = TP_CONNECTION (object);
+
+  DEBUG ("%p", self);
+
+  /* not true unless we were finalized before we were ready */
+  if (self->priv->introspect_needed != NULL)
+    {
+      g_array_free (self->priv->introspect_needed, TRUE);
+      self->priv->introspect_needed = NULL;
+    }
+
+  if (self->priv->contact_attribute_interfaces != NULL)
+    {
+      g_array_free (self->priv->contact_attribute_interfaces, TRUE);
+      self->priv->contact_attribute_interfaces = NULL;
+    }
+
+  ((GObjectClass *) tp_connection_parent_class)->finalize (object);
+}
+
+static void
 tp_connection_dispose (GObject *object)
 {
   DEBUG ("%p", object);
@@ -417,6 +520,7 @@ tp_connection_class_init (TpConnectionClass *klass)
   object_class->constructor = tp_connection_constructor;
   object_class->get_property = tp_connection_get_property;
   object_class->dispose = tp_connection_dispose;
+  object_class->finalize = tp_connection_finalize;
 
   proxy_class->interface = TP_IFACE_QUARK_CONNECTION;
   /* If you change this, you must also change TpChannel to stop asserting
-- 
1.5.6.5




More information about the Telepathy-commits mailing list