/*
- 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
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- This program is distributed in the hope that it will be useful,
+ DCP-o-matic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
*/
#include "job_manager.h"
#include "job.h"
#include "util.h"
+#include "film.h"
#include "transcode_job.h"
+#include <boost/make_shared.hpp>
+#include <iostream>
using std::string;
-using std::stringstream;
using std::cout;
using std::map;
using std::list;
using boost::thread;
using boost::shared_ptr;
+using boost::make_shared;
using boost::dynamic_pointer_cast;
using boost::asio::ip::tcp;
{
boost::asio::io_service io_service;
tcp::acceptor a (io_service, tcp::endpoint (tcp::v4 (), port));
- while (1) {
+ while (true) {
try {
- shared_ptr<tcp::socket> s (new tcp::socket (io_service));
+ shared_ptr<tcp::socket> s = make_shared<tcp::socket> (io_service);
a.accept (*s);
handle (s);
}
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);
JSONServer::request (string url, shared_ptr<tcp::socket> socket)
{
cout << "request: " << url << "\n";
-
+
map<string, string> r = split_get_request (url);
for (map<string, string>::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;
+
+ SafeStringStream json;
if (action == "status") {
-
+
list<shared_ptr<Job> > jobs = JobManager::instance()->get ();
-
+
json << "{ \"jobs\": [";
for (list<shared_ptr<Job> >::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<shared_ptr<Job> >::iterator j = i;
++j;
if (j != jobs.end ()) {
}
}
json << "] }";
-
+
if (json.str().empty ()) {
json << "{ }";
}
}
-
- stringstream reply;
+
+ SafeStringStream reply;
reply << "HTTP/1.1 200 OK\r\n"
<< "Content-Length: " << json.str().length() << "\r\n"
<< "Content-Type: application/json\r\n"