[next] telepathy-glib: tp_connection_upgrade_contacts_async: fall back to old API if no Contacts
Simon McVittie
smcv at kemper.freedesktop.org
Fri May 11 07:29:13 PDT 2012
Module: telepathy-glib
Branch: next
Commit: 34e4109a86992b88d0cc879618e892f3417cb312
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=34e4109a86992b88d0cc879618e892f3417cb312
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Thu May 10 18:53:08 2012 +0100
tp_connection_upgrade_contacts_async: fall back to old API if no Contacts
Previously it would just crash with an assertion failure, because
contacts_bind_to_signals() relies on the Contacts interface.
Also test that case in contacts-slow-path.c.
Signed-off-by: Simon McVittie <simon.mcvittie at collabora.co.uk>
Reviewed-by: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=49735
---
telepathy-glib/contact.c | 49 +++++++++++++++++++++++++++++++-------
tests/dbus/contacts-slow-path.c | 34 ++++++++++++++++++++------
2 files changed, 66 insertions(+), 17 deletions(-)
diff --git a/telepathy-glib/contact.c b/telepathy-glib/contact.c
index f86170b..a80c778 100644
--- a/telepathy-glib/contact.c
+++ b/telepathy-glib/contact.c
@@ -4810,6 +4810,22 @@ got_contact_attributes_cb (TpConnection *self,
g_simple_async_result_complete (data->result);
}
+static void
+upgrade_contacts_async_fallback_cb (TpConnection *self,
+ guint n_contacts,
+ TpContact * const *contacts,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ GSimpleAsyncResult *result = user_data;
+
+ if (error != NULL)
+ g_simple_async_result_set_from_error (result, error);
+
+ g_simple_async_result_complete (result);
+}
+
/**
* tp_connection_upgrade_contacts_async:
* @self: A connection, which must have the %TP_CONNECTION_FEATURE_CONNECTED
@@ -4886,26 +4902,41 @@ tp_connection_upgrade_contacts_async (TpConnection *self,
/* Remove features that all contacts have */
feature_flags &= (~minimal_feature_flags);
- supported_interfaces = contacts_bind_to_signals (self, feature_flags);
-
result = g_simple_async_result_new ((GObject *) self, callback, user_data,
tp_connection_upgrade_contacts_async);
+
g_simple_async_result_set_op_res_gpointer (result, contacts_array,
(GDestroyNotify) g_ptr_array_unref);
- if (handles->len > 0 && supported_interfaces[0] != NULL)
+ if (tp_proxy_has_interface_by_id (self,
+ TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACTS))
{
- data = contacts_async_data_new (result, feature_flags);
- tp_cli_connection_interface_contacts_call_get_contact_attributes (self,
- -1, handles, supported_interfaces, TRUE, got_contact_attributes_cb,
- data, (GDestroyNotify) contacts_async_data_free, NULL);
+ supported_interfaces = contacts_bind_to_signals (self, feature_flags);
+
+ if (handles->len > 0 && supported_interfaces[0] != NULL)
+ {
+ data = contacts_async_data_new (result, feature_flags);
+ tp_cli_connection_interface_contacts_call_get_contact_attributes (
+ self, -1, handles, supported_interfaces, TRUE,
+ got_contact_attributes_cb, data,
+ (GDestroyNotify) contacts_async_data_free, NULL);
+ }
+ else
+ {
+ g_simple_async_result_complete_in_idle (result);
+ }
+
+ g_free (supported_interfaces);
}
else
{
- g_simple_async_result_complete_in_idle (result);
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+ tp_connection_upgrade_contacts (self, n_contacts, contacts, n_features,
+ features, upgrade_contacts_async_fallback_cb,
+ g_object_ref (result), g_object_unref, NULL);
+ G_GNUC_END_IGNORE_DEPRECATIONS
}
- g_free (supported_interfaces);
g_object_unref (result);
g_array_unref (handles);
}
diff --git a/tests/dbus/contacts-slow-path.c b/tests/dbus/contacts-slow-path.c
index b518b80..31c22f7 100644
--- a/tests/dbus/contacts-slow-path.c
+++ b/tests/dbus/contacts-slow-path.c
@@ -377,7 +377,7 @@ upgrade_cb (TpConnection *connection,
static void
test_upgrade (Fixture *f,
- gconstpointer unused G_GNUC_UNUSED)
+ gconstpointer mode)
{
TpTestsContactsConnection *service_conn = f->legacy_service_conn;
TpConnection *client_conn = f->legacy_client_conn;
@@ -461,13 +461,29 @@ test_upgrade (Fixture *f,
result.contacts = NULL;
g_assert (result.error == NULL);
- tp_connection_upgrade_contacts (client_conn,
- 3, contacts,
- G_N_ELEMENTS (features), features,
- upgrade_cb,
- &result, finish, NULL);
+ if (!tp_strdiff (mode, "old"))
+ {
+ tp_connection_upgrade_contacts (client_conn,
+ 3, contacts,
+ G_N_ELEMENTS (features), features,
+ upgrade_cb,
+ &result, finish, NULL);
- g_main_loop_run (result.loop);
+ g_main_loop_run (result.loop);
+ }
+ else
+ {
+ GAsyncResult *res = NULL;
+
+ tp_connection_upgrade_contacts_async (client_conn,
+ 3, contacts,
+ G_N_ELEMENTS (features), features,
+ tp_tests_result_ready_cb, &res);
+ tp_tests_run_until_result (&res);
+
+ tp_connection_upgrade_contacts_finish (client_conn, res,
+ &result.contacts, &result.error);
+ }
MYASSERT (result.contacts->len == 3, ": %u", result.contacts->len);
MYASSERT (result.invalid == NULL, "");
@@ -1243,7 +1259,9 @@ main (int argc,
test_no_features, teardown);
g_test_add ("/contacts-slow-path/features", Fixture, NULL, setup,
test_features, teardown);
- g_test_add ("/contacts-slow-path/upgrade", Fixture, NULL, setup,
+ g_test_add ("/contacts-slow-path/upgrade/old", Fixture, "old", setup,
+ test_upgrade, teardown);
+ g_test_add ("/contacts-slow-path/upgrade", Fixture, "async", setup,
test_upgrade, teardown);
g_test_add ("/contacts-slow-path/by-id", Fixture, NULL, setup,
test_by_id, teardown);
More information about the telepathy-commits
mailing list