]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-job-queue.c
Added. Returns whether the animation has everything necessary to run. Do
[evince.git] / shell / ev-job-queue.c
index a860f377f39b2d30a572c5bbc1c967ca0e526756..8280aab4b88939ffa3521b99a04cdeed92ab464c 100644 (file)
@@ -1,3 +1,4 @@
+#include <config.h>
 #include "ev-job-queue.h"
 
 /* Like glib calling convention, all functions with _locked in their name assume
 #include "ev-job-queue.h"
 
 /* Like glib calling convention, all functions with _locked in their name assume
@@ -13,8 +14,9 @@ static GQueue *render_queue_low = NULL;
 static GQueue *thumbnail_queue_high = NULL;
 static GQueue *thumbnail_queue_low = NULL;
 static GQueue *load_queue = NULL;
 static GQueue *thumbnail_queue_high = NULL;
 static GQueue *thumbnail_queue_low = NULL;
 static GQueue *load_queue = NULL;
-static GQueue *xfer_queue = NULL;
+static GQueue *save_queue = NULL;
 static GQueue *fonts_queue = NULL;
 static GQueue *fonts_queue = NULL;
+static GQueue *print_queue = NULL;
 
 /* Queues used for backends supporting EvAsyncRender interface,
    they are executed on the main thread */
 
 /* Queues used for backends supporting EvAsyncRender interface,
    they are executed on the main thread */
@@ -52,6 +54,14 @@ add_job_to_async_queue (GQueue *queue, EvJob *job)
        g_queue_push_tail (queue, job);
 }
 
        g_queue_push_tail (queue, job);
 }
 
+/**
+ * add_job_to_queue_locked:
+ * @queue: a #GQueue where the #EvJob will be added.
+ * @job: an #EvJob to be added to the specified #GQueue.
+ *
+ * Add the #EvJob to the specified #GQueue and woke up the ev_render_thread who
+ * is waiting for render_cond.
+ */
 static void
 add_job_to_queue_locked (GQueue *queue,
                         EvJob  *job)
 static void
 add_job_to_queue_locked (GQueue *queue,
                         EvJob  *job)
@@ -61,6 +71,14 @@ add_job_to_queue_locked (GQueue *queue,
        g_cond_broadcast (render_cond);
 }
 
        g_cond_broadcast (render_cond);
 }
 
+/**
+ * notify_finished:
+ * @job: the object that signal will be reseted.
+ *
+ * It does emit the job finished signal and returns %FALSE.
+ *
+ * Returns: %FALSE.
+ */
 static gboolean
 notify_finished (GObject *job)
 {
 static gboolean
 notify_finished (GObject *job)
 {
@@ -69,6 +87,13 @@ notify_finished (GObject *job)
        return FALSE;
 }
 
        return FALSE;
 }
 
+/**
+ * job_finished_cb:
+ * @job: the #EvJob that has been handled.
+ *
+ * It does finish the job last work and look if there is any more job to be
+ * handled.
+ */
 static void
 job_finished_cb (EvJob *job)
 {
 static void
 job_finished_cb (EvJob *job)
 {
@@ -77,6 +102,14 @@ job_finished_cb (EvJob *job)
        ev_job_queue_run_next ();
 }
 
        ev_job_queue_run_next ();
 }
 
+/**
+ * handle_job:
+ * @job: the #EvJob to be handled.
+ *
+ * First, it does check if the job is async and then it does attend it if
+ * possible giving a failed assertion otherwise. If the job isn't async it does
+ * attend it and notify that the job has been finished.
+ */
 static void
 handle_job (EvJob *job)
 {
 static void
 handle_job (EvJob *job)
 {
@@ -98,12 +131,14 @@ handle_job (EvJob *job)
                ev_job_links_run (EV_JOB_LINKS (job));
        else if (EV_IS_JOB_LOAD (job))
                ev_job_load_run (EV_JOB_LOAD (job));
                ev_job_links_run (EV_JOB_LINKS (job));
        else if (EV_IS_JOB_LOAD (job))
                ev_job_load_run (EV_JOB_LOAD (job));
-       else if (EV_IS_JOB_XFER (job))
-               ev_job_xfer_run (EV_JOB_XFER (job));
+       else if (EV_IS_JOB_SAVE (job))
+               ev_job_save_run (EV_JOB_SAVE (job));
        else if (EV_IS_JOB_RENDER (job))
                ev_job_render_run (EV_JOB_RENDER (job));
        else if (EV_IS_JOB_FONTS (job))
                ev_job_fonts_run (EV_JOB_FONTS (job));
        else if (EV_IS_JOB_RENDER (job))
                ev_job_render_run (EV_JOB_RENDER (job));
        else if (EV_IS_JOB_FONTS (job))
                ev_job_fonts_run (EV_JOB_FONTS (job));
+       else if (EV_IS_JOB_PRINT (job))
+               ev_job_print_run (EV_JOB_PRINT (job));
 
        if (!EV_JOB (job)->async) {
                /* We let the idle own a ref, as we (the queue) are done with the job. */
 
        if (!EV_JOB (job)->async) {
                /* We let the idle own a ref, as we (the queue) are done with the job. */
@@ -114,6 +149,24 @@ handle_job (EvJob *job)
        }
 }
 
        }
 }
 
