QP/C++ 8.1.2
Real-Time Event Framework
Loading...
Searching...
No Matches
Algorithm Viewpoint

Time ViewpointInterface Viewpoint

Viewpoint


SDS_QP_ALG_VP

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:

  • Explanation of algorithms applied
  • Analysis of algorithms regarding their correctness under various scenarios
  • Analysis of algorithms about their efficiency and time-space performance
  • Analysis of algorithms about their testability
Remarks
This viewpoint describes the internal design and algorithms from the perspective of the QP/C++ Framework. It frequently references the State Dynamics Viewpoint, which describes how QP/C++ Application implements hierarchical state machines based on the QP::QHsm and QP::QMsm base classes.


QHsm Implementation View

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.

Remarks
Dispatching events to a hierarchical state machine is the most complicated part in the state machine implementation strategy. Most other aspects of the QP::QHsm class, such as implementing the top-most initial transition, can be understood as a special case of event dispatching, so it won't be covered here.

SDS_QP_QHsm_dispatch

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

explicit QHsm(QStateHandler const initial) noexcept;



SDS_QP_QHsm_init

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

[1] void QHsm::init_(void const * const par) {
. . .
// execute the top-most initial tran.
[2] r = (*m_temp.fun)(this, par);
// find all superstates of the target state and store them in array path[]
[3] . . .
[4] enter_target_(&path[0], ip);
}



SDS_QP_QHsm_dispatch

QHsm Event Dispatching

Description



SDS_QP_QHsm_tran-simple

QHsm Simple Transition

Description



SDS_QP_QHsm_tran-complex

QHsm Complex Transition

Description


QMsm Implementation View

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.


SDS_QP_QMsm_ctor

QMsm Constructor

Description



SDS_QP_QMsm_init

QMsm Top-most Initial Transition

Description



SDS_QP_QMsm_disp

QMsm Event Dispatching

Description



SDS_QP_QMsm_tran

QMsm Transition

Description



SDS_QP_QMsm_tat

QMsm Transition Action Tables

Description


Time ViewpointInterface Viewpoint