9#ifndef CORE_UTILS_BAT_DB_INTERFACE_HPP_
10#define CORE_UTILS_BAT_DB_INTERFACE_HPP_
14#include <fmt/format.h>
15#include <boost/lockfree/spsc_queue.hpp>
16#include <boost/atomic.hpp>
20#include <rad/cii/oldbAdapter.hpp>
21#include <rad/cii/oldbTypes.hpp>
26 using DbPair = std::pair<std::string, std::any>;
27 using DbVector = std::vector<DbPair>;
41 std::chrono::seconds db_timeout,
42 std::chrono::milliseconds db_task_period,
43 bool with_worker_thread =
true);
61 const std::string& state,
62 const std::string& substate);
72 void Get(
const std::string& key, T& value);
81 void Set(
const std::string& key,
96 void SetAsync(
const std::string& key,
118 std::string m_prefix;
119 bool m_connected{
false};
123 rad::DoubleMap<rad::cii::OldbType> m_oldb_map;
126 rad::cii::OldbAdapter m_oldb_adapter;
131 bool m_with_worker_thread {
true};
132 log4cplus::Logger m_logger;
139 LOG4CPLUS_DEBUG(m_logger, fmt::format(
"Reading attribute <{}> with value: {}", key, value));
140 m_oldb_adapter.Get<T>(m_prefix + key, value);
141 LOG4CPLUS_DEBUG(m_logger, fmt::format(
"Reading attribute <{}> finished !", key));
146 LOG4CPLUS_DEBUG(m_logger, fmt::format(
"Writing attribute <{}>", key));
147 m_oldb_adapter.Set<T>(m_prefix + key, value);
148 LOG4CPLUS_DEBUG(m_logger, fmt::format(
"Writing attribute <{}> finished !", key));
155 m_oldb_map.Set(m_prefix + key, value);
DbInterface(const std::string &prefix, std::chrono::seconds db_timeout, std::chrono::milliseconds db_task_period, bool with_worker_thread=true)
Definition dbInterface.cpp:20
std::string GetPrefix()
Definition dbInterface.hpp:51
void SetAsync(const std::string &key, const T &value)
Aynchronous OLDB set for single attributes.
Definition dbInterface.hpp:152
void SetStates(const std::string &prefix, const std::string &state, const std::string &substate)
Definition dbInterface.cpp:60
virtual ~DbInterface()
Definition dbInterface.cpp:52
void Set(const std::string &key, const T &value)
Definition dbInterface.hpp:145
void BatchSetAsync(const DbVector &vec)
Aynchronous OLDB set for a vector.
Definition dbInterface.cpp:79
DbInterface(const DbInterface &)=delete
Disable copy constructor.
void Get(const std::string &key, T &value)
Definition dbInterface.hpp:138
bool IsConnected()
Definition dbInterface.hpp:50
DbInterface & operator=(const DbInterface &)=delete
Disable assignment operator.
Definition taskOldb.hpp:31
std::pair< std::string, std::any > DbPair
Definition config.hpp:78
std::vector< DbPair > DbVector
Definition config.hpp:79
taskSetup class header file.