+/**
+ * search_for_jobs_unlocked:
+ *
+ * Check if there is any job at the synchronized queues and return any existing
+ * job in them taking in account the next priority:
+ *
+ *  render_queue_high       >
+ *  thumbnail_queue_high    >
+ *  render_queue_low        >
+ *  links_queue             >
+ *  load_queue              >
+ *  thumbnail_queue_low     >
+ *  fonts_queue             >
+ *  print_queue             >
+ *
+ * Returns: an available #EvJob in the queues taking in account stablished queue
+ *          priorities.
+ */
 static EvJob *
 search_for_jobs_unlocked (void)
 {
 static EvJob *
 search_for_jobs_unlocked (void)
 {
@@ -139,7 +192,7 @@ search_for_jobs_unlocked (void)
        if (job)
                return job;
 
        if (job)
                return job;
 
-       job = (EvJob *) g_queue_pop_head (xfer_queue);
+       job = (EvJob *) g_queue_pop_head (save_queue);
        if (job)
                return job;
 
        if (job)
                return job;
 
@@ -151,9 +204,22 @@ search_for_jobs_unlocked (void)
        if (job)
                return job;
 
        if (job)
                return job;
 
+       job = (EvJob *) g_queue_pop_head (print_queue);
+       if (job)
+               return job;
+
        return NULL;
 }
 
        return NULL;
 }
 
+/**
+ * no_jobs_available_unlocked:
+ *
+ * Looks if there is any job at render, links, load, thumbnail. fonts and print
+ * queues.
+ *
+ * Returns: %TRUE if the render, links, load, thumbnail, fonts and print queues
+ *          are empty, %FALSE in other case.
+ */
 static gboolean
 no_jobs_available_unlocked (void)
 {
 static gboolean
 no_jobs_available_unlocked (void)
 {
@@ -161,13 +227,24 @@ no_jobs_available_unlocked (void)
                && g_queue_is_empty (render_queue_low)
                && g_queue_is_empty (links_queue)
                && g_queue_is_empty (load_queue)
                && g_queue_is_empty (render_queue_low)
                && g_queue_is_empty (links_queue)
                && g_queue_is_empty (load_queue)
-               && g_queue_is_empty (xfer_queue)
+               && g_queue_is_empty (save_queue)
                && g_queue_is_empty (thumbnail_queue_high)
                && g_queue_is_empty (thumbnail_queue_low)
                && g_queue_is_empty (thumbnail_queue_high)
                && g_queue_is_empty (thumbnail_queue_low)
-               && g_queue_is_empty (fonts_queue);
+               && g_queue_is_empty (fonts_queue)
+               && g_queue_is_empty (print_queue);
 }
 
 /* the thread mainloop function */
 }
 
 /* the thread mainloop function */
+/**
+ * ev_render_thread:
+ * @data: data passed to the thread.
+ *
+ * The thread mainloop function. It does wait for any available job in synced
+ * queues to handle it.
+ *
+ * Returns: the return value of the thread, which will be returned by
+ *          g_thread_join().
+ */
 static gpointer
 ev_render_thread (gpointer data)
 {
 static gpointer
 ev_render_thread (gpointer data)
 {
@@ -192,6 +269,12 @@ ev_render_thread (gpointer data)
 
 }
 
 
 }
 
