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 CFrameworkunifiedOrthogonalState class definitions. CFrameworkunifiedOrthogonalState is derived from
22 /// CFrameworkunifiedCompositeState class.This class implements the additional functionality supported by HSM
23 /// Orthogonal state. It provides the standard interfaces for adding orthogonal state machines.
25 ///////////////////////////////////////////////////////////////////////////////
28 * @file frameworkunified_sm_orthogonalstate.h
29 * @brief \~english This file has the CFrameworkunifiedOrthogonalState class definitions. CFrameworkunifiedOrthogonalState is derived from
30 * CFrameworkunifiedCompositeState class.This class implements the additional functionality supported by HSM
31 * Orthogonal state. It provides the standard interfaces for adding orthogonal state machines.
33 /** @addtogroup BaseSystem
36 /** @addtogroup native_service
40 /** @addtogroup framework_unified
41 * @ingroup native_service
44 /** @addtogroup framework
45 * @ingroup framework_unified
48 /** @addtogroup statemachine
52 #ifndef _FRAMEWORKUNIFIEDORTHOGONALSTATE_H // NOLINT (build/header_guard)
53 #define _FRAMEWORKUNIFIEDORTHOGONALSTATE_H
55 ///////////////////////////////////////////////////////////////////////////////////////////////////
57 ///////////////////////////////////////////////////////////////////////////////////////////////////
59 #include <native_service/frameworkunified_sm_state.h>
62 typedef std::vector<CFrameworkunifiedState *> OrthogonalRegionList;
64 class CFrameworkunifiedCompositeState;
66 class CFrameworkunifiedHSM;
67 ///////////////////////////////////////////////////////////////////////////////////////////////////
68 /// This class implements the additional functionality supported by HSM
69 /// Orthogonal state. It provides the standard interfaces for adding orthogonal state machines.
70 ///////////////////////////////////////////////////////////////////////////////////////////////////
71 class CFrameworkunifiedOrthogonalState : public CFrameworkunifiedState {
73 ///////////////////////////////////////////////////////////////////////////////////////////
74 /// \ingroup tag_CFrameworkunifiedOrthogonalState
75 /// \~english @par Brief
76 /// Constructors for CFrameworkunifiedOrthogonalState classes
77 /// \~english @param [in] f_pName
78 /// std::string - state name
79 /// \~english @retval None
80 /// \~english @par Prerequisite
82 /// \~english @par Change of internal state
83 /// - The internal state is not changed.
84 /// \~english @par Conditions of processing failure
85 /// - When the quadrature region list cannot be created due to insufficient memory
86 /// \~english @par Detail
87 /// Generates an orthographic region list.\n
88 /// CFrameworkunifiedOrthogonalState classes are used to manage the status of independent features individually.\n
89 /// For example, when the function of the clock is set to the following two, the management of the internal state is performed according to the function.\n
90 /// - Clock function (Clock display by 12h/24h)\n
91 /// - Alarm function (on/off setting)
92 /// \~english @par Classification
94 /// \~english @par Type
96 /// \~english @see ~CFrameworkunifiedOrthogonalState
97 ///////////////////////////////////////////////////////////////////////////////////////////
98 /// CFrameworkunifiedCompositeState
99 /// Parameterized constructor
100 /// \param [in] f_pName
101 /// string - Name of the state
104 CFrameworkunifiedOrthogonalState(std::string f_pName); // NOLINT (readability/nolint)
106 ///////////////////////////////////////////////////////////////////////////////////////////
107 /// \ingroup tag_CFrameworkunifiedOrthogonalState
108 /// \~english @par Brief
109 /// Destructors of CFrameworkunifiedOrthogonalState classes
110 /// \~english @retval None
111 /// \~english @par Prerequisite
112 /// - Its own instance (CFrameworkunifiedOrthogonalState) has been created.
113 /// \~english @par Change of internal state
114 /// - The internal state is not changed.
115 /// \~english @par Conditions of processing failure
117 /// \~english @par Detail
118 /// Frees the memory in the orthographic area list and clears the memory contents.
119 /// \~english @par Classification
121 /// \~english @par Type
123 /// \~english @see CFrameworkunifiedOrthogonalState
124 ///////////////////////////////////////////////////////////////////////////////////////////
125 /// ~CFrameworkunifiedOrthogonalState
129 virtual ~CFrameworkunifiedOrthogonalState();
133 ///////////////////////////////////////////////////////////////////////////////////////////
134 /// \ingroup tag_CFrameworkunifiedOrthogonalState
135 /// \~english @par Brief
137 /// \~english @param [in] f_pEventData
138 /// CEventDataPtr - Pointer to the event data class
139 /// \~english @retval Successful pointer to the current state after processing
140 /// \~english @retval NULL Exception supine in internal processing
141 /// \~english @par Prerequisite
142 /// - Its own instance (CFrameworkunifiedOrthogonalState) has been created.
143 /// - The State Machine for the current state of the application is set in the FrameworkunifiedSetHSM.
144 /// \~english @par Change of internal state
145 /// - The internal state is not changed.
146 /// \~english @par Conditions of processing failure
147 /// - Failed recursive function call (FrameworkunifiedOnEntry call)[NULL]
148 /// - If the pointers to the orthographic regions are NULL [NULL]
149 /// \~english @par Detail
150 /// Loops as many times as the number of elements in the quadrature area list, and initializes the active state (calls FrameworkunifiedOnEntry).\n
151 /// If the current state is Leaf State, it does not initialize because it does not have any active state.\n
152 /// If, after initialization, the current state is a child state of Orthogonal State, sets itself (the this pointer) to the current state.\n
153 /// Breaks looping if the current state is not a child state of Orthogonal State.\n
154 /// To maintain the hierarchy, the active state of the parent state is set to the current state.
155 /// \~english @par Classification
157 /// \~english @par Type
159 /// \~english @see FrameworkunifiedOnHSMStop, FrameworkunifiedOnEntry, CFrameworkunifiedState::FrameworkunifiedOnHSMStart, IsOrthogonalChildState
160 ///////////////////////////////////////////////////////////////////////////////////////////
161 /// FrameworkunifiedOnHSMStart
162 /// This function is called recursively till the leaf state is reached. This internally
163 /// calls the Entry function of the current state.
165 /// \param [in] f_pEventData
166 /// CEventDataPtr - Event data
168 /// \return CurrentState
169 /// CFrameworkunifiedState* - Returns current state after operation
170 CFrameworkunifiedState *FrameworkunifiedOnHSMStart(CEventDataPtr f_pEventData);
172 ///////////////////////////////////////////////////////////////////////////////////////////
173 /// \ingroup tag_CFrameworkunifiedOrthogonalState
174 /// \~english @par Brief
176 /// \~english @param [in] f_pEventData
177 /// CEventDataPtr - Pointer to the event data class
178 /// \~english @retval Successful pointer to the current state after processing
179 /// \~english @retval NULL Exception supine in internal processing
180 /// \~english @par Prerequisite
181 /// - Its own instance (CFrameworkunifiedOrthogonalState) has been created.
182 /// - The State Machine for the current state of the application is set in the FrameworkunifiedSetHSM.
183 /// \~english @par Change of internal state
184 /// - The internal state is not changed.
185 /// \~english @par Conditions of processing failure
186 /// - If the pointers to the orthographic regions are NULL [NULL]
187 /// - If the pointers to the orthographic area lists of the member variables are NULL [NULL]
188 /// - Active state pointers from orthographic area lists of member variables are NULL [NULL]
189 /// - If the current state of the state being cleaned up is NULL [NULL]
190 /// \~english @par Detail
191 /// Loops as many times as the number of elements in the quadrature area list, and performs cleanup of the active state (calls FrameworkunifiedOnExit).\n
192 /// If the current state is Leaf State,Do not clean up because it does not have any active state.\n
193 /// If the current state is a child state of Orthogonal State (orthographic state) after the cleanup process finishes,Sets itself (the this pointer) to the current state.\n
194 /// Breaks looping if the current state is not a child state of Orthogonal State.
195 /// \~english @par Classification
197 /// \~english @par Type
199 /// \~english @see FrameworkunifiedOnHSMStart, CFrameworkunifiedState::FrameworkunifiedOnHSMStop, CFrameworkunifiedState::FrameworkunifiedPostEvent, FrameworkunifiedOnExit,
200 /// IsOrthogonalChildState
201 ///////////////////////////////////////////////////////////////////////////////////////////
202 /// FrameworkunifiedOnHSMStop
203 /// This function is called recursively till the required parent state is reached. This
204 /// internally calls the Exit function of the current state.
206 /// \param [in] f_pEventData
207 /// CEventDataPtr - Event data
209 /// \return CurrentState
210 /// CFrameworkunifiedState* - Returns current state after operation
211 CFrameworkunifiedState *FrameworkunifiedOnHSMStop(CEventDataPtr f_pEventData);
213 ///////////////////////////////////////////////////////////////////////////////////////////
214 /// FrameworkunifiedAddOrthogonalRegion
215 /// This Interface adds orthogonal region in the orthogonal state.
217 /// \param [in] f_pOrthogonalRegion
218 /// CFrameworkunifiedCompositeState - Orthogonal region object to be associated with state.
220 /// \return CurrentState
221 /// CFrameworkunifiedState* - Returns current state after operation
222 ///////////////////////////////////////////////////////////////////////////////////////////
223 EFrameworkunifiedStatus FrameworkunifiedAddOrthogonalRegion(CFrameworkunifiedCompositeState *f_pOrthogonalRegion);
225 ///////////////////////////////////////////////////////////////////////////////////////////
226 /// \ingroup tag_CFrameworkunifiedOrthogonalState
227 /// \~english @par Brief
228 /// Checks whether OrthogonalRegion (orthographic area) is registered or not.
229 /// \~english @retval TRUE OrthogonalRegion (orthographic area) is registered
230 /// \~english @retval FALSE OrthogonalRegion (orthographic area) is not registered
231 /// \~english @par Prerequisite
232 /// - Its own instance (CFrameworkunifiedOrthogonalState) has been created.
233 /// - OrthogonalRegion (orthographic area) is registered in FrameworkunifiedAddOrthogonalRegion.
234 /// \~english @par Change of internal state
235 /// - The internal state is not changed.
236 /// \~english @par Conditions of processing failure
237 /// - If the pointers to the orthographic regions are NULL [FALSE]
238 /// - When the OrthogonalRegion (orthographic area) is not registered and the number of elements (size) of the orthographic area is 0, [FALSE]
239 /// \~english @par Detail
240 /// Checks whether OrthogonalRegion (orthographic area) is registered by referring to the number of elements (size) of the orthographic area list.
241 /// \~english @par Classification
243 /// \~english @par Type
246 ///////////////////////////////////////////////////////////////////////////////////////////
247 /// FrameworkunifiedHasOrthogoanlRegions
248 /// This checks if the current state has Orthogonal regions
251 /// \return TRUE/FASLE
252 /// BOOL - returns TRUE if orthogonal regions are available in the state
253 virtual BOOL FrameworkunifiedHasOrthogoanlRegions();
255 ///////////////////////////////////////////////////////////////////////////////////////////
256 /// \ingroup tag_CFrameworkunifiedOrthogonalState
257 /// \~english @par Brief
259 /// \~english @param [in] f_pEventData
260 /// CEventDataPtr - Pointer to the event data class
261 /// \~english @retval Successful pointer to the current state after processing
262 /// \~english @retval NULL Operation cannot be guaranteed.
263 /// \~english @par Prerequisite
264 /// - Its own instance (CFrameworkunifiedOrthogonalState) has been created.
265 /// - The State Machine for the current state of the application is set in the FrameworkunifiedSetHSM.
266 /// - OrthogonalRegion (orthographic area) is registered in FrameworkunifiedAddOrthogonalRegion.
267 /// \~english @par Change of internal state
268 /// - The internal state is not changed.
269 /// \~english @par Conditions of processing failure
270 /// - If the pointers to the orthographic regions are NULL [NULL]
271 /// - If the event data class is pointed to by NULL [NULL]
272 /// \~english @par Detail
273 /// If the event specified in the argument (f_pEventData) is available in the current state,Set itself (this) to current state and return it.\n
274 /// Invokes the parent-state FrameworkunifiedOnEvent if not available in the current state
275 /// (Repeated until the root state is reached.)\n
276 /// However, since the FrameworkunifiedState that is the parent state of the Orthogonal State (orthographic state) is the root state,You call the FrameworkunifiedOnEvent of FrameworkunifiedState.\n
277 /// If the current state is a child state of the Orthogonal State (quadrature state) after the above process, sets itself (the this pointer) to the current state.
278 /// \~english @par Classification
280 /// \~english @par Type
282 /// \~english @see CFrameworkunifiedCompositeState::FrameworkunifiedGetActiveState, CFrameworkunifiedState::FrameworkunifiedIsReactionAvailable, CFrameworkunifiedState::FrameworkunifiedOnEvent,
283 /// IsOrthogonalChildState
284 ///////////////////////////////////////////////////////////////////////////////////////////
285 ///////////////////////////////////////////////////////////////////////////////////////////
286 /// FrameworkunifiedOnEvent
287 /// This function processes the event. If the reaction for event is available in the current
288 /// state within eventlist and deferred eventlist then it is consumed in the current state
289 /// otherwise forwarded to the parent state. Event forwarding is done recursively till either
290 /// event is consumed or the root state has encountered. This also process the events posted
291 /// in the reactions recursively till all posted events are cleared.
293 /// \param [in] f_pEventData
294 /// CEventDataPtr - Event data
298 /// CFrameworkunifiedState* - Returns current state after the event is processed
300 virtual CFrameworkunifiedState *FrameworkunifiedOnEvent(CEventDataPtr f_pEventData);
302 ///////////////////////////////////////////////////////////////////////////////////////////
303 /// \ingroup tag_CFrameworkunifiedOrthogonalState
304 /// \~english @par Brief
305 /// Logs the state name and event name.
306 /// \~english @retval eFrameworkunifiedStatusOK success
307 /// \~english @retval eFrameworkunifiedStatusNullPointer Specifying NULL pointers
308 /// \~english @par Prerequisite
309 /// - Its own instance (CFrameworkunifiedOrthogonalState) has been created.
310 /// - OrthogonalRegion (orthographic area) is registered in FrameworkunifiedAddOrthogonalRegion.
311 /// \~english @par Change of internal state
312 /// - The internal state is not changed.
313 /// \~english @par Conditions of processing failure
314 /// - If the pointers to the orthographic regions are NULL [eFrameworkunifiedStatusNullPointer]
315 /// \~english @par Detail
316 /// Size of the log output data
317 /// - State name of the parent state machine and the state name of the self-state machine
318 /// - All event names on the event list
319 /// - All event names on the deferred event list
320 /// \~english @par Classification
322 /// \~english @par Type
324 /// \~english @see CFrameworkunifiedCompositeState::FrameworkunifiedPrintStates
325 ///////////////////////////////////////////////////////////////////////////////////////////
326 ///////////////////////////////////////////////////////////////////////////////////////////
327 /// FrameworkunifiedPrintStates
328 /// This logs the state name and events associated with the state
330 /// \return EFrameworkunifiedStatus
331 /// EFrameworkunifiedStatus - Returns status of operation
332 ///////////////////////////////////////////////////////////////////////////////////////////
333 virtual EFrameworkunifiedStatus FrameworkunifiedPrintStates();
335 ///////////////////////////////////////////////////////////////////////////////////////////
336 /// \ingroup tag_CFrameworkunifiedOrthogonalState
337 /// \~english @par Brief
338 /// Get the active state.
339 /// \~english @retval Successful pointer to the active state
340 /// \~english @par Prerequisite
341 /// - Its own instance (CFrameworkunifiedOrthogonalState) has been created.
342 /// \~english @par Change of internal state
343 /// - The internal state is not changed.
344 /// \~english @par Conditions of processing failure
346 /// \~english @par Detail
347 /// In this class, the current state (this state) is always returned as the active state.
348 /// \~english @par Classification
350 /// \~english @par Type
352 /// \~english @see None
353 ///////////////////////////////////////////////////////////////////////////////////////////
354 ///////////////////////////////////////////////////////////////////////////////////////////
355 /// FrameworkunifiedGetActiveState
356 /// This interface returns the Active state of the current composite state. In case of
357 /// non-composite state current state is active state
359 /// \return Active state
360 /// CFrameworkunifiedState* - Active state
361 virtual CFrameworkunifiedState *FrameworkunifiedGetActiveState();
363 ///////////////////////////////////////////////////////////////////////////////////////////
364 /// \ingroup tag_CFrameworkunifiedOrthogonalState
365 /// \~english @par Brief
366 /// Associate the state machine with the current state.
367 /// \~english @param [in] f_pStatemachine
368 /// CFrameworkunifiedHSM* - Pointers to state machines (CFrameworkunifiedHSM classes)
369 /// \~english @retval eFrameworkunifiedStatusOK success
370 /// \~english @retval eFrameworkunifiedStatusNullPointer Specifiying NULL pointers
371 /// \~english @par Prerequisite
372 /// - Its own instance (CFrameworkunifiedOrthogonalState) has been created.
373 /// \~english @par Change of internal state
374 /// - The internal state is not changed.
375 /// \~english @par Conditions of processing failure
376 /// - When the pointers to the state machines (CFrameworkunifiedHSM classes) specified in the arguments (f_pStatemachine) are NULL
377 /// [eFrameworkunifiedStatusNullPointer]
378 /// \~english @par Detail
379 /// Associates a state machine with the current state by setting a pointer (f_pStatemachine) to the state machine (CFrameworkunifiedHSM) specified by the argument to the pointer to the state machine of the member variables.
380 /// \~english @par Classification
382 /// \~english @par Type
384 /// \~english @see CFrameworkunifiedCompositeState::FrameworkunifiedSetHSM
385 ///////////////////////////////////////////////////////////////////////////////////////////
386 ///////////////////////////////////////////////////////////////////////////////////////////
387 /// FrameworkunifiedSetHSM
388 /// This Interface associates the gives statemachine with the current state
390 /// \param [in] f_pStatemachine
391 /// CFrameworkunifiedHSM* - Statemachine associated with the state.
393 /// \return EFrameworkunifiedStatus
394 /// EFrameworkunifiedStatus - Returns status of operation
395 ///////////////////////////////////////////////////////////////////////////////////////////
396 virtual EFrameworkunifiedStatus FrameworkunifiedSetHSM(CFrameworkunifiedHSM *f_pStatemachine);
398 ///////////////////////////////////////////////////////////////////////////////////////////
399 /// \ingroup tag_CFrameworkunifiedOrthogonalState
400 /// \~english @par Brief
401 /// Outputs state information in the form of XML tags.
402 /// \~english @param [out] f_strXMLString
403 /// std::ostringstream& - Only kept in NPS
404 /// \~english @retval eFrameworkunifiedStatusOK success
405 /// \~english @retval eFrameworkunifiedStatusNullPointer Specifiying NULL pointers
406 /// \~english @par Prerequisite
407 /// - Its own instance (CFrameworkunifiedOrthogonalState) has been created.
408 /// - The State Machine for the current state of the application is set in the FrameworkunifiedSetHSM.
409 /// \~english @par Change of internal state
410 /// - The internal state is not changed.
411 /// \~english @par Conditions of processing failure
412 /// - If generating of own instance (CFrameworkunifiedOrthogonalState) failed, [eFrameworkunifiedStatusNullPointer]
413 /// \~english @par Detail
414 /// Outputs the following state information in XML tag format to the XML stream specified by the argument.
416 /// - All event information (event ID and event name) in the event list
417 /// - All event information (event ID and event name) in the deferred event list
418 /// \~english @par Classification
420 /// \~english @par Type
422 /// \~english @see CFrameworkunifiedCompositeState::FrameworkunifiedPrintXML
423 ///////////////////////////////////////////////////////////////////////////////////////////
424 ///////////////////////////////////////////////////////////////////////////////////////////
425 /// FrameworkunifiedPrintXML
426 /// Update the State information in the given stream in the form of XML tags
428 /// \param [in] f_strXMLString
429 /// std::ostringstream & - reference to the XML stream
431 /// \return EFrameworkunifiedStatus
432 /// EFrameworkunifiedStatus - Returns status of operation
433 ///////////////////////////////////////////////////////////////////////////////////////////
434 EFrameworkunifiedStatus FrameworkunifiedPrintXML(std::ostringstream &f_strXMLString);
436 ///////////////////////////////////////////////////////////////////////////////////////////
437 /// \ingroup tag_CFrameworkunifiedOrthogonalState
438 /// \~english @par Brief
439 /// Always returns eFrameworkunifiedStatusOK (Successful).
440 /// \~english @retval eFrameworkunifiedStatusOK success
441 /// \~english @par Prerequisite
442 /// - Its own instance (CFrameworkunifiedOrthogonalState) has been created.
443 /// \~english @par Change of internal state
444 /// - The internal state is not changed.
445 /// \~english @par Conditions of processing failure
447 /// \~english @par Detail
448 /// In this class, eFrameworkunifiedStatusOK is always returned because the class does not require the History feature.\n
449 /// The History feature holds the active state prior to preprocessing and
450 /// returns the inside state to the active state prior to processing after the processing is executed.
451 /// \~english @par Classification
453 /// \~english @par Type
456 ///////////////////////////////////////////////////////////////////////////////////////////
458 /// This function stores the last active state
460 /// \return EFrameworkunifiedStatus
461 /// EFrameworkunifiedStatus - Returns status of operation
462 EFrameworkunifiedStatus UpdateHistory();
466 ///////////////////////////////////////////////////////////////////////////////////////////
467 /// FrameworkunifiedOnEntry
468 /// state initialization can be performed in this function.
470 /// \param [in] f_pEventData
471 /// CEventDataPtr - Event data
473 /// \return EFrameworkunifiedStatus
474 /// EFrameworkunifiedStatus - Returns status of operation
475 ///////////////////////////////////////////////////////////////////////////////////////////
476 virtual EFrameworkunifiedStatus FrameworkunifiedOnEntry(CEventDataPtr f_pEventData);
478 ///////////////////////////////////////////////////////////////////////////////////////////
479 /// FrameworkunifiedOnExit
480 /// state cleanup can be performed in this function.
482 /// \param [in] f_pEventData
483 /// CEventDataPtr - Event data
485 /// \return EFrameworkunifiedStatus
486 /// EFrameworkunifiedStatus - Returns status of operation
487 ///////////////////////////////////////////////////////////////////////////////////////////
488 virtual EFrameworkunifiedStatus FrameworkunifiedOnExit(CEventDataPtr f_pEventData);
491 /// Pointer to the map that stores the pointer to Orthogonal region list
492 OrthogonalRegionList *m_pOrthogonalReigonList;
494 ///////////////////////////////////////////////////////////////////////////////////////////
495 /// IsOrthogonalChildState
496 /// Checks if the given state is a child of orthogonal region
498 /// \param [in] f_pChildState
499 /// CFrameworkunifiedState* - Child state pointer
501 /// \return TRUE/FASLE
502 /// BOOL - returns TRUE if the given state is child of orthogonal state
503 ///////////////////////////////////////////////////////////////////////////////////////////
504 BOOL IsOrthogonalChildState(CFrameworkunifiedState *f_pChildState);
507 #endif // _FRAMEWORKUNIFIEDORTHOGONALSTATE_H // NOLINT (build/header_guard)