CamelIMAPXJob: Add camel_imapx_job_run().
authorMatthew Barnes <mbarnes@redhat.com>
Mon, 30 Jan 2012 19:26:34 +0000 (14:26 -0500)
committerMatthew Barnes <mbarnes@redhat.com>
Tue, 31 Jan 2012 22:06:05 +0000 (17:06 -0500)
camel/providers/imapx/camel-imapx-job.c
camel/providers/imapx/camel-imapx-job.h
camel/providers/imapx/camel-imapx-server.c

index 19ba0fd..d6df79c 100644 (file)
@@ -36,6 +36,18 @@ struct _CamelIMAPXRealJob {
        GDestroyNotify destroy_data;
 };
 
+static void
+imapx_job_cancelled_cb (GCancellable *cancellable,
+                        CamelIMAPXJob *job)
+{
+       /* Unblock camel_imapx_run_job() immediately.
+        *
+        * If camel_imapx_job_done() is called sometime later,
+        * the GCond will broadcast but no one will be listening. */
+
+       camel_imapx_job_done (job);
+}
+
 CamelIMAPXJob *
 camel_imapx_job_new (GCancellable *cancellable)
 {
@@ -139,6 +151,47 @@ camel_imapx_job_done (CamelIMAPXJob *job)
        g_mutex_unlock (real_job->done_mutex);
 }
 
