Hand-apply e30fd8d; resurrect JSON server code.
authorCarl Hetherington <cth@carlh.net>
Tue, 24 Mar 2015 23:57:22 +0000 (23:57 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 24 Mar 2015 23:57:22 +0000 (23:57 +0000)
21 files changed:
ChangeLog
TO_PORT
src/lib/analyse_audio_job.cc
src/lib/analyse_audio_job.h
src/lib/examine_content_job.cc
src/lib/examine_content_job.h
src/lib/job.cc
src/lib/job.h
src/lib/scp_dcp_job.cc
src/lib/scp_dcp_job.h
src/lib/send_kdm_email_job.cc
src/lib/send_kdm_email_job.h
src/lib/send_problem_report_job.cc
src/lib/send_problem_report_job.h
src/lib/transcode_job.cc
src/lib/transcode_job.h
src/lib/util.cc
src/lib/util.h
src/lib/wscript
src/tools/dcpomatic_cli.cc
test/job_test.cc

index b063002d9f1c3c3e372aea4736636d0b7018b810..9fb6dff1dfe2be04fb1caec9c113d63490f2c6f7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2015-03-24  Carl Hetherington  <cth@carlh.net>
 
+       * Hand-apply e30fd8d; resurrect JSON server code.
+
        * Hand-apply 7ba9dcdbfe8f0d94ad9887843995c152c45dfe9e from master;
        allow "deletion" of the audio part of a FFmpeg file from the
        timeline; delete unmaps the audio (#316).
diff --git a/TO_PORT b/TO_PORT
index 8e85ad774300b070229a42dbba37da38bf942b28..daab0e85f0dfb27add02aa20f7a6e9888a2143a2 100644 (file)
--- a/TO_PORT
+++ b/TO_PORT
@@ -1,4 +1,3 @@
-e30fd8d
 31eafa8a121b8d341d198e4fe426ee843cc70167
 3e3d3e46a74af7b3e6431033c7c80bd058c02cf6
 ec3e6abf817b84d589f0782b01f5059dd3bf0953
index 74c0125f3f6c2059d8af58820e9789eb79d1c584..079fe884e762f76980f1b08799f659363ed9ef8b 100644 (file)
@@ -49,6 +49,12 @@ AnalyseAudioJob::name () const
        return _("Analyse audio");
 }
 
+string
+AnalyseAudioJob::json_name () const
+{
+       return N_("analyse_audio");
+}
+
 void
 AnalyseAudioJob::run ()
 {
index bde9d0d403fae5723e48950adec02ff8eb676bd7..6f64dd27248c13f029aab6257c35181f57ad972b 100644 (file)
@@ -41,6 +41,7 @@ public:
        AnalyseAudioJob (boost::shared_ptr<const Film>, boost::shared_ptr<AudioContent>);
 
        std::string name () const;
+       std::string json_name () const;
        void run ();
 
 private:
index 2b8f118f8d11b0cf665dbf621913afc984ca7ade..b5441e36b55c662451f2a3d9bab92bcd45a72fa6 100644 (file)
@@ -46,6 +46,12 @@ ExamineContentJob::name () const
        return _("Examine content");
 }
 
+string
+ExamineContentJob::json_name () const
+{
+       return N_("examine_content");
+}
+
 void
 ExamineContentJob::run ()
 {
index 016a56371de1ff8f8641b137484a2712d6d9ad04..b97e7823d6b99b808e18c0ddd0ab6fbbd4ba5096 100644 (file)
@@ -30,6 +30,7 @@ public:
        ~ExamineContentJob ();
 
        std::string name () const;
+       std::string json_name () const;
        void run ();
 
 private:
index 547b484a37affe06e01df7ecd940510f66c902f3..eadafbf73a1f8d6b20c3ffca9527d90a68f2fb18 100644 (file)
@@ -340,6 +340,29 @@ Job::status () const
        return s.str ();
 }
 
+string
+Job::json_status () const
+{
+       boost::mutex::scoped_lock lm (_state_mutex);
+
+       switch (_state) {
+       case NEW:
+               return N_("new");
+       case RUNNING:
+               return N_("running");
+       case PAUSED:
+               return N_("paused");
+       case FINISHED_OK:
+               return N_("finished_ok");
+       case FINISHED_ERROR:
+               return N_("finished_error");
+       case FINISHED_CANCELLED:
+               return N_("finished_cancelled");
+       }
+
+       return "";
+}
+
 /** @return An estimate of the remaining time for this sub-job, in seconds */
 int
 Job::remaining_time () const
index f6120f1289458814d3569970a177ab5257a884b6..7c6707880d752cc62d3c7a0c602c7f7272ebaff2 100644 (file)
@@ -43,6 +43,7 @@ public:
 
        /** @return user-readable name of this job */
        virtual std::string name () const = 0;
+       virtual std::string json_name () const = 0;
        /** Run this job in the current thread. */
        virtual void run () = 0;
        
@@ -64,6 +65,7 @@ public:
 
        int elapsed_time () const;
        virtual std::string status () const;
+       std::string json_status () const;
        std::string sub_name () const {
                return _sub_name;
        }
index 67a1fb8026a68325b768a86fa1808dd258345490..5aade6382d13b3442dee91ca94f98cb7fad05838 100644 (file)
@@ -111,6 +111,12 @@ SCPDCPJob::name () const
        return _("Copy DCP to TMS");
 }
 
