summaryrefslogtreecommitdiffstats
path: root/nsframework/framework_unified/client/include/native_service/frameworkunified_sm_framework_types.h
blob: fb00ecd3298fd050c824c9def55d53b309e6af2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
/*
 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

///////////////////////////////////////////////////////////////////////////////
/// \ingroup  tag_StateMachine
/// \brief
///
/// This File has public Macro definition that simplifies the statemachine implementation
///
///////////////////////////////////////////////////////////////////////////////
//@{
/**
 * @file frameworkunified_sm_framework_types.h
 * @brief \~english This File has public Macro definition that simplifies the statemachine implementation
 *
 */
/** @addtogroup BaseSystem
 *  @{
 */
/** @addtogroup native_service
 *  @ingroup BaseSystem
 *  @{
 */
/** @addtogroup framework_unified
 *  @ingroup native_service
 *  @{
 */
/** @addtogroup framework
 *  @ingroup framework_unified
 *  @{
 */
/** @addtogroup statemachine
 *  @ingroup framework
 *  @{
 */
#ifndef __FRAMEWORKUNIFIED_NATIVESERVICES_NATIVESERVICES_INC_FRAMEWORK_STATEMACHINE_FRAMEWORKUNIFIED_FRAMEWORKUNIFIED_SM_FRAMEWORK_TYPES_H__  // NOLINT  (build/header_guard)
#define __FRAMEWORKUNIFIED_NATIVESERVICES_NATIVESERVICES_INC_FRAMEWORK_STATEMACHINE_FRAMEWORKUNIFIED_FRAMEWORKUNIFIED_SM_FRAMEWORK_TYPES_H__

///////////////////////////////////////////////////////////////////////////////////////////////////
// Include Files
///////////////////////////////////////////////////////////////////////////////////////////////////

#include <native_service/frameworkunified_sm_leafstate.h>
#include <native_service/frameworkunified_sm_internaltransition.h>
#include <native_service/frameworkunified_sm_compositestate.h>
#include <native_service/frameworkunified_sm_eventfactory.h>
#include <native_service/frameworkunified_sm_externaltransition.h>
#include <native_service/frameworkunified_sm_localtransition.h>
#include <native_service/frameworkunified_sm_orthogonalstate.h>
#include <native_service/frameworkunified_sm_shallowhistorystate.h>
#include <native_service/frameworkunified_sm_deephistorystate.h>
#include <native_service/frameworkunified_sm_guard.h>
#include <native_service/frameworkunified_sm_conditionconnector.h>
#include <native_service/frameworkunified_sm_action.h>
#include <native_service/frameworkunified_sm_eventdata.h>
#include <exception>
#include <string>

class CFrameworkunifiedState;


///////////////////////////////////////////////////////////////////////////////////////////////////
/// Defines the null pointer exception
///////////////////////////////////////////////////////////////////////////////////////////////////
class CNullPointerException: public std::exception {
  virtual const char *what() const throw() {
    return "Null pointer exception";
  }
};


/// Macro to check pointer for null value and throw null pointer exception
#define CHKNULL(x) if (NULL == x) throw CNullPointerException();

#define SHALLOWHISTORYSTATE   "ShallowHistory"
#define DEEPHISTORYSTATE    "DeepHistory"

/// Defines the state machine class
#define DEFINE_STATEMACHINE(class_name) \
    class C## class_name : public CFrameworkunifiedHSM{ \
     public: \
      C## class_name(); \
      virtual ~C## class_name(); \
      EFrameworkunifiedStatus FrameworkunifiedCreate(PVOID f_pEventData = NULL); \
    };

/// Defines the leafstate class that does not override entry and exit of base state
#define DEFINE_LEAFSTATE(class_name) \
    class C## class_name : public CFrameworkunifiedLeafState { \
     public: \
      C## class_name(std::string f_pName):CFrameworkunifiedLeafState(f_pName) {} };

/// Defines the Composite state that does not override entry and exit of base state
#define DEFINE_COMPOSITESTATE(class_name) \
    class C## class_name : public CFrameworkunifiedCompositeState { \
     public: \
      C## class_name(std::string f_pName):CFrameworkunifiedCompositeState(f_pName) {} };

