forked from QuantumLeaps/qpcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qpcpp.qm
14824 lines (13722 loc) · 578 KB
/
qpcpp.qm
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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?>
<model version="5.2.2" links="1">
<documentation>QP/C++ Real-Time Embedded Framework (RTEF)
The model is used to generate the whole QP/C++ source code.
Copyright (C) 2005 Quantum Leaps, LLC <state-machine.com>.
SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
This software is dual-licensed under the terms of the open source GNU
General Public License version 3 (or any later version), or alternatively,
under the terms of one of the closed source Quantum Leaps commercial
licenses.
The terms of the open source GNU General Public License version 3
can be found at: <www.gnu.org/licenses/gpl-3.0>
The terms of the closed source Quantum Leaps commercial licenses
can be found at: <www.state-machine.com/licensing>
Redistributions in source code must retain this copyright notice.
Plagiarizing this software to sidestep the license obligations is illegal.
Contact information:
<www.state-machine.com/licensing>
<info@state-machine.com></documentation>
<!--${qpcpp}-->
<framework name="qpcpp" license="LICENSES/LicenseRef-QL-dual.qlc"/>
<!--${glob-types}-->
<package name="glob-types" stereotype="0x00">
<!--${glob-types::int_t}-->
<attribute name="int_t" type="using" visibility="0x04" properties="0x00">
<documentation>//! alias for line numbers in assertions and return from QF::run()</documentation>
<code> = int;</code>
</attribute>
<!--${glob-types::enum_t}-->
<attribute name="enum_t" type="using" visibility="0x04" properties="0x00">
<documentation>//! alias for enumerations used for event signals</documentation>
<code> = int;</code>
</attribute>
<!--${glob-types::float32_t}-->
<attribute name="float32_t" type="using" visibility="0x04" properties="0x00">
<documentation>//! alias for 32-bit IEEE 754 floating point numbers
//!
//! @note
//! QP does not use floating-point types anywhere in the internal
//! implementation, except in QS software tracing, where utilities for
//! output of floating-point numbers are provided for application-specific
//! trace records.</documentation>
<code> = float;</code>
</attribute>
<!--${glob-types::float64_t}-->
<attribute name="float64_t" type="using" visibility="0x04" properties="0x00">
<documentation>//! alias for 64-bit IEEE 754 floating point numbers
//!
//! @note
//! QP does not use floating-point types anywhere in the internal
//! implementation, except in QS software tracing, where utilities for
//! output of floating-point numbers are provided for application-specific
//! trace records.</documentation>
<code> = double;</code>
</attribute>
</package>
<!--${QEP-config}-->
<package name="QEP-config" stereotype="0x02">
<!--${QEP-config::Q_SIGNAL_SIZE}-->
<attribute name="Q_SIGNAL_SIZE?ndef Q_SIGNAL_SIZE" type="" visibility="0x03" properties="0x00">
<documentation>//! The size (in bytes) of the signal of an event. Valid values:
//! 1U, 2U, or 4U; default 2U
//!
//! @details
//! This macro can be defined in the QEP port file (qep_port.hpp) to
//! configure the QP::QSignal type. When the macro is not defined, the
//! default of 2 bytes is applied.</documentation>
<code>2U</code>
</attribute>
</package>
<!--${QEP-macros}-->
<package name="QEP-macros" stereotype="0x02">
<!--${QEP-macros::Q_STATE_DECL}-->
<operation name="Q_STATE_DECL" type="" visibility="0x03" properties="0x00">
<documentation>//! Macro to generate a declaration of a state-handler, state-caller and
//! a state-object for a given state in a subclass of QP::QHsm.</documentation>
<!--${QEP-macros::Q_STATE_DECL::state_}-->
<parameter name="state_" type="<state name>"/>
<code>\
QP::QState state_ ## _h(QP::QEvt const * const e); \
static QP::QState state_(void * const me, QP::QEvt const * const e)</code>
</operation>
<!--${QEP-macros::Q_STATE_DEF}-->
<operation name="Q_STATE_DEF" type="" visibility="0x03" properties="0x00">
<documentation>//! Macro to generate a declaration of a state-handler, state-caller and
//! a state-object for a given state in a subclass of QP::QHsm.</documentation>
<!--${QEP-macros::Q_STATE_DEF::subclass_}-->
<parameter name="subclass_" type="<QHsm subclass>"/>
<!--${QEP-macros::Q_STATE_DEF::state_}-->
<parameter name="state_" type="<state name>"/>
<code>\
QP::QState subclass_::state_(void * const me, QP::QEvt const * const e) { \
return static_cast<subclass_ *>(me)->state_ ## _h(e); } \
QP::QState subclass_::state_ ## _h(QP::QEvt const * const e)</code>
</operation>
<!--${QEP-macros::Q_HANDLED}-->
<operation name="Q_HANDLED" type="" visibility="0x03" properties="0x00">
<documentation>//! Macro to specify that the event was handled</documentation>
<code>(Q_RET_HANDLED)</code>
</operation>
<!--${QEP-macros::Q_UNHANDLED}-->
<operation name="Q_UNHANDLED" type="" visibility="0x03" properties="0x00">
<documentation>//! Macro to specify that the event was NOT handled
//! due to a guard condition evaluating to 'false'</documentation>
<code>(Q_RET_UNHANDLED)</code>
</operation>
<!--${QEP-macros::Q_EVT_CAST}-->
<operation name="Q_EVT_CAST" type="" visibility="0x03" properties="0x00">
<documentation>//! Perform downcast of an event onto a subclass of QEvt `class_`
//!
//! @details
//! This macro encapsulates the downcast of QEvt pointers, which violates
//! MISRA-C 2004 rule 11.4(advisory). This macro helps to localize this
//! deviation.</documentation>
<!--${QEP-macros::Q_EVT_CAST::subclass_}-->
<parameter name="subclass_" type="<QEvt subclass>"/>
<code>(static_cast<subclass_ const *>(e))</code>
</operation>
<!--${QEP-macros::Q_STATE_CAST}-->
<operation name="Q_STATE_CAST" type="" visibility="0x03" properties="0x00">
<documentation>//! Macro to perform casting to QStateHandler.
//!
//! @details
//! This macro encapsulates the cast of a specific state handler function
//! pointer to QStateHandler, which violates MISRA-C 2004 rule 11.4(advisory).
//! This macro helps to localize this deviation.</documentation>
<!--${QEP-macros::Q_STATE_CAST::handler_}-->
<parameter name="handler_" type="<state handler>"/>
<code>\
(reinterpret_cast<QP::QStateHandler>(handler_))</code>
</operation>
<!--${QEP-macros::Q_ACTION_CAST}-->
<operation name="Q_ACTION_CAST" type="" visibility="0x03" properties="0x00">
<documentation>//! Macro to perform casting to QActionHandler.
//!
//! @details
//! This macro encapsulates the cast of a specific action handler function
//! pointer to QActionHandler, which violates MISRA-C2004 rule 11.4(advisory).
//! This macro helps to localize this deviation.</documentation>
<!--${QEP-macros::Q_ACTION_CAST::act_}-->
<parameter name="act_" type="<action handler>"/>
<code>\
(reinterpret_cast<QP::QActionHandler>(act_))</code>
</operation>
<!--${QEP-macros::QM_STATE_DECL}-->
<operation name="QM_STATE_DECL" type="" visibility="0x03" properties="0x00">
<documentation>//! Macro to generate a declaration of a state-handler, state-caller and
//! a state-object for a given state in a subclass of QP::QMsm.</documentation>
<!--${QEP-macros::QM_STATE_DECL::state_}-->
<parameter name="state_" type="<state name>"/>
<code>\
QP::QState state_ ## _h(QP::QEvt const * const e); \
static QP::QState state_(void * const me, QP::QEvt const * const e); \
static QP::QMState const state_ ## _s</code>
</operation>
<!--${QEP-macros::QM_SM_STATE_DECL}-->
<operation name="QM_SM_STATE_DECL" type="" visibility="0x03" properties="0x00">
<documentation>//! Macro to generate a declaration of a state-handler, state-caller and
//! a state-object for a given *submachine* state in a subclass of QP::QMsm.</documentation>
<!--${QEP-macros::QM_SM_STATE_DECL::subm_}-->
<parameter name="subm_" type="<submachine name>"/>
<!--${QEP-macros::QM_SM_STATE_DECL::state_}-->
<parameter name="state_" type="<state name>"/>
<code>\
QP::QState state_ ## _h(QP::QEvt const * const e);\
static QP::QState state_(void * const me, QP::QEvt const * const e); \
static SM_ ## subm_ const state_ ## _s</code>
</operation>
<!--${QEP-macros::QM_ACTION_DECL}-->
<operation name="QM_ACTION_DECL" type="" visibility="0x03" properties="0x00">
<documentation>//! Macro to generate a declaration of an action-handler and action-caller
//! in a subclass of QP::QMsm.</documentation>
<!--${QEP-macros::QM_ACTION_DECL::action_}-->
<parameter name="action_" type="<predefined>"/>
<code>\
QP::QState action_ ## _h(); \
static QP::QState action_(void * const me)</code>
</operation>
<!--${QEP-macros::QM_STATE_DEF}-->
<operation name="QM_STATE_DEF" type="" visibility="0x03" properties="0x00">
<documentation>//! Macro to generate a definition of a state-caller and state-handler
//! for a given state in a subclass of QP::QMsm.</documentation>
<!--${QEP-macros::QM_STATE_DEF::subclass_}-->
<parameter name="subclass_" type="<QMsm subclass>"/>
<!--${QEP-macros::QM_STATE_DEF::state_}-->
<parameter name="state_" type="<state name>"/>
<code>\
QP::QState subclass_::state_(void * const me, QP::QEvt const * const e) { \
return static_cast<subclass_ *>(me)->state_ ## _h(e); } \
QP::QState subclass_::state_ ## _h(QP::QEvt const * const e)</code>
</operation>
<!--${QEP-macros::QM_ACTION_DEF}-->
<operation name="QM_ACTION_DEF" type="" visibility="0x03" properties="0x00">
<documentation>//! Macro to generate a definition of an action-caller and action-handler
//! in a subclass of QP::QMsm.</documentation>
<!--${QEP-macros::QM_ACTION_DEF::subclass_}-->
<parameter name="subclass_" type="<QMsm subclass>"/>
<!--${QEP-macros::QM_ACTION_DEF::action_}-->
<parameter name="action_" type="<predefined>"/>
<code> \
QP::QState subclass_::action_(void * const me) { \
return static_cast<subclass_ *>(me)->action_ ## _h(); } \
QP::QState subclass_::action_ ## _h()</code>
</operation>
<!--${QEP-macros::QM_HANDLED}-->
<operation name="QM_HANDLED" type="" visibility="0x03" properties="0x00">
<documentation>//! Macro for a QM action-handler when it handles the event.</documentation>
<code>(Q_RET_HANDLED)</code>
</operation>
<!--${QEP-macros::QM_UNHANDLED}-->
<operation name="QM_UNHANDLED" type="" visibility="0x03" properties="0x00">
<documentation>//! Macro for a QM action-handler when it does not handle the event
//! due to a guard condition evaluating to false.</documentation>
<code>(Q_RET_HANDLED)</code>
</operation>
<!--${QEP-macros::QM_SUPER}-->
<operation name="QM_SUPER" type="" visibility="0x03" properties="0x00">
<documentation>//! Macro for a QM action-handler when it passes the event to the superstate</documentation>
<code>(Q_RET_SUPER)</code>
</operation>
<!--${QEP-macros::QM_STATE_NULL}-->
<attribute name="QM_STATE_NULL" type="<action handler>" visibility="0x03" properties="0x00">
<documentation>//! Macro to provide strictly-typed zero-state to use for submachines.
//! Applicable to suclasses of QP::QMsm.</documentation>
<code>(nullptr)</code>
</attribute>
<!--${QEP-macros::Q_ACTION_NULL}-->
<attribute name="Q_ACTION_NULL" type="<action handler>" visibility="0x03" properties="0x00">
<documentation>//! Macro to provide strictly-typed zero-action to terminate action lists
//! in the transition-action-tables in QP::QMsm.</documentation>
<code>(nullptr)</code>
</attribute>
<!--${QEP-macros::Q_UNUSED_PAR}-->
<operation name="Q_UNUSED_PAR" type="<param type>" visibility="0x03" properties="0x00">
<documentation>//! Helper macro to clearly mark unused parameters of functions.</documentation>
<!--${QEP-macros::Q_UNUSED_PAR::par_}-->
<parameter name="par_" type="<param type>"/>
<code>(static_cast<void>(par_))</code>
</operation>
<!--${QEP-macros::Q_DIM}-->
<operation name="Q_DIM" type="unsigned" visibility="0x03" properties="0x00">
<documentation>//! Helper macro to calculate static dimension of a 1-dim `array_`
//!
//! @param[in] array_ 1-dimensional array
//!
//! @returns
//! the length of the array (number of elements it can hold)</documentation>
<!--${QEP-macros::Q_DIM::array_}-->
<parameter name="array_" type="1-dimensional array"/>
<code>(sizeof(array_) / sizeof((array_)[0U]))</code>
</operation>
<!--${QEP-macros::Q_UINT2PTR_CAST}-->
<operation name="Q_UINT2PTR_CAST" type="" visibility="0x03" properties="0x00">
<documentation>//! Perform cast from unsigned integer `uint_` to pointer of type `type_`
//!
//! @details
//! This macro encapsulates the cast to (type_ *), which QP ports or
//! application might use to access embedded hardware registers.
//! Such uses can trigger PC-Lint "Note 923: cast from int to pointer"
//! and this macro helps to encapsulate this deviation.</documentation>
<!--${QEP-macros::Q_UINT2PTR_CAST::type_}-->
<parameter name="type_" type=""/>
<!--${QEP-macros::Q_UINT2PTR_CAST::uint_}-->
<parameter name="uint_" type=""/>
<code>(reinterpret_cast<type_ *>(uint_))</code>
</operation>
<!--${QEP-macros::QEVT_INITIALIZER}-->
<operation name="QEVT_INITIALIZER" type="" visibility="0x03" properties="0x00">
<documentation>//! Initializer of static constant QEvt instances
//!
//! @details
//! This macro encapsulates the ugly casting of enumerated signals
//! to QSignal and constants for QEvt.poolID and QEvt.refCtr_.</documentation>
<!--${QEP-macros::QEVT_INITIALIZER::sig_}-->
<parameter name="sig_" type="QSignal"/>
<code>{ static_cast<QP::QSignal>(sig_), 0U, 0U }</code>
</operation>
</package>
<!--${QEP}-->
<package name="QEP" stereotype="0x05" namespace="QP::">
<!--${QEP::versionStr[]}-->
<attribute name="versionStr[]" type="constexpr char const" visibility="0x04" properties="0x01">
<documentation>//! the current QP version number string based on QP_VERSION_STR</documentation>
<code>{QP_VERSION_STR};</code>
</attribute>
<!--${QEP::QSignal}-->
<attribute name="QSignal? (Q_SIGNAL_SIZE == 2U)" type="using" visibility="0x04" properties="0x00">
<documentation>//! QSignal represents the signal of an event
//!
//! @details
//! The relationship between an event and a signal is as follows. A signal
//! in UML is the specification of an asynchronous stimulus that triggers
//! reactions, and as such is an essential part of an event. (The signal
//! conveys the type of the occurrence--what happened?) However, an event
//! can also contain additional quantitative information about the
//! occurrence in form of event parameters.</documentation>
<code>= std::uint16_t;</code>
</attribute>
<!--${QEP::QSignal}-->
<attribute name="QSignal? (Q_SIGNAL_SIZE == 1U)" type="using" visibility="0x04" properties="0x00">
<code>= std::uint8_t;</code>
</attribute>
<!--${QEP::QSignal}-->
<attribute name="QSignal? (Q_SIGNAL_SIZE == 4U)" type="using" visibility="0x04" properties="0x00">
<code>= std::uint32_t;</code>
</attribute>
<!--${QEP::QEvt}-->
<class name="QEvt">
<documentation>//! Event class
//!
//! @details
//! QP::QEvt represents events without parameters and serves as the
//! base class for derivation of events with parameters.
//!
//! @note
//! When #Q_EVT_CTOR and #Q_EVT_VIRTUAL are NOT defined, the QP::QEvt is
//! a POD (Plain Old Data). Otherwise, it is a class with constructors
//! and virtual destructor.
//!
//! @usage
//! The following example illustrates how to add an event parameter by
//! inheriting from the QP::QEvt class.
//! @include qep_qevt.cpp</documentation>
<!--${QEP::QEvt::sig}-->
<attribute name="sig" type="QSignal" visibility="0x00" properties="0x00">
<documentation>//! signal of the event instance
//! @tr{RQP002}</documentation>
</attribute>
<!--${QEP::QEvt::poolId_}-->
<attribute name="poolId_" type="std::uint8_t" visibility="0x00" properties="0x00">
<documentation>//! pool ID (0 for static, immutable event)
//! @tr{RQP003}</documentation>
</attribute>
<!--${QEP::QEvt::refCtr_}-->
<attribute name="refCtr_" type="std::uint8_t volatile" visibility="0x00" properties="0x00">
<documentation>//! reference counter (only used for dynamic, mutable events)
//! @tr{RQP003}</documentation>
</attribute>
<!--${QEP::QEvt::QEvt}-->
<operation name="QEvt?def Q_EVT_CTOR" type="explicit" visibility="0x00" properties="0x02">
<specifiers>noexcept</specifiers>
<documentation>//! QP::QEvt constructor when the macro #Q_EVT_CTOR is defined</documentation>
<!--${QEP::QEvt::QEvt::s}-->
<parameter name="s" type="QSignal"/>
<code>: sig(s)
// poolId_/refCtr_ intentionally uninitialized</code>
</operation>
<!--${QEP::QEvt::QEvt}-->
<operation name="QEvt?def Q_EVT_CTOR" type="constexpr" visibility="0x00" properties="0x02">
<specifiers>noexcept</specifiers>
<documentation>//! QP::QEvt constructor (overload for static, immutable events)</documentation>
<!--${QEP::QEvt::QEvt::s}-->
<parameter name="s" type="QSignal"/>
<!--${QEP::QEvt::QEvt::/* dummy */}-->
<parameter name="/* dummy */" type="std::uint8_t"/>
<code>: sig(s),
poolId_(0U),
refCtr_(0U)</code>
</operation>
<!--${QEP::QEvt::~QEvt}-->
<operation name="~QEvt?def Q_EVT_VIRTUAL" type="" visibility="0x00" properties="0x06">
<specifiers>noexcept</specifiers>
<documentation>//! QP::QEvt virtual destructor when the macro #Q_EVT_VIRTUAL is defined</documentation>
<code>// empty</code>
</operation>
</class>
<!--${QEP::QState}-->
<attribute name="QState" type="using" visibility="0x04" properties="0x00">
<documentation>//! Type returned from state-handler functions</documentation>
<code>= std::uint_fast8_t;</code>
</attribute>
<!--${QEP::QStateHandler}-->
<attribute name="QStateHandler" type="using" visibility="0x04" properties="0x00">
<documentation>//! Pointer to state-handler function</documentation>
<code>= QState (*)(void * const me, QEvt const * const e);</code>
</attribute>
<!--${QEP::QActionHandler}-->
<attribute name="QActionHandler" type="using" visibility="0x04" properties="0x00">
<documentation>//! Pointer to an action-handler function</documentation>
<code>= QState (*)(void * const me);</code>
</attribute>
<!--${QEP::QXThread}-->
<attribute name="QXThread" type="class" visibility="0x04" properties="0x00">
<documentation>//! forward declaration</documentation>
</attribute>
<!--${QEP::QXThreadHandler}-->
<attribute name="QXThreadHandler" type="using" visibility="0x04" properties="0x00">
<documentation>//! Pointer to an extended thread-handler function</documentation>
<code>= void (*)(QXThread * const me);</code>
</attribute>
<!--${QEP::QMState}-->
<attribute name="QMState" type="struct" visibility="0x04" properties="0x00">
<documentation>//! State object for the QP::QMsm class (QM State Machine).
//!
//! @details
//! This class groups together the attributes of a QP::QMsm state, such as
//! the parent state (state nesting), the associated state handler function
//! and the exit action handler function. These attributes are used inside
//! the QP::QMsm::dispatch() and QP::QMsm::init() functions.
//!
//! @attention
//! The QP::QMState class is only intended for the QM code generator and
//! should not be used in hand-crafted code.</documentation>
<code>{
QMState const * superstate; //!< superstate of this state
QStateHandler const stateHandler; //!< state handler function
QActionHandler const entryAction; //!< entry action handler function
QActionHandler const exitAction; //!< exit action handler function
QActionHandler const initAction; //!< init action handler function
};</code>
</attribute>
<!--${QEP::QMTranActTable}-->
<attribute name="QMTranActTable" type="struct" visibility="0x04" properties="0x00">
<documentation>//! Transition-Action Table for the QP::QMsm State Machine.</documentation>
<code>{
QMState const * target; //!< target of the transition
QActionHandler const act[1]; //!< array of actions
};</code>
</attribute>
<!--${QEP::QHsmAttr}-->
<attribute name="QHsmAttr" type="union" visibility="0x04" properties="0x00">
<documentation>//! Attribute of for the QP::QHsm class (Hierarchical State Machine)
//!
//! @details
//! This union represents possible values stored in the 'state' and 'temp'
//! attributes of the QP::QHsm class.</documentation>
<code>{
QStateHandler fun; //!< pointer to a state handler function
QActionHandler act; //!< pointer to an action-handler function
QXThreadHandler thr; //!< pointer to an thread-handler function
QMState const *obj; //!< pointer to QMState object
QMTranActTable const *tatbl; //!< transition-action table
};</code>
</attribute>
<!--${QEP::Q_USER_SIG}-->
<attribute name="Q_USER_SIG" type="constexpr enum_t " visibility="0x04" properties="0x00">
<documentation>//! Type returned from state-handler functions</documentation>
<code>{4};</code>
</attribute>
<!--${QEP::QHsm}-->
<class name="QHsm">
<documentation>//! Hierarchical State Machine abstract base class (ABC)
//!
//! @details
//! QP::QHsm represents a Hierarchical State Machine (HSM) with full support
//! for hierarchical nesting of states, entry/exit actions, and initial
//! transitions in any composite state. QHsm inherits QP::QMsm without adding
//! new attributes, so it takes the same amount of RAM as QP::QMsm.<br>
//!
//! QP::QHsm is also the base class for the QP::QMsm state machine, which
//! provides better efficiency, but requires the use of the QM modeling tool
//! to generate code.
//!
//! @note
//! QP::QHsm is not intended to be instantiated directly, but rather serves as
//! the base class for derivation of state machines in the application code.
//!
//! @usage
//! The following example illustrates how to derive a state machine class
//! from QP::QHsm.
//! @include qep_qhsm.cpp</documentation>
<!--${QEP::QHsm::m_state}-->
<attribute name="m_state" type="QHsmAttr" visibility="0x02" properties="0x00">
<documentation>//! current active state (the state-variable)</documentation>
</attribute>
<!--${QEP::QHsm::m_temp}-->
<attribute name="m_temp" type="QHsmAttr" visibility="0x02" properties="0x00">
<documentation>//! temporary: transition chain, target state, etc.</documentation>
</attribute>
<!--${QEP::QHsm::MAX_NEST_DEPTH_}-->
<attribute name="MAX_NEST_DEPTH_" type="static constexpr std::int_fast8_t" visibility="0x04" properties="0x01">
<documentation>//! Maximum nesting depth of states in HSM</documentation>
<code>{6};</code>
</attribute>
<!--${QEP::QHsm::QMsm}-->
<attribute name="QMsm" type="friend class" visibility="0x02" properties="0x00">
<documentation>// friends...</documentation>
</attribute>
<!--${QEP::QHsm::QActive}-->
<attribute name="QActive" type="friend class" visibility="0x02" properties="0x00"/>
<!--${QEP::QHsm::QMActive}-->
<attribute name="QMActive" type="friend class" visibility="0x02" properties="0x00"/>
<!--${QEP::QHsm::QXThread}-->
<attribute name="QXThread" type="friend class" visibility="0x02" properties="0x00"/>
<!--${QEP::QHsm::QXMutex}-->
<attribute name="QXMutex" type="friend class" visibility="0x02" properties="0x00"/>
<!--${QEP::QHsm::QXSemaphore}-->
<attribute name="QXSemaphore" type="friend class" visibility="0x02" properties="0x00"/>
<!--${QEP::QHsm::QHsmDummy}-->
<attribute name="QHsmDummy?def Q_UTEST" type="friend class" visibility="0x02" properties="0x00"/>
<!--${QEP::QHsm::QActiveDummy}-->
<attribute name="QActiveDummy?def Q_UTEST" type="friend class" visibility="0x02" properties="0x00"/>
<!--${QEP::QHsm::ReservedHsmSignals}-->
<attribute name="ReservedHsmSignals" type="enum" visibility="0x04" properties="0x01">
<documentation>//! Reserved signals by the HSM-style state machine
//! implementation strategy.</documentation>
<code> : QSignal {
Q_ENTRY_SIG = 1U, //!< signal for entry actions
Q_EXIT_SIG, //!< signal for exit actions
Q_INIT_SIG //!< signal for nested initial transitions
};</code>
</attribute>
<!--${QEP::QHsm::QStateRet}-->
<attribute name="QStateRet" type="enum" visibility="0x04" properties="0x01">
<documentation>//! All possible return values from state-handlers</documentation>
<code> : std::uint_fast8_t {
// unhandled and need to "bubble up"
Q_RET_SUPER, //!< event passed to superstate to handle
Q_RET_SUPER_SUB, //!< event passed to submachine superstate
Q_RET_UNHANDLED, //!< event unhandled due to a guard
// handled and do not need to "bubble up"
Q_RET_HANDLED, //!< event handled (internal transition)
Q_RET_IGNORED, //!< event silently ignored (bubbled up to top)
// entry/exit
Q_RET_ENTRY, //!< state entry action executed
Q_RET_EXIT, //!< state exit action executed
// no side effects
Q_RET_NULL, //!< return value without any effect
// transitions need to execute transition-action table in QP::QMsm
Q_RET_TRAN, //!< regular transition
Q_RET_TRAN_INIT, //!< initial transition in a state or submachine
Q_RET_TRAN_EP, //!< entry-point transition into a submachine
// transitions that additionally clobber QHsm.m_state
Q_RET_TRAN_HIST, //!< transition to history of a given state
Q_RET_TRAN_XP //!< exit-point transition out of a submachine
};</code>
</attribute>
<!--${QEP::QHsm::QHsm}-->
<operation name="QHsm" type="explicit" visibility="0x01" properties="0x00">
<specifiers>noexcept</specifiers>
<documentation>//! protected constructor of QHsm</documentation>
<!--${QEP::QHsm::QHsm::initial}-->
<parameter name="initial" type="QStateHandler const"/>
<code>m_state.fun = Q_STATE_CAST(&top);
m_temp.fun = initial;</code>
</operation>
<!--${QEP::QHsm::~QHsm}-->
<operation name="~QHsm?def Q_HSM_XTOR" type="" visibility="0x00" properties="0x06">
<specifiers>noexcept</specifiers>
<documentation>//! virtual destructor</documentation>
<code>// empty</code>
</operation>
<!--${QEP::QHsm::init}-->
<operation name="init" type="void" visibility="0x00" properties="0x04">
<documentation>//! Executes the top-most initial transition in QP::QHsm
//!
//! @details
//! Executes the top-most initial transition in a HSM.
//!
//! @param[in] e pointer to an extra parameter (might be NULL)
//! @param[in] qs_id QS-id of this state machine (for QS local filter)
//!
//! @note
//! Must be called exactly __once__ before the QP::QHsm::dispatch().
//!
//! @tr{RQP103} @tr{RQP120I} @tr{RQP120D}</documentation>
<!--${QEP::QHsm::init::e}-->
<parameter name="e" type="void const * const"/>
<!--${QEP::QHsm::init::qs_id}-->
<parameter name="qs_id" type="std::uint_fast8_t const"/>
<code>Q_UNUSED_PAR(qs_id); // when Q_SPY not defined
QStateHandler t = m_state.fun;
//! @pre ctor must have been executed and initial tran NOT taken
Q_REQUIRE_ID(200, (m_temp.fun != nullptr)
&& (t == Q_STATE_CAST(&top)));
// execute the top-most initial transition
QState r = (*m_temp.fun)(this, Q_EVT_CAST(QEvt));
// the top-most initial transition must be taken
Q_ASSERT_ID(210, r == Q_RET_TRAN);
QS_CRIT_STAT_
QS_BEGIN_PRE_(QS_QEP_STATE_INIT, qs_id)
QS_OBJ_PRE_(this); // this state machine object
QS_FUN_PRE_(t); // the source state
QS_FUN_PRE_(m_temp.fun); // the target of the initial transition
QS_END_PRE_()
// drill down into the state hierarchy with initial transitions...
do {
QStateHandler path[MAX_NEST_DEPTH_]; // tran entry path array
std::int_fast8_t ip = 0; // entry path index
path[0] = m_temp.fun;
QEP_TRIG_(m_temp.fun, QEP_EMPTY_SIG_);
while (m_temp.fun != t) {
++ip;
Q_ASSERT_ID(220, ip < MAX_NEST_DEPTH_);
path[ip] = m_temp.fun;
QEP_TRIG_(m_temp.fun, QEP_EMPTY_SIG_);
}
m_temp.fun = path[0];
// retrace the entry path in reverse (desired) order...
do {
QEP_ENTER_(path[ip]); // enter path[ip]
--ip;
} while (ip >= 0);
t = path[0]; // current state becomes the new source
r = QEP_TRIG_(t, Q_INIT_SIG); // execute initial transition
#ifdef Q_SPY
if (r == Q_RET_TRAN) {
QS_BEGIN_PRE_(QS_QEP_STATE_INIT, qs_id)
QS_OBJ_PRE_(this); // this state machine object
QS_FUN_PRE_(t); // the source state
QS_FUN_PRE_(m_temp.fun); // the target of the initial tran.
QS_END_PRE_()
}
#endif // Q_SPY
} while (r == Q_RET_TRAN);
QS_BEGIN_PRE_(QS_QEP_INIT_TRAN, qs_id)
QS_TIME_PRE_(); // time stamp
QS_OBJ_PRE_(this); // this state machine object
QS_FUN_PRE_(t); // the new active state
QS_END_PRE_()
m_state.fun = t; // change the current active state
m_temp.fun = t; // mark the configuration as stable</code>
</operation>
<!--${QEP::QHsm::init}-->
<operation name="init" type="void" visibility="0x00" properties="0x06">
<documentation>//! overloaded init(qs_id)
//!
//! @details
//! Executes the top-most initial transition in a HSM (overloaded).
//!
//! @param[in] qs_id QS-id of this state machine (for QS local filter)
//!
//! @attention
//! QHsm::init() must be called exactly **once** before
//! QHsm::dispatch()</documentation>
<!--${QEP::QHsm::init::qs_id}-->
<parameter name="qs_id" type="std::uint_fast8_t const"/>
<code>init(nullptr, qs_id);</code>
</operation>
<!--${QEP::QHsm::dispatch}-->
<operation name="dispatch" type="void" visibility="0x00" properties="0x04">
<documentation>//! Dispatches an event to QP::QHsm
//!
//! @details
//! Dispatches an event for processing to a hierarchical state machine.
//! The event dispatching represents one run-to-completion (RTC) step.
//!
//! @param[in] e pointer to the event to be dispatched to the HSM
//! @param[in] qs_id QS-id of this state machine (for QS local filter)
//!
//! @attention
//! This state machine must be initialized by calling QP::QHsm::init()
//! exactly **once** before calling QP::QHsm::dispatch().
//!
//! @tr{RQP103}
//! @tr{RQP120A} @tr{RQP120B} @tr{RQP120C} @tr{RQP120D} @tr{RQP120E}</documentation>
<!--${QEP::QHsm::dispatch::e}-->
<parameter name="e" type="QEvt const * const"/>
<!--${QEP::QHsm::dispatch::qs_id}-->
<parameter name="qs_id" type="std::uint_fast8_t const"/>
<code>QStateHandler t = m_state.fun;
QS_CRIT_STAT_
//! @pre the current state must be initialized and
//! the state configuration must be stable
Q_REQUIRE_ID(400, (t != nullptr)
&& (t == m_temp.fun));
QS_BEGIN_PRE_(QS_QEP_DISPATCH, qs_id)
QS_TIME_PRE_(); // time stamp
QS_SIG_PRE_(e->sig); // the signal of the event
QS_OBJ_PRE_(this); // this state machine object
QS_FUN_PRE_(t); // the current state
QS_END_PRE_()
QStateHandler s;
QState r;
// process the event hierarchically...
//! @tr{RQP120A}
do {
s = m_temp.fun;
r = (*s)(this, e); // invoke state handler s
if (r == Q_RET_UNHANDLED) { // unhandled due to a guard?
QS_BEGIN_PRE_(QS_QEP_UNHANDLED, qs_id)
QS_SIG_PRE_(e->sig); // the signal of the event
QS_OBJ_PRE_(this); // this state machine object
QS_FUN_PRE_(s); // the current state
QS_END_PRE_()
r = QEP_TRIG_(s, QEP_EMPTY_SIG_); // find superstate of s
}
} while (r == Q_RET_SUPER);
// regular transition taken?
//! @tr{RQP120E}
if (r >= Q_RET_TRAN) {
QStateHandler path[MAX_NEST_DEPTH_];
path[0] = m_temp.fun; // save the target of the transition
path[1] = t;
path[2] = s;
// exit current state to transition source s...
//! @tr{RQP120C}
for (; t != s; t = m_temp.fun) {
// exit handled?
if (QEP_TRIG_(t, Q_EXIT_SIG) == Q_RET_HANDLED) {
QS_BEGIN_PRE_(QS_QEP_STATE_EXIT, qs_id)
QS_OBJ_PRE_(this); // this state machine object
QS_FUN_PRE_(t); // the exited state
QS_END_PRE_()
// find superstate of t
QEP_TRIG_(t, QEP_EMPTY_SIG_);
}
}
std::int_fast8_t ip = hsm_tran(path, qs_id); // the HSM transition
#ifdef Q_SPY
if (r == Q_RET_TRAN_HIST) {
QS_BEGIN_PRE_(QS_QEP_TRAN_HIST, qs_id)
QS_OBJ_PRE_(this); // this state machine object
QS_FUN_PRE_(t); // the source of the transition
QS_FUN_PRE_(path[0]); // the target of the tran. to history
QS_END_PRE_()
}
#endif // Q_SPY
// execute state entry actions in the desired order...
//! @tr{RQP120B}
for (; ip >= 0; --ip) {
QEP_ENTER_(path[ip]); // enter path[ip]
}
t = path[0]; // stick the target into register
m_temp.fun = t; // update the next state
// drill into the target hierarchy...
//! @tr{RQP120I}
while (QEP_TRIG_(t, Q_INIT_SIG) == Q_RET_TRAN) {
QS_BEGIN_PRE_(QS_QEP_STATE_INIT, qs_id)
QS_OBJ_PRE_(this); // this state machine object
QS_FUN_PRE_(t); // the source (pseudo)state
QS_FUN_PRE_(m_temp.fun); // the target of the transition
QS_END_PRE_()
ip = 0;
path[0] = m_temp.fun;
// find superstate
QEP_TRIG_(m_temp.fun, QEP_EMPTY_SIG_);
while (m_temp.fun != t) {
++ip;
path[ip] = m_temp.fun;
// find superstate
QEP_TRIG_(m_temp.fun, QEP_EMPTY_SIG_);
}
m_temp.fun = path[0];
// entry path must not overflow
Q_ASSERT_ID(410, ip < MAX_NEST_DEPTH_);
// retrace the entry path in reverse (correct) order...
do {
QEP_ENTER_(path[ip]); // enter path[ip]
--ip;
} while (ip >= 0);
t = path[0];
}
QS_BEGIN_PRE_(QS_QEP_TRAN, qs_id)
QS_TIME_PRE_(); // time stamp
QS_SIG_PRE_(e->sig); // the signal of the event
QS_OBJ_PRE_(this); // this state machine object
QS_FUN_PRE_(s); // the source of the transition
QS_FUN_PRE_(t); // the new active state
QS_END_PRE_()
}
#ifdef Q_SPY
else if (r == Q_RET_HANDLED) {
QS_BEGIN_PRE_(QS_QEP_INTERN_TRAN, qs_id)
QS_TIME_PRE_(); // time stamp
QS_SIG_PRE_(e->sig); // the signal of the event
QS_OBJ_PRE_(this); // this state machine object
QS_FUN_PRE_(s); // the source state
QS_END_PRE_()
}
else {
QS_BEGIN_PRE_(QS_QEP_IGNORED, qs_id)
QS_TIME_PRE_(); // time stamp
QS_SIG_PRE_(e->sig); // the signal of the event
QS_OBJ_PRE_(this); // this state machine object
QS_FUN_PRE_(m_state.fun);// the current state
QS_END_PRE_()
}
#else
Q_UNUSED_PAR(qs_id); // when Q_SPY not defined
#endif // Q_SPY
m_state.fun = t; // change the current active state
m_temp.fun = t; // mark the configuration as stable</code>
</operation>
<!--${QEP::QHsm::top}-->
<operation name="top" type="QState" visibility="0x00" properties="0x01">
<specifiers>noexcept</specifiers>
<documentation>//! The top-state handler
//!
//! @details
//! The QHsm::top() state handler is the ultimate root of state
//! hierarchy in all HSMs derived from QP::QHsm.
//!
//! @param[in] me pointer to the HSM instance
//! @param[in] e pointer to the event to be dispatched to the HSM
//!
//! @returns
//! Always returns #Q_RET_IGNORED, which means that the top state ignores
//! all events.
//!
//! @note
//! The parameters to this state handler are not used. They are provided
//! for conformance with the state-handler function signature
//! QP::QStateHandler.
//!
//! @tr{RQP103} @tr{RQP120T}</documentation>
<!--${QEP::QHsm::top::me}-->
<parameter name="me" type="void * const"/>
<!--${QEP::QHsm::top::e}-->
<parameter name="e" type="QEvt const * const"/>
<code>Q_UNUSED_PAR(me);
Q_UNUSED_PAR(e);
return Q_RET_IGNORED; // the top state ignores all events</code>
</operation>
<!--${QEP::QHsm::state}-->
<operation name="state" type="QStateHandler" visibility="0x00" properties="0x02">
<specifiers>const noexcept</specifiers>
<documentation>//! Obtain the current state (state handler function)
//!
//! @note used in the QM code generation</documentation>
<code>return m_state.fun;</code>
</operation>
<!--${QEP::QHsm::getStateHandler}-->
<operation name="getStateHandler?def Q_SPY" type="QStateHandler" visibility="0x00" properties="0x06">
<specifiers>noexcept</specifiers>
<documentation>//! Get the current state handler of the QP::QHsm</documentation>
<code>return m_state.fun;</code>
</operation>
<!--${QEP::QHsm::isIn}-->
<operation name="isIn" type="bool" visibility="0x00" properties="0x00">
<specifiers>noexcept</specifiers>
<documentation>//! Tests if a given state is part of the current active state
//! configuration
//!
//! @details
//! Tests if a state machine derived from QHsm is-in a given state.
//!
//! @note
//! For a HSM, to "be in a state" means also to be in a superstate of
//! of the state.
//!
//! @param[in] s pointer to the state-handler function to be tested
//!
//! @returns
//! 'true' if the HSM is in the `state` and 'false' otherwise
//!
//! @tr{RQP103}
//! @tr{RQP120S}</documentation>
<!--${QEP::QHsm::isIn::s}-->
<parameter name="s" type="QStateHandler const"/>
<code>//! @pre state configuration must be stable
Q_REQUIRE_ID(600, m_temp.fun == m_state.fun);
bool inState = false; // assume that this HSM is not in 'state'
// scan the state hierarchy bottom-up
QState r;
do {
// do the states match?
if (m_temp.fun == s) {
inState = true; // 'true' means that match found
r = Q_RET_IGNORED; // cause breaking out of the loop
}
else {
r = QEP_TRIG_(m_temp.fun, QEP_EMPTY_SIG_);
}
} while (r != Q_RET_IGNORED); // QHsm::top() state not reached
m_temp.fun = m_state.fun; // restore the stable state configuration
return inState; // return the status</code>
</operation>
<!--${QEP::QHsm::childState}-->
<operation name="childState" type="QStateHandler" visibility="0x00" properties="0x00">
<specifiers>noexcept</specifiers>
<documentation>//! Obtain the current active child state of a given parent
//!
//! @note used in the QM code generation</documentation>
<!--${QEP::QHsm::childState::parent}-->
<parameter name="parent" type="QStateHandler const"/>
<code>QStateHandler child = m_state.fun; // start with the current state
bool isFound = false; // start with the child not found
// establish stable state configuration
m_temp.fun = m_state.fun;
QState r;
do {
// is this the parent of the current child?
if (m_temp.fun == parent) {
isFound = true; // child is found
r = Q_RET_IGNORED; // cause breaking out of the loop
}
else {
child = m_temp.fun;
r = QEP_TRIG_(m_temp.fun, QEP_EMPTY_SIG_);
}
} while (r != Q_RET_IGNORED); // QHsm::top() state not reached
m_temp.fun = m_state.fun; // establish stable state configuration
//! @post the child must be confirmed
Q_ENSURE_ID(810, isFound);
#ifdef Q_NASSERT
Q_UNUSED_PAR(isFound);
#endif
return child; // return the child</code>
</operation>
<!--${QEP::QHsm::tran}-->
<operation name="tran" type="QState" visibility="0x01" properties="0x02">
<specifiers>noexcept</specifiers>
<documentation>//! Helper function to specify a state transition</documentation>
<!--${QEP::QHsm::tran::target}-->
<parameter name="target" type="QStateHandler const"/>
<code>m_temp.fun = target;
return Q_RET_TRAN;</code>
</operation>
<!--${QEP::QHsm::tran_hist}-->
<operation name="tran_hist" type="QState" visibility="0x01" properties="0x02">
<specifiers>noexcept</specifiers>
<documentation>//! Helper function to specify a transition to history</documentation>
<!--${QEP::QHsm::tran_hist::hist}-->
<parameter name="hist" type="QStateHandler const"/>
<code>m_temp.fun = hist;
return Q_RET_TRAN_HIST;</code>
</operation>
<!--${QEP::QHsm::super}-->
<operation name="super" type="QState" visibility="0x01" properties="0x02">
<specifiers>noexcept</specifiers>
<documentation>//! Helper function to specify the superstate of a given state</documentation>
<!--${QEP::QHsm::super::superstate}-->
<parameter name="superstate" type="QStateHandler const"/>
<code>m_temp.fun = superstate;
return Q_RET_SUPER;</code>
</operation>
<!--${QEP::QHsm::qm_tran}-->
<operation name="qm_tran" type="QState" visibility="0x01" properties="0x02">
<specifiers>noexcept</specifiers>
<documentation>//! Helper function to specify a regular state transition
//! in a QM state-handler</documentation>
<!--${QEP::QHsm::qm_tran::tatbl}-->
<parameter name="tatbl" type="void const * const"/>
<code>m_temp.tatbl = static_cast<QP::QMTranActTable const *>(tatbl);
return Q_RET_TRAN;</code>
</operation>
<!--${QEP::QHsm::qm_tran_init}-->
<operation name="qm_tran_init" type="QState" visibility="0x01" properties="0x02">
<specifiers>noexcept</specifiers>
<documentation>//! Helper function to specify an initial state transition
//! in a QM state-handler</documentation>
<!--${QEP::QHsm::qm_tran_init::tatbl}-->
<parameter name="tatbl" type="void const * const"/>
<code>m_temp.tatbl = static_cast<QP::QMTranActTable const *>(tatbl);
return Q_RET_TRAN_INIT;</code>
</operation>