Merge master; fix crash on new film.
[dcpomatic.git] / src / lib / job_manager.cc
index 562c887de9b57479c75f702928ac2ae6aec5d313..f962754677c2c1c672092838a0eca23f73e5873f 100644 (file)
 #include "job_manager.h"
 #include "job.h"
 #include "cross.h"
+#include "ui_signaller.h"
 
-using namespace std;
-using namespace boost;
+using std::string;
+using std::list;
+using boost::shared_ptr;
 
 JobManager* JobManager::_instance = 0;
 
 JobManager::JobManager ()
+       : _last_active_jobs (false)
 {
        boost::thread (boost::bind (&JobManager::scheduler, this));
 }
@@ -87,27 +90,43 @@ JobManager::errors () const
        return false;
 }      
 
-
 void
 JobManager::scheduler ()
 {
        while (1) {
+
+               bool active_jobs = false;
+
                {
                        boost::mutex::scoped_lock lm (_mutex);
                        for (list<shared_ptr<Job> >::iterator i = _jobs.begin(); i != _jobs.end(); ++i) {
-                               if ((*i)->is_new()) {
-                                       shared_ptr<Job> r = (*i)->required ();
-                                       if (!r || r->finished_ok ()) {
-                                               (*i)->start ();
 
-                                               /* Only start one job at once */
-                                               break;
-                                       }
+                               if (!(*i)->finished ()) {
+                                       active_jobs = true;
+                               }
+                               
+                               if ((*i)->running ()) {
+                                       /* Something is already happening */
+                                       break;
                                }
+                               
+                               if ((*i)->is_new()) {
+                                       (*i)->start ();
+                                       
+                                       /* Only start one job at once */
+                                       break;
+                               }
+                       }
+               }
+
+               if (active_jobs != _last_active_jobs) {
+                       _last_active_jobs = active_jobs;
+                       if (ui_signaller) {
+                               ui_signaller->emit (boost::bind (boost::ref (ActiveJobsChanged), active_jobs));
                        }
                }
 
-               dvdomatic_sleep (1);
+               dcpomatic_sleep (1);
        }
 }