iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
node_state.hpp
Go to the documentation of this file.
1// Copyright (c) 2024 Contributors to the Eclipse Foundation
2//
3// See the NOTICE file(s) distributed with this work for additional
4// information regarding copyright ownership.
5//
6// This program and the accompanying materials are made available under the
7// terms of the Apache Software License 2.0 which is available at
8// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
9// which is available at https://opensource.org/licenses/MIT.
10//
11// SPDX-License-Identifier: Apache-2.0 OR MIT
12
13#ifndef IOX2_NODE_STATE_HPP
14#define IOX2_NODE_STATE_HPP
15
16#include "iox2/bb/expected.hpp"
17#include "iox2/bb/optional.hpp"
20#include "node_details.hpp"
22#include "service_type.hpp"
23#include "unique_node_id.hpp"
24
25namespace iox2 {
27template <ServiceType>
29 public:
30 AliveNodeView(const AliveNodeView&) = default;
32 auto operator=(const AliveNodeView&) -> AliveNodeView& = default;
33 auto operator=(AliveNodeView&&) -> AliveNodeView& = default;
34 ~AliveNodeView() = default;
35
37
39 auto id() const -> const UniqueNodeId&;
40
43 auto details() const -> const bb::Optional<NodeDetails>&;
44
45 private:
46 UniqueNodeId m_id;
47 bb::Optional<NodeDetails> m_details;
48};
49
51template <ServiceType T>
53 public:
54 DeadNodeView(const DeadNodeView&) = default;
56 auto operator=(const DeadNodeView&) -> DeadNodeView& = default;
57 auto operator=(DeadNodeView&&) -> DeadNodeView& = default;
58 ~DeadNodeView() = default;
59
60 explicit DeadNodeView(const AliveNodeView<T>& view);
61
63 auto id() const -> const UniqueNodeId&;
64
67 auto details() const -> bb::Optional<NodeDetails>;
68
71 auto try_remove_stale_resources() -> iox2::bb::Expected<void, NodeCleanupFailure>;
72
82 auto blocking_remove_stale_resources(iox2::bb::Duration timeout) -> iox2::bb::Expected<void, NodeCleanupFailure>;
83
84 private:
85 AliveNodeView<T> m_view;
86};
87
89template <ServiceType T>
90class NodeState {
91 public:
92 NodeState(const NodeState&) = default;
93 NodeState(NodeState&&) = default;
94 auto operator=(const NodeState&) -> NodeState& = default;
95 auto operator=(NodeState&&) -> NodeState& = default;
96 ~NodeState() = default;
97
100 auto alive(const iox2::bb::StaticFunction<void(AliveNodeView<T>&)>& callback) -> NodeState&;
101
104 auto dead(const iox2::bb::StaticFunction<void(DeadNodeView<T>&)>& callback) -> NodeState&;
105
109
112 auto undefined(const iox2::bb::StaticFunction<void(UniqueNodeId&)>& callback) -> NodeState&;
113
114 private:
115 template <ServiceType>
116 friend auto internal::list_callback(iox2_node_state_e,
117 iox2_unique_node_id_ptr,
118 const char*,
119 iox2_node_name_ptr,
120 iox2_config_ptr,
121 iox2_callback_context) -> iox2_callback_progression_e;
122
123 explicit NodeState(const AliveNodeView<T>& view);
124 explicit NodeState(const DeadNodeView<T>& view);
125 NodeState(iox2_node_state_e node_state, const UniqueNodeId& node_id);
126
128};
129} // namespace iox2
130
131#endif
Contains all details of a [Node] that is alive.
AliveNodeView(AliveNodeView &&)=default
auto id() const -> const UniqueNodeId &
Returns the [NodeId].
AliveNodeView(UniqueNodeId node_id, const bb::Optional< NodeDetails > &details)
AliveNodeView(const AliveNodeView &)=default
~AliveNodeView()=default
auto operator=(AliveNodeView &&) -> AliveNodeView &=default
auto details() const -> const bb::Optional< NodeDetails > &
auto operator=(const AliveNodeView &) -> AliveNodeView &=default
Contains all details of a [Node] that is dead.
DeadNodeView(const AliveNodeView< T > &view)
auto operator=(const DeadNodeView &) -> DeadNodeView &=default
DeadNodeView(DeadNodeView &&)=default
auto id() const -> const UniqueNodeId &
Returns the [NodeId].
~DeadNodeView()=default
DeadNodeView(const DeadNodeView &)=default
auto operator=(DeadNodeView &&) -> DeadNodeView &=default
Contains details of a [Node].
Describes the state of a [Node].
auto operator=(const NodeState &) -> NodeState &=default
auto inaccessible(const iox2::bb::StaticFunction< void(UniqueNodeId &)> &callback) -> NodeState &
auto undefined(const iox2::bb::StaticFunction< void(UniqueNodeId &)> &callback) -> NodeState &
auto alive(const iox2::bb::StaticFunction< void(AliveNodeView< T > &)> &callback) -> NodeState &
auto operator=(NodeState &&) -> NodeState &=default
NodeState(const NodeState &)=default
NodeState(NodeState &&)=default
~NodeState()=default
auto dead(const iox2::bb::StaticFunction< void(DeadNodeView< T > &)> &callback) -> NodeState &
The system-wide unique id of a [Node].
Variant implementation from the C++17 standard with C++11. The interface is inspired by the C++17 sta...
Definition variant.hpp:101
iox2::bb::variation::Optional< T > Optional
Definition optional.hpp:25
auto list_callback(iox2_node_state_e node_state, iox2_unique_node_id_ptr node_id_ptr, const char *executable, iox2_node_name_ptr node_name, iox2_config_ptr config, iox2_callback_context context) -> iox2_callback_progression_e