iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
backpressure_handler.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 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_BACKPRESSURE_HANDLER_HPP
14#define IOX2_BACKPRESSURE_HANDLER_HPP
15
17#include "iox2/bb/duration.hpp"
21
22namespace iox2 {
23namespace detail {
24// forward declaration in order to make it a friend in BackpressureInfo
25inline auto backpressure_handler_delegate(iox2_backpressure_info_h_ref info_handle, iox2_callback_context callback_cxt)
26 -> iox2_backpressure_action_e;
27} // namespace detail
28
31 private:
32 iox2_backpressure_info_h_ref m_info;
33
34 explicit BackpressureInfo(iox2_backpressure_info_h_ref info)
35 : m_info(info) {
36 }
37
38 friend auto iox2::detail::backpressure_handler_delegate(iox2_backpressure_info_h_ref info_handle,
39 iox2_callback_context callback_cxt)
40 -> iox2_backpressure_action_e;
41
42 static_assert(sizeof(iox2_buffer_16_align_4_t::data) == RawIdType::capacity(),
43 "RawIdType capacity must match iox2_buffer_16_align_4_t capacity");
44
45 public:
47 auto service_id() const -> RawIdType {
48 iox2_buffer_16_align_4_t buf;
49 iox2_backpressure_info_service_id(m_info, &buf);
50 return RawIdType::from_range_unchecked(buf.data).value();
51 }
53 auto receiver_port_id() const -> RawIdType {
54 iox2_buffer_16_align_4_t buf;
55 iox2_backpressure_info_receiver_port_id(m_info, &buf);
56 return RawIdType::from_range_unchecked(buf.data).value();
57 }
59 auto sender_port_id() const -> RawIdType {
60 iox2_buffer_16_align_4_t buf;
61 iox2_backpressure_info_sender_port_id(m_info, &buf);
62 return RawIdType::from_range_unchecked(buf.data).value();
63 }
65 auto retries() const -> uint64_t {
66 return iox2_backpressure_info_retries(m_info);
67 }
69 auto elapsed_time() const -> bb::Duration {
70 uint64_t seconds = 0;
71 uint32_t nanoseconds = 0;
72 iox2_backpressure_info_elapsed_time(m_info, &seconds, &nanoseconds);
73 return bb::Duration::create_duration(seconds, nanoseconds);
74 }
75};
76
84
85namespace detail {
86inline auto backpressure_handler_delegate(iox2_backpressure_info_h_ref info_handle, iox2_callback_context callback_cxt)
87 -> iox2_backpressure_action_e {
88 auto* callback = static_cast<BackpressureHandler*>(callback_cxt);
89
90 auto info = BackpressureInfo(info_handle);
91
92 return bb::into<iox2_backpressure_action_e>((*callback)(info));
93}
94} // namespace detail
95
96} // namespace iox2
97
98#endif // IOX2_BACKPRESSURE_HANDLER_HPP
The info passed to the [BackpressureHandler].
auto retries() const -> uint64_t
Returns the number retries for the running delivery to the receiver port.
auto sender_port_id() const -> RawIdType
Returns the ReceiverPortId of the involved ports.
auto receiver_port_id() const -> RawIdType
Returns the ReceiverPortId of the involved ports.
auto service_id() const -> RawIdType
Returns the ServiceId of the involved ports.
auto elapsed_time() const -> bb::Duration
Returns the elapsed time since the initial retry.
static constexpr auto create_duration(SecondsT seconds, NanosecondsT nanoseconds) noexcept -> Duration
Definition duration.hpp:409
A resizable container with compile-time fixed static capacity and contiguous inplace storage.
static constexpr auto capacity() noexcept -> SizeType
Retrieves the static capacity of the vector.
static constexpr auto from_range_unchecked(Iter it_begin, Sentinel it_end) -> bb::Optional< StaticVector >
auto backpressure_handler_delegate(iox2_backpressure_info_h_ref info_handle, iox2_callback_context callback_cxt) -> iox2_backpressure_action_e
BackpressureAction
Defines the action that shall be take when data cannot be delivered.