C++ TargetRTS
Loading...
Searching...
No Matches
Public Member Functions | List of all members
RTMultiReceive Class Reference

This utility class can be used by a capsule to keep track of the reception of multiple events. More...

#include <RTMultiReceive.h>

Public Member Functions

 RTMultiReceive (RTActor *actor)
 Construction of an RTMultiReceive object that belongs to a certain capsule instance.
 
 ~RTMultiReceive ()
 Destroy the RTMultiReceive object.
 
void expectEvent (RTEventReceptionInterface *event)
 Set up an expectation that the capsule must receive a certain event.
 
bool eventReceived ()
 Call this function from an internal transition in a state where the capsule is waiting for one or many events to be received (one for each call made to expectEvent()).
 
bool isAllEventsReceived ()
 Answers if all expected events have been received by the capsule.
 
size_t remainingExpectedEventsCount ()
 Returns the number of remaining expected events to be received by the capsule.
 
void reset ()
 Reset the RTMultiReceive object to its initial state so it can be used again.
 
void setOrderMatters (bool orderMatters)
 Controls whether the order in which expected events are received should matter or not.
 
 RTMultiReceive (const RTMultiReceive &other)
 
RTMultiReceiveoperator= (const RTMultiReceive &other)
 

Detailed Description

This utility class can be used by a capsule to keep track of the reception of multiple events.

The typical usecase is to let the capsule wait in a source state until certain expected events have arrived and only after that let it transition to a target state. When entering the source state, set up the expectations on what kinds of events that should be received by calling the expectEvent() function. Then use an internal transition in the source state with triggers for all events that can be received and call eventReceived() in its effect code. The utility will match the received event with the list of expected events. If it matches, and there are no more events expected to be received, then a copy of the last received event is resent to the capsule so it can trigger the transition to the target state. That transition should be guarded by a call to isAllEventsReceived().

Constructor & Destructor Documentation

◆ RTMultiReceive()

RTMultiReceive::RTMultiReceive ( RTActor actor)

Construction of an RTMultiReceive object that belongs to a certain capsule instance.

Typically the RTMultiReceive object is declared as a value member of the capsule class and constructed by passing "this" in the capsule constructor.

Parameters
[in]actorthe capsule instance that owns the RTMultiReceive object

◆ ~RTMultiReceive()

RTMultiReceive::~RTMultiReceive ( )

Destroy the RTMultiReceive object.

Memory for all expected events is freed.

Member Function Documentation

◆ eventReceived()

bool RTMultiReceive::eventReceived ( )

Call this function from an internal transition in a state where the capsule is waiting for one or many events to be received (one for each call made to expectEvent()).

The message that triggered the internal transition will be matched against expected events, and when all expected events have been received, the message will trigger an outgoing transition to enter another state.

Returns
true if all expected events have been received

◆ expectEvent()

void RTMultiReceive::expectEvent ( RTEventReceptionInterface event)

Set up an expectation that the capsule must receive a certain event.

Call this function before the capsule enters a state where it should wait for that event to be received before proceeding to another state. By default, the order in which events are received does not matter. However, if setOrderMatters(true) has been called the events must be received in the order in which this function is called (one call for each expected event). Expectations on received events can either be specified statically using an instance of RTEventReception or dynamically using an instance of RTEventReceptionMsg. The object passed should be created by the caller and will be destroyed by the RTMultiReceive object when no longer needed.

Parameters
[in]eventdescription of what kind of event that is expected to be received

◆ isAllEventsReceived()

bool RTMultiReceive::isAllEventsReceived ( )

Answers if all expected events have been received by the capsule.

Returns
true if all expected events have been received, otherwise false

◆ remainingExpectedEventsCount()

size_t RTMultiReceive::remainingExpectedEventsCount ( )

Returns the number of remaining expected events to be received by the capsule.

Returns
how many more events are expected to be received

◆ reset()

void RTMultiReceive::reset ( )

Reset the RTMultiReceive object to its initial state so it can be used again.

Memory for all currently registered expected events will be deleted.

◆ setOrderMatters()

void RTMultiReceive::setOrderMatters ( bool  orderMatters)

Controls whether the order in which expected events are received should matter or not.

By default the order does not matter.

Parameters
[in]orderMatterstrue, if the order in which expected events are received should matter

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