9 #ifndef CORE_UTILS_BAT_DB_INTERFACE_HPP_
10 #define CORE_UTILS_BAT_DB_INTERFACE_HPP_
15 #include <fmt/format.h>
16 #include <boost/lockfree/spsc_queue.hpp>
17 #include <boost/atomic.hpp>
23 #include <rad/cii/oldbAdapter.hpp>
24 #include <rad/cii/oldbTypes.hpp>
29 using DbPair = std::pair<std::string, std::any>;
30 using DbVector = std::vector<DbPair>;
44 std::chrono::seconds db_timeout,
45 std::chrono::milliseconds db_task_period,
46 bool with_worker_thread =
true);
64 const std::string& state,
65 const std::string& substate);
75 void Get(
const std::string& key, T& value);
84 void Set(
const std::string& key,
99 void SetAsync(
const std::string& key,
121 std::string m_prefix;
122 bool m_connected{
false};
126 rad::DoubleMap<rad::cii::OldbType> m_oldb_map;
129 rad::cii::OldbAdapter m_oldb_adapter;
134 bool m_with_worker_thread {
true};
142 LOG4CPLUS_DEBUG(m_logger, fmt::format(
"Reading attribute <{}> with value: {}", key, value));
143 m_oldb_adapter.Get<T>(m_prefix + key, value);
144 LOG4CPLUS_DEBUG(m_logger, fmt::format(
"Reading attribute <{}> fnished !", key));
149 LOG4CPLUS_DEBUG(m_logger, fmt::format(
"Writting attribute <{}> with value: {}", key, value));
150 m_oldb_adapter.Set<T>(m_prefix + key, value);
151 LOG4CPLUS_DEBUG(m_logger, fmt::format(
"Writting attribute <{}> fnished !", key));
158 m_oldb_map.Set(m_prefix + key, value);
Definition: dbInterface.hpp:35
void Set(const std::string &key, const T &value)
Definition: dbInterface.hpp:148
void SetAsync(const std::string &key, const T &value)
Aynchronous OLDB set for single attributes.
Definition: dbInterface.hpp:155
void Get(const std::string &key, T &value)
Definition: dbInterface.hpp:141
void BatchSetAsync(const DbVector &vec)
Aynchronous OLDB set for a vector.
Definition: dbInterface.cpp:80
DbInterface(const DbInterface &)=delete
Disable copy constructor.
bool IsConnected()
Definition: dbInterface.hpp:53
virtual ~DbInterface()
Definition: dbInterface.cpp:53
DbInterface & operator=(const DbInterface &)=delete
Disable assignment operator.
DbInterface(const std::string &prefix, std::chrono::seconds db_timeout, std::chrono::milliseconds db_task_period, bool with_worker_thread=true)
Definition: dbInterface.cpp:21
std::string GetPrefix()
Definition: dbInterface.hpp:54
void SetStates(const std::string &prefix, const std::string &state, const std::string &substate)
Definition: dbInterface.cpp:61
Definition: taskOldb.hpp:32
log4cplus::Logger & Logger()
Definition: defines.cpp:13
Definition: config.cpp:31
std::pair< std::string, std::any > DbPair
Definition: config.hpp:80
std::vector< DbPair > DbVector
Definition: config.hpp:81
taskSetup class header file.