+string
+SCPDCPJob::json_name () const
+{
+       return N_("scp_dcp");
+}
+
 void
 SCPDCPJob::run ()
 {
index bdc83af187f85a0091d31e107d554ee9dd07ef4c..e3960d73b512dac54d25124be28740d15dfd67cf 100644 (file)
@@ -29,6 +29,7 @@ public:
        SCPDCPJob (boost::shared_ptr<const Film>);
 
        std::string name () const;
+       std::string json_name () const;
        void run ();
        std::string status () const;
 
index 541307f5acc8ace90d682b5b396046ddcdcbab2e..de03222725074b9a6a9fdfa670a463de0f88f396 100644 (file)
@@ -52,6 +52,12 @@ SendKDMEmailJob::name () const
        return String::compose (_("Email KDMs for %1"), _film->name());
 }
 
+string
+SendKDMEmailJob::json_name () const
+{
+       return N_("send_kdm_email");
+}
+
 void
 SendKDMEmailJob::run ()
 {
index 8d9f9b008f721d2413e1b28930bda0eb47e89a0b..5226bb79744bfa6942c17bf4f48b7ab6154b73ef 100644 (file)
@@ -36,6 +36,7 @@ public:
                );
 
        std::string name () const;
+       std::string json_name () const;
        void run ();
 
 private:
index b2eb4e25dcbf72bde9dfddb897b761ba3f1e7cbc..b0e37c5ef226301caacac73c1f496e9f6fac37b1 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2015 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
@@ -49,6 +49,12 @@ SendProblemReportJob::name () const
        return String::compose (_("Email problem report for %1"), _film->name());
 }
 
+string
+SendProblemReportJob::json_name () const
+{
+       return N_("send_problem_report");
+}
+
 void
 SendProblemReportJob::run ()
 {
index c40011d0ce733696c09e0f343258e6071905aae7..8c4d9db253a6d02e116333ee791a23ecac63c0ac 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2015 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
@@ -31,6 +31,7 @@ public:
                );
 
        std::string name () const;
+       std::string json_name () const;
        void run ();
 
 private:
index fe2ad6775f351e2748b4ad5b5052ab3c3762e226..1a2202ad2f2b91b9914297c07c9852ff227b3cb7 100644 (file)
@@ -54,6 +54,12 @@ TranscodeJob::name () const
        return String::compose (_("Transcode %1"), _film->name());
 }
 
+string
+TranscodeJob::json_name () const
+{
+       return N_("transcode");
+}
+
 void
 TranscodeJob::run ()
 {
index 97a7d49f2c8efb4082513256ceb7cb84f401de96..e0145d7d06e082a998bda94f172546166700c7c4 100644 (file)
@@ -35,6 +35,7 @@ public:
        TranscodeJob (boost::shared_ptr<const Film> f);
        
        std::string name () const;
+       std::string json_name () const;
        void run ();
        std::string status () const;
 
index 6bb16c4420799e9172cabf44f9fee62e572454d9..2b5eb69fb07c64ff5aa1340f53b71e9adadc8c56 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2015 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
@@ -70,6 +70,7 @@ using std::endl;
 using std::vector;
 using std::min;
 using std::max;
+using std::map;
 using std::list;
 using std::multimap;
 using std::istream;
@@ -576,3 +577,49 @@ subtitle_period (AVSubtitle const & sub)
 
        return period;
 }
