Hand apply e4615ebe1cef519e3aaee317ca6d319fbb9a0903 from master; put job errors in...
[dcpomatic.git] / src / lib / job.cc
index 52ec1426c0bd0300a6658293471ef795e2e995ae..5b0b9c6044475a0b11c5e84318b09df409c60908 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 #include <boost/thread.hpp>
 #include <boost/filesystem.hpp>
-#include <libdcp/exceptions.h>
+#include <dcp/exceptions.h>
 #include "job.h"
 #include "util.h"
 #include "cross.h"
 #include "ui_signaller.h"
 #include "exceptions.h"
-#include "safe_stringstream.h"
+#include "film.h"
+#include "log.h"
 
 #include "i18n.h"
 
@@ -38,6 +39,8 @@ using std::list;
 using std::cout;
 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)
@@ -66,8 +69,8 @@ Job::run_wrapper ()
 
                run ();
 
-       } catch (libdcp::FileError& e) {
-               
+       } catch (dcp::FileError& e) {
+
                string m = String::compose (_("An error occurred whilst handling the file %1."), boost::filesystem::path (e.filename()).leaf());
 
                try {
@@ -108,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);
@@ -118,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);
@@ -204,7 +207,7 @@ Job::set_state (State s)
        }       
 }
 
-/** @return Time (in seconds) that this sub-job has been running */
+/** @return DCPTime (in seconds) that this sub-job has been running */
 int
 Job::elapsed_time () const
 {
@@ -230,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) {
@@ -279,6 +283,10 @@ 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;
        _error_details = d;
@@ -348,6 +356,7 @@ Job::pause ()
 {
        if (running ()) {
                set_state (PAUSED);
+               _pause_changed.notify_all ();
        }
 }
 
@@ -356,5 +365,6 @@ Job::resume ()
 {
        if (paused ()) {
                set_state (RUNNING);
+               _pause_changed.notify_all ();
        }
 }