From 7d19a594042efce3db283c9d3c90cbcf6f2bbd83 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 7 Mar 2012 14:23:16 +0000 Subject: [PATCH 08/10] tp_protocol_dup_params, tp_protocol_dup_param, tp_protocol_borrow_params: add tp_protocol_dup_params might be less nice for C (you have to free the list and the items), but is definitely nicer for Python and other g-i bindings. It will probably be renamed to ...get_params in Telepathy 1.0. tp_protocol_borrow_params is an efficient "C binding", but not as GObject'y. tp_protocol_dup_param will replace get_param in Telepathy 1.0. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=46358 Signed-off-by: Simon McVittie --- docs/reference/telepathy-glib-sections.txt | 3 + telepathy-glib/protocol.c | 79 ++++++++++++++++++++++++++++ telepathy-glib/protocol.h | 5 ++ tests/dbus/protocol-objects.c | 22 ++++++++ 4 files changed, 109 insertions(+), 0 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index c1280b5..46ea52f 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -5886,8 +5886,11 @@ tp_protocol_get_name tp_protocol_init_known_interfaces TP_PROTOCOL_FEATURE_PARAMETERS +tp_protocol_borrow_params +tp_protocol_dup_params tp_protocol_dup_param_names tp_protocol_get_param +tp_protocol_dup_param tp_protocol_has_param tp_protocol_can_register diff --git a/telepathy-glib/protocol.c b/telepathy-glib/protocol.c index 0c94250..3b95849 100644 --- a/telepathy-glib/protocol.c +++ b/telepathy-glib/protocol.c @@ -877,6 +877,7 @@ tp_protocol_has_param (TpProtocol *self, return (tp_protocol_get_param (self, param) != NULL); } +/* FIXME: in Telepathy 1.0, rename to tp_protocol_borrow_param or remove */ /** * tp_protocol_get_param: * @self: a protocol @@ -897,6 +898,30 @@ const TpConnectionManagerParam *tp_protocol_get_param (TpProtocol *self, &self->priv->protocol_struct, param); } +/* FIXME: in Telepathy 1.0, rename to tp_protocol_get_param */ +/** + * tp_protocol_dup_param: + * @self: a protocol + * @param: a parameter name + * + * + * + * Returns: (transfer full): a structure representing the parameter @param, + * or %NULL if not supported. Free with tp_connection_manager_param_free() + * + * Since: 0.UNRELEASED + */ +TpConnectionManagerParam * +tp_protocol_dup_param (TpProtocol *self, + const gchar *param) +{ + g_return_val_if_fail (TP_IS_PROTOCOL (self), NULL); + + return tp_connection_manager_param_copy ( + tp_connection_manager_protocol_get_param ( + &self->priv->protocol_struct, param)); +} + /** * tp_protocol_can_register: * @self: a protocol @@ -937,6 +962,60 @@ tp_protocol_dup_param_names (TpProtocol *self) } /** + * tp_protocol_borrow_params: (skip) + * @self: a protocol + * + * Returns an array of parameters supported by this connection manager, + * without additional memory allocations. The returned array is owned by + * @self, and must not be used after @self has been freed. + * + * Returns: (transfer none): an array of #TpConnectionManagerParam structures, + * terminated by one whose @name is %NULL + * + * Since: 0.UNRELEASED + */ +const TpConnectionManagerParam * +tp_protocol_borrow_params (TpProtocol *self) +{ + g_return_val_if_fail (TP_IS_PROTOCOL (self), NULL); + + return self->priv->protocol_struct.params; +} + +/** + * tp_protocol_dup_params: + * @self: a protocol + * + * Returns a list of parameters supported by this connection manager. + * + * The returned list must be freed by the caller, for instance with + * g_list_free_full (l, + * (GDestroyNotify) tp_connection_manager_param_free). + * + * Returns: (transfer full) (element-type TelepathyGLib.ConnectionManagerParam): + * a list of #TpConnectionManagerParam structures, owned by the caller + * + * Since: 0.UNRELEASED + */ +GList * +tp_protocol_dup_params (TpProtocol *self) +{ + guint i; + GList *ret = NULL; + + g_return_val_if_fail (TP_IS_PROTOCOL (self), NULL); + + for (i = 0; self->priv->protocol_struct.params[i].name != NULL; i++) + { + ret = g_list_prepend (ret, + tp_connection_manager_param_copy ( + &(self->priv->protocol_struct.params[i]))); + } + + return g_list_reverse (ret); +} + +/** * tp_protocol_get_vcard_field: * @self: a protocol object * diff --git a/telepathy-glib/protocol.h b/telepathy-glib/protocol.h index 8b25390..c73babd 100644 --- a/telepathy-glib/protocol.h +++ b/telepathy-glib/protocol.h @@ -85,10 +85,15 @@ GQuark tp_protocol_get_feature_quark_parameters (void) G_GNUC_CONST; const TpConnectionManagerParam *tp_protocol_get_param (TpProtocol *self, const gchar *param); +TpConnectionManagerParam *tp_protocol_dup_param (TpProtocol *self, + const gchar *param); gboolean tp_protocol_has_param (TpProtocol *self, const gchar *param); gboolean tp_protocol_can_register (TpProtocol *self); GStrv tp_protocol_dup_param_names (TpProtocol *self) G_GNUC_WARN_UNUSED_RESULT; +GList *tp_protocol_dup_params (TpProtocol *self) G_GNUC_WARN_UNUSED_RESULT; +const TpConnectionManagerParam *tp_protocol_borrow_params (TpProtocol *self) + G_GNUC_WARN_UNUSED_RESULT; const gchar * const * /* gtk-doc sucks */ diff --git a/tests/dbus/protocol-objects.c b/tests/dbus/protocol-objects.c index 819b641..df78eb5 100644 --- a/tests/dbus/protocol-objects.c +++ b/tests/dbus/protocol-objects.c @@ -388,6 +388,8 @@ test_protocol_object (Test *test, gconstpointer data G_GNUC_UNUSED) { TpAvatarRequirements *req; + GList *l; + TpConnectionManagerParam *param; g_assert_cmpstr (tp_connection_manager_get_name (test->cm), ==, "example_echo_2"); @@ -424,6 +426,26 @@ test_protocol_object (Test *test, g_object_get (test->protocol, "avatar-requirements", &req, NULL); check_avatar_requirements (req); + + l = tp_protocol_dup_params (test->protocol); + g_assert_cmpuint (g_list_length (l), ==, 1); + param = l->data; + g_assert_cmpstr (param->name, ==, "account"); + g_list_free_full (l, (GDestroyNotify) tp_connection_manager_param_free); + + g_assert_cmpstr (tp_protocol_get_param (test->protocol, "account")->name, ==, + "account"); + + param = tp_protocol_dup_param (test->protocol, "account"); + /* it's a copy */ + g_assert (param != tp_protocol_get_param (test->protocol, "account")); + g_assert_cmpstr (param->name, ==, "account"); + tp_connection_manager_param_free (param); + + g_assert_cmpstr (tp_protocol_borrow_params (test->protocol)[0].name, ==, + "account"); + g_assert_cmpstr (tp_protocol_borrow_params (test->protocol)[1].name, ==, + NULL); } static void -- 1.7.9.1