+
+map<string, string>
+split_get_request (string url)
+{
+       enum {
+               AWAITING_QUESTION_MARK,
+               KEY,
+               VALUE
+       } state = AWAITING_QUESTION_MARK;
+       
+       map<string, string> r;
+       string k;
+       string v;
+       for (size_t i = 0; i < url.length(); ++i) {
+               switch (state) {
+               case AWAITING_QUESTION_MARK:
+                       if (url[i] == '?') {
+                               state = KEY;
+                       }
+                       break;
+               case KEY:
+                       if (url[i] == '=') {
+                               v.clear ();
+                               state = VALUE;
+                       } else {
+                               k += url[i];
+                       }
+                       break;
+               case VALUE:
+                       if (url[i] == '&') {
+                               r.insert (make_pair (k, v));
+                               k.clear ();
+                               state = KEY;
+                       } else {
+                               v += url[i];
+                       }
+                       break;
+               }
+       }
+
+       if (state == VALUE) {
+               r.insert (make_pair (k, v));
+       }
+
+       return r;
+}
index bfb39fc1da39d95e4b02bca24fc76209c40da565..97e119389d9462c23181be1ddee453dd92a1e5eb 100644 (file)
@@ -76,6 +76,7 @@ extern void* wrapped_av_malloc (size_t);
 extern ContentTimePeriod subtitle_period (AVSubtitle const &);
 extern void set_backtrace_file (boost::filesystem::path);
 extern int64_t video_frames_to_audio_frames (VideoFrame v, float audio_sample_rate, float frames_per_second);
+extern std::map<std::string, std::string> split_get_request (std::string url);
 
 #endif
 
index 322f87792963abb6ee74deeaf4d58dbe27351b62..217c0c86d9e1546c7d6aa6fb096c1f31c2c91436 100644 (file)
@@ -58,6 +58,7 @@ sources = """
           job.cc
           job_manager.cc
           kdm.cc
+          json_server.cc
           log.cc
           magick_image_proxy.cc
           md5_digester.cc
index 2a2db9842a4599e23eb080d98bdf8470aee26bdc..e187e573e2887caaa5ef877f245b4ffc38da5c82 100644 (file)
@@ -33,6 +33,7 @@
 #include "lib/log.h"
 #include "lib/ui_signaller.h"
 #include "lib/server_finder.h"
+#include "lib/json_server.h"
 
 using std::string;
 using std::cerr;
@@ -41,6 +42,7 @@ using std::vector;
 using std::pair;
 using std::list;
 using boost::shared_ptr;
+using boost::optional;
 
 static void
 help (string n)
@@ -51,6 +53,7 @@ help (string n)
             << "  -f, --flags        show flags passed to C++ compiler on build\n"
             << "  -n, --no-progress  do not print progress to stdout\n"
             << "  -r, --no-remote    do not use any remote servers\n"
+            << "  -j, --json <port>  run a JSON server on the specified port\n"
             << "  -k, --keep-going   keep running even when the job is complete\n"
             << "\n"
             << "<FILM> is the film directory.\n";
@@ -62,6 +65,7 @@ main (int argc, char* argv[])
        string film_dir;
        bool progress = true;
        bool no_remote = false;
+       optional<int> json_port;
        bool keep_going = false;
 
        int option_index = 0;
@@ -72,11 +76,12 @@ main (int argc, char* argv[])
                        { "flags", no_argument, 0, 'f'},
                        { "no-progress", no_argument, 0, 'n'},
                        { "no-remote", no_argument, 0, 'r'},
+                       { "json", required_argument, 0, 'j'},
                        { "keep-going", no_argument, 0, 'k' },
                        { 0, 0, 0, 0 }
                };
 
-               int c = getopt_long (argc, argv, "vhfnrk", long_options, &option_index);
+               int c = getopt_long (argc, argv, "vhfnrj:k", long_options, &option_index);
 
                if (c == -1) {
                        break;
@@ -98,6 +103,9 @@ main (int argc, char* argv[])
                case 'r':
                        no_remote = true;
                        break;
+               case 'j':
+                       json_port = atoi (optarg);
+                       break;
                case 'k':
                        keep_going = true;
                        break;
@@ -113,11 +121,15 @@ main (int argc, char* argv[])
                        
        dcpomatic_setup ();
        ui_signaller = new UISignaller ();
-
+       
        if (no_remote) {
                ServerFinder::instance()->disable ();
        }
 
+       if (json_port) {
+               new JSONServer (json_port.get ());
+       }
+
        cout << "DCP-o-matic " << dcpomatic_version << " git " << dcpomatic_git_commit;
        char buf[256];
        if (gethostname (buf, 256) == 0) {
index 97a23b946a765eb7c758c41678960d3f0d69ea81..c1b66d4e01f38f36127c49087c79473cbdb20739 100644 (file)
@@ -58,6 +58,10 @@ public:
        string name () const {
                return "";
        }
+
+       string json_name () const {
+               return "";
+       }
 };
 
 BOOST_AUTO_TEST_CASE (job_manager_test)