| Subject: |
|
Re: History pattern without QHsm_getState in QP 4.0 ? |
| Name: |
|
Miro Samek |
| Date Posted: |
|
Jun 10, 08 - 6:30 AM |
| Email: |
|
miro@quantum-leaps.com |
| Website: |
|
http://www.quantum-leaps.com |
| Message: |
|
Anders,
Yes, the QHsm_getState() operation has been eliminated in QEP v4, because it turned out to be quite expensive in the new implementation. As you observe, the lack of the QHsm_getState() operation has a negative impact on the “Transition to History” pattern, which in QEP v4 is much less elegant than before.
Let me try to explain why QHsm_getState() has been eliminated. In the new QHsm implementation, the state handler functions do *not* return superstates. Instead, the state handler functions return simply the status of the event processing (a single byte), such as Q_HANDLED(), Q_TRAN(), or Q_SUPER(). This new design eliminates the recursive definition of the state-handler signature (a state handler no longer returns a state handler) and is more efficient (especially on 8-bit machines). The new design is easier for the compilers, which often had problems with returning a pointer to function from a function (e.g., ImageCraft compiler ICCM8C for Cypress PSoC).
However, the consequence of the new design is that state handler functions now use the internal state variable (QHsm::state) for conveying targets of state transitions or superstates to the QEP event processor. This is fine, because QHsm::state is a private data member and the QEP makes sure that the state variable eventually has the right value. But, during execution of the transition chain (exit and entry actions), the state variable keeps changing and in general does *not* point to the source of the transition.
Of course, it is possible to keep restoring the internal QHsm::state data member to the source of the transition before every call to a state handler function, just for the sake of the QHsm_getState() operation, but it gets expensive. I don’t think that the elegance of the “Transition to History” design pattern justifies the added overhead that would be incurred regardless if QHsm_getState() is ever called.
Miro |
|
|
|
|
|
|