From b6cbd57dcdb7af87f1b0e84323ddf95d3cc1f023 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 7 Mar 2012 14:32:28 +0000 Subject: [PATCH 09/10] tp_connection_manager_dup_protocols: add Again, this provides a more introspectable way to get the protocols. Combining dup_protocol_names() and get_protocol() is more type-safe, but less obvious. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=46358 Signed-off-by: Simon McVittie --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/connection-manager.c | 45 +++++++++++++++++++++++++-- telepathy-glib/connection-manager.h | 2 + tests/dbus/cm.c | 13 ++++++++ 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 46ea52f..27e91cd 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -4649,6 +4649,7 @@ TP_TYPE_CM_INFO_SOURCE tp_connection_manager_get_info_source tp_connection_manager_activate tp_connection_manager_is_running +tp_connection_manager_dup_protocols tp_connection_manager_dup_protocol_names tp_connection_manager_has_protocol tp_connection_manager_get_protocol diff --git a/telepathy-glib/connection-manager.c b/telepathy-glib/connection-manager.c index 3a4aacd..b82a99e 100644 --- a/telepathy-glib/connection-manager.c +++ b/telepathy-glib/connection-manager.c @@ -83,10 +83,10 @@ * on a #TpConnectionManager. * * After this feature is prepared, basic information about the connection - * manager's protocols (tp_connection_manager_get_protocol() and - * tp_connection_manager_dup_protocol_names()), and their available parameters, - * will have been retrieved, either by activating the connection manager over - * D-Bus or by reading the .manager file in which that information is cached. + * manager's protocols (tp_connection_manager_dup_protocols()), and their + * available parameters, will have been retrieved, either by activating the + * connection manager over D-Bus or by reading the .manager file in which + * that information is cached. * * Since 0.11.11, this feature also finds any extra interfaces that * this connection manager has, and adds them to #TpProxy:interfaces (where @@ -2281,6 +2281,43 @@ tp_connection_manager_get_protocol_object (TpConnectionManager *self, return g_hash_table_lookup (self->priv->protocol_objects, protocol); } +/* FIXME: in Telepathy 1.0, rename to get_protocols */ +/** + * tp_connection_manager_dup_protocols: + * @self: a connection manager + * + * Return objects representing all protocols supported by this connection + * manager. + * + * If this function is called before the connection manager information has + * been obtained, the result is always %NULL. Use tp_proxy_prepare_async() + * to wait for this. + * + * The caller must free the list, for instance with + * g_list_free_full (l, g_object_unref). + * + * Returns: (transfer full) (element-type TelepathyGLib.Protocol): a list + * of #TpProtocol objects representing the protocols supported by @self, + * owned by the caller + * + * Since: 0.UNRELEASED + */ +GList * +tp_connection_manager_dup_protocols (TpConnectionManager *self) +{ + GList *l; + + g_return_val_if_fail (TP_IS_CONNECTION_MANAGER (self), NULL); + + if (self->priv->protocol_objects == NULL) + return NULL; + + l = g_hash_table_get_values (self->priv->protocol_objects); + + g_list_foreach (l, (GFunc) g_object_ref, NULL); + return l; +} + /** * tp_connection_manager_has_protocol: * @self: a connection manager diff --git a/telepathy-glib/connection-manager.h b/telepathy-glib/connection-manager.h index 742edbe..478785c 100644 --- a/telepathy-glib/connection-manager.h +++ b/telepathy-glib/connection-manager.h @@ -155,6 +155,8 @@ const TpConnectionManagerProtocol *tp_connection_manager_get_protocol ( TpConnectionManager *self, const gchar *protocol); TpProtocol *tp_connection_manager_get_protocol_object ( TpConnectionManager *self, const gchar *protocol); +GList *tp_connection_manager_dup_protocols (TpConnectionManager *self) + G_GNUC_WARN_UNUSED_RESULT; gchar **tp_connection_manager_protocol_dup_param_names ( const TpConnectionManagerProtocol *protocol) diff --git a/tests/dbus/cm.c b/tests/dbus/cm.c index 31f4143..4586db8 100644 --- a/tests/dbus/cm.c +++ b/tests/dbus/cm.c @@ -191,6 +191,7 @@ test_nothing_got_info (Test *test, g_assert_cmpuint (test->cm->running, ==, FALSE); g_assert_cmpuint (test->cm->info_source, ==, TP_CM_INFO_SOURCE_NONE); g_assert (test->cm->protocols == NULL); + g_assert (tp_connection_manager_dup_protocols (test->cm) == NULL); } static void @@ -797,6 +798,7 @@ test_file_ready (Test *test, gchar *name; guint info_source; TestFlags flags = GPOINTER_TO_INT (data); + GList *l; test->error = NULL; test->cm = tp_connection_manager_new (test->dbus, "spurious", @@ -836,6 +838,11 @@ test_file_ready (Test *test, g_assert_cmpuint (info_source, ==, TP_CM_INFO_SOURCE_FILE); g_free (name); + l = tp_connection_manager_dup_protocols (test->cm); + g_assert_cmpuint (g_list_length (l), ==, 2); + g_assert (TP_IS_PROTOCOL (l->data)); + g_assert (TP_IS_PROTOCOL (l->next->data)); + g_list_free_full (l, g_object_unref); } static void @@ -899,6 +906,7 @@ test_dbus_ready (Test *test, gchar *name; guint info_source; const TestFlags flags = GPOINTER_TO_INT (data); + GList *l; test->error = NULL; test->cm = tp_connection_manager_new (test->dbus, @@ -953,6 +961,11 @@ test_dbus_ready (Test *test, g_assert_cmpstr (name, ==, "example_echo"); g_assert_cmpuint (info_source, ==, TP_CM_INFO_SOURCE_LIVE); g_free (name); + + l = tp_connection_manager_dup_protocols (test->cm); + g_assert_cmpuint (g_list_length (l), ==, 1); + g_assert_cmpstr (tp_protocol_get_name (l->data), ==, "example"); + g_list_free_full (l, g_object_unref); } static void -- 1.7.9.1