[Telepathy-commits] [telepathy-gabble/master] GabbleJingleContent: implemented timeout for content addition

Senko Rasic senko at phyrexia.lan
Tue Dec 2 04:34:05 PST 2008


---
 src/jingle-content.c |   30 ++++++++++++++++++++++++++++++
 src/jingle-session.c |    1 +
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/src/jingle-content.c b/src/jingle-content.c
index e7056d6..9c2fcea 100644
--- a/src/jingle-content.c
+++ b/src/jingle-content.c
@@ -79,11 +79,15 @@ struct _GabbleJingleContentPrivate
   gboolean media_ready;
   gboolean transport_ready;
 
+  guint timer_id;
+
   gboolean dispose_has_run;
 };
 
 #define GABBLE_JINGLE_CONTENT_GET_PRIVATE(o) ((o)->priv)
 
+#define DEFAULT_CONTENT_TIMEOUT 60000
+
 /* lookup tables */
 
 G_DEFINE_TYPE(GabbleJingleContent, gabble_jingle_content, G_TYPE_OBJECT);
@@ -104,6 +108,7 @@ gabble_jingle_content_init (GabbleJingleContent *obj)
   priv->created_by_us = TRUE;
   priv->media_ready = FALSE;
   priv->transport_ready = FALSE;
+  priv->timer_id = 0;
   priv->dispose_has_run = FALSE;
 
   obj->conn = NULL;
@@ -122,6 +127,8 @@ gabble_jingle_content_dispose (GObject *object)
   DEBUG ("dispose called");
   priv->dispose_has_run = TRUE;
 
+  g_assert (priv->timer_id == 0);
+
   g_free (priv->name);
   priv->name = NULL;
 
@@ -722,6 +729,19 @@ gabble_jingle_content_is_ready (GabbleJingleContent *self)
   return FALSE;
 }
 
+static gboolean
+timeout_content (gpointer data)
+{
+  GabbleJingleContent *c = data;
+
+  c->priv->timer_id = 0;
+  DEBUG ("content timed out");
+
+  /* we're handling it as if it were rejected */
+  gabble_jingle_content_remove (c, FALSE);
+  return FALSE;
+}
+
 static void
 send_content_add_or_accept (GabbleJingleContent *self)
 {
@@ -738,6 +758,10 @@ send_content_add_or_accept (GabbleJingleContent *self)
       /* TODO: set a timer for acknowledgement */
       action = JINGLE_ACTION_CONTENT_ADD;
       new_state = JINGLE_CONTENT_STATE_SENT;
+
+      g_assert (priv->timer_id == 0);
+      priv->timer_id = g_timeout_add (DEFAULT_CONTENT_TIMEOUT,
+        timeout_content, self);
     }
   else
     {
@@ -914,5 +938,11 @@ gabble_jingle_content_remove (GabbleJingleContent *c, gboolean signal_peer)
     {
       g_signal_emit (c, signals[REMOVED], 0);
     }
+
+  if (priv->timer_id != 0)
+    {
+      g_source_remove (priv->timer_id);
+      priv->timer_id = 0;
+    }
 }
 
diff --git a/src/jingle-session.c b/src/jingle-session.c
index e02d9cc..ffb17ce 100644
--- a/src/jingle-session.c
+++ b/src/jingle-session.c
@@ -1335,6 +1335,7 @@ timeout_session (gpointer data)
   GabbleJingleSession *session = data;
 
   DEBUG ("session timed out");
+  session->priv->timer_id = 0;
 
   /* FIXME: distinguish between different cases; we somehow need to
    * signal this to media channel - parameter to TERMINATED perhaps?*/
-- 
1.5.6.5




More information about the Telepathy-commits mailing list