telepathy-gabble: console: close channels on disconnect
Simon McVittie
smcv at kemper.freedesktop.org
Mon Oct 14 08:21:20 PDT 2013
Module: telepathy-gabble
Branch: master
Commit: 3d4f7ce3fe75756eef5066bd79c0a123a36258ed
URL: http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=3d4f7ce3fe75756eef5066bd79c0a123a36258ed
Author: Will Thompson <will.thompson at collabora.co.uk>
Date: Sun Jun 23 11:35:37 2013 +0100
console: close channels on disconnect
Pretty much all of the 268 lines of channel-manager.c is boilerplate :(
---
plugins/console/channel-manager.c | 54 +++++++++++++++++++++++++++++++++++-
tests/twisted/console.py | 5 +++
2 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/plugins/console/channel-manager.c b/plugins/console/channel-manager.c
index f2be4f7..48c814f 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 b2efd65..5eddaf0 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})
More information about the telepathy-commits
mailing list