telepathy-mission-control: Service points: use tp_connection_dup_contact_by_id_async
Simon McVittie
smcv at kemper.freedesktop.org
Tue Sep 10 03:39:25 PDT 2013
Module: telepathy-mission-control
Branch: master
Commit: 9219b4282cc9c6465dc1f9efd9e549c97bc6e3a9
URL: http://cgit.freedesktop.org/telepathy/telepathy-mission-control/commit/?id=9219b4282cc9c6465dc1f9efd9e549c97bc6e3a9
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Mon Sep 9 17:21:47 2013 +0100
Service points: use tp_connection_dup_contact_by_id_async
tp_connection_request_handles is deprecated. Ideally, we should drop
this whole chunk of code, but it seems best to save that for
Telepathy 1.0.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=55391
Reviewed-by: Xavier Claessens <xavier.claessens at collabora.co.uk>
---
src/mcd-connection-priv.h | 3 -
src/mcd-connection-service-points.c | 43 ++++++++++----------
src/mcd-connection.c | 7 +--
src/mcd-connection.h | 2 +
.../dispatcher/create-delayed-by-mini-plugin.py | 26 +++++------
5 files changed, 39 insertions(+), 42 deletions(-)
diff --git a/src/mcd-connection-priv.h b/src/mcd-connection-priv.h
index c3866c3..ac44b52 100644
--- a/src/mcd-connection-priv.h
+++ b/src/mcd-connection-priv.h
@@ -58,9 +58,6 @@ G_GNUC_INTERNAL gboolean _mcd_connection_presence_info_is_ready (McdConnection *
G_GNUC_INTERNAL void _mcd_connection_take_emergency_numbers (McdConnection *self,
GSList *numbers);
-G_GNUC_INTERNAL void _mcd_connection_take_emergency_handles (McdConnection *self,
- TpIntset *handles);
-
G_GNUC_INTERNAL gboolean _mcd_connection_target_id_is_urgent (McdConnection *connection,
const gchar *name);
diff --git a/src/mcd-connection-service-points.c b/src/mcd-connection-service-points.c
index 4ab6dc0..58b65f1 100644
--- a/src/mcd-connection-service-points.c
+++ b/src/mcd-connection-service-points.c
@@ -31,26 +31,22 @@
#include <telepathy-glib/telepathy-glib-dbus.h>
static void
-service_handles_fetched_cb (TpConnection *tp_conn,
- TpHandleType handle_type,
- guint n_handles,
- const TpHandle *handles,
- const gchar * const *ids,
- const GError *error,
- gpointer user_data G_GNUC_UNUSED,
- GObject *weak)
+service_point_contact_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- guint i;
- McdConnection *connection = MCD_CONNECTION (weak);
- TpIntset *e_handles = tp_intset_new ();
-
- if (error != NULL)
- return;
+ McdConnection *connection = MCD_CONNECTION (user_data);
+ TpContact *contact = tp_connection_dup_contact_by_id_finish (
+ TP_CONNECTION (source), result, NULL);
- for (i = 0; i < n_handles; i++)
- tp_intset_add (e_handles, handles[i]);
+ if (contact != NULL)
+ {
+ mcd_connection_add_emergency_handle (connection,
+ tp_contact_get_handle (contact));
+ g_object_unref (contact);
+ }
- _mcd_connection_take_emergency_handles (connection, e_handles);
+ g_object_unref (connection);
}
static void
@@ -83,12 +79,17 @@ parse_services_list (McdConnection *connection,
GSList *service;
TpConnection *tp_conn = mcd_connection_get_tp_connection (connection);
+ /* FIXME: in 1.0, drop this and spec that when calling a service point,
+ * you should use TargetID. See
+ * https://bugs.freedesktop.org/show_bug.cgi?id=59162#c3 */
for (service = e_numbers; service != NULL; service =g_slist_next (service))
{
- if (service->data != NULL)
- tp_connection_request_handles (tp_conn, -1, TP_HANDLE_TYPE_CONTACT,
- (const gchar *const *) service->data,
- service_handles_fetched_cb, NULL, NULL, G_OBJECT (connection));
+ const gchar * const *iter;
+
+ for (iter = service->data; iter != NULL && *iter != NULL; iter++)
+ tp_connection_dup_contact_by_id_async (tp_conn,
+ *iter, 0, NULL, service_point_contact_cb,
+ g_object_ref (connection));
}
_mcd_connection_take_emergency_numbers (connection, e_numbers);
diff --git a/src/mcd-connection.c b/src/mcd-connection.c
index c103e9a..1e5955a 100644
--- a/src/mcd-connection.c
+++ b/src/mcd-connection.c
@@ -2356,13 +2356,12 @@ _mcd_connection_take_emergency_numbers (McdConnection *self,
}
void
-_mcd_connection_take_emergency_handles (McdConnection *self,
- TpIntset *handles)
+mcd_connection_add_emergency_handle (McdConnection *self,
+ TpHandle handle)
{
if (self->priv->service_point_handles == NULL)
self->priv->service_point_handles = tp_intset_new ();
/* As above, we treat emergency numbers as "sticky". */
- tp_intset_union_update (self->priv->service_point_handles, handles);
- tp_intset_destroy (handles);
+ tp_intset_add (self->priv->service_point_handles, handle);
}
diff --git a/src/mcd-connection.h b/src/mcd-connection.h
index 90bfce7..347723c 100644
--- a/src/mcd-connection.h
+++ b/src/mcd-connection.h
@@ -79,5 +79,7 @@ void mcd_connection_close (McdConnection *connection,
McdChannel * mcd_connection_find_channel_by_path (McdConnection *connection,
const gchar *object_path);
+void mcd_connection_add_emergency_handle (McdConnection *self, TpHandle handle);
+
G_END_DECLS
#endif /* __MCD_CONNECTION_H__ */
diff --git a/tests/twisted/dispatcher/create-delayed-by-mini-plugin.py b/tests/twisted/dispatcher/create-delayed-by-mini-plugin.py
index 38b776e..8c2925c 100644
--- a/tests/twisted/dispatcher/create-delayed-by-mini-plugin.py
+++ b/tests/twisted/dispatcher/create-delayed-by-mini-plugin.py
@@ -56,10 +56,11 @@ def test(q, bus, mc):
q.dbus_return(e.message, points, signature='v')
# MC looks up the handles for these numbers
- e = q.expect('dbus-method-call', path=conn.object_path,
+ patterns = [EventPattern('dbus-method-call', path=conn.object_path,
interface=cs.CONN, method='RequestHandles',
- args=[cs.HT_CONTACT, e_numbers],
- handled=True)
+ args=[cs.HT_CONTACT, [num]],
+ handled=True) for num in e_numbers]
+ q.expect_many(*patterns)
# the service points change
e_numbers = ['911', '112', '999']
@@ -69,10 +70,11 @@ def test(q, bus, mc):
'ServicePointsChanged', points, signature='a((us)as)')
# MC looks up the new handles
- e = q.expect('dbus-method-call', path=conn.object_path,
+ patterns = [EventPattern('dbus-method-call', path=conn.object_path,
interface=cs.CONN, method='RequestHandles',
- args=[cs.HT_CONTACT, e_numbers],
- handled=True)
+ args=[cs.HT_CONTACT, [num]],
+ handled=True) for num in e_numbers]
+ q.expect_many(*patterns)
# MC used to critical if more than one emergency service point was
# given by the CM. That's silly, so let's test it.
@@ -87,15 +89,11 @@ def test(q, bus, mc):
e_numbers = e_numbers1 + e_numbers2
- q.expect_many(EventPattern('dbus-method-call', path=conn.object_path,
+ patterns = [EventPattern('dbus-method-call', path=conn.object_path,
interface=cs.CONN, method='RequestHandles',
- args=[cs.HT_CONTACT, e_numbers1],
- handled=True),
- EventPattern('dbus-method-call', path=conn.object_path,
- interface=cs.CONN, method='RequestHandles',
- args=[cs.HT_CONTACT, e_numbers2],
- handled=True),
- )
+ args=[cs.HT_CONTACT, [num]],
+ handled=True) for num in e_numbers]
+ q.expect_many(*patterns)
fixed_properties = dbus.Dictionary({
cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT,
More information about the telepathy-commits
mailing list