+/**
+ * ev_job_queue_run_next:
+ *
+ * It does look for any job on the render high priority queue first and after
+ * in the render low priority one, and then it does handle it.
+ */
 static void
 ev_job_queue_run_next (void)
 {
 static void
 ev_job_queue_run_next (void)
 {
@@ -211,6 +294,12 @@ ev_job_queue_run_next (void)
 }
 
 /* Public Functions */
 }
 
 /* Public Functions */
+/**
+ * ev_job_queue_init:
+ *
+ * Creates a new cond, new mutex, a thread for evince job handling and inits
+ * every queue.
+ */
 void
 ev_job_queue_init (void)
 {
 void
 ev_job_queue_init (void)
 {
@@ -221,7 +310,7 @@ ev_job_queue_init (void)
 
        links_queue = g_queue_new ();
        load_queue = g_queue_new ();
 
        links_queue = g_queue_new ();
        load_queue = g_queue_new ();
-       xfer_queue = g_queue_new ();
+       save_queue = g_queue_new ();
        render_queue_high = g_queue_new ();
        render_queue_low = g_queue_new ();
        async_render_queue_high = g_queue_new ();
        render_queue_high = g_queue_new ();
        render_queue_low = g_queue_new ();
        async_render_queue_high = g_queue_new ();
@@ -229,6 +318,7 @@ ev_job_queue_init (void)
        thumbnail_queue_high = g_queue_new ();
        thumbnail_queue_low = g_queue_new ();
        fonts_queue = g_queue_new ();
        thumbnail_queue_high = g_queue_new ();
        thumbnail_queue_low = g_queue_new ();
        fonts_queue = g_queue_new ();
+       print_queue = g_queue_new ();
 
        g_thread_create (ev_render_thread, NULL, FALSE, NULL);
 
 
        g_thread_create (ev_render_thread, NULL, FALSE, NULL);
 
@@ -259,15 +349,18 @@ find_queue (EvJob         *job,
                } else if (EV_IS_JOB_LOAD (job)) {
                        /* the priority doesn't effect load */
                        return load_queue;
                } else if (EV_IS_JOB_LOAD (job)) {
                        /* the priority doesn't effect load */
                        return load_queue;
-               } else if (EV_IS_JOB_XFER (job)) {
-                       /* the priority doesn't effect xfer */
-                       return xfer_queue;
+               } else if (EV_IS_JOB_SAVE (job)) {
+                       /* the priority doesn't effect save */
+                       return save_queue;
                } else if (EV_IS_JOB_LINKS (job)) {
                        /* the priority doesn't effect links */
                        return links_queue;
                } else if (EV_IS_JOB_FONTS (job)) {
                        /* the priority doesn't effect fonts */
                        return fonts_queue;
                } else if (EV_IS_JOB_LINKS (job)) {
                        /* the priority doesn't effect links */
                        return links_queue;
                } else if (EV_IS_JOB_FONTS (job)) {
                        /* the priority doesn't effect fonts */
                        return fonts_queue;
+               } else if (EV_IS_JOB_PRINT (job)) {
+                       /* the priority doesn't effect print */
+                       return print_queue;
                }
        }
 
                }
        }
 
@@ -405,10 +498,12 @@ ev_job_queue_remove_job (EvJob *job)
                        retval = remove_job_from_queue_locked (links_queue, job);
                } else if (EV_IS_JOB_LOAD (job)) {
                        retval = remove_job_from_queue_locked (load_queue, job);
                        retval = remove_job_from_queue_locked (links_queue, job);
                } else if (EV_IS_JOB_LOAD (job)) {
                        retval = remove_job_from_queue_locked (load_queue, job);
-               } else if (EV_IS_JOB_XFER (job)) {
-                       retval = remove_job_from_queue_locked (xfer_queue, job);
+               } else if (EV_IS_JOB_SAVE (job)) {
+                       retval = remove_job_from_queue_locked (save_queue, job);
                } else if (EV_IS_JOB_FONTS (job)) {
                        retval = remove_job_from_queue_locked (fonts_queue, job);
                } else if (EV_IS_JOB_FONTS (job)) {
                        retval = remove_job_from_queue_locked (fonts_queue, job);
+               } else if (EV_IS_JOB_PRINT (job)) {
+                       retval = remove_job_from_queue_locked (print_queue, job);
                } else {
                        g_assert_not_reached ();
                }
                } else {
                        g_assert_not_reached ();
                }