mirror of
https://github.com/QuantumLeaps/qpc.git
synced 2025-01-14 06:43:19 +08:00
6.8.1
This commit is contained in:
parent
10a53fa20e
commit
4646482066
BIN
doxygen/img/favicon.ico
Normal file
BIN
doxygen/img/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 894 B |
@ -1,36 +1,21 @@
|
||||
/*****************************************************************************
|
||||
* Product: Deferred Event state pattern example
|
||||
* Last updated for version 6.8.0
|
||||
* Last updated on 2019-02-08
|
||||
/*.$file${.::defer.c} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
|
||||
/*
|
||||
* Model: defer.qm
|
||||
* File: ${.::defer.c}
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ------------------------
|
||||
* Modern Embedded Software
|
||||
*
|
||||
* Copyright (C) 2005-2019 Quantum Leaps, LLC. All rights reserved.
|
||||
* This code has been generated by QM 5.0.1 <www.state-machine.com/qm/>.
|
||||
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
||||
*
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this program may be distributed and modified under the
|
||||
* terms of Quantum Leaps commercial licenses, which expressly supersede
|
||||
* the GNU General Public License and are specifically designed for
|
||||
* licensees interested in retaining the proprietary status of their code.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contact information:
|
||||
* <www.state-machine.com/licensing>
|
||||
* <info@state-machine.com>
|
||||
*****************************************************************************/
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
/*.$endhead${.::defer.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
|
||||
#include "qpc.h"
|
||||
#include "bsp.h"
|
||||
|
||||
@ -46,51 +31,75 @@ enum TServerSignals {
|
||||
TERMINATE_SIG /* terminate the application */
|
||||
};
|
||||
/*..........................................................................*/
|
||||
/*.$declare${Events::RequestEvt} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
|
||||
/*.${Events::RequestEvt} ...................................................*/
|
||||
typedef struct {
|
||||
QEvt super; /* inherit QEvt */
|
||||
uint8_t ref_num; /* reference number of the request */
|
||||
/* protected: */
|
||||
QEvt super;
|
||||
|
||||
/* public: */
|
||||
uint8_t ref_num;
|
||||
} RequestEvt;
|
||||
/*.$enddecl${Events::RequestEvt} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
|
||||
|
||||
/*..........................................................................*/
|
||||
typedef struct TServerTag { /* Transaction Server active object */
|
||||
QActive super; /* inherit QActive */
|
||||
/* Active object class -----------------------------------------------------*/
|
||||
/*.$declare${Components::TServer} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
|
||||
/*.${Components::TServer} ..................................................*/
|
||||
typedef struct {
|
||||
/* protected: */
|
||||
QActive super;
|
||||
|
||||
QEQueue requestQueue; /* native QF queue for deferred request events */
|
||||
QEvt const *requestQSto[3]; /* storage for deferred queue buffer */
|
||||
RequestEvt const *activeRequest; /* request event being processed */
|
||||
/* private: */
|
||||
QEQueue requestQueue;
|
||||
QEvt const * requestQSto[3];
|
||||
|
||||
QTimeEvt receivedEvt; /* private time event generator */
|
||||
QTimeEvt authorizedEvt; /* private time event generator */
|
||||
/* public: */
|
||||
RequestEvt const * activeRequest;
|
||||
QTimeEvt receivedEvt;
|
||||
QTimeEvt authorizedEvt;
|
||||
} TServer;
|
||||
|
||||
void TServer_ctor(TServer * const me); /* the default ctor */
|
||||
/* public: */
|
||||
static void TServer_ctor(TServer * const me);
|
||||
|
||||
/* hierarchical state machine ... */
|
||||
static QState TServer_initial (TServer * const me, QEvt const * const e);
|
||||
static QState TServer_idle (TServer * const me, QEvt const * const e);
|
||||
static QState TServer_busy (TServer * const me, QEvt const * const e);
|
||||
static QState TServer_receiving (TServer * const me, QEvt const * const e);
|
||||
/* protected: */
|
||||
static QState TServer_initial(TServer * const me, QEvt const * const e);
|
||||
static QState TServer_idle(TServer * const me, QEvt const * const e);
|
||||
static QState TServer_busy(TServer * const me, QEvt const * const e);
|
||||
static QState TServer_receiving(TServer * const me, QEvt const * const e);
|
||||
static QState TServer_authorizing(TServer * const me, QEvt const * const e);
|
||||
static QState TServer_final (TServer * const me, QEvt const * const e);
|
||||
static QState TServer_final(TServer * const me, QEvt const * const e);
|
||||
/*.$enddecl${Components::TServer} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
|
||||
|
||||
/*..........................................................................*/
|
||||
void TServer_ctor(TServer * const me) { /* the default ctor */
|
||||
/*.$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
|
||||
/*. Check for the minimum required QP version */
|
||||
#if (QP_VERSION < 670U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
|
||||
#error qpc version 6.7.0 or higher required
|
||||
#endif
|
||||
/*.$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
|
||||
/*.$define${Components::TServer} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
|
||||
/*.${Components::TServer} ..................................................*/
|
||||
/*.${Components::TServer::ctor} ............................................*/
|
||||
static void TServer_ctor(TServer * const me) {
|
||||
QActive_ctor(&me->super, Q_STATE_CAST(&TServer_initial));
|
||||
QEQueue_init(&me->requestQueue,
|
||||
me->requestQSto, Q_DIM(me->requestQSto));
|
||||
me->requestQSto, Q_DIM(me->requestQSto));
|
||||
QTimeEvt_ctorX(&me->receivedEvt, &me->super, RECEIVED_SIG, 0U);
|
||||
QTimeEvt_ctorX(&me->authorizedEvt, &me->super, AUTHORIZED_SIG, 0U);
|
||||
}
|
||||
/* HSM definition ----------------------------------------------------------*/
|
||||
QState TServer_initial(TServer * const me, QEvt const * const e) {
|
||||
|
||||
/*.${Components::TServer::SM} ..............................................*/
|
||||
static QState TServer_initial(TServer * const me, QEvt const * const e) {
|
||||
/*.${Components::TServer::SM::initial} */
|
||||
(void)e; /* unused parameter */
|
||||
me->activeRequest = (RequestEvt const *)0; /* no active request yet */
|
||||
return Q_TRAN(&TServer_idle);
|
||||
}
|
||||
/*..........................................................................*/
|
||||
QState TServer_idle(TServer * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
/*.${Components::TServer::SM::idle} ........................................*/
|
||||
static QState TServer_idle(TServer * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/*.${Components::TServer::SM::idle} */
|
||||
case Q_ENTRY_SIG: {
|
||||
PRINTF_S("%s\n", "idle-ENTRY;");
|
||||
|
||||
@ -101,9 +110,10 @@ QState TServer_idle(TServer * const me, QEvt const * const e) {
|
||||
else {
|
||||
PRINTF_S("%s\n", "No deferred requests");
|
||||
}
|
||||
status = Q_HANDLED();
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/*.${Components::TServer::SM::idle::NEW_REQUEST} */
|
||||
case NEW_REQUEST_SIG: {
|
||||
/* create and save a new reference to the request event so that
|
||||
* this event will be available beyond this RTC step and won't be
|
||||
@ -113,25 +123,26 @@ QState TServer_idle(TServer * const me, QEvt const * const e) {
|
||||
|
||||
PRINTF_S("Processing request #%d\n",
|
||||
(int)me->activeRequest->ref_num);
|
||||
|
||||
status = Q_TRAN(&TServer_receiving);
|
||||
status_ = Q_TRAN(&TServer_receiving);
|
||||
break;
|
||||
}
|
||||
/*.${Components::TServer::SM::idle::TERMINATE} */
|
||||
case TERMINATE_SIG: {
|
||||
status = Q_TRAN(&TServer_final);
|
||||
status_ = Q_TRAN(&TServer_final);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/*..........................................................................*/
|
||||
QState TServer_busy(TServer * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
/*.${Components::TServer::SM::busy} ........................................*/
|
||||
static QState TServer_busy(TServer * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/*.${Components::TServer::SM::busy} */
|
||||
case Q_EXIT_SIG: {
|
||||
PRINTF_S("busy-EXIT; done processing request #%d\n",
|
||||
(int)me->activeRequest->ref_num);
|
||||
@ -140,10 +151,10 @@ QState TServer_busy(TServer * const me, QEvt const * const e) {
|
||||
* it is now processed.
|
||||
*/
|
||||
Q_DELETE_REF(me->activeRequest);
|
||||
|
||||
status = Q_HANDLED();
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/*.${Components::TServer::SM::busy::NEW_REQUEST} */
|
||||
case NEW_REQUEST_SIG: {
|
||||
/* defer the new request event... */
|
||||
if (QActive_defer(&me->super, &me->requestQueue, e)) {
|
||||
@ -155,24 +166,26 @@ QState TServer_busy(TServer * const me, QEvt const * const e) {
|
||||
PRINTF_S("Request #%d IGNORED;\n",
|
||||
(int)Q_EVT_CAST(RequestEvt)->ref_num);
|
||||
}
|
||||
status = Q_HANDLED();
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/*.${Components::TServer::SM::busy::TERMINATE} */
|
||||
case TERMINATE_SIG: {
|
||||
status = Q_TRAN(&TServer_final);
|
||||
status_ = Q_TRAN(&TServer_final);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/*..........................................................................*/
|
||||
QState TServer_receiving(TServer * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
/*.${Components::TServer::SM::busy::receiving} .............................*/
|
||||
static QState TServer_receiving(TServer * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/*.${Components::TServer::SM::busy::receiving} */
|
||||
case Q_ENTRY_SIG: {
|
||||
/* inform about the first stage of processing of the request... */
|
||||
PRINTF_S("receiving-ENTRY; active request: #%d\n",
|
||||
@ -180,29 +193,32 @@ QState TServer_receiving(TServer * const me, QEvt const * const e) {
|
||||
|
||||
/* one-shot timeout in 1 second */
|
||||
QTimeEvt_armX(&me->receivedEvt, BSP_TICKS_PER_SEC, 0U);
|
||||
status = Q_HANDLED();
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/*.${Components::TServer::SM::busy::receiving} */
|
||||
case Q_EXIT_SIG: {
|
||||
QTimeEvt_disarm(&me->receivedEvt);
|
||||
status = Q_HANDLED();
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/*.${Components::TServer::SM::busy::receiving::RECEIVED} */
|
||||
case RECEIVED_SIG: {
|
||||
status = Q_TRAN(&TServer_authorizing);
|
||||
status_ = Q_TRAN(&TServer_authorizing);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&TServer_busy);
|
||||
status_ = Q_SUPER(&TServer_busy);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/*..........................................................................*/
|
||||
QState TServer_authorizing(TServer * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
/*.${Components::TServer::SM::busy::authorizing} ...........................*/
|
||||
static QState TServer_authorizing(TServer * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/*.${Components::TServer::SM::busy::authorizing} */
|
||||
case Q_ENTRY_SIG: {
|
||||
/* inform about the second stage of processing of the request.. */
|
||||
PRINTF_S("authorizing-ENTRY; active request: #%d\n",
|
||||
@ -210,42 +226,47 @@ QState TServer_authorizing(TServer * const me, QEvt const * const e) {
|
||||
|
||||
/* one-shot timeout in 2 seconds */
|
||||
QTimeEvt_armX(&me->authorizedEvt, 2U*BSP_TICKS_PER_SEC, 0U);
|
||||
status = Q_HANDLED();
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/*.${Components::TServer::SM::busy::authorizing} */
|
||||
case Q_EXIT_SIG: {
|
||||
QTimeEvt_disarm(&me->authorizedEvt);
|
||||
status = Q_HANDLED();
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
/*.${Components::TServer::SM::busy::authorizing::AUTHORIZED} */
|
||||
case AUTHORIZED_SIG: {
|
||||
status = Q_TRAN(&TServer_idle);
|
||||
status_ = Q_TRAN(&TServer_idle);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&TServer_busy);
|
||||
status_ = Q_SUPER(&TServer_busy);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/*..........................................................................*/
|
||||
QState TServer_final(TServer * const me, QEvt const * const e) {
|
||||
QState status;
|
||||
/*.${Components::TServer::SM::final} .......................................*/
|
||||
static QState TServer_final(TServer * const me, QEvt const * const e) {
|
||||
QState status_;
|
||||
switch (e->sig) {
|
||||
/*.${Components::TServer::SM::final} */
|
||||
case Q_ENTRY_SIG: {
|
||||
PRINTF_S("%s\n", "final-ENTRY;");
|
||||
QF_stop(); /* terminate the application */
|
||||
status = Q_HANDLED();
|
||||
QF_stop(); /* terminate the application */
|
||||
status_ = Q_HANDLED();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
status = Q_SUPER(&QHsm_top);
|
||||
status_ = Q_SUPER(&QHsm_top);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status_;
|
||||
}
|
||||
/*.$enddef${Components::TServer} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
|
||||
|
||||
// test harness ============================================================*/
|
||||
|
||||
// Local-scope objects -------------------------------------------------------
|
||||
|
257
examples/workstation/defer/defer.qm
Normal file
257
examples/workstation/defer/defer.qm
Normal file
@ -0,0 +1,257 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<model version="5.0.1" links="1">
|
||||
<documentation>Dining Philosopher Problem example
|
||||
|
||||
NOTE: Requries QP6.</documentation>
|
||||
<!--${qpc}-->
|
||||
<framework name="qpc"/>
|
||||
<!--${Events}-->
|
||||
<package name="Events" stereotype="0x01">
|
||||
<!--${Events::RequestEvt}-->
|
||||
<class name="RequestEvt" superclass="qpc::QEvt">
|
||||
<!--${Events::RequestEvt::ref_num}-->
|
||||
<attribute name="ref_num" type="uint8_t" visibility="0x00" properties="0x00">
|
||||
<documentation>reference number of the request</documentation>
|
||||
</attribute>
|
||||
</class>
|
||||
</package>
|
||||
<!--${Components}-->
|
||||
<package name="Components" stereotype="0x02">
|
||||
<!--${Components::TServer}-->
|
||||
<class name="TServer" superclass="qpc::QActive">
|
||||
<documentation>"Transaction Server" AO</documentation>
|
||||
<!--${Components::TServer::requestQueue}-->
|
||||
<attribute name="requestQueue" type="QEQueue" visibility="0x02" properties="0x00"/>
|
||||
<!--${Components::TServer::requestQSto[3]}-->
|
||||
<attribute name="requestQSto[3]" type="QEvt const *" visibility="0x02" properties="0x00"/>
|
||||
<!--${Components::TServer::activeRequest}-->
|
||||
<attribute name="activeRequest" type="RequestEvt const *" visibility="0x00" properties="0x00"/>
|
||||
<!--${Components::TServer::receivedEvt}-->
|
||||
<attribute name="receivedEvt" type="QTimeEvt" visibility="0x00" properties="0x00">
|
||||
<documentation>private time event</documentation>
|
||||
</attribute>
|
||||
<!--${Components::TServer::authorizedEvt}-->
|
||||
<attribute name="authorizedEvt" type="QTimeEvt" visibility="0x00" properties="0x00">
|
||||
<documentation>private time event</documentation>
|
||||
</attribute>
|
||||
<!--${Components::TServer::ctor}-->
|
||||
<operation name="ctor" type="void" visibility="0x00" properties="0x00">
|
||||
<code>QActive_ctor(&me->super, Q_STATE_CAST(&TServer_initial));
|
||||
QEQueue_init(&me->requestQueue,
|
||||
me->requestQSto, Q_DIM(me->requestQSto));
|
||||
QTimeEvt_ctorX(&me->receivedEvt, &me->super, RECEIVED_SIG, 0U);
|
||||
QTimeEvt_ctorX(&me->authorizedEvt, &me->super, AUTHORIZED_SIG, 0U);</code>
|
||||
</operation>
|
||||
<!--${Components::TServer::SM}-->
|
||||
<statechart properties="0x01">
|
||||
<!--${Components::TServer::SM::initial}-->
|
||||
<initial target="../1">
|
||||
<action>(void)e; /* unused parameter */
|
||||
me->activeRequest = (RequestEvt const *)0; /* no active request yet */</action>
|
||||
<initial_glyph conn="2,2,5,1,32,6,-2">
|
||||
<action box="0,-2,6,2"/>
|
||||
</initial_glyph>
|
||||
</initial>
|
||||
<!--${Components::TServer::SM::idle}-->
|
||||
<state name="idle">
|
||||
<entry brief="recall">PRINTF_S("%s\n", "idle-ENTRY;");
|
||||
|
||||
/* recall the oldest deferred request... */
|
||||
if (QActive_recall(&me->super, &me->requestQueue)) {
|
||||
PRINTF_S("%s\n", "Request recalled");
|
||||
}
|
||||
else {
|
||||
PRINTF_S("%s\n", "No deferred requests");
|
||||
}</entry>
|
||||
<!--${Components::TServer::SM::idle::NEW_REQUEST}-->
|
||||
<tran trig="NEW_REQUEST" target="../../2/2">
|
||||
<action>/* create and save a new reference to the request event so that
|
||||
* this event will be available beyond this RTC step and won't be
|
||||
* recycled.
|
||||
*/
|
||||
Q_NEW_REF(me->activeRequest, RequestEvt);
|
||||
|
||||
PRINTF_S("Processing request #%d\n",
|
||||
(int)me->activeRequest->ref_num);</action>
|
||||
<tran_glyph conn="2,18,3,1,56,32,-12">
|
||||
<action box="0,-2,24,2"/>
|
||||
</tran_glyph>
|
||||
</tran>
|
||||
<!--${Components::TServer::SM::idle::TERMINATE}-->
|
||||
<tran trig="TERMINATE" target="../../3">
|
||||
<tran_glyph conn="2,22,3,1,62,68,-32">
|
||||
<action box="0,-2,10,2"/>
|
||||
</tran_glyph>
|
||||
</tran>
|
||||
<state_glyph node="2,6,30,20">
|
||||
<entry box="1,2,13,2"/>
|
||||
</state_glyph>
|
||||
</state>
|
||||
<!--${Components::TServer::SM::busy}-->
|
||||
<state name="busy">
|
||||
<exit>PRINTF_S("busy-EXIT; done processing request #%d\n",
|
||||
(int)me->activeRequest->ref_num);
|
||||
|
||||
/* delete the reference to the active request, because
|
||||
* it is now processed.
|
||||
*/
|
||||
Q_DELETE_REF(me->activeRequest);</exit>
|
||||
<!--${Components::TServer::SM::busy::NEW_REQUEST}-->
|
||||
<tran trig="NEW_REQUEST">
|
||||
<action brief="defer">/* defer the new request event... */
|
||||
if (QActive_defer(&me->super, &me->requestQueue, e)) {
|
||||
PRINTF_S("Request #%d deferred;\n",
|
||||
(int)Q_EVT_CAST(RequestEvt)->ref_num);
|
||||
}
|
||||
else {
|
||||
/* notify the request sender that his request was denied... */
|
||||
PRINTF_S("Request #%d IGNORED;\n",
|
||||
(int)Q_EVT_CAST(RequestEvt)->ref_num);
|
||||
}</action>
|
||||
<tran_glyph conn="2,40,3,-1,26">
|
||||
<action box="0,-2,24,2"/>
|
||||
</tran_glyph>
|
||||
</tran>
|
||||
<!--${Components::TServer::SM::busy::TERMINATE}-->
|
||||
<tran trig="TERMINATE" target="../../3">
|
||||
<tran_glyph conn="2,44,3,1,60,48,-30">
|
||||
<action box="0,-2,10,2"/>
|
||||
</tran_glyph>
|
||||
</tran>
|
||||
<!--${Components::TServer::SM::busy::receiving}-->
|
||||
<state name="receiving">
|
||||
<entry>/* inform about the first stage of processing of the request... */
|
||||
PRINTF_S("receiving-ENTRY; active request: #%d\n",
|
||||
(int)me->activeRequest->ref_num);
|
||||
|
||||
/* one-shot timeout in 1 second */
|
||||
QTimeEvt_armX(&me->receivedEvt, BSP_TICKS_PER_SEC, 0U);</entry>
|
||||
<exit>QTimeEvt_disarm(&me->receivedEvt);</exit>
|
||||
<!--${Components::TServer::SM::busy::receiving::RECEIVED}-->
|
||||
<tran trig="RECEIVED" target="../../3">
|
||||
<tran_glyph conn="6,58,3,1,44,10,-4">
|
||||
<action box="0,-2,8,2"/>
|
||||
</tran_glyph>
|
||||
</tran>
|
||||
<state_glyph node="6,48,40,14">
|
||||
<entry box="1,2,27,2"/>
|
||||
<exit box="1,4,6,2"/>
|
||||
</state_glyph>
|
||||
</state>
|
||||
<!--${Components::TServer::SM::busy::authorizing}-->
|
||||
<state name="authorizing">
|
||||
<entry>/* inform about the second stage of processing of the request.. */
|
||||
PRINTF_S("authorizing-ENTRY; active request: #%d\n",
|
||||
(int)me->activeRequest->ref_num);
|
||||
|
||||
/* one-shot timeout in 2 seconds */
|
||||
QTimeEvt_armX(&me->authorizedEvt, 2U*BSP_TICKS_PER_SEC, 0U);</entry>
|
||||
<exit>QTimeEvt_disarm(&me->authorizedEvt);</exit>
|
||||
<!--${Components::TServer::SM::busy::authorizing::AUTHORIZED}-->
|
||||
<tran trig="AUTHORIZED" target="../../../1">
|
||||
<tran_glyph conn="6,76,3,1,54,-62,-28">
|
||||
<action box="0,-2,14,2"/>
|
||||
</tran_glyph>
|
||||
</tran>
|
||||
<state_glyph node="6,66,40,14">
|
||||
<entry box="1,2,17,2"/>
|
||||
<exit box="1,4,6,2"/>
|
||||
</state_glyph>
|
||||
</state>
|
||||
<state_glyph node="2,30,54,54">
|
||||
<exit box="1,2,6,2"/>
|
||||
</state_glyph>
|
||||
</state>
|
||||
<!--${Components::TServer::SM::final}-->
|
||||
<state name="final">
|
||||
<entry brief="stop">PRINTF_S("%s\n", "final-ENTRY;");
|
||||
QF_stop(); /* terminate the application */</entry>
|
||||
<state_glyph node="2,88,30,10">
|
||||
<entry box="1,2,6,2"/>
|
||||
</state_glyph>
|
||||
</state>
|
||||
<state_diagram size="68,102"/>
|
||||
</statechart>
|
||||
</class>
|
||||
</package>
|
||||
<!--${.}-->
|
||||
<directory name=".">
|
||||
<!--${.::defer.c}-->
|
||||
<file name="defer.c">
|
||||
<text>#include "qpc.h"
|
||||
#include "bsp.h"
|
||||
|
||||
#include "safe_std.h" /* portable "safe" <stdio.h>/<string.h> facilities */
|
||||
|
||||
Q_DEFINE_THIS_FILE
|
||||
|
||||
/*..........................................................................*/
|
||||
enum TServerSignals {
|
||||
NEW_REQUEST_SIG = Q_USER_SIG, /* the new request signal */
|
||||
RECEIVED_SIG, /* the request has been received */
|
||||
AUTHORIZED_SIG, /* the request has been authorized */
|
||||
TERMINATE_SIG /* terminate the application */
|
||||
};
|
||||
/*..........................................................................*/
|
||||
$declare${Events::RequestEvt}
|
||||
|
||||
/* Active object class -----------------------------------------------------*/
|
||||
$declare${Components::TServer}
|
||||
|
||||
$define${Components::TServer}
|
||||
|
||||
// test harness ============================================================*/
|
||||
|
||||
// Local-scope objects -------------------------------------------------------
|
||||
static TServer l_tserver; /* the TServer active object */
|
||||
static QEvt const *l_tserverQSto[10]; /* Event queue storage for TServer */
|
||||
static QF_MPOOL_EL(RequestEvt) l_smlPoolSto[20]; /* storage for small pool */
|
||||
|
||||
/*..........................................................................*/
|
||||
int main(int argc, char *argv[]) {
|
||||
PRINTF_S("Deferred Event state pattern\nQP version: %s\n"
|
||||
"Press 'n' to generate a new request\n"
|
||||
"Press ESC to quit...\n",
|
||||
QP_VERSION_STR);
|
||||
|
||||
BSP_init(argc, argv); /* initialize the BSP */
|
||||
|
||||
QF_init(); /* initialize the framework and the underlying RTOS/OS */
|
||||
|
||||
|
||||
/* publish-subscribe not used, no call to QF_psInit() */
|
||||
|
||||
/* initialize event pools... */
|
||||
QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
|
||||
|
||||
/* start the active objects... */
|
||||
TServer_ctor(&l_tserver);
|
||||
QACTIVE_START((QMActive *)&l_tserver,
|
||||
1U,
|
||||
l_tserverQSto, Q_DIM(l_tserverQSto),
|
||||
(void *)0, 0U, (QEvt *)0);
|
||||
|
||||
return QF_run(); /* run the QF application */
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void BSP_onKeyboardInput(uint8_t key) {
|
||||
switch (key) {
|
||||
case 'n': { /* 'n': new request? */
|
||||
static uint8_t reqCtr = 0; /* count the requests */
|
||||
RequestEvt *e = Q_NEW(RequestEvt, NEW_REQUEST_SIG);
|
||||
e->ref_num = (++reqCtr); /* set the reference number */
|
||||
/* post directly to TServer active object */
|
||||
QACTIVE_POST((QMActive *)&l_tserver, (QEvt *)e, (void *)0);
|
||||
break;
|
||||
}
|
||||
case '\33': { /* ESC pressed? */
|
||||
static QEvt const terminateEvt = { TERMINATE_SIG, 0U, 0U };
|
||||
QACTIVE_POST((QMActive *)&l_tserver, &terminateEvt, (void *)0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
</text>
|
||||
</file>
|
||||
</directory>
|
||||
</model>
|
@ -4,8 +4,8 @@
|
||||
* @ingroup qs
|
||||
* @cond
|
||||
******************************************************************************
|
||||
* Last updated for version 6.8.0
|
||||
* Last updated on 2020-01-19
|
||||
* Last updated for version 6.8.1
|
||||
* Last updated on 2020-05-06
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ------------------------
|
||||
@ -69,7 +69,7 @@ void QS_u64_raw_(uint64_t d) {
|
||||
/** @note This function is only to be used through macros, never in the
|
||||
* client code directly.
|
||||
*/
|
||||
void QS_u64(uint8_t format, uint64_t d) {
|
||||
void QS_u64_fmt_(uint8_t format, uint64_t d) {
|
||||
uint8_t chksum = QS_priv_.chksum;
|
||||
uint8_t *buf = QS_priv_.buf;
|
||||
QSCtr head = QS_priv_.head;
|
||||
|
Loading…
x
Reference in New Issue
Block a user