xronos-sdk 0.12.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

 Reactor (std::string_view name, const Context &parent_context)
 Constructor.
Public Member Functions inherited from xronos::sdk::Element
 Element (Element &&)=default
 Move constructor.
virtual ~Element ()=default
 Virtual destructor.
auto add_attribute (std::string_view key, const AttributeValue &value) noexcept -> bool
 Annotate an element with an attribute.
template<std::ranges::input_range R>
requires requires(std::ranges::range_value_t<R> pair) { { pair.first } -> std::convertible_to<std::string_view>; { pair.second } ->
std::convertible_to<AttributeValue>; }
auto add_attributes (const R &range) noexcept -> bool
 Annotate an element with multiple attributes.
auto add_attributes (std::initializer_list< std::pair< std::string_view, AttributeValue > > attributes) -> bool
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
auto fqn () const noexcept -> const std::string &
 Get the element's fully qualified name.
auto name () const noexcept -> const std::string &
 Get the element's name.
auto operator= (Element &&) -> Element &=default
 Move assignment operator.
auto uid () const noexcept -> std::uint64_t
 Get the element's unique ID.

Protected Member Functions

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.
template<class ReactionClass>
requires (std::is_base_of_v<BaseReaction, ReactionClass>)
void add_reaction_with_deadline (std::string_view name, Duration deadline, std::source_location source_location=std::source_location::current())
 Instantiate and add a new reaction with a deadline to the reactor.
template<class T, template< class > class FromSerializer, template< class > class ToSerializer>
requires std::is_same_v<FromSerializer<T>, NoSerializer<T>> || std::is_same_v<ToSerializer<T>, NoSerializer<T>> || std::is_same_v
<FromSerializer<T>, ToSerializer<T>>
void connect (const InputPort< T, FromSerializer > &from, const InputPort< T, ToSerializer > &to)
 Connect two ports.
template<class T, template< class > class FromSerializer, template< class > class ToSerializer>
requires std::is_same_v<FromSerializer<T>, NoSerializer<T>> || std::is_same_v<ToSerializer<T>, NoSerializer<T>> || std::is_same_v
<FromSerializer<T>, ToSerializer<T>>
void connect (const InputPort< T, FromSerializer > &from, const InputPort< T, ToSerializer > &to, Duration delay)
 Connect two ports with a delay.
template<class T, template< class > class FromSerializer, template< class > class ToSerializer>
requires std::is_same_v<FromSerializer<T>, NoSerializer<T>> || std::is_same_v<ToSerializer<T>, NoSerializer<T>> || std::is_same_v
<FromSerializer<T>, ToSerializer<T>>
void connect (const OutputPort< T, FromSerializer > &from, const InputPort< T, ToSerializer > &to)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T, template< class > class FromSerializer, template< class > class ToSerializer>
requires std::is_same_v<FromSerializer<T>, NoSerializer<T>> || std::is_same_v<ToSerializer<T>, NoSerializer<T>> || std::is_same_v
<FromSerializer<T>, ToSerializer<T>>
void connect (const OutputPort< T, FromSerializer > &from, const InputPort< T, ToSerializer > &to, Duration delay)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T, template< class > class FromSerializer, template< class > class ToSerializer>
requires std::is_same_v<FromSerializer<T>, NoSerializer<T>> || std::is_same_v<ToSerializer<T>, NoSerializer<T>> || std::is_same_v
<FromSerializer<T>, ToSerializer<T>>
void connect (const OutputPort< T, FromSerializer > &from, const OutputPort< T, ToSerializer > &to)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class T, template< class > class FromSerializer, template< class > class ToSerializer>
requires std::is_same_v<FromSerializer<T>, NoSerializer<T>> || std::is_same_v<ToSerializer<T>, NoSerializer<T>> || std::is_same_v
<FromSerializer<T>, ToSerializer<T>>
void connect (const OutputPort< T, FromSerializer > &from, const OutputPort< T, ToSerializer > &to, Duration delay)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
auto context (std::source_location source_location=std::source_location::current()) noexcept -> ReactorContext
 Get a context object for constructing reactor elements and contained reactors.
auto get_lag () const noexcept -> Duration
 Get the current lag.
auto get_time () const noexcept -> TimePoint
 Get the current time.
auto get_time_since_startup () const noexcept -> Duration
 Get how far the internal clock has advanced since the startup event.
auto shutdown () noexcept -> Shutdown &
 Get the shutdown event source.
auto startup () const noexcept -> const Startup &
 Get the startup event source.

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,
const Context & parent_context )

Constructor.

Parameters
nameThe name of the reactor instance.
parent_contextEither the environment's or the containing reactor's context.

Member Function Documentation

◆ 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 factory method is intended to be invoked when overloading assemble() in a subclass. It instantiates a reaction and registers it for execution by the runtime.

