Hand apply e4615ebe1cef519e3aaee317ca6d319fbb9a0903 from master; put job errors in...
[dcpomatic.git] / src / lib / job.cc
index 594c0da34f1b5cdc7a55177e61bee698b5ac21d5..5b0b9c6044475a0b11c5e84318b09df409c60908 100644 (file)
 using std::string;
 using std::list;
 using std::cout;
-using std::stringstream;
 using boost::shared_ptr;
 
+#define LOG_ERROR_NC(...) _film->log()->log (__VA_ARGS__, Log::TYPE_ERROR);
+
 Job::Job (shared_ptr<const Film> f)
        : _film (f)
        , _thread (0)
@@ -110,7 +111,7 @@ Job::run_wrapper ()
 
                set_error (
                        e.what (),
-                       _("It is not known what caused this error.  Please report the problem to the DCP-o-matic author (carl@dcpomatic.com).")
+                       string (_("It is not known what caused this error.")) + "  " + REPORT_PROBLEM
                        );
 
                set_progress (1);
@@ -120,7 +121,7 @@ Job::run_wrapper ()
 
                set_error (
                        _("Unknown error"),
-                       _("It is not known what caused this error.  Please report the problem to the DCP-o-matic author (carl@dcpomatic.com).")
+                       string (_("It is not known what caused this error.")) + "  " + REPORT_PROBLEM
                        );
 
                set_progress (1);
@@ -232,8 +233,9 @@ Job::set_progress (float p, bool force)
        _progress = p;
        boost::this_thread::interruption_point ();
 
-       if (paused ()) {
-               dcpomatic_sleep (1);
+       boost::mutex::scoped_lock lm2 (_state_mutex);
+       while (_state == PAUSED) {
+               _pause_changed.wait (lm2);
        }
 
        if (ui_signaller) {
@@ -281,6 +283,9 @@ Job::error_summary () const
 void
 Job::set_error (string s, string d)
 {
+       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;
@@ -309,7 +314,7 @@ Job::status () const
                pc = 99;
        }
 
-       stringstream s;
+       SafeStringStream s;
        if (!finished ()) {
                s << pc << N_("%");
                if (p >= 0 && t > 10 && r > 0) {
@@ -328,29 +333,6 @@ Job::status () const
        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
@@ -374,6 +356,7 @@ Job::pause ()
 {
        if (running ()) {
                set_state (PAUSED);
+               _pause_changed.notify_all ();
        }
 }
 
@@ -382,5 +365,6 @@ Job::resume ()
 {
        if (paused ()) {
                set_state (RUNNING);
+               _pause_changed.notify_all ();
        }
 }