iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
port_factory_request_response.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_REQUEST_RESPONSE_HPP
14#define IOX2_PORTFACTORY_REQUEST_RESPONSE_HPP
15
17#include "iox2/bb/expected.hpp"
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 {
37template <ServiceType Service,
38 typename RequestPayload,
39 typename RequestUserHeader,
40 typename ResponsePayload,
41 typename ResponseUserHeader>
43 public:
47
50
52 auto name() const -> ServiceNameView;
53
55 auto service_hash() const -> ServiceHash;
56
58 auto attributes() const -> AttributeSetView;
59
63
67
72 auto nodes(const iox2::bb::StaticFunction<CallbackProgression(NodeState<Service>)>& callback) const
73 -> bb::Expected<void, NodeListFailure>;
74
77 auto client_builder() const
78 -> PortFactoryClient<Service, RequestPayload, RequestUserHeader, ResponsePayload, ResponseUserHeader>;
79
82 auto server_builder() const
83 -> PortFactoryServer<Service, RequestPayload, RequestUserHeader, ResponsePayload, ResponseUserHeader>;
84
90
98 auto blocking_cleanup_dead_nodes(iox2::bb::Duration timeout) const -> CleanupState;
99
100 private:
101 template <typename, typename, typename, typename, ServiceType>
103
104 explicit PortFactoryRequestResponse(iox2_port_factory_request_response_h handle);
105 void drop();
106
107 iox2_port_factory_request_response_h m_handle = nullptr;
108};
109
110template <ServiceType Service,
111 typename RequestPayload,
112 typename RequestUserHeader,
113 typename ResponsePayload,
114 typename ResponseUserHeader>
115inline PortFactoryRequestResponse<Service, RequestPayload, RequestUserHeader, ResponsePayload, ResponseUserHeader>::
117 *this = std::move(rhs);
118}
119
120template <ServiceType Service,
121 typename RequestPayload,
122 typename RequestUserHeader,
123 typename ResponsePayload,
124 typename ResponseUserHeader>
125inline auto
128 if (this != &rhs) {
129 drop();
130 m_handle = rhs.m_handle;
131 rhs.m_handle = nullptr;
132 }
133
134 return *this;
135}
136
137template <ServiceType Service,
138 typename RequestPayload,
139 typename RequestUserHeader,
140 typename ResponsePayload,
141 typename ResponseUserHeader>
146
147template <ServiceType Service,
148 typename RequestPayload,
149 typename RequestUserHeader,
150 typename ResponsePayload,
151 typename ResponseUserHeader>
152inline auto
154 const -> ServiceNameView {
155 const auto* service_name_ptr = iox2_port_factory_request_response_service_name(&m_handle);
156 return ServiceNameView(service_name_ptr);
157}
158
159template <ServiceType Service,
160 typename RequestPayload,
161 typename RequestUserHeader,
162 typename ResponsePayload,
163 typename ResponseUserHeader>
164inline auto
166 service_hash() const -> ServiceHash {
168 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-avoid-unchecked-container-access) index 0 is guaranteed to be valid
169 iox2_port_factory_request_response_service_hash(&m_handle, &buffer[0], IOX2_SERVICE_HASH_LENGTH);
170
172 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-avoid-unchecked-container-access) index 0 is guaranteed to be valid
173 &buffer[0],
174 IOX2_SERVICE_HASH_LENGTH));
175}
176
177template <ServiceType Service,
178 typename RequestPayload,
179 typename RequestUserHeader,
180 typename ResponsePayload,
181 typename ResponseUserHeader>
182inline auto
187
188template <ServiceType Service,
189 typename RequestPayload,
190 typename RequestUserHeader,
191 typename ResponsePayload,
192 typename ResponseUserHeader>
193inline auto
196 iox2_static_config_request_response_t static_config {};
197 iox2_port_factory_request_response_static_config(&m_handle, &static_config);
198
200}
201
202template <ServiceType Service,
203 typename RequestPayload,
204 typename RequestUserHeader,
205 typename ResponsePayload,
206 typename ResponseUserHeader>
207inline auto
212
213template <ServiceType Service,
214 typename RequestPayload,
215 typename RequestUserHeader,
216 typename ResponsePayload,
217 typename ResponseUserHeader>
218inline auto
222 auto ctx = internal::ctx(callback);
223
224 const auto ret_val =
225 iox2_port_factory_request_response_nodes(&m_handle, internal::list_callback<Service>, static_cast<void*>(&ctx));
226
227 if (ret_val == IOX2_OK) {
228 return {};
229 }
230
231 return bb::err(bb::into<NodeListFailure>(ret_val));
232}
233
234template <ServiceType S,
235 typename RequestPayload,
236 typename RequestUserHeader,
237 typename ResponsePayload,
238 typename ResponseUserHeader>
241 iox2_cleanup_state_t cleanup_state {};
242
243 iox2_port_factory_request_response_try_cleanup_dead_nodes(&m_handle, &cleanup_state);
244
245 CleanupState ret_val {};
246 ret_val.cleanups = cleanup_state.cleanups;
247 ret_val.failed_cleanups = cleanup_state.failed_cleanups;
248 return ret_val;
249}
250
251template <ServiceType T,
252 typename RequestPayload,
253 typename RequestUserHeader,
254 typename ResponsePayload,
255 typename ResponseUserHeader>
258 iox2_cleanup_state_t cleanup_state {};
259
260 iox2_port_factory_request_response_blocking_cleanup_dead_nodes(
261 &m_handle, &cleanup_state, timeout.as_secs(), timeout.subsec_nanos());
262
263 CleanupState ret_val {};
264 ret_val.cleanups = cleanup_state.cleanups;
265 ret_val.failed_cleanups = cleanup_state.failed_cleanups;
266 return ret_val;
267}
268
269template <ServiceType Service,
270 typename RequestPayload,
271 typename RequestUserHeader,
272 typename ResponsePayload,
273 typename ResponseUserHeader>
274inline auto
276 client_builder() const
277 -> PortFactoryClient<Service, RequestPayload, RequestUserHeader, ResponsePayload, ResponseUserHeader> {
279 iox2_port_factory_request_response_client_builder(&m_handle, nullptr));
280}
281
282template <ServiceType Service,
283 typename RequestPayload,
284 typename RequestUserHeader,
285 typename ResponsePayload,
286 typename ResponseUserHeader>
287inline auto
289 server_builder() const
290 -> PortFactoryServer<Service, RequestPayload, RequestUserHeader, ResponsePayload, ResponseUserHeader> {
292 iox2_port_factory_request_response_server_builder(&m_handle, nullptr));
293}
294
295template <ServiceType Service,
296 typename RequestPayload,
297 typename RequestUserHeader,
298 typename ResponsePayload,
299 typename ResponseUserHeader>
301 PortFactoryRequestResponse(iox2_port_factory_request_response_h handle)
302 : m_handle { handle } {
303}
304
305template <ServiceType Service,
306 typename RequestPayload,
307 typename RequestUserHeader,
308 typename ResponsePayload,
309 typename ResponseUserHeader>
310inline void
311PortFactoryRequestResponse<Service, RequestPayload, RequestUserHeader, ResponsePayload, ResponseUserHeader>::drop() {
312 if (m_handle != nullptr) {
313 iox2_port_factory_request_response_drop(m_handle);
314 m_handle = nullptr;
315 }
316}
317} // namespace iox2
318
319#endif
Describes the state of a [Node].
auto service_hash() const -> ServiceHash
Returns the [ServiceHash] of the [Service].
auto operator=(const PortFactoryRequestResponse &) -> PortFactoryRequestResponse &=delete
auto attributes() const -> AttributeSetView
Returns the attributes defined in the [Service].
auto server_builder() const -> PortFactoryServer< Service, RequestPayload, RequestUserHeader, ResponsePayload, ResponseUserHeader >
PortFactoryRequestResponse(PortFactoryRequestResponse &&rhs) noexcept
auto operator=(PortFactoryRequestResponse &&rhs) noexcept -> PortFactoryRequestResponse &
auto blocking_cleanup_dead_nodes(iox2::bb::Duration timeout) const -> CleanupState
PortFactoryRequestResponse(const PortFactoryRequestResponse &)=delete
auto name() const -> ServiceNameView
Returns the [ServiceName] of the service.
auto static_config() const -> StaticConfigRequestResponse
auto client_builder() const -> PortFactoryClient< Service, RequestPayload, RequestUserHeader, ResponsePayload, ResponseUserHeader >
auto try_cleanup_dead_nodes() const -> CleanupState
auto nodes(const iox2::bb::StaticFunction< CallbackProgression(NodeState< Service >)> &callback) const -> bb::Expected< void, NodeListFailure >
auto dynamic_config() const -> DynamicConfigRequestResponse
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 >
NodeListFailure
All failures that can occur in [Node::list()].
uint64_t cleanups
The number of successful dead node cleanups.