iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
port_factory_blackboard.hpp
Go to the documentation of this file.
1// Copyright (c) 2025 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_PORTFACTORY_BLACKBOARD_HPP
14#define IOX2_PORTFACTORY_BLACKBOARD_HPP
15
17#include "iox2/bb/expected.hpp"
22#include "iox2/iceoryx2.h"
25#include "iox2/node_state.hpp"
28#include "iox2/service_hash.hpp"
29#include "iox2/service_name.hpp"
30#include "iox2/service_type.hpp"
32
33namespace iox2 {
35template <ServiceType S, typename KeyType>
37 public:
41
44
46 auto name() const -> ServiceNameView;
47
49 auto service_hash() const -> ServiceHash;
50
52 auto attributes() const -> AttributeSetView;
53
57
61
66 auto nodes(const iox2::bb::StaticFunction<CallbackProgression(NodeState<S>)>& callback) const
67 -> bb::Expected<void, NodeListFailure>;
68
70 auto writer_builder() const -> PortFactoryWriter<S, KeyType>;
71
73 auto reader_builder() const -> PortFactoryReader<S, KeyType>;
74
77 void list_keys(const iox2::bb::StaticFunction<CallbackProgression(const KeyType&)>& callback) const;
78
84
92 auto blocking_cleanup_dead_nodes(iox2::bb::Duration timeout) const -> CleanupState;
93
94 private:
95 template <typename, ServiceType>
97 template <typename, ServiceType>
99
100 explicit PortFactoryBlackboard(iox2_port_factory_blackboard_h handle);
101 void drop() noexcept;
102
103 iox2_port_factory_blackboard_h m_handle = nullptr;
104};
105
106template <ServiceType S, typename KeyType>
107inline PortFactoryBlackboard<S, KeyType>::PortFactoryBlackboard(iox2_port_factory_blackboard_h handle)
108 : m_handle { handle } {
109}
110
111template <ServiceType S, typename KeyType>
112inline void PortFactoryBlackboard<S, KeyType>::drop() noexcept {
113 if (m_handle != nullptr) {
114 iox2_port_factory_blackboard_drop(m_handle);
115 m_handle = nullptr;
116 }
117}
118
119template <ServiceType S, typename KeyType>
121 *this = std::move(rhs);
122}
123
124template <ServiceType S, typename KeyType>
127 if (this != &rhs) {
128 drop();
129 m_handle = rhs.m_handle;
130 rhs.m_handle = nullptr;
131 }
132
133 return *this;
134}
135
136template <ServiceType S, typename KeyType>
140
141template <ServiceType S, typename KeyType>
143 const auto* service_name_ptr = iox2_port_factory_blackboard_service_name(&m_handle);
144 return ServiceNameView(service_name_ptr);
145}
146
147template <ServiceType S, typename KeyType>
150 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-avoid-unchecked-container-access) index 0 is guaranteed to be valid
151 iox2_port_factory_blackboard_service_hash(&m_handle, &buffer[0], IOX2_SERVICE_HASH_LENGTH);
152
154 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-avoid-unchecked-container-access) index 0 is guaranteed to be valid
155 &buffer[0],
156 IOX2_SERVICE_HASH_LENGTH));
157}
158
159template <ServiceType S, typename KeyType>
161 return AttributeSetView(iox2_port_factory_blackboard_attributes(&m_handle));
162}
163
164template <ServiceType S, typename KeyType>
166 iox2_static_config_blackboard_t static_config {};
167 iox2_port_factory_blackboard_static_config(&m_handle, &static_config);
168
170}
171
172template <ServiceType S, typename KeyType>
176
177template <ServiceType S, typename KeyType>
181 auto ctx = internal::ctx(callback);
182
183 const auto ret_val =
184 iox2_port_factory_blackboard_nodes(&m_handle, internal::list_callback<S>, static_cast<void*>(&ctx));
185
186 if (ret_val == IOX2_OK) {
187 return {};
188 }
189
190 return bb::err(bb::into<NodeListFailure>(ret_val));
191}
192
193template <ServiceType S, typename KeyType>
195 iox2_cleanup_state_t cleanup_state {};
196
197 iox2_port_factory_blackboard_try_cleanup_dead_nodes(&m_handle, &cleanup_state);
198
199 CleanupState ret_val {};
200 ret_val.cleanups = cleanup_state.cleanups;
201 ret_val.failed_cleanups = cleanup_state.failed_cleanups;
202 return ret_val;
203}
204
205template <ServiceType T, typename KeyType>
207 -> CleanupState {
208 iox2_cleanup_state_t cleanup_state {};
209
210 iox2_port_factory_blackboard_blocking_cleanup_dead_nodes(
211 &m_handle, &cleanup_state, timeout.as_secs(), timeout.subsec_nanos());
212
213 CleanupState ret_val {};
214 ret_val.cleanups = cleanup_state.cleanups;
215 ret_val.failed_cleanups = cleanup_state.failed_cleanups;
216 return ret_val;
217}
218
219template <ServiceType S, typename KeyType>
221 return PortFactoryWriter<S, KeyType>(iox2_port_factory_blackboard_writer_builder(&m_handle, nullptr));
222}
223
224template <ServiceType S, typename KeyType>
226 return PortFactoryReader<S, KeyType>(iox2_port_factory_blackboard_reader_builder(&m_handle, nullptr));
227}
228
229template <typename KeyType>
230auto list_keys_callback(const void* const key_ptr, void* ctx) -> iox2_callback_progression_e {
231 auto callback = static_cast<iox2::bb::StaticFunction<CallbackProgression(const KeyType&)>*>(ctx);
232 auto result = (*callback)(*static_cast<const KeyType* const>(key_ptr));
233 return iox2::bb::into<iox2_callback_progression_e>(result);
234}
235
236template <ServiceType S, typename KeyType>
238 const iox2::bb::StaticFunction<CallbackProgression(const KeyType&)>& callback) const {
239 auto mutable_callback = callback;
240 iox2_port_factory_blackboard_list_keys(&m_handle, list_keys_callback<KeyType>, &mutable_callback);
241}
242} // namespace iox2
243
244#endif
Describes the state of a [Node].
Represents the port factory of a [Service] with [MessagingPattern::Blackboard].
auto dynamic_config() const -> DynamicConfigBlackboard
PortFactoryBlackboard(const PortFactoryBlackboard &)=delete
void list_keys(const iox2::bb::StaticFunction< CallbackProgression(const KeyType &)> &callback) const
auto static_config() const -> StaticConfigBlackboard
auto attributes() const -> AttributeSetView
Returns the attributes defined in the [Service].
auto blocking_cleanup_dead_nodes(iox2::bb::Duration timeout) const -> CleanupState
auto writer_builder() const -> PortFactoryWriter< S, KeyType >
Returns a [PortFactoryWriter] to create a new [Writer] port.
auto service_hash() const -> ServiceHash
Returns the [ServiceHash] of the [Service].
auto operator=(const PortFactoryBlackboard &) -> PortFactoryBlackboard &=delete
PortFactoryBlackboard(PortFactoryBlackboard &&rhs) noexcept
auto name() const -> ServiceNameView
Returns the [ServiceName] of the service.
auto try_cleanup_dead_nodes() const -> CleanupState
auto reader_builder() const -> PortFactoryReader< S, KeyType >
Returns a [PortFactoryReader] to create a new [Reader] port.
auto nodes(const iox2::bb::StaticFunction< CallbackProgression(NodeState< S >)> &callback) const -> bb::Expected< void, NodeListFailure >
auto operator=(PortFactoryBlackboard &&rhs) noexcept -> PortFactoryBlackboard &
Builder to create new [MessagingPattern::Blackboard] based [Service]s.
Represents the unique if of a [Service].
Non-owning view of a [ServiceName].
Wrapper class for a C-style array of type ElementType and size Capacity. Per default it is uninitiali...
constexpr auto err(const E &error) -> Unexpected< E >
Definition expected.hpp:33
iox2::bb::variation::Expected< T, E > Expected
Definition expected.hpp:22
auto ctx(const T &ptr) -> CallbackContext< T >
auto list_keys_callback(const void *const key_ptr, void *ctx) -> iox2_callback_progression_e
NodeListFailure
All failures that can occur in [Node::list()].
uint64_t cleanups
The number of successful dead node cleanups.