From 90c75bb55acf671b911abe0beef8e2555f9c1834 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 13 Nov 2013 17:06:31 +0000 Subject: [PATCH 10/26] mcd_account_delete: convert into mcd_account_delete_async --- src/mcd-account-manager.c | 49 ++++++++++++++++++++++++++++++------------- src/mcd-account.c | 53 +++++++++++++++++++++++++++++++---------------- src/mcd-account.h | 14 ++++++------- 3 files changed, 77 insertions(+), 39 deletions(-) diff --git a/src/mcd-account-manager.c b/src/mcd-account-manager.c index 806f38f..f158292 100644 --- a/src/mcd-account-manager.c +++ b/src/mcd-account-manager.c @@ -367,11 +367,27 @@ reconnect_cb (GObject *plugin, const gchar *name, gpointer data) } static void -_mcd_account_delete_cb (McdAccount *account, const GError *error, gpointer data) +mcd_account_delete_debug_cb (GObject *source, + GAsyncResult *res, + gpointer user_data) { - /* no need to do anything other than release the account ref, which * - * should be the last ref we hold by the time this rolls arouns: */ - g_object_unref (account); + McdAccount *account = MCD_ACCOUNT (source); + GError *error = NULL; + + if (mcd_account_delete_finish (account, res, &error)) + { + DEBUG ("successfully deleted account %s (%s)", + mcd_account_get_unique_name (account), + (const gchar *) user_data); + } + else + { + WARNING ("could not delete account %s (%s): %s #%d: %s", + mcd_account_get_unique_name (account), + (const gchar *) user_data, + g_quark_to_string (error->domain), error->code, error->message); + g_clear_error (&error); + } } /* a backend plugin notified us that an account was vaporised: remove it */ @@ -395,9 +411,11 @@ deleted_cb (GObject *plugin, const gchar *name, gpointer data) /* this unhooks the account's signal handlers */ g_hash_table_remove (manager->priv->accounts, name); tp_svc_account_manager_emit_account_removed (manager, object_path); - mcd_account_delete (account, - MCD_DBUS_PROP_SET_FLAG_ALREADY_IN_STORAGE, - _mcd_account_delete_cb, NULL); + mcd_account_delete_async (account, + MCD_DBUS_PROP_SET_FLAG_ALREADY_IN_STORAGE, + mcd_account_delete_debug_cb, + "in response to McpAccountStorage::deleted"); + g_object_unref (account); } } @@ -708,8 +726,10 @@ complete_account_creation_finish (McdAccount *account, if (!cad->ok) { - mcd_account_delete (account, MCD_DBUS_PROP_SET_FLAG_NONE, - NULL, NULL); + mcd_account_delete_async (account, + MCD_DBUS_PROP_SET_FLAG_NONE, + mcd_account_delete_debug_cb, + "while recovering from failure to create"); tp_clear_object (&account); } @@ -1133,12 +1153,13 @@ migrate_ctx_free (MigrateCtx *ctx) static void -migrate_delete_account_cb (McdAccount *account, - const GError *error, - gpointer user_data) +migrate_delete_account_cb (GObject *source, + GAsyncResult *res, + gpointer user_data) { MigrateCtx *ctx = user_data; + mcd_account_delete_debug_cb (source, res, "after migrating it"); migrate_ctx_free (ctx); } @@ -1162,8 +1183,8 @@ migrate_create_account_cb (McdAccountManager *account_manager, DEBUG ("Account %s migrated, removing it", mcd_account_get_unique_name (ctx->account)); - mcd_account_delete (ctx->account, MCD_DBUS_PROP_SET_FLAG_NONE, - migrate_delete_account_cb, ctx); + mcd_account_delete_async (ctx->account, MCD_DBUS_PROP_SET_FLAG_NONE, + migrate_delete_account_cb, ctx); } static void diff --git a/src/mcd-account.c b/src/mcd-account.c index e5763a4..c1cae82 100644 --- a/src/mcd-account.c +++ b/src/mcd-account.c @@ -674,16 +674,19 @@ static TpStorageRestrictionFlags mcd_account_get_storage_restrictions ( McdAccount *account); void -mcd_account_delete (McdAccount *account, - McdDBusPropSetFlags flags, - McdAccountDeleteCb callback, - gpointer user_data) +mcd_account_delete_async (McdAccount *account, + McdDBusPropSetFlags flags, + GAsyncReadyCallback callback, + gpointer user_data) { McdAccountPrivate *priv = account->priv; gchar *data_dir_str; GError *error = NULL; const gchar *name = mcd_account_get_unique_name (account); TpConnectionManager *cm = mcd_account_get_cm (account); + GTask *task; + + task = g_task_new (account, NULL, callback, user_data); /* We don't really have a flag for "cannot delete accounts" yet, but * it seems reasonable that if you can't disable it or put it @@ -694,16 +697,18 @@ mcd_account_delete (McdAccount *account, (TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED | TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PRESENCE)) != 0) { - g_set_error (&error, TP_ERROR, TP_ERROR_PERMISSION_DENIED, + g_task_return_new_error (task, TP_ERROR, TP_ERROR_PERMISSION_DENIED, "Storage plugin for %s does not allow deleting it", name); - callback (account, error, user_data); - g_error_free (error); + g_object_unref (task); return; } - /* if the CM implements CM.I.AccountStorage, we need to tell the CM - * to forget any account credentials it knows */ + /* If the CM implements CM.I.AccountStorage, we need to tell the CM + * to forget any account credentials it knows. + * + * FIXME: put this in the main flow rather than doing it async and + * throwing away its result? */ if (tp_proxy_has_interface_by_id (cm, MC_IFACE_QUARK_CONNECTION_MANAGER_INTERFACE_ACCOUNT_STORAGE)) { @@ -728,8 +733,8 @@ mcd_account_delete (McdAccount *account, flags, &error)) { g_warning ("could not disable account %s (%s)", name, error->message); - callback (account, error, user_data); - g_error_free (error); + g_task_return_error (task, error); + g_object_unref (task); return; } @@ -769,8 +774,18 @@ mcd_account_delete (McdAccount *account, tp_svc_account_emit_removed (account); } - if (callback != NULL) - callback (account, NULL, user_data); + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +gboolean +mcd_account_delete_finish (McdAccount *self, + GAsyncResult *result, + GError **error) +{ + g_return_val_if_fail (g_task_is_valid (result, self), NULL); + + return g_task_propagate_boolean (G_TASK (result), error); } void @@ -2424,14 +2439,17 @@ typedef struct } RemoveMethodData; static void -account_remove_delete_cb (McdAccount *account, const GError *error, +account_remove_delete_cb (GObject *source, + GAsyncResult *res, gpointer user_data) { RemoveMethodData *data = (RemoveMethodData *) user_data; + GError *error = NULL; - if (error != NULL) + if (!mcd_account_delete_finish (MCD_ACCOUNT (source), res, &error)) { dbus_g_method_return_error (data->context, (GError *) error); + g_error_free (error); return; } @@ -2439,7 +2457,6 @@ account_remove_delete_cb (McdAccount *account, const GError *error, g_warn_if_fail (data->self->priv->removed); tp_svc_account_return_from_remove (data->context); - g_slice_free (RemoveMethodData, data); } @@ -2454,8 +2471,8 @@ account_remove (TpSvcAccount *svc, DBusGMethodInvocation *context) data->context = context; DEBUG ("called"); - mcd_account_delete (self, MCD_DBUS_PROP_SET_FLAG_NONE, - account_remove_delete_cb, data); + mcd_account_delete_async (self, MCD_DBUS_PROP_SET_FLAG_NONE, + account_remove_delete_cb, data); } /* diff --git a/src/mcd-account.h b/src/mcd-account.h index 3aad723..edb8da0 100644 --- a/src/mcd-account.h +++ b/src/mcd-account.h @@ -61,9 +61,6 @@ GQuark mcd_account_error_quark (void); typedef void (*McdAccountLoadCb) (McdAccount *account, const GError *error, gpointer user_data); -typedef void (*McdAccountDeleteCb) (McdAccount *account, - const GError *error, - gpointer user_data); struct _McdAccountClass { @@ -85,10 +82,13 @@ McdAccount *mcd_account_new (McdAccountManager *account_manager, const gchar *name, McdConnectivityMonitor *minotaur); -void mcd_account_delete (McdAccount *account, - McdDBusPropSetFlags flags, - McdAccountDeleteCb callback, - gpointer user_data); +void mcd_account_delete_async (McdAccount *account, + McdDBusPropSetFlags flags, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean mcd_account_delete_finish (McdAccount *account, + GAsyncResult *result, + GError **error); const gchar *mcd_account_get_unique_name (McdAccount *account); const gchar *mcd_account_get_object_path (McdAccount *account); -- 1.8.4.3