X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Ftools%2Fdcpomatic_server_cli.cc;h=6d7f6aba729ae06113de78f76ae9bbd5ab8dba68;hp=eff10a897f5992ddbe2b2839412a18ade713c45b;hb=dd9be86db6cde0afa5da0d1d1ac43b42e05dca26;hpb=59404039618db5d70a2f8fc0cb8c49ae4f8ce527 diff --git a/src/tools/dcpomatic_server_cli.cc b/src/tools/dcpomatic_server_cli.cc index eff10a897..6d7f6aba7 100644 --- a/src/tools/dcpomatic_server_cli.cc +++ b/src/tools/dcpomatic_server_cli.cc @@ -1,76 +1,86 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2015 Carl Hetherington - 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 . */ -#include "lib/server.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "lib/config.h" -#include "lib/dcp_video_frame.h" +#include "lib/dcp_video.h" #include "lib/exceptions.h" #include "lib/util.h" #include "lib/config.h" -#include "lib/scaler.h" #include "lib/image.h" -#include "lib/log.h" +#include "lib/file_log.h" +#include "lib/null_log.h" #include "lib/version.h" +#include "lib/encode_server.h" +#include "lib/dcpomatic_log.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include using std::cerr; using std::string; using std::cout; -using boost::shared_ptr; +using std::shared_ptr; static void 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"; + << " -h, --help show this help\n" + << " -t, --threads number of parallel encoding threads to use\n" + << " --verbose be verbose to stdout\n" + << " --log write a log file of activity\n"; } int main (int argc, char* argv[]) { - int num_threads = Config::instance()->num_local_encoding_threads (); + dcpomatic_setup_path_encoding (); + dcpomatic_setup (); + + int num_threads = Config::instance()->server_encoding_threads (); + bool verbose = false; + bool write_log = false; int option_index = 0; - while (1) { + while (true) { static struct option long_options[] = { { "version", no_argument, 0, 'v'}, { "help", no_argument, 0, 'h'}, { "threads", required_argument, 0, 't'}, + { "verbose", no_argument, 0, 'A'}, + { "log", no_argument, 0, 'B'}, { 0, 0, 0, 0 } }; - int c = getopt_long (argc, argv, "vht:", long_options, &option_index); + int c = getopt_long (argc, argv, "vht:AB", long_options, &option_index); if (c == -1) { break; @@ -86,12 +96,31 @@ main (int argc, char* argv[]) case 't': num_threads = atoi (optarg); break; + case 'A': + verbose = true; + break; + case 'B': + write_log = true; + break; } } - Scaler::setup_scalers (); - shared_ptr log (new FileLog ("servomatic.log")); - Server server (log); - server.run (num_threads); + if (write_log) { + dcpomatic_log.reset (new FileLog("dcpomatic_server_cli.log")); + } + + EncodeServer server (verbose, num_threads); + + try { + server.run (); + } catch (boost::system::system_error& e) { + if (e.code() == boost::system::errc::address_in_use) { + cerr << argv[0] << ": address already in use. Is another DCP-o-matic server instance already running?\n"; + exit (EXIT_FAILURE); + } + cerr << argv[0] << ": " << e.what() << "\n"; + } catch (std::exception& e) { + cerr << argv[0] << ": failed to start server; " << e.what() << "\n"; + } return 0; }