ifw-daq  2.1.0-pre1
IFW Data Acquisition modules
dataContext.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 DataContext class source file.
8  */
9 
10 #include "dataContext.hpp"
11 #include "logger.hpp"
12 
13 #include <rad/assert.hpp>
14 #include <rad/exceptions.hpp>
15 
16 
17 namespace server {
18 
19 DataContext::DataContext(Config& config, rad::DbAdapter& db_adapter)
20 : m_config(config),
21  m_runtime_db(db_adapter),
22  m_db_interface(m_config.GetDbPrefix(), m_runtime_db) {
23  RAD_TRACE(GetLogger());
24  UpdateDb();
25 }
26 
28  RAD_TRACE(GetLogger());
29 }
30 
32  RAD_TRACE(GetLogger());
33 
34  m_config.LoadConfig(m_config.GetConfigFilename());
35  UpdateDb();
36 }
37 
39  RAD_TRACE(GetLogger());
40 
41  try {
42  m_runtime_db.Disconnect();
43  m_runtime_db.Config(m_config.GetDbEndpoint(), m_config.GetDbTimeout());
44  m_runtime_db.Connect();
45  RAD_ASSERT(m_runtime_db.IsConnected());
46  m_db_interface.SetConfig(m_config);
47  } catch (rad::Exception const& e) {
48  /*
49  * Log error but do not terminate, DB could be temporarily unavailable.
50  */
51  LOG4CPLUS_ERROR(GetLogger(), e.what());
52  }
53 }
54 
56  RAD_TRACE(GetLogger());
57  return m_db_interface;
58 }
59 
60 } // namespace server
61 
dataContext.hpp
DataContext class header file.
server::Config::LoadConfig
void LoadConfig(const std::string &filename="")
This method load from a configuration file the application configuration overriding the initializatio...
Definition: config.cpp:151
server::DbInterface
This class is the interface to the in-memory DB.
Definition: dbInterface.hpp:46
server::DbInterface::SetConfig
void SetConfig(Config &cfg)
Set the application configuration information in the DB.
Definition: dbInterface.cpp:49
server::Config::GetDbEndpoint
const std::string & GetDbEndpoint() const
Definition: config.cpp:325
server::DataContext::DataContext
DataContext(Config &config, rad::DbAdapter &db_adapter)
This constructor uses the application configuration to initialize the adapter object to the in-memory...
Definition: dataContext.cpp:19
server::Config::GetDbTimeout
const timeval GetDbTimeout() const
Definition: config.cpp:339
server::DataContext::UpdateDb
void UpdateDb()
Try to connect to the DB and update the application configuration.
Definition: dataContext.cpp:38
server::DataContext::GetDbInterface
DbInterface & GetDbInterface()
Definition: dataContext.cpp:55
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::DataContext::~DataContext
virtual ~DataContext()
Destructor.
Definition: dataContext.cpp:27
logger.hpp
Default logger name.
server::DataContext::ReloadConfig
void ReloadConfig()
Reload the configuration from file and reconnect to the in-memory DB.
Definition: dataContext.cpp:31
server::Config
This class provide access to the command line options and the configuration parameters stored in the ...
Definition: config.hpp:46