remote-device-name: Minor cleanup of documentation and code
[remote/remote-mci.git] / diku_mcs / Configuration.cc
blob97647d3419532e2cd4aaaa994efeb56c9f8a9484
1 #include "Configuration.h"
3 namespace remote { namespace diku_mcs {
5 void Configuration::printHelp(po::options_description& desc)
7 std::cerr << PACKAGE_NAME << " (MCH) version " << PACKAGE_VERSION
8 << std::endl << std::endl
9 << desc
10 << std::endl;
11 exit(0);
14 void Configuration::read(int argc, char **argv)
16 // command line options
17 po::options_description cmdline_options("Command line options");
19 cmdline_options.add_options()
20 ("help", "Print usage help and exit")
21 ("config-help", "Print config file usage help and exit")
22 ("config-file",
23 po::value<std::string>()->default_value("/etc/diku_mcs.cfg"),
24 "Path to the configuration file.")
25 ("daemonize",
26 po::value<int>()->default_value(false),
27 "Run as a daemon.");
29 // declare all configuration groups
30 po::options_description config("Configuration options");
32 config.add_options()
33 ("dbName",
34 po::value<std::string>(),
35 "Name of the infrastructure database.")
36 ("dbHost",
37 po::value<std::string>(),
38 "Host name of the infrastructure database server.")
39 ("dbUser",
40 po::value<std::string>(),
41 "User name for the infrastructure database.")
42 ("dbPassword",
43 po::value<std::string>(),
44 "Password for the infrastructure database.")
45 ("sessionListenerPort",
46 po::value<unsigned int>()->default_value(10000),
47 "Port number to use when listening for new sessions.")
48 ("hostListenerPort",
49 po::value<unsigned int>()->default_value(10001),
50 "Port number to use when listening for new hosts.")
51 ("pidFile",
52 po::value<std::string>()->default_value("/var/run/diku_mcs.pid"),
53 "Path to the file containing the PID of the mote host.")
54 ("log-file",
55 po::value<std::string>()->default_value("/var/log/diku_mcs.log"),
56 "Path to the output log file when running as a daemon.")
57 ("errorlog-file",
58 po::value<std::string>()->default_value("/var/log/diku_mcs_error.log"),
59 "Path to the error log file when running as a daemon.")
62 try {
63 store(po::parse_command_line(argc, argv, cmdline_options), vm);
64 } catch (boost::program_options::error exception) {
65 std::cerr << "Error while parsing command line options: "
66 << exception.what() << std::endl << std::endl;
67 printHelp(cmdline_options);
69 notify(vm);
71 if (vm.count("help"))
72 printHelp(cmdline_options);
73 if (vm.count("config-help"))
74 printHelp(config);
76 // get the configuration settings from a file
77 std::ifstream ifs(Configuration::vm["config-file"].as<std::string>().c_str());
78 try {
79 store(parse_config_file(ifs, config), vm);
80 } catch (boost::program_options::error exception) {
81 std::cerr << "Error while parsing configuration file: "
82 << exception.what() << std::endl << std::endl;
83 printHelp(config);
85 notify(vm);
88 po::variables_map Configuration::vm;