swaroop: beginnings of DCP -> ecinema support.
[dcpomatic.git] / src / lib / util.cc
index 1f6fba96302b4f9b3dc8943374860221fcc7b1cf..3b6be6dcc227625d28574da53b3af4419d893d28 100644 (file)
@@ -44,6 +44,7 @@
 #include "ffmpeg_image_proxy.h"
 #include "image.h"
 #include "text_decoder.h"
+#include "job_manager.h"
 #include <dcp/locale_convert.h>
 #include <dcp/util.h>
 #include <dcp/raw_convert.h>
@@ -945,6 +946,70 @@ emit_subtitle_image (ContentTimePeriod period, dcp::SubtitleImage sub, dcp::Size
        decoder->emit_bitmap (period, image, rect);
 }
 
+bool
+show_jobs_on_console (bool progress)
+{
+       bool should_stop = false;
+       bool first = true;
+       bool error = false;
+       while (!should_stop) {
+
+               dcpomatic_sleep (5);
+
+               list<shared_ptr<Job> > jobs = JobManager::instance()->get();
+
+               if (!first && progress) {
+                       for (size_t i = 0; i < jobs.size(); ++i) {
+                               cout << "\033[1A\033[2K";
+                       }
+                       cout.flush ();
+               }
+
+               first = false;
+
+               int unfinished = 0;
+               int finished_in_error = 0;
+
+               BOOST_FOREACH (shared_ptr<Job> i, jobs) {
+                       if (progress) {
+                               cout << i->name();
+                               if (!i->sub_name().empty()) {
+                                       cout << "; " << i->sub_name();
+                               }
+                               cout << ": ";
+
+                               if (i->progress ()) {
+                                       cout << i->status() << "                            \n";
+                               } else {
+                                       cout << ": Running           \n";
+                               }
+                       }
+
+                       if (!i->finished ()) {
+                               ++unfinished;
+                       }
+
+                       if (i->finished_in_error ()) {
+                               ++finished_in_error;
+                               error = true;
+                       }
+
+                       if (!progress && i->finished_in_error ()) {
+                               /* We won't see this error if we haven't been showing progress,
+                                  so show it now.
+                               */
+                               cout << i->status() << "\n";
+                       }
+               }
+
+               if (unfinished == 0 || finished_in_error != 0) {
+                       should_stop = true;
+               }
+       }
+
+       return error;
+}
+
 #ifdef DCPOMATIC_VARIANT_SWAROOP
 
 /* Make up a key from the machine UUID */