[telepathy-gabble/master] delay creation of search channel until the service disco process is done

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Tue Aug 25 03:47:36 PDT 2009


---
 src/search-manager.c                       |   65 ++++++++++++++++++++++++++--
 tests/twisted/search/no-server-property.py |   21 +++++----
 2 files changed, 72 insertions(+), 14 deletions(-)

diff --git a/src/search-manager.c b/src/search-manager.c
index dba0284..b67da23 100644
--- a/src/search-manager.c
+++ b/src/search-manager.c
@@ -46,6 +46,10 @@ G_DEFINE_TYPE_WITH_CODE (GabbleSearchManager, gabble_search_manager,
     G_IMPLEMENT_INTERFACE (GABBLE_TYPE_CAPS_CHANNEL_MANAGER,
       caps_channel_manager_iface_init));
 
+static void new_search_channel (GabbleSearchManager *self,
+    const gchar *server,
+    gpointer request_token);
+
 /* properties */
 enum
 {
@@ -63,6 +67,11 @@ struct _GabbleSearchManagerPrivate
   GHashTable *channels;
 
   gchar *default_jud;
+  gboolean disco_done;
+
+  /* List of request tokens (gpointer) waiting that the disco process is
+   * completed. */
+  GSList *requests_waiting_disco;
 
   gboolean dispose_has_run;
 };
@@ -78,6 +87,9 @@ gabble_search_manager_init (GabbleSearchManager *self)
 
   self->priv->conn = NULL;
   self->priv->dispose_has_run = FALSE;
+
+  self->priv->disco_done = FALSE;
+  self->priv->requests_waiting_disco = NULL;
 }
 
 static void
@@ -120,6 +132,37 @@ disco_item_found_cb (GabbleDisco *disco,
 }
 
 static void
+disco_done_cb (GabbleDisco *disco,
+    GabbleSearchManager *self)
+{
+  GSList *l;
+
+  DEBUG ("Disco is done; complete pending requests");
+
+  self->priv->disco_done = TRUE;
+
+  for (l = self->priv->requests_waiting_disco; l != NULL; l = g_slist_next (l))
+    {
+      gpointer request_token = l->data;
+
+      if (self->priv->default_jud != NULL)
+        {
+          new_search_channel (self, self->priv->default_jud, request_token);
+        }
+      else
+        {
+          tp_channel_manager_emit_request_failed (self, request_token,
+              TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
+              "No Server has been specified and no server has been "
+              "discovered on the connection");
+        }
+    }
+
+  g_slist_free (self->priv->requests_waiting_disco);
+  self->priv->requests_waiting_disco = NULL;
+}
+
+static void
 connection_status_changed_cb (GabbleConnection *conn,
                               guint status,
                               guint reason,
@@ -134,6 +177,8 @@ connection_status_changed_cb (GabbleConnection *conn,
          * can connect this signal in our constructor. */
         gabble_signal_connect_weak (self->priv->conn->disco, "item-found",
             G_CALLBACK (disco_item_found_cb), G_OBJECT (self));
+        gabble_signal_connect_weak (self->priv->conn->disco, "done",
+            G_CALLBACK (disco_done_cb), G_OBJECT (self));
         break;
 
       case TP_CONNECTION_STATUS_DISCONNECTED:
@@ -433,10 +478,22 @@ gabble_search_manager_create_channel (TpChannelManager *manager,
     {
       if (self->priv->default_jud == NULL)
         {
-          error = g_error_new (TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
-              "No Server has been specified and no server has been discovered "
-              "on the connection");
-          goto error;
+          if (self->priv->disco_done)
+            {
+              error = g_error_new (TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
+                  "No Server has been specified and no server has been "
+                  "discovered on the connection");
+              goto error;
+            }
+
+          /* Wait until disco is finished as we still have a chance to
+           * discover a search server. */
+          DEBUG ("No Server has been specified; wait for the end of "
+              "the disco process");
+
+          self->priv->requests_waiting_disco = g_slist_append (
+              self->priv->requests_waiting_disco, request_token);
+          return TRUE;
         }
 
       DEBUG ("No Server specified; use %s as default", self->priv->default_jud);
diff --git a/tests/twisted/search/no-server-property.py b/tests/twisted/search/no-server-property.py
index 8bc1404..01daa2a 100644
--- a/tests/twisted/search/no-server-property.py
+++ b/tests/twisted/search/no-server-property.py
@@ -30,11 +30,9 @@ def server_discovered(q, bus, conn, stream):
 
     requests = dbus.Interface(conn, cs.CONN_IFACE_REQUESTS)
 
-    # no search server has been discovered yet. Requesting a search channel
-    # without specifying the Server will fail
+    # no search server has been discovered yet. The CreateChannel operation
+    # will be completed once the disco process is finished.
     call_create(q, requests, server=None)
-    e = q.expect('dbus-error', method='CreateChannel')
-    assert e.error.get_dbus_name() == cs.INVALID_ARGUMENT
 
     # reply to IQ query
     reply = make_result_iq(stream, disco_event.stanza)
@@ -53,12 +51,11 @@ def server_discovered(q, bus, conn, stream):
 
     stream.send(reply)
 
-    # Make sure Gabble's received the reply
-    sync_stream(q, stream)
+    # JUD_SERVER is used as default
+    answer_field_query(q, stream, JUD_SERVER)
 
+    # Now that the search server has been discovered, it is used right away.
     call_create(q, requests, server=None)
-
-    # JUD_SERVER is used as default
     answer_field_query(q, stream, JUD_SERVER)
 
 def no_server_discovered(q, bus, conn, stream):
@@ -75,12 +72,16 @@ def no_server_discovered(q, bus, conn, stream):
 
     requests = dbus.Interface(conn, cs.CONN_IFACE_REQUESTS)
 
+    # no search server has been discovered yet. The CreateChannel operation
+    # will fail once the disco process is finished.
+    call_create(q, requests, server=None)
+
     # reply to IQ query. No search server is present
     reply = make_result_iq(stream, disco_event.stanza)
     stream.send(reply)
 
-    # Make sure Gabble's received the reply
-    sync_stream(q, stream)
+    # creation of the channel failed
+    e = q.expect('dbus-error', method='CreateChannel', name=cs.INVALID_ARGUMENT)
 
     # This server doesn't have a search server. We can't create Search channel
     # without specifying a Server property
-- 
1.5.6.5




More information about the telepathy-commits mailing list