#include "job_manager.h"
#include "job.h"
#include "cross.h"
-#include "ui_signaller.h"
using std::string;
using std::list;
JobManager::JobManager ()
: _terminate (false)
, _last_active_jobs (false)
- , _scheduler (new boost::thread (boost::bind (&JobManager::scheduler, this)))
+ , _scheduler (0)
{
-
+
+}
+
+void
+JobManager::start ()
+{
+ _scheduler = new boost::thread (boost::bind (&JobManager::scheduler, this));
}
JobManager::~JobManager ()
_terminate = true;
}
- if (_scheduler->joinable ()) {
+ if (_scheduler) {
_scheduler->join ();
}
+
+ delete _scheduler;
}
shared_ptr<Job>
_jobs.push_back (j);
}
- if (ui_signaller) {
- ui_signaller->emit (boost::bind (boost::ref (JobAdded), weak_ptr<Job> (j)));
- }
-
+ emit (boost::bind (boost::ref (JobAdded), weak_ptr<Job> (j)));
+
return j;
}
}
return false;
-}
+}
void
JobManager::scheduler ()
if (_terminate) {
return;
}
-
+
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()) {
(*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));
- }
+ emit (boost::bind (boost::ref (ActiveJobsChanged), active_jobs));
}
dcpomatic_sleep (1);
{
if (_instance == 0) {
_instance = new JobManager ();
+ _instance->start ();
}
return _instance;