Deferred Event - Quantum Leaps
Deferred Event - Quantum Leaps
Deferred Event - Quantum Leaps
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Design Pattern<strong>Deferred</strong> <strong>Event</strong>state-machine.com/resources/appnotes.phpNote:Even though the deferred event is in principle available directly from the recall() operation, it is notprocessed in the entry action to “idle”. Rather, the recall() operation posts the event to self (to theevent queue of this state machine). The state machine then handles the NEW_REQUEST event as anyother event, that is, in the transition from “idle” to “receiving”.Sample CodeThe sample code for the <strong>Deferred</strong> <strong>Event</strong> state pattern is found in the directoryqpc\examples\win32\mingw\defer\. You can execute the application by double-clicking on the fileDEFER.EXE file in the dbg\ subdirectory. Figure 5.7 shows the output generated by the DEFER.EXEapplication. The application prints every state entry (to “idle”, “receiving”, and “authorizing”). Additionally, youget notification of every NEW_REQUEST event and whether it has been deferred or processed directly. Yougenerate new requests by pressing the ‘n’ key. Please note that request #7 is NOT deferred because the deferredevent queue gets full. Please see the explanation section following Listing 5.3 for an overview of options tohandle this situation.Figure 5.7 Annotated output generated by DEFER.EXE.Listing 5.3 The <strong>Deferred</strong> <strong>Event</strong> sample code (file defer.c).Copyright © <strong>Quantum</strong> <strong>Leaps</strong>, LLC. All Rights Reserved.3 of 9