ifw-fcf  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
config.hpp
Go to the documentation of this file.
1 
8 #ifndef FCF_DEVMGR_COMMON_CONFIG_HPP_
9 #define FCF_DEVMGR_COMMON_CONFIG_HPP_
10 
11 // System headers
12 #include <string>
13 
14 // Third party headers
15 #include <yaml-cpp/yaml.h>
16 
17 // Local headers
18 #include <dit/fits/fits.hpp>
20 
21 #include <fcf/devmgr/common/events.rad.hpp>
22 
23 namespace fcf {
24  namespace devmgr {
25  namespace common {
26 
30  constexpr auto CONFIG_DEFAULT_PROCNAME = "devmgrServer";
33  constexpr auto CONFIG_DEFAULT_FILENAME = "";
34  constexpr auto CONFIG_DEFAULT_SCXML_FILENAME = "Supervisor.xml";
35  constexpr auto CONFIG_DEFAULT_LOGLEVEL = "ERROR";
36  constexpr auto CONFIG_DEFAULT_DB_ENDPOINT = "127.0.0.1:6379";
37  constexpr int CONFIG_DEFAULT_DB_TIMEOUT = 2;
38  constexpr auto CONFIG_DEFAULT_REQ_ENDPOINT = "tcp://*:5578";
39  constexpr auto CONFIG_DEFAULT_PUB_ENDPOINT = "tcp://*:5568";
40  constexpr auto CONFIG_DEFAULT_DICTIONARIES = "fcf/devmgr/server/primary.did";
41  constexpr auto CONFIG_DEFAULT_FIT_PREFIX = "FCS";
42 
43  constexpr unsigned int CONFIG_DEFAULT_CMD_TOUT = 60000;
44 
48  constexpr auto CONFIG_ENVVAR_DBHOST = "DB_HOST";
49 
54  class Config : public IConfig {
55  public:
63  Config();
64 
68  virtual ~Config();
69 
78  bool ParseOptions(int argc, char* argv[]);
79 
87  void LoadConfig(const std::string& filename = "");
88 
92  const std::string GetServerId() const;
93 
99  const std::string GetMsgReplierEndpoint() const;
100 
104  const std::string GetDbEndpoint() const;
105 
111  const std::string GetPubEndpoint() const;
112 
116  const timeval GetDbTimeout() const;
117 
121  const std::string GetSmScxmlFilename() const;
122 
126  const std::string GetConfigFilename() const;
127 
131  const std::string GetProcName() const;
132 
136  const std::string GetLogLevel() const;
137 
142  const int GetNumDevices();
143 
144  const std::string GetFitsPrefix() const;
145 
151  const std::string GetDeviceName(const int& device_index);
152 
158  const std::string GetDeviceFile(const std::string& name);
159 
165  const std::string GetDeviceType(const std::string& name);
166 
170  virtual dit::did::Did& GetDid();
171 
180  virtual void GetConfigList(std::vector<std::string>& cfg_list);
181 
186  const unsigned int GetCmdTout();
187 
192  void SetCmdTout(const unsigned int cmd_tout);
193 
194  Config(const Config&) = delete;
195  Config& operator=(const Config&) = delete;
196 
197  private:
198  YAML::Node m_config_node;
199  std::string m_server_id;
200  std::string m_proc_name;
201  std::string m_log_level;
202  std::string m_config_filename;
203  std::string m_scxml_filename;
204  std::string m_db_host_endpoint;
205  int m_db_timeout_sec;
206  std::string m_req_endpoint;
207  std::string m_pub_endpoint;
208  std::string m_fits_prefix;
209  int m_num_devices;
210  int m_num_dictionaries;
211  unsigned int m_cmd_tout;
212  dit::did::Did m_did;
213  };
214  }
215  }
216 } // namespace devmgr::common
217 
218 
219 #endif // FCF_DEVMGR_COMMON_CONFIG_HPP_
IConfig class header file.
const std::string GetMsgReplierEndpoint() const
Definition: config.cpp:338
virtual dit::did::Did & GetDid()
Definition: config.cpp:447
constexpr auto CONFIG_DEFAULT_FIT_PREFIX
Definition: config.hpp:41
const std::string GetConfigFilename() const
Definition: config.cpp:376
virtual ~Config()
Definition: config.cpp:63
constexpr auto CONFIG_DEFAULT_DB_ENDPOINT
Definition: config.hpp:36
constexpr unsigned int CONFIG_DEFAULT_CMD_TOUT
Definition: config.hpp:43
bool ParseOptions(int argc, char *argv[])
Definition: config.cpp:67
virtual void GetConfigList(std::vector< std::string > &cfg_list)
Get configuration list.
Definition: config.cpp:454
Config()
Definition: config.cpp:30
constexpr auto CONFIG_ENVVAR_DBHOST
Definition: config.hpp:48
constexpr auto CONFIG_DEFAULT_REQ_ENDPOINT
Definition: config.hpp:38
const std::string GetDbEndpoint() const
Definition: config.cpp:345
const std::string GetDeviceType(const std::string &name)
GetDeviceType.
Definition: config.cpp:413
Config & operator=(const Config &)=delete
Disable copy constructor.
Definition: config.hpp:54
const std::string GetServerId() const
Definition: config.cpp:333
constexpr auto CONFIG_DEFAULT_PUB_ENDPOINT
Definition: config.hpp:39
constexpr auto CONFIG_DEFAULT_FILENAME
Definition: config.hpp:33
const std::string GetDeviceName(const int &device_index)
GetDeviceName.
Definition: config.cpp:400
constexpr auto CONFIG_DEFAULT_LOGLEVEL
Definition: config.hpp:35
constexpr int CONFIG_DEFAULT_DB_TIMEOUT
Definition: config.hpp:37
constexpr auto CONFIG_DEFAULT_SCXML_FILENAME
Definition: config.hpp:34
constexpr auto CONFIG_DEFAULT_PROCNAME
Definition: config.hpp:30
constexpr auto CONFIG_DEFAULT_DICTIONARIES
Definition: config.hpp:40
const std::string GetFitsPrefix() const
Get FITS prefix.
Definition: config.cpp:357
const timeval GetDbTimeout() const
Definition: config.cpp:363
Definition: iConfig.hpp:22
const std::string GetLogLevel() const
Definition: config.cpp:388
const std::string GetProcName() const
Definition: config.cpp:382
const std::string GetPubEndpoint() const
Definition: config.cpp:351
const std::string GetSmScxmlFilename() const
Definition: config.cpp:370
void LoadConfig(const std::string &filename="")
Definition: config.cpp:145
const int GetNumDevices()
GetNumDevices.
Definition: config.cpp:394
const std::string GetDeviceFile(const std::string &name)
GetDeviceFile.
Definition: config.cpp:425
const unsigned int GetCmdTout()
GetCmdTout.
Definition: config.cpp:440
void SetCmdTout(const unsigned int cmd_tout)
SetCmdTout.
Definition: config.cpp:495