[Telepathy-commits] [telepathy-glib/master] TpChannel: avoid calling GetInterfaces if we already know the channel exists, and we already know its interfaces

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Nov 28 07:05:13 PST 2008


---
 telepathy-glib/channel-internal.h |    6 ++++++
 telepathy-glib/channel.c          |   30 +++++++++++++++++++++++++-----
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/telepathy-glib/channel-internal.h b/telepathy-glib/channel-internal.h
index bc0eeb1..eab5d4c 100644
--- a/telepathy-glib/channel-internal.h
+++ b/telepathy-glib/channel-internal.h
@@ -64,7 +64,13 @@ struct _TpChannelPrivate {
     GHashTable *group_handle_owners;
 
     /* These are really booleans, but gboolean is signed. Thanks, GLib */
+
+    /* channel-ready */
     unsigned ready:1;
+    /* Enough method calls have succeeded that we believe that the channel
+     * exists (implied by ready) */
+    unsigned exists:1;
+    /* GetGroupFlags has returned */
     unsigned have_group_flags:1;
 };
 
diff --git a/telepathy-glib/channel.c b/telepathy-glib/channel.c
index 6775db8..ca43b0b 100644
--- a/telepathy-glib/channel.c
+++ b/telepathy-glib/channel.c
@@ -515,6 +515,7 @@ tp_channel_got_interfaces_cb (TpChannel *self,
       return;
     }
 
+  self->priv->exists = TRUE;
   _tp_channel_maybe_set_interfaces (self, interfaces);
 
   /* FIXME: give subclasses a chance to influence the definition of "ready"
@@ -529,8 +530,19 @@ _tp_channel_get_interfaces (TpChannel *self)
 {
   DEBUG ("%p", self);
 
-  tp_cli_channel_call_get_interfaces (self, -1,
-      tp_channel_got_interfaces_cb, NULL, NULL, NULL);
+  if (self->priv->exists &&
+      tp_asv_lookup (self->priv->channel_properties,
+          TP_IFACE_CHANNEL ".Interfaces") != NULL)
+    {
+      _tp_channel_continue_introspection (self);
+    }
+  else
+    {
+      /* either we don't know the Interfaces, or we just want to verify the
+       * channel's existence */
+      tp_cli_channel_call_get_interfaces (self, -1,
+          tp_channel_got_interfaces_cb, NULL, NULL, NULL);
+    }
 }
 
 
@@ -549,6 +561,7 @@ tp_channel_got_channel_type_cb (TpChannel *self,
     }
   else if (tp_dbus_check_valid_interface_name (channel_type, &err2))
     {
+      self->priv->exists = TRUE;
       DEBUG ("%p: Introspected channel type %s", self, channel_type);
       _tp_channel_maybe_set_channel_type (self, channel_type);
       g_object_notify ((GObject *) self, "channel-type");
@@ -599,6 +612,8 @@ tp_channel_got_handle_cb (TpChannel *self,
     {
       GValue *value;
 
+      self->priv->exists = TRUE;
+
       DEBUG ("%p: Introspected handle #%d of type %d", self, handle,
           handle_type);
       self->priv->handle_type = handle_type;
@@ -665,6 +680,8 @@ _tp_channel_got_properties (TpProxy *proxy,
 
       DEBUG ("Received %u channel properties", g_hash_table_size (asv));
 
+      self->priv->exists = TRUE;
+
       _tp_channel_maybe_set_channel_type (self,
           tp_asv_get_string (asv, "ChannelType"));
       _tp_channel_maybe_set_interfaces (self,
@@ -863,9 +880,12 @@ tp_channel_constructor (GType type,
   g_queue_push_tail (self->priv->introspect_needed,
       _tp_channel_get_channel_type);
 
-  /* currently this always runs, regardless of anything else;
-   * this means the channel never becomes ready until we re-enter the
-   * main loop, and we always verify that the channel does actually exist */
+  /* This makes a call unless (a) we already know the Interfaces by now, and
+   * (b) priv->exists is TRUE (i.e. either GetAll, GetHandle or GetChannelType
+   * has succeeded).
+   *
+   * This means the channel never becomes ready until we re-enter the
+   * main loop, and we always verify that the channel does actually exist. */
   g_queue_push_tail (self->priv->introspect_needed,
       _tp_channel_get_interfaces);
 
-- 
1.5.6.5




More information about the Telepathy-commits mailing list