ifw-daq  1.0.0
IFW Data Acquisition modules
dbInterface.hpp
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 header file.
8  */
9 #ifndef SERVER_DB_INTERFACE_HPP_
10 #define SERVER_DB_INTERFACE_HPP_
11 
12 #include <rad/dbAdapter.hpp>
13 
14 #include <string>
15 
16 namespace server {
17 
18 const std::string KEY_CONTROL_STATE = "ctr.state";
19 
20 const std::string KEY_CONFIG_REQ_ENDPOINT = "cfg.req.endpoint";
21 const std::string KEY_CONFIG_PUB_ENDPOINT = "cfg.pub.endpoint";
22 const std::string KEY_CONFIG_DB_ENDPOINT = "cfg.db.endpoint";
23 const std::string KEY_CONFIG_DB_TIMEOUT_SEC = "cfg.db.timeout.sec";
24 const std::string KEY_CONFIG_SM_SCXML = "cfg.sm.scxml";
25 const std::string KEY_CONFIG_FILENAME = "cfg.filename";
26 const std::string KEY_CONFIG_LOG_LEVEL = "cfg.log.level";
27 const std::string KEY_CONFIG_LOG_PROPERTIES = "cfg.log.properties";
28 const std::string KEY_CONFIG_INSTRUMENT_ID = "cfg.instrument_id";
29 const std::string KEY_CONFIG_DATAROOT = "cfg.dataroot";
30 
31 class Config;
32 
33 
34 /**
35  * This class is the interface to the in-memory DB.
36  */
37 class DbInterface {
38  public:
39  /**
40  * Constructor.
41  *
42  * @param[in] prefix String used as prefix when building the keys.
43  * @param[in] runtime_db Reference to the in-memory DB adapter.
44  */
45  DbInterface(const std::string& prefix, rad::DbAdapter& runtime_db);
46 
47  /**
48  * Destructor
49  */
50  virtual ~DbInterface();
51 
52  /**
53  * @return The current state of the application stored in the DB.
54  */
55  std::string GetControlState();
56 
57  /**
58  * @param[in] key Key in the DB.
59  * @return The value stored in the DB associated to the given key.
60  */
61  std::string Get(const std::string& key);
62 
63  /**
64  * @param[in] value State to be stored in the DB.
65  */
66  void SetControlState(const std::string& value);
67 
68  /**
69  * Set the application configuration information in the DB.
70  *
71  * @param[in] reqEndpoint Request msg endpoint.
72  * @param[in] dbIpAddr DB IP address.
73  * @param[in] dbPort DB port.
74  * @param[in] dbTimeout DB timeout.
75  */
76  void SetConfig(Config& cfg);
77 
78  /**
79  * @param[in] key Key to be written in the DB.
80  * @param[in] value Value, associated to the given key, to be written in the DB.
81  */
82  void Set(const std::string& key, const std::string& value);
83 
84  DbInterface(const DbInterface&) = delete; //! Disable copy constructor
85  DbInterface& operator=(const DbInterface&) = delete; //! Disable assignment operator
86 
87  private:
88  std::string m_prefix;
89  rad::DbAdapter& m_runtime_db;
90 };
91 
92 } // namespace server
93 
94 #endif // SERVER_DB_INTERFACE_HPP_
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:29
server::DbInterface::Set
void Set(const std::string &key, const std::string &value)
Definition: dbInterface.cpp:74
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:25
server::DbInterface
This class is the interface to the in-memory DB.
Definition: dbInterface.hpp:37
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::KEY_CONFIG_INSTRUMENT_ID
const std::string KEY_CONFIG_INSTRUMENT_ID
Definition: dbInterface.hpp:28
server::KEY_CONFIG_DB_ENDPOINT
const std::string KEY_CONFIG_DB_ENDPOINT
Definition: dbInterface.hpp:22
server::DbInterface::DbInterface
DbInterface(const DbInterface &)=delete
server::KEY_CONTROL_STATE
const std::string KEY_CONTROL_STATE
Definition: dbInterface.hpp:18
server::KEY_CONFIG_LOG_LEVEL
const std::string KEY_CONFIG_LOG_LEVEL
Definition: dbInterface.hpp:26
server::DbInterface::SetControlState
void SetControlState(const std::string &value)
Definition: dbInterface.cpp:44
server::KEY_CONFIG_DB_TIMEOUT_SEC
const std::string KEY_CONFIG_DB_TIMEOUT_SEC
Definition: dbInterface.hpp:23
server
Definition: actionMgr.cpp:21
server::DbInterface::DbInterface
DbInterface(const std::string &prefix, rad::DbAdapter &runtime_db)
Constructor.
Definition: dbInterface.cpp:20
server::DbInterface::GetControlState
std::string GetControlState()
Definition: dbInterface.cpp:34
server::DbInterface::operator=
DbInterface & operator=(const DbInterface &)=delete
Disable copy constructor.
server::KEY_CONFIG_LOG_PROPERTIES
const std::string KEY_CONFIG_LOG_PROPERTIES
Definition: dbInterface.hpp:27
server::Config
This class provide access to the command line options and the configuration parameters stored in the ...
Definition: config.hpp:41
server::KEY_CONFIG_SM_SCXML
const std::string KEY_CONFIG_SM_SCXML
Definition: dbInterface.hpp:24