summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2013-06-23 11:35:37 +0100
committerWill Thompson <will.thompson@collabora.co.uk>2013-06-23 16:06:06 +0100
commit3d4f7ce3fe75756eef5066bd79c0a123a36258ed (patch)
tree6ab7049183056d6b08813aedbb28182331ae260a
parente5385533d99716a27c42d41be96ea32ef7e23f71 (diff)
downloadtelepathy-gabble-3d4f7ce3fe75756eef5066bd79c0a123a36258ed.tar.gz
console: close channels on disconnect
Pretty much all of the 268 lines of channel-manager.c is boilerplate :(
-rw-r--r--plugins/console/channel-manager.c54
-rw-r--r--tests/twisted/console.py5
2 files changed, 57 insertions, 2 deletions
diff --git a/plugins/console/channel-manager.c b/plugins/console/channel-manager.c
index f2be4f776..48c814f2a 100644
--- a/plugins/console/channel-manager.c
+++ b/plugins/console/channel-manager.c
@@ -35,11 +35,33 @@ enum {
PROP_CONNECTION = 1,
};
+static void connection_status_changed_cb (
+ TpBaseConnection *conn,
+ guint status,
+ guint reason,
+ GabbleConsoleChannelManager *self);
+static void gabble_console_channel_manager_close_all (
+ GabbleConsoleChannelManager *self);
+
static void
gabble_console_channel_manager_init (GabbleConsoleChannelManager *self)
{
}
+
+static void
+gabble_console_channel_manager_constructed (GObject *object)
+{
+ GabbleConsoleChannelManager *self = GABBLE_CONSOLE_CHANNEL_MANAGER (object);
+
+ G_OBJECT_CLASS (gabble_console_channel_manager_parent_class)->constructed (object);
+
+ g_return_if_fail (self->plugin_connection != NULL);
+ g_signal_connect_object (self->plugin_connection, "status-changed",
+ G_CALLBACK (connection_status_changed_cb), self, 0);
+}
+
+
static void
gabble_console_channel_manager_set_property (
GObject *object,
@@ -87,14 +109,41 @@ gabble_console_channel_manager_dispose (
GObject *object)
{
GabbleConsoleChannelManager *self = GABBLE_CONSOLE_CHANNEL_MANAGER (object);
+
+ gabble_console_channel_manager_close_all (self);
+
+ G_OBJECT_CLASS (gabble_console_channel_manager_parent_class)->dispose (object);
+}
+
+
+static void
+connection_status_changed_cb (
+ TpBaseConnection *conn,
+ guint status,
+ guint reason,
+ GabbleConsoleChannelManager *self)
+{
+ switch (status)
+ {
+ case TP_CONNECTION_STATUS_DISCONNECTED:
+ gabble_console_channel_manager_close_all (self);
+ break;
+
+ default:
+ return;
+ }
+}
+
+static void
+gabble_console_channel_manager_close_all (
+ GabbleConsoleChannelManager *self)
+{
TpBaseChannel *channel;
while ((channel = g_queue_peek_head (&self->console_channels)) != NULL)
{
tp_base_channel_close (channel);
}
-
- G_OBJECT_CLASS (gabble_console_channel_manager_parent_class)->dispose (object);
}
@@ -103,6 +152,7 @@ gabble_console_channel_manager_class_init (GabbleConsoleChannelManagerClass *kla
{
GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ oclass->constructed = gabble_console_channel_manager_constructed;
oclass->set_property = gabble_console_channel_manager_set_property;
oclass->get_property = gabble_console_channel_manager_get_property;
oclass->dispose = gabble_console_channel_manager_dispose;
diff --git a/tests/twisted/console.py b/tests/twisted/console.py
index b2efd658c..5eddaf024 100644
--- a/tests/twisted/console.py
+++ b/tests/twisted/console.py
@@ -39,6 +39,11 @@ def test(q, bus, conn, stream):
assertContains((fixed, allowed), rccs)
path, _ = conn.Requests.CreateChannel({ cs.CHANNEL_TYPE: CONSOLE_PLUGIN_IFACE })
+ other_path, _ = conn.Requests.CreateChannel({ cs.CHANNEL_TYPE: CONSOLE_PLUGIN_IFACE })
+
+ assertNotEquals(path, other_path)
+ # leave the other one open, to test we don't crash on disconnect
+
console = ProxyWrapper(bus.get_object(conn.bus_name, path),
CONSOLE_PLUGIN_IFACE,
{'Channel': cs.CHANNEL})