rad  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 
9 #ifndef {{cookiecutter.module_name|upper}}_CONFIG_HPP_
10 #define {{cookiecutter.module_name|upper}}_CONFIG_HPP_
11 
12 #include <yaml-cpp/yaml.h>
13 
14 #include <string>
15 
16 namespace {{cookiecutter.module_name}} {
17 
21 const std::string CONFIG_DEFAULT_PROCNAME = "{{cookiecutter.application_name}}";
23 const std::string CONFIG_DEFAULT_FILENAME = ""; // "{{cookiecutter.module_name}}/config.yaml";
24 const std::string CONFIG_DEFAULT_SCXML_FILENAME = "{{cookiecutter.module_name}}/sm.xml";
25 const std::string CONFIG_DEFAULT_LOG_LEVEL = "INFO";
26 const std::string CONFIG_DEFAULT_LOG_PROPERTIES = "{{cookiecutter.module_name}}/log.properties";
27 const std::string CONFIG_DEFAULT_DB_ENDPOINT = "127.0.0.1:6379";
28 const int CONFIG_DEFAULT_DB_TIMEOUT = 2; // sec
29 const std::string CONFIG_DEFAULT_REQ_ENDPOINT = "tcp://*:5577";
30 const std::string CONFIG_DEFAULT_SUB_ENDPOINT = "tcp://127.0.0.1::5560";
31 
35 const std::string CONFIG_ENVVAR_DBHOST = "DB_HOST";
36 
37 
46 class Config
47 {
48 public:
49  Config();
50  virtual ~Config();
51 
52  bool ParseOptions(int argc, char *argv[]);
53 
54  void LoadConfig(const std::string& filename = "");
55 
56  const std::string& GetMsgReplierEndpoint() const;
57  const std::string& GetMsgSubEndpoint() const;
58 
59  const std::string& GetDbEndpoint() const;
60  const timeval GetDbTimeout() const;
61 
62  const std::string& GetSmScxmlFilename() const;
63 
64  const std::string& GetConfigFilename() const;
65  const std::string& GetProcName() const;
66  const std::string& GetLogLevel() const;
67  const std::string& GetLogProperties() const;
68 
69  Config(const Config&) = delete;
70  Config& operator= (const Config&) = delete;
71 
72 private:
73  YAML::Node m_config_node;
74 
75  std::string m_proc_name;
76  std::string m_log_level;
77  std::string m_log_properties;
78  std::string m_config_filename;
79  std::string m_scxml_filename;
80  std::string m_db_host_endpoint;
81  int m_db_timeout_sec;
82  std::string m_req_endpoint;
83  std::string m_sub_endpoint;
84 };
85 
86 } // namespace {{cookiecutter.module_name}}
87 
88 #endif // {{cookiecutter.module_name|upper}}_CONFIG_HPP_
89 
const std::string CONFIG_DEFAULT_FILENAME
no default value to force user to specify config filename since it overwrites the command line option...
Definition: config.hpp:23
const std::string CONFIG_ENVVAR_DBHOST
Definition: config.hpp:35
const std::string CONFIG_DEFAULT_SUB_ENDPOINT
Definition: config.hpp:30
const std::string CONFIG_DEFAULT_LOG_LEVEL
Definition: config.hpp:25
const std::string CONFIG_DEFAULT_REQ_ENDPOINT
Definition: config.hpp:29
const std::string CONFIG_DEFAULT_PROCNAME
Definition: config.hpp:21
const int CONFIG_DEFAULT_DB_TIMEOUT
Definition: config.hpp:28
#define cookiecutter
const std::string CONFIG_DEFAULT_DB_ENDPOINT
Definition: config.hpp:27
const std::string CONFIG_DEFAULT_SCXML_FILENAME
Definition: config.hpp:24
const std::string CONFIG_DEFAULT_LOG_PROPERTIES
Definition: config.hpp:26