[evolution-data-server] CamelSession: Remove all asynchronous class methods.



commit eea07284fa0f437bcb87fdafbeb36bed0207bd96
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Dec 2 15:27:56 2013 -0500

    CamelSession: Remove all asynchronous class methods.
    
    For consistency with CamelStore, CamelFolder, etc.

 camel/camel-session.c |  336 +++++++++++++++++++-----------------------------
 camel/camel-session.h |   24 +----
 2 files changed, 135 insertions(+), 225 deletions(-)
---
diff --git a/camel/camel-session.c b/camel/camel-session.c
index b0f18d5..69320cd 100644
--- a/camel/camel-session.c
+++ b/camel/camel-session.c
@@ -573,77 +573,6 @@ retry:
        return (result == CAMEL_AUTHENTICATION_ACCEPTED);
 }
 
-static void
-session_authenticate_thread (GSimpleAsyncResult *simple,
-                             GObject *object,
-                             GCancellable *cancellable)
-{
-       AsyncContext *async_context;
-       GError *error = NULL;
-
-       async_context = g_simple_async_result_get_op_res_gpointer (simple);
-
-       if (!camel_session_authenticate_sync (
-               CAMEL_SESSION (object),
-               async_context->service,
-               async_context->auth_mechanism,
-               cancellable, &error)) {
-
-               if (!error)
-                       error = g_error_new_literal (CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("Unknown error"));
-       }
-
-       if (error != NULL)
-               g_simple_async_result_take_error (simple, error);
-}
-
-static void
-session_authenticate (CamelSession *session,
-                      CamelService *service,
-                      const gchar *mechanism,
-                      gint io_priority,
-                      GCancellable *cancellable,
-                      GAsyncReadyCallback callback,
-                      gpointer user_data)
-{
-       GSimpleAsyncResult *simple;
-       AsyncContext *async_context;
-
-       async_context = g_slice_new0 (AsyncContext);
-       async_context->service = g_object_ref (service);
-       async_context->auth_mechanism = g_strdup (mechanism);
-
-       simple = g_simple_async_result_new (
-               G_OBJECT (session), callback, user_data, session_authenticate);
-
-       g_simple_async_result_set_check_cancellable (simple, cancellable);
-
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_context, (GDestroyNotify) async_context_free);
-
-       g_simple_async_result_run_in_thread (
-               simple, session_authenticate_thread, io_priority, cancellable);
-
-       g_object_unref (simple);
-}
-
-static gboolean
-session_authenticate_finish (CamelSession *session,
-                             GAsyncResult *result,
-                             GError **error)
-{
-       GSimpleAsyncResult *simple;
-
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (session), session_authenticate), FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-
-       /* Assume success unless a GError is set. */
-       return !g_simple_async_result_propagate_error (simple, error);
-}
-
 static gboolean
 session_forward_to_sync (CamelSession *session,
                          CamelFolder *folder,
@@ -660,76 +589,6 @@ session_forward_to_sync (CamelSession *session,
 }
 
 static void
-session_forward_to_thread (GSimpleAsyncResult *simple,
-                           GObject *object,
-                           GCancellable *cancellable)
-{
-       AsyncContext *async_context;
-       GError *error = NULL;
-
-       async_context = g_simple_async_result_get_op_res_gpointer (simple);
-
-       camel_session_forward_to_sync (
-               CAMEL_SESSION (object),
-               async_context->folder,
-               async_context->message,
-               async_context->address,
-               cancellable, &error);
-
-       if (error != NULL)
-               g_simple_async_result_take_error (simple, error);
-}
-
-static void
-session_forward_to (CamelSession *session,
-                    CamelFolder *folder,
-                    CamelMimeMessage *message,
-                    const gchar *address,
-                    gint io_priority,
-                    GCancellable *cancellable,
-                    GAsyncReadyCallback callback,
-                    gpointer user_data)
-{
-       GSimpleAsyncResult *simple;
-       AsyncContext *async_context;
-
-       async_context = g_slice_new0 (AsyncContext);
-       async_context->folder = g_object_ref (folder);
-       async_context->message = g_object_ref (message);
-       async_context->address = g_strdup (address);
-
-       simple = g_simple_async_result_new (
-               G_OBJECT (session), callback, user_data, session_forward_to);
-
-       g_simple_async_result_set_check_cancellable (simple, cancellable);
-
-       g_simple_async_result_set_op_res_gpointer (
-               simple, async_context, (GDestroyNotify) async_context_free);
-
-       g_simple_async_result_run_in_thread (
-               simple, session_forward_to_thread, io_priority, cancellable);
-
-       g_object_unref (simple);
-}
-
-static gboolean
-session_forward_to_finish (CamelSession *session,
-                           GAsyncResult *result,
-                           GError **error)
-{
-       GSimpleAsyncResult *simple;
-
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (session), session_forward_to), FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-
-       /* Assume success unless a GError is set. */
-       return !g_simple_async_result_propagate_error (simple, error);
-}
-
-static void
 camel_session_class_init (CamelSessionClass *class)
 {
        GObjectClass *object_class;
@@ -748,11 +607,6 @@ camel_session_class_init (CamelSessionClass *class)
        class->authenticate_sync = session_authenticate_sync;
        class->forward_to_sync = session_forward_to_sync;
 
-       class->authenticate = session_authenticate;
-       class->authenticate_finish = session_authenticate_finish;
-       class->forward_to = session_forward_to;
-       class->forward_to_finish = session_forward_to_finish;
-
        g_object_class_install_property (
                object_class,
                PROP_JUNK_FILTER,
@@ -1687,47 +1541,29 @@ camel_session_authenticate_sync (CamelSession *session,
        return success;
 }
 
-/**
- * camel_session_forward_to_sync:
- * @session: a #CamelSession
- * @folder: the #CamelFolder where @message is located
- * @message: the #CamelMimeMessage to forward
- * @address: the recipient's email address
- * @cancellable: optional #GCancellable object, or %NULL
- * @error: return location for a #GError, or %NULL
- *
- * Forwards @message in @folder to the email address(es) given by @address.
- *
- * If an error occurs, the function sets @error and returns %FALSE.
- *
- * Returns: %TRUE on success, %FALSE on failure
- *
- * Since: 3.6
- **/
-gboolean
-camel_session_forward_to_sync (CamelSession *session,
-                               CamelFolder *folder,
-                               CamelMimeMessage *message,
-                               const gchar *address,
-                               GCancellable *cancellable,
-                               GError **error)
+/* Helper for camel_session_authenticate() */
+static void
+session_authenticate_thread (GSimpleAsyncResult *simple,
+                             GObject *object,
+                             GCancellable *cancellable)
 {
-       CamelSessionClass *class;
-       gboolean success;
+       AsyncContext *async_context;
+       GError *error = NULL;
 
-       g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
-       g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
-       g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), FALSE);
-       g_return_val_if_fail (address != NULL, FALSE);
+       async_context = g_simple_async_result_get_op_res_gpointer (simple);
 
-       class = CAMEL_SESSION_GET_CLASS (session);
-       g_return_val_if_fail (class->forward_to_sync != NULL, FALSE);
+       if (!camel_session_authenticate_sync (
+               CAMEL_SESSION (object),
+               async_context->service,
+               async_context->auth_mechanism,
+               cancellable, &error)) {
 
-       success = class->forward_to_sync (
-               session, folder, message, address, cancellable, error);
-       CAMEL_CHECK_GERROR (session, forward_to_sync, success, error);
+               if (!error)
+                       error = g_error_new_literal (CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("Unknown error"));
+       }
 
-       return success;
+       if (error != NULL)
+               g_simple_async_result_take_error (simple, error);
 }
 
 /**
@@ -1761,17 +1597,29 @@ camel_session_authenticate (CamelSession *session,
                             GAsyncReadyCallback callback,
                             gpointer user_data)
 {
-       CamelSessionClass *class;
+       GSimpleAsyncResult *simple;
+       AsyncContext *async_context;
 
        g_return_if_fail (CAMEL_IS_SESSION (session));
        g_return_if_fail (CAMEL_IS_SERVICE (service));
 
-       class = CAMEL_SESSION_GET_CLASS (session);
-       g_return_if_fail (class->authenticate != NULL);
+       async_context = g_slice_new0 (AsyncContext);
+       async_context->service = g_object_ref (service);
+       async_context->auth_mechanism = g_strdup (mechanism);
 
-       class->authenticate (
-               session, service, mechanism, io_priority,
-               cancellable, callback, user_data);
+       simple = g_simple_async_result_new (
+               G_OBJECT (session), callback, user_data,
+               camel_session_authenticate);
+
+       g_simple_async_result_set_check_cancellable (simple, cancellable);
+
+       g_simple_async_result_set_op_res_gpointer (
+               simple, async_context, (GDestroyNotify) async_context_free);
+
+       g_simple_async_result_run_in_thread (
+               simple, session_authenticate_thread, io_priority, cancellable);
+
+       g_object_unref (simple);
 }
 
 /**
@@ -1794,15 +1642,82 @@ camel_session_authenticate_finish (CamelSession *session,
                                    GAsyncResult *result,
                                    GError **error)
 {
+       GSimpleAsyncResult *simple;
+
+       g_return_val_if_fail (
+               g_simple_async_result_is_valid (
+               result, G_OBJECT (session),
+               camel_session_authenticate), FALSE);
+
+       simple = G_SIMPLE_ASYNC_RESULT (result);
+
+       /* Assume success unless a GError is set. */
+       return !g_simple_async_result_propagate_error (simple, error);
+}
+
+/**
+ * camel_session_forward_to_sync:
+ * @session: a #CamelSession
+ * @folder: the #CamelFolder where @message is located
+ * @message: the #CamelMimeMessage to forward
+ * @address: the recipient's email address
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @error: return location for a #GError, or %NULL
+ *
+ * Forwards @message in @folder to the email address(es) given by @address.
+ *
+ * If an error occurs, the function sets @error and returns %FALSE.
+ *
+ * Returns: %TRUE on success, %FALSE on failure
+ *
+ * Since: 3.6
+ **/
+gboolean
+camel_session_forward_to_sync (CamelSession *session,
+                               CamelFolder *folder,
+                               CamelMimeMessage *message,
+                               const gchar *address,
+                               GCancellable *cancellable,
+                               GError **error)
+{
        CamelSessionClass *class;
+       gboolean success;
 
        g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
-       g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+       g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE);
+       g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), FALSE);
+       g_return_val_if_fail (address != NULL, FALSE);
 
        class = CAMEL_SESSION_GET_CLASS (session);
