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

Active object class (based on QMsm implementation strategy). More...

#include <qp.hpp>

Inheritance diagram for QP::QMActive:
QP::QActive QP::QAsm

Public Member Functions

void init (void const *const e, std::uint_fast8_t const qsId) override
 Virtual function to take the top-most initial transition in the state machine.
void dispatch (QEvt const *const e, std::uint_fast8_t const qsId) override
 Virtual function to dispatch an event to the state machine.
bool isIn (QStateHandler const stateHndl) noexcept override
 Virtual function to check whether the state machine is in a given state.
QStateHandler getStateHandler () const noexcept override
 Virtual method for getting the current state handler.
QMState const * childStateObj (QMState const *const parent) const noexcept
virtual void init (std::uint_fast8_t const qsId)
 Virtual function to take the top-most initial transition in the state machine (overloaded).
Public Member Functions inherited from QP::QActive
QStateHandler childState (QStateHandler const parentHandler) noexcept
void setAttr (std::uint32_t attr1, void const *attr2=nullptr)
 Generic setting of additional attributes (defined in some QP ports).
void start (QPrioSpec const prioSpec, QEvtPtr *const qSto, std::uint_fast16_t const qLen, void *const stkSto, std::uint_fast16_t const stkSize, void const *const par=nullptr)
 Starts execution of an active object and registers the object with the framework.
void stop ()
 Stops execution of an active object and removes it from the framework's supervision.
void register_ () noexcept
 Register this active object to be managed by the framework.
void unregister_ () noexcept
 Un-register the active object from the framework.
void post_ (QEvt const *const e, void const *const sender) noexcept
 Posts an event e directly to the event queue of the active object using the First-In-First-Out (FIFO) policy.
bool postx_ (QEvt const *const e, std::uint_fast16_t const margin, void const *const sender) noexcept
 Posts an event e directly to the event queue of the active object using the First-In-First-Out (FIFO) policy.
void postLIFO (QEvt const *const e) noexcept
 Posts an event e directly to the event queue of the active object using the Last-In-First-Out (LIFO) policy.
QEvt const * get_ () noexcept
 Get an event from the event queue of an active object.
void subscribe (QSignal const sig) const noexcept
 Subscribes for delivery of signal sig to the active object.
void unsubscribe (QSignal const sig) const noexcept
 Unsubscribes from the delivery of signal sig to the active object.
void unsubscribeAll () const noexcept
 Unsubscribes from the delivery of all signals to the active object.
bool defer (QEQueue *const eq, QEvt const *const e) const noexcept
 Defer an event to a given separate event queue.
bool recall (QEQueue *const eq) noexcept
 Recall a deferred event from a given event queue.
std::uint16_t flushDeferred (QEQueue *const eq, std::uint_fast16_t const num=0xFFFFU) const noexcept
 Flush the specified deferred queue eq.
std::uint8_t getPrio () const noexcept
QACTIVE_THREAD_TYPE const & getThread () const &
QACTIVE_THREAD_TYPE const & getThread () const &&=delete
void setThread (QACTIVE_THREAD_TYPE const &thr) noexcept
QACTIVE_OS_OBJ_TYPE const & getOsObject () const &
QACTIVE_OS_OBJ_TYPE const & getOsObject () const &&=delete
virtual bool postFromISR (QEvt const *const e, std::uint_fast16_t const margin, void *par, void const *const sender) noexcept
 The "FromISR" variant used in the QP port to "FreeRTOS".
Public Member Functions inherited from QP::QAsm
virtual ~QAsm () noexcept
 Virtual destructor of the QP::QAsm abstract base class.
QStateHandler state () const noexcept
QMState const * stateObj () const noexcept

Protected Member Functions

 QMActive (QStateHandler const initial) noexcept
 Constructor of QP::QMActive class.
Protected Member Functions inherited from QP::QActive
 QActive (QStateHandler const initial) noexcept
 QActive constructor (abstract base class).
Protected Member Functions inherited from QP::QAsm
 QAsm () noexcept
 Constructor of the QP::QAsm base class.
QState tran (QStateHandler const target) noexcept
 Internal helper function to take a state transition in sublclasses of QP::QAsm.
QState tran_hist (QStateHandler const hist) noexcept
 Internal helper function to take a state transition to history in sublclasses of QP::QAsm.
QState super (QStateHandler const superstate) noexcept
 Internal helper function to indicate superstate of a given state in sublclasses of QP::QAsm.
QState qm_tran (void const *const tatbl) noexcept
 Internal helper function to take a state transition in QP::QMsm.
QState qm_tran_init (void const *const tatbl) noexcept
QState qm_tran_hist (QMState const *const hist, void const *const tatbl) noexcept
 Internal helper function to take a state transition to history in QP::QMsm.
