[Telepathy-commits] [telepathy-gabble/master] implement org.laptop.Telepathy.Activity.SearchByProperties()
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Fri Sep 26 10:02:09 PDT 2008
20080521134409-7fe3f-97d30a6611879c0d88e97cb6f053dddbe3e279b4.gz
---
src/conn-olpc.c | 75 +++++++++++++++++++++++++++-
tests/twisted/olpc/olpc-activity-search.py | 53 +++++++++++++++++++-
2 files changed, 125 insertions(+), 3 deletions(-)
diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index 1316156..bc15944 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -3383,7 +3383,7 @@ olpc_activity_request_random (GabbleSvcOLPCActivity *iface,
max_str = g_strdup_printf ("%u", max);
id_str = g_strdup_printf ("%u", id);
- query = lm_message_build_with_sub_type (conn->olpc_gadget_buddy,
+ query = lm_message_build_with_sub_type (conn->olpc_gadget_activity,
LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
'(', "query", "",
'@', "xmlns", NS_OLPC_ACTIVITY,
@@ -3416,6 +3416,78 @@ olpc_activity_request_random (GabbleSvcOLPCActivity *iface,
lm_message_unref (query);
}
+static void
+olpc_activity_search_by_properties (GabbleSvcOLPCActivity *iface,
+ GHashTable *properties,
+ DBusGMethodInvocation *context)
+{
+ GabbleConnection *conn = GABBLE_CONNECTION (iface);
+ LmMessage *query;
+ LmMessageNode *properties_node;
+ gchar *id_str;
+ gchar *object_path;
+ guint id;
+ GabbleOlpcActivityView *view;
+
+ if (!check_gadget_activity (conn, context))
+ return;
+
+ view = create_activity_view (conn);
+ if (view == NULL)
+ {
+ GError error = { TP_ERRORS, TP_ERROR_NETWORK_ERROR,
+ "can't create view" };
+
+ DEBUG ("%s", error.message);
+ dbus_g_method_return_error (context, &error);
+ return;
+ }
+
+ g_object_get (view,
+ "id", &id,
+ "object-path", &object_path,
+ NULL);
+
+ id_str = g_strdup_printf ("%u", id);
+
+ query = lm_message_build_with_sub_type (conn->olpc_gadget_activity,
+ LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
+ '(', "query", "",
+ '@', "xmlns", NS_OLPC_ACTIVITY,
+ '@', "id", id_str,
+ '(', "activity", "",
+ '(', "properties", "",
+ '*', &properties_node,
+ '@', "xmlns", NS_OLPC_ACTIVITY_PROPS,
+ ')',
+ ')',
+ ')',
+ NULL);
+
+ g_free (id_str);
+
+ lm_message_node_add_children_from_properties (properties_node, properties,
+ "property");
+
+ if (!_gabble_connection_send_with_reply (conn, query,
+ activity_query_result_cb, G_OBJECT (view), NULL, NULL))
+ {
+ GError error = { TP_ERRORS, TP_ERROR_NETWORK_ERROR,
+ "Failed to send activity search query to server" };
+
+ DEBUG ("%s", error.message);
+ dbus_g_method_return_error (context, &error);
+ lm_message_unref (query);
+ g_free (object_path);
+ return;
+ }
+
+ gabble_svc_olpc_activity_return_from_search_by_properties (context, object_path);
+
+ g_free (object_path);
+ lm_message_unref (query);
+}
+
void
olpc_activity_iface_init (gpointer g_iface,
gpointer iface_data)
@@ -3425,5 +3497,6 @@ olpc_activity_iface_init (gpointer g_iface,
#define IMPLEMENT(x) gabble_svc_olpc_activity_implement_##x (\
klass, olpc_activity_##x)
IMPLEMENT(request_random);
+ IMPLEMENT(search_by_properties);
#undef IMPLEMENT
}
diff --git a/tests/twisted/olpc/olpc-activity-search.py b/tests/twisted/olpc/olpc-activity-search.py
index 40b5b14..3d97d0c 100644
--- a/tests/twisted/olpc/olpc-activity-search.py
+++ b/tests/twisted/olpc/olpc-activity-search.py
@@ -104,11 +104,50 @@ def test(q, bus, conn, stream):
event = q.expect('dbus-signal', signal='ActivityPropertiesChanged')
handle, props = event.args
- print handle
- print props
assert conn.InspectHandles(2, [handle])[0] == 'room1 at conference.localhost'
assert props == {'color': '#005FE4,#00A0FF'}
+ # activity search by properties
+ props = {'color': '#AABBCC,#001122'}
+ call_async(q, activity_iface, 'SearchByProperties', props)
+
+ iq_event, return_event = q.expect_many(
+ EventPattern('stream-iq', to='gadget.localhost', query_ns=NS_OLPC_ACTIVITY),
+ EventPattern('dbus-return', method='SearchByProperties'))
+
+ properties = xpath.queryForNodes('/iq/query/activity/properties/property', iq_event.stanza)
+ query = iq_event.stanza.firstChildElement()
+ assert query.name == 'query'
+ assert query['id'] == '1'
+ assert len(properties) == 1
+ property = properties[0]
+ assert property['type'] == 'str'
+ assert property['name'] == 'color'
+ assert property.children == ['#AABBCC,#001122']
+
+ # reply to request
+ reply = make_result_iq(stream, iq_event.stanza)
+ reply['from'] = 'gadget.localhost'
+ reply['to'] = 'alice at localhost'
+ query = xpath.queryForNodes('/iq/query', reply)[0]
+ activity = query.addElement((None, "activity"))
+ activity['room'] = 'room2 at conference.localhost'
+ properties = activity.addElement((NS_OLPC_ACTIVITY_PROPS, "properties"))
+ property = properties.addElement((None, "property"))
+ property['type'] = 'str'
+ property['name'] = 'color'
+ property.addContent('#AABBCC,#001122')
+ stream.send(reply)
+
+ view_path = return_event.value[0]
+ view1 = bus.get_object(conn.bus_name, view_path)
+ view1_iface = dbus.Interface(view1, 'org.laptop.Telepathy.ActivityView')
+
+ event = q.expect('dbus-signal', signal='ActivityPropertiesChanged')
+ handle, props = event.args
+ assert conn.InspectHandles(2, [handle])[0] == 'room2 at conference.localhost'
+ assert props == {'color': '#AABBCC,#001122'}
+
# close view 0
call_async(q, view0_iface, 'Close')
event, _ = q.expect_many(
@@ -118,5 +157,15 @@ def test(q, bus, conn, stream):
assert len(close) == 1
assert close[0]['id'] == '0'
+ # close view 1
+ call_async(q, view1_iface, 'Close')
+ event, _ = q.expect_many(
+ EventPattern('stream-message', to='gadget.localhost'),
+ EventPattern('dbus-return', method='Close'))
+ close = xpath.queryForNodes('/message/close', event.stanza)
+ assert len(close) == 1
+ assert close[0]['id'] == '1'
+
+
if __name__ == '__main__':
exec_test(test)
--
1.5.6.5
More information about the Telepathy-commits
mailing list