From d72702738cca78f70832963fb0c26a9a2a556d26 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 5 Mar 2012 19:36:55 +0000 Subject: [PATCH 06/10] tp_list_connection_managers_async: add This is a modern, bindable version of tp_list_connection_managers(), which has been noted not to work in Python. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=46358 Signed-off-by: Simon McVittie --- docs/reference/telepathy-glib-sections.txt | 2 + telepathy-glib/connection-manager.c | 100 ++++++++++++++++++++++++++++ telepathy-glib/connection-manager.h | 6 ++ 3 files changed, 108 insertions(+), 0 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 244a2b0..c1280b5 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -4633,6 +4633,8 @@ tp_cli_connection_interface_addressing_callback_for_get_contacts_by_vcard_field connection-manager telepathy-glib/connection-manager.h TpConnectionManagerListCb +tp_list_connection_managers_async +tp_list_connection_managers_finish tp_list_connection_managers TpConnectionManager TpConnectionManagerClass diff --git a/telepathy-glib/connection-manager.c b/telepathy-glib/connection-manager.c index b7d0091..3a4aacd 100644 --- a/telepathy-glib/connection-manager.c +++ b/telepathy-glib/connection-manager.c @@ -37,6 +37,7 @@ #define DEBUG_FLAG TP_DEBUG_MANAGER #include "telepathy-glib/debug-internal.h" #include "telepathy-glib/protocol-internal.h" +#include "telepathy-glib/util-internal.h" #include "telepathy-glib/_gen/tp-cli-connection-manager-body.h" @@ -1671,6 +1672,7 @@ typedef struct { GHashTable *table; GPtrArray *arr; + GSimpleAsyncResult *result; TpConnectionManagerListCb callback; gpointer user_data; GDestroyNotify destroy; @@ -1877,6 +1879,104 @@ tp_list_connection_managers (TpDBusDaemon *bus_daemon, (GDestroyNotify) list_context_unref, weak_object); } +static void +list_connection_managers_async_cb (TpConnectionManager * const *cms, + gsize n_cms, + 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); + } + else + { + GList *l = NULL; + gsize i; + + for (i = 0; i < n_cms; i++) + l = g_list_prepend (l, g_object_ref (cms[i])); + + l = g_list_reverse (l); + + g_simple_async_result_set_op_res_gpointer (result, l, + (GDestroyNotify) _tp_object_list_free); + } + + g_simple_async_result_complete_in_idle (result); + + /* result is unreffed by GDestroyNotify */ +} + +/** + * tp_list_connection_managers_async: + * @dbus_daemon: (allow-none): a #TpDBusDaemon, or %NULL to use + * tp_dbus_daemon_dup() + * @callback: a callback to call with a list of CMs + * @user_data: data to pass to @callback + * + * List the available (running or installed) connection managers, + * asynchronously, and wait for their %TP_CONNECTION_MANAGER_FEATURE_CORE + * feature to be ready. + * + * Since: 0.UNRELEASED + */ +void +tp_list_connection_managers_async (TpDBusDaemon *dbus_daemon, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *result; + GError *error = NULL; + + if (dbus_daemon == NULL) + dbus_daemon = tp_dbus_daemon_dup (&error); + else + g_object_ref (dbus_daemon); + + result = g_simple_async_result_new (NULL, callback, user_data, + tp_list_connection_managers_async); + + if (dbus_daemon == NULL) + { + g_simple_async_result_take_error (result, error); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); + } + else + { + tp_list_connection_managers (dbus_daemon, + list_connection_managers_async_cb, result, g_object_unref, NULL); + g_object_unref (dbus_daemon); + } +} + +/** + * tp_list_connection_managers_finish: + * @result: the result of tp_list_connection_managers_async() + * @error: used to raise an error if the operation failed + * + * Finish listing the available connection managers. + * + * Free the list after use, for instance with + * g_list_free_full (list, g_object_unref). + * + * Returns: (transfer full) (element-type TelepathyGLib.ConnectionManager): a + * newly allocated list of references to #TpConnectionManager objects + * Since: 0.UNRELEASED + */ +GList * +tp_list_connection_managers_finish (GAsyncResult *result, + GError **error) +{ + _tp_implement_finish_return_copy_pointer (NULL, + tp_list_connection_managers_async, + _tp_object_list_copy); +} + /** * tp_connection_manager_check_valid_name: * @name: a possible connection manager name diff --git a/telepathy-glib/connection-manager.h b/telepathy-glib/connection-manager.h index 423b051..742edbe 100644 --- a/telepathy-glib/connection-manager.h +++ b/telepathy-glib/connection-manager.h @@ -117,6 +117,12 @@ void tp_list_connection_managers (TpDBusDaemon *bus_daemon, gpointer user_data, GDestroyNotify destroy, GObject *weak_object); +void tp_list_connection_managers_async (TpDBusDaemon *dbus_daemon, + GAsyncReadyCallback callback, + gpointer user_data); +GList *tp_list_connection_managers_finish (GAsyncResult *result, + GError **error); + #ifndef TP_DISABLE_DEPRECATED typedef void (*TpConnectionManagerWhenReadyCb) (TpConnectionManager *cm, const GError *error, gpointer user_data, GObject *weak_object); -- 1.7.9.1