Merge 1.0 in.
[dcpomatic.git] / src / tools / dcpomatic_server_cli.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "lib/server.h"
21 #include <iostream>
22 #include <stdexcept>
23 #include <sstream>
24 #include <cstring>
25 #include <vector>
26 #include <unistd.h>
27 #include <errno.h>
28 #include <getopt.h>
29 #include <boost/array.hpp>
30 #include <boost/asio.hpp>
31 #include <boost/algorithm/string.hpp>
32 #include <boost/thread.hpp>
33 #include <boost/thread/mutex.hpp>
34 #include <boost/thread/condition.hpp>
35 #include "lib/config.h"
36 #include "lib/dcp_video_frame.h"
37 #include "lib/exceptions.h"
38 #include "lib/util.h"
39 #include "lib/config.h"
40 #include "lib/scaler.h"
41 #include "lib/image.h"
42 #include "lib/log.h"
43 #include "lib/version.h"
44
45 using std::cerr;
46 using std::string;
47 using std::cout;
48 using boost::shared_ptr;
49
50 static void
51 help (string n)
52 {
53         cerr << "Syntax: " << n << " [OPTION]\n"
54              << "  -v, --version      show DCP-o-matic version\n"
55              << "  -h, --help         show this help\n"
56              << "  -t, --threads      number of parallel encoding threads to use\n";
57 }
58
59 int
60 main (int argc, char* argv[])
61 {
62         int num_threads = Config::instance()->num_local_encoding_threads ();
63
64         int option_index = 0;
65         while (1) {
66                 static struct option long_options[] = {
67                         { "version", no_argument, 0, 'v'},
68                         { "help", no_argument, 0, 'h'},
69                         { "threads", required_argument, 0, 't'},
70                         { 0, 0, 0, 0 }
71                 };
72
73                 int c = getopt_long (argc, argv, "vht:", long_options, &option_index);
74
75                 if (c == -1) {
76                         break;
77                 }
78
79                 switch (c) {
80                 case 'v':
81                         cout << "dcpomatic version " << dcpomatic_version << " " << dcpomatic_git_commit << "\n";
82                         exit (EXIT_SUCCESS);
83                 case 'h':
84                         help (argv[0]);
85                         exit (EXIT_SUCCESS);
86                 case 't':
87                         num_threads = atoi (optarg);
88                         break;
89                 }
90         }
91
92         Scaler::setup_scalers ();
93         shared_ptr<FileLog> log (new FileLog ("servomatic.log"));
94         Server server (log);
95         server.run (num_threads);
96         return 0;
97 }