Take Film pointer out of Content.
[dcpomatic.git] / src / lib / job.cc
index 61c5b376734d202624967f24156dbfe5e7c8f002..7539a50703faa2074375bbf17ff7639509a7ddc5 100644 (file)
@@ -87,6 +87,9 @@ Job::start ()
        _start_time = time (0);
        _sub_start_time = time (0);
        _thread = new boost::thread (boost::bind (&Job::run_wrapper, this));
+#ifdef DCPOMATIC_LINUX
+       pthread_setname_np (_thread->native_handle(), "job-wrapper");
+#endif
 }
 
 /** A wrapper for the ::run() method to catch exceptions */
@@ -171,6 +174,18 @@ Job::run_wrapper ()
                set_progress (1);
                set_state (FINISHED_ERROR);
 
+       } catch (dcp::DCPReadError& e) {
+
+               set_error (e.message(), e.detail().get_value_or(""));
+               set_progress (1);
+               set_state (FINISHED_ERROR);
+
+       } catch (KDMError& e) {
+
+               set_error (e.summary(), e.detail());
+               set_progress (1);
+               set_state (FINISHED_ERROR);
+
        } catch (std::exception& e) {
 
                set_error (
@@ -384,8 +399,6 @@ void
 Job::set_error (string s, string 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);
        }
 
@@ -504,13 +517,27 @@ Job::cancel ()
        _thread = 0;
 }
 
-void
+/** @return true if the job was paused, false if it was not running */
+bool
 Job::pause_by_user ()
 {
-       if (running ()) {
-               set_state (PAUSED_BY_USER);
+       bool paused = false;
+       {
+               boost::mutex::scoped_lock lm (_state_mutex);
+               /* We can set _state here directly because we have a lock and we aren't
+                  setting the job to FINISHED_*
+               */
+               if (_state == RUNNING) {
+                       paused = true;
+                       _state = PAUSED_BY_USER;
+               }
+       }
+
+       if (paused) {
                _pause_changed.notify_all ();
        }
+
+       return paused;
 }
 
 void
@@ -541,3 +568,17 @@ Job::when_finished (boost::signals2::connection& connection, function<void()> fi
                connection = Finished.connect (finished);
        }
 }
+
+optional<string>
+Job::message () const
+{
+       boost::mutex::scoped_lock lm (_state_mutex);
+       return _message;
+}
+
+void
+Job::set_message (string m)
+{
+       boost::mutex::scoped_lock lm (_state_mutex);
+       _message = m;
+}