xronos-sdk 0.14.0
Xronos C++ SDK
Loading...
Searching...
No Matches
xronos::sdk::PhysicalEvent< T > Class Template Referencefinal

A reactor element for receiving events from external sources. More...

#include <xronos/sdk/physical_event.hh>

Inheritance diagram for xronos::sdk::PhysicalEvent< T >:
[legend]

Public Member Functions

 PhysicalEvent (std::string_view name, const ReactorContext &context)
 Constructor.
auto trigger () noexcept -> TriggerStatus requires(std::is_same_v< T, void >)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class U>
auto trigger (const U &value) -> TriggerStatus requires(!std::is_same_v< U, void > &&std::is_same_v< T, U >)
 Emit a new event with an associated value and trigger reactions.
auto trigger (const Value< T > &value) -> TriggerStatus requires(!std::is_same_v< T, void >)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
auto trigger (const ValueView< T > &view) -> TriggerStatus requires(!std::is_same_v< T, void >)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<class U>
auto trigger (U &&value) -> TriggerStatus requires(!std::is_same_v< U, void > &&std::is_same_v< T, U >)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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.

Detailed Description

template<class T>
class xronos::sdk::PhysicalEvent< T >

A reactor element for receiving events from external sources.

Physical events may be used to trigger reactions from a context outside of the scope of the reactor program. These could be external event handlers that respond to sensor inputs.

Can be used as a reaction trigger allowing the reaction handler to read the associated value.

trigger may be called from any thread, and is safe while this element and its Environment are alive. This includes calls concurrent with program startup, with shutdown, and with Environment::execute returning. Once the program has stopped, every attempt returns TriggerStatus::Stopped; sensor threads should treat that status as the signal to exit.

Template Parameters
TThe type of values carried by emitted events.

Constructor & Destructor Documentation

◆ PhysicalEvent()

template<class T>
xronos::sdk::PhysicalEvent< T >::PhysicalEvent ( std::string_view name,
const ReactorContext & context )

Constructor.

Parameters
nameThe name of the physical event.
contextThe containing reactor's context.

Member Function Documentation

◆ trigger() [1/5]

template<class T>
auto xronos::sdk::PhysicalEvent< T >::trigger ( ) -> TriggerStatus requires(std::is_same_v< T, void >)
nodiscardnoexcept

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

Emits an event without an associated value. This is only available if T is void.

◆ trigger() [2/5]

template<class T>
template<class U>
auto xronos::sdk::PhysicalEvent< T >::trigger ( const U & value) -> TriggerStatus requires(!std::is_same_v< U, void > &&std::is_same_v< T, U >)
nodiscard

Emit a new event with an associated value and trigger reactions.

The event will be assigned a timestamp equal to the current wall-clock time.

May be called from any thread while this element and its Environment are alive (see PhysicalEvent). Events emitted while the program is not running are dropped, and the status reports why.

Parameters
valueThe value to be associated with the emitted event.
Returns
The outcome of the attempt. TriggerStatus::Accepted on success.

◆ trigger() [3/5]

template<class T>
auto xronos::sdk::PhysicalEvent< T >::trigger ( const Value< T > & value) -> TriggerStatus requires(!std::is_same_v< T, void >)
nodiscard

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

Emits the given value without copying it.

Exceptions
std::invalid_argumentIf the value is empty.

◆ trigger() [4/5]

template<class T>
auto xronos::sdk::PhysicalEvent< T >::trigger ( const ValueView< T > & view) -> TriggerStatus requires(!std::is_same_v< T, void >)
nodiscard

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

Emits the viewed value without copying it.

Exceptions
std::invalid_argumentIf the view is absent.

◆ trigger() [5/5]

template<class T>
template<class U>
auto xronos::sdk::PhysicalEvent< T >::trigger ( U && value) -> TriggerStatus requires(!std::is_same_v< U, void > &&std::is_same_v< T, U >)
nodiscard

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

Move constructs the value using the given rvalue reference.


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