[telepathy-salut/master] tube-stream: fire ConnectionClosed

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Jun 26 07:16:31 PDT 2009


---
 src/tube-stream.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/src/tube-stream.c b/src/tube-stream.c
index 6d71186..2a006f8 100644
--- a/src/tube-stream.c
+++ b/src/tube-stream.c
@@ -67,6 +67,14 @@
 #include "salut-tubes-channel.h"
 #include "salut-xmpp-connection-manager.h"
 
+/* FIXME: use tp-glib errors */
+#define SALUT_ERROR_STR_CONNECTION_LOST \
+  "org.freedesktop.Telepathy.Error.ConnectionLost"
+#define SALUT_ERROR_STR_CONNECTION_REFUSED \
+  "org.freedesktop.Telepathy.Error.ConnectionRefused"
+#define SALUT_ERROR_STR_CANCELLED \
+  "org.freedesktop.Telepathy.Error.Cancelled"
+
 static void tube_iface_init (gpointer g_iface, gpointer iface_data);
 static void channel_iface_init (gpointer g_iface, gpointer iface_data);
 static void streamtube_iface_init (gpointer g_iface, gpointer iface_data);
@@ -282,12 +290,40 @@ transport_handler (GibberTransport *transport,
 }
 
 static void
+fire_connection_closed (SalutTubeStream *self,
+    GibberTransport *transport,
+    const gchar *error,
+    const gchar *debug_msg)
+{
+  SalutTubeStreamPrivate *priv = SALUT_TUBE_STREAM_GET_PRIVATE (self);
+  guint connection_id;
+
+  connection_id = GPOINTER_TO_UINT (g_hash_table_lookup (priv->transport_to_id,
+        transport));
+  if (connection_id == 0)
+    {
+      DEBUG ("ConnectionClosed has already been fired for this connection");
+      return;
+    }
+
+  /* remove the ID so we are sure we won't fire ConnectionClosed twice for the
+   * same connection. */
+  g_hash_table_remove (priv->transport_to_id, transport);
+
+  salut_svc_channel_type_stream_tube_emit_connection_closed (self,
+      connection_id, error, debug_msg);
+}
+
+static void
 transport_disconnected_cb (GibberTransport *transport,
                            SalutTubeStream *self)
 {
   SalutTubeStreamPrivate *priv = SALUT_TUBE_STREAM_GET_PRIVATE (self);
   GibberBytestreamIface *bytestream;
 
+  fire_connection_closed (self, transport, SALUT_ERROR_STR_CANCELLED,
+      "local socket has been disconnected");
+
   bytestream = g_hash_table_lookup (priv->transport_to_bytestream, transport);
   if (bytestream == NULL)
     return;
@@ -310,6 +346,9 @@ remove_transport (SalutTubeStream *self,
 
   gibber_transport_disconnect (transport);
 
+  fire_connection_closed (self, transport, SALUT_ERROR_STR_CONNECTION_LOST,
+      "bytestream has been broken");
+
   /* the transport may not be in transport_to_bytestream if the bytestream was
    * not fully open */
   g_hash_table_remove (priv->transport_to_bytestream, transport);
@@ -454,6 +493,9 @@ extra_bytestream_negotiate_cb (GibberBytestreamIface *bytestream,
     {
       DEBUG ("initiator refused new bytestream");
 
+      fire_connection_closed (self, data->transport,
+          SALUT_ERROR_STR_CONNECTION_REFUSED, "connection has been refused");
+
       g_object_unref (data->transport);
       g_slice_free (struct _extra_bytestream_negotiate_cb_data, data);
       return;
@@ -965,6 +1007,8 @@ close_each_extra_bytestream (gpointer key,
 
   gibber_bytestream_iface_close (bytestream, NULL);
   gibber_transport_disconnect (transport);
+  fire_connection_closed (self, transport, SALUT_ERROR_STR_CANCELLED,
+      "tube is closing");
 
   g_hash_table_remove (priv->transport_to_bytestream, transport);
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list