xentara-plugin v2.0.4
The Xentara Plugin Framework
Loading...
Searching...
No Matches
xentara::process::Event Class Referencefinal

A free-standing event provided by an element. More...

#include <xentara/process/Event.hpp>

+ Inheritance diagram for xentara::process::Event:

Classes

class  Role
 A built-in event role. More...
 

Public Member Functions

 Event ()=default
 Constructor for a regular event.
 
 Event (const Role &role)
 Constructor for an event with a certain role.
 
 Event (io::Directions ioDirections)
 Constructor for an I/O event.
 
internal auto ioDirections () const -> io::Directions
 Gets the relevant I/O directions.
 
auto setIoDirections (io::Directions ioDirections) -> void
 Sets the relevant I/O directions.
 
auto addHandler (std::reference_wrapper< EventHandler > handler) const -> void
 Adds an event handler.
 
auto removeHandler (std::reference_wrapper< EventHandler > handler) const -> void
 Removes an event handler.
 
auto raise (std::chrono::system_clock::time_point eventTime) const noexcept -> void
 Raises the event.
 
Depracated functions
 Event (const model::Attribute &attribute)
 deprecated Deprecated constructor for an attribute change event
 
 Event (const model::Attribute::Role &attributeRole)
 deprecated Deprecated constructor for an attribute change event
 
auto fire (std::chrono::system_clock::time_point eventTime=std::chrono::system_clock::now()) const -> void
 deprecated Deprecated alias for raise()
 
- Public Member Functions inherited from xentara::utils::tools::DisableCopy
constexpr DisableCopy () noexcept=default
 
 DisableCopy (const DisableCopy &)=delete
 
DisableCopyoperator= (const DisableCopy &)=delete
 

Static Public Member Functions

template<std::same_as< Event >... Events>
requires (sizeof...(Events) > 0)
static auto raise (std::chrono::system_clock::time_point eventTime, const Events &... events) noexcept -> void
 Raises a list of events atomically.
 
static auto raise (std::chrono::system_clock::time_point eventTime, std::span< std::reference_wrapper< const Event > > events) noexcept -> void
 Raises a list of events atomically.
 

Static Public Attributes

Standard Roles
static const Role kChanged
 The standard role for the change event of a data point.
 
static const Role kConnected
 The standard role for the connection event of an I/O component.
 
static const Role kDisconnected
 The standard role for the disconnection event of an I/O component.
 

Detailed Description

A free-standing event provided by an element.

This class is used by xentara elements to publish so called “free-standing” events, i.e. events that are not change events for attributes. Change events for attributes are published automatically, and do not use process::Event. They can be accessed using ExtendedEvent, or using data::ReadHandle.

See also
ExtendedEvent
Publishing Events
Events in the Xentara user manual

Constructor & Destructor Documentation

◆ Event() [1/5]

xentara::process::Event::Event ( )
default

Constructor for a regular event.

◆ Event() [2/5]

xentara::process::Event::Event ( const Role role)

Constructor for an event with a certain role.

This constructor marks this event as an event with a particular role. If the role is a role for an I/O event, the event is markes as such.

Parameters
roleThe event role.

◆ Event() [3/5]

xentara::process::Event::Event ( io::Directions  ioDirections)

Constructor for an I/O event.

Parameters
ioDirectionsThe relevant I/O directions.

The I/O directions are used for I/O events to specify whether a data point should inherit this event from its attached input and/or output. If the directions contain the flag io::Direction::Input, then the data point will inherit this event from its input. If the directions contain the flag io::Direction::Output, then the data point will inherit this event from its output. If you do not set either flag (the default), then the event will not be considered an I/O event and will not be inherited by any data points. This is equivalent to calling the default constructor.

◆ Event() [4/5]

xentara::process::Event::Event ( const model::Attribute attribute)

deprecated Deprecated constructor for an attribute change event

Deprecated:
Replaced by automatic change events

◆ Event() [5/5]

xentara::process::Event::Event ( const model::Attribute::Role attributeRole)

deprecated Deprecated constructor for an attribute change event

Deprecated:
Replaced by automatic change events

Member Function Documentation

◆ addHandler()

auto xentara::process::Event::addHandler ( std::reference_wrapper< EventHandler handler) const -> void

Adds an event handler.

Parameters
handlerThe handler

◆ fire()

auto xentara::process::Event::fire ( std::chrono::system_clock::time_point  eventTime = std::chrono::system_clock::now()) const -> void

