8#ifndef CORE_UTILS_BAT_DB_INTERFACE_HPP_
9#define CORE_UTILS_BAT_DB_INTERFACE_HPP_
13#include <fmt/format.h>
14#include <boost/lockfree/spsc_queue.hpp>
15#include <boost/atomic.hpp>
19#include <rad/cii/oldbAdapter.hpp>
20#include <rad/cii/oldbTypes.hpp>
25 using DbPair = std::pair<std::string, std::any>;
26 using DbVector = std::vector<DbPair>;
40 std::chrono::seconds db_timeout,
41 std::chrono::milliseconds db_task_period,
42 bool with_worker_thread =
true);
60 const std::string& state,
61 const std::string& substate);
71 void Get(
const std::string& key, T& value);
80 void Set(
const std::string& key,
95 void SetAsync(
const std::string& key,
117 std::string m_prefix;
118 bool m_connected{
false};
122 rad::DoubleMap<rad::cii::OldbType> m_oldb_map;
125 rad::cii::OldbAdapter m_oldb_adapter;
130 bool m_with_worker_thread {
true};
131 log4cplus::Logger m_logger;
138 LOG4CPLUS_DEBUG(m_logger, fmt::format(
"Reading attribute <{}> with value: {}", key, value));
139 m_oldb_adapter.Get<T>(m_prefix + key, value);
140 LOG4CPLUS_DEBUG(m_logger, fmt::format(
"Reading attribute <{}> finished !", key));
145 LOG4CPLUS_DEBUG(m_logger, fmt::format(
"Writing attribute <{}>", key));
146 m_oldb_adapter.Set<T>(m_prefix + key, value);
147 LOG4CPLUS_DEBUG(m_logger, fmt::format(
"Writing attribute <{}> finished !", key));
154 m_oldb_map.Set(m_prefix + key, value);
Definition dbInterface.hpp:31
DbInterface(const std::string &prefix, std::chrono::seconds db_timeout, std::chrono::milliseconds db_task_period, bool with_worker_thread=true)
Definition dbInterface.cpp:19
std::string GetPrefix()
Definition dbInterface.hpp:50
void SetAsync(const std::string &key, const T &value)
Aynchronous OLDB set for single attributes.
Definition dbInterface.hpp:151
void SetStates(const std::string &prefix, const std::string &state, const std::string &substate)
Definition dbInterface.cpp:59
virtual ~DbInterface()
Definition dbInterface.cpp:51
void Set(const std::string &key, const T &value)
Definition dbInterface.hpp:144
void BatchSetAsync(const DbVector &vec)
Aynchronous OLDB set for a vector.
Definition dbInterface.cpp:78
DbInterface(const DbInterface &)=delete
Disable copy constructor.
void Get(const std::string &key, T &value)
Definition dbInterface.hpp:137
bool IsConnected()
Definition dbInterface.hpp:49
DbInterface & operator=(const DbInterface &)=delete
Disable assignment operator.
Definition taskOldb.hpp:29
Config class source file.
Definition config.cpp:26
std::pair< std::string, std::any > DbPair
Definition config.hpp:76
std::vector< DbPair > DbVector
Definition config.hpp:77