1111 <attribute name =" iter" type =" std::uint32_t" visibility =" 0x00" properties =" 0x00" >
1212 <documentation >the next iteration to perform</documentation >
1313 </attribute >
14+ <!-- ${Events::ReminderEvt::ReminderEvt}-->
15+ <operation name =" ReminderEvt?def QEVT_DYN_CTOR" type =" explicit" visibility =" 0x00" properties =" 0x02" >
16+ <specifiers >noexcept</specifiers >
17+ <!-- ${Events::ReminderEvt::ReminderEvt::i}-->
18+ <parameter name =" i" type =" std::uint32_t" />
19+ <code > : QEvt(QP::QEvt::DYNAMIC),
20+ iter(i)</code >
21+ </operation >
1422 </class >
1523 </package >
1624 <!-- ${Components}-->
3240 <statechart properties =" 0x02" >
3341 <!-- ${Components::Cruncher::SM::initial}-->
3442 <initial target =" ../1" >
35- <action >(void)e; // unused parameter </action >
43+ <action >Q_UNUSED_PAR(e); </action >
3644 <initial_glyph conn =" 2,2,5,1,44,6,-2" >
3745 <action box =" 0,-2,6,2" />
3846 </initial_glyph >
3947 </initial >
4048 <!-- ${Components::Cruncher::SM::processing}-->
4149 <state name =" processing" >
42- <entry >ReminderEvt *reminder = Q_NEW(ReminderEvt, CRUNCH_SIG);
43- reminder-> iter = 0;
50+ <entry >#ifdef QEVT_DYN_CTOR
51+ ReminderEvt *reminder = Q_NEW(ReminderEvt, CRUNCH_SIG, 0U);
52+ #else
53+ ReminderEvt *reminder = Q_NEW(ReminderEvt, CRUNCH_SIG);
54+ reminder-> iter = 0U;
55+ #endif
56+
4457POST(reminder, this);
4558m_sum = 0.0;</entry >
4659 <!-- ${Components::Cruncher::SM::processing::CRUNCH}-->
4760 <tran trig =" CRUNCH" >
48- <action >uint32_t i = Q_EVT_CAST(ReminderEvt)-> iter;
49- uint32_t n = i;
61+ <action >std:: uint32_t i = Q_EVT_CAST(ReminderEvt)-> iter;
62+ std:: uint32_t n = i;
5063i += 100U;
5164for (; n < i; ++n) {
5265 if ((n & 1) == 0) {
53- m_sum += 1.0/(2 *n + 1 );
66+ m_sum += 1.0/(2U *n + 1U );
5467 }
5568 else {
56- m_sum -= 1.0/(2 *n + 1 );
69+ m_sum -= 1.0/(2U *n + 1U );
5770 }
5871}</action >
5972 <!-- ${Components::Cruncher::SM::processing::CRUNCH::[else]}-->
@@ -67,9 +80,14 @@ for (; n < i; ++n) {
6780 <!-- ${Components::Cruncher::SM::processing::CRUNCH::[i<0x07000000U]}-->
6881 <choice >
6982 <guard >i < 0x07000000U</guard >
70- <action >ReminderEvt *reminder = Q_NEW(ReminderEvt, CRUNCH_SIG);
83+ <action >#ifdef QEVT_DYN_CTOR
84+ ReminderEvt *reminder = Q_NEW(ReminderEvt, CRUNCH_SIG, i);
85+ #else
86+ ReminderEvt *reminder = Q_NEW(ReminderEvt, CRUNCH_SIG);
7187reminder-> iter = i;
72- POST(reminder, me);</action >
88+ #endif
89+
90+ POST(reminder, this);</action >
7391 <choice_glyph conn =" 24,18,4,-1,-4,14" >
7492 <action box =" 0,-6,17,2" />
7593 </choice_glyph >
@@ -130,7 +148,7 @@ enum ReminderSignals {
130148//............................................................................
131149$declare${Events::ReminderEvt}
132150
133- // Active object class -----------------------------------------------------..
151+ // Active object class -------------------------------------------------------
134152$declare${Components::Cruncher}
135153
136154$define${Components::Cruncher}
@@ -147,7 +165,7 @@ int main(int argc, char *argv[]) {
147165 PRINTF_S(" Reminder state pattern\nQP version: %s\n"
148166 " Press 'e' to echo the current value...\n"
149167 " Press ESC to quit...\n" ,
150- QP::versionStr );
168+ QP_VERSION_STR );
151169
152170 BSP_init(argc, argv); // initialize the BSP
153171 QF::init(); // initialize the framework and the underlying RT kernel
@@ -168,14 +186,24 @@ int main(int argc, char *argv[]) {
168186void BSP_onKeyboardInput(uint8_t key) {
169187 switch (key) {
170188 case 'e': {
171- static QEvt const echoEvt(ECHO_SIG);
172- l_cruncher.POST(& echoEvt, nullptr);
189+ // NOTE:
190+ // The following Q_NEW_X() allocation might potentially fail
191+ // but this is acceptable becasue the " ECHO" event is not
192+ // considered critical. This code illustrates the Q_NEW_X()
193+ // API and its use.
194+ #ifdef QEVT_DYN_CTOR
195+ QEvt const *echoEvt = Q_NEW_X(QEvt, 2U, ECHO_SIG, QEvt::DYNAMIC);
196+ #else
197+ QEvt const *echoEvt = Q_NEW_X(QEvt, 2U, ECHO_SIG);
198+ #endif
199+ if (echoEvt != nullptr) { // event allocated successfully?
200+ l_cruncher.POST(echoEvt, nullptr);
201+ }
173202 break;
174203 }
175204 case '\033': { // ESC pressed?
176205 // NOTE: this constant event is statically pre-allocated.
177206 // It can be posted/published as any other event.
178- //
179207 static QEvt const terminateEvt(TERMINATE_SIG);
180208 l_cruncher.POST(& terminateEvt, nullptr);
181209 break;
0 commit comments