ifw-fcf  2.0.0
 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 FCF_DEVMGR_COMMON_DATA_CONTEXT_HPP_
10 #define FCF_DEVMGR_COMMON_DATA_CONTEXT_HPP_
11 
12 // System headers
13 #include <unordered_map>
14 
15 // Local headers
16 #include <rad/topicPub.hpp>
17 
20 
21 namespace fcf {
22  namespace devmgr {
23  namespace common {
24 
25  // Constants for state values
26  const short SRV_STATE_NOT_OPERATIONAL = 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_INITIALISING = 4;
34  const short SRV_SUBSTATE_ENABLING = 5;
35  const short SRV_SUBSTATE_ERROR = 10;
36 
37  const std::string SRV_STATE_NOT_OPERATIONAL_STR = "NotOperational";
38  const std::string SRV_STATE_OPERATIONAL_STR = "Operational";
39  const std::string SRV_STATE_UNAVAILABLE_STR = "Unavailable";
40 
41  const std::string SRV_SUBSTATE_NOTREADY_STR = "NotRead";
42  const std::string SRV_SUBSTATE_READY_STR = "Ready";
43  const std::string SRV_SUBSTATE_IDLE_STR = "Idle";
44  const std::string SRV_SUBSTATE_INITIALISING_STR = "Initialising";
45  const std::string SRV_SUBSTATE_ENABLING_STR = "Enabling";
46  const std::string SRV_SUBSTATE_ERROR_STR = "Error";
47 
48 
49  const std::unordered_map<short, std::string> SrvStateMap = {
52  };
53 
54  const std::unordered_map<std::string, short> SrvStateStrMap = {
57  };
58 
59  const std::unordered_map<short, std::string> SrvSubstateMap = {
66  };
67 
68  const std::unordered_map<std::string, short> SrvSubstateStrMap = {
75  };
76 
81  class DataContext {
82  public:
94  DataContext(IConfig& config,
95  rad::DbAdapter& db_adapter,
96  boost::asio::io_service& ios);
97 
101  virtual ~DataContext();
102 
106  void ReloadConfig();
107 
111  void UpdateDb();
112 
117 
121  IConfig& GetConfig();
122 
123  short GetState();
124  void SetState(const short state);
125  void SetState(const std::string state);
126  short GetSubstate();
127  void SetSubstate(const short state);
128  void SetSubstate(const std::string state);
129 
130  DataContext(const DataContext&) = delete;
131  DataContext& operator=(const DataContext&) = delete;
132 
133  private:
134  IConfig& m_config;
135  rad::DbAdapter& m_runtime_db;
136 
137  boost::asio::io_service& m_ios;
138  DbInterface m_db_interface;
139  //std::shared_ptr<rad::TopicPub> m_publisher; //!< Publish object used by all devices
140 
141  short m_state;
142  short m_substate;
143  };
144 
145  }
146  } // namespace common
147 } // namespace devmgr
148 
149 #endif // DEVMGR_COMMON_DATA_CONTEXT_HPP_
const std::string SRV_SUBSTATE_ENABLING_STR
Definition: dataContext.hpp:45
IConfig class header file.
DbInterface class header file.
const short SRV_SUBSTATE_READY
Definition: dataContext.hpp:31
const std::string SRV_STATE_UNAVAILABLE_STR
Definition: dataContext.hpp:39
Definition: dbInterface.hpp:53
const short SRV_SUBSTATE_NOTREADY
Definition: dataContext.hpp:30
const short SRV_STATE_NOT_OPERATIONAL
Definition: dataContext.hpp:26
const std::string SRV_STATE_OPERATIONAL_STR
Definition: dataContext.hpp:38
const std::string SRV_SUBSTATE_READY_STR
Definition: dataContext.hpp:42
IConfig & GetConfig()
Definition: dataContext.cpp:71
const std::unordered_map< short, std::string > SrvSubstateMap
Definition: dataContext.hpp:59
const short SRV_SUBSTATE_ERROR
Definition: dataContext.hpp:35
void SetState(const short state)
Definition: dataContext.cpp:92
void UpdateDb()
Definition: dataContext.cpp:51
const short SRV_SUBSTATE_IDLE
Definition: dataContext.hpp:32
const std::string SRV_STATE_NOT_OPERATIONAL_STR
Definition: dataContext.hpp:37
void SetSubstate(const short state)
Definition: dataContext.cpp:112
DataContext(IConfig &config, rad::DbAdapter &db_adapter, boost::asio::io_service &ios)
Definition: dataContext.cpp:23
const short SRV_STATE_OPERATIONAL
Definition: dataContext.hpp:27
const std::string SRV_SUBSTATE_IDLE_STR
Definition: dataContext.hpp:43
DataContext & operator=(const DataContext &)=delete
Disable assignment operator.
virtual ~DataContext()
Definition: dataContext.cpp:38
const std::unordered_map< short, std::string > SrvStateMap
Definition: dataContext.hpp:49
Definition: dataContext.hpp:81
short GetState()
Definition: dataContext.cpp:87
const short SRV_SUBSTATE_ENABLING
Definition: dataContext.hpp:34
void ReloadConfig()
Definition: dataContext.cpp:44
Definition: iConfig.hpp:22
const std::unordered_map< std::string, short > SrvStateStrMap
Definition: dataContext.hpp:54
short GetSubstate()
Definition: dataContext.cpp:107
const std::string SRV_SUBSTATE_NOTREADY_STR
Definition: dataContext.hpp:41
const std::unordered_map< std::string, short > SrvSubstateStrMap
Definition: dataContext.hpp:68
const std::string SRV_SUBSTATE_INITIALISING_STR
Definition: dataContext.hpp:44
DbInterface & GetDbInterface()
Definition: dataContext.cpp:81
const std::string SRV_SUBSTATE_ERROR_STR
Definition: dataContext.hpp:46
const short SRV_SUBSTATE_INITIALISING
Definition: dataContext.hpp:33