QState qm_entry (QMState const *const s) noexcept
 Internal helper function to execute state entry actions in QP::QMsm.
QState qm_exit (QMState const *const s) noexcept
 Internal helper function to execute state exit actions in QP::QMsm.

Additional Inherited Members

Static Public Member Functions inherited from QP::QActive
static std::uint16_t getQueueUse (std::uint_fast8_t const prio) noexcept
static std::uint16_t getQueueFree (std::uint_fast8_t const prio) noexcept
static std::uint16_t getQueueMin (std::uint_fast8_t const prio) noexcept
static void psInit (QSubscrList *const subscrSto, QSignal const maxSignal) noexcept
 Publish event to all subscribers of a given signal e->sig.
static void publish_ (QEvt const *const e, void const *const sender, std::uint_fast8_t const qsId) noexcept
 Publish event to all subscribers of a given signal e->sig.
static void evtLoop_ (QActive *act)
 Event loop thread routine for executing an active object act (defined some in QP ports).
static QActivefromRegistry (std::uint_fast8_t const prio)
static void publishFromISR (QEvt const *e, void *par, void const *sender) noexcept
 The "FromISR" variant used in the QP port to "FreeRTOS".
Static Public Member Functions inherited from QP::QAsm
static constexpr QState Q_HANDLED ()
static constexpr QState Q_UNHANDLED ()
static constexpr QState QM_HANDLED ()
static constexpr QState QM_UNHANDLED ()
static constexpr QState QM_SUPER ()
static QState top (void *const me, QEvt const *const e) noexcept
 Top state handler that ignores all events.
Public Attributes inherited from QP::QAsm
QAsmAttr m_state
 Current state (pointer to the current state-handler function).
QAsmAttr m_temp
 Temporary storage for target/act-table etc.
Static Public Attributes inherited from QP::QAsm
static constexpr QState Q_RET_SUPER {0U}
static constexpr QState Q_RET_UNHANDLED {1U}
static constexpr QState Q_RET_HANDLED {2U}
static constexpr QState Q_RET_TRAN {3U}
static constexpr QState Q_RET_TRAN_HIST {4U}
static constexpr QState Q_RET_IGNORED {5U}
static constexpr QState Q_RET_ENTRY {6U}
static constexpr QState Q_RET_EXIT {7U}
static constexpr QState Q_RET_TRAN_INIT {8U}
static constexpr QSignal Q_EMPTY_SIG {0U}
static constexpr QSignal Q_ENTRY_SIG {1U}
static constexpr QSignal Q_EXIT_SIG {2U}
static constexpr QSignal Q_INIT_SIG {3U}
static constexpr QMState const * QM_STATE_NULL { nullptr }
static constexpr QActionHandler const Q_ACTION_NULL { nullptr }

Detailed Description

Active object class (based on QMsm implementation strategy).

Details
QP::QMActive represents an active object that uses the QP::QMsm style state machine implementation strategy. This strategy requires the use of the QM modeling tool to generate state machine code automatically, but the code is faster than in the QP::QHsm style implementation strategy and needs less run-time support (smaller event-processor).

Note
QP::QMActive is not intended to be instantiated directly, but rather serves as the base class for derivation of active objects in the application.

Usage
The following example illustrates how to derive an active object from QP::QMActive. Please note the call to the QMActive constructor in the Philo subclass' constructor.

class Philo : public QP::QMActive { // <====
private:
QP::QTimeEvt m_timeEvt;
public:
Philo::Philo()
: QMActive(Q_STATE_CAST(&initial)), // <===
m_timeEvt(this, TIMEOUT_SIG, 0U)
{}
protected:
QM_STATE_DECL( initial);
QM_STATE_DECL( thinking);
QM_ACTION_DECL(thinking_e);
QM_ACTION_DECL(thinking_x);
. . .
}; // class Philo
Active object class (based on QMsm implementation strategy).
Definition qp.hpp:643
QMActive(QStateHandler const initial) noexcept
Constructor of QP::QMActive class.
Definition qf_qmact.cpp:48
Time Event class.
Definition qp.hpp:664
#define Q_STATE_CAST(handler_)
Perform cast to QP::QStateHandler.
Definition qp.hpp:389
#define QM_STATE_DECL(state_)
Definition qp.hpp:391
#define QM_ACTION_DECL(action_)
Definition qp.hpp:396

Backward Traceability

  • SRS_QP_SM_21: QP/C++ Framework should provide a State Machine Implementation Strategy optimized for "automatic code generation"
  • SDS_QP_QMActive: QMActive Active Object class.