/// Defines the Orthogonal state that does not override entry and exit of base state
#define DEFINE_ORTHOGONALSTATE(class_name) \
    class C## class_name : public CFrameworkunifiedOrthogonalState { \
     public: \
      C## class_name(std::string f_pName):CFrameworkunifiedOrthogonalState(f_pName) {} };


///////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup StateMachine_Macro
/// \~english @par Brief
///        Macros that inherit CFrameworkunifiedLeafState classes.
/// \~english @param [in] class_name Class name
/// \~english @retval None
/// \~english @par Prerequisite
///       - None
/// \~english @par Change of internal state
///       - The internal state is not changed.
/// \~english @par Conditions of processing failure
///       - None
/// \~english @par Detail
///       Macros that inherit from CFrameworkunifiedLeafState classes and override the following methods:
///       The following overriding methods should be implemented by the user.
///       - FrameworkunifiedOnEntry
///       - FrameworkunifiedOnExit
/// \~english @par Classification
///          Public
/// \~english @see  None
///////////////////////////////////////////////////////////////////////////////////////////
/// Defines the leafstate that overrides entry and exit of base state
#define DEFINE_LEAFSTATE_OVERRIDE(class_name) \
    class C## class_name : public CFrameworkunifiedLeafState{ \
     public: \
      C## class_name(std::string f_pName); \
      virtual ~C## class_name(); \
      EFrameworkunifiedStatus FrameworkunifiedOnEntry(CEventDataPtr f_pEventData); \
      EFrameworkunifiedStatus FrameworkunifiedOnExit(CEventDataPtr f_pEventData); \
    };

///////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup StateMachine_Macro
/// \~english @par Brief
///        Macros that inherit CFrameworkunifiedCompositeState classes.
/// \~english @param [in] class_name Class name
/// \~english @retval None
/// \~english @par Prerequisite
///       - None
/// \~english @par Change of internal state
///       - The internal state is not changed.
/// \~english @par Conditions of processing failure
///       - None
/// \~english @par Detail
///       Macros that inherit from CFrameworkunifiedCompositeState classes and override the following methods:
///       The following overriding methods should be implemented by the user.
///       - FrameworkunifiedOnEntry
///       - FrameworkunifiedOnExit
/// \~english @par Classification
///          Public
/// \~english @see  None
///////////////////////////////////////////////////////////////////////////////////////////
/// Defines the Composite state class that overrides entry and exit of base state
#define DEFINE_COMPOSITESTATE_OVERRIDE(class_name) \
    class C## class_name : public CFrameworkunifiedCompositeState{ \
     public: \
      C## class_name(std::string f_pName); \
      virtual ~C## class_name(); \
      EFrameworkunifiedStatus FrameworkunifiedOnEntry(CEventDataPtr f_pEventData); \
      EFrameworkunifiedStatus FrameworkunifiedOnExit(CEventDataPtr f_pEventData); \
    };

///////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup StateMachine_Macro
/// \~english @par Brief
///        Macros that inherit CFrameworkunifiedOrthogonalState classes.
/// \~english @param [in] class_name Class name
/// \~english @retval None
/// \~english @par Prerequisite
///       - None
/// \~english @par Change of internal state
///       - The internal state is not changed.
/// \~english @par Conditions of processing failure
///       - None
/// \~english @par Detail
///       Macros that inherit from CFrameworkunifiedOrthogonalState classes and override the following methods:
///       The following overriding methods should be implemented by the user.
///       - FrameworkunifiedOnEntry
///       - FrameworkunifiedOnExit
/// \~english @par Classification
///          Public
/// \~english @see  None
///////////////////////////////////////////////////////////////////////////////////////////
/// Defines the Orthogonal state that overrides entry and exit of base state
#define DEFINE_ORTHOGONALSTATE_OVERRIDE(class_name) \
    class C## class_name : public CFrameworkunifiedOrthogonalState{ \
     public: \
      C## class_name(std::string f_pName); \
      virtual ~C## class_name(); \
      EFrameworkunifiedStatus FrameworkunifiedOnEntry(CEventDataPtr f_pEventData); \
      EFrameworkunifiedStatus FrameworkunifiedOnExit(CEventDataPtr f_pEventData); \
    };

