xronos-sdk 0.9.0
Xronos C++ SDK
Loading...
Searching...
No Matches
xronos::sdk::BaseReaction Class Referenceabstract

Base class for implementing reactions. More...

#include <xronos/sdk/reaction.hh>

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

Classes

class  Trigger
 Declares a reaction trigger and provides read access to the triggering EventSource. 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  MetricEffect
 Allows a reaction to record telemetry data using a given Metric. More...
class  ShutdownEffect
 Allows a reaction to terminate the program. More...

Public Member Functions

 BaseReaction (const ReactionProperties &properties)
 Constructor.
Public Member Functions inherited from xronos::sdk::Element
auto name () const noexcept -> const std::string &
 Get the element's name.
auto fqn () const noexcept -> const std::string &
 Get the element's fully qualified name.
auto uid () const noexcept -> std::uint64_t
 Get the element's unique ID.
auto add_attribute (std::string_view key, const AttributeValue &value) noexcept -> bool
 Annotate an element with an attribute.
template<std::ranges::input_range R>
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.
virtual ~Element ()=default
 Virtual destructor.
 Element (Element &&)=default
 Move constructor.
auto operator= (Element &&) -> Element &=default
 Move assignment operator.

Protected Member Functions

auto deadline () const noexcept -> std::optional< TimePoint >
 Get the deadline associated with the current handler invocation.
auto remaining_slack () const noexcept -> Duration
 Get the time remaining until the deadline.
auto is_before_deadline () const noexcept -> bool
 Check if the currently executing handler is before the deadline.
auto context () noexcept -> auto
 Get a context object for constructing reaction triggers and effects Reaction effect classes..

Private Member Functions

virtual void handler ()=0
 The reaction handler.

Detailed Description

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.

See also
Reaction
Reactor::add_reaction()

Constructor & Destructor Documentation

◆ BaseReaction()

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.

Member Function Documentation

◆ deadline()

auto xronos::sdk::BaseReaction::deadline ( ) const -> std::optional< TimePoint >
nodiscardprotectednoexcept

Get the deadline associated with the current handler invocation.

If the reaction was created using Reactor::add_reaction_with_deadline(), this returns the absolute deadline (time point) until which the handler needs to complete.

This should only be called from the reaction handler.

Returns
The deadline for the current handler invocation or std::nullopt if no deadline is set.

◆ remaining_slack()

auto xronos::sdk::BaseReaction::remaining_slack ( ) const -> Duration
nodiscardprotectednoexcept

Get the time remaining until the deadline.

Calculates the remaining time for completing the handler within the deadline. A negative slack indicates that the deadline was violated.

This should only be called from the reaction handler.

Returns
The time left for completing the handler without violating the deadline. If there is no deadline, Duration::max() is returned.

◆ is_before_deadline()

auto xronos::sdk::BaseReaction::is_before_deadline ( ) const -> bool
nodiscardprotectednoexcept

Check if the currently executing handler is before the deadline.

This should only be called from the reaction handler.

Returns
true if the execution is before the deadline and false if the deadline was missed.

◆ context()

auto xronos::sdk::BaseReaction::context ( ) -> auto
nodiscardprotectednoexcept

Get a context object for constructing reaction triggers and effects Reaction effect classes..

Returns
This reaction's context.

◆ handler()

virtual void xronos::sdk::BaseReaction::handler ( )
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.


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