MoteHost: Introduce remote::error exception with easy usable constructor
[remote/remote-mci.git] / diku_mch / Configuration.cc
blob89b42b3d96c7a8bbda3d4894400b9cd574708105
1 #include "Configuration.h"
3 namespace remote { namespace diku_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/diku_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 motehost of mote hotplug events.")
39 ("serverAddress",
40 po::value<std::string>()->default_value("localhost"),
41 "DNS or IP address of the mote server.")
42 ("serverPort",
43 po::value<uint16_t>()->default_value(10001),
44 "Port number to use for connecting to the mote server.")
45 ("serverConnectionRetryInterval",
46 po::value<uint64_t>()->default_value(30),
47 "Number of seconds to wait between server connection retries.")
50 try {
51 store(po::parse_command_line(argc, argv, cmdline_options), vm);
52 } catch (boost::program_options::error exception) {
53 std::cerr << "Error while parsing command line options: "
54 << exception.what() << std::endl << std::endl;
55 printHelp(cmdline_options);
57 notify(vm);
59 if (vm.count("help"))
60 printHelp(cmdline_options);
61 if (vm.count("config-help"))
62 printHelp(config);
64 // get the configuration settings from a file
65 std::ifstream ifs(Configuration::vm["config-file"].as<std::string>().c_str());
66 try {
67 store(parse_config_file(ifs, config), vm);
68 } catch (boost::program_options::error exception) {
69 std::cerr << "Error while parsing configuration file: "
70 << exception.what() << std::endl << std::endl;
71 printHelp(config);
73 notify(vm);