-
Notifications
You must be signed in to change notification settings - Fork 80
/
g13_main.cc
70 lines (58 loc) · 1.95 KB
/
g13_main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "g13.h"
#include <boost/program_options.hpp>
#if 0
#include <boost/log/core/core.hpp>
#include <boost/log/attributes.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/expressions/formatters/stream.hpp>
#include <boost/log/support/date_time.hpp>
#endif
using namespace std;
using namespace G13;
namespace po = boost::program_options;
int main(int argc, char *argv[]) {
G13_Manager manager;
manager.set_log_level("info");
// Declare the supported options.
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
;
std::vector<std::string> sopt_names;
auto add_string_option = [ &sopt_names, &desc ]( const char *name, const char *description ) {
desc.add_options()( name, po::value<std::string>(), description );
sopt_names.push_back(name);
};
add_string_option( "logo", "set logo from file" );
add_string_option( "config", "load config commands from file" );
add_string_option( "pipe_in", "specify name for input pipe" );
add_string_option( "pipe_out", "specify name for output pipe" );
add_string_option( "log_level", "logging level" );
// add_string_option( "logfile", "write log to logfile" );
po::positional_options_description p;
p.add("logo", -1);
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).
options(desc).positional(p).run(), vm);
po::notify(vm);
if (vm.count("help")) {
cout << argv[0] << " : user space G13 driver" << endl;
cout << desc << "\n";
return 1;
}
BOOST_FOREACH( const std::string &tag, sopt_names ) {
if (vm.count(tag) ) {
manager.set_string_config_value(tag,vm[tag].as<std::string>());
}
}
if (vm.count("logo")) {
manager.set_logo(vm["logo"].as<std::string>());
}
if (vm.count("log_level")) {
manager.set_log_level( manager.string_config_value( "log_level") );
}
manager.run();
}