iceoryx2
C++ Language 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/service_type.hpp"
27
28namespace iox2 {
31template <ServiceType Service,
32 typename RequestPayload,
33 typename RequestUserHeader,
34 typename ResponsePayload,
35 typename ResponseUserHeader>
37 public:
41#ifdef DOXYGEN_MACRO_FIX
42 auto backpressure_strategy(const BackpressureStrategy value) -> decltype(auto);
43#else
45#endif
48#ifdef DOXYGEN_MACRO_FIX
49 auto max_active_requests(const uint64_t value) -> decltype(auto);
50#else
52#endif
53
54 public:
59 ~PortFactoryClient() = default;
60
62 template <typename T = RequestPayload, typename = std::enable_if_t<bb::IsSlice<T>::VALUE, void>>
63 auto initial_max_slice_len(uint64_t value) && -> PortFactoryClient&&;
64
69 template <typename T = RequestPayload, typename = std::enable_if_t<bb::IsSlice<T>::VALUE, void>>
71
85
93
101
109
111 auto
114
115 private:
116 template <ServiceType, typename, typename, typename, typename>
118
119 explicit PortFactoryClient(iox2_port_factory_client_builder_h handle);
120
121 iox2_port_factory_client_builder_h m_handle = nullptr;
122 bb::Optional<uint64_t> m_max_slice_len;
123 bb::Optional<AllocationStrategy> m_allocation_strategy;
124 bb::Optional<OverridePreallocationCallback> m_override_preallocation_callback;
125 bb::Optional<DegradationHandler* const> m_request_degradation_handler;
126 bb::Optional<DegradationHandler* const> m_response_degradation_handler;
127 bb::Optional<BackpressureHandler* const> m_backpressure_handler;
128};
129
130template <ServiceType Service,
131 typename RequestPayload,
132 typename RequestUserHeader,
133 typename ResponsePayload,
134 typename ResponseUserHeader>
135template <typename T, typename>
137 initial_max_slice_len(uint64_t value) && -> PortFactoryClient&& {
138 m_max_slice_len.emplace(value);
139 return std::move(*this);
140}
141
142template <ServiceType Service,
143 typename RequestPayload,
144 typename RequestUserHeader,
145 typename ResponsePayload,
146 typename ResponseUserHeader>
149 m_override_preallocation_callback.emplace(callback);
150 return std::move(*this);
151}
152
153template <ServiceType Service,
154 typename RequestPayload,
155 typename RequestUserHeader,
156 typename ResponsePayload,
157 typename ResponseUserHeader>
158template <typename T, typename>
159inline auto
165
166template <ServiceType Service,
167 typename RequestPayload,
168 typename RequestUserHeader,
169 typename ResponsePayload,
170 typename ResponseUserHeader>
173 m_request_degradation_handler.emplace(handler);
174 return std::move(*this);
175}
176
177template <ServiceType Service,
178 typename RequestPayload,
179 typename RequestUserHeader,
180 typename ResponsePayload,
181 typename ResponseUserHeader>
184 m_response_degradation_handler.emplace(handler);
185 return std::move(*this);
186}
187
188template <ServiceType Service,
189 typename RequestPayload,
190 typename RequestUserHeader,
191 typename ResponsePayload,
192 typename ResponseUserHeader>
195 m_backpressure_handler.emplace(handler);
196 return std::move(*this);
197}
198
199template <ServiceType Service,
200 typename RequestPayload,
201 typename RequestUserHeader,
202 typename ResponsePayload,
203 typename ResponseUserHeader>
207 if (m_backpressure_strategy.has_value()) {
208 iox2_port_factory_client_builder_backpressure_strategy(
209 &m_handle, static_cast<iox2_backpressure_strategy_e>(bb::into<int>(m_backpressure_strategy.value())));
210 }
211 if (m_max_slice_len.has_value()) {
212 iox2_port_factory_client_builder_set_initial_max_slice_len(&m_handle, m_max_slice_len.value());
213 } else {
214 iox2_port_factory_client_builder_set_initial_max_slice_len(&m_handle, 1);
215 }
216 if (m_allocation_strategy.has_value()) {
217 iox2_port_factory_client_builder_set_allocation_strategy(
218 &m_handle, bb::into<iox2_allocation_strategy_e>(m_allocation_strategy.value()));
219 }
220 if (m_override_preallocation_callback.has_value()) {
221 // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) must be a raw pointer - crosses FFI boundary
222 auto* callback = new OverridePreallocationCallback(m_override_preallocation_callback.value());
223 // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) must be a raw pointer - crosses FFI boundary
225 iox2_port_factory_client_builder_override_requests_preallocation(
226 &m_handle, internal::override_callback, static_cast<void*>(ctx));
227 }
228
229 if (m_request_degradation_handler.has_value()) {
230 iox2_port_factory_client_builder_set_request_degradation_handler(
231 &m_handle, detail::degradation_handler_delegate, static_cast<void*>(m_request_degradation_handler.value()));
232 }
233
234 if (m_response_degradation_handler.has_value()) {
235 iox2_port_factory_client_builder_set_response_degradation_handler(
236 &m_handle,
238 static_cast<void*>(m_response_degradation_handler.value()));
239 }
240
241 if (m_backpressure_handler.has_value()) {
242 iox2_port_factory_client_builder_set_backpressure_handler(
243 &m_handle, detail::backpressure_handler_delegate, static_cast<void*>(m_backpressure_handler.value()));
244 }
245
246 if (m_max_active_requests.has_value()) {
247 iox2_port_factory_client_builder_set_max_active_requests(&m_handle, m_max_active_requests.value());
248 }
249
250 iox2_client_h client_handle {};
251 auto result = iox2_port_factory_client_builder_create(m_handle, nullptr, &client_handle);
252
253 if (result == IOX2_OK) {
255 }
256
257 return bb::err(bb::into<ClientCreateError>(result));
258}
259
260template <ServiceType Service,
261 typename RequestPayload,
262 typename RequestUserHeader,
263 typename ResponsePayload,
264 typename ResponseUserHeader>
266 PortFactoryClient(iox2_port_factory_client_builder_h handle)
267 : m_handle { handle } {
268}
269} // namespace iox2
270#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:31
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 &&
PortFactoryClient(PortFactoryClient &&)=default
auto set_request_degradation_handler(DegradationHandler *handler) &&-> PortFactoryClient &&
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