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
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/diku_mcs.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
>(),
35 "Name of the infrastructure database.")
37 po::value
<std::string
>(),
38 "Host name of the infrastructure database server.")
40 po::value
<std::string
>(),
41 "User name for the infrastructure database.")
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.")
49 po::value
<unsigned int>()->default_value(10001),
50 "Port number to use when listening for new hosts.")
52 po::value
<std::string
>()->default_value("/var/run/diku_mcs.pid"),
53 "Path to the file containing the PID of the mote host.")
55 po::value
<std::string
>()->default_value("/var/log/diku_mcs.log"),
56 "Path to the output log file when running as a daemon.")
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.")
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
);
72 printHelp(cmdline_options
);
73 if (vm
.count("config-help"))
76 // get the configuration settings from a file
77 std::ifstream
ifs(Configuration::vm
["config-file"].as
<std::string
>().c_str());
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
;
88 po::variables_map
Configuration::vm
;