ifw  0.0.1-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dataContext.hpp
Go to the documentation of this file.
1 
9 #ifndef DEVMGR_COMMON_DATA_CONTEXT_HPP_
10 #define DEVMGR_COMMON_DATA_CONTEXT_HPP_
11 
12 // System headers
13 #include <unordered_map>
14 
15 // Local headers
16 #include <rad/TopicPub.hpp>
17 
18 #include <devmgr/common/iConfig.hpp>
19 #include <devmgr/common/dbInterface.hpp>
20 
21 
22 namespace devmgr {
23  namespace common {
24 
25  // Constants for state values
26  const short SRV_STATE_STANDBY = 1;
27  const short SRV_STATE_OPERATIONAL = 2;
28 
29  // Constants for substate values
30  const short SRV_SUBSTATE_NOTREADY = 1;
31  const short SRV_SUBSTATE_READY = 2;
32  const short SRV_SUBSTATE_IDLE = 3;
33  const short SRV_SUBSTATE_ERROR = 4;
34 
35  const std::string SRV_STATE_STANDBY_STR = "NotOperational";
36  const std::string SRV_STATE_OPERATIONAL_STR = "Operational";
37  const std::string SRV_STATE_UNAVAILABLE_STR = "Unavailable";
38 
39  const std::string SRV_SUBSTATE_NOTREADY_STR = "NotRead";
40  const std::string SRV_SUBSTATE_READY_STR = "Ready";
41  const std::string SRV_SUBSTATE_IDLE_STR = "Idle";
42  const std::string SRV_SUBSTATE_ERROR_STR = "Error";
43 
44 
45  const std::unordered_map<short, std::string> SrvStateMap = {
48  };
49 
50  const std::unordered_map<std::string, short> SrvStateStrMap = {
53  };
54 
55  const std::unordered_map<short, std::string> SrvSubstateMap = {
60  };
61 
62  const std::unordered_map<std::string, short> SrvSubstateStrMap = {
67  };
68 
73  class DataContext {
74  public:
84  DataContext(IConfig& config,
85  rad::DbAdapter& db_adapter,
86  boost::asio::io_service& ios);
87 
91  virtual ~DataContext();
92 
96  void ReloadConfig();
97 
101  void UpdateDb();
102 
106  DbInterface& GetDbInterface();
107 
111  IConfig& GetConfig();
112 
117  std::shared_ptr<rad::TopicPub> GetPublisher();
118 
119  short GetState();
120  void SetState(const short state);
121  void SetState(const std::string state);
122  short GetSubstate();
123  void SetSubstate(const short state);
124  void SetSubstate(const std::string state);
125 
126  DataContext(const DataContext&) = delete;
127  DataContext& operator=(const DataContext&) = delete;
128 
129  private:
130  IConfig& m_config;
131  rad::DbAdapter& m_runtime_db;
132 
133  boost::asio::io_service& m_ios;
134  DbInterface m_db_interface;
135  std::shared_ptr<rad::TopicPub> m_publisher;
136 
137  short m_state;
138  short m_substate;
139  };
140 
141  } // namespace common
142 } // namespace devmgr
143 
144 #endif // DEVMGR_COMMON_DATA_CONTEXT_HPP_
const short SRV_SUBSTATE_IDLE
Definition: dataContext.hpp:32
const short SRV_SUBSTATE_READY
Definition: dataContext.hpp:31
IConfig & GetConfig()
Definition: dataContext.cpp:78
const short SRV_STATE_OPERATIONAL
Definition: dataContext.hpp:27
short GetState()
Definition: dataContext.cpp:100
void ReloadConfig()
Definition: dataContext.cpp:51
DbInterface & GetDbInterface()
Definition: dataContext.cpp:88
const short SRV_SUBSTATE_NOTREADY
Definition: dataContext.hpp:30
void SetSubstate(const short state)
Definition: dataContext.cpp:125
const std::string SRV_SUBSTATE_ERROR_STR
Definition: dataContext.hpp:42
const std::unordered_map< short, std::string > SrvStateMap
Definition: dataContext.hpp:45
const short SRV_SUBSTATE_ERROR
Definition: dataContext.hpp:33
DataContext(IConfig &config, rad::DbAdapter &db_adapter, boost::asio::io_service &ios)
Definition: dataContext.cpp:23
const std::string SRV_SUBSTATE_READY_STR
Definition: dataContext.hpp:40
void UpdateDb()
Definition: dataContext.cpp:58
Definition: DbAdapter.hpp:29
const std::string SRV_STATE_UNAVAILABLE_STR
Definition: dataContext.hpp:37
virtual ~DataContext()
Definition: dataContext.cpp:45
void SetState(const short state)
Definition: dataContext.cpp:105
const std::unordered_map< short, std::string > SrvSubstateMap
Definition: dataContext.hpp:55
const std::string SRV_SUBSTATE_NOTREADY_STR
Definition: dataContext.hpp:39
const short SRV_STATE_STANDBY
Definition: dataContext.hpp:26
DataContext & operator=(const DataContext &)=delete
Disable assignment operator.
const std::string SRV_SUBSTATE_IDLE_STR
Definition: dataContext.hpp:41
const std::unordered_map< std::string, short > SrvSubstateStrMap
Definition: dataContext.hpp:62
short GetSubstate()
Definition: dataContext.cpp:120
const std::unordered_map< std::string, short > SrvStateStrMap
Definition: dataContext.hpp:50
const std::string SRV_STATE_STANDBY_STR
Definition: dataContext.hpp:35
const std::string SRV_STATE_OPERATIONAL_STR
Definition: dataContext.hpp:36
std::shared_ptr< rad::TopicPub > GetPublisher()
Definition: dataContext.cpp:94