Add Job::seconds_since_last_progress_update().
authorCarl Hetherington <cth@carlh.net>
Thu, 4 Nov 2021 22:43:54 +0000 (23:43 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 13 Nov 2021 21:34:20 +0000 (22:34 +0100)
src/lib/job.cc
src/lib/job.h

index cb2120de1ea492fb907f3a74d5653a3f007739eb..4c8199bdcc1b52294368b305f101238dd222f0c9 100644 (file)
@@ -361,6 +361,22 @@ Job::check_for_interruption_or_pause ()
        }
 }
 
+
+optional<float>
+Job::seconds_since_last_progress_update () const
+{
+       boost::mutex::scoped_lock lm (_progress_mutex);
+       if (!_last_progress_update) {
+               return {};
+       }
+
+       struct timeval now;
+       gettimeofday (&now, 0);
+
+       return seconds(now) - seconds(*_last_progress_update);
+}
+
+
 /** Set the progress of the current part of the job.
  *  @param p Progress (from 0 to 1)
  *  @param force Do not ignore this update, even if it hasn't been long since the last one.
index 96f0acbe5a0c886d54a9b96128eed3c5a11a439d..b44fd1365ee503c6479f6148907145d473d656ff 100644 (file)
@@ -81,6 +81,7 @@ public:
        void set_progress (float, bool force = false);
        void sub (std::string);
        boost::optional<float> progress () const;
+       boost::optional<float> seconds_since_last_progress_update () const;
 
        std::shared_ptr<const Film> film () const {
                return _film;