summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2010-08-10 12:09:05 +0200
committerXavier Claessens <xclaesse@gmail.com>2010-08-10 13:25:50 +0200
commit0a07fea1a95c381490f1e07ba046e69b623d6259 (patch)
treea8375c87a41a5d07624af87939eeee33eb7f1399
parent9deca32ad5d45d7c712e737c4d9c74a3391c0be8 (diff)
Leave service when channel is invalidated
-rw-r--r--src/service.c49
1 files changed, 36 insertions, 13 deletions
diff --git a/src/service.c b/src/service.c
index 2230e27..6ac42c5 100644
--- a/src/service.c
+++ b/src/service.c
@@ -28,27 +28,46 @@
#include "common.h"
static GMainLoop *loop = NULL;
-static guint n_sessions = 0;
+static GList *channel_list = NULL;
+
+static void channel_invalidated_cb (TpChannel *channel, guint domain, gint code,
+ gchar *message, gpointer user_data);
static void
-throw_error (const GError *error)
+session_complete (TpChannel *channel, const GError *error)
{
- g_debug ("Error: %s", error ? error->message : "No error message");
+ if (error != NULL)
+ {
+ g_debug ("Error for channel %p: %s", channel,
+ error ? error->message : "No error message");
+ }
- if (--n_sessions == 0)
+ g_signal_handlers_disconnect_by_func (channel, channel_invalidated_cb, NULL);
+ tp_cli_channel_call_close (channel, -1, NULL, NULL, NULL, NULL);
+ channel_list = g_list_remove (channel_list, channel);
+ g_object_unref (channel);
+
+ if (channel_list == NULL)
g_main_loop_quit (loop);
}
static void
+channel_invalidated_cb (TpChannel *channel,
+ guint domain,
+ gint code,
+ gchar *message,
+ gpointer user_data)
+{
+ session_complete (channel, tp_proxy_get_invalidated (TP_PROXY (channel)));
+}
+
+static void
splice_cb (GIOStream *stream1,
GIOStream *stream2,
const GError *error,
- gpointer user_data)
+ gpointer channel)
{
- if (error != NULL)
- throw_error (error);
- else if (--n_sessions == 0)
- g_main_loop_quit (loop);
+ session_complete (channel, error);
}
static void
@@ -67,7 +86,7 @@ accept_tube_cb (TpChannel *channel,
if (error != NULL)
{
- throw_error (error);
+ session_complete (channel, error);
return;
}
@@ -99,12 +118,12 @@ accept_tube_cb (TpChannel *channel,
/* Splice tube and ssh connections */
_g_io_stream_splice (G_IO_STREAM (tube_connection),
- G_IO_STREAM (sshd_connection), splice_cb, NULL);
+ G_IO_STREAM (sshd_connection), splice_cb, channel);
OUT:
if (err != NULL)
- throw_error (err);
+ session_complete (channel, err);
tp_clear_object (&inet_address);
tp_clear_object (&socket_address);
@@ -138,7 +157,11 @@ got_channel_cb (TpSimpleHandler *handler,
TP_IFACE_CHANNEL_TYPE_STREAM_TUBE))
continue;
- n_sessions++;
+ g_debug ("New channel: %p", channel);
+
+ channel_list = g_list_prepend (channel_list, g_object_ref (channel));
+ g_signal_connect (channel, "invalidated",
+ G_CALLBACK (channel_invalidated_cb), NULL);
tp_cli_channel_type_stream_tube_call_accept (channel, -1,
TP_SOCKET_ADDRESS_TYPE_UNIX,