Base class for implementing reactions. More...
#include <xronos/sdk/reaction.hh>
Classes | |
| class | MetricEffect |
| Allows a reaction to record telemetry data using a given Metric. More... | |
| class | PortEffect |
| Allows a reaction to write data to a given Port. More... | |
| class | ProgrammableTimerEffect |
| Allows a reaction to schedule future events using a ProgrammableTimer. More... | |
| class | ShutdownEffect |
| Allows a reaction to terminate the program. More... | |
| class | Trigger |
| Declares a reaction trigger and provides read access to the triggering EventSource. More... | |
Public Member Functions | |
| BaseReaction (const ReactionProperties &properties) | |
| 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 | |
| auto | context () noexcept -> auto |
| Get a context object for constructing reaction triggers and effects Reaction effect classes.. | |
| auto | current_time () const noexcept -> TimePoint |
| Get the current time. | |
| auto | deadline () const noexcept -> std::optional< TimePoint > |
| Get the deadline associated with the current handler invocation. | |
| auto | elapsed_time () const noexcept -> Duration |
| Get how far the internal clock has advanced since the startup event. | |
| auto | is_before_deadline () const noexcept -> bool |
| Check whether the currently executing handler is still within its deadline. | |
| auto | lag () const noexcept -> Duration |
| Get the current lag. | |
| auto | remaining_slack () const noexcept -> Duration |
| auto | slack () const noexcept -> Duration |
| Get the remaining slack before the deadline. | |
Private Member Functions | |
| virtual void | handler ()=0 |
| The reaction handler. | |
Base class for implementing reactions.
In the Xronos SDK, reactions define the behavior of a reactor. Reactions have one or more triggers and may have effects Reaction effect classes.. The reaction's behavior is defined by overriding the handler() method, which is invoked automatically for any event received on the triggers.
Typically, user reactions should not inherit from BaseReaction directly and use Reaction instead as it provides additional tools for accessing other reactor elements and reactor state.
Note that reaction classes may not be instantiated directly. Use the Reactor::add_reaction() factory method instead.
| xronos::sdk::BaseReaction::BaseReaction | ( | const ReactionProperties & | properties | ) |
Constructor.
Since ReactionProperties has no public constructor, this constructor cannot be invoked directly. Use the Reactor::add_reaction() factory method instead.
|
nodiscardprotectednoexcept |
Get a context object for constructing reaction triggers and effects Reaction effect classes..
|
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, and this returns the current reading of that clock. The internal clock does not advance while a reaction handler executes, so this value does not change while the handler runs: any two reads within the same handler return the same value.
This is a reaction-scoped accessor and is only meaningful while the reaction handler executes; values read outside a handler must not be relied upon. If the program is not yet executing (for example, when called during the reaction's construction or member initialization), this returns a default value: the epoch (a default-constructed TimePoint).
|
nodiscardprotectednoexcept |
Get the deadline associated with the current handler invocation.
If the reaction was created using Reactor::add_reaction_with_deadline() with a deadline duration D, this returns the wall-clock instant by which the handler must complete, equal to current_time() + D. It is therefore anchored to current_time() and stays fixed for the duration of the handler. The handler meets its deadline if it completes before the wall clock reaches this instant.
This should only be called from the reaction handler. If called outside of program execution (e.g. during reaction declaration), this returns std::nullopt.
|
nodiscardprotectednoexcept |
Get how far the internal clock has advanced since the startup event.
This is the difference between the current time and the time at which the program started. It is measured on the internal clock and does not depend on wall-clock time. Like current_time(), it does not change while a reaction handler executes.
This is a reaction-scoped accessor and is only meaningful while the reaction handler executes; values read outside a handler must not be relied upon. If the program is not yet executing (for example, when called during the reaction's construction or member initialization), this returns a default value: zero.
|
privatepure virtual |
The reaction handler.
This method is invoked automatically in response to triggering events. User code must override this method to define a reaction's behavior.
|
nodiscardprotectednoexcept |
Check whether the currently executing handler is still within its deadline.
This should only be called from the reaction handler.
|
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 current_time(). It relates the internal clock to the advancing wall clock and therefore changes while the handler runs: the current time does not advance, but the wall clock does, so the lag 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.
This is a reaction-scoped accessor and is only meaningful while the reaction handler executes; values read outside a handler must not be relied upon. If the program is not yet executing (for example, when called during the reaction's construction or member initialization), this returns a default value: zero.
|
nodiscardprotectednoexcept |
|
nodiscardprotectednoexcept |
Get the remaining slack before the deadline.
This is the remaining wall-clock duration before the deadline, computed as deadline() minus the current wall-clock reading. Equivalently, for a declared deadline duration D it is D - lag(): the lag and the slack always sum to D, so as the lag grows during the handler the slack shrinks by the same amount. The slack denotes how much further the lag may grow before the deadline is violated. A negative value means the deadline has been missed: the wall clock has passed the deadline.
This should only be called from the reaction handler.