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
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")
23 po::value
<std::string
>()->default_value("/etc/remote-mch.cfg"),
24 "Path to the configuration file.")
26 po::value
<int>()->default_value(false),
29 // declare all configuration groups
30 po::options_description
config("Configuration options");
34 po::value
<std::string
>()->default_value("/dev/remote"),
35 "Path to the remote mote device hierarchy.")
37 po::value
<std::string
>()->default_value("/var/run/motehost.events"),
38 "Path to the fifo notifying the mote host of mote hotplug events.")
40 po::value
<std::string
>()->default_value("/var/run/remote-mch.pid"),
41 "Path to the file containing the PID of the mote host.")
43 po::value
<std::string
>()->default_value("localhost"),
44 "DNS or IP address of the mote server.")
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.")
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
);
63 printHelp(cmdline_options
);
64 if (vm
.count("config-help"))
67 // get the configuration settings from a file
68 std::ifstream
ifs(Configuration::vm
["config-file"].as
<std::string
>().c_str());
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
;