X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fjson_server.cc;h=c7a3ca144e4c5974c7e632ba970955c6eb9f103c;hb=f09e6545efa4c5ca816e89e28a287bc6ab1ee50b;hp=9d625a287ff454d3da10c9fca6581051de84546d;hpb=830acd944e1a194d8639f51cd72d3839ecd0ecfe;p=dcpomatic.git diff --git a/src/lib/json_server.cc b/src/lib/json_server.cc index 9d625a287..c7a3ca144 100644 --- a/src/lib/json_server.cc +++ b/src/lib/json_server.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Carl Hetherington + Copyright (C) 2014-2015 Carl Hetherington 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 @@ -24,7 +24,9 @@ #include "job_manager.h" #include "job.h" #include "util.h" +#include "film.h" #include "transcode_job.h" +#include using std::string; using std::stringstream; @@ -57,7 +59,7 @@ try { boost::asio::io_service io_service; tcp::acceptor a (io_service, tcp::endpoint (tcp::v4 (), port)); - while (1) { + while (true) { try { shared_ptr s (new tcp::socket (io_service)); a.accept (*s); @@ -79,7 +81,7 @@ JSONServer::handle (shared_ptr socket) string url; State state = AWAITING_G; - while (1) { + while (true) { char data[MAX_LENGTH]; boost::system::error_code error; size_t len = socket->read_some (boost::asio::buffer (data), error); @@ -138,32 +140,40 @@ void JSONServer::request (string url, shared_ptr socket) { cout << "request: " << url << "\n"; - + map r = split_get_request (url); for (map::iterator i = r.begin(); i != r.end(); ++i) { cout << i->first << " => " << i->second << "\n"; } - + string action; if (r.find ("action") != r.end ()) { action = r["action"]; } - + stringstream json; if (action == "status") { - + list > jobs = JobManager::instance()->get (); - + json << "{ \"jobs\": ["; for (list >::iterator i = jobs.begin(); i != jobs.end(); ++i) { - json << "{ " - << "\"name\": \"" << (*i)->json_name() << "\", " - << "\"progress\": " << (*i)->progress () << ", " - << "\"status\": \"" << (*i)->json_status() << "\""; - + json << "{ "; + + if ((*i)->film()) { + json << "\"dcp\": \"" << (*i)->film()->dcp_name() << "\", "; + } + + json << "\"name\": \"" << (*i)->json_name() << "\", "; + if ((*i)->progress ()) { + json << "\"progress\": " << (*i)->progress().get() << ", "; + } else { + json << "\"progress\": unknown, "; + } + json << "\"status\": \"" << (*i)->json_status() << "\""; json << " }"; - + list >::iterator j = i; ++j; if (j != jobs.end ()) { @@ -171,12 +181,12 @@ JSONServer::request (string url, shared_ptr socket) } } json << "] }"; - + if (json.str().empty ()) { json << "{ }"; } } - + stringstream reply; reply << "HTTP/1.1 200 OK\r\n" << "Content-Length: " << json.str().length() << "\r\n"