Logging improvements to allow prettier displays in the server GUI.
[dcpomatic.git] / src / lib / json_server.cc
index 1be3c7d0e9d894698534d84d6df4aaeaea265c30..c7a3ca144e4c5974c7e632ba970955c6eb9f103c 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
@@ -26,6 +26,7 @@
 #include "util.h"
 #include "film.h"
 #include "transcode_job.h"
+#include <iostream>
 
 using std::string;
 using std::stringstream;
@@ -139,22 +140,22 @@ void
 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;
        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) {
 
@@ -163,12 +164,16 @@ JSONServer::request (string url, shared_ptr<tcp::socket> socket)
                        if ((*i)->film()) {
                                json << "\"dcp\": \"" << (*i)->film()->dcp_name() << "\", ";
                        }
-                       
-                       json << "\"name\": \""   << (*i)->json_name() << "\", "
-                            << "\"progress\": " << (*i)->progress () << ", "
-                            << "\"status\": \"" << (*i)->json_status() << "\"";
+
+                       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 ()) {
@@ -176,12 +181,12 @@ JSONServer::request (string url, shared_ptr<tcp::socket> socket)
                        }
                }
                json << "] }";
-               
+
                if (json.str().empty ()) {
                        json << "{ }";
                }
        }
-       
+
        stringstream reply;
        reply << "HTTP/1.1 200 OK\r\n"
              << "Content-Length: " << json.str().length() << "\r\n"