X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fjob.cc;h=2c2e0667329c1c0ef435d036fd31c256d109000a;hb=8f12ef26c5f6c0e9f408828b99ff8bdc90236406;hp=d9715aa18535603d6040b6c8287b2788e385f086;hpb=1d68fe1e3ad1a9aa85fa7fc6071a0b8c64973953;p=dcpomatic.git diff --git a/src/lib/job.cc b/src/lib/job.cc index d9715aa18..2c2e06673 100644 --- a/src/lib/job.cc +++ b/src/lib/job.cc @@ -31,6 +31,7 @@ #include #include #include +#include #include "i18n.h" @@ -39,9 +40,12 @@ using std::list; using std::cout; using boost::shared_ptr; using boost::optional; +using boost::function; -#define LOG_ERROR_NC(...) _film->log()->log (__VA_ARGS__, Log::TYPE_ERROR); +#define LOG_ERROR_NC(...) _film->log()->log (__VA_ARGS__, LogEntry::TYPE_ERROR); +#define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL); +/** @param film Associated film, or 0 */ Job::Job (shared_ptr film) : _film (film) , _thread (0) @@ -53,6 +57,17 @@ Job::Job (shared_ptr film) } +Job::~Job () +{ + if (_thread) { + _thread->interrupt (); + DCPOMATIC_ASSERT (_thread->joinable ()); + _thread->join (); + } + + delete _thread; +} + /** Start the job in a separate thread, returning immediately */ void Job::start () @@ -92,7 +107,10 @@ Job::run_wrapper () set_error ( String::compose (_("Could not open %1"), e.file().string()), - String::compose (_("DCP-o-matic could not open the file %1. Perhaps it does not exist or is in an unexpected format."), e.file().string()) + String::compose ( + _("DCP-o-matic could not open the file %1. Perhaps it does not exist or is in an unexpected format."), + boost::filesystem::absolute (e.file()).string() + ) ); set_progress (1); @@ -103,7 +121,10 @@ Job::run_wrapper () if (e.code() == boost::system::errc::no_such_file_or_directory) { set_error ( String::compose (_("Could not open %1"), e.path1().string ()), - String::compose (_("DCP-o-matic could not open the file %1. Perhaps it does not exist or is in an unexpected format."), e.path1().string()) + String::compose ( + _("DCP-o-matic could not open the file %1. Perhaps it does not exist or is in an unexpected format."), + boost::filesystem::absolute (e.path1()).string() + ) ); } else { set_error ( @@ -121,7 +142,7 @@ Job::run_wrapper () } catch (std::bad_alloc& e) { - set_error (_("Out of memory"), _("There was not enough memory to do this.")); + set_error (_("Out of memory"), _("There was not enough memory to do this. If you are running a 32-bit operating system try reducing the number of encoding threads in the General tab of Preferences.")); set_progress (1); set_state (FINISHED_ERROR); @@ -247,6 +268,12 @@ Job::set_progress (float p, bool force) return; } + set_progress_common (p); +} + +void +Job::set_progress_common (optional p) +{ boost::mutex::scoped_lock lm (_progress_mutex); _progress = p; boost::this_thread::interruption_point (); @@ -275,6 +302,7 @@ Job::sub (string n) { { boost::mutex::scoped_lock lm (_progress_mutex); + LOG_GENERAL ("Sub-job %1 starting", n); _sub_name = n; } @@ -302,10 +330,12 @@ Job::error_summary () const void Job::set_error (string s, string d) { - LOG_ERROR_NC (s); - LOG_ERROR_NC (d); + if (_film) { + LOG_ERROR_NC (s); + LOG_ERROR_NC (d); + _film->log()->log (String::compose ("Error in job: %1 (%2)", s, d), LogEntry::TYPE_ERROR); + } - _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; @@ -315,11 +345,7 @@ Job::set_error (string s, string d) void Job::set_progress_unknown () { - boost::mutex::scoped_lock lm (_progress_mutex); - _progress.reset (); - lm.unlock (); - - emit (boost::bind (boost::ref (Progress))); + set_progress_common (optional ()); } /** @return Human-readable status of this job */ @@ -402,7 +428,10 @@ Job::cancel () } _thread->interrupt (); + DCPOMATIC_ASSERT (_thread->joinable ()); _thread->join (); + delete _thread; + _thread = 0; } void @@ -422,3 +451,14 @@ Job::resume () _pause_changed.notify_all (); } } + +void +Job::when_finished (boost::signals2::connection& connection, function finished) +{ + boost::mutex::scoped_lock lm (_state_mutex); + if (_state == FINISHED_OK || _state == FINISHED_ERROR || _state == FINISHED_CANCELLED) { + finished (); + } else { + connection = Finished.connect (finished); + } +}