iceoryx2
C++ Bindings
Loading...
Searching...
No Matches
port_factory_client.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_CLIENT_HPP
14#define IOX2_PORTFACTORY_CLIENT_HPP
15
19#include "iox2/bb/expected.hpp"
20#include "iox2/bb/optional.hpp"
21#include "iox2/client.hpp"
22#include "iox2/client_error.hpp"
26#include "iox2/marker.hpp"
27#include "iox2/port_name.hpp"
28#include "iox2/service_type.hpp"
29
30namespace iox2 {
33template <ServiceType Service,
34 typename RequestPayload,
35 typename RequestUserHeader,
36 typename ResponsePayload,
37 typename ResponseUserHeader>
39 public:
43#ifdef DOXYGEN_MACRO_FIX
44 auto backpressure_strategy(const BackpressureStrategy value) -> decltype(auto);
45#else
47#endif
50#ifdef DOXYGEN_MACRO_FIX
51 auto max_active_requests(const uint64_t value) -> decltype(auto);
52#else
54#endif
55
59#ifdef DOXYGEN_MACRO_FIX
60 auto name(const PortName value) -> decltype(auto);
61#else
63#endif
64
65 public:
70 ~PortFactoryClient() = default;
71
73 template <typename T = RequestPayload, typename = std::enable_if_t<bb::IsSlice<T>::VALUE, void>>
74 auto initial_max_slice_len(uint64_t value) && -> PortFactoryClient&&;
75
78 template <typename T = RequestPayload, typename = std::enable_if_t<has_flatbuffer_marker<T>(), void>>
79 auto initial_reserved_memory(uint64_t value) && -> PortFactoryClient&&;
80
85 template <typename T = RequestPayload,
86 typename = std::enable_if_t<bb::IsSlice<T>::VALUE || has_flatbuffer_marker<T>(), void>>
88
102
110
118
126
128 auto
131
132 private:
133 template <ServiceType, typename, typename, typename, typename>
135
136 explicit PortFactoryClient(iox2_port_factory_client_builder_h handle);
137
138 iox2_port_factory_client_builder_h m_handle = nullptr;
139 bb::Optional<uint64_t> m_max_slice_len;
140 bb::Optional<AllocationStrategy> m_allocation_strategy;
141 bb::Optional<OverridePreallocationCallback> m_override_preallocation_callback;
142 bb::Optional<DegradationHandler* const> m_request_degradation_handler;
143 bb::Optional<DegradationHandler* const> m_response_degradation_handler;
144 bb::Optional<BackpressureHandler* const> m_backpressure_handler;
145};
146
147template <ServiceType Service,
148 typename RequestPayload,
149 typename RequestUserHeader,
150 typename ResponsePayload,
151 typename ResponseUserHeader>
152template <typename T, typename>
154 initial_max_slice_len(uint64_t value) && -> PortFactoryClient&& {
155 m_max_slice_len.emplace(value);
156 return std::move(*this);
157}
158
159template <ServiceType Service,
160 typename RequestPayload,
161 typename RequestUserHeader,
162 typename ResponsePayload,
163 typename ResponseUserHeader>
164template <typename T, typename>
166 initial_reserved_memory(uint64_t value) && -> PortFactoryClient&& {
167 m_max_slice_len.emplace(value);
168 return std::move(*this);
169}
170
171template <ServiceType Service,
172 typename RequestPayload,
173 typename RequestUserHeader,
174 typename ResponsePayload,
175 typename ResponseUserHeader>
178 m_override_preallocation_callback.emplace(callback);
179 return std::move(*this);
180}
181
182template <ServiceType Service,
183 typename RequestPayload,
184 typename RequestUserHeader,
185 typename ResponsePayload,
186 typename ResponseUserHeader>
187template <typename T, typename>
188inline auto
194
195template <ServiceType Service,
196 typename RequestPayload,
197 typename RequestUserHeader,
198 typename ResponsePayload,
199 typename ResponseUserHeader>
202 m_request_degradation_handler.emplace(handler);
203 return std::move(*this);
204}
205
206template <ServiceType Service,
207 typename RequestPayload,
208 typename RequestUserHeader,
209 typename ResponsePayload,
210 typename ResponseUserHeader>
213 m_response_degradation_handler.emplace(handler);
214 return std::move(*this);
215}
216
217template <ServiceType Service,
218 typename RequestPayload,
219 typename RequestUserHeader,
220 typename ResponsePayload,
221 typename ResponseUserHeader>
224 m_backpressure_handler.emplace(handler);
225 return std::move(*this);
226}
227
228template <ServiceType Service,
229 typename RequestPayload,
230 typename RequestUserHeader,
231 typename ResponsePayload,
232 typename ResponseUserHeader>
236 if (m_backpressure_strategy.has_value()) {
237 iox2_port_factory_client_builder_backpressure_strategy(
238 &m_handle, static_cast<iox2_backpressure_strategy_e>(bb::into<int>(m_backpressure_strategy.value())));
239 }
240 if (m_max_slice_len.has_value()) {
241 iox2_port_factory_client_builder_set_initial_max_slice_len(&m_handle, m_max_slice_len.value());
242 } else {
243 iox2_port_factory_client_builder_set_initial_max_slice_len(&m_handle, 1);
244 }
245 if (m_allocation_strategy.has_value()) {
246 iox2_port_factory_client_builder_set_allocation_strategy(
247 &m_handle, bb::into<iox2_allocation_strategy_e>(m_allocation_strategy.value()));
248 }
249 if (m_override_preallocation_callback.has_value()) {
250 // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) must be a raw pointer - crosses FFI boundary
251 auto* callback = new OverridePreallocationCallback(m_override_preallocation_callback.value());
252 // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) must be a raw pointer - crosses FFI boundary
254 iox2_port_factory_client_builder_override_requests_preallocation(
255 &m_handle, internal::override_callback, static_cast<void*>(ctx));
256 }
257
258 if (m_request_degradation_handler.has_value()) {
259 iox2_port_factory_client_builder_set_request_degradation_handler(
260 &m_handle, detail::degradation_handler_delegate, static_cast<void*>(m_request_degradation_handler.value()));
261 }
262
263 if (m_response_degradation_handler.has_value()) {
264 iox2_port_factory_client_builder_set_response_degradation_handler(
265 &m_handle,
267 static_cast<void*>(m_response_degradation_handler.value()));
268 }
269
270 if (m_backpressure_handler.has_value()) {
271 iox2_port_factory_client_builder_set_backpressure_handler(
272 &m_handle, detail::backpressure_handler_delegate, static_cast<void*>(m_backpressure_handler.value()));
273 }
274
275 if (m_max_active_requests.has_value()) {
276 iox2_port_factory_client_builder_set_max_active_requests(&m_handle, m_max_active_requests.value());
277 }
278
279 if (m_name.has_value()) {
280 const auto* name_ptr = m_name.value().as_view().native_ptr();
281 iox2_port_factory_client_builder_set_name(&m_handle, name_ptr);
282 }
283
284 iox2_client_h client_handle {};
285 auto result = iox2_port_factory_client_builder_create(m_handle, nullptr, &client_handle);
286
287 if (result == IOX2_OK) {
289 }
290
291 return bb::err(bb::into<ClientCreateError>(result));
292}
293
294template <ServiceType Service,
295 typename RequestPayload,
296 typename RequestUserHeader,
297 typename ResponsePayload,
298 typename ResponseUserHeader>
300 PortFactoryClient(iox2_port_factory_client_builder_h handle)
301 : m_handle { handle } {
302}
303} // namespace iox2
304#endif
#define IOX2_BUILDER_OPTIONAL(type, name)
Definition builder.hpp:47
Sends [RequestMut]s to a [Server] in a request-response based communication.
Definition client.hpp:33
auto backpressure_strategy(const BackpressureStrategy value) -> decltype(auto)
auto override_request_preallocation(const OverridePreallocationCallback &callback) &&-> PortFactoryClient &&
auto set_response_degradation_handler(DegradationHandler *handler) &&-> PortFactoryClient &&
PortFactoryClient(const PortFactoryClient &)=delete
auto operator=(PortFactoryClient &&) -> PortFactoryClient &=default
auto operator=(const PortFactoryClient &) -> PortFactoryClient &=delete
auto allocation_strategy(AllocationStrategy value) &&-> PortFactoryClient &&
auto initial_max_slice_len(uint64_t value) &&-> PortFactoryClient &&
Sets the maximum number of elements that can be loaned in a slice.
auto create() &&-> bb::Expected< Client< Service, RequestPayload, RequestUserHeader, ResponsePayload, ResponseUserHeader >, ClientCreateError >
Creates a new [Client] or returns a [ClientCreateError] on failure.
auto max_active_requests(const uint64_t value) -> decltype(auto)
auto set_backpressure_handler(BackpressureHandler *handler) &&-> PortFactoryClient &&
auto initial_reserved_memory(uint64_t value) &&-> PortFactoryClient &&
auto name(const PortName value) -> decltype(auto)
PortFactoryClient(PortFactoryClient &&)=default
auto set_request_degradation_handler(DegradationHandler *handler) &&-> PortFactoryClient &&
Represent the name for a [Port].
Definition port_name.hpp:52
constexpr auto err(const E &error) -> Unexpected< E >
Definition expected.hpp:33
iox2::bb::variation::Optional< T > Optional
Definition optional.hpp:25
iox2::bb::variation::Expected< T, E > Expected
Definition expected.hpp:22
auto backpressure_handler_delegate(iox2_backpressure_info_h_ref info_handle, iox2_callback_context callback_cxt) -> iox2_backpressure_action_e
auto degradation_handler_delegate(iox2_degradation_cause_e degradation_cause, iox2_degradation_info_h_ref info_handle, iox2_callback_context callback_cxt) -> iox2_degradation_action_e
auto override_callback(size_t value, iox2_callback_context ctx) -> size_t
ClientCreateError
iox2::bb::StaticFunction< size_t(size_t)> OverridePreallocationCallback