ifw-daq  2.1.0-pre1
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 
17 
18 namespace server {
19 
20 DbInterface::DbInterface(const std::string& prefix, rad::DbAdapter& runtime_db)
21  : m_prefix(prefix),
22  m_runtime_db(runtime_db) {
23  RAD_TRACE(GetLogger());
24 
25  if (prefix.size() > 0) {
26  m_prefix = prefix + ".";
27  }
28 }
29 
31  RAD_TRACE(GetLogger());
32 }
33 
35  RAD_TRACE(GetLogger());
36  return m_runtime_db.Get(m_prefix + KEY_CONTROL_STATE);
37 }
38 
39 std::string DbInterface::Get(const std::string& key) {
40  RAD_TRACE(GetLogger());
41  return m_runtime_db.Get(m_prefix + key);
42 }
43 
44 void DbInterface::SetControlState(const std::string& value) {
45  RAD_TRACE(GetLogger());
46  m_runtime_db.Set(m_prefix + KEY_CONTROL_STATE, value);
47 }
48 
50  RAD_TRACE(GetLogger());
51 
52  // @TODO avoid copying strings
53  std::vector < std::string > kvs;
54  kvs.push_back(m_prefix + KEY_CONFIG_REQ_ENDPOINT);
55  kvs.push_back(cfg.GetMsgReplierEndpoint());
56  kvs.push_back(m_prefix + KEY_CONFIG_PUB_ENDPOINT);
57  kvs.push_back(cfg.GetPubEndpoint());
58  kvs.push_back(m_prefix + KEY_CONFIG_DB_ENDPOINT);
59  kvs.push_back(cfg.GetDbEndpoint());
60  kvs.push_back(m_prefix + KEY_CONFIG_DB_TIMEOUT_SEC);
61  kvs.push_back(std::to_string(cfg.GetDbTimeout().tv_sec));
62  kvs.push_back(m_prefix + KEY_CONFIG_SM_SCXML);
63  kvs.push_back(cfg.GetSmScxmlFilename());
64  kvs.push_back(m_prefix + KEY_CONFIG_FILENAME);
65  kvs.push_back(cfg.GetConfigFilename());
66  kvs.push_back(m_prefix + KEY_CONFIG_LOG_LEVEL);
67  kvs.push_back(cfg.GetLogLevel());
68  kvs.push_back(m_prefix + KEY_CONFIG_LOG_PROPERTIES);
69  kvs.push_back(cfg.GetLogProperties());
70 
71  kvs.push_back(m_prefix + KEY_CONFIG_DATAROOT);
72  kvs.push_back(cfg.m_out_path);
73  kvs.push_back(m_prefix + KEY_CONFIG_WORKSPACE);
74  kvs.push_back(cfg.GetWorkspace());
75 
76 
77  daq::DpmClientParams const& dpm = cfg.GetDpmClientParams();
78 
79  kvs.push_back(m_prefix + KEY_CONFIG_DPM_REQ_ENDPOINT);
80  kvs.push_back(dpm.rr_uri);
81  kvs.push_back(m_prefix + KEY_CONFIG_DPM_PUB_ENDPOINT);
82  kvs.push_back(dpm.ps_uri);
83  kvs.push_back(m_prefix + KEY_CONFIG_DPM_TIMEOUT_SEC);
84  kvs.push_back(std::to_string(dpm.timeout.count()));
85 
86  m_runtime_db.MultiSet(kvs);
87 }
88 
89 void DbInterface::Set(const std::string& key, const std::string& value) {
90  RAD_TRACE(GetLogger());
91  m_runtime_db.Set(m_prefix + key, value);
92 }
93 
94 } // namespace server
server::KEY_CONFIG_DPM_TIMEOUT_SEC
const std::string KEY_CONFIG_DPM_TIMEOUT_SEC
Definition: dbInterface.hpp:38
server::KEY_CONFIG_REQ_ENDPOINT
const std::string KEY_CONFIG_REQ_ENDPOINT
Definition: dbInterface.hpp:20
server::KEY_CONFIG_DATAROOT
const std::string KEY_CONFIG_DATAROOT
Definition: dbInterface.hpp:30
server::DbInterface::Set
void Set(const std::string &key, const std::string &value)
Definition: dbInterface.cpp:89
server::DbInterface::~DbInterface
virtual ~DbInterface()
Destructor.
Definition: dbInterface.cpp:30
server::DbInterface::Get
std::string Get(const std::string &key)
Definition: dbInterface.cpp:39
server::KEY_CONFIG_FILENAME
const std::string KEY_CONFIG_FILENAME
Definition: dbInterface.hpp:26
server::KEY_CONFIG_PUB_ENDPOINT
const std::string KEY_CONFIG_PUB_ENDPOINT
Definition: dbInterface.hpp:21
server::DbInterface::SetConfig
void SetConfig(Config &cfg)
Set the application configuration information in the DB.
Definition: dbInterface.cpp:49
server::Config::GetDpmClientParams
daq::DpmClientParams const & GetDpmClientParams() const
Definition: config.cpp:370
server::KEY_CONFIG_DPM_REQ_ENDPOINT
const std::string KEY_CONFIG_DPM_REQ_ENDPOINT
Definition: dbInterface.hpp:36
server::KEY_CONFIG_WORKSPACE
const std::string KEY_CONFIG_WORKSPACE
Definition: dbInterface.hpp:31
server::KEY_CONFIG_DB_ENDPOINT
const std::string KEY_CONFIG_DB_ENDPOINT
Definition: dbInterface.hpp:22
server::Config::m_out_path
std::string m_out_path
Definition: config.hpp:162
daq::DpmClientParams::timeout
std::chrono::seconds timeout
Definition: dpmClient.hpp:77
server::Config::GetDbEndpoint
const std::string & GetDbEndpoint() const
Definition: config.cpp:325
config.hpp
Config class header file.
server::KEY_CONTROL_STATE
const std::string KEY_CONTROL_STATE
Definition: dbInterface.hpp:18
server::Config::GetPubEndpoint
const std::string & GetPubEndpoint() const
Definition: config.cpp:320
server::Config::GetLogProperties
const std::string & GetLogProperties() const
Definition: config.cpp:365
server::KEY_CONFIG_LOG_LEVEL
const std::string KEY_CONFIG_LOG_LEVEL
Definition: dbInterface.hpp:27
server::Config::GetDbTimeout
const timeval GetDbTimeout() const
Definition: config.cpp:339
server::Config::GetLogLevel
const std::string & GetLogLevel() const
Definition: config.cpp:360
server::Config::GetWorkspace
std::filesystem::path GetWorkspace() const
Definition: config.hpp:138
server::DbInterface::SetControlState
void SetControlState(const std::string &value)
Definition: dbInterface.cpp:44
daq::DpmClientParams::ps_uri
std::string ps_uri
Definition: dpmClient.hpp:76
server::Config::GetSmScxmlFilename
const std::string & GetSmScxmlFilename() const
Definition: config.cpp:345
dbInterface.hpp
DbInterface class header file.
server::KEY_CONFIG_DB_TIMEOUT_SEC
const std::string KEY_CONFIG_DB_TIMEOUT_SEC
Definition: dbInterface.hpp:24
server::Config::GetConfigFilename
const std::string & GetConfigFilename() const
Definition: config.cpp:350
server
Definition: actionMgr.cpp:21
server::GetLogger
log4cplus::Logger & GetLogger()
Definition: logger.cpp:14
server::DbInterface::DbInterface
DbInterface(const std::string &prefix, rad::DbAdapter &runtime_db)
Constructor.
Definition: dbInterface.cpp:20
server::KEY_CONFIG_DPM_PUB_ENDPOINT
const std::string KEY_CONFIG_DPM_PUB_ENDPOINT
Definition: dbInterface.hpp:37
logger.hpp
Default logger name.
daq::DpmClientParams
Connection parameters for DPM.
Definition: dpmClient.hpp:74
server::Config::GetMsgReplierEndpoint
const std::string & GetMsgReplierEndpoint() const
Definition: config.cpp:315
server::DbInterface::GetControlState
std::string GetControlState()
Definition: dbInterface.cpp:34
server::KEY_CONFIG_LOG_PROPERTIES
const std::string KEY_CONFIG_LOG_PROPERTIES
Definition: dbInterface.hpp:28
server::Config
This class provide access to the command line options and the configuration parameters stored in the ...
Definition: config.hpp:46
server::KEY_CONFIG_SM_SCXML
const std::string KEY_CONFIG_SM_SCXML
Definition: dbInterface.hpp:25
daq::DpmClientParams::rr_uri
std::string rr_uri
Definition: dpmClient.hpp:75