xronos-sdk 0.2.0
Xronos C++ SDK
 
Loading...
Searching...
No Matches
xronos::sdk::Reactor Class Referenceabstract

An abstract reactor that can be subclassed to define new reactors. More...

#include <xronos/sdk/reactor.hh>

Inheritance diagram for xronos::sdk::Reactor:
[legend]

Public Member Functions

virtual ~Reactor ()=default
 Correct deletion of an instance of a derived class is permitted.
 
 Reactor (std::string_view name, Context parent_context)
 Construct a new Reactor object.
 
- Public Member Functions inherited from xronos::sdk::Element
auto name () const noexcept -> const std::string &
 The name of the current element.
 
auto fqn () const noexcept -> const std::string &
 The fully qualified name of the current element.
 

Protected Member Functions

auto get_time () const noexcept -> TimePoint
 Get the current point in time.
 
auto get_lag () const noexcept -> Duration
 Get the current lag.
 
auto get_time_since_startup () const noexcept -> Duration
 Get the time that passed since the startup event.
 
auto startup () const noexcept -> const EventSource< void > &
 Startup event.
 
auto shutdown () const noexcept -> const EventSource< void > &
 Shutdown event.
 
void request_shutdown () noexcept
 Request the termination of the currently running reactor program.
 
template<class T>
void connect (const InputPort< T > &from, const InputPort< T > &to)
 Connect two ports.
 
template<class T>
void connect (const OutputPort< T > &from, const OutputPort< T > &to)
 
template<class T>
void connect (const OutputPort< T > &from, const InputPort< T > &to)
 
template<class T>
void connect (const InputPort< T > &from, const InputPort< T > &to, Duration delay)
 Connect two ports with a delay.
 
template<class T>
void connect (const OutputPort< T > &from, const OutputPort< T > &to, Duration delay)
 
template<class T>
void connect (const OutputPort< T > &from, const InputPort< T > &to, Duration delay)
 
template<class ReactionClass>
requires (std::is_base_of_v<BaseReaction, ReactionClass>)
void add_reaction (std::string_view name, std::source_location source_location=std::source_location::current())
 Instantiate and add a new reaction to the reactor.
 

Private Member Functions

virtual void assemble ()=0
 Method that sets up the internal topology of the reactor.
 

Detailed Description

An abstract reactor that can be subclassed to define new reactors.

Constructor & Destructor Documentation

◆ Reactor()

xronos::sdk::Reactor::Reactor ( std::string_view name,
Context parent_context )

Construct a new Reactor object.

Parameters
nameThe name of the reactor instance.
parent_contextThe initialization context of the reactor's parent reactor or environment, typically obtained from Reactor::context or Environment::context.

Member Function Documentation

◆ get_time()

auto xronos::sdk::Reactor::get_time ( ) const -> TimePoint
nodiscardprotectednoexcept

Get the current point in time.

This does not read wall-clock time. The xronos runtime uses an internal clock to control how a program advances. Reactor::get_time reads the current time as measured by the internal clock.

Returns
TimePoint The current point in time.

◆ get_lag()

auto xronos::sdk::Reactor::get_lag ( ) const -> Duration
nodiscardprotectednoexcept

Get the current lag.

Since time in the xronos runtime does not advance while reactions execute, the internal clock may advance slower than a wall clock would. The lag denotes the difference between the wall clock and the internal clock. It is a measure of how far the execution of reactions lags behind events in the physical world.

Returns
Duration The current lag.

◆ get_time_since_startup()

auto xronos::sdk::Reactor::get_time_since_startup ( ) const -> Duration
nodiscardprotectednoexcept

Get the time that passed since the startup event.

Returns
Duration The difference between the current time point given by Reactor::get_time and the time at which the program started.

◆ startup()

auto xronos::sdk::Reactor::startup ( ) const -> const EventSource<void>&
nodiscardprotectednoexcept

Startup event.

Returns
const EventSource<void>& The event that triggers once when the program execution starts.

◆ shutdown()

auto xronos::sdk::Reactor::shutdown ( ) const -> const EventSource<void>&
nodiscardprotectednoexcept

Shutdown event.

Returns
const EventSource<void>& The event that triggers once right before the program execution ends.

◆ request_shutdown()

void xronos::sdk::Reactor::request_shutdown ( )
protectednoexcept

Request the termination of the currently running reactor program.

Terminates a program started with Environment::execute at the next convenience. This triggers Reactor::shutdown after completing all currently active reactions, and stops program execution after processing all reactions triggered by Reactor::shutdown.

◆ connect() [1/6]

template<class T>
void xronos::sdk::Reactor::connect ( const InputPort< T > & from,
const InputPort< T > & to )
protected

Connect two ports.

Creates a new connection from the port given in from to the port given in to.

This is intended to be invoked in Reactor::assemble.

Template Parameters
TThe type carried by the connection.
Parameters
fromThe port to draw the connection from.
toThe port to draw the connection to.

◆ connect() [2/6]

template<class T>
void xronos::sdk::Reactor::connect ( const OutputPort< T > & from,
const OutputPort< T > & to )
protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ connect() [3/6]

template<class T>
void xronos::sdk::Reactor::connect ( const OutputPort< T > & from,
const InputPort< T > & to )
protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ connect() [4/6]

template<class T>
void xronos::sdk::Reactor::connect ( const InputPort< T > & from,
const InputPort< T > & to,
Duration delay )
protected

Connect two ports with a delay.

Creates a new connection from the port given in from to the port given in to.

This is intended to be invoked in Reactor::assemble.

Template Parameters
TThe type carried by the connection.
Parameters
fromThe port to draw the connection from.
toThe port to draw the connection to.
delayThe connection waits for delay before delivering the messages to to.

◆ connect() [5/6]

template<class T>
void xronos::sdk::Reactor::connect ( const OutputPort< T > & from,
const OutputPort< T > & to,
Duration delay )
protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ connect() [6/6]

template<class T>
void xronos::sdk::Reactor::connect ( const OutputPort< T > & from,
const InputPort< T > & to,
Duration delay )
protected

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ add_reaction()

template<class ReactionClass>
requires (std::is_base_of_v<BaseReaction, ReactionClass>)
void xronos::sdk::Reactor::add_reaction ( std::string_view name,
std::source_location source_location = std::source_location::current() )
protected

Instantiate and add a new reaction to the reactor.

This is intended to be invoked in Reactor::assemble and is the only way to correctly register a reaction for execution by the runtime.

Template Parameters
ReactionClassThe reaction to instantiate. This is typically a subclass of Reaction.

◆ assemble()

virtual void xronos::sdk::Reactor::assemble ( )
privatepure virtual

Method that sets up the internal topology of the reactor.

This method should be overridden by application code so that the xronos framework can correctly connect ports and instantiate reactions during program initialization.


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