summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2019-12-22 11:12:59 +0100
committerNiels De Graef <nielsdegraef@gmail.com>2021-01-12 22:13:52 +0000
commit127d84b6174b39c444d7c55cb4b0933b090ea13b (patch)
treee1651aaf6240aab6224119da6ef1d7f9f6863079
parent96c0ef43fa7ea34e345241552912d9de3275e8af (diff)
downloadgcr-127d84b6174b39c444d7c55cb4b0933b090ea13b.tar.gz
gcr-console-interaction: Port to GTask
-rw-r--r--gcr/console-interaction.c55
1 files changed, 29 insertions, 26 deletions
diff --git a/gcr/console-interaction.c b/gcr/console-interaction.c
index bc3b7dc..47c2cb4 100644
--- a/gcr/console-interaction.c
+++ b/gcr/console-interaction.c
@@ -108,46 +108,49 @@ console_interaction_ask_password (GTlsInteraction *interaction,
}
static void
-ask_password_with_getpass (GSimpleAsyncResult *res,
- GObject *object,
- GCancellable *cancellable)
+ask_password_with_getpass (GTask *task,
+ gpointer src_object,
+ gpointer task_data,
+ GCancellable *cancellable)
{
GTlsPassword *password;
GError *error = NULL;
- password = g_simple_async_result_get_op_res_gpointer (res);
- console_interaction_ask_password (G_TLS_INTERACTION (object), password,
- cancellable, &error);
- if (error != NULL)
- g_simple_async_result_take_error (res, error);
+ password = g_task_get_task_data (task);
+ console_interaction_ask_password (G_TLS_INTERACTION (src_object), password,
+ cancellable, &error);
+ if (error == NULL)
+ g_task_return_boolean (task, TRUE);
+ else
+ g_task_return_error (task, g_steal_pointer (&error));
}
static void
console_interaction_ask_password_async (GTlsInteraction *interaction,
- GTlsPassword *password,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ GTlsPassword *password,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- GSimpleAsyncResult *res;
-
- res = g_simple_async_result_new (G_OBJECT (interaction), callback, user_data,
- console_interaction_ask_password);
- g_simple_async_result_set_op_res_gpointer (res, g_object_ref (password), g_object_unref);
- g_simple_async_result_run_in_thread (res, ask_password_with_getpass,
- G_PRIORITY_DEFAULT, cancellable);
- g_object_unref (res);
+ GTask *task;
+
+ task = g_task_new (interaction, cancellable, callback, user_data);
+ g_task_set_source_tag (task, console_interaction_ask_password);
+ g_task_set_task_data (task, g_object_ref (password), g_object_unref);
+
+ g_task_run_in_thread (task, ask_password_with_getpass);
+ g_clear_object (&task);
}
static GTlsInteractionResult
-console_interaction_ask_password_finish (GTlsInteraction *interaction,
- GAsyncResult *result,
- GError **error)
+console_interaction_ask_password_finish (GTlsInteraction *interaction,
+ GAsyncResult *result,
+ GError **error)
{
- g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (interaction),
- console_interaction_ask_password), G_TLS_INTERACTION_FAILED);
+ g_return_val_if_fail (g_task_is_valid (result, interaction),
+ G_TLS_INTERACTION_FAILED);
- if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
+ if (!g_task_propagate_boolean (G_TASK (result), error))
return G_TLS_INTERACTION_FAILED;
return G_TLS_INTERACTION_HANDLED;