diff options
author | Xavier Claessens <xclaesse@gmail.com> | 2011-08-25 11:56:43 +0200 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2011-08-25 11:56:43 +0200 |
commit | 944af3fbdf71ca3333c7d20c32792f5ad524ce73 (patch) | |
tree | 2047fa019c5744a93e2c53ea0f65c7380885674b /telepathy-glib/contact-operations.c | |
parent | f3dd6328aefdbc14876cdd52e1f931589a54ed3e (diff) | |
download | telepathy-glib-944af3fbdf71ca3333c7d20c32792f5ad524ce73.tar.gz |
tp_contact_foo_async() callback must be the TpContact not its TpConnection
Diffstat (limited to 'telepathy-glib/contact-operations.c')
-rw-r--r-- | telepathy-glib/contact-operations.c | 111 |
1 files changed, 83 insertions, 28 deletions
diff --git a/telepathy-glib/contact-operations.c b/telepathy-glib/contact-operations.c index db9622983..1852f3343 100644 --- a/telepathy-glib/contact-operations.c +++ b/telepathy-glib/contact-operations.c @@ -23,6 +23,54 @@ #define DEBUG_FLAG TP_DEBUG_CONTACTS #include "telepathy-glib/debug-internal.h" +#include "telepathy-glib/util-internal.h" + +static void +generic_callback (TpConnection *self, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *result = user_data; + + if (error != NULL) + { + DEBUG ("Operation failed: %s", error->message); + g_simple_async_result_set_from_error (result, error); + } + + /* tp_cli callbacks can potentially be called in a re-entrant way, + * so we can't necessarily complete @result without using an idle. */ + g_simple_async_result_complete_in_idle (result); +} + +/* Small macro trick because DBus method is remove_contacts and in this + * TpContact helper API we removed the redundant _contacts. */ +#define tp_contact_remove_contacts_async tp_contact_remove_async + +#define contact_list_generic_async(method, ...) \ + G_STMT_START { \ + GSimpleAsyncResult *result; \ + TpHandle handle; \ + GArray *handles; \ + \ + g_return_if_fail (TP_IS_CONTACT (self)); \ + \ + handle = tp_contact_get_handle (self); \ + handles = g_array_new (FALSE, FALSE, sizeof (TpHandle)); \ + g_array_append_val (handles, handle); \ + \ + result = g_simple_async_result_new ((GObject *) self, callback, user_data, \ + tp_contact_##method##_async); \ + \ + tp_cli_connection_interface_contact_list_call_##method ( \ + tp_contact_get_connection (self), -1, handles, ##__VA_ARGS__, \ + generic_callback, result, g_object_unref, NULL); \ + g_array_unref (handles); \ + } G_STMT_END + +#define generic_finish(method) \ + _tp_implement_finish_void (self, tp_contact_##method##_async); /** * tp_contact_request_subscription_async: @@ -42,8 +90,7 @@ tp_contact_request_subscription_async (TpContact *self, GAsyncReadyCallback callback, gpointer user_data) { - tp_connection_request_subscription_async (tp_contact_get_connection (self), - 1, &self, message, callback, user_data); + contact_list_generic_async (request_subscription, message); } /** @@ -63,8 +110,7 @@ tp_contact_request_subscription_finish (TpContact *self, GAsyncResult *result, GError **error) { - return tp_connection_request_subscription_finish ( - tp_contact_get_connection (self), result, error); + generic_finish (request_subscription); } /** @@ -83,8 +129,7 @@ tp_contact_authorize_publication_async (TpContact *self, GAsyncReadyCallback callback, gpointer user_data) { - tp_connection_authorize_publication_async (tp_contact_get_connection (self), - 1, &self, callback, user_data); + contact_list_generic_async (authorize_publication); } /** @@ -104,8 +149,7 @@ tp_contact_authorize_publication_finish (TpContact *self, GAsyncResult *result, GError **error) { - return tp_connection_authorize_publication_finish ( - tp_contact_get_connection (self), result, error); + generic_finish (authorize_publication); } /** @@ -124,8 +168,7 @@ tp_contact_remove_async (TpContact *self, GAsyncReadyCallback callback, gpointer user_data) { - tp_connection_remove_contacts_async (tp_contact_get_connection (self), - 1, &self, callback, user_data); + contact_list_generic_async (remove_contacts); } /** @@ -145,8 +188,7 @@ tp_contact_remove_finish (TpContact *self, GAsyncResult *result, GError **error) { - return tp_connection_remove_contacts_finish ( - tp_contact_get_connection (self), result, error); + generic_finish (remove_contacts); } /** @@ -165,8 +207,7 @@ tp_contact_unsubscribe_async (TpContact *self, GAsyncReadyCallback callback, gpointer user_data) { - tp_connection_unsubscribe_async (tp_contact_get_connection (self), - 1, &self, callback, user_data); + contact_list_generic_async (unsubscribe); } /** @@ -186,8 +227,7 @@ tp_contact_unsubscribe_finish (TpContact *self, GAsyncResult *result, GError **error) { - return tp_connection_unsubscribe_finish ( - tp_contact_get_connection (self), result, error); + generic_finish (unsubscribe); } /** @@ -206,8 +246,7 @@ tp_contact_unpublish_async (TpContact *self, GAsyncReadyCallback callback, gpointer user_data) { - tp_connection_unpublish_async (tp_contact_get_connection (self), - 1, &self, callback, user_data); + contact_list_generic_async (unpublish); } /** @@ -227,10 +266,30 @@ tp_contact_unpublish_finish (TpContact *self, GAsyncResult *result, GError **error) { - return tp_connection_unpublish_finish ( - tp_contact_get_connection (self), result, error); + generic_finish (unpublish); } +#define contact_groups_generic_async(method) \ + G_STMT_START { \ + GSimpleAsyncResult *result; \ + TpHandle handle; \ + GArray *handles; \ + \ + g_return_if_fail (TP_IS_CONTACT (self)); \ + \ + handle = tp_contact_get_handle (self); \ + handles = g_array_new (FALSE, FALSE, sizeof (TpHandle)); \ + g_array_append_val (handles, handle); \ + \ + result = g_simple_async_result_new ((GObject *) self, callback, user_data, \ + tp_contact_##method##_async); \ + \ + tp_cli_connection_interface_contact_groups_call_##method ( \ + tp_contact_get_connection (self), -1, group, handles, \ + generic_callback, result, g_object_unref, NULL); \ + g_array_unref (handles); \ + } G_STMT_END + /** * tp_contact_add_to_group_async: * @self: a #TpContact @@ -249,8 +308,7 @@ tp_contact_add_to_group_async (TpContact *self, GAsyncReadyCallback callback, gpointer user_data) { - tp_connection_add_to_group_async (tp_contact_get_connection (self), - group, 1, &self, callback, user_data); + contact_groups_generic_async (add_to_group); } /** @@ -270,8 +328,7 @@ tp_contact_add_to_group_finish (TpContact *self, GAsyncResult *result, GError **error) { - return tp_connection_add_to_group_finish ( - tp_contact_get_connection (self), result, error); + generic_finish (add_to_group); } /** @@ -292,8 +349,7 @@ tp_contact_remove_from_group_async (TpContact *self, GAsyncReadyCallback callback, gpointer user_data) { - tp_connection_remove_from_group_async (tp_contact_get_connection (self), - group, 1, &self, callback, user_data); + contact_groups_generic_async (remove_from_group); } /** @@ -313,6 +369,5 @@ tp_contact_remove_from_group_finish (TpContact *self, GAsyncResult *result, GError **error) { - return tp_connection_remove_from_group_finish ( - tp_contact_get_connection (self), result, error); + generic_finish (remove_from_group); } |