ifw-fcf  3.0.0
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 #include <mal/Cii.hpp>
18 #include <mal/utility/LoadMal.hpp>
19 #include <rad/topicPub.hpp>
20 #include <rad/mal/publisher.hpp>
21 #include <boost/asio.hpp>
22 #include <Stdif.hpp>
25 
26 namespace fcf {
27  namespace devmgr {
28  namespace common {
29 
30  // Constants for state values
31  const short SRV_STATE_NOT_OPERATIONAL = 1;
32  const short SRV_STATE_OPERATIONAL = 2;
33 
34  // Constants for substate values
35  const short SRV_SUBSTATE_NOTREADY = 1;
36  const short SRV_SUBSTATE_READY = 2;
37  const short SRV_SUBSTATE_IDLE = 3;
38  const short SRV_SUBSTATE_INITIALISING = 4;
39  const short SRV_SUBSTATE_ENABLING = 5;
40  const short SRV_SUBSTATE_SETTING_UP = 6;
41  const short SRV_SUBSTATE_ERROR = 10;
42 
43 
44  const std::string SRV_STATE_NOT_OPERATIONAL_STR = "NotOperational";
45  const std::string SRV_STATE_OPERATIONAL_STR = "Operational";
46  const std::string SRV_STATE_UNAVAILABLE_STR = "Unavailable";
47 
48  const std::string SRV_SUBSTATE_NOTREADY_STR = "NotRead";
49  const std::string SRV_SUBSTATE_READY_STR = "Ready";
50  const std::string SRV_SUBSTATE_IDLE_STR = "Idle";
51  const std::string SRV_SUBSTATE_INITIALISING_STR = "Initialising";
52  const std::string SRV_SUBSTATE_ENABLING_STR = "Enabling";
53  const std::string SRV_SUBSTATE_ERROR_STR = "Error";
54  const std::string SRV_SUBSTATE_SETTING_UP_STR = "SettingUp";
55 
56 
57 
58  const std::unordered_map<short, std::string> SrvStateMap = {
61  };
62 
63  const std::unordered_map<std::string, short> SrvStateStrMap = {
66  };
67 
68  const std::unordered_map<short, std::string> SrvSubstateMap = {
76  };
77 
78  const std::unordered_map<std::string, short> SrvSubstateStrMap = {
86  };
87 
92  class DataContext {
93  public:
105  DataContext(IConfig& config,
106  rad::DbAdapter& db_adapter,
107  boost::asio::io_service& ios,
108  bool with_publisher = true);
109 
113  virtual ~DataContext();
114 
118  void ReloadConfig();
119 
123  void UpdateDb();
124 
129 
133  IConfig& GetConfig();
134 
135  short GetState();
136  std::string GetStateStr();
137  void SetState(const short state);
138  void SetState(const std::string state);
139  short GetSubstate();
140  std::string GetSubstateStr();
141  void SetSubstate(const short state);
142  void SetSubstate(const std::string state);
143  void SetSettingState(bool new_state);
144  bool GetSettingState();
145 
146  void PublishStates();
147 
148  DataContext(const DataContext&) = delete;
149  DataContext& operator=(const DataContext&) = delete;
150 
151  private:
152  IConfig& m_config;
153  rad::DbAdapter& m_runtime_db;
154 
155  boost::asio::io_service& m_ios;
156  DbInterface m_db_interface;
157  std::unique_ptr<rad::cii::Publisher<stdif::StatusTopic>> m_publisher;
158 
159 
160  short m_state;
161  short m_substate;
162  std::string m_state_str;
163  std::string m_substate_str;
164 
166  bool m_setting_state {false};
167  };
168 
169  }
170  } // namespace common
171 } // namespace devmgr
172 
173 #endif // DEVMGR_COMMON_DATA_CONTEXT_HPP_
fcf::devmgr::common::SrvSubstateStrMap
const std::unordered_map< std::string, short > SrvSubstateStrMap
Definition: dataContext.hpp:78
fcf::devmgr::common::SRV_SUBSTATE_IDLE_STR
const std::string SRV_SUBSTATE_IDLE_STR
Definition: dataContext.hpp:50
fcf::devmgr::common::SRV_STATE_NOT_OPERATIONAL
const short SRV_STATE_NOT_OPERATIONAL
Definition: dataContext.hpp:31
fcf::devmgr::common::DataContext::DataContext
DataContext(const DataContext &)=delete
Disable copy constructor.
fcf::devmgr::common::DataContext::PublishStates
void PublishStates()
Definition: dataContext.cpp:154
fcf::devmgr::common::DataContext::SetSettingState
void SetSettingState(bool new_state)
Definition: dataContext.cpp:167
fcf::devmgr::common::SRV_SUBSTATE_ERROR_STR
const std::string SRV_SUBSTATE_ERROR_STR
Definition: dataContext.hpp:53
fcf::devmgr::common::DataContext::GetState
short GetState()
Definition: dataContext.cpp:99
fcf::devmgr::common::SRV_SUBSTATE_INITIALISING_STR
const std::string SRV_SUBSTATE_INITIALISING_STR
Definition: dataContext.hpp:51
fcf::devmgr::common::DataContext::DataContext
DataContext(IConfig &config, rad::DbAdapter &db_adapter, boost::asio::io_service &ios, bool with_publisher=true)
Definition: dataContext.cpp:23
fcf::devmgr::common::SRV_SUBSTATE_NOTREADY_STR
const std::string SRV_SUBSTATE_NOTREADY_STR
Definition: dataContext.hpp:48
fcf::devmgr::common::SRV_SUBSTATE_READY_STR
const std::string SRV_SUBSTATE_READY_STR
Definition: dataContext.hpp:49
fcf::devmgr::common::SRV_SUBSTATE_ENABLING
const short SRV_SUBSTATE_ENABLING
Definition: dataContext.hpp:39
fcf::devmgr::common::SRV_SUBSTATE_READY
const short SRV_SUBSTATE_READY
Definition: dataContext.hpp:36
fcf::devmgr::common::SRV_STATE_OPERATIONAL
const short SRV_STATE_OPERATIONAL
Definition: dataContext.hpp:32
fcf::devmgr::common::DataContext::SetSubstate
void SetSubstate(const short state)
Definition: dataContext.cpp:136
fcf::devmgr::common::SRV_SUBSTATE_IDLE
const short SRV_SUBSTATE_IDLE
Definition: dataContext.hpp:37
fcf::devmgr::common::DbInterface
Definition: dbInterface.hpp:53
fcf::devmgr::common::SrvStateMap
const std::unordered_map< short, std::string > SrvStateMap
Definition: dataContext.hpp:58
fcf::devmgr::common::SRV_SUBSTATE_SETTING_UP_STR
const std::string SRV_SUBSTATE_SETTING_UP_STR
Definition: dataContext.hpp:54
fcf::devmgr::common::DataContext::~DataContext
virtual ~DataContext()
Definition: dataContext.cpp:50
fcf::devmgr::common::DataContext::operator=
DataContext & operator=(const DataContext &)=delete
Disable assignment operator.
fcf::devmgr::common::DataContext
Definition: dataContext.hpp:92
fcf
Definition: actionMgr.cpp:29
fcf::devmgr::common::SRV_SUBSTATE_ENABLING_STR
const std::string SRV_SUBSTATE_ENABLING_STR
Definition: dataContext.hpp:52
fcf::devmgr::common::DataContext::GetSettingState
bool GetSettingState()
Definition: dataContext.cpp:172
dbInterface.hpp
DbInterface class header file.
fcf::devmgr::common::DataContext::UpdateDb
void UpdateDb()
Definition: dataContext.cpp:63
fcf::devmgr::common::SRV_SUBSTATE_SETTING_UP
const short SRV_SUBSTATE_SETTING_UP
Definition: dataContext.hpp:40
fcf::devmgr::common::DataContext::ReloadConfig
void ReloadConfig()
Definition: dataContext.cpp:56
fcf::devmgr::common::DataContext::SetState
void SetState(const short state)
Definition: dataContext.cpp:109
fcf::devmgr::common::SRV_STATE_NOT_OPERATIONAL_STR
const std::string SRV_STATE_NOT_OPERATIONAL_STR
Definition: dataContext.hpp:44
fcf::devmgr::common::SRV_SUBSTATE_NOTREADY
const short SRV_SUBSTATE_NOTREADY
Definition: dataContext.hpp:35
fcf::devmgr::common::DataContext::GetDbInterface
DbInterface & GetDbInterface()
Definition: dataContext.cpp:93
fcf::devmgr::common::DataContext::GetSubstate
short GetSubstate()
Definition: dataContext.cpp:126
fcf::devmgr::common::SRV_SUBSTATE_ERROR
const short SRV_SUBSTATE_ERROR
Definition: dataContext.hpp:41
fcf::devmgr::common::SRV_SUBSTATE_INITIALISING
const short SRV_SUBSTATE_INITIALISING
Definition: dataContext.hpp:38
fcf::devmgr::common::SrvStateStrMap
const std::unordered_map< std::string, short > SrvStateStrMap
Definition: dataContext.hpp:63
fcf::devmgr::common::SRV_STATE_OPERATIONAL_STR
const std::string SRV_STATE_OPERATIONAL_STR
Definition: dataContext.hpp:45
fcf::devmgr::common::DataContext::GetSubstateStr
std::string GetSubstateStr()
Definition: dataContext.cpp:131
fcf::devmgr::common::DataContext::GetStateStr
std::string GetStateStr()
Definition: dataContext.cpp:104
iConfig.hpp
IConfig class header file.
fcf::devmgr::common::SrvSubstateMap
const std::unordered_map< short, std::string > SrvSubstateMap
Definition: dataContext.hpp:68
fcf::devmgr::common::IConfig
Definition: iConfig.hpp:22
fcf::devmgr::common::DataContext::GetConfig
IConfig & GetConfig()
Definition: dataContext.cpp:83
fcf::devmgr::common::SRV_STATE_UNAVAILABLE_STR
const std::string SRV_STATE_UNAVAILABLE_STR
Definition: dataContext.hpp:46