Tinker with verbosity of command-line server.
authorCarl Hetherington <cth@carlh.net>
Tue, 5 Nov 2013 22:59:39 +0000 (22:59 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 5 Nov 2013 22:59:39 +0000 (22:59 +0000)
src/lib/server.cc
src/lib/server.h
src/tools/dcpomatic_server.cc
src/tools/dcpomatic_server_cli.cc
test/client_server_test.cc

index 5010a2051df0e92e7e6b23efac3af963fb4f83f1..ff77f8e8feba3e6d70161cf61c4f297f884196ba 100644 (file)
@@ -46,6 +46,7 @@ using std::multimap;
 using std::vector;
 using std::list;
 using std::cout;
+using std::cerr;
 using boost::shared_ptr;
 using boost::algorithm::is_any_of;
 using boost::algorithm::split;
@@ -86,8 +87,9 @@ ServerDescription::create_from_metadata (string v)
        return ServerDescription (b[0], atoi (b[1].c_str ()));
 }
 
-Server::Server (shared_ptr<Log> log)
+Server::Server (shared_ptr<Log> log, bool verbose)
        : _log (log)
+       , _verbose (verbose)
 {
 
 }
@@ -103,6 +105,7 @@ Server::process (shared_ptr<Socket> socket)
        shared_ptr<cxml::Document> xml (new cxml::Document ("EncodingRequest"));
        xml->read_stream (s);
        if (xml->number_child<int> ("Version") != SERVER_LINK_VERSION) {
+               cerr << "Mismatched server/client versions\n";
                _log->log ("Mismatched server/client versions");
                return -1;
        }
@@ -163,8 +166,16 @@ Server::worker_thread ()
                if (frame >= 0) {
                        struct timeval end;
                        gettimeofday (&end, 0);
-                       cout << String::compose ("Encoded frame %1 in %2", frame, seconds (end) - seconds (start)) << "\n";
-                       _log->log (String::compose ("Encoded frame %1 in %2", frame, seconds (end) - seconds (start)));
+
+                       string const message = String::compose (
+                               "Encoded frame %1 from %2 in %3s", frame, socket->socket().remote_endpoint().address().to_string(), seconds(end) - seconds(start)
+                               );
+                       
+                       if (_verbose) {
+                               cout << message << "\n";
+                       }
+
+                       _log->log (message);
                }
                
                _worker_condition.notify_all ();
@@ -174,7 +185,10 @@ Server::worker_thread ()
 void
 Server::run (int num_threads)
 {
-       _log->log (String::compose (N_("Server starting with %1 threads"), num_threads));
+       _log->log (String::compose ("Server starting with %1 threads", num_threads));
+       if (_verbose) {
+               cout << "DCP-o-matic server started with " << num_threads << " threads.\n";
+       }
        
        for (int i = 0; i < num_threads; ++i) {
                _worker_threads.push_back (new thread (bind (&Server::worker_thread, this)));
index 55d1075457aa4000e96b0e8d561107bbe27eebad..abc5676d8a076685a39c3ea2957a3557cc66e63b 100644 (file)
@@ -94,7 +94,7 @@ private:
 class Server : public boost::noncopyable
 {
 public:
-       Server (boost::shared_ptr<Log> log);
+       Server (boost::shared_ptr<Log> log, bool verbose);
 
        void run (int num_threads);
 
@@ -109,6 +109,7 @@ private:
        boost::mutex _worker_mutex;
        boost::condition _worker_condition;
        boost::shared_ptr<Log> _log;
+       bool _verbose;
 
        struct Broadcast {
 
index 78354c46889999c8c28ca1234fe6d598a0529f2b..8c6a294619bed2230357fc4124bb6f317093025f 100644 (file)
@@ -166,7 +166,7 @@ private:
 
        void main_thread ()
        {
-               Server server (memory_log);
+               Server server (memory_log, false);
                server.run (Config::instance()->num_local_encoding_threads ());
        }
 
index eff10a897f5992ddbe2b2839412a18ade713c45b..e9540ff70944a1570fc5d44aecbbdd7b154e50db 100644 (file)
@@ -53,13 +53,15 @@ help (string n)
        cerr << "Syntax: " << n << " [OPTION]\n"
             << "  -v, --version      show DCP-o-matic version\n"
             << "  -h, --help         show this help\n"
-            << "  -t, --threads      number of parallel encoding threads to use\n";
+            << "  -t, --threads      number of parallel encoding threads to use\n"
+            << "  --verbose          be verbose\n";
 }
 
 int
 main (int argc, char* argv[])
 {
        int num_threads = Config::instance()->num_local_encoding_threads ();
+       bool verbose = false;
 
        int option_index = 0;
        while (1) {
@@ -67,6 +69,7 @@ main (int argc, char* argv[])
                        { "version", no_argument, 0, 'v'},
                        { "help", no_argument, 0, 'h'},
                        { "threads", required_argument, 0, 't'},
+                       { "verbose", no_argument, 0, 'A'},
                        { 0, 0, 0, 0 }
                };
 
@@ -86,12 +89,15 @@ main (int argc, char* argv[])
                case 't':
                        num_threads = atoi (optarg);
                        break;
+               case 'A':
+                       verbose = true;
+                       break;
                }
        }
 
        Scaler::setup_scalers ();
-       shared_ptr<FileLog> log (new FileLog ("servomatic.log"));
-       Server server (log);
+       shared_ptr<FileLog> log (new FileLog ("dcpomatic_server_cli.log"));
+       Server server (log, verbose);
        server.run (num_threads);
        return 0;
 }
index 8662f54e8f6a3fa11f482da25b423c32e0e125cb..91b482f4f849ba37558695d9772609fa596fff06 100644 (file)
@@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE (client_server_test)
        shared_ptr<EncodedData> locally_encoded = frame->encode_locally ();
        BOOST_ASSERT (locally_encoded);
        
-       Server* server = new Server (log);
+       Server* server = new Server (log, true);
 
        new thread (boost::bind (&Server::run, server, 2));