Template Parameters
ReactionClassThe reaction class to instantiate. This is typically a subclass of Reaction.
Parameters
nameThe name of the reaction
source_locationSource location of the call site. Normally this should be omitted to use the default argument.
See also
assemble()
add_reaction_with_deadline()

◆ add_reaction_with_deadline()

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

Instantiate and add a new reaction with a deadline to the reactor.

This factory method is intended to be invoked when overloading assemble() in a subclass. It instantiates a reaction and registers it for execution by the runtime.

In contrast to add_reaction(), this method annotates the added reaction with a deadline. The deadline is relative to the timestamp of the triggering events. The deadline is violated if the lag exceeds the given duration.

Template Parameters
ReactionClassThe reaction class to instantiate. This is typically a subclass of Reaction.
Parameters
nameThe name of the reaction
deadlineRelative deadline of the reaction
source_locationSource location of the call site. Normally this should be omitted to use the default argument.
See also
assemble()
add_reaction()

◆ assemble()

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

Method that sets up the internal topology of the reactor.

This method needs to be overridden by concrete subclasses. The method is called by the runtime before the execution starts. An implementation of assemble() should call add_reaction() to instantiate the reactor's reactions. If the reactor contains other reactors, their ports may be connected using connect().

◆ connect() [1/2]

template<class T, template< class > class FromSerializer, template< class > class ToSerializer>
requires std::is_same_v<FromSerializer<T>, NoSerializer<T>> || std::is_same_v<ToSerializer<T>, NoSerializer<T>> || std::is_same_v
<FromSerializer<T>, ToSerializer<T>>
void xronos::sdk::Reactor::connect ( const InputPort< T, FromSerializer > & from,
const InputPort< T, ToSerializer > & to )
protected

Connect two ports.

Creates a new connection from the port given in from to the port given in to. Messages are delivered without a delay. This means that the timestamp at which the message is received is the same as the timestamp at which it was sent.

Template Parameters
TValue type associated with events relayed by the connection.
Parameters
fromThe port to draw the connection from
toThe port to draw the connection to.
See also
assemble()

◆ connect() [2/2]

template<class T, template< class > class FromSerializer, template< class > class ToSerializer>
requires std::is_same_v<FromSerializer<T>, NoSerializer<T>> || std::is_same_v<ToSerializer<T>, NoSerializer<T>> || std::is_same_v
<FromSerializer<T>, ToSerializer<T>>
void xronos::sdk::Reactor::connect ( const InputPort< T, FromSerializer > & from,
const InputPort< T, ToSerializer > & 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. Messages are delivered with a delay. This means that the timestamp at which the message is received is the timestamp at which it was sent plus delay.

Template Parameters
TValue type associated with events relayed by the connection.
Parameters
fromThe port to draw the connection from
toThe port to draw the connection to.
delayThe delay to apply to all messages.
See also
assemble()

◆ context()

auto xronos::sdk::Reactor::context ( std::source_location source_location = std::source_location::current()) -> ReactorContext
nodiscardprotectednoexcept

Get a context object for constructing reactor elements and contained reactors.

Parameters
source_locationSource location of the call site. Normally this should be omitted to use the default argument.
Returns
This reactors's context.

◆ get_lag()

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

Get the current lag.

The lag is the difference between wall-clock time and the current time, computed as the current wall-clock reading minus get_time(). While a reaction handler executes, the current time does not advance, but the wall clock does; the lag therefore measures how far the wall clock has run ahead of the internal clock – that is, how far the execution of reactions lags behind the events it processes.

Deprecated
The current time is only well-defined while a reaction handler executes. This reactor-level accessor will be removed in an upcoming release; use the reaction-scoped BaseReaction::lag() instead.
Returns
The current lag as a wall-clock duration.

◆ get_time()

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

Get the current time.

This does not read wall-clock time. The Xronos runtime uses an internal clock to control how a program advances.

Deprecated
The current time is only well-defined while a reaction handler executes. This reactor-level accessor will be removed in an upcoming release; use the reaction-scoped BaseReaction::current_time() instead.
Returns
The current time as provided by the internal clock.

◆ get_time_since_startup()

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

Get how far the internal clock has advanced since the startup event.

Deprecated
The current time is only well-defined while a reaction handler executes. This reactor-level accessor will be removed in an upcoming release; use the reaction-scoped BaseReaction::elapsed_time() instead.
Returns
The difference between the current time given by get_time() and the time at which the program started.

◆ shutdown()

auto xronos::sdk::Reactor::shutdown ( ) -> Shutdown &
nodiscardprotectednoexcept

Get the shutdown event source.

Returns
An event source that triggers once right before the program execution ends.

◆ startup()

auto xronos::sdk::Reactor::startup ( ) const -> const Startup &
nodiscardprotectednoexcept

Get the startup event source.

Returns
An event source that triggers once when the program execution starts.

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