[Telepathy-commits] [telepathy-gabble/master] conn-olpc: close open views when Gadget is restarted
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Fri Sep 26 10:02:56 PDT 2008
20080804123921-7fe3f-1fcbf800230a3a2a9621069e96b8ba8c778994a6.gz
---
src/conn-olpc.c | 29 ++++++++++++++
tests/twisted/olpc/gadget-restarted.py | 66 ++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+), 0 deletions(-)
create mode 100644 tests/twisted/olpc/gadget-restarted.py
diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index cff5f2b..b77d273 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -4347,6 +4347,26 @@ olpc_gadget_publish (GabbleSvcOLPCGadget *iface,
gabble_svc_olpc_gadget_return_from_publish (context);
}
+static gboolean
+close_view_foreach (gpointer key,
+ GabbleOlpcView *view,
+ GabbleConnection *conn)
+{
+ g_signal_handlers_disconnect_by_func (view, G_CALLBACK (view_closed_cb),
+ conn);
+
+ gabble_olpc_view_close (view, NULL);
+
+ return TRUE;
+}
+
+static void
+close_all_views (GabbleConnection *conn)
+{
+ g_hash_table_foreach_remove (conn->olpc_views, (GHRFunc) close_view_foreach,
+ conn);
+}
+
LmHandlerResult
conn_olpc_presence_cb (LmMessageHandler *handler,
LmConnection *connection,
@@ -4359,6 +4379,9 @@ conn_olpc_presence_cb (LmMessageHandler *handler,
LmMessageSubType sub_type;
GError *error = NULL;
+ if (!check_gadget_buddy (conn, NULL))
+ return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
+
pres_node = lm_message_get_node (presence);
from = lm_message_node_get_attribute (pres_node, "from");
if (from == NULL)
@@ -4397,6 +4420,12 @@ conn_olpc_presence_cb (LmMessageHandler *handler,
}
}
}
+ else if (sub_type == LM_MESSAGE_SUB_TYPE_NOT_SET ||
+ sub_type == LM_MESSAGE_SUB_TYPE_AVAILABLE)
+ {
+ DEBUG ("Got presence from Gadget. Close open views if any");
+ close_all_views (conn);
+ }
return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
diff --git a/tests/twisted/olpc/gadget-restarted.py b/tests/twisted/olpc/gadget-restarted.py
new file mode 100644
index 0000000..205f4b0
--- /dev/null
+++ b/tests/twisted/olpc/gadget-restarted.py
@@ -0,0 +1,66 @@
+"""
+test OLPC search activity
+"""
+
+import dbus
+
+from servicetest import call_async, EventPattern
+from gabbletest import exec_test, make_result_iq, acknowledge_iq, sync_stream
+
+from twisted.words.xish import domish, xpath
+from twisted.words.protocols.jabber.client import IQ
+from util import announce_gadget, request_random_activity_view, elem
+
+NS_OLPC_BUDDY_PROPS = "http://laptop.org/xmpp/buddy-properties"
+NS_OLPC_ACTIVITIES = "http://laptop.org/xmpp/activities"
+NS_OLPC_CURRENT_ACTIVITY = "http://laptop.org/xmpp/current-activity"
+NS_OLPC_ACTIVITY_PROPS = "http://laptop.org/xmpp/activity-properties"
+NS_OLPC_BUDDY = "http://laptop.org/xmpp/buddy"
+NS_OLPC_ACTIVITY = "http://laptop.org/xmpp/activity"
+
+NS_PUBSUB = "http://jabber.org/protocol/pubsub"
+NS_DISCO_INFO = "http://jabber.org/protocol/disco#info"
+NS_DISCO_ITEMS = "http://jabber.org/protocol/disco#items"
+
+NS_AMP = "http://jabber.org/protocol/amp"
+NS_STANZA = "urn:ietf:params:xml:ns:xmpp-stanzas"
+
+def test(q, bus, conn, stream):
+ conn.Connect()
+
+ handles = {}
+
+ _, iq_event, disco_event = q.expect_many(
+ EventPattern('dbus-signal', signal='StatusChanged', args=[0, 1]),
+ EventPattern('stream-iq', to=None, query_ns='vcard-temp',
+ query_name='vCard'),
+ EventPattern('stream-iq', to='localhost', query_ns=NS_DISCO_ITEMS))
+
+ acknowledge_iq(stream, iq_event.stanza)
+ announce_gadget(q, stream, disco_event.stanza)
+
+ activity_prop_iface = dbus.Interface(conn,
+ 'org.laptop.Telepathy.ActivityProperties')
+ buddy_prop_iface = dbus.Interface(conn, 'org.laptop.Telepathy.BuddyInfo')
+ gadget_iface = dbus.Interface(conn, 'org.laptop.Telepathy.Gadget')
+
+ sync_stream(q, stream)
+
+ # request 3 random activities (view 0)
+ view_path = request_random_activity_view(q, stream, conn, 3, '0',
+ [('activity1', 'room1 at conference.localhost',
+ {'color': ('str', '#005FE4,#00A0FF')},
+ [('lucien at localhost', {'color': ('str', '#AABBCC,#CCBBAA')}),
+ ('jean at localhost', {})]),])
+
+ view0 = bus.get_object(conn.bus_name, view_path)
+ view0_iface = dbus.Interface(view0, 'org.laptop.Telepathy.View')
+
+ # Gadget is restarted so send us a new presence stanza
+ presence = elem('presence', from_='gadget.localhost', to='test at localhost')
+ stream.send(presence)
+
+ q.expect('dbus-signal', signal='Closed', interface='org.laptop.Telepathy.View')
+
+if __name__ == '__main__':
+ exec_test(test)
--
1.5.6.5
More information about the Telepathy-commits
mailing list