[Telepathy-commits] [telepathy-gabble/master] change View spec to return the ID and the room of activities instead of just the handle
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Fri Sep 26 10:02:19 PDT 2008
20080610140203-7fe3f-6808301f7ebe86de0f274c28b1b9db038fa90ca5.gz
---
extensions/OLPC_View.xml | 16 +++++---
src/olpc-view.c | 50 ++++++++++++++++++++--------
tests/twisted/olpc/olpc-activity-search.py | 16 +++++++--
3 files changed, 58 insertions(+), 24 deletions(-)
diff --git a/extensions/OLPC_View.xml b/extensions/OLPC_View.xml
index 3d89425..7bc33de 100644
--- a/extensions/OLPC_View.xml
+++ b/extensions/OLPC_View.xml
@@ -19,10 +19,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA</p>
<interface name="org.laptop.Telepathy.View">
<method name="GetActivities">
- <arg direction="out" name="activities" type="au">
- <tp:docstring>
- An array of room handles
- </tp:docstring>
+ <arg direction="out" name="activities" type="a(su)" tp:type="Activity[]">
+ <tp:docstring xmlns="http://www.w3.org/1999/xhtml">
+ An array of structs containing:
+ <ul>
+ <li>the identifier of the activity</li>
+ <li>the room handle of the activity channel</li>
+ </ul>
+ </tp:docstring>
</arg>
<tp:docstring xmlns="http://www.w3.org/1999/xhtml">
<p>Return all the activities of this view</p>
@@ -56,12 +60,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA</p>
</method>
<signal name="ActivitiesChanged">
- <arg name="added" type="au">
+ <arg name="added" type="a(su)" tp:type="Activity[]">
<tp:docstring>
Room handles of the added activities
</tp:docstring>
</arg>
- <arg name="removed" type="au">
+ <arg name="removed" type="a(su)" tp:type="Activity[]">
<tp:docstring>
Room handles of the removed activities
</tp:docstring>
diff --git a/src/olpc-view.c b/src/olpc-view.c
index 60a19e8..3930754 100644
--- a/src/olpc-view.c
+++ b/src/olpc-view.c
@@ -335,11 +335,32 @@ olpc_view_get_buddies (GabbleSvcOLPCView *iface,
}
static void
-add_handle_to_array (TpHandle handle,
- GabbleOlpcActivity *activity,
- GArray *array)
+add_activity_to_array (TpHandle handle,
+ GabbleOlpcActivity *activity,
+ GPtrArray *array)
{
- g_array_append_val (array, handle);
+ GValue gvalue = { 0 };
+
+ g_value_init (&gvalue, GABBLE_STRUCT_TYPE_ACTIVITY);
+ g_value_take_boxed (&gvalue, dbus_g_type_specialized_construct
+ (GABBLE_STRUCT_TYPE_ACTIVITY));
+ dbus_g_type_struct_set (&gvalue,
+ 0, activity->id,
+ 1, activity->room,
+ G_MAXUINT);
+
+ g_ptr_array_add (array, g_value_get_boxed (&gvalue));
+}
+
+static void
+free_activities_array (GPtrArray *activities)
+{
+ guint i;
+
+ for (i = 0; i < activities->len; i++)
+ g_boxed_free (GABBLE_STRUCT_TYPE_ACTIVITY, activities->pdata[i]);
+
+ g_ptr_array_free (activities, TRUE);
}
static void
@@ -348,15 +369,16 @@ olpc_view_get_activities (GabbleSvcOLPCView *iface,
{
GabbleOlpcView *self = GABBLE_OLPC_VIEW (iface);
GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
- GArray *activities;
+ GPtrArray *activities;
- activities = g_array_new (FALSE, FALSE, sizeof (TpHandle));
- g_hash_table_foreach (priv->activities, (GHFunc) add_handle_to_array,
+ activities = g_ptr_array_new ();
+
+ g_hash_table_foreach (priv->activities, (GHFunc) add_activity_to_array,
activities);
gabble_svc_olpc_view_return_from_get_activities (context, activities);
- g_array_free (activities, TRUE);
+ free_activities_array (activities);
}
static void
@@ -508,19 +530,19 @@ gabble_olpc_view_add_activities (GabbleOlpcView *self,
GHashTable *activities)
{
GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
- GArray *added, *empty;
+ GPtrArray *added, *empty;
tp_g_hash_table_update (priv->activities, activities, NULL, g_object_ref);
- added = g_array_new (FALSE, FALSE, sizeof (TpHandle));
- g_hash_table_foreach (activities, (GHFunc) add_handle_to_array, added);
+ added = g_ptr_array_new ();
+ g_hash_table_foreach (activities, (GHFunc) add_activity_to_array, added);
- empty = g_array_new (FALSE, FALSE, sizeof (TpHandle));
+ empty = g_ptr_array_new ();
gabble_svc_olpc_view_emit_activities_changed (self, added, empty);
- g_array_free (added, TRUE);
- g_array_free (empty, TRUE);
+ free_activities_array (added);
+ g_ptr_array_free (empty, TRUE);
}
static void
diff --git a/tests/twisted/olpc/olpc-activity-search.py b/tests/twisted/olpc/olpc-activity-search.py
index 6479f88..5bc1ffd 100644
--- a/tests/twisted/olpc/olpc-activity-search.py
+++ b/tests/twisted/olpc/olpc-activity-search.py
@@ -114,8 +114,10 @@ def test(q, bus, conn, stream):
event = q.expect('dbus-signal', signal='ActivitiesChanged')
added, removed = event.args
- assert removed == []
- assert sorted(conn.InspectHandles(2, added)) == ['room1 at conference.localhost']
+ assert len(added) == 1
+ id, handle = added[0]
+ assert id == 'activity1'
+ assert sorted(conn.InspectHandles(2, [handle])) == ['room1 at conference.localhost']
act = view0_iface.GetActivities()
assert sorted(act) == sorted(added)
@@ -173,7 +175,10 @@ def test(q, bus, conn, stream):
event = q.expect('dbus-signal', signal='ActivitiesChanged')
added, removed = event.args
assert removed == []
- assert sorted(conn.InspectHandles(2, added)) == ['room2 at conference.localhost']
+ assert len(added) == 1
+ id, handle = added[0]
+ assert id == 'activity2'
+ assert sorted(conn.InspectHandles(2, [handle])) == ['room2 at conference.localhost']
act = view1.GetActivities()
assert sorted(act) == sorted(added)
@@ -220,7 +225,10 @@ def test(q, bus, conn, stream):
event = q.expect('dbus-signal', signal='ActivitiesChanged')
added, removed = event.args
assert removed == []
- assert sorted(conn.InspectHandles(2, added)) == ['room2 at conference.localhost']
+ assert len(added) == 1
+ id, handle = added[0]
+ assert id == 'activity2'
+ assert sorted(conn.InspectHandles(2, [handle])) == ['room2 at conference.localhost']
act = view2.GetActivities()
assert sorted(act) == sorted(added)
--
1.5.6.5
More information about the Telepathy-commits
mailing list