ifw-fcf 7.1.4
Loading...
Searching...
No Matches
dataContext.hpp
Go to the documentation of this file.
1
8#ifndef FCF_DEVMGR_COMMON_DATA_CONTEXT_HPP_
9#define FCF_DEVMGR_COMMON_DATA_CONTEXT_HPP_
10
11#include <unordered_map>
12
13//#include <mal/Cii.hpp>
14//#include <mal/utility/LoadMal.hpp>
15#include <rad/topicPub.hpp>
16#include <rad/mal/publisher.hpp>
17//#include <boost/asio.hpp>
18#include <Stdif.hpp>
20#include <ifw/core/utils/bat/dbInterface.hpp>
21
23
24 // Constants for state values
26 const short SRV_STATE_OPERATIONAL = 2;
27
28 // Constants for substate values
29 const short SRV_SUBSTATE_NOTREADY = 1;
30 const short SRV_SUBSTATE_READY = 2;
31 const short SRV_SUBSTATE_IDLE = 3;
33 const short SRV_SUBSTATE_ENABLING = 5;
34 const short SRV_SUBSTATE_SETTING_UP = 6;
35 const short SRV_SUBSTATE_ERROR = 10;
36
37
38 const std::string SRV_STATE_NOT_OPERATIONAL_STR = "NotOperational";
39 const std::string SRV_STATE_OPERATIONAL_STR = "Operational";
40 const std::string SRV_STATE_UNAVAILABLE_STR = "Unavailable";
41
42 const std::string SRV_SUBSTATE_NOTREADY_STR = "NotReady";
43 const std::string SRV_SUBSTATE_READY_STR = "Ready";
44 const std::string SRV_SUBSTATE_IDLE_STR = "Idle";
45 const std::string SRV_SUBSTATE_INITIALISING_STR = "Initialising";
46 const std::string SRV_SUBSTATE_ENABLING_STR = "Enabling";
47 const std::string SRV_SUBSTATE_ERROR_STR = "Error";
48 const std::string SRV_SUBSTATE_SETTING_UP_STR = "SettingUp";
49
50
51
56
61
71
81
87 public:
99 DataContext(Config& config,
100 boost::asio::io_service& ios,
101 bool with_publisher = true,
102 bool with_oldb = true);
103
107 virtual ~DataContext();
108
112 void ReloadConfig();
113
117 void UpdateDb();
118 void UpdateDb(ifw::core::utils::bat::DbVector& vec);
119
120
124 Config& GetConfig();
125
126 short GetState();
127 std::string GetStateStr();
128 void SetState(const short state);
129 void SetState(const std::string state);
130 short GetSubstate();
131 std::string GetSubstateStr();
132 void SetSubstate(const short state);
133 void SetSubstate(const std::string state);
134 void SetSettingState(bool new_state);
135 bool GetSettingState();
136
137 void PublishStates();
138
139 /*
140 template<typename T>
141 void Set(const std::string& key,
142 const T& value);
143 */
144
145 template<typename T>
146 void SetAsync(const std::string& key,
147 const T& value);
148
149
150 DataContext(const DataContext&) = delete;
152
153 private:
154 Config& m_config;
155 std::unique_ptr<ifw::core::utils::bat::DbInterface> m_db_interface;
156
158 boost::asio::io_service& m_ios;
162 std::unique_ptr<rad::cii::Publisher<stdif::Status>> m_publisher;
163
164 short m_state;
165 short m_substate;
166 std::string m_state_str;
167 std::string m_substate_str;
168
172 bool m_setting_state {false};
173 log4cplus::Logger m_logger;
174 };
175
176 /*
177 template<typename T>
178 void DataContext::Set(const std::string& key, const T& value) {
179 if (m_db_interface) {
180 m_db_interface->Set<T>(key, value);
181 }
182 }
183 */
184
185 template<typename T>
186 void DataContext::SetAsync(const std::string& key, const T& value) {
187 if (m_db_interface) {
188 m_db_interface->SetAsync<T>(key, value);
189 }
190 }
191
192} // namespace devmgr
193
194#endif // DEVMGR_COMMON_DATA_CONTEXT_HPP_
Definition config.hpp:54
Definition dataContext.hpp:86
Config & GetConfig()
Definition dataContext.cpp:98
bool GetSettingState()
Definition dataContext.cpp:206
void UpdateDb()
Definition dataContext.cpp:65
void ReloadConfig()
Definition dataContext.cpp:58
void SetSubstate(const short state)
Definition dataContext.cpp:142
std::string GetSubstateStr()
Definition dataContext.cpp:137
virtual ~DataContext()
Definition dataContext.cpp:52
short GetSubstate()
Definition dataContext.cpp:132
void SetSettingState(bool new_state)
Definition dataContext.cpp:201
void SetAsync(const std::string &key, const T &value)
Definition dataContext.hpp:186
DataContext & operator=(const DataContext &)=delete
Disable assignment operator.
void PublishStates()
Definition dataContext.cpp:160
DataContext(const DataContext &)=delete
Disable copy constructor.
DataContext(Config &config, boost::asio::io_service &ios, bool with_publisher=true, bool with_oldb=true)
Definition dataContext.cpp:20
short GetState()
Definition dataContext.cpp:105
void SetState(const short state)
Definition dataContext.cpp:115
std::string GetStateStr()
Definition dataContext.cpp:110
ActionMgr class source file.
Definition actionMgr.cpp:28
const short SRV_SUBSTATE_ENABLING
Definition dataContext.hpp:33
const std::string SRV_STATE_UNAVAILABLE_STR
Definition dataContext.hpp:40
const std::string SRV_SUBSTATE_READY_STR
Definition dataContext.hpp:43
const short SRV_SUBSTATE_SETTING_UP
Definition dataContext.hpp:34
const short SRV_SUBSTATE_INITIALISING
Definition dataContext.hpp:32
const std::unordered_map< std::string, short > SRV_SUBSTATE_STR_MAP
Definition dataContext.hpp:72
const short SRV_SUBSTATE_IDLE
Definition dataContext.hpp:31
const std::string SRV_STATE_NOT_OPERATIONAL_STR
Definition dataContext.hpp:38
const short SRV_SUBSTATE_ERROR
Definition dataContext.hpp:35
const std::string SRV_SUBSTATE_IDLE_STR
Definition dataContext.hpp:44
const std::string SRV_SUBSTATE_ERROR_STR
Definition dataContext.hpp:47
const short SRV_STATE_OPERATIONAL
Definition dataContext.hpp:26
const std::string SRV_SUBSTATE_INITIALISING_STR
Definition dataContext.hpp:45
const short SRV_SUBSTATE_READY
Definition dataContext.hpp:30
const short SRV_SUBSTATE_NOTREADY
Definition dataContext.hpp:29
const std::string SRV_SUBSTATE_SETTING_UP_STR
Definition dataContext.hpp:48
const std::string SRV_SUBSTATE_NOTREADY_STR
Definition dataContext.hpp:42
const short SRV_STATE_NOT_OPERATIONAL
Definition dataContext.hpp:25
const std::string SRV_SUBSTATE_ENABLING_STR
Definition dataContext.hpp:46
const std::string SRV_STATE_OPERATIONAL_STR
Definition dataContext.hpp:39
const std::unordered_map< short, std::string > SRV_SUBSTATE_MAP
Definition dataContext.hpp:62
const std::unordered_map< short, std::string > SRV_STATE_MAP
Definition dataContext.hpp:52
const std::unordered_map< std::string, short > SRV_STATE_STR_MAP
Definition dataContext.hpp:57