|
ifw-daq
1.0.0
IFW Data Acquisition modules
|
Go to the documentation of this file.
14 #include <rad/assert.hpp>
15 #include <rad/exceptions.hpp>
16 #include <rad/helper.hpp>
18 #include <fmt/format.h>
19 #include <boost/program_options.hpp>
23 namespace bpo = boost::program_options;
45 LOG4CPLUS_DEBUG(
GetLogger(),
"Default - Configuration filename: <"
58 if (db_addr.size() > 0) {
77 bpo::options_description options_desc(
"Options");
79 options_desc.add_options()
80 (
"help,h",
"Print help messages")
86 "Log level: ERROR, WARNING, STATE, EVENT, ACTION, INFO, DEBUG, TRACE")
89 "Configuration filename")
92 "In-memory DB host (ipaddr:port)");
97 bpo::variables_map options_map;
98 bpo::store(bpo::parse_command_line(argc, argv, options_desc),
100 if (options_map.count(
"help")) {
101 std::cout << options_desc << std::endl;
109 bpo::notify(options_map);
111 if (options_map.count(
"log-level")) {
112 log4cplus::LogLevelManager& log_mgr = log4cplus::getLogLevelManager();
113 log4cplus::LogLevel ll = log_mgr.fromString(
m_log_level);
114 if (ll != log4cplus::NOT_SET_LOG_LEVEL) {
119 std::cout << options_desc << std::endl;
120 throw rad::InvalidOptionException(
"Invalid log level.");
124 if (options_map.count(
"proc-name") == 0) {
133 if (options_map.count(
"db-host")) {
141 if (options_map.count(
"config")) {
142 LOG4CPLUS_DEBUG(
GetLogger(),
"CmdOpt - Configuration filename: <"
145 LOG4CPLUS_DEBUG(
GetLogger(),
"Default - Configuration filename: <"
148 }
catch (bpo::error& e) {
149 std::cerr <<
"ERROR: " << e.what() << std::endl << std::endl;
150 std::cerr << options_desc << std::endl;
151 throw rad::InvalidOptionException(e.what());
160 std::string config_filename = filename;
161 if (config_filename ==
"") {
166 std::string resolved_config_filename = rad::Helper::FindFile(
168 if (resolved_config_filename.size() == 0) {
169 LOG4CPLUS_ERROR(
GetLogger(),
"Cannot find <" << config_filename <<
">");
170 throw rad::Exception(rad::errorMsg::CFG_LOAD, resolved_config_filename);
186 throw rad::Exception(rad::errorMsg::CFG_LOAD,
187 fmt::format(
"invalid configuration for '{}': '{}' request "
188 "endpoint must be non-empty and have a trailing "
199 throw rad::Exception(rad::errorMsg::CFG_LOAD,
200 fmt::format(
"invalid configuration for '{}': '{}' publish "
201 "endpoint must be non-empty and have a trailing "
236 LOG4CPLUS_ERROR(
GetLogger(),
"Required configuration parameter <" <<
238 throw rad::Exception(rad::errorMsg::CFG_LOAD, resolved_config_filename);
245 }
catch (YAML::Exception& e) {
246 throw rad::Exception(rad::errorMsg::CFG_LOAD, resolved_config_filename);
std::string m_req_endpoint
const std::string CONFIG_DEFAULT_LOG_PROPERTIES
Config()
Default constructor.
const std::string KEY_CONFIG_REQ_ENDPOINT
const std::string KEY_CONFIG_DATAROOT
std::string m_instrument_id
const std::string CONFIG_DEFAULT_PUB_ENDPOINT
const int CONFIG_DEFAULT_DB_TIMEOUT_SEC
void LoadConfig(const std::string &filename="")
This method load from a configuration file the application configuration overriding the initializatio...
const std::string CONFIG_DEFAULT_LOGLEVEL
const std::string KEY_CONFIG_PUB_ENDPOINT
const std::string CONFIG_DEFAULT_PROCNAME
Default application configuration values.
virtual ~Config()
Default destructor.
std::string m_db_host_endpoint
const std::string KEY_CONFIG_INSTRUMENT_ID
const std::string CONFIG_ENVVAR_OUT_PATH
const std::string KEY_CONFIG_DB_ENDPOINT
const std::string & GetDbEndpoint() const
const std::string CONFIG_DEFAULT_SCXML_FILENAME
bool ParseOptions(int argc, char *argv[])
This method parses the command line parameters overriding the initialization done in the constructor.
std::string m_config_filename
const std::string & GetPubEndpoint() const
YAML::Node m_config_node
Disable assignment operator.
const std::string CONFIG_DEFAULT_REQ_ENDPOINT
Config class header file.
const std::string & GetLogProperties() const
const timeval GetDbTimeout() const
const std::string & GetLogLevel() const
std::string m_pub_endpoint
const std::string & GetSmScxmlFilename() const
DbInterface class header file.
const std::string CONFIG_DEFAULT_FILENAME
const std::string KEY_CONFIG_DB_TIMEOUT_SEC
std::string m_scxml_filename
const std::string & GetConfigFilename() const
const std::string CONFIG_DEFAULT_DB_ENDPOINT
log4cplus::Logger & GetLogger()
const std::string & GetMsgReplierEndpoint() const
std::string m_log_properties
const std::string KEY_CONFIG_LOG_PROPERTIES
const std::string & GetProcName() const
const std::string KEY_CONFIG_SM_SCXML
const std::string CONFIG_ENVVAR_DBHOST
Application configuration environment variables.