ifw-daq  3.0.0-pre2
IFW Data Acquisition modules
dbInterface.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup server
4  * @copyright ESO - European Southern Observatory
5  * @author
6  *
7  * @brief DbInterface class source file.
8  */
9 
10 #include "dbInterface.hpp"
11 #include "config.hpp"
12 #include "logger.hpp"
13 
14 #include <rad/assert.hpp>
15 #include <rad/exceptions.hpp>
16 #include <rad/oldbInterface.hpp> // KEY_MON_STATE
17 
18 namespace server {
19 
20 DbInterface::DbInterface(const std::string& prefix, rad::OldbAsyncWriter& writer)
21  : m_prefix(prefix), m_runtime_db(writer) {
22  RAD_TRACE(GetLogger());
23  if (prefix.empty()) {
24  throw std::invalid_argument("OLDB prefix is invalid (empty)");
25  }
26  if (prefix.back() != '/') {
27  m_prefix.push_back('/');
28  }
29 }
30 
32  RAD_TRACE(GetLogger());
33 }
34 
35 void DbInterface::SetControlState(const std::string& value) {
36  RAD_TRACE(GetLogger());
37  m_runtime_db.Set(m_prefix + rad::KEY_MON_STATE, value);
38 }
39 
41  RAD_TRACE(GetLogger());
42  cfg.GetMgr().Visit([&](daq::config::Manager::CiiValue const& param) {
43  m_runtime_db.Set(m_prefix + param.metadata.canonical_name, param.value);
44  });
45 }
46 
47 void DbInterface::Set(const std::string& key, const std::string& value) {
48  RAD_TRACE(GetLogger());
49  m_runtime_db.Set(m_prefix + key, value);
50 }
51 
52 } // namespace server
void Visit(Func &&func)
Visit each registered parameter.
Definition: manager.hpp:217
rad::cii::OldbType value
Definition: manager.hpp:197
Metadata const & metadata
Definition: manager.hpp:199
CII representation of real value.
Definition: manager.hpp:196
This class provide access to the command line options and the configuration parameters stored in the ...
Definition: config.hpp:60
daq::config::Manager & GetMgr()
Definition: config.hpp:151
DbInterface(const std::string &prefix, rad::OldbAsyncWriter &runtime_db)
Constructor.
Definition: dbInterface.cpp:20
void Set(const std::string &key, const std::string &value)
Definition: dbInterface.cpp:47
void SetConfig(Config &cfg)
Set the application configuration information in the DB.
Definition: dbInterface.cpp:40
void SetControlState(const std::string &value)
Definition: dbInterface.cpp:35
virtual ~DbInterface()
Destructor.
Definition: dbInterface.cpp:31
DbInterface class header file.
Default logger name.
std::string canonical_name
Definition: manager.hpp:71
log4cplus::Logger & GetLogger()
Definition: logger.cpp:14
Config class header file.