+gboolean
+camel_imapx_job_run (CamelIMAPXJob *job,
+                     CamelIMAPXServer *is,
+                     GError **error)
+{
+       gulong cancel_id = 0;
+
+       g_return_val_if_fail (job != NULL, FALSE);
+       g_return_val_if_fail (job->start != NULL, FALSE);
+       g_return_val_if_fail (CAMEL_IS_IMAPX_SERVER (is), FALSE);
+
+       if (g_cancellable_set_error_if_cancelled (job->cancellable, error))
+               return FALSE;
+
+       if (G_IS_CANCELLABLE (job->cancellable))
+               cancel_id = g_cancellable_connect (
+                       job->cancellable,
+                       G_CALLBACK (imapx_job_cancelled_cb),
+                       camel_imapx_job_ref (job),
+                       (GDestroyNotify) camel_imapx_job_unref);
+
+       job->start (job, is);
+
+       if (!job->noreply)
+               camel_imapx_job_wait (job);
+
+       if (cancel_id > 0)
+               g_cancellable_disconnect (job->cancellable, cancel_id);
+
+       if (g_cancellable_set_error_if_cancelled (job->cancellable, error))
+               return FALSE;
+
+       if (job->error != NULL) {
+               g_propagate_error (error, job->error);
+               job->error = NULL;
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
 gpointer
 camel_imapx_job_get_data (CamelIMAPXJob *job)
 {
index 9e2a021..36ac855 100644 (file)
@@ -122,6 +122,9 @@ CamelIMAPXJob *     camel_imapx_job_ref             (CamelIMAPXJob *job);
 void           camel_imapx_job_unref           (CamelIMAPXJob *job);
 void           camel_imapx_job_wait            (CamelIMAPXJob *job);
 void           camel_imapx_job_done            (CamelIMAPXJob *job);
+gboolean       camel_imapx_job_run             (CamelIMAPXJob *job,
+                                                CamelIMAPXServer *is,
+                                                GError **error);
 gpointer       camel_imapx_job_get_data        (CamelIMAPXJob *job);
 void           camel_imapx_job_set_data        (CamelIMAPXJob *job,
                                                 gpointer data,
index 01bda7f..3742202 100644 (file)
@@ -150,7 +150,6 @@ struct _imapx_flag_change {
 
 static CamelIMAPXJob *imapx_match_active_job (CamelIMAPXServer *is, guint32 type, const gchar *uid);
 static void imapx_job_done (CamelIMAPXServer *is, CamelIMAPXJob *job);
-static gboolean imapx_run_job (CamelIMAPXServer *is, CamelIMAPXJob *job, GError **error);
 static void imapx_job_fetch_new_messages_start (CamelIMAPXJob *job, CamelIMAPXServer *is);
 static gint imapx_refresh_info_uid_cmp (gconstpointer ap, gconstpointer bp, gboolean ascending);
 static gint imapx_uids_array_cmp (gconstpointer ap, gconstpointer bp);
@@ -1754,18 +1753,6 @@ imapx_job_done (CamelIMAPXServer *is,
        QUEUE_UNLOCK (is);
 }
 
-static void
-imapx_job_cancelled (GCancellable *cancellable,
-                     CamelIMAPXJob *job)
-{
-       /* Unblock imapx_run_job() immediately.
-        *
-        * If camel_imapx_job_done() is called sometime later,
-        * the GCond will broadcast but no one will be listening. */
-
-       camel_imapx_job_done (job);
-}
-
 static gboolean
 imapx_register_job (CamelIMAPXServer *is,
                     CamelIMAPXJob *job,
@@ -1789,43 +1776,6 @@ imapx_register_job (CamelIMAPXServer *is,
 }
 
 static gboolean
-imapx_run_job (CamelIMAPXServer *is,
-               CamelIMAPXJob *job,
-               GError **error)
-{
-       gulong cancel_id = 0;
-
-       if (g_cancellable_set_error_if_cancelled (is->cancellable, error))
-               return FALSE;
-
-       if (G_IS_CANCELLABLE (job->cancellable))
-               cancel_id = g_cancellable_connect (
-                       job->cancellable,
-                       G_CALLBACK (imapx_job_cancelled),
-                       camel_imapx_job_ref (job),
-                       (GDestroyNotify) camel_imapx_job_unref);
-
-       job->start (job, is);
-
-       if (!job->noreply)
-               camel_imapx_job_wait (job);
-
-       if (cancel_id > 0)
-               g_cancellable_disconnect (job->cancellable, cancel_id);
-
-       if (g_cancellable_set_error_if_cancelled (job->cancellable, error))
-               return FALSE;
-
-       if (job->error != NULL) {
-               g_propagate_error (error, job->error);
-               job->error = NULL;
-               return FALSE;
-       }
-
-       return TRUE;
-}
-
-static gboolean
 imapx_submit_job (CamelIMAPXServer *is,
                   CamelIMAPXJob *job,
                   GError **error)
@@ -1833,7 +1783,7 @@ imapx_submit_job (CamelIMAPXServer *is,
        if (!imapx_register_job (is, job, error))
                return FALSE;
 
-       return imapx_run_job (is, job, error);
+       return camel_imapx_job_run (job, is, error);
 }
 
 /* ********************************************************************** */
@@ -5043,7 +4993,7 @@ imapx_server_get_message (CamelIMAPXServer *is,
 
        QUEUE_UNLOCK (is);
 
-       success = registered && imapx_run_job (is, job, error);
+       success = registered && camel_imapx_job_run (job, is, error);
 
        if (success)
                stream = job->u.get_message.stream;
@@ -5269,7 +5219,7 @@ camel_imapx_server_refresh_info (CamelIMAPXServer *is,
 
        QUEUE_UNLOCK (is);
 
-       success = registered && imapx_run_job (is, job, error);
+       success = registered && camel_imapx_job_run (job, is, error);
 
        if (success && camel_folder_change_info_changed (job->u.refresh_info.changes))
                camel_folder_changed (folder, job->u.refresh_info.changes);
@@ -5450,7 +5400,7 @@ imapx_server_sync_changes (CamelIMAPXServer *is,
 
        QUEUE_UNLOCK (is);
 
-       success = registered && imapx_run_job (is, job, error);
+       success = registered && camel_imapx_job_run (job, is, error);
 
        camel_imapx_job_unref (job);
 
@@ -5503,7 +5453,7 @@ camel_imapx_server_expunge (CamelIMAPXServer *is,
 
        QUEUE_UNLOCK (is);
 
-       success = registered && imapx_run_job (is, job, error);
+       success = registered && camel_imapx_job_run (job, is, error);
 
        camel_imapx_job_unref (job);