rad 6.2.0
Loading...
Searching...
No Matches
oldbInterface.hpp
Go to the documentation of this file.
1
9#ifndef RAD_OLDB_INTERFACE_HPP
10#define RAD_OLDB_INTERFACE_HPP
11
13#include <rad/config.hpp>
14#include <rad/logger.hpp>
15
16#include <string>
17
18
19namespace rad {
20
21/*
22 * Monitor attributes common to all LSV applications.
23 * Note that CII OLDB convert all keys to lowercase.
24 */
25const std::string KEY_MON_STATE = "mon/state";
26const std::string KEY_MON_TRS_HEALTH = "mon/trs/health";
27const 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;
114};
115
116template <typename T>
117void 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
126template <typename T>
127void 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:77
Definition oldbInterface.hpp:34
const std::string & GetPrefix()
Definition oldbInterface.hpp:51
virtual void SetTrsHealth(const std::string &health, const std::string &desc)
Definition oldbInterface.cpp:46
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:40
OldbInterface(const OldbInterface &)=delete
OldbInterface & operator=(const OldbInterface &)=delete
Disable copy constructor.
void SetPrefix(const std::string &prefix)
Definition oldbInterface.hpp:63
rad::cii::OldbAdapter & GetOldbAdapter()
Definition oldbInterface.hpp:56
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
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:536
bool TryGet(const std::string &key, T &value) noexcept
Definition oldbAdapter.hpp:418
Logger class.
Definition actionsApp.cpp:23
const std::string KEY_MON_TRS_REASON
Definition oldbInterface.hpp:27
log4cplus::Logger & GetLogger()
Definition logger.cpp:72
const std::string KEY_MON_STATE
Definition oldbInterface.hpp:25
const std::string KEY_MON_TRS_HEALTH
Definition oldbInterface.hpp:26