2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_StateMachine
21 /// This file has the CFrameworkunifiedCompositeState class definitions. CFrameworkunifiedCompositeState is derived from C
22 /// FrameworkunifiedState class.This class implements the additional functionality supported by HSM Composite
23 /// state. It provides the standard interfaces for adding state.
25 ///////////////////////////////////////////////////////////////////////////////
28 * @file frameworkunified_sm_compositestate.h
29 * @brief \~english This file has the CFrameworkunifiedCompositeState class definitions. CFrameworkunifiedCompositeState is derived from C
30 * FrameworkunifiedState class.This class implements the additional functionality supported by HSM Composite
31 * state. It provides the standard interfaces for adding state.
34 /** @addtogroup BaseSystem
37 /** @addtogroup native_service
41 /** @addtogroup framework_unified
42 * @ingroup native_service
45 /** @addtogroup framework
46 * @ingroup framework_unified
49 /** @addtogroup statemachine
53 #ifndef _FRAMEWORKUNIFIEDCOMPOSITESTATE_H // NOLINT (build/header_guard)
54 #define _FRAMEWORKUNIFIEDCOMPOSITESTATE_H
56 ///////////////////////////////////////////////////////////////////////////////////////////////////
58 ///////////////////////////////////////////////////////////////////////////////////////////////////
60 #include <native_service/frameworkunified_sm_state.h>
64 typedef std::map<std::string, CFrameworkunifiedState *> ChildStateList;
65 typedef std::map<std::string, CFrameworkunifiedState *>::iterator StateIterator;
67 class CFrameworkunifiedHSM;
69 ///////////////////////////////////////////////////////////////////////////////////////////////////
70 /// This class implements the additional functionality supported by HSM Composite
71 /// state. It provides the standard interfaces for adding state.
72 ///////////////////////////////////////////////////////////////////////////////////////////////////
73 class CFrameworkunifiedCompositeState : public CFrameworkunifiedState {
76 typedef enum _FRAMEWORKUNIFIED_STATE_TYPE {
77 eFrameworkunifiedState = 0,
78 eFrameworkunifiedDefaultState
79 } FRAMEWORKUNIFIED_STATE_TYPE;
81 ///////////////////////////////////////////////////////////////////////////////////////////
82 /// \ingroup CFrameworkunifiedCompositeState
83 /// \~english @par Brief
84 /// Constructor for class CFrameworkunifiedCompositeState.
85 /// \~english @param [in] f_strName
86 /// std::string -Name of state
88 /// \~english @par Prerequisite
90 /// \~english @par Change of internal state
92 /// \~english @par Conditions of processing failure
94 /// \~english @par Detail
95 /// This class inherit from CFrameworkunifiedState(basic class of state machine), \n
96 /// and create object of CFrameworkunifiedCompositeState class. \n
97 /// Create and initialize child state, and set the pointor to member variable. \n
98 /// Initialize other member variables with NULL. \n
99 /// Output the process error logs.
100 /// \~english @par Classification
102 /// \~english @par Type
104 /// \~english @see CFrameworkunifiedState, ~CFrameworkunifiedCompositeState
105 ///////////////////////////////////////////////////////////////////////////////////////////
106 CFrameworkunifiedCompositeState(std::string f_pName); // NOLINT (readability/nolint)
108 ///////////////////////////////////////////////////////////////////////////////////////////
109 /// \ingroup CFrameworkunifiedCompositeState
110 /// \~english @par Brief
111 /// Destructor for CFrameworkunifiedCompositeState
112 /// \~english @retval none
113 /// \~english @par Preconditons
114 /// - Self instance of CFrameworkunifiedCompositeState created.
115 /// \~english @par Change of internal status
117 /// \~english @par Conditions of processing failure
119 /// \~english @par Detail
120 /// Release the objects of CFrameworkunifiedState class and CFrameworkunifiedCompositeState class. \n
121 /// Release all the child states registered in child states list of member variable. \n
122 /// Output error log if failed.
123 /// \~english @par Classification
125 /// \~english @par Type
127 /// \~english @see CFrameworkunifiedState, CFrameworkunifiedCompositeState::CFrameworkunifiedCompositeState
128 ///////////////////////////////////////////////////////////////////////////////////////////
129 virtual ~CFrameworkunifiedCompositeState();
131 ////////////////////////////////////////////////////////////////////////////////////////////
132 /// \ingroup CFrameworkunifiedCompositeState
133 /// \~english @par Brief
134 /// sets the given state as a substate of the current state. If the f_eStateType is
135 /// eFrameworkunifiedDefaultState then substate is default state for current state.
136 /// \~english @param [in] f_pState
137 /// CFrameworkunifiedState* - Pointer to the substate object to be added in the current state
138 /// \~english @param [in] f_eStateType
139 /// FRAMEWORKUNIFIED_STATE_TYPE - state type indicating if it is default state
140 /// \~english @retval EFrameworkunifiedStatus
142 /// \~english @par Preconditons
143 /// - Self instance of CFrameworkunifiedCompositeState created.
144 /// \~english @par Change of internal status
146 /// \~english @par Conditions of processing failure
147 /// - If parameter f_pState is NULL. [eFrameworkunifiedStatusNullPointer]
148 /// - If m_pChildStates is NULL. [eFrameworkunifiedStatusNullPointer]
149 /// \~english @par Detail
150 /// sets the given state as a substate of the current state. If the f_eStateType is
151 /// eFrameworkunifiedDefaultState then substate is default state for current state.
152 /// \~english @par Classification
154 /// \~english @par Type
156 /// \~english @see none
157 ////////////////////////////////////////////////////////////////////////////////////////////
158 EFrameworkunifiedStatus FrameworkunifiedAddState(CFrameworkunifiedState *f_pState,
159 FRAMEWORKUNIFIED_STATE_TYPE f_eStateType = eFrameworkunifiedState);
161 ////////////////////////////////////////////////////////////////////////////////////////////
162 /// \ingroup CFrameworkunifiedCompositeState
163 /// \~english @par Brief
164 /// Returns the default state of the current composite state.
165 /// \~english @param none
166 /// \~english @retval CFrameworkunifiedState* - pointer default state
167 /// \~english @par Preconditons
168 /// - Self instance of CFrameworkunifiedCompositeState created.
169 /// \~english @par Change of internal status
171 /// \~english @par Conditions of processing failure
173 /// \~english @par Detail
174 /// Returns the default state of the current composite state.
175 /// \~english @par Classification
177 /// \~english @par Type
179 /// \~english @see none
180 ////////////////////////////////////////////////////////////////////////////////////////////
181 CFrameworkunifiedState *FrameworkunifiedGetDefaultState();
183 ///////////////////////////////////////////////////////////////////////////////////////////
184 /// \ingroup CFrameworkunifiedCompositeState
185 /// \~english @par Brief
186 /// Logs the state name and events associated with the state.
187 /// \~english @param none
188 /// \~english @retval eFrameworkunifiedStatusOK succ
189 /// \~english @retval eFrameworkunifiedStatusNullPointer failed
190 /// \~english @par Preconditons
191 /// - Self instance of CFrameworkunifiedCompositeState created.
192 /// \~english @par Change of internal status
194 /// \~english @par Conditions of processing failure
195 /// - Don't create instance of CFrameworkunifiedCompositeState [eFrameworkunifiedStatusNullPointer]
196 /// \~english @par Detail
197 /// This function overrides the fuction of CFrameworkunifiedState::FrameworkunifiedPrintStates.
198 /// This function outputs log of state name and events associated with the state as follows:
199 /// - state name of parent state machine and self state machine
200 /// - all the event names in event list
201 /// - all the event names in delay event list
202 /// \~english @par Classification
204 /// \~english @par Type
206 /// \~english @see none
207 ///////////////////////////////////////////////////////////////////////////////////////////
208 virtual EFrameworkunifiedStatus FrameworkunifiedPrintStates();
210 ///////////////////////////////////////////////////////////////////////////////////////////
211 /// \ingroup CFrameworkunifiedCompositeState
212 /// \~english @par Brief
213 /// This indicates if the state has sub states. It returns TRUE only in the CompositeState
214 /// where this function is overridden
215 /// \~english @param none
216 /// \~english @retval BOOL TRUE - has substate FALSE - has not substatue
217 /// \~english @par Preconditons
218 /// - Self instance of CFrameworkunifiedCompositeState created.
219 /// \~english @par Change of internal status
221 /// \~english @par Conditions of processing failure
223 /// \~english @par Detail
224 /// This function overrides the fuction of CFrameworkunifiedState::FrameworkunifiedHasSubStates.
225 /// Return true only in CFrameworkunifiedCompositeState class.
226 /// \~english @par Classification
228 /// \~english @par Type
230 /// \~english @see CFrameworkunifiedState::FrameworkunifiedHasSubStates
231 virtual BOOL FrameworkunifiedHasSubStates();
233 ///////////////////////////////////////////////////////////////////////////////////////////
234 /// \ingroup CFrameworkunifiedCompositeState
235 /// \~english @par Brief
236 /// This interface returns the Active state of the current composite state. In case of
237 /// non-composite state current state is active state
238 /// \~english @param none
239 /// \~english @retval CFrameworkunifiedState* pointer of active state
240 /// \~english @par Preconditons
241 /// - Self instance of CFrameworkunifiedCompositeState created.
242 /// \~english @par Change of internal status
244 /// \~english @par Conditions of processing failure
246 /// \~english @par Detail
247 /// This function overrides the pure virtual fuction of CFrameworkunifiedState::FrameworkunifiedGetActiveState.
248 /// Reture active state of current composite state. If it isn't a composite state,
249 /// return current state as an active state.
250 /// \~english @par Classification
252 /// \~english @par Type
254 /// \~english @see CFrameworkunifiedState::FrameworkunifiedGetActiveState
255 ///////////////////////////////////////////////////////////////////////////////////////////
256 virtual CFrameworkunifiedState *FrameworkunifiedGetActiveState();
258 ///////////////////////////////////////////////////////////////////////////////////////////
259 /// \ingroup CFrameworkunifiedCompositeState
260 /// \~english @par Brief
261 /// This function stores the last active state
262 /// \~english @param none
263 /// \~english @retval EFrameworkunifiedStatus eFrameworkunifiedStatusOK
264 /// \~english @par Preconditons
265 /// - Self instance of CFrameworkunifiedCompositeState created.
266 /// \~english @par Change of internal status
268 /// \~english @par Conditions of processing failure
270 /// \~english @par Detail
271 /// This function overrides the pure virtual fuction of CFrameworkunifiedState::UpdateHistory.
272 /// Store the last active state.
273 /// \~english @par Classification
275 /// \~english @par Type
277 /// \~english @see CFrameworkunifiedState::UpdateHistory
278 ///////////////////////////////////////////////////////////////////////////////////////////
279 EFrameworkunifiedStatus UpdateHistory();
281 ///////////////////////////////////////////////////////////////////////////////////////////
282 /// \ingroup CFrameworkunifiedCompositeState
283 /// \~english @par Brief
284 /// Update the State information in the given stream in the form of XML tags
286 /// \~english @param f_strXMLString
287 /// std::ostringstream & - reference to the XML stream
288 /// \~english @retval EFrameworkunifiedStatus eFrameworkunifiedStatusOK
289 /// eFrameworkunifiedStatusNullPointer
290 /// \~english @par Preconditons
291 /// - Self instance of CFrameworkunifiedCompositeState created.
292 /// - State machine of current state in the applicaton is setted in FrameworkunifiedSetHSM.
293 /// \~english @par Change of internal status
294 /// - Self instance of CFrameworkunifiedCompositeState created failed. [eFrameworkunifiedStatusNullPointer].
295 /// \~english @par Conditions of processing failure
297 /// \~english @par Detail
298 /// This function overrides the fuction of CFrameworkunifiedState::FrameworkunifiedPrintXML.
299 /// Set parameter f_strXMLString with the following state information by XML type.
301 /// - all the event information in event list(event ID, event name)
302 /// - all the event information in delay event list(event ID, event name)
303 /// \~english @par Classification
305 /// \~english @par Type
307 /// \~english @see CFrameworkunifiedState::FrameworkunifiedPrintXML
308 ///////////////////////////////////////////////////////////////////////////////////////////
309 virtual EFrameworkunifiedStatus FrameworkunifiedPrintXML(std::ostringstream &f_strXMLString);
314 ///////////////////////////////////////////////////////////////////////////////////////////
315 /// \ingroup CFrameworkunifiedCompositeState
316 /// \~english @par Brief
318 /// \~english @param f_pEventData
319 /// CEventDataPtr - Pointer to the event data class
320 /// \~english @retval eFrameworkunifiedStatusOK
321 /// \~english @par Preconditions
322 /// - Its own instance (CFrameworkunifiedCompositeState) has been created.
323 /// \~english @par Change of internal status
324 /// - The internal state is not changed.
325 /// \~english @par Conditions of processing failure
327 /// \~english @par Detail
328 /// This method overrides and uses CFrameworkunifiedState::FrameworkunifiedOnEntry, which is pure virtual functions, to initialize state.
329 /// \~english @par Classification
331 /// \~english @par Type
333 /// \~english @see CFrameworkunifiedState::FrameworkunifiedOnEntry, FrameworkunifiedOnExit
335 /// state initialization can be performed in this function.
337 /// \param [in] f_pEventData
338 /// CEventDataPtr - Event data
340 /// \return EFrameworkunifiedStatus
341 /// EFrameworkunifiedStatus - Returns status of operation
342 ///////////////////////////////////////////////////////////////////////////////////////////
343 virtual EFrameworkunifiedStatus FrameworkunifiedOnEntry(CEventDataPtr f_pEventData);
345 ///////////////////////////////////////////////////////////////////////////////////////////
346 /// \ingroup CFrameworkunifiedCompositeState
347 /// \~english @par Brief
349 /// \~english @param f_pEventData
350 /// CEventDataPtr - Pointer to the event data class
351 /// \~english @retval eFrameworkunifiedStatusOK
352 /// \~english @par Preconditions
353 /// - Its own instance (CFrameworkunifiedCompositeState) has been created.
354 /// \~english @par Change of internal status
355 /// - The internal state is not changed.
356 /// \~english @par Conditions of processing failure
358 /// \~english @par Detail
359 /// This method overrides and uses CFrameworkunifiedState::FrameworkunifiedOnExit, which is pure virtual functions, to clean up state.
360 /// \~english @par Classification
362 /// \~english @par Type
364 /// \~english @see CFrameworkunifiedState::FrameworkunifiedOnExit, FrameworkunifiedOnEntry
366 /// state cleanup can be performed in this function.
368 /// \param [in] f_pEventData
369 /// CEventDataPtr - Event data
371 /// \return EFrameworkunifiedStatus
372 /// EFrameworkunifiedStatus - Returns status of operation
373 ///////////////////////////////////////////////////////////////////////////////////////////
374 virtual EFrameworkunifiedStatus FrameworkunifiedOnExit(CEventDataPtr f_pEventData);
376 /// stores the pointers to sub state, key is state name
377 ChildStateList *m_pChildStates;
379 ///////////////////////////////////////////////////////////////////////////////////////////
380 /// \ingroup CFrameworkunifiedCompositeState
381 /// \~english @par Brief
382 /// Associate the state machine with the current state.
383 /// \~english @param [in] f_pStatemachine
384 /// CFrameworkunifiedHSM* - Pointers to state machines (CFrameworkunifiedHSM classes)
385 /// \~english @retval eFrameworkunifiedStatusOK
386 /// \~english @retval eFrameworkunifiedStatusNullPointer Specifying NULL pointers
387 /// \~english @par Preconditions
388 /// - Its own instance (CFrameworkunifiedCompositeState) has been created.
389 /// \~english @par Change of internal status
390 /// - The internal state is not changed.
391 /// \~english @par Conditions of processing failure
392 /// - When the pointers to the state machines (CFrameworkunifiedHSM classes) specified in the arguments (f_pStatemachine) are NULL [eFrameworkunifiedStatusNullPointer]
393 /// \~english @par Detail
394 /// This method is used by overriding CFrameworkunifiedState::FrameworkunifiedSetHSM.\n
395 /// Associates a state machine with the current state by setting a pointer (f_pStatemachine)
396 /// to the state machine (CFrameworkunifiedHSM) specified by the argument to the pointer to the state machine of the member variable. \n
397 /// Calling FrameworkunifiedSetHSM() for child states also associates the state machine of the child states with the state of the current state.
398 /// \~english @par Classification
400 /// \~english @par Type
402 /// \~english @see CFrameworkunifiedHSM, CFrameworkunifiedState::FrameworkunifiedSetHSM
404 /// Sets the statemachine in the status
406 /// \param [in] f_pStatemachine
407 /// CFrameworkunifiedHSM* - Statemachine pointer
409 /// \return EFrameworkunifiedStatus
410 /// EFrameworkunifiedStatus - Returns status of operation
411 ///////////////////////////////////////////////////////////////////////////////////////////
412 virtual EFrameworkunifiedStatus FrameworkunifiedSetHSM(CFrameworkunifiedHSM *f_pStatemachine);
415 ////////////////////////////////////////////////////////////////////////////////////////////////
417 /// This function searches for history state in this composite state and updates it.
419 /// \param [in] l_cHistoryType
420 /// string - Type of history state (shallow or deep)
422 /// \return EFrameworkunifiedStatus
423 /// EFrameworkunifiedStatus - Returns status of operation
424 ///////////////////////////////////////////////////////////////////////////////////////////
425 EFrameworkunifiedStatus CheckHistory(std::string l_cHistoryType);
428 #endif // _FRAMEWORKUNIFIEDCOMPOSITESTATE_H // NOLINT (build/header_guard)