An abstract reactor that can be subclassed to define new reactors.
More...
#include <xronos/sdk/reactor.hh>
|
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.
|
|
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.
|
|
|
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.
|
|
|
virtual void | assemble ()=0 |
| Method that sets up the internal topology of the reactor.
|
|
An abstract reactor that can be subclassed to define new reactors.
◆ Reactor()
xronos::sdk::Reactor::Reactor |
( |
std::string_view | name, |
|
|
Context | parent_context ) |
Construct a new Reactor
object.
- Parameters
-
name | The name of the reactor instance. |
parent_context | The initialization context of the reactor's parent reactor or environment, typically obtained from Reactor::context or Environment::context . |
◆ 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 |
◆ shutdown()
auto xronos::sdk::Reactor::shutdown |
( |
| ) |
const -> const EventSource<void>& |
|
nodiscardprotectednoexcept |
◆ 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
-
T | The type carried by the connection. |
- Parameters
-
from | The port to draw the connection from. |
to | The port to draw the connection to. |
◆ connect() [2/6]
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]
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]
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
-
T | The type carried by the connection. |
- Parameters
-
from | The port to draw the connection from. |
to | The port to draw the connection to. |
delay | The connection waits for delay before delivering the messages to to . |
◆ connect() [5/6]
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]
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
-
ReactionClass | The 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: