Reorganize to remove DIKU specific naming
[remote/remote-mci.git] / mch / Configuration.cc
blob479ec5953a0b935185b5e47295cf822fbe786003
1 #include "Configuration.h"
3 namespace remote { namespace mch {
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/remote-mch.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 ("devicePath",
34 po::value<std::string>()->default_value("/dev/remote"),
35 "Path to the remote mote device hierarchy.")
36 ("usbPlugEventPipe",
37 po::value<std::string>()->default_value("/var/run/motehost.events"),
38 "Path to the fifo notifying the mote host of mote hotplug events.")
39 ("pidFile",
40 po::value<std::string>()->default_value("/var/run/remote-mch.pid"),
41 "Path to the file containing the PID of the mote host.")
42 ("serverAddress",
43 po::value<std::string>()->default_value("localhost"),
44 "DNS or IP address of the mote server.")
45 ("serverPort",
46 po::value<uint16_t>()->default_value(10001),
47 "Port number to use for connecting to the mote server.")
48 ("serverConnectionRetryInterval",
49 po::value<uint64_t>()->default_value(30),
50 "Number of seconds to wait between server connection retries.")
53 try {
54 store(po::parse_command_line(argc, argv, cmdline_options), vm);
55 } catch (boost::program_options::error exception) {
56 std::cerr << "Error while parsing command line options: "
57 << exception.what() << std::endl << std::endl;
58 printHelp(cmdline_options);
60 notify(vm);
62 if (vm.count("help"))
63 printHelp(cmdline_options);
64 if (vm.count("config-help"))
65 printHelp(config);
67 // get the configuration settings from a file
68 std::ifstream ifs(Configuration::vm["config-file"].as<std::string>().c_str());
69 try {
70 store(parse_config_file(ifs, config), vm);
71 } catch (boost::program_options::error exception) {
72 std::cerr << "Error while parsing configuration file: "
73 << exception.what() << std::endl << std::endl;
74 printHelp(config);
76 notify(vm);