I am newer to using the QP Framework and I am trying to understand how to implement the Defer Event state pattern.
Can anyone lead me towards or provide an example using defer and recall? I will soon be moving to QPC, so an example in either QPC or QPCPP is helpful, though ultimately QPC will be preferred over everything else.
Thank you very much!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In QP/C/C++ 6.x the examples have been reorganized. Specifically, the folder examples\win32\mingw has been renamed to examples\workstation. This is because all console-style examples can now be built and run on any workstation, including Windows, Linux and MacOS. The provided Makefiles in the examples\workstation folder should work on all these operating systems.
Thank you for the quick response! This is really helpful.
I will take a look at this. In addition I am using the QM modeling tool, are there resources similar to the one you just posted, that have QM model examples? I am also looking through the sourceforge directory for this.
Thank you
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK so this is just a really quick model (attached), I haven't even tested it yet, but hopefully it gives you an idea. (Also, it's modeled after the MinGW version, not tailored to Arduino)
There is still one thing I am not quite understanding. If idle were it's own Active Object, how would you change the New_Request Transitions to make this work? Right now I am trying to make a test model using QPCPP and Arduino, though after I understand this and the other hardware is ready I will be taking it to QPC.
Thanks again.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is still one thing I am not quite understanding. If idle were it's own Active Object, how would you change the New_Request Transitions to make this work? Right now I am trying to make a test model using QPCPP and Arduino, though after I understand this and the other hardware is ready I will be taking it to QP.
In this example, Idle is one state within one state machine within the TServer active object. In other words, all of this processing takes place inside a single active object.
Someone (presumably another active object, or perhaps an ISR) sends the New Request to the TServer AO. And the sender doesn't even know that the request was deferred. The TServer just comes back and handles it later.
So I guess what I'm saying is that I don't quite understand when you say, "If idle were its own active object", what that means? In this example, the deferring (in superstate Busy) and the recall (in Idle) both take place within the same active object. I'm not sure how this could be split apart without adding a lot of handshaking. And that kind of defeats the purpose of the design pattern, which hides the whole defer/recall processing.
Does that make sense, or can you add a bit of clarification to what you're describing?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yep that makes sense that idle and busy have to be within the same Active Object, after looking at it further I understand why. Thanks for baring with me. If and when I get my example working, I will post it for completion.
Last edit: Anton Morgan 2014-06-18
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have the same question (how to implement the defer pattern in QP/C using QActive_defer() while working in QM), but unfortunately the model that was so generously posted in 2014 is no longer compatible with QM.
Is there information about this anywhere online, or could anyone help me with a set of steps? The question uppermost in my mind is whether QM supports this natively or whether I need to insert code of my own.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The "defer" example in QP/C/C++ 6.8.1 is still coded manually and the example directory has no QM model file. But the models have been created and will be included in the upcoming QP/C/C++ 6.8.2 release. For now, I simply attach the model file defer.qm for QP/C++. This model should be copied to the directory qpcpp\examples\workstation\defer, where it can be built with the Makefile. The following snippet shows the command-prompt output from a build and run of the defer example:
C:\qp_lab\qpcpp\examples\workstation\defer>makeg++-MM-MTbuild/defer.o-c-g-O-fno-pie-std=c++11-pedantic-Wall-Wextra-fno-rtti-fno-exceptions-I. -I../../../include-I../../../src-I../../../ports/win32-qv-DQP_API_VERSION=9999defer.cpp>build/defer.dg++-MM-MTbuild/bsp.o-c-g-O-fno-pie-std=c++11-pedantic-Wall-Wextra-fno-rtti-fno-exceptions-I. -I../../../include-I../../../src-I../../../ports/win32-qv-DQP_API_VERSION=9999bsp.cpp>build/bsp.dg++-c-g-O-fno-pie-std=c++11-pedantic-Wall-Wextra-fno-rtti-fno-exceptions-I. -I../../../include-I../../../src-I../../../ports/win32-qv-DQP_API_VERSION=9999bsp.cpp-obuild/bsp.og++-c-g-O-fno-pie-std=c++11-pedantic-Wall-Wextra-fno-rtti-fno-exceptions-I. -I../../../include-I../../../src-I../../../ports/win32-qv-DQP_API_VERSION=9999defer.cpp-obuild/defer.og++-c-g-O-fno-pie-std=c++11-pedantic-Wall-Wextra-fno-rtti-fno-exceptions-I. -I../../../include-I../../../src-I../../../ports/win32-qv-DQP_API_VERSION=9999 ../../../include/qstamp.cpp-obuild/qstamp.og++-no-pie-L../../../ports/win32-qv/dbg-obuild/defer.exebuild/bsp.obuild/defer.obuild/qstamp.o-lqp-lws2_32C:\qp_lab\qpcpp\examples\workstation\defer>build\defer.exeDeferredEventstatepatternQPversion: 6.8.2Press'n'togenerateanewrequestPressESCtoquit...
idle-ENTRY;NodeferredrequestsProcessingrequest#1receiving-ENTRY; active request: #1Request#2deferred;authorizing-ENTRY; active request: #1Request#3deferred;Request#4deferred;Request#5deferred;Request#6IGNORED;busy-EXIT; done processing request #1idle-ENTRY;RequestrecalledProcessingrequest#2receiving-ENTRY; active request: #2authorizing-ENTRY; active request: #2busy-EXIT; done processing request #2idle-ENTRY;RequestrecalledProcessingrequest#3receiving-ENTRY; active request: #3authorizing-ENTRY; active request: #3busy-EXIT; done processing request #3idle-ENTRY;RequestrecalledProcessingrequest#4receiving-ENTRY; active request: #4authorizing-ENTRY; active request: #4busy-EXIT; done processing request #4idle-ENTRY;RequestrecalledProcessingrequest#5receiving-ENTRY; active request: #5authorizing-ENTRY; active request: #5busy-EXIT; done processing request #5idle-ENTRY;Nodeferredrequestsfinal-ENTRY;C:\qp_lab\qpcpp\examples\workstation\defer>
I am newer to using the QP Framework and I am trying to understand how to implement the Defer Event state pattern.
Can anyone lead me towards or provide an example using defer and recall? I will soon be moving to QPC, so an example in either QPC or QPCPP is helpful, though ultimately QPC will be preferred over everything else.
Thank you very much!
The code examples in QP/C++ baseline distribution are applicable to Arduino as well.
So, I would recommend that you download the latest QP/C++ baseline code from http://sourceforge.net/projects/qpc/files/QP-Cpp/ and look in the directory:
qpcpp\examples\win32\mingw\defer
.Regarding the QP/C framework, you need to download QP/C baseline code from http://sourceforge.net/projects/qpc/files/QP-C and look in the directory:
qpc\examples\win32\mingw\defer
.For completeness, for QP-nano, you need to download QP-nano baseline code from http://sourceforge.net/projects/qpc/files/QP-nano/ and look in the directory:
qpn\examples\win32\mingw\defer
.Update as of July 2020:
In QP/C/C++ 6.x the examples have been reorganized. Specifically, the folder
examples\win32\mingw
has been renamed toexamples\workstation
. This is because all console-style examples can now be built and run on any workstation, including Windows, Linux and MacOS. The provided Makefiles in theexamples\workstation
folder should work on all these operating systems.Also, the recommended way of downloading QP is now directly from state-machine.com in form of "QP-bundle", which includes all QP frameworks, QM modeling tool and QTools collection.
--MMS
Last edit: Quantum Leaps 2020-07-14
Thank you for the quick response! This is really helpful.
I will take a look at this. In addition I am using the QM modeling tool, are there resources similar to the one you just posted, that have QM model examples? I am also looking through the sourceforge directory for this.
Thank you
Many QM models are already available in the QP baseline distributions. You can just grep for model files (*.qm).
For example, here is the listing of *.qm files from the QP/C++ baseline distribution:
--MMS
Do any of the QM models have a defer/recall example? If so can you point me to which one that is?
Thanks for the help.
I don't believe there is currently a model for the deferred event design pattern.
It wouldn't be hard to do, if I can find the time I'll try to throw one together, I would copy Miro's implementation as closely as possible.
That would be awesome. Thanks!
OK so this is just a really quick model (attached), I haven't even tested it yet, but hopefully it gives you an idea. (Also, it's modeled after the MinGW version, not tailored to Arduino)
Thank you! I'm actually migrating to our final controller, so not a problem. I will give feedback once I am able to test it.
There is still one thing I am not quite understanding. If idle were it's own Active Object, how would you change the New_Request Transitions to make this work? Right now I am trying to make a test model using QPCPP and Arduino, though after I understand this and the other hardware is ready I will be taking it to QPC.
Thanks again.
In this example, Idle is one state within one state machine within the TServer active object. In other words, all of this processing takes place inside a single active object.
Someone (presumably another active object, or perhaps an ISR) sends the New Request to the TServer AO. And the sender doesn't even know that the request was deferred. The TServer just comes back and handles it later.
So I guess what I'm saying is that I don't quite understand when you say, "If idle were its own active object", what that means? In this example, the deferring (in superstate Busy) and the recall (in Idle) both take place within the same active object. I'm not sure how this could be split apart without adding a lot of handshaking. And that kind of defeats the purpose of the design pattern, which hides the whole defer/recall processing.
Does that make sense, or can you add a bit of clarification to what you're describing?
Thanks.
Yep that makes sense that idle and busy have to be within the same Active Object, after looking at it further I understand why. Thanks for baring with me. If and when I get my example working, I will post it for completion.
Last edit: Anton Morgan 2014-06-18
I have the same question (how to implement the defer pattern in QP/C using QActive_defer() while working in QM), but unfortunately the model that was so generously posted in 2014 is no longer compatible with QM.
Is there information about this anywhere online, or could anyone help me with a set of steps? The question uppermost in my mind is whether QM supports this natively or whether I need to insert code of my own.
Hi Dana,
I assume you have a modern (i.e. 6.x) version of QP/C?
I have 6.7.0 and there is a QM model for the Defer Pattern that can be found under: qpc\examples\workstation\defer\defer.qm
Hope that helps.
Yikes. Apologies. I just realized that the model in my QP distribution is one I create (reverse-engineered from the code). Sorry.
Thanks for looking into this.
Hi Dana,
The "defer" example in QP/C/C++ 6.8.1 is still coded manually and the example directory has no QM model file. But the models have been created and will be included in the upcoming QP/C/C++ 6.8.2 release. For now, I simply attach the model file
defer.qm
for QP/C++. This model should be copied to the directoryqpcpp\examples\workstation\defer
, where it can be built with the Makefile. The following snippet shows the command-prompt output from a build and run of the defer example:Last edit: Quantum Leaps 2020-07-14
Many thanks - I'll start here.