///////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup StateMachine_Macro
/// \~english @par Brief
///        Macros that inherit CFrameworkunifiedInternalTransition classes.
/// \~english @param [in] class_name Class name
/// \~english @retval None
/// \~english @par Prerequisite
///       - None
/// \~english @par Change of internal state
///       - The internal state is not changed.
/// \~english @par Conditions of processing failure
///       - None
/// \~english @par Detail
///       Macros that inherit from CFrameworkunifiedInternalTransition classes and override the following methods:
///       The following overriding methods should be implemented by the user.
///       - FrameworkunifiedReaction
/// \~english @par Classification
///          Public
/// \~english @see  None
///////////////////////////////////////////////////////////////////////////////////////////
/// Defines the InternalTransition class
#define DEFINE_INTERNALTRANSITION(class_name) \
    class C## class_name : public CFrameworkunifiedInternalTransition{ \
     public: \
        virtual CFrameworkunifiedState* FrameworkunifiedReaction(CFrameworkunifiedState* f_pSourceState, CEventDataPtr f_pData); \
    };

///////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup StateMachine_Macro
/// \~english @par Brief
///        Macros that define application events.
/// \~english @param [in] event_name Event name
/// \~english @param [in] value Event value
/// \~english @retval UI_32  Event value for the application
/// \~english @par Prerequisite
///       - None
/// \~english @par Change of internal state
///       - The internal state is not changed.
/// \~english @par Conditions of processing failure
///       - None
/// \~english @par Detail
///       Values of events defined in CFrameworkunifiedEventFactory classes (evFrameworkunifiedEventLimit:10) are specifiedMacros that define events for an application by adding event values (value).
/// \~english @par Classification
///          Public
/// \~english @see  None
///////////////////////////////////////////////////////////////////////////////////////////
/// Defines the application event
#define DEFINE_EVENT(event_name, value) \
    static const UI_32 _## event_name = CFrameworkunifiedEventFactory::evFrameworkunifiedEventLimit + value;

#define DEFINE_ACTION(class_name) \
    class C## class_name: public CFrameworkunifiedAction{ \
     public: \
        C## class_name(std::string f_strName):CFrameworkunifiedAction(f_strName) {} \
        VOID FrameworkunifiedAction(CFrameworkunifiedState *f_pSourceState, CFrameworkunifiedState *f_pTargetState, CEventDataPtr f_pEventData); \
    };