deprecated Deprecated alias for raise()

Deprecated:
Replaced by raise()

◆ ioDirections()

internal auto xentara::process::Event::ioDirections ( ) const -> io::Directions

Gets the relevant I/O directions.

Returns
The I/O directions. The I/O directions are used for I/O events to specify whether a data point should inherit this event from its attached input and/or output.

◆ raise() [1/3]

auto xentara::process::Event::raise ( std::chrono::system_clock::time_point  eventTime) const -> void
noexcept

Raises the event.

This function raises the event asynchronously and returns immediately.

Do not use this function to raise the event as a result of committing a write sentinel. Pass the event to the commit() function of the write sentinel instead. This raises the event atomically together with the change events generated by the write sentinel.

If you need to raise multiple events as the result of the same action, use one of the static overloads of this function instead. The events will then be raised atomically as a block.

Parameters
eventTimeThe (canonical) time the event occurred

◆ raise() [2/3]

template<std::same_as< Event >... Events>
requires (sizeof...(Events) > 0)
static auto xentara::process::Event::raise ( std::chrono::system_clock::time_point  eventTime,
const Events &...  events 
) -> void
staticnoexcept

Raises a list of events atomically.

This function raises all the events atomically. This means, that first, handleEvent() is called for all the handlers of all the events, and then postHandleEvent() is called for all the handlers of all the events. This is different than firing the events separately, where handleEvent() and postHandleEvent() are called for each event in turn.

For example, if you have two handlers, handlerA1 and handlerA2 attached to “Event A”, and two further two handlers, handlerB1 and handlerB2 attached to “Event B”, then the handlers will be executed in the following order:

handlerA1.handleEvent(eventTime);
handlerA2.handleEvent(eventTime);
handlerB1.handleEvent(eventTime);
handlerB2.handleEvent(eventTime);
handlerA1.postHandleEvent(eventTime);
handlerA2.postHandleEvent(eventTime);
handlerB1.postHandleEvent(eventTime);
handlerB2.postHandleEvent(eventTime);

This allows handlers to implement behaviour that handle all the events together.

Parameters
eventTimeThe (canonical) time the event occurred
eventsThe events to trigger

◆ raise() [3/3]

static auto xentara::process::Event::raise ( std::chrono::system_clock::time_point  eventTime,
std::span< std::reference_wrapper< const Event > >  events 
) -> void
staticnoexcept

Raises a list of events atomically.

This function raises all the events atomically. This means, that first, handleEvent() is called for all the handlers of all the events, and then postHandleEvent() is called for all the handlers of all the events. This is different than firing the events separately, where handleEvent() and postHandleEvent() are called for each event in turn.

For example, if you have two handlers, handlerA1 and handlerA2 attached to “Event A”, and two further two handlers, handlerB1 and handlerB2 attached to “Event B”, then the handlers will be executed in the following order:

handlerA1.handleEvent(eventTime);
handlerA2.handleEvent(eventTime);
handlerB1.handleEvent(eventTime);
handlerB2.handleEvent(eventTime);
handlerA1.postHandleEvent(eventTime);
handlerA2.postHandleEvent(eventTime);
handlerB1.postHandleEvent(eventTime);
handlerB2.postHandleEvent(eventTime);

This allows handlers to implement behaviour that handle all the events together.

Parameters
eventTimeThe (canonical) time the event occurred
eventsThe events to trigger
See also
EventList
FixedEventList
StaticEventList

◆ removeHandler()

auto xentara::process::Event::removeHandler ( std::reference_wrapper< EventHandler handler) const -> void

Removes an event handler.

Parameters
handlerThe handler. If the handler is not attached to the event, this function does nothing.

◆ setIoDirections()

auto xentara::process::Event::setIoDirections ( io::Directions  ioDirections) -> void

Sets the relevant I/O directions.

Parameters
ioDirectionsThe desired I/O directions. The I/O directions are used for I/O events to specify whether a data point should inherit this event from its attached input and/or output.

Member Data Documentation

◆ kChanged

const Role xentara::process::Event::kChanged
static

The standard role for the change event of a data point.

◆ kConnected

const Role xentara::process::Event::kConnected
static

The standard role for the connection event of an I/O component.

◆ kDisconnected

const Role xentara::process::Event::kDisconnected
static

The standard role for the disconnection event of an I/O component.