diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-03-05 19:36:55 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-03-09 15:51:24 +0000 |
commit | 0c7e8cb86c9f47d043fbdb598c0efdb87cbcba17 (patch) | |
tree | 07d3b6e5ad501b5889a66df64ed165bfafb8d9eb | |
parent | b455b394c152fbad69fcd743c2882469e2dec73f (diff) | |
download | telepathy-glib-0c7e8cb86c9f47d043fbdb598c0efdb87cbcba17.tar.gz |
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 <simon.mcvittie@collabora.co.uk>
Reviewed-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r-- | docs/reference/telepathy-glib-sections.txt | 2 | ||||
-rw-r--r-- | telepathy-glib/connection-manager.c | 100 | ||||
-rw-r--r-- | 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 244a2b064..c1280b5a2 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 <TITLE>connection-manager</TITLE> <INCLUDE>telepathy-glib/connection-manager.h</INCLUDE> 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 b7d009193..3a4aacdf2 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 + * <literal>g_list_free_full (list, g_object_unref)</literal>. + * + * 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 423b051e1..742edbeeb 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); |