[telepathy-gabble/master] Let the transport decide if it's ready to accept

Will Thompson will.thompson at collabora.co.uk
Sat Jun 27 09:29:06 PDT 2009


---
 src/jingle-content.c          |   12 +++---------
 src/jingle-transport-iface.c  |   22 ++++++++++++++++++++++
 src/jingle-transport-iface.h  |    3 +++
 src/jingle-transport-rawudp.c |   12 +++++++++++-
 4 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/src/jingle-content.c b/src/jingle-content.c
index dfc6e53..55d109d 100644
--- a/src/jingle-content.c
+++ b/src/jingle-content.c
@@ -79,8 +79,6 @@ struct _GabbleJingleContentPrivate
   /* Whether we've got the codecs (intersection) ready. */
   gboolean media_ready;
 
-  /* Whether the underlying transport is connected. */
-  gboolean transport_connected;
   /* Whether we have at least one local candidate. */
   gboolean have_local_candidates;
 
@@ -113,7 +111,6 @@ gabble_jingle_content_init (GabbleJingleContent *obj)
   priv->state = JINGLE_CONTENT_STATE_EMPTY;
   priv->created_by_us = TRUE;
   priv->media_ready = FALSE;
-  priv->transport_connected = FALSE;
   priv->have_local_candidates = FALSE;
   priv->timer_id = 0;
   priv->gtalk4_event_id = 0;
@@ -781,7 +778,8 @@ gabble_jingle_content_is_ready (GabbleJingleContent *self)
     {
       /* If it's created by peer, media and transports ready,
        * and not acknowledged yet, it's ready for acceptance. */
-      if (priv->media_ready && priv->transport_connected &&
+      if (priv->media_ready &&
+          gabble_jingle_transport_iface_can_accept (priv->transport) &&
           (priv->state == JINGLE_CONTENT_STATE_NEW))
         return TRUE;
     }
@@ -951,11 +949,7 @@ gabble_jingle_content_set_transport_state (GabbleJingleContent *self,
 
   g_object_set (priv->transport, "state", state, NULL);
 
-  if (state == JINGLE_TRANSPORT_STATE_CONNECTED)
-    {
-      priv->transport_connected = TRUE;
-      _maybe_ready (self);
-    }
+  _maybe_ready (self);
 }
 
 GList *
diff --git a/src/jingle-transport-iface.c b/src/jingle-transport-iface.c
index a605272..76128a6 100644
--- a/src/jingle-transport-iface.c
+++ b/src/jingle-transport-iface.c
@@ -92,6 +92,28 @@ gabble_jingle_transport_iface_send_candidates (
     virtual_method (self, all);
 }
 
+/* Returns TRUE if and only if @self has enough candidates to inject into a
+ * {session,content}-accept, and is connected.
+ */
+gboolean
+gabble_jingle_transport_iface_can_accept (GabbleJingleTransportIface *self)
+{
+  JingleTransportState state;
+  gboolean (*m) (GabbleJingleTransportIface *) =
+      GABBLE_JINGLE_TRANSPORT_IFACE_GET_CLASS (self)->can_accept;
+
+  g_object_get (self, "state", &state, NULL);
+
+  if (state != JINGLE_TRANSPORT_STATE_CONNECTED)
+    return FALSE;
+
+  /* Only Raw UDP *needs* contents in order to accept. */
+  if (m != NULL)
+    return m (self);
+  else
+    return TRUE;
+}
+
 GList *
 gabble_jingle_transport_iface_get_remote_candidates (
     GabbleJingleTransportIface *self)
diff --git a/src/jingle-transport-iface.h b/src/jingle-transport-iface.h
index 810da0b..9ee4a08 100644
--- a/src/jingle-transport-iface.h
+++ b/src/jingle-transport-iface.h
@@ -48,6 +48,7 @@ struct _GabbleJingleTransportIfaceClass {
   void (*inject_candidates) (GabbleJingleTransportIface *,
       LmMessageNode *transport_node);
   void (*send_candidates) (GabbleJingleTransportIface *, gboolean all);
+  gboolean (*can_accept) (GabbleJingleTransportIface *);
 
   GList * (*get_remote_candidates) (GabbleJingleTransportIface *);
   JingleTransportType (*get_transport_type) (void);
@@ -78,6 +79,8 @@ void gabble_jingle_transport_iface_inject_candidates (
 void gabble_jingle_transport_iface_send_candidates (
     GabbleJingleTransportIface *self,
     gboolean all);
+gboolean gabble_jingle_transport_iface_can_accept (
+    GabbleJingleTransportIface *self);
 
 GList *gabble_jingle_transport_iface_get_remote_candidates (GabbleJingleTransportIface *);
 JingleTransportType gabble_jingle_transport_iface_get_transport_type (GabbleJingleTransportIface *);
diff --git a/src/jingle-transport-rawudp.c b/src/jingle-transport-rawudp.c
index 0cb1e01..f947b9e 100644
--- a/src/jingle-transport-rawudp.c
+++ b/src/jingle-transport-rawudp.c
@@ -310,7 +310,8 @@ inject_candidates (GabbleJingleTransportIface *obj,
   LmMessageNode *cnode;
 
   /* If we don't have the local candidates yet, we should've waited with
-   * the session initiation. */
+   * the session initiation, or can_accept would have returned FALSE.
+   */
   g_assert (priv->local_candidates != NULL);
 
   for (li = priv->local_candidates; li != NULL; li = li->next)
@@ -357,6 +358,14 @@ new_local_candidates (GabbleJingleTransportIface *obj, GList *new_candidates)
       priv->pending_candidates = new_candidates;
 }
 
+static gboolean
+can_accept (GabbleJingleTransportIface *iface)
+{
+  GabbleJingleTransportRawUdp *self = GABBLE_JINGLE_TRANSPORT_RAWUDP (iface);
+
+  return (self->priv->local_candidates != NULL);
+}
+
 static GList *
 get_remote_candidates (GabbleJingleTransportIface *iface)
 {
@@ -387,6 +396,7 @@ transport_iface_init (gpointer g_iface, gpointer iface_data)
   /* Not implementing _send: XEP-0177 says that the candidates live in
    * content-{add,accept}, not in transport-info.
    */
+  klass->can_accept = can_accept;
 
   klass->get_remote_candidates = get_remote_candidates;
   klass->get_transport_type = get_transport_type;
-- 
1.5.6.5




More information about the telepathy-commits mailing list