rad  5.1.0
oldbInterface.hpp
Go to the documentation of this file.
1 
9 #ifndef RAD_OLDB_INTERFACE_HPP
10 #define RAD_OLDB_INTERFACE_HPP
11 
12 #include <rad/cii/oldbAdapter.hpp>
13 #include <rad/config.hpp>
14 #include <rad/logger.hpp>
15 
16 #include <string>
17 
18 
19 namespace rad {
20 
21 /*
22  * Monitor attributes common to all LSV applications.
23  * Note that CII OLDB convert all keys to lowercase.
24  */
25 const std::string KEY_MON_STATE = "mon/state";
26 const std::string KEY_MON_TRS_HEALTH = "mon/trs/health";
27 const std::string KEY_MON_TRS_REASON = "mon/trs/reason";
28 
29 
35  public:
41  explicit OldbInterface(const std::string& prefix = "");
42 
46  virtual ~OldbInterface();
47 
51  inline const std::string& GetPrefix() { return m_prefix; }
52 
56  inline rad::cii::OldbAdapter& GetOldbAdapter() { return m_oldb; }
57 
63  inline void SetPrefix(const std::string& prefix) { m_prefix = prefix; }
64 
73  template <typename T>
74  void SetValue(const std::string& key, const T& value);
75 
84  template <typename T>
85  void GetValue(const std::string& key, T& value);
86 
92  virtual void SetConfig(const Config& cfg);
93 
99  virtual void SetControlState(const std::string& value);
100 
106  virtual void SetTrsHealth(const std::string& health, const std::string& desc);
107 
108  OldbInterface(const OldbInterface&) = delete;
110 
111  private:
112  std::string m_prefix;
113  rad::cii::OldbAdapter m_oldb;
114 };
115 
116 template <typename T>
117 void OldbInterface::SetValue(const std::string& key, const T& value) {
118  //std::cout << "Write " << m_prefix + key << " with value " <<
119  bool res = m_oldb.TrySet<T>(m_prefix + key, value);
120  if (res == false) {
121  LOG4CPLUS_WARN(GetLogger(), "Cannot write to OLDB the key " << m_prefix << key);
122  return;
123  }
124 }
125 
126 template <typename T>
127 void OldbInterface::GetValue(const std::string& key, T& value) {
128  //std::cout << "Write " << m_prefix + key << " with value " <<
129  bool res = m_oldb.TryGet<T>(m_prefix + key, value);
130  if (res == false) {
131  LOG4CPLUS_WARN(GetLogger(), "Cannot read from OLDB the key " << m_prefix << key);
132  return;
133  }
134 }
135 
136 } // namespace rad
137 
138 #endif // RAD_OLDB_INTERFACE_HPP
Config class header file.
OldbAdapter interface file.
Definition: config.hpp:67
Definition: oldbInterface.hpp:34
rad::cii::OldbAdapter & GetOldbAdapter()
Definition: oldbInterface.hpp:56
virtual void SetTrsHealth(const std::string &health, const std::string &desc)
Definition: oldbInterface.cpp:42
virtual void SetConfig(const Config &cfg)
Definition: oldbInterface.cpp:23
virtual ~OldbInterface()
Definition: oldbInterface.cpp:19
virtual void SetControlState(const std::string &value)
Definition: oldbInterface.cpp:36
OldbInterface & operator=(const OldbInterface &)=delete
Disable copy constructor.
OldbInterface(const OldbInterface &)=delete
void SetPrefix(const std::string &prefix)
Definition: oldbInterface.hpp:63
void SetValue(const std::string &key, const T &value)
Definition: oldbInterface.hpp:117
void GetValue(const std::string &key, T &value)
Definition: oldbInterface.hpp:127
const std::string & GetPrefix()
Definition: oldbInterface.hpp:51
OldbInterface(const std::string &prefix="")
Definition: oldbInterface.cpp:14
Definition: oldbAdapter.hpp:44
bool TrySet(const std::string &key, const T &value, const std::int64_t timestamp=elt::oldb::CiiOldbUtil::Now()) noexcept
Definition: oldbAdapter.hpp:552
bool TryGet(const std::string &key, T &value) noexcept
Definition: oldbAdapter.hpp:434
Logger class.
Definition: actionsApp.cpp:20
const std::string KEY_MON_TRS_REASON
Definition: oldbInterface.hpp:27
log4cplus::Logger & GetLogger()
Definition: logger.cpp:70
const std::string KEY_MON_STATE
Definition: oldbInterface.hpp:25
const std::string KEY_MON_TRS_HEALTH
Definition: oldbInterface.hpp:26