Algorithm Viewpoint
Purpose
The Algorithm Viewpoint addresses the design concerns related to computational logic, control flow, data transformations, and decision-making mechanisms within the software. It provides a precise, implementation-oriented description of how the software operates, ensuring that the logic is correct, deterministic, analyzable, and traceable to requirements.
Design Concerns
The Algorithm Viewpoint focuses on the following concerns:
The QP::QHsm class (see Figure SDS-CLS [13]) implements the state machine strategy optimized for "manual coding". This section describes the internal design of the QP::QHsm class, with the particular focus on the algorithms used for dispatching events to hierarchical state machines.
QHsm event dispatching
Description
Dispatching an event to an HSM requires implementing the UML state nesting semantics, that is, propagating the event through all the levels of state nesting until it is handled or reaches the top state.
The QHsm constructor associates the state machine with its top-most initial-transition. The top-most initial transition is not executed at this point.
Pseudocode
QHsm Top-most Initial Transition
Description
The top-most initial transition in a hierarchical state machine might be complex because the UML semantics require "drilling" into the state hierarchy with any nested initial transitions encountered in the target states until the leaf state is reached. Unfortunately, this direction of navigation through the state hierarchy is opposite to the natural direction. As you recall, a hierarchical state-handler function provides the superstate, so it's easy to traverse the state hierarchy from substates to superstates. Although this order is very convenient for the efficient implementation of the most frequently used dispatch operation, entering states is more complex. The solution implemented in the QHsm class is to use an automatic array path[] to record the exit path from the target state of the initial transition source, without executing any actions. This is achieved by calling the state handlers with the reserved QEP_EMPTY_SIG_ signal, which causes every state handler to immediately return the superstate without executing any other actions. These superstates are saved in the path[] array until the current state is reached. The stored path[] array is subsequently played backward to enter the target substates (from superstates to substates), which is the exact reversed order in which they were visited.
Pseudocode
QHsm Event Dispatching
Description
QHsm Simple Transition
Description
QHsm Complex Transition
Description
The QP::QMsm class (see Figure SDS-CLS [14]) derived from QP::QAsm implements the state machine strategy optimized for "automatic code generation" (see SRS_QP_SM_21). The QMsm Design View describes how QP Applications implement hierarchical state machines based on the QP::QMsm class. This section describes how the QP::QMsm class itself is internally implemented.
QMsm Constructor
Description
QMsm Top-most Initial Transition
Description
QMsm Event Dispatching
Description
QMsm Transition
Description
QMsm Transition Action Tables
Description