///////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup StateMachine_Macro
/// \~english @par Brief
///        This macro creates an instance for an internal transition.
/// \~english @param [in] class_name Class name
/// \~english @retval None
/// \~english @par Prerequisite
///       - None
/// \~english @par Change of internal state
///       - The internal state is not changed.
/// \~english @par Conditions of processing failure
///       - None
/// \~english @par Detail
///       This macro creates an instance for an internal transition of a class with the specified name.\n
///       Otherwise, the CNullPointerException objects are excepted.
/// \~english @par Classification
///          Public
/// \~english @see  None
///////////////////////////////////////////////////////////////////////////////////////////
/// creates the instance of the internal transition
#define CREATE_INTERNALTRANSITION(class_name) \
    C## class_name *l_pTrn## class_name = new C## class_name(); \
    CHKNULL(l_pTrn## class_name);

///////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup StateMachine_Macro
/// \~english @par Brief
///        This macro creates an instance for an external transition.
/// \~english @param [in] target_state State name for external transition
/// \~english @retval None
/// \~english @par Prerequisite
///       - None
/// \~english @par Change of internal state
///       - The internal state is not changed.
/// \~english @par Conditions of processing failure
///       - None
/// \~english @par Detail
///       Macros that instantiate CFrameworkunifiedExternalTransition classes for external transitions.\n
///       Otherwise, the CNullPointerException objects are excepted.
/// \~english @par Classification
///          Public
/// \~english @see  None
///////////////////////////////////////////////////////////////////////////////////////////
/// creates the instance of the external transition
#define CREATE_EXTERNALTRANSITION(target_state) \
    CFrameworkunifiedExternalTransition *l_pTrn## target_state  = new CFrameworkunifiedExternalTransition(l_p## target_state); \
    CHKNULL(l_pTrn## target_state);

/// creates the instance of the external transition
#define CREATE_CONDITIONCONNECTOR(connector_name) \
    CFrameworkunifiedConditionConnector *l_pTrn## connector_name = new CFrameworkunifiedConditionConnector( #connector_name); \
    CHKNULL(l_pTrn## connector_name);


/// creates the instance of the local transition
#define CREATE_LOCALTRANSITION(target_state) \
    CFrameworkunifiedLocalTransition *l_pLocalTrn## target_state  = new CFrameworkunifiedLocalTransition(l_p## target_state); \
    CHKNULL(l_pLocalTrn## target_state);

///////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup StateMachine_Macro
/// \~english @par Brief
///        A macro that instantiates an orthographic region.
/// \~english @param [in] target_state State name for external transition
/// \~english @retval None
/// \~english @par Prerequisite
///       - None
/// \~english @par Change of internal state
///       - The internal state is not changed.
/// \~english @par Conditions of processing failure
///       - None
/// \~english @par Detail
///       Macros that create instances of compound states (CFrameworkunifiedCompositeState classes) as instances of orthographic regions.\n
/// \~english @par Classification
///          Public
/// \~english @see  None
///////////////////////////////////////////////////////////////////////////////////////////
/// create orthogonal region
#define CREATE_ORTHOGONALREGION(name) \
    CFrameworkunifiedCompositeState *l_p## name = new CFrameworkunifiedCompositeState(#name);

/// create action for external transition
#define CREATE_ACTION(class_name) \
    C## class_name *l_pTrn## class_name = new C## class_name( #class_name); \
    CHKNULL(l_pTrn## class_name);


///////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup StateMachine_Macro
/// \~english @par Brief
///        A macro that defines events for the framework.
/// \~english @param [in] eventid Event ID
/// \~english @retval None
/// \~english @par Prerequisite
///       - None
/// \~english @par Change of internal state
///       - The internal state is not changed.
/// \~english @par Conditions of processing failure
///       - None
/// \~english @par Detail
///       These macros define the IDs of the current events in the CFrameworkunifiedHSMParentFramework classes.
/// \~english @par Classification
///          Public
/// \~english @see  None
///////////////////////////////////////////////////////////////////////////////////////////
/// framework event
#define FRAMEWORKUNIFIED_EVENT(eventid) \
    CFrameworkunifiedHSMParentFramework::_## eventid

///////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup StateMachine_Macro
/// \~english @par Brief
///        Is a macro that defines events for an application
/// \~english @param [in] eventid Event ID
/// \~english @retval None
/// \~english @par Prerequisite
///       - None
/// \~english @par Change of internal state
///       - The internal state is not changed.
/// \~english @par Conditions of processing failure
///       - None
/// \~english @par Detail
///       A macro that defines an event ID for an application.
/// \~english @par Classification
///          Public
/// \~english @see  None
///////////////////////////////////////////////////////////////////////////////////////////
/// Application event
#define EVENT(eventid) \
    _## eventid

/// FrameworkunifiedReaction function signature for internal transition class
#define IMPLEMENT_INTERNALTRANSITION(name) \
    CFrameworkunifiedState* C## name::FrameworkunifiedReaction(CFrameworkunifiedState* f_pSourceState, CEventDataPtr f_pData)

#define IMPLEMENT_ACTION(action_name) \
    void C## action_name::FrameworkunifiedAction(CFrameworkunifiedState *f_pSourceState, CFrameworkunifiedState *f_pTargetState, CEventDataPtr f_pEventData)

#define DEFINE_GUARD(guard_name)\
  class C## guard_name : public CFrameworkunifiedGuard{ \
   public: \
      C## guard_name(std::string f_pName):CFrameworkunifiedGuard(f_pName) {} \
      virtual BOOL FrameworkunifiedEvaluate();\
  };

#define CREATE_GUARD(guard_name)\
    CFrameworkunifiedGuard *l_pGrd## guard_name = new C## guard_name(#guard_name);

#define CONNECT_GUARD(transition, guard)\
  l_pTrn## transition->FrameworkunifiedSetGuard(l_pGrd## guard);

#define CONNECT_CONDITION(connector_name , guard , target_state) \
  CHKNULL(l_pTrn## connector_name)\
  l_pTrn## connector_name->FrameworkunifiedAddCondition(l_pGrd## guard , l_p## target_state); \

#define IMPLEMENT_GUARD(guard_name) \
  BOOL C## guard_name::FrameworkunifiedEvaluate()


///////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup StateMachine_Macro
/// \~english @par Brief
///        These macros create instances for Shallow history transitions.
/// \~english @param [in] parent State name for external transition
/// \~english @retval None
/// \~english @par Prerequisite
///       - None
/// \~english @par Change of internal state
///       - The internal state is not changed.
/// \~english @par Conditions of processing failure
///       - None
/// \~english @par Detail
///       These macros create instances of CFrameworkunifiedExternalTransition classes for external transitions of Shallow history transitions.\n
///       Otherwise, the CNullPointerException objects are excepted.
/// \~english @par Classification
///          Public
/// \~english @see  None
///////////////////////////////////////////////////////////////////////////////////////////
/// creates the instance of the shallow history transition
#define CREATE_SHALLOWHISTORYTRANSITION(parent) \
    CFrameworkunifiedExternalTransition *l_pTrn##parent##SHALLOWHISTORYSTATE = \
    new CFrameworkunifiedExternalTransition(l_p##parent##SHALLOWHISTORYSTATE); \
    CHKNULL(l_pTrn##parent##SHALLOWHISTORYSTATE);

/// creates the instance of the deep history transition
#define CREATE_DEEPHISTORYTRANSITION(parent) \
    CFrameworkunifiedExternalTransition *l_pTrn##parent##DEEPHISTORYSTATE = \
    new CFrameworkunifiedExternalTransition(l_p##parent##DEEPHISTORYSTATE); \
    CHKNULL(l_pTrn##parent##DEEPHISTORYSTATE);

#define CONNECT_CONDITION_SHALLOWHISTORYTRANSITION(connector_name , guard , target_state) \
    CHKNULL(l_pTrn## connector_name)\
    l_pTrn## connector_name->FrameworkunifiedAddCondition(l_pGrd## guard , l_p## target_state##SHALLOWHISTORYSTATE); \


#define CONNECT_CONDITION_DEEPHISTORYTRANSITION(connector_name , guard , target_state) \
    CHKNULL(l_pTrn## connector_name)\
    l_pTrn## connector_name->FrameworkunifiedAddCondition(l_pGrd## guard , l_p## target_state##DEEPHISTORYSTATE); \


#define CONNECT_ACTION(transition, action_name) \
    CHKNULL(l_pTrn## action_name); \
    CHKNULL(l_pTrn## transition); \
    l_pTrn## transition->FrameworkunifiedAddAction(l_pTrn## action_name); \

#ifdef DEBUG
#define FRAMEWORKUNIFIED_PRINT_HSM(x) (FrameworkunifiedGetStateMachine(x))->FrameworkunifiedPrintXML();
#define PRINT_HSM() FrameworkunifiedPrintXML();
#else
#define FRAMEWORKUNIFIED_PRINT_HSM(x)
#define PRINT_HSM()
#endif

/// defines options for integrating user change state
typedef enum _EUserChangeOptions {
  eUserchangeIgnore = 0,
  eUserchangeReInit,
  eUserchangeRetPrevState
} EUserChangeOptions;
#endif /* __FRAMEWORKUNIFIED_NATIVESERVICES_NATIVESERVICES_INC_FRAMEWORK_STATEMACHINE_FRAMEWORKUNIFIED_FRAMEWORKUNIFIED_SM_FRAMEWORK_TYPES_H__ */  // NOLINT  (build/header_guard)
/** @}*/
/** @}*/
/** @}*/
/** @}*/
/** @}*/
//@}