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 public Macro definition that simplifies the statemachine implementation
23 ///////////////////////////////////////////////////////////////////////////////
26 * @file frameworkunified_sm_framework_types.h
27 * @brief \~english This File has public Macro definition that simplifies the statemachine implementation
30 /** @addtogroup BaseSystem
33 /** @addtogroup native_service
37 /** @addtogroup framework_unified
38 * @ingroup native_service
41 /** @addtogroup framework
42 * @ingroup framework_unified
45 /** @addtogroup statemachine
49 #ifndef __FRAMEWORKUNIFIED_NATIVESERVICES_NATIVESERVICES_INC_FRAMEWORK_STATEMACHINE_FRAMEWORKUNIFIED_FRAMEWORKUNIFIED_SM_FRAMEWORK_TYPES_H__ // NOLINT (build/header_guard)
50 #define __FRAMEWORKUNIFIED_NATIVESERVICES_NATIVESERVICES_INC_FRAMEWORK_STATEMACHINE_FRAMEWORKUNIFIED_FRAMEWORKUNIFIED_SM_FRAMEWORK_TYPES_H__
52 ///////////////////////////////////////////////////////////////////////////////////////////////////
54 ///////////////////////////////////////////////////////////////////////////////////////////////////
56 #include <native_service/frameworkunified_sm_leafstate.h>
57 #include <native_service/frameworkunified_sm_internaltransition.h>
58 #include <native_service/frameworkunified_sm_compositestate.h>
59 #include <native_service/frameworkunified_sm_eventfactory.h>
60 #include <native_service/frameworkunified_sm_externaltransition.h>
61 #include <native_service/frameworkunified_sm_localtransition.h>
62 #include <native_service/frameworkunified_sm_orthogonalstate.h>
63 #include <native_service/frameworkunified_sm_shallowhistorystate.h>
64 #include <native_service/frameworkunified_sm_deephistorystate.h>
65 #include <native_service/frameworkunified_sm_guard.h>
66 #include <native_service/frameworkunified_sm_conditionconnector.h>
67 #include <native_service/frameworkunified_sm_action.h>
68 #include <native_service/frameworkunified_sm_eventdata.h>
72 class CFrameworkunifiedState;
75 ///////////////////////////////////////////////////////////////////////////////////////////////////
76 /// Defines the null pointer exception
77 ///////////////////////////////////////////////////////////////////////////////////////////////////
78 class CNullPointerException: public std::exception {
79 virtual const char *what() const throw() {
80 return "Null pointer exception";
85 /// Macro to check pointer for null value and throw null pointer exception
86 #define CHKNULL(x) if (NULL == x) throw CNullPointerException();
88 #define SHALLOWHISTORYSTATE "ShallowHistory"
89 #define DEEPHISTORYSTATE "DeepHistory"
91 /// Defines the state machine class
92 #define DEFINE_STATEMACHINE(class_name) \
93 class C## class_name : public CFrameworkunifiedHSM{ \
96 virtual ~C## class_name(); \
97 EFrameworkunifiedStatus FrameworkunifiedCreate(PVOID f_pEventData = NULL); \
100 /// Defines the leafstate class that does not override entry and exit of base state
101 #define DEFINE_LEAFSTATE(class_name) \
102 class C## class_name : public CFrameworkunifiedLeafState { \
104 C## class_name(std::string f_pName):CFrameworkunifiedLeafState(f_pName) {} };
106 /// Defines the Composite state that does not override entry and exit of base state
107 #define DEFINE_COMPOSITESTATE(class_name) \
108 class C## class_name : public CFrameworkunifiedCompositeState { \
110 C## class_name(std::string f_pName):CFrameworkunifiedCompositeState(f_pName) {} };
112 /// Defines the Orthogonal state that does not override entry and exit of base state
113 #define DEFINE_ORTHOGONALSTATE(class_name) \
114 class C## class_name : public CFrameworkunifiedOrthogonalState { \
116 C## class_name(std::string f_pName):CFrameworkunifiedOrthogonalState(f_pName) {} };
119 ///////////////////////////////////////////////////////////////////////////////////////////
120 /// \ingroup StateMachine_Macro
121 /// \~english @par Brief
122 /// Macros that inherit CFrameworkunifiedLeafState classes.
123 /// \~english @param [in] class_name Class name
124 /// \~english @retval None
125 /// \~english @par Prerequisite
127 /// \~english @par Change of internal state
128 /// - The internal state is not changed.
129 /// \~english @par Conditions of processing failure
131 /// \~english @par Detail
132 /// Macros that inherit from CFrameworkunifiedLeafState classes and override the following methods:
133 /// The following overriding methods should be implemented by the user.
134 /// - FrameworkunifiedOnEntry
135 /// - FrameworkunifiedOnExit
136 /// \~english @par Classification
138 /// \~english @see None
139 ///////////////////////////////////////////////////////////////////////////////////////////
140 /// Defines the leafstate that overrides entry and exit of base state
141 #define DEFINE_LEAFSTATE_OVERRIDE(class_name) \
142 class C## class_name : public CFrameworkunifiedLeafState{ \
144 C## class_name(std::string f_pName); \
145 virtual ~C## class_name(); \
146 EFrameworkunifiedStatus FrameworkunifiedOnEntry(CEventDataPtr f_pEventData); \
147 EFrameworkunifiedStatus FrameworkunifiedOnExit(CEventDataPtr f_pEventData); \
150 ///////////////////////////////////////////////////////////////////////////////////////////
151 /// \ingroup StateMachine_Macro
152 /// \~english @par Brief
153 /// Macros that inherit CFrameworkunifiedCompositeState classes.
154 /// \~english @param [in] class_name Class name
155 /// \~english @retval None
156 /// \~english @par Prerequisite
158 /// \~english @par Change of internal state
159 /// - The internal state is not changed.
160 /// \~english @par Conditions of processing failure
162 /// \~english @par Detail
163 /// Macros that inherit from CFrameworkunifiedCompositeState classes and override the following methods:
164 /// The following overriding methods should be implemented by the user.
165 /// - FrameworkunifiedOnEntry
166 /// - FrameworkunifiedOnExit
167 /// \~english @par Classification
169 /// \~english @see None
170 ///////////////////////////////////////////////////////////////////////////////////////////
171 /// Defines the Composite state class that overrides entry and exit of base state
172 #define DEFINE_COMPOSITESTATE_OVERRIDE(class_name) \
173 class C## class_name : public CFrameworkunifiedCompositeState{ \
175 C## class_name(std::string f_pName); \
176 virtual ~C## class_name(); \
177 EFrameworkunifiedStatus FrameworkunifiedOnEntry(CEventDataPtr f_pEventData); \
178 EFrameworkunifiedStatus FrameworkunifiedOnExit(CEventDataPtr f_pEventData); \
181 ///////////////////////////////////////////////////////////////////////////////////////////
182 /// \ingroup StateMachine_Macro
183 /// \~english @par Brief
184 /// Macros that inherit CFrameworkunifiedOrthogonalState classes.
185 /// \~english @param [in] class_name Class name
186 /// \~english @retval None
187 /// \~english @par Prerequisite
189 /// \~english @par Change of internal state
190 /// - The internal state is not changed.
191 /// \~english @par Conditions of processing failure
193 /// \~english @par Detail
194 /// Macros that inherit from CFrameworkunifiedOrthogonalState classes and override the following methods:
195 /// The following overriding methods should be implemented by the user.
196 /// - FrameworkunifiedOnEntry
197 /// - FrameworkunifiedOnExit
198 /// \~english @par Classification
200 /// \~english @see None
201 ///////////////////////////////////////////////////////////////////////////////////////////
202 /// Defines the Orthogonal state that overrides entry and exit of base state
203 #define DEFINE_ORTHOGONALSTATE_OVERRIDE(class_name) \
204 class C## class_name : public CFrameworkunifiedOrthogonalState{ \
206 C## class_name(std::string f_pName); \
207 virtual ~C## class_name(); \
208 EFrameworkunifiedStatus FrameworkunifiedOnEntry(CEventDataPtr f_pEventData); \
209 EFrameworkunifiedStatus FrameworkunifiedOnExit(CEventDataPtr f_pEventData); \
212 ///////////////////////////////////////////////////////////////////////////////////////////
213 /// \ingroup StateMachine_Macro
214 /// \~english @par Brief
215 /// Macros that inherit CFrameworkunifiedInternalTransition classes.
216 /// \~english @param [in] class_name Class name
217 /// \~english @retval None
218 /// \~english @par Prerequisite
220 /// \~english @par Change of internal state
221 /// - The internal state is not changed.
222 /// \~english @par Conditions of processing failure
224 /// \~english @par Detail
225 /// Macros that inherit from CFrameworkunifiedInternalTransition classes and override the following methods:
226 /// The following overriding methods should be implemented by the user.
227 /// - FrameworkunifiedReaction
228 /// \~english @par Classification
230 /// \~english @see None
231 ///////////////////////////////////////////////////////////////////////////////////////////
232 /// Defines the InternalTransition class
233 #define DEFINE_INTERNALTRANSITION(class_name) \
234 class C## class_name : public CFrameworkunifiedInternalTransition{ \
236 virtual CFrameworkunifiedState* FrameworkunifiedReaction(CFrameworkunifiedState* f_pSourceState, CEventDataPtr f_pData); \
239 ///////////////////////////////////////////////////////////////////////////////////////////
240 /// \ingroup StateMachine_Macro
241 /// \~english @par Brief
242 /// Macros that define application events.
243 /// \~english @param [in] event_name Event name
244 /// \~english @param [in] value Event value
245 /// \~english @retval UI_32 Event value for the application
246 /// \~english @par Prerequisite
248 /// \~english @par Change of internal state
249 /// - The internal state is not changed.
250 /// \~english @par Conditions of processing failure
252 /// \~english @par Detail
253 /// Values of events defined in CFrameworkunifiedEventFactory classes (evFrameworkunifiedEventLimit:10) are specifiedMacros that define events for an application by adding event values (value).
254 /// \~english @par Classification
256 /// \~english @see None
257 ///////////////////////////////////////////////////////////////////////////////////////////
258 /// Defines the application event
259 #define DEFINE_EVENT(event_name, value) \
260 static const UI_32 _## event_name = CFrameworkunifiedEventFactory::evFrameworkunifiedEventLimit + value;
262 #define DEFINE_ACTION(class_name) \
263 class C## class_name: public CFrameworkunifiedAction{ \
265 C## class_name(std::string f_strName):CFrameworkunifiedAction(f_strName) {} \
266 VOID FrameworkunifiedAction(CFrameworkunifiedState *f_pSourceState, CFrameworkunifiedState *f_pTargetState, CEventDataPtr f_pEventData); \
269 ///////////////////////////////////////////////////////////////////////////////////////////
270 /// \ingroup StateMachine_Macro
271 /// \~english @par Brief
272 /// This macro creates an instance for an internal transition.
273 /// \~english @param [in] class_name Class name
274 /// \~english @retval None
275 /// \~english @par Prerequisite
277 /// \~english @par Change of internal state
278 /// - The internal state is not changed.
279 /// \~english @par Conditions of processing failure
281 /// \~english @par Detail
282 /// This macro creates an instance for an internal transition of a class with the specified name.\n
283 /// Otherwise, the CNullPointerException objects are excepted.
284 /// \~english @par Classification
286 /// \~english @see None
287 ///////////////////////////////////////////////////////////////////////////////////////////
288 /// creates the instance of the internal transition
289 #define CREATE_INTERNALTRANSITION(class_name) \
290 C## class_name *l_pTrn## class_name = new C## class_name(); \
291 CHKNULL(l_pTrn## class_name);
293 ///////////////////////////////////////////////////////////////////////////////////////////
294 /// \ingroup StateMachine_Macro
295 /// \~english @par Brief
296 /// This macro creates an instance for an external transition.
297 /// \~english @param [in] target_state State name for external transition
298 /// \~english @retval None
299 /// \~english @par Prerequisite
301 /// \~english @par Change of internal state
302 /// - The internal state is not changed.
303 /// \~english @par Conditions of processing failure
305 /// \~english @par Detail
306 /// Macros that instantiate CFrameworkunifiedExternalTransition classes for external transitions.\n
307 /// Otherwise, the CNullPointerException objects are excepted.
308 /// \~english @par Classification
310 /// \~english @see None
311 ///////////////////////////////////////////////////////////////////////////////////////////
312 /// creates the instance of the external transition
313 #define CREATE_EXTERNALTRANSITION(target_state) \
314 CFrameworkunifiedExternalTransition *l_pTrn## target_state = new CFrameworkunifiedExternalTransition(l_p## target_state); \
315 CHKNULL(l_pTrn## target_state);
317 /// creates the instance of the external transition
318 #define CREATE_CONDITIONCONNECTOR(connector_name) \
319 CFrameworkunifiedConditionConnector *l_pTrn## connector_name = new CFrameworkunifiedConditionConnector( #connector_name); \
320 CHKNULL(l_pTrn## connector_name);
323 /// creates the instance of the local transition
324 #define CREATE_LOCALTRANSITION(target_state) \
325 CFrameworkunifiedLocalTransition *l_pLocalTrn## target_state = new CFrameworkunifiedLocalTransition(l_p## target_state); \
326 CHKNULL(l_pLocalTrn## target_state);
328 ///////////////////////////////////////////////////////////////////////////////////////////
329 /// \ingroup StateMachine_Macro
330 /// \~english @par Brief
331 /// A macro that instantiates an orthographic region.
332 /// \~english @param [in] target_state State name for external transition
333 /// \~english @retval None
334 /// \~english @par Prerequisite
336 /// \~english @par Change of internal state
337 /// - The internal state is not changed.
338 /// \~english @par Conditions of processing failure
340 /// \~english @par Detail
341 /// Macros that create instances of compound states (CFrameworkunifiedCompositeState classes) as instances of orthographic regions.\n
342 /// \~english @par Classification
344 /// \~english @see None
345 ///////////////////////////////////////////////////////////////////////////////////////////
346 /// create orthogonal region
347 #define CREATE_ORTHOGONALREGION(name) \
348 CFrameworkunifiedCompositeState *l_p## name = new CFrameworkunifiedCompositeState(#name);
350 /// create action for external transition
351 #define CREATE_ACTION(class_name) \
352 C## class_name *l_pTrn## class_name = new C## class_name( #class_name); \
353 CHKNULL(l_pTrn## class_name);
356 ///////////////////////////////////////////////////////////////////////////////////////////
357 /// \ingroup StateMachine_Macro
358 /// \~english @par Brief
359 /// A macro that defines events for the framework.
360 /// \~english @param [in] eventid Event ID
361 /// \~english @retval None
362 /// \~english @par Prerequisite
364 /// \~english @par Change of internal state
365 /// - The internal state is not changed.
366 /// \~english @par Conditions of processing failure
368 /// \~english @par Detail
369 /// These macros define the IDs of the current events in the CFrameworkunifiedHSMParentFramework classes.
370 /// \~english @par Classification
372 /// \~english @see None
373 ///////////////////////////////////////////////////////////////////////////////////////////
375 #define FRAMEWORKUNIFIED_EVENT(eventid) \
376 CFrameworkunifiedHSMParentFramework::_## eventid
378 ///////////////////////////////////////////////////////////////////////////////////////////
379 /// \ingroup StateMachine_Macro
380 /// \~english @par Brief
381 /// Is a macro that defines events for an application
382 /// \~english @param [in] eventid Event ID
383 /// \~english @retval None
384 /// \~english @par Prerequisite
386 /// \~english @par Change of internal state
387 /// - The internal state is not changed.
388 /// \~english @par Conditions of processing failure
390 /// \~english @par Detail
391 /// A macro that defines an event ID for an application.
392 /// \~english @par Classification
394 /// \~english @see None
395 ///////////////////////////////////////////////////////////////////////////////////////////
396 /// Application event
397 #define EVENT(eventid) \
400 /// FrameworkunifiedReaction function signature for internal transition class
401 #define IMPLEMENT_INTERNALTRANSITION(name) \
402 CFrameworkunifiedState* C## name::FrameworkunifiedReaction(CFrameworkunifiedState* f_pSourceState, CEventDataPtr f_pData)
404 #define IMPLEMENT_ACTION(action_name) \
405 void C## action_name::FrameworkunifiedAction(CFrameworkunifiedState *f_pSourceState, CFrameworkunifiedState *f_pTargetState, CEventDataPtr f_pEventData)
407 #define DEFINE_GUARD(guard_name)\
408 class C## guard_name : public CFrameworkunifiedGuard{ \
410 C## guard_name(std::string f_pName):CFrameworkunifiedGuard(f_pName) {} \
411 virtual BOOL FrameworkunifiedEvaluate();\
414 #define CREATE_GUARD(guard_name)\
415 CFrameworkunifiedGuard *l_pGrd## guard_name = new C## guard_name(#guard_name);
417 #define CONNECT_GUARD(transition, guard)\
418 l_pTrn## transition->FrameworkunifiedSetGuard(l_pGrd## guard);
420 #define CONNECT_CONDITION(connector_name , guard , target_state) \
421 CHKNULL(l_pTrn## connector_name)\
422 l_pTrn## connector_name->FrameworkunifiedAddCondition(l_pGrd## guard , l_p## target_state); \
424 #define IMPLEMENT_GUARD(guard_name) \
425 BOOL C## guard_name::FrameworkunifiedEvaluate()
428 ///////////////////////////////////////////////////////////////////////////////////////////
429 /// \ingroup StateMachine_Macro
430 /// \~english @par Brief
431 /// These macros create instances for Shallow history transitions.
432 /// \~english @param [in] parent State name for external transition
433 /// \~english @retval None
434 /// \~english @par Prerequisite
436 /// \~english @par Change of internal state
437 /// - The internal state is not changed.
438 /// \~english @par Conditions of processing failure
440 /// \~english @par Detail
441 /// These macros create instances of CFrameworkunifiedExternalTransition classes for external transitions of Shallow history transitions.\n
442 /// Otherwise, the CNullPointerException objects are excepted.
443 /// \~english @par Classification
445 /// \~english @see None
446 ///////////////////////////////////////////////////////////////////////////////////////////
447 /// creates the instance of the shallow history transition
448 #define CREATE_SHALLOWHISTORYTRANSITION(parent) \
449 CFrameworkunifiedExternalTransition *l_pTrn##parent##SHALLOWHISTORYSTATE = \
450 new CFrameworkunifiedExternalTransition(l_p##parent##SHALLOWHISTORYSTATE); \
451 CHKNULL(l_pTrn##parent##SHALLOWHISTORYSTATE);
453 /// creates the instance of the deep history transition
454 #define CREATE_DEEPHISTORYTRANSITION(parent) \
455 CFrameworkunifiedExternalTransition *l_pTrn##parent##DEEPHISTORYSTATE = \
456 new CFrameworkunifiedExternalTransition(l_p##parent##DEEPHISTORYSTATE); \
457 CHKNULL(l_pTrn##parent##DEEPHISTORYSTATE);
459 #define CONNECT_CONDITION_SHALLOWHISTORYTRANSITION(connector_name , guard , target_state) \
460 CHKNULL(l_pTrn## connector_name)\
461 l_pTrn## connector_name->FrameworkunifiedAddCondition(l_pGrd## guard , l_p## target_state##SHALLOWHISTORYSTATE); \
464 #define CONNECT_CONDITION_DEEPHISTORYTRANSITION(connector_name , guard , target_state) \
465 CHKNULL(l_pTrn## connector_name)\
466 l_pTrn## connector_name->FrameworkunifiedAddCondition(l_pGrd## guard , l_p## target_state##DEEPHISTORYSTATE); \
469 #define CONNECT_ACTION(transition, action_name) \
470 CHKNULL(l_pTrn## action_name); \
471 CHKNULL(l_pTrn## transition); \
472 l_pTrn## transition->FrameworkunifiedAddAction(l_pTrn## action_name); \
475 #define FRAMEWORKUNIFIED_PRINT_HSM(x) (FrameworkunifiedGetStateMachine(x))->FrameworkunifiedPrintXML();
476 #define PRINT_HSM() FrameworkunifiedPrintXML();
478 #define FRAMEWORKUNIFIED_PRINT_HSM(x)
482 /// defines options for integrating user change state
483 typedef enum _EUserChangeOptions {
484 eUserchangeIgnore = 0,
486 eUserchangeRetPrevState
487 } EUserChangeOptions;
488 #endif /* __FRAMEWORKUNIFIED_NATIVESERVICES_NATIVESERVICES_INC_FRAMEWORK_STATEMACHINE_FRAMEWORKUNIFIED_FRAMEWORKUNIFIED_SM_FRAMEWORK_TYPES_H__ */ // NOLINT (build/header_guard)