Merge 1.0 in.
[dcpomatic.git] / src / lib / job_manager.cc
index 1fae179656222b299192d71652ad5abe719ec844..a841fa60bd553698a873e7105d5f2086e8e4040b 100644 (file)
@@ -30,7 +30,9 @@
 
 using std::string;
 using std::list;
+using std::cout;
 using boost::shared_ptr;
+using boost::weak_ptr;
 
 JobManager* JobManager::_instance = 0;
 
@@ -43,19 +45,16 @@ JobManager::JobManager ()
 shared_ptr<Job>
 JobManager::add (shared_ptr<Job> j)
 {
-       boost::mutex::scoped_lock lm (_mutex);
-       _jobs.push_back (j);
-       return j;
-}
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+               _jobs.push_back (j);
+       }
 
-void
-JobManager::add_after (shared_ptr<Job> after, shared_ptr<Job> j)
-{
-       boost::mutex::scoped_lock lm (_mutex);
-       list<shared_ptr<Job> >::iterator i = find (_jobs.begin(), _jobs.end(), after);
-       assert (i != _jobs.end ());
-       ++i;
-       _jobs.insert (i, j);
+       if (ui_signaller) {
+               ui_signaller->emit (boost::bind (boost::ref (JobAdded), weak_ptr<Job> (j)));
+       }
+       
+       return j;
 }
 
 list<shared_ptr<Job> >
@@ -100,33 +99,33 @@ JobManager::scheduler ()
                {
                        boost::mutex::scoped_lock lm (_mutex);
                        for (list<shared_ptr<Job> >::iterator i = _jobs.begin(); i != _jobs.end(); ++i) {
+
+                               if (!(*i)->finished ()) {
+                                       active_jobs = true;
+                               }
+                               
                                if ((*i)->running ()) {
                                        /* Something is already happening */
                                        break;
                                }
                                
                                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;
+                                       (*i)->start ();
+                                       
+                                       /* Only start one job at once */
+                                       break;
                                }
                        }
                }
 
                if (active_jobs != _last_active_jobs) {
                        _last_active_jobs = active_jobs;
-                       ui_signaller->emit (boost::bind (boost::ref (ActiveJobsChanged), active_jobs));
+                       if (ui_signaller) {
+                               ui_signaller->emit (boost::bind (boost::ref (ActiveJobsChanged), active_jobs));
+                       }
                }
 
-               dvdomatic_sleep (1);
+               dcpomatic_sleep (1);
        }
 }