A Xronos program's entry point, launched with xronos run. More...
#include <xronos/sdk/node.hh>
Public Member Functions | |
| Reactor (std::string_view name, const Context &parent_context) | |
| Constructor. | |
| Public Member Functions inherited from xronos::sdk::Reactor | |
| Reactor (std::string_view name, const Context &parent_context) | |
| 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 | |
| template<class T, template< class > class Serializer> requires HasValueTypeName<T> && (std::is_same_v<T, void> || IsSerializer<Serializer<T>, T>) | |
| void | export_port (const InputPort< T, Serializer > &port) |
Declare port as part of this node's interface. | |
| template<class T, template< class > class Serializer, class ExportSerializer> requires HasValueTypeName<T> && IsSerializer<ExportSerializer, T> && std::is_same_v<Serializer<T>, NoSerializer<T>> | |
| void | export_port (const InputPort< T, Serializer > &port, ExportSerializer serializer) |
Declare port with serializer as part of this node's interface. | |
|
template<class T, template< class > class Serializer> requires HasValueTypeName<T> && (std::is_same_v<T, void> || IsSerializer<Serializer<T>, T>) | |
| void | export_port (const OutputPort< T, Serializer > &port) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
|
template<class T, template< class > class Serializer, class ExportSerializer> requires HasValueTypeName<T> && IsSerializer<ExportSerializer, T> && std::is_same_v<Serializer<T>, NoSerializer<T>> | |
| void | export_port (const OutputPort< T, Serializer > &port, ExportSerializer serializer) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| Protected Member Functions inherited from xronos::sdk::Reactor | |
| 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. | |
| template<class ReactionClass> requires (std::is_base_of_v<BaseReaction, ReactionClass>) | |
| void | add_reaction_with_deadline (std::string_view name, Duration deadline, std::source_location source_location=std::source_location::current()) |
| Instantiate and add a new reaction with a deadline to the reactor. | |
| template<class T, template< class > class FromSerializer, template< class > class ToSerializer> requires std::is_same_v<FromSerializer<T>, NoSerializer<T>> || std::is_same_v<ToSerializer<T>, NoSerializer<T>> || std::is_same_v <FromSerializer<T>, ToSerializer<T>> | |
| void | connect (const InputPort< T, FromSerializer > &from, const InputPort< T, ToSerializer > &to) |
| Connect two ports. | |
| template<class T, template< class > class FromSerializer, template< class > class ToSerializer> requires std::is_same_v<FromSerializer<T>, NoSerializer<T>> || std::is_same_v<ToSerializer<T>, NoSerializer<T>> || std::is_same_v <FromSerializer<T>, ToSerializer<T>> | |
| void | connect (const InputPort< T, FromSerializer > &from, const InputPort< T, ToSerializer > &to, Duration delay) |
| Connect two ports with a delay. | |
|
template<class T, template< class > class FromSerializer, template< class > class ToSerializer> requires std::is_same_v<FromSerializer<T>, NoSerializer<T>> || std::is_same_v<ToSerializer<T>, NoSerializer<T>> || std::is_same_v <FromSerializer<T>, ToSerializer<T>> | |
| void | connect (const OutputPort< T, FromSerializer > &from, const InputPort< T, ToSerializer > &to) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
|
template<class T, template< class > class FromSerializer, template< class > class ToSerializer> requires std::is_same_v<FromSerializer<T>, NoSerializer<T>> || std::is_same_v<ToSerializer<T>, NoSerializer<T>> || std::is_same_v <FromSerializer<T>, ToSerializer<T>> | |
| void | connect (const OutputPort< T, FromSerializer > &from, const InputPort< T, ToSerializer > &to, Duration delay) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
|
template<class T, template< class > class FromSerializer, template< class > class ToSerializer> requires std::is_same_v<FromSerializer<T>, NoSerializer<T>> || std::is_same_v<ToSerializer<T>, NoSerializer<T>> || std::is_same_v <FromSerializer<T>, ToSerializer<T>> | |
| void | connect (const OutputPort< T, FromSerializer > &from, const OutputPort< T, ToSerializer > &to) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
|
template<class T, template< class > class FromSerializer, template< class > class ToSerializer> requires std::is_same_v<FromSerializer<T>, NoSerializer<T>> || std::is_same_v<ToSerializer<T>, NoSerializer<T>> || std::is_same_v <FromSerializer<T>, ToSerializer<T>> | |
| void | connect (const OutputPort< T, FromSerializer > &from, const OutputPort< T, ToSerializer > &to, Duration delay) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| auto | context (std::source_location source_location=std::source_location::current()) noexcept -> ReactorContext |
| Get a context object for constructing reactor elements and contained reactors. | |
| auto | shutdown () noexcept -> Shutdown & |
| Get the shutdown event source. | |
| auto | startup () const noexcept -> const Startup & |
| Get the startup event source. | |
A Xronos program's entry point, launched with xronos run.
A node is the root reactor of a program that xronos run loads and runs, in place of a hand-written main() and Environment. Because a Node is a Reactor, it has the full reactor surface: define its behavior with reactions, build and wire child reactors as data members using context(), and override assemble() — which runs automatically when the program starts.
To define a node, derive from Node, add its reactions and any child reactors, and register the class with XRONOS_REGISTER_NODE so xronos run can find it:
|
protected |
Declare port as part of this node's interface.
An exported port is visible outside the node and may be connected to another node's exported port. Ports are internal unless exported. A node's interface is the set of all exported ports.
port must be one of this node's own ports; exporting anything else throws. To export a child reactor's port, give the node a port of its own and connect the two.
This overload exports the port under the encoding named by the serializer the port itself declares, and applies to a valueless port too, which has only one possible encoding. A port left with NoSerializer uses the overload below.
Call this from the constructor or from assemble(), like connect(). Each port may be exported once; exporting the same port twice throws.
| port | One of this node's own ports. |
|
protected |
Declare port with serializer as part of this node's interface.
For a port that declares no serializer of its own. Everything else matches the overloads above.
serializer fixes how the port's values are laid out in bytes; its encoding name is declared alongside the value type's name from ValueType. Two ports connect only when their value type and encoding names are equal. This means that the caller is responsible for ensuring that the encoding and the value type are uniquely named, and that the schema does not change in an incompatible way without changing the name. Prefer a structurally versioned encoding — such as protocol buffers — that tolerates the type gaining or losing fields.
| port | One of this node's own ports, declaring no serializer. |
| serializer | The serializer defining the encoding the port is exported under. |
| xronos::sdk::Reactor::Reactor | ( | std::string_view | name, |
| const Context & | parent_context ) |
Constructor.
| name | The name of the reactor instance. |
| parent_context | Either the environment's or the containing reactor's context. |