#include "job.h"
#include "util.h"
#include "cross.h"
-#include "ui_signaller.h"
#include "exceptions.h"
#include "film.h"
#include "log.h"
#define LOG_ERROR_NC(...) _film->log()->log (__VA_ARGS__, Log::TYPE_ERROR);
-Job::Job (shared_ptr<const Film> f)
- : _film (f)
+Job::Job (shared_ptr<const Film> film)
+ : _film (film)
, _thread (0)
, _state (NEW)
, _start_time (0)
set_error (e.what(), m);
set_progress (1);
set_state (FINISHED_ERROR);
-
+
} catch (OpenFileError& e) {
set_error (
set_error (_("Out of memory"), _("There was not enough memory to do this."));
set_progress (1);
set_state (FINISHED_ERROR);
-
+
} catch (std::exception& e) {
set_error (
set_progress (1);
set_state (FINISHED_ERROR);
-
+
} catch (...) {
set_error (
boost::mutex::scoped_lock lm (_state_mutex);
return _state == PAUSED;
}
-
+
/** Set the state of this job.
* @param s New state.
*/
}
}
- if (finished && ui_signaller) {
- ui_signaller->emit (boost::bind (boost::ref (Finished)));
- }
+ if (finished) {
+ emit (boost::bind (boost::ref (Finished)));
+ }
}
/** @return DCPTime (in seconds) that this sub-job has been running */
if (_start_time == 0) {
return 0;
}
-
+
return time (0) - _start_time;
}
_pause_changed.wait (lm2);
}
- if (ui_signaller) {
- ui_signaller->emit (boost::bind (boost::ref (Progress)));
- }
+ lm.unlock ();
+ lm2.unlock ();
+
+ emit (boost::bind (boost::ref (Progress)));
}
/** @return fractional progress of the current sub-job, if known */
boost::mutex::scoped_lock lm (_progress_mutex);
_sub_name = n;
}
-
+
set_progress (0, true);
}
{
LOG_ERROR_NC (s);
LOG_ERROR_NC (d);
-
+
_film->log()->log (String::compose ("Error in job: %1 (%2)", s, d), Log::TYPE_ERROR);
boost::mutex::scoped_lock lm (_state_mutex);
_error_summary = s;
_progress.reset ();
lm.unlock ();
- if (ui_signaller) {
- ui_signaller->emit (boost::bind (boost::ref (Progress)));
- }
+ emit (boost::bind (boost::ref (Progress)));
}
/** @return Human-readable status of this job */
/* 100% makes it sound like we've finished when we haven't */
pc = 99;
}
-
+
s << pc << N_("%");
-
+
if (t > 10 && r > 0) {
/// TRANSLATORS: remaining here follows an amount of time that is remaining
/// on an operation.
} else if (finished_ok ()) {
s << String::compose (_("OK (ran for %1)"), seconds_to_hms (_ran_for));
} else if (finished_in_error ()) {
- string es = error_summary ();
- if (es.length() > 25) {
- es = es.substr (0, 25) + "...";
- }
- s << String::compose (_("Error (%1)"), es);
+ s << String::compose (_("Error (%1)"), error_summary ());
} else if (finished_cancelled ()) {
s << _("Cancelled");
}
return s.str ();
}
+string
+Job::json_status () const
+{
+ boost::mutex::scoped_lock lm (_state_mutex);
+
+ switch (_state) {
+ case NEW:
+ return N_("new");
+ case RUNNING:
+ return N_("running");
+ case PAUSED:
+ return N_("paused");
+ case FINISHED_OK:
+ return N_("finished_ok");
+ case FINISHED_ERROR:
+ return N_("finished_error");
+ case FINISHED_CANCELLED:
+ return N_("finished_cancelled");
+ }
+
+ return "";
+}
+
/** @return An estimate of the remaining time for this sub-job, in seconds */
int
Job::remaining_time () const
if (progress().get_value_or(0) == 0) {
return elapsed_time ();
}
-
+
return elapsed_time() / progress().get() - elapsed_time();
}
return;
}
+ if (paused ()) {
+ resume ();
+ }
+
_thread->interrupt ();
_thread->join ();
}