Go to the documentation of this file.
9 #ifndef EAGINE_MESSAGE_BUS_REMOTE_NODE_HPP
10 #define EAGINE_MESSAGE_BUS_REMOTE_NODE_HPP
12 #include "../bitfield.hpp"
13 #include "../build_info.hpp"
14 #include "../callable_ref.hpp"
15 #include "../flat_map.hpp"
16 #include "../identifier_t.hpp"
17 #include "../message_id.hpp"
18 #include "../optional_ref.hpp"
19 #include "../tribool.hpp"
20 #include "../types.hpp"
21 #include "../valid_if/ge0_le1.hpp"
22 #include "../valid_if/nonnegative.hpp"
23 #include "../valid_if/not_empty.hpp"
24 #include "../valid_if/not_zero.hpp"
25 #include "../valid_if/positive.hpp"
66 template <
typename Selector>
69 return enumerator_map_type<remote_node_change, 13>{
105 -> remote_node_changes {
109 class remote_node_tracker_impl;
110 class remote_host_impl;
112 class remote_instance_impl;
113 class remote_instance;
114 class remote_instance_state;
115 class remote_host_state;
116 class remote_node_impl;
118 class remote_node_state;
119 class node_connection_impl;
120 class node_connection;
121 class node_connection_state;
122 class node_connections;
136 : _pimpl{std::move(pimpl)} {}
198 template <
typename Function>
208 template <
typename Function>
217 template <
typename Function>
227 template <
typename Function>
237 template <
typename Function>
248 template <
typename Function>
251 template <
typename Function>
252 void for_each_connection(Function func);
259 template <
typename Function>
260 void for_each_connection(Function func)
const;
265 auto _get_nodes() noexcept -> flat_map<identifier_t, remote_node_state>&;
266 auto _get_hosts() noexcept -> flat_map<host_id_t, remote_host_state>&;
267 auto _get_connections() noexcept -> std::vector<node_connection_state>&;
268 auto _get_connections()
const noexcept
269 ->
const std::vector<node_connection_state>&;
271 std::shared_ptr<remote_node_tracker_impl> _pimpl{};
287 explicit operator bool() const noexcept {
297 auto is_alive() const noexcept ->
bool;
369 auto _impl() const noexcept -> const remote_host_impl*;
370 auto _impl() noexcept -> remote_host_impl*;
374 std::shared_ptr<remote_host_impl> _pimpl{};
384 using remote_host::remote_host;
386 auto should_query_sensors() -> bool;
413 , _tracker{std::move(tracker)} {}
416 explicit operator bool() const noexcept {
426 auto is_alive() const noexcept ->
bool;
436 std::shared_ptr<remote_instance_impl> _pimpl{};
439 remote_node_tracker _tracker{
nothing};
440 auto _impl() const noexcept -> const remote_instance_impl*;
441 auto _impl() noexcept -> remote_instance_impl*;
451 using remote_instance::remote_instance;
469 , _tracker{std::move(tracker)} {}
472 explicit operator bool() const noexcept {
496 auto is_router_node() const noexcept ->
tribool;
501 auto is_bridge_node() const noexcept ->
tribool;
504 auto has_endpoint_info() const noexcept ->
bool;
521 auto is_pingable() const noexcept ->
tribool;
525 void set_ping_interval(std::chrono::milliseconds) noexcept;
534 auto is_responsive() const noexcept ->
tribool;
553 std::shared_ptr<remote_node_impl> _pimpl{};
556 remote_node_tracker _tracker{
nothing};
557 auto _impl() const noexcept -> const remote_node_impl*;
558 auto _impl() noexcept -> remote_node_impl*;
568 using remote_node::remote_node;
586 auto should_ping() -> std::tuple<bool, std::chrono::milliseconds>;
611 , _tracker{std::move(tracker)} {}
614 explicit operator bool() const noexcept {
621 return (_id1 ==
id) || (_id2 ==
id);
627 return ((_id1 == id1) && (_id2 == id2)) ||
628 ((_id1 == id2) && (_id2 == id1));
648 std::shared_ptr<node_connection_impl> _pimpl{};
653 remote_node_tracker _tracker{
nothing};
654 auto _impl() const noexcept -> const node_connection_impl*;
655 auto _impl() noexcept -> node_connection_impl*;
667 using node_connection::node_connection;
683 std::vector<identifier_t> remote_ids,
685 : _origin_id{origin_id}
686 , _remote_ids{std::move(remote_ids)}
687 , _tracker{std::move(tracker)} {}
691 return _tracker.get_node(_origin_id);
706 EAGINE_ASSERT((index >= 0) && (index < count()));
707 return _tracker.get_connection(
708 _origin_id, _remote_ids[
std_size(index)]);
716 EAGINE_ASSERT((index >= 0) && (index < count()));
717 return _tracker.get_node(_remote_ids[
std_size(index)]);
722 std::vector<identifier_t> _remote_ids{};
723 remote_node_tracker _tracker{
nothing};
726 template <
typename Function>
728 if(EAGINE_LIKELY(_pimpl)) {
735 template <
typename Function>
737 if(EAGINE_LIKELY(_pimpl)) {
744 template <
typename Function>
746 if(EAGINE_LIKELY(_pimpl)) {
747 for(
auto& [node_id, node] : _get_nodes()) {
753 template <
typename Function>
755 if(EAGINE_LIKELY(_pimpl)) {
756 for(
auto& [node_id, node] : _get_nodes()) {
762 template <
typename Function>
766 if(EAGINE_LIKELY(_pimpl)) {
767 for(
auto& [node_id, node] : _get_nodes()) {
768 if(node.instance_id() == inst_id) {
775 template <
typename Function>
779 if(EAGINE_LIKELY(_pimpl)) {
780 for(
auto& [node_id, node] : _get_nodes()) {
781 if(node.host_id() ==
host_id) {
788 template <
typename Function>
789 void remote_node_tracker::for_each_connection(Function func) {
790 if(EAGINE_LIKELY(_pimpl)) {
791 for(
auto& conn : _get_connections()) {
797 template <
typename Function>
798 void remote_node_tracker::for_each_connection(Function func)
const {
799 if(EAGINE_LIKELY(_pimpl)) {
800 for(
const auto& conn : _get_connections()) {
808 #if !EAGINE_LINK_LIBRARY || defined(EAGINE_IMPLEMENTING_LIBRARY)
809 #include <eagine/message_bus/remote_node.inl>
812 #endif // EAGINE_MESSAGE_BUS_REMOTE_NODE_HPP
auto count() const noexcept -> span_size_t
Returns the number of adjacent connections of the origin node.
Definition: remote_node.hpp:697
auto free_ram_size() const noexcept -> valid_if_positive< span_size_t >
Returns the free RAM size on the remote host.
Class providin and manipulating information about remote node changes.
Definition: remote_node.hpp:87
void for_each_instance_node_state(process_instance_id_t inst_id, Function func)
Calls a function on tracked remote bus nodes of an instance (process).
Definition: remote_node.hpp:763
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
@ host_id
The host identifier has appeared or changed.
@ connection_info
The bus connection information has appeared or changed.
Class providing information about connections from the perspective of a node.
Definition: remote_node.hpp:679
static constexpr auto span_size(T v) noexcept
Converts argument to span size type.
Definition: types.hpp:59
@ host_info
The host information has appeared or changed.
auto id() const noexcept -> valid_if_not_zero< host_id_t >
Returns the unique host id.
Definition: remote_node.hpp:292
auto responsivity() const noexcept -> bool
Remote node responsivity has changed.
Definition: remote_node.hpp:92
auto new_instance() const noexcept -> bool
Remote node instance id has changed.
Definition: remote_node.hpp:99
auto get_instance(host_id_t) -> remote_instance_state &
Finds and returns the information about a remote instance (process).
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
auto connects(identifier_t id1, identifier_t id2) const noexcept
Indicates if the connection connects nodes with the specified id.
Definition: remote_node.hpp:626
Class providing information about connection between bus nodes.
Definition: remote_node.hpp:602
Class representing "none" / "nothing" values.
Definition: nothing.hpp:17
Primary template for conditionally valid values.
Definition: decl.hpp:49
Class for manipulating and testing a group of enumeration-based bits.
Definition: bitfield.hpp:19
@ stopped_responding
Node stopped responding to pings.
constexpr auto has(bit_type bit) const noexcept
Tests if the specified bit is set.
Definition: bitfield.hpp:70
Optional reference to an instance of type T.
Definition: optional_ref.hpp:23
@ sensor_values
New sensor values have appeared or changed.
@ started_responding
Node started responding to pings.
auto swap_usage() const noexcept -> valid_if_nonnegative< float >
Returns the swap usage on the remote host (0.0, 1.0).
Definition: remote_node.hpp:359
std::uint32_t host_id_t
Unique host identifier type.
Definition: identifier_t.hpp:25
@ methods_added
New remotly callable methods have been added.
void for_each_node_state(Function func)
Calls a function on each tracked remote bus node.
Definition: remote_node.hpp:754
auto cpu_concurrent_threads() const noexcept -> valid_if_positive< span_size_t >
Returns the number of concurrent threads supported at the host.
Class manipulating information about connection between bus nodes.
Definition: remote_node.hpp:665
auto get_connection(identifier_t node_id1, identifier_t node_id2) -> node_connection_state &
Finds and returns the information about remote node connections.
@ methods_removed
New remotly callable methods have been removed.
constexpr auto has_any(bit_type bit, B... bits) const noexcept -> std::enable_if_t< all_are_same_v< bit_type, B... >, bool >
Tests if any of the specified bits are set.
Definition: bitfield.hpp:106
auto total_swap_size() const noexcept -> valid_if_positive< span_size_t >
Returns the total swap size on the remote host.
Class manipulating information about a remote host of bus nodes.
Definition: remote_node.hpp:382
Tri-state boolean value.
Definition: tribool.hpp:61
Class manipulating information about a remote instance running bus nodes.
Definition: remote_node.hpp:449
auto get(span_size_t index) -> node_connection
Returns the i-th connection of the origin node.
Definition: remote_node.hpp:705
auto long_average_load() const noexcept -> valid_if_nonnegative< float >
Returns the long average load on the remote host.
auto is_alive() const noexcept -> bool
Indicates if the remote host is reachable/alive.
std::uint32_t process_instance_id_t
Unique process identifier type (does not necessarily match to OS PID).
Definition: identifier_t.hpp:22
@ endpoint_info
The endpoint information has appeared or changed.
remote_node_tracker()
Default constructor.
static constexpr auto std_size(T v) noexcept
Converts argument to std size type.
Definition: types.hpp:52
std::uint32_t message_sequence_t
Alias for message sequence number type.
Definition: types.hpp:22
auto is_alive() const noexcept -> bool
Indicates if the remote instance (process) is alive and responsive.
auto origin() -> remote_node
Returns the origin node connected by the listed connections.
Definition: remote_node.hpp:690
auto total_ram_size() const noexcept -> valid_if_positive< span_size_t >
Returns the total RAM size on the remote host.
@ kind
The node kind has appeared or changed.
Class providing information about a remote host of bus nodes.
Definition: remote_node.hpp:280
Message bus endpoint information.
Definition: types.hpp:102
auto host() const noexcept -> remote_host
Returns the information about the host where the instance is running.
Message bus code is placed in this namespace.
Definition: eagine.hpp:58
@ hardware_config
The hardware configuration information has appeared or changed.
void for_each_host(Function func)
Calls a function on each tracked remote host.
Definition: remote_node.hpp:727
node_kind
Message bus node kind enumeration.
Definition: node_kind.hpp:18
remote_node_change
Enumeration of changes tracked about remote message bus nodes.
Definition: remote_node.hpp:36
connection_kind
Message bus connection kind bits enumeration.
Definition: connection_kind.hpp:21
auto get_node(identifier_t node_id) -> remote_node_state &
Finds and returns the state information about a remote bus node.
auto opposite_id(identifier_t id) const noexcept -> valid_if_not_zero< identifier_t >
Returns the id of the node opposite to the node with id in argument.
Definition: remote_node.hpp:633
auto id() const noexcept -> valid_if_not_zero< identifier_t >
Returns the unique id of the remote bus node.
Definition: remote_node.hpp:477
@ instance_id
The endpoint instance id has changed.
void for_each_node(Function func)
Calls a function on each tracked remote bus node.
Definition: remote_node.hpp:745
Basic interface for retrieving message bus connection information.
Definition: connection.hpp:98
Class providing basic system information.
Definition: build_info.hpp:20
void for_each_host_node_state(host_id_t host_id, Function func)
Calls a function on tracked remote bus nodes of a remote host.
Definition: remote_node.hpp:776
auto build() const noexcept -> optional_reference_wrapper< const build_info >
Returns the build information about the program running in the instance.
std::uint64_t identifier_t
The underlying integer type for eagine::identifier.
Definition: identifier_t.hpp:19
Class tracking the state of remote message bus nodes.
Definition: remote_node.hpp:127
auto name() const noexcept -> valid_if_not_empty< string_view >
Returns the name of the remote host.
Class providing information about a remote bus node.
Definition: remote_node.hpp:464
Template type used mostly for function type-tag dispatching.
Definition: type_identity.hpp:19
auto id() const noexcept -> valid_if_not_zero< process_instance_id_t >
Returns the id of the instance unique in the host scope.
Definition: remote_node.hpp:421
Class storing two identifier values representing class/method pair.
Definition: message_id.hpp:25
Class manipulating information about a remote bus node.
Definition: remote_node.hpp:566
auto get_host(host_id_t) -> remote_host_state &
Finds and returns the state information about a remote host.
void for_each_host_state(Function func)
Calls a function on each tracked remote host.
Definition: remote_node.hpp:736
auto ram_usage() const noexcept -> valid_if_nonnegative< float >
Returns the RAM usage on the remote host (0.0, 1.0).
Definition: remote_node.hpp:333
auto short_average_load() const noexcept -> valid_if_nonnegative< float >
Returns the short average load on the remote host.
Class providing information about a remote instance running bus nodes.
Definition: remote_node.hpp:406
auto connects(identifier_t id) const noexcept
Indicates if the connection connects node with the specified id.
Definition: remote_node.hpp:620
@ build_info
The build information has appeared or changed.
auto remote(span_size_t index) -> remote_node
Returns the node connected through the i-th connection.
Definition: remote_node.hpp:715
auto free_swap_size() const noexcept -> valid_if_nonnegative< span_size_t >
Returns the free swap size on the remote host.
static constexpr nothing_t nothing
Constant of nothing_t type.
Definition: nothing.hpp:30