ifw-daq  1.0.0
IFW Data Acquisition modules
config.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup server
4  * @copyright ESO - European Southern Observatory
5  * @author
6  *
7  * @brief Config class header file.
8  */
9 #ifndef SERVER_CONFIG_HPP_
10 #define SERVER_CONFIG_HPP_
11 
12 #include <yaml-cpp/yaml.h>
13 
14 #include <string>
15 
16 namespace server {
17 
18 /**
19  * Default application configuration values.
20  */
21 const std::string CONFIG_DEFAULT_PROCNAME = "ocm";
22 const std::string CONFIG_DEFAULT_FILENAME = "config/ocmServer/config.yaml";
23 const std::string CONFIG_DEFAULT_SCXML_FILENAME = "config/ocmServer/sm.xml";
24 const std::string CONFIG_DEFAULT_LOGLEVEL = "INFO";
25 const std::string CONFIG_DEFAULT_LOG_PROPERTIES = "server/log.properties";
26 const std::string CONFIG_DEFAULT_DB_ENDPOINT = "127.0.0.1:6379";
28 const std::string CONFIG_DEFAULT_REQ_ENDPOINT = "zpb.rr://127.0.0.1:12081/";
29 const std::string CONFIG_DEFAULT_PUB_ENDPOINT = "zpb.ps://127.0.0.1:12082/";
30 
31 /**
32  * Application configuration environment variables
33  */
34 const std::string CONFIG_ENVVAR_DBHOST = "DB_HOST";
35 const std::string CONFIG_ENVVAR_OUT_PATH = "DATAROOT";
36 
37 /**
38  * This class provide access to the command line options and
39  * the configuration parameters stored in the configuration file.
40  */
41 class Config {
42  public:
43  /**
44  * Default constructor.
45  *
46  * Initialize application configuration attributes by
47  * - first use the default constant values defined in the header
48  * - override the constant values with environment variables (if defined)
49  */
50  Config();
51 
52  /**
53  * Default destructor.
54  */
55  virtual ~Config();
56 
57  /**
58  * This method parses the command line parameters overriding
59  * the initialization done in the constructor.
60  *
61  * @param[in] argc Number of command line options.
62  * @param[in] argv Pointer to the array of command line options.
63  * @return false if the help option has been invoked, true otherwise.
64  */
65  bool ParseOptions(int argc, char* argv[]);
66 
67  /**
68  * This method load from a configuration file the application
69  * configuration overriding the initialization done in the constructor
70  * and the command line options.
71  *
72  * @param[in] filename Application configuration filename.
73  */
74  void LoadConfig(const std::string& filename = "");
75 
76  /**
77  * @return The network endpoint to send request to this application.
78  * The format is "<middleware>.<protocol>://<ipaddr>:<port>".
79  * For example: "zpb.rr://127.0.0.1:12081/"
80  */
81  const std::string& GetMsgReplierEndpoint() const;
82 
83  /**
84  * @return The network endpoint used to publish topics from this application.
85  * The format is "<middleware>.<protocol>://<ipaddr>:<port>".
86  * For example: "zpb.ps://127.0.0.1:12082/"
87  */
88  const std::string& GetPubEndpoint() const;
89 
90  /**
91  * @return The IP address and port used to connect to the runtime DB.
92  */
93  const std::string& GetDbEndpoint() const;
94 
95  /**
96  * @return The timeout used when communicating to the runtime DB.
97  */
98  const timeval GetDbTimeout() const;
99 
100  /**
101  * @return The SCXML State Machine model filename used by the application.
102  */
103  const std::string& GetSmScxmlFilename() const;
104 
105  /**
106  * @return The application configuration filename.
107  */
108  const std::string& GetConfigFilename() const;
109 
110  /**
111  * @return The application process name.
112  */
113  const std::string& GetProcName() const;
114 
115  /**
116  * @return The configured log level.
117  */
118  const std::string& GetLogLevel() const;
119 
120  /**
121  * @return The log properties config filename.
122  */
123  const std::string& GetLogProperties() const;
124 
125  Config(const Config&) = delete; //! Disable copy constructor
126  Config& operator=(const Config&) = delete; //! Disable assignment operator
127 
128  YAML::Node m_config_node;
129  std::string m_proc_name;
130  std::string m_instrument_id;
131  std::string m_log_level;
132  std::string m_log_properties;
133  std::string m_config_filename;
134  std::string m_scxml_filename;
135  std::string m_db_host_endpoint;
137  std::string m_req_endpoint;
138  std::string m_pub_endpoint;
139  std::string m_out_path;
140 };
141 
142 } // namespace server
143 
144 #endif // SERVER_CONFIG_HPP_
server::Config::m_req_endpoint
std::string m_req_endpoint
Definition: config.hpp:137
server::CONFIG_DEFAULT_LOG_PROPERTIES
const std::string CONFIG_DEFAULT_LOG_PROPERTIES
Definition: config.hpp:25
server::Config::Config
Config(const Config &)=delete
server::Config::Config
Config()
Default constructor.
Definition: config.cpp:27
server::Config::m_instrument_id
std::string m_instrument_id
Definition: config.hpp:130
server::CONFIG_DEFAULT_PUB_ENDPOINT
const std::string CONFIG_DEFAULT_PUB_ENDPOINT
Definition: config.hpp:29
server::CONFIG_DEFAULT_DB_TIMEOUT_SEC
const int CONFIG_DEFAULT_DB_TIMEOUT_SEC
Definition: config.hpp:27
server::Config::LoadConfig
void LoadConfig(const std::string &filename="")
This method load from a configuration file the application configuration overriding the initializatio...
Definition: config.cpp:157
server::CONFIG_DEFAULT_LOGLEVEL
const std::string CONFIG_DEFAULT_LOGLEVEL
Definition: config.hpp:24
server::Config::m_proc_name
std::string m_proc_name
Definition: config.hpp:129
server::CONFIG_DEFAULT_PROCNAME
const std::string CONFIG_DEFAULT_PROCNAME
Default application configuration values.
Definition: config.hpp:21
server::Config::~Config
virtual ~Config()
Default destructor.
Definition: config.cpp:67
server::Config::m_db_host_endpoint
std::string m_db_host_endpoint
Definition: config.hpp:135
server::CONFIG_ENVVAR_OUT_PATH
const std::string CONFIG_ENVVAR_OUT_PATH
Definition: config.hpp:35
server::Config::m_out_path
std::string m_out_path
Definition: config.hpp:139
server::Config::GetDbEndpoint
const std::string & GetDbEndpoint() const
Definition: config.cpp:265
server::CONFIG_DEFAULT_SCXML_FILENAME
const std::string CONFIG_DEFAULT_SCXML_FILENAME
Definition: config.hpp:23
server::Config::ParseOptions
bool ParseOptions(int argc, char *argv[])
This method parses the command line parameters overriding the initialization done in the constructor.
Definition: config.cpp:71
server::Config::m_config_filename
std::string m_config_filename
Definition: config.hpp:133
server::Config::m_db_timeout_sec
int m_db_timeout_sec
Definition: config.hpp:136
server::Config::GetPubEndpoint
const std::string & GetPubEndpoint() const
Definition: config.cpp:260
server::Config::m_config_node
YAML::Node m_config_node
Disable assignment operator.
Definition: config.hpp:128
server::CONFIG_DEFAULT_REQ_ENDPOINT
const std::string CONFIG_DEFAULT_REQ_ENDPOINT
Definition: config.hpp:28
server::Config::GetLogProperties
const std::string & GetLogProperties() const
Definition: config.cpp:296
server::Config::GetDbTimeout
const timeval GetDbTimeout() const
Definition: config.cpp:270
server::Config::GetLogLevel
const std::string & GetLogLevel() const
Definition: config.cpp:291
server::Config::m_pub_endpoint
std::string m_pub_endpoint
Definition: config.hpp:138
server::Config::operator=
Config & operator=(const Config &)=delete
Disable copy constructor.
server::Config::GetSmScxmlFilename
const std::string & GetSmScxmlFilename() const
Definition: config.cpp:276
server::CONFIG_DEFAULT_FILENAME
const std::string CONFIG_DEFAULT_FILENAME
Definition: config.hpp:22
server::Config::m_scxml_filename
std::string m_scxml_filename
Definition: config.hpp:134
server::Config::GetConfigFilename
const std::string & GetConfigFilename() const
Definition: config.cpp:281
server::CONFIG_DEFAULT_DB_ENDPOINT
const std::string CONFIG_DEFAULT_DB_ENDPOINT
Definition: config.hpp:26
server
Definition: actionMgr.cpp:21
server::Config::GetMsgReplierEndpoint
const std::string & GetMsgReplierEndpoint() const
Definition: config.cpp:255
server::Config::m_log_properties
std::string m_log_properties
Definition: config.hpp:132
server::Config::GetProcName
const std::string & GetProcName() const
Definition: config.cpp:286
server::Config::m_log_level
std::string m_log_level
Definition: config.hpp:131
server::Config
This class provide access to the command line options and the configuration parameters stored in the ...
Definition: config.hpp:41
server::CONFIG_ENVVAR_DBHOST
const std::string CONFIG_ENVVAR_DBHOST
Application configuration environment variables.
Definition: config.hpp:34