Command-line option to specify servomatic_cli threads.
authorCarl Hetherington <cth@carlh.net>
Sun, 23 Sep 2012 11:39:27 +0000 (12:39 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 23 Sep 2012 11:39:27 +0000 (12:39 +0100)
src/lib/server.cc
src/lib/server.h
src/lib/util.cc
src/tools/servomatic_cli.cc
src/tools/servomatic_gui.cc

index ff784db5a8839bfafb6146a6ce7ca22d9261257e..a627634471e2af032a9c668c86aa88bdff550fbb 100644 (file)
@@ -181,9 +181,9 @@ Server::worker_thread ()
 }
 
 void
-Server::run ()
+Server::run (int num_threads)
 {
-       int const num_threads = Config::instance()->num_local_encoding_threads ();
+       cout << "Server starting 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 58cfe0b3fffa8cc08e5f099a64aedfa201a76d6f..fac440a76134e3f90a308a2bea7fc8c7c458e7a3 100644 (file)
@@ -76,7 +76,7 @@ class Server
 public:
        Server (Log* log);
 
-       void run ();
+       void run (int num_threads);
 
 private:
        void worker_thread ();
index 1478bab2e52dca65bab8631e59f3cd3cae6a1c9b..e79c7cd1cb6d1c1cb2ae412f3f1c3a4823296469 100644 (file)
@@ -518,5 +518,9 @@ colour_lut_index_to_name (int index)
        return "";
 }
 
-               
-                       
+int
+read_with_timeout (boost::asio::ip::tcp::socket* socket, uint8_t* data, int size)
+{
+       
+       return asio::read (socket, asio::buffer (data, size));
+}
index 3ad73faf95b2309a836b1faa88386f80ca39703e..f8e71319357aed790b43918206e197a579d753f5 100644 (file)
@@ -25,6 +25,7 @@
 #include <vector>
 #include <unistd.h>
 #include <errno.h>
+#include <getopt.h>
 #include <boost/array.hpp>
 #include <boost/asio.hpp>
 #include <boost/algorithm/string.hpp>
 #include "scaler.h"
 #include "image.h"
 #include "log.h"
+#include "version.h"
+
+using namespace std;
+
+static void
+help (string n)
+{
+       cerr << "Syntax: " << n << " [OPTION]\n"
+            << "  -v, --version      show DVD-o-matic version\n"
+            << "  -h, --help         show this help\n"
+            << "  -t, --threads      number of parallel encoding threads to use\n";
+}
 
 int
-main ()
+main (int argc, char* argv[])
 {
+       int num_threads = Config::instance()->num_local_encoding_threads ();
+
+       int option_index = 0;
+       while (1) {
+               static struct option long_options[] = {
+                       { "version", no_argument, 0, 'v'},
+                       { "help", no_argument, 0, 'h'},
+                       { "threads", required_argument, 0, 't'},
+                       { 0, 0, 0, 0 }
+               };
+
+               int c = getopt_long (argc, argv, "vht:", long_options, &option_index);
+
+               if (c == -1) {
+                       break;
+               }
+
+               switch (c) {
+               case 'v':
+                       cout << "dvdomatic version " << dvdomatic_version << " " << dvdomatic_git_commit << "\n";
+                       exit (EXIT_SUCCESS);
+               case 'h':
+                       help (argv[0]);
+                       exit (EXIT_SUCCESS);
+               case 't':
+                       num_threads = atoi (optarg);
+                       break;
+               }
+       }
+
        Scaler::setup_scalers ();
        FileLog log ("servomatic.log");
        Server server (&log);
-       server.run ();
+       server.run (num_threads);
        return 0;
 }
index a151658f54b3244fc87ddeeb60a7362a2ef14aee..610ba8005eb30aa5c70bac0e27e436571fa8069e 100644 (file)
@@ -23,6 +23,7 @@
 #include "wx_util.h"
 #include "lib/util.h"
 #include "lib/server.h"
+#include "lib/config.h"
 
 using namespace std;
 using namespace boost;
@@ -141,7 +142,7 @@ private:
        void main_thread ()
        {
                Server server (&memory_log);
-               server.run ();
+               server.run (Config::instance()->num_local_encoding_threads ());
        }
 
        boost::thread* _thread;