From d50e5820d9042a85a94daad8cb1a98ff25c77b4a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 8 Mar 2012 13:32:23 +0000 Subject: [PATCH 6/7] tp_account_update_parameters_vardict_async: add Bug: https://bugs.freedesktop.org/show_bug.cgi?id=30422 --- docs/reference/telepathy-glib-sections.txt | 2 + telepathy-glib/account.c | 68 ++++++++++++++++++++++++++++ telepathy-glib/account.h | 6 ++- tests/dbus/account.c | 38 +++++++++++---- 4 files changed, 103 insertions(+), 11 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 0fb0a5e..cc7afea 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -5065,6 +5065,8 @@ tp_account_is_enabled tp_account_is_valid tp_account_update_parameters_async tp_account_update_parameters_finish +tp_account_update_parameters_vardict_async +tp_account_update_parameters_vardict_finish tp_account_remove_async tp_account_remove_finish tp_account_set_display_name_async diff --git a/telepathy-glib/account.c b/telepathy-glib/account.c index 2ff7f85..6a3b7b8 100644 --- a/telepathy-glib/account.c +++ b/telepathy-glib/account.c @@ -2752,6 +2752,74 @@ tp_account_update_parameters_finish (TpAccount *account, } /** + * tp_account_update_parameters_vardict_async: + * @account: a #TpAccount + * @parameters: (transfer none): a variant of type %G_VARIANT_TYPE_VARDICT + * containing new parameters to set on @account + * @unset_parameters: list of parameters to unset on @account + * @callback: a callback to call when the request is satisfied + * @user_data: data to pass to @callback + * + * Requests an asynchronous update of parameters of @account. When the + * operation is finished, @callback will be called. You can then call + * tp_account_update_parameters_finish() to get the result of the operation. + * + * If @parameters is a floating reference (see g_variant_ref_sink()), + * ownership of @parameters is taken by this function. This means + * you can pass the result of g_variant_new() or g_variant_new_parsed() + * directly to this function without additional reference-count management. + * + * Since: 0.UNRELEASED + */ +void +tp_account_update_parameters_vardict_async (TpAccount *account, + GVariant *parameters, + const gchar **unset_parameters, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GValue v = G_VALUE_INIT; + + g_return_if_fail (parameters != NULL); + g_return_if_fail (g_variant_is_of_type (parameters, G_VARIANT_TYPE_VARDICT)); + + g_variant_ref_sink (parameters); + + dbus_g_value_parse_g_variant (parameters, &v); + g_assert (G_VALUE_HOLDS (&v, TP_HASH_TYPE_STRING_VARIANT_MAP)); + + tp_account_update_parameters_async (account, g_value_get_boxed (&v), + unset_parameters, callback, user_data); + g_value_unset (&v); + g_variant_unref (parameters); +} + +/** + * tp_account_update_parameters_vardict_finish: + * @account: a #TpAccount + * @result: a #GAsyncResult + * @reconnect_required: (out) (type GObject.Strv) (transfer full): a #GStrv to + * fill with properties that need a reconnect to take effect + * @error: a #GError to fill + * + * Finishes an async update of the parameters on @account. + * + * Returns: %TRUE if the request succeeded, otherwise %FALSE + * + * Since: 0.UNRELEASED + */ +gboolean +tp_account_update_parameters_vardict_finish (TpAccount *account, + GAsyncResult *result, + gchar ***reconnect_required, + GError **error) +{ + /* share an implementation with the non-vardict version */ + return tp_account_update_parameters_finish (account, result, + reconnect_required, error); +} + +/** * tp_account_set_display_name_async: * @account: a #TpAccount * @display_name: a new display name, or %NULL to unset the display name diff --git a/telepathy-glib/account.h b/telepathy-glib/account.h index 4b38fbc..79878cd 100644 --- a/telepathy-glib/account.h +++ b/telepathy-glib/account.h @@ -125,9 +125,13 @@ gboolean tp_account_is_valid (TpAccount *account); void tp_account_update_parameters_async (TpAccount *account, GHashTable *parameters, const gchar **unset_parameters, GAsyncReadyCallback callback, gpointer user_data); - gboolean tp_account_update_parameters_finish (TpAccount *account, GAsyncResult *result, gchar ***reconnect_required, GError **error); +void tp_account_update_parameters_vardict_async (TpAccount *account, + GVariant *parameters, const gchar **unset_parameters, + GAsyncReadyCallback callback, gpointer user_data); +gboolean tp_account_update_parameters_vardict_finish (TpAccount *account, + GAsyncResult *result, gchar ***reconnect_required, GError **error); void tp_account_remove_async (TpAccount *account, GAsyncReadyCallback callback, gpointer user_data); diff --git a/tests/dbus/account.c b/tests/dbus/account.c index a272da0..11e4dd4 100644 --- a/tests/dbus/account.c +++ b/tests/dbus/account.c @@ -257,22 +257,38 @@ test_setters (Test *test, static void test_reconnect (Test *test, - gconstpointer data G_GNUC_UNUSED) + gconstpointer data) { - GHashTable *set = tp_asv_new ( - "set", G_TYPE_STRING, "value", - NULL); - const gchar *unset[] = { "unset", NULL }; GStrv reconnect_required; + const gchar *unset[] = { "unset", NULL }; test->account = tp_account_new (test->dbus, ACCOUNT_PATH, NULL); g_assert (test->account != NULL); - tp_account_update_parameters_async (test->account, set, unset, - tp_tests_result_ready_cb, &test->result); - tp_tests_run_until_result (&test->result); - tp_account_update_parameters_finish (test->account, test->result, - &reconnect_required, &test->error); + if (!tp_strdiff (data, "vardict")) + { + tp_account_update_parameters_vardict_async (test->account, + g_variant_new_parsed ("{ 'set': <%s> }", "value"), unset, + tp_tests_result_ready_cb, &test->result); + tp_tests_run_until_result (&test->result); + tp_account_update_parameters_vardict_finish (test->account, test->result, + &reconnect_required, &test->error); + } + else + { + GHashTable *set = tp_asv_new ( + "set", G_TYPE_STRING, "value", + NULL); + + tp_account_update_parameters_async (test->account, set, unset, + tp_tests_result_ready_cb, &test->result); + tp_tests_run_until_result (&test->result); + tp_account_update_parameters_finish (test->account, test->result, + &reconnect_required, &test->error); + + g_hash_table_unref (set); + } + g_assert_no_error (test->error); /* check that reconnect_required survives longer than result */ tp_clear_object (&test->result); @@ -888,6 +904,8 @@ main (int argc, g_test_add ("/account/reconnect", Test, NULL, setup_service, test_reconnect, teardown_service); + g_test_add ("/account/reconnect", Test, "vardict", setup_service, + test_reconnect, teardown_service); g_test_add ("/account/prepare/success", Test, NULL, setup_service, test_prepare_success, teardown_service); -- 1.7.9.1