[evolution-data-server] CamelSasl: Port to GTask.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] CamelSasl: Port to GTask.
- Date: Tue, 3 Dec 2013 16:45:34 +0000 (UTC)
commit 05299668e627392d9afe6d28d41501815cdbf462
Author: Matthew Barnes <mbarnes redhat com>
Date: Mon Dec 2 14:56:38 2013 -0500
CamelSasl: Port to GTask.
camel/camel-sasl.c | 210 +++++++++++++++++++++++-----------------------------
1 files changed, 93 insertions(+), 117 deletions(-)
---
diff --git a/camel/camel-sasl.c b/camel/camel-sasl.c
index 137729b..ad6c019 100644
--- a/camel/camel-sasl.c
+++ b/camel/camel-sasl.c
@@ -55,13 +55,8 @@ struct _CamelSaslPrivate {
};
struct _AsyncContext {
- /* arguments */
GByteArray *token;
gchar *base64_token;
-
- /* results */
- GByteArray *response;
- gchar *base64_response;
};
enum {
@@ -80,11 +75,7 @@ async_context_free (AsyncContext *async_context)
if (async_context->token != NULL)
g_byte_array_free (async_context->token, TRUE);
- if (async_context->response != NULL)
- g_byte_array_free (async_context->response, TRUE);
-
g_free (async_context->base64_token);
- g_free (async_context->base64_response);
g_slice_free (AsyncContext, async_context);
}
@@ -438,19 +429,23 @@ camel_sasl_try_empty_password_sync (CamelSasl *sasl,
/* Helpder for camel_sasl_try_empty_password() */
static void
-sasl_try_empty_password_thread (GSimpleAsyncResult *simple,
- GObject *object,
+sasl_try_empty_password_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable)
{
- gboolean res;
- GError *error = NULL;
+ gboolean result;
+ GError *local_error = NULL;
- res = camel_sasl_try_empty_password_sync (
- CAMEL_SASL (object), cancellable, &error);
- g_simple_async_result_set_op_res_gboolean (simple, res);
+ result = camel_sasl_try_empty_password_sync (
+ CAMEL_SASL (source_object),
+ cancellable, &local_error);
- if (error != NULL)
- g_simple_async_result_take_error (simple, error);
+ if (local_error != NULL) {
+ g_task_return_error (task, local_error);
+ } else {
+ g_task_return_boolean (task, result);
+ }
}
/**
@@ -477,21 +472,17 @@ camel_sasl_try_empty_password (CamelSasl *sasl,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *simple;
+ GTask *task;
g_return_if_fail (CAMEL_IS_SASL (sasl));
- simple = g_simple_async_result_new (
- G_OBJECT (sasl), callback, user_data,
- camel_sasl_try_empty_password);
+ task = g_task_new (sasl, cancellable, callback, user_data);
+ g_task_set_source_tag (task, camel_sasl_try_empty_password);
+ g_task_set_priority (task, io_priority);
- g_simple_async_result_set_check_cancellable (simple, cancellable);
+ g_task_run_in_thread (task, sasl_try_empty_password_thread);
- g_simple_async_result_run_in_thread (
- simple, sasl_try_empty_password_thread,
- io_priority, cancellable);
-
- g_object_unref (simple);
+ g_object_unref (task);
}
/**
@@ -511,19 +502,14 @@ camel_sasl_try_empty_password_finish (CamelSasl *sasl,
GAsyncResult *result,
GError **error)
{
- GSimpleAsyncResult *simple;
+ g_return_val_if_fail (CAMEL_IS_SASL (sasl), FALSE);
+ g_return_val_if_fail (g_task_is_valid (result, sasl), FALSE);
g_return_val_if_fail (
- g_simple_async_result_is_valid (
- result, G_OBJECT (sasl),
- camel_sasl_try_empty_password), FALSE);
-
- simple = G_SIMPLE_ASYNC_RESULT (result);
-
- if (g_simple_async_result_propagate_error (simple, error))
- return FALSE;
+ g_async_result_is_tagged (
+ result, camel_sasl_try_empty_password), FALSE);
- return g_simple_async_result_get_op_res_gboolean (simple);
+ return g_task_propagate_boolean (G_TASK (result), error);
}
/**
@@ -630,21 +616,30 @@ camel_sasl_challenge_sync (CamelSasl *sasl,
/* Helper for camel_sasl_challenge() */
static void
-sasl_challenge_thread (GSimpleAsyncResult *simple,
- GObject *object,
+sasl_challenge_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable)
{
+ GByteArray *response;
AsyncContext *async_context;
- GError *error = NULL;
-
- async_context = g_simple_async_result_get_op_res_gpointer (simple);
-
- async_context->response = camel_sasl_challenge_sync (
- CAMEL_SASL (object), async_context->token,
- cancellable, &error);
-
- if (error != NULL)
- g_simple_async_result_take_error (simple, error);
+ GError *local_error = NULL;
+
+ async_context = (AsyncContext *) task_data;
+
+ response = camel_sasl_challenge_sync (
+ CAMEL_SASL (source_object),
+ async_context->token,
+ cancellable, &local_error);
+
+ if (local_error != NULL) {
+ g_warn_if_fail (response == NULL);
+ g_task_return_error (task, local_error);
+ } else {
+ g_task_return_pointer (
+ task, response,
+ (GDestroyNotify) g_byte_array_unref);
+ }
}
/**
@@ -674,7 +669,7 @@ camel_sasl_challenge (CamelSasl *sasl,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *simple;
+ GTask *task;
AsyncContext *async_context;
g_return_if_fail (CAMEL_IS_SASL (sasl));
@@ -684,19 +679,17 @@ camel_sasl_challenge (CamelSasl *sasl,
g_byte_array_append (async_context->token, token->data, token->len);
- simple = g_simple_async_result_new (
- G_OBJECT (sasl), callback, user_data,
- camel_sasl_challenge);
+ task = g_task_new (sasl, cancellable, callback, user_data);
+ g_task_set_source_tag (task, camel_sasl_challenge);
+ g_task_set_priority (task, io_priority);
- g_simple_async_result_set_check_cancellable (simple, cancellable);
+ g_task_set_task_data (
+ task, async_context,
+ (GDestroyNotify) async_context_free);
- g_simple_async_result_set_op_res_gpointer (
- simple, async_context, (GDestroyNotify) async_context_free);
+ g_task_run_in_thread (task, sasl_challenge_thread);
- g_simple_async_result_run_in_thread (
- simple, sasl_challenge_thread, io_priority, cancellable);
-
- g_object_unref (simple);
+ g_object_unref (task);
}
/**
@@ -718,24 +711,14 @@ camel_sasl_challenge_finish (CamelSasl *sasl,
GAsyncResult *result,
GError **error)
{
- GSimpleAsyncResult *simple;
- AsyncContext *async_context;
- GByteArray *response;
+ g_return_val_if_fail (CAMEL_IS_SASL (sasl), NULL);
+ g_return_val_if_fail (g_task_is_valid (result, sasl), NULL);
g_return_val_if_fail (
- g_simple_async_result_is_valid (
- result, G_OBJECT (sasl), camel_sasl_challenge), NULL);
+ g_async_result_is_tagged (
+ result, camel_sasl_challenge), NULL);
- simple = G_SIMPLE_ASYNC_RESULT (result);
- async_context = g_simple_async_result_get_op_res_gpointer (simple);
-
- if (g_simple_async_result_propagate_error (simple, error))
- return NULL;
-
- response = async_context->response;
- async_context->response = NULL;
-
- return response;
+ return g_task_propagate_pointer (G_TASK (result), error);
}
/**
@@ -795,21 +778,30 @@ camel_sasl_challenge_base64_sync (CamelSasl *sasl,
/* Helper for camel_sasl_challenge_base64() */
static void
-sasl_challenge_base64_thread (GSimpleAsyncResult *simple,
- GObject *object,
+sasl_challenge_base64_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable)
{
+ gchar *base64_response;
AsyncContext *async_context;
- GError *error = NULL;
-
- async_context = g_simple_async_result_get_op_res_gpointer (simple);
-
- async_context->base64_response = camel_sasl_challenge_base64_sync (
- CAMEL_SASL (object), async_context->base64_token,
- cancellable, &error);
-
- if (error != NULL)
- g_simple_async_result_take_error (simple, error);
+ GError *local_error = NULL;
+
+ async_context = (AsyncContext *) task_data;
+
+ base64_response = camel_sasl_challenge_base64_sync (
+ CAMEL_SASL (source_object),
+ async_context->base64_token,
+ cancellable, &local_error);
+
+ if (local_error != NULL) {
+ g_warn_if_fail (base64_response == NULL);
+ g_task_return_error (task, local_error);
+ } else {
+ g_task_return_pointer (
+ task, base64_response,
+ (GDestroyNotify) g_free);
+ }
}
/**
@@ -838,7 +830,7 @@ camel_sasl_challenge_base64 (CamelSasl *sasl,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *simple;
+ GTask *task;
AsyncContext *async_context;
g_return_if_fail (CAMEL_IS_SASL (sasl));
@@ -846,20 +838,17 @@ camel_sasl_challenge_base64 (CamelSasl *sasl,
async_context = g_slice_new0 (AsyncContext);
async_context->base64_token = g_strdup (token);
- simple = g_simple_async_result_new (
- G_OBJECT (sasl), callback, user_data,
- camel_sasl_challenge_base64);
+ task = g_task_new (sasl, cancellable, callback, user_data);
+ g_task_set_source_tag (task, camel_sasl_challenge_base64);
+ g_task_set_priority (task, io_priority);
- g_simple_async_result_set_check_cancellable (simple, cancellable);
+ g_task_set_task_data (
+ task, async_context,
+ (GDestroyNotify) async_context_free);
- g_simple_async_result_set_op_res_gpointer (
- simple, async_context, (GDestroyNotify) async_context_free);
+ g_task_run_in_thread (task, sasl_challenge_base64_thread);
- g_simple_async_result_run_in_thread (
- simple, sasl_challenge_base64_thread,
- io_priority, cancellable);
-
- g_object_unref (simple);
+ g_object_unref (task);
}
/**
@@ -879,27 +868,14 @@ camel_sasl_challenge_base64_finish (CamelSasl *sasl,
GAsyncResult *result,
GError **error)
{
- GSimpleAsyncResult *simple;
- AsyncContext *async_context;
- gchar *response;
-
g_return_val_if_fail (CAMEL_IS_SASL (sasl), NULL);
- g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
+ g_return_val_if_fail (g_task_is_valid (result, sasl), NULL);
g_return_val_if_fail (
- g_simple_async_result_is_valid (
- result, G_OBJECT (sasl), camel_sasl_challenge_base64), NULL);
-
- simple = G_SIMPLE_ASYNC_RESULT (result);
- async_context = g_simple_async_result_get_op_res_gpointer (simple);
+ g_async_result_is_tagged (
+ result, camel_sasl_challenge_base64), NULL);
- if (g_simple_async_result_propagate_error (simple, error))
- return NULL;
-
- response = async_context->base64_response;
- async_context->base64_response = NULL;
-
- return response;
+ return g_task_propagate_pointer (G_TASK (result), error);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]