OS  v1.7.5
Documentation
Loading...
Searching...
No Matches
qOS::sm::signalPublisher Class Reference

An object to subscribe FSM(Finite State Machine) objects to specific user-defined signals. More...

#include <fsm.hpp>

Public Member Functions

 signalPublisher ()
 
bool subscribeToSignal (stateMachine &m, sm::signalID s) noexcept
 Subscribe state machine to a particular signal.
 
bool subscribeToSignal (stateMachine &m, sm::signalIDType s) noexcept
 
bool unsubscribeFromSignal (stateMachine &m, sm::signalID s) noexcept
 Unsubscribe state machine from a particular signal.
 
bool unsubscribeFromSignal (stateMachine &m, sm::signalIDType s) noexcept
 
bool sendSignal (sm::signalID sig, void *sData=nullptr, bool isUrgent=false) noexcept
 Sends a signal to all its subscribers.
 
bool sendSignal (sm::signalIDType sig, void *sData=nullptr, bool isUrgent=false) noexcept
 

Detailed Description

An object to subscribe FSM(Finite State Machine) objects to specific user-defined signals.

This object provides a mechanism to decouple signal producers from the signal consumers, so state-machine objects interested in certain signals subscribe to one or more Signals".

Constructor & Destructor Documentation

◆ signalPublisher()

qOS::sm::signalPublisher::signalPublisher ( )

Member Function Documentation

◆ sendSignal() [1/2]

bool qOS::sm::signalPublisher::sendSignal ( sm::signalID sig,
void * sData = nullptr,
bool isUrgent = false )
noexcept

Sends a signal to all its subscribers.

Note
If the signal queue is not available, an exclusion variable will be used.This means that the signal cannot be sent until the variable is empty. (the signal was handled by the state-machine engine).
Remarks
To enable the functionality of sending signals to subscribers, you must set the macros Q_FSM_PS_SIGNALS_MAX and Q_FSM_PS_SUB_PER_SIGNAL_MAX in the configuration file config.h
Warning
Data associated to the signal is not deep-copied to a queue or any buffer. It's only data pointer (address in memory) that is shallow-copied to a signal queue so it has to point to a globally accessible memory. If it pointed to a sender's local variable (from the stack) it would be invalid after sender returns from the function that sends the signal.
Note
The signal-queue event has the highest precedence.
Parameters
[in]sigThe user-defined signal.
[in]sDataThe data associated to the signal.
[in]isUrgentIf true, the signal will be sent to the front of the queue. (only if the there is a signal-queue available)
Returns
true if the provided signal was successfully delivered to the subscribers (if available), otherwise return false. false if there is a queue, and the signal cannot be inserted because it is full.

◆ sendSignal() [2/2]

bool qOS::sm::signalPublisher::sendSignal ( sm::signalIDType sig,
void * sData = nullptr,
bool isUrgent = false )
inlinenoexcept

◆ subscribeToSignal() [1/2]

bool qOS::sm::signalPublisher::subscribeToSignal ( stateMachine & m,
sm::signalID s )
noexcept

Subscribe state machine to a particular signal.

Parameters
[in]mState-machine to be subscribed
[in]sSignal ID to which the subscriber FSM wants to subscribe.
Returns
Returns true on success, otherwise returns false.

◆ subscribeToSignal() [2/2]

bool qOS::sm::signalPublisher::subscribeToSignal ( stateMachine & m,
sm::signalIDType s )
inlinenoexcept

◆ unsubscribeFromSignal() [1/2]

bool qOS::sm::signalPublisher::unsubscribeFromSignal ( stateMachine & m,
sm::signalID s )
noexcept

Unsubscribe state machine from a particular signal.

Parameters
[in]mState-machine to be subscribed
[in]sSignal ID to which the subscriber FSM wants to unsubscribe.
Returns
Returns true on success, otherwise returns false.

◆ unsubscribeFromSignal() [2/2]

bool qOS::sm::signalPublisher::unsubscribeFromSignal ( stateMachine & m,
sm::signalIDType s )
inlinenoexcept