-       g_return_val_if_fail (class->authenticate_finish != NULL, FALSE);
+       g_return_val_if_fail (class->forward_to_sync != NULL, FALSE);
+
+       success = class->forward_to_sync (
+               session, folder, message, address, cancellable, error);
+       CAMEL_CHECK_GERROR (session, forward_to_sync, success, error);
 
-       return class->authenticate_finish (session, result, error);
+       return success;
+}
+
+/* Helper for camel_session_forward_to() */
+static void
+session_forward_to_thread (GSimpleAsyncResult *simple,
+                           GObject *object,
+                           GCancellable *cancellable)
+{
+       AsyncContext *async_context;
+       GError *error = NULL;
+
+       async_context = g_simple_async_result_get_op_res_gpointer (simple);
+
+       camel_session_forward_to_sync (
+               CAMEL_SESSION (object),
+               async_context->folder,
+               async_context->message,
+               async_context->address,
+               cancellable, &error);
+
+       if (error != NULL)
+               g_simple_async_result_take_error (simple, error);
 }
 
 /**
@@ -1835,19 +1750,32 @@ camel_session_forward_to (CamelSession *session,
                           GAsyncReadyCallback callback,
                           gpointer user_data)
 {
-       CamelSessionClass *class;
+       GSimpleAsyncResult *simple;
+       AsyncContext *async_context;
 
        g_return_if_fail (CAMEL_IS_SESSION (session));
        g_return_if_fail (CAMEL_IS_FOLDER (folder));
        g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
        g_return_if_fail (address != NULL);
 
-       class = CAMEL_SESSION_GET_CLASS (session);
-       g_return_if_fail (class->forward_to != NULL);
+       async_context = g_slice_new0 (AsyncContext);
+       async_context->folder = g_object_ref (folder);
+       async_context->message = g_object_ref (message);
+       async_context->address = g_strdup (address);
+
+       simple = g_simple_async_result_new (
+               G_OBJECT (session), callback, user_data,
+               camel_session_forward_to);
 
-       class->forward_to (
-               session, folder, message, address,
-               io_priority, cancellable, callback, user_data);
+       g_simple_async_result_set_check_cancellable (simple, cancellable);
+
+       g_simple_async_result_set_op_res_gpointer (
+               simple, async_context, (GDestroyNotify) async_context_free);
+
+       g_simple_async_result_run_in_thread (
+               simple, session_forward_to_thread, io_priority, cancellable);
+
+       g_object_unref (simple);
 }
 
 /**
@@ -1869,14 +1797,16 @@ camel_session_forward_to_finish (CamelSession *session,
                                  GAsyncResult *result,
                                  GError **error)
 {
-       CamelSessionClass *class;
+       GSimpleAsyncResult *simple;
 
-       g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
-       g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+       g_return_val_if_fail (
+               g_simple_async_result_is_valid (
+               result, G_OBJECT (session),
+               camel_session_forward_to), FALSE);
 
-       class = CAMEL_SESSION_GET_CLASS (session);
-       g_return_val_if_fail (class->forward_to_finish != NULL, FALSE);
+       simple = G_SIMPLE_ASYNC_RESULT (result);
 
-       return class->forward_to_finish (session, result, error);
+       /* Assume success unless a GError is set. */
+       return !g_simple_async_result_propagate_error (simple, error);
 }
 
diff --git a/camel/camel-session.h b/camel/camel-session.h
index c994829..79c0a93 100644
--- a/camel/camel-session.h
+++ b/camel/camel-session.h
@@ -137,28 +137,8 @@ struct _CamelSessionClass {
                                                 GCancellable *cancellable,
                                                 GError **error);
 
-       /* Asynchronous I/O Methods (all have defaults) */
-       void            (*authenticate)         (CamelSession *session,
-                                                CamelService *service,
-                                                const gchar *mechanism,
-                                                gint io_priority,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-       gboolean        (*authenticate_finish)  (CamelSession *session,
-                                                GAsyncResult *result,
-                                                GError **error);
-       void            (*forward_to)           (CamelSession *session,
-                                                CamelFolder *folder,
-                                                CamelMimeMessage *message,
-                                                const gchar *address,
-                                                gint io_priority,
-                                                GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-       gboolean        (*forward_to_finish)    (CamelSession *session,
-                                                GAsyncResult *result,
-                                                GError **error);
+       /* Reserved slots for methods. */
+       gpointer reserved_for_methods[4];
 
        /* Signals */
        void            (*job_started)          (CamelSession *session,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]