Definition at line 643 of file qp.hpp.

Constructor & Destructor Documentation

◆ QMActive()

QP::QMActive::QMActive ( QStateHandler const initial)
explicitprotectednoexcept

Constructor of QP::QMActive class.

Details
Performs the first step of active object initialization by assigning the virtual pointer and calling the superclass constructor.

Parameters
[in]initialpointer to the event to be dispatched to the MSM
Note
Must be called only ONCE before QASM_INIT().

Definition at line 48 of file qf_qmact.cpp.

Member Function Documentation

◆ init() [1/2]

void QP::QMActive::init ( void const *const e,
std::uint_fast8_t const qsId )
overridevirtual

Virtual function to take the top-most initial transition in the state machine.

Details
Synchronously executes the top-most initial transition in a state machine (must be overridden in the subclasses).

Parameters
[in]epointer to an initialization parameter (might be nullptr)
[in]qsIdQS-id of this state machine (for QS local filter)

Reimplemented from QP::QActive.

Definition at line 58 of file qf_qmact.cpp.

◆ dispatch()

void QP::QMActive::dispatch ( QEvt const *const e,
std::uint_fast8_t const qsId )
overridevirtual

Virtual function to dispatch an event to the state machine.

Details
Synchronously dispatches an event for processing to a state machine (must be overridden in the subclasses). The processing of an event represents one run-to-completion (RTC) step.

Parameters
[in]epointer to the event to be dispatched to the MSM
[in]qsIdQS-id of this state machine (for QS local filter)

Reimplemented from QP::QActive.

Definition at line 66 of file qf_qmact.cpp.

◆ isIn()

bool QP::QMActive::isIn ( QStateHandler const state)
overridevirtualnoexcept

Virtual function to check whether the state machine is in a given state.

Details
Tests if a given state is part of the current active state configuration. Please note that in a hierarchical state machine, to "be in a state" means also to be in a superstate of the state.

Parameters
[in]statepointer to the state-handler function to be checked
Returns
'true' if the state machine "is in" the state and 'false' otherwise
Attention
The QAsm::isIn() operation is available only for tracing/testing (when Q_SPY is defined). This is to prevent the following problematic uses of the "is-in" query:
  • Querying the current state inside the state machine in question (e.g., as a guard condition based on QAsm::isIn()) is generally a bad design and often makes no sense because the state machine might be in the middle of a transition, where the current state is not well-defined.
  • Querying the current state of a concurrently executing state machine (e.g., from one active object to the other) is a bad idea because such a state can change asynchronously. Also, the other state machine might be in the middle of a state transition, where the "current state" is not well-defined.
  • Querying the current state requires exposing the state handlers to the rest of the system. (The QAsm::isIn() requires the state-handler parameter).

Backward Traceability

  • SRS_QP_SM_25: All State Machine Implementation Strategies provided by the QP/C++ Framework might supply a method for checking if a state machine is in a given state.

Reimplemented from QP::QActive.

Definition at line 74 of file qf_qmact.cpp.

◆ getStateHandler()

QStateHandler QP::QMActive::getStateHandler ( ) const
overridevirtualnoexcept

Virtual method for getting the current state handler.

Details
This virtual call applies to all subclasses of QP::QAsm, such as: QP::QHsm, QP::QMsm, QP::QActive, and QP::QMActive.

Returns
the current state-handler of the type QP::QStateHandler (pointer to function)
Note
This function can be called in any context (including from a critical section) and also not necessarily in the "stable state configuration". When called during a state transition in the state machine, it returns the source state.

Backward Traceability

  • SRS_QP_SM_26: All State Machine Implementation Strategies provided by the QP/C++ Framework might supply a method for obtaining the current state.

Usage
The following example illustrates how to obtain the current state handler of an Active Object:

QStateHandler handler = myAO->getStateHandler();
QState(*)(void *const me, QEvt const *const e) QStateHandler
Pointer to a state-handler function.
Definition qp.hpp:138

Reimplemented from QP::QActive.

Definition at line 85 of file qf_qmact.cpp.

◆ childStateObj()

QMState const * QP::QMActive::childStateObj ( QMState const *const parent) const
noexcept

Definition at line 79 of file qf_qmact.cpp.

◆ init() [2/2]

void QP::QAsm::init ( std::uint_fast8_t const qsId)
virtual

Virtual function to take the top-most initial transition in the state machine (overloaded).

Details
Synchronously executes the top-most initial transition in a state machine. This overloaded version takes no initialization parameter.

Parameters
[in]qsIdQS-id of this state machine (for QS local filter)

Reimplemented from QP::QActive.

Definition at line 513 of file qf_act.cpp.


The documentation for this class was generated from the following files: