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/port_name.hpp"
27#include "iox2/service_type.hpp"
28
29namespace iox2 {
32template <ServiceType Service,
33 typename RequestPayload,
34 typename RequestUserHeader,
35 typename ResponsePayload,
36 typename ResponseUserHeader>
38 public:
42#ifdef DOXYGEN_MACRO_FIX
43 auto backpressure_strategy(const BackpressureStrategy value) -> decltype(auto);
44#else
46#endif
49#ifdef DOXYGEN_MACRO_FIX
50 auto max_active_requests(const uint64_t value) -> decltype(auto);
51#else
53#endif
54
58#ifdef DOXYGEN_MACRO_FIX
59 auto name(const PortName value) -> decltype(auto);
60#else
62#endif
63
64 public:
69 ~PortFactoryClient() = default;
70
72 template <typename T = RequestPayload, typename = std::enable_if_t<bb::IsSlice<T>::VALUE, void>>
73 auto initial_max_slice_len(uint64_t value) && -> PortFactoryClient&&;
74
79 template <typename T = RequestPayload, typename = std::enable_if_t<bb::IsSlice<T>::VALUE, void>>
81
95
103
111
119
121 auto
124
125 private:
126 template <ServiceType, typename, typename, typename, typename>
128
129 explicit PortFactoryClient(iox2_port_factory_client_builder_h handle);
130
131 iox2_port_factory_client_builder_h m_handle = nullptr;
132 bb::Optional<uint64_t> m_max_slice_len;
133 bb::Optional<AllocationStrategy> m_allocation_strategy;
134 bb::Optional<OverridePreallocationCallback> m_override_preallocation_callback;
135 bb::Optional<DegradationHandler* const> m_request_degradation_handler;
136 bb::Optional<DegradationHandler* const> m_response_degradation_handler;
137 bb::Optional<BackpressureHandler* const> m_backpressure_handler;
138};
139
140template <ServiceType Service,
141 typename RequestPayload,
142 typename RequestUserHeader,
143 typename ResponsePayload,
144 typename ResponseUserHeader>
145template <typename T, typename>
147 initial_max_slice_len(uint64_t value) && -> PortFactoryClient&& {
148 m_max_slice_len.emplace(value);
149 return std::move(*this);
150}
151
152template <ServiceType Service,
153 typename RequestPayload,
154 typename RequestUserHeader,
155 typename ResponsePayload,
156 typename ResponseUserHeader>
159 m_override_preallocation_callback.emplace(callback);
160 return std::move(*this);
161}
162
163template <ServiceType Service,
164 typename RequestPayload,
165 typename RequestUserHeader,
166 typename ResponsePayload,
167 typename ResponseUserHeader>
168template <typename T, typename>
169inline auto
175
176template <ServiceType Service,
177 typename RequestPayload,
178 typename RequestUserHeader,
179 typename ResponsePayload,
180 typename ResponseUserHeader>
183 m_request_degradation_handler.emplace(handler);
184 return std::move(*this);
185}
186
187template <ServiceType Service,
188 typename RequestPayload,
189 typename RequestUserHeader,
190 typename ResponsePayload,
191 typename ResponseUserHeader>
194 m_response_degradation_handler.emplace(handler);
195 return std::move(*this);
196}
197
198template <ServiceType Service,
199 typename RequestPayload,
200 typename RequestUserHeader,
201 typename ResponsePayload,
202 typename ResponseUserHeader>
205 m_backpressure_handler.emplace(handler);
206 return std::move(*this);
207}
208
209template <ServiceType Service,
210 typename RequestPayload,
211 typename RequestUserHeader,
212 typename ResponsePayload,
213 typename ResponseUserHeader>
217 if (m_backpressure_strategy.has_value()) {
218 iox2_port_factory_client_builder_backpressure_strategy(
219 &m_handle, static_cast<iox2_backpressure_strategy_e>(bb::into<int>(m_backpressure_strategy.value())));
220 }
221 if (m_max_slice_len.has_value()) {
222 iox2_port_factory_client_builder_set_initial_max_slice_len(&m_handle, m_max_slice_len.value());
223 } else {
224 iox2_port_factory_client_builder_set_initial_max_slice_len(&m_handle, 1);
225 }
226 if (m_allocation_strategy.has_value()) {
227 iox2_port_factory_client_builder_set_allocation_strategy(
228 &m_handle, bb::into<iox2_allocation_strategy_e>(m_allocation_strategy.value()));
229 }
230 if (m_override_preallocation_callback.has_value()) {
231 // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) must be a raw pointer - crosses FFI boundary
232 auto* callback = new OverridePreallocationCallback(m_override_preallocation_callback.value());
233 // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) must be a raw pointer - crosses FFI boundary
235 iox2_port_factory_client_builder_override_requests_preallocation(
236 &m_handle, internal::override_callback, static_cast<void*>(ctx));
237 }
238
239 if (m_request_degradation_handler.has_value()) {
240 iox2_port_factory_client_builder_set_request_degradation_handler(
241 &m_handle, detail::degradation_handler_delegate, static_cast<void*>(m_request_degradation_handler.value()));
242 }
243
244 if (m_response_degradation_handler.has_value()) {
245 iox2_port_factory_client_builder_set_response_degradation_handler(
246 &m_handle,
248 static_cast<void*>(m_response_degradation_handler.value()));
249 }
250
251 if (m_backpressure_handler.has_value()) {
252 iox2_port_factory_client_builder_set_backpressure_handler(
253 &m_handle, detail::backpressure_handler_delegate, static_cast<void*>(m_backpressure_handler.value()));
254 }
255
256 if (m_max_active_requests.has_value()) {
257 iox2_port_factory_client_builder_set_max_active_requests(&m_handle, m_max_active_requests.value());
258 }
259
260 if (m_name.has_value()) {
261 const auto* name_ptr = m_name.value().as_view().native_ptr();
262 iox2_port_factory_client_builder_set_name(&m_handle, name_ptr);
263 }
264
265 iox2_client_h client_handle {};
266 auto result = iox2_port_factory_client_builder_create(m_handle, nullptr, &client_handle);
267
268 if (result == IOX2_OK) {
270 }
271
272 return bb::err(bb::into<ClientCreateError>(result));
273}
274
275template <ServiceType Service,
276 typename RequestPayload,
277 typename RequestUserHeader,
278 typename ResponsePayload,
279 typename ResponseUserHeader>
281 PortFactoryClient(iox2_port_factory_client_builder_h handle)
282 : m_handle { handle } {
283}
284} // namespace iox2
285#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:32
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 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