[telepathy-idle/master] Implement Destroyable for IM channels
Will Thompson
will.thompson at collabora.co.uk
Sun Aug 30 15:43:39 PDT 2009
---
src/idle-im-channel.c | 22 +++++++++++++++++++++-
tests/twisted/channels/requests-create.py | 10 ++++++++++
2 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/src/idle-im-channel.c b/src/idle-im-channel.c
index edd1868..c07c9e7 100644
--- a/src/idle-im-channel.c
+++ b/src/idle-im-channel.c
@@ -40,12 +40,14 @@
static void _channel_iface_init(gpointer, gpointer);
static void _text_iface_init(gpointer, gpointer);
+static void _destroyable_iface_init(gpointer, gpointer);
G_DEFINE_TYPE_WITH_CODE(IdleIMChannel, idle_im_channel, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CHANNEL, _channel_iface_init);
G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CHANNEL_TYPE_TEXT, _text_iface_init);
G_IMPLEMENT_INTERFACE(TP_TYPE_CHANNEL_IFACE, NULL);
- G_IMPLEMENT_INTERFACE(TP_TYPE_EXPORTABLE_CHANNEL, NULL);)
+ G_IMPLEMENT_INTERFACE(TP_TYPE_EXPORTABLE_CHANNEL, NULL);
+ G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CHANNEL_INTERFACE_DESTROYABLE, _destroyable_iface_init);)
/* property enum */
enum {
@@ -511,6 +513,18 @@ static void idle_im_channel_send(TpSvcChannelTypeText *iface, guint type, const
idle_text_send((GObject *)(obj), type, recipient, text, priv->connection, context);
}
+static void idle_im_channel_destroy(TpSvcChannelInterfaceDestroyable *iface, DBusGMethodInvocation *context) {
+ IdleIMChannel *obj = (IdleIMChannel *)(iface);
+ IdleIMChannelPrivate *priv = IDLE_IM_CHANNEL_GET_PRIVATE(obj);
+
+ IDLE_DEBUG ("called on %p with %spending messages", obj,
+ tp_text_mixin_has_pending_messages((GObject *)obj, NULL) ? "" : "no ");
+
+ priv->closed = TRUE;
+ tp_svc_channel_emit_closed(iface);
+ tp_svc_channel_interface_destroyable_return_from_destroy(context);
+}
+
static void _channel_iface_init(gpointer g_iface, gpointer iface_data) {
TpSvcChannelClass *klass = (TpSvcChannelClass *)g_iface;
@@ -533,3 +547,9 @@ static void _text_iface_init(gpointer g_iface, gpointer iface_data) {
#undef IMPLEMENT
}
+static void _destroyable_iface_init(gpointer klass, gpointer iface_data) {
+#define IMPLEMENT(x) tp_svc_channel_interface_destroyable_implement_##x (\
+ klass, idle_im_channel_##x)
+ IMPLEMENT (destroy);
+#undef IMPLEMENT
+}
diff --git a/tests/twisted/channels/requests-create.py b/tests/twisted/channels/requests-create.py
index ebe1db4..64120ec 100644
--- a/tests/twisted/channels/requests-create.py
+++ b/tests/twisted/channels/requests-create.py
@@ -103,6 +103,16 @@ def test(q, bus, conn, stream):
assert len(ms) == 1
assert ms[0][5] == 'oh hai'
+ # Without acknowledging the message, we destroy the channel:
+ chan.Destroy(dbus_interface=cs.CHANNEL_IFACE_DESTROYABLE)
+
+ q.expect('dbus-signal', signal='ChannelClosed')
+
+ # It should be gone for good this time.
+ channels = conn.Get(cs.CONN_IFACE_REQUESTS, 'Channels',
+ dbus_interface=cs.PROPERTIES_IFACE)
+ assert channels == [], channels
+
call_async(q, conn, 'Disconnect')
q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
--
1.5.6.5
More information about the telepathy-commits
mailing list