summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-03-24 23:57:22 +0000
committerCarl Hetherington <cth@carlh.net>2015-03-24 23:57:22 +0000
commita71a3b3d0f8545e44af75ded10dfda4a382158f2 (patch)
treeefb300dac7006409079d544eecc9dc1e5b792e45 /src
parent86aaba4f392c35ccf28221049f87b8cdba868777 (diff)
Hand-apply e30fd8d; resurrect JSON server code.
Diffstat (limited to 'src')
-rw-r--r--src/lib/analyse_audio_job.cc6
-rw-r--r--src/lib/analyse_audio_job.h1
-rw-r--r--src/lib/examine_content_job.cc6
-rw-r--r--src/lib/examine_content_job.h1
-rw-r--r--src/lib/job.cc23
-rw-r--r--src/lib/job.h2
-rw-r--r--src/lib/scp_dcp_job.cc6
-rw-r--r--src/lib/scp_dcp_job.h1
-rw-r--r--src/lib/send_kdm_email_job.cc6
-rw-r--r--src/lib/send_kdm_email_job.h1
-rw-r--r--src/lib/send_problem_report_job.cc8
-rw-r--r--src/lib/send_problem_report_job.h3
-rw-r--r--src/lib/transcode_job.cc6
-rw-r--r--src/lib/transcode_job.h1
-rw-r--r--src/lib/util.cc49
-rw-r--r--src/lib/util.h1
-rw-r--r--src/lib/wscript1
-rw-r--r--src/tools/dcpomatic_cli.cc16
18 files changed, 133 insertions, 5 deletions
diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc
index 74c0125f3..079fe884e 100644
--- a/src/lib/analyse_audio_job.cc
+++ b/src/lib/analyse_audio_job.cc
@@ -49,6 +49,12 @@ AnalyseAudioJob::name () const
return _("Analyse audio");
}
+string
+AnalyseAudioJob::json_name () const
+{
+ return N_("analyse_audio");
+}
+
void
AnalyseAudioJob::run ()
{
diff --git a/src/lib/analyse_audio_job.h b/src/lib/analyse_audio_job.h
index bde9d0d40..6f64dd272 100644
--- a/src/lib/analyse_audio_job.h
+++ b/src/lib/analyse_audio_job.h
@@ -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:
diff --git a/src/lib/examine_content_job.cc b/src/lib/examine_content_job.cc
index 2b8f118f8..b5441e36b 100644
--- a/src/lib/examine_content_job.cc
+++ b/src/lib/examine_content_job.cc
@@ -46,6 +46,12 @@ ExamineContentJob::name () const
return _("Examine content");
}
+string
+ExamineContentJob::json_name () const
+{
+ return N_("examine_content");
+}
+
void
ExamineContentJob::run ()
{
diff --git a/src/lib/examine_content_job.h b/src/lib/examine_content_job.h
index 016a56371..b97e7823d 100644
--- a/src/lib/examine_content_job.h
+++ b/src/lib/examine_content_job.h
@@ -30,6 +30,7 @@ public:
~ExamineContentJob ();
std::string name () const;
+ std::string json_name () const;
void run ();
private:
diff --git a/src/lib/job.cc b/src/lib/job.cc
index 547b484a3..eadafbf73 100644
--- a/src/lib/job.cc
+++ b/src/lib/job.cc
@@ -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
diff --git a/src/lib/job.h b/src/lib/job.h
index f6120f128..7c6707880 100644
--- a/src/lib/job.h
+++ b/src/lib/job.h
@@ -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;
}
diff --git a/src/lib/scp_dcp_job.cc b/src/lib/scp_dcp_job.cc
index 67a1fb802..5aade6382 100644
--- a/src/lib/scp_dcp_job.cc
+++ b/src/lib/scp_dcp_job.cc
@@ -111,6 +111,12 @@ SCPDCPJob::name () const
return _("Copy DCP to TMS");
}
+string
+SCPDCPJob::json_name () const
+{
+ return N_("scp_dcp");
+}
+
void
SCPDCPJob::run ()
{
diff --git a/src/lib/scp_dcp_job.h b/src/lib/scp_dcp_job.h
index bdc83af18..e3960d73b 100644
--- a/src/lib/scp_dcp_job.h
+++ b/src/lib/scp_dcp_job.h
@@ -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;
diff --git a/src/lib/send_kdm_email_job.cc b/src/lib/send_kdm_email_job.cc
index 541307f5a..de0322272 100644
--- a/src/lib/send_kdm_email_job.cc
+++ b/src/lib/send_kdm_email_job.cc
@@ -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 ()
{
diff --git a/src/lib/send_kdm_email_job.h b/src/lib/send_kdm_email_job.h
index 8d9f9b008..5226bb797 100644
--- a/src/lib/send_kdm_email_job.h
+++ b/src/lib/send_kdm_email_job.h
@@ -36,6 +36,7 @@ public:
);
std::string name () const;
+ std::string json_name () const;
void run ();
private:
diff --git a/src/lib/send_problem_report_job.cc b/src/lib/send_problem_report_job.cc
index b2eb4e25d..b0e37c5ef 100644
--- a/src/lib/send_problem_report_job.cc
+++ b/src/lib/send_problem_report_job.cc
@@ -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 ()
{
diff --git a/src/lib/send_problem_report_job.h b/src/lib/send_problem_report_job.h
index c40011d0c..8c4d9db25 100644
--- a/src/lib/send_problem_report_job.h
+++ b/src/lib/send_problem_report_job.h
@@ -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:
diff --git a/src/lib/transcode_job.cc b/src/lib/transcode_job.cc
index fe2ad6775..1a2202ad2 100644
--- a/src/lib/transcode_job.cc
+++ b/src/lib/transcode_job.cc
@@ -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 ()
{
diff --git a/src/lib/transcode_job.h b/src/lib/transcode_job.h
index 97a7d49f2..e0145d7d0 100644
--- a/src/lib/transcode_job.h
+++ b/src/lib/transcode_job.h
@@ -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;
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 6bb16c442..2b5eb69fb 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -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;
+}
diff --git a/src/lib/util.h b/src/lib/util.h
index bfb39fc1d..97e119389 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -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
diff --git a/src/lib/wscript b/src/lib/wscript
index 322f87792..217c0c86d 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -58,6 +58,7 @@ sources = """
job.cc
job_manager.cc
kdm.cc
+ json_server.cc
log.cc
magick_image_proxy.cc
md5_digester.cc
diff --git a/src/tools/dcpomatic_cli.cc b/src/tools/dcpomatic_cli.cc
index 2a2db9842..e187e573e 100644
--- a/src/tools/dcpomatic_cli.cc
+++ b/src/tools/dcpomatic_cli.cc
@@ -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) {