summaryrefslogtreecommitdiff
path: root/src/tube-stream.c
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2009-05-27 16:30:52 +0100
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2009-06-26 10:27:22 +0100
commit20497ca7fe92db648f08de3c978669b964b6473f (patch)
tree99266e63678e64c1ebd01ee0f8fe47ef6d6726af /src/tube-stream.c
parent4377d940f331650aea07e02716ebb94e3cd4011f (diff)
downloadtelepathy-salut-20497ca7fe92db648f08de3c978669b964b6473f.tar.gz
tube-stream: fire ConnectionClosed
Diffstat (limited to 'src/tube-stream.c')
-rw-r--r--src/tube-stream.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/tube-stream.c b/src/tube-stream.c
index 6d711865..2a006f81 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);