rad  5.1.0
activityUpdateOldb.hpp
Go to the documentation of this file.
1 
9 #ifndef RAD_ACTIVITY_UPDATE_OLDB_HPP
10 #define RAD_ACTIVITY_UPDATE_OLDB_HPP
11 
12 #include <rad/logger.hpp>
13 #include <rad/activity.hpp>
14 #include <rad/doubleMap.hpp>
15 #include <rad/cii/oldbAdapter.hpp>
16 #include <rad/cii/oldbTypes.hpp>
17 
18 #include <string>
19 #include <chrono>
20 #include <vector>
21 
22 namespace rad {
23 
39  public:
50  ActivityUpdateOldb(const std::string& id,
51  const std::string& logger_name,
53  std::chrono::seconds conn_timeout,
54  std::chrono::milliseconds period);
55  virtual ~ActivityUpdateOldb();
56 
61 
68  void SetOldbPrefix(const std::string& prefix);
69 
75  void Run() override;
76 
79 
80  private:
88  template<typename T>
89  void WriteScalarToOldb(const std::string& key, rad::cii::OldbType& value) {
90  m_oldb_adapter.TrySet<T>(m_oldb_prefix + key, std::get<T>(value));
91  LOG4CPLUS_DEBUG(m_logger, "Writing to OLDB: " << m_oldb_prefix + key
92  << " = " << std::get<T>(value));
93  }
94 
102  template<typename T>
103  void WriteVectorToOldb(const std::string& key, rad::cii::OldbType& values) {
104  m_oldb_adapter.TrySet<T>(m_oldb_prefix + key, std::get<std::vector<T>>(values));
105  LOG4CPLUS_DEBUG(m_logger, "Writing vector to OLDB: " << m_oldb_prefix + key << " = "
106  << PrintVector<T>(std::get<std::vector<T>>(values)));
107  }
108 
116  template<typename T>
117  std::string PrintVector(const std::vector<T>& vec) {
118  std::string str = "";
119  for (auto el : vec) {
120  str += std::to_string(el) + " ";
121  }
122  return str;
123  }
124 
125  log4cplus::Logger m_logger;
127  rad::cii::OldbAdapter m_oldb_adapter;
128  std::chrono::milliseconds m_period;
129  std::string m_oldb_prefix;
130 };
131 
132 } // namespace rad
133 
134 #endif // RAD_ACTIVITY_UPDATE_OLDB_HPP
OldbAdapter interface file.
Definition: activityUpdateOldb.hpp:38
ActivityUpdateOldb & operator=(const ActivityUpdateOldb &)=delete
Disable copy constructor.
void SetOldbPrefix(const std::string &prefix)
Definition: activityUpdateOldb.cpp:36
void Run() override
Definition: activityUpdateOldb.cpp:41
virtual ~ActivityUpdateOldb()
Definition: activityUpdateOldb.cpp:27
rad::cii::OldbAdapter & GetOldbAdapter()
Definition: activityUpdateOldb.cpp:31
ActivityUpdateOldb(const std::string &id, const std::string &logger_name, rad::DoubleMap< rad::cii::OldbType > &oldb_map, std::chrono::seconds conn_timeout, std::chrono::milliseconds period)
Definition: activityUpdateOldb.cpp:14
ActivityUpdateOldb(const ActivityUpdateOldb &)=delete
Definition: activity.hpp:116
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
Logger class.
DoubleMap header file.
std::variant< std::int8_t, std::int16_t, std::int32_t, std::int64_t, std::uint8_t, std::uint16_t, std::uint32_t, std::uint64_t, bool, float, double, std::string, VecInt8Type, VecInt16Type, VecInt32Type, VecInt64Type, VecUint8Type, VecUint16Type, VecUint32Type, VecUint64Type, VecBoolType, VecFloatType, VecDoubleType > OldbType
Definition: oldbTypes.hpp:46
Definition: actionsApp.cpp:20
OldbAdapter interface file.