iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
port_factory_subscriber.hpp
Go to the documentation of this file.
1// Copyright (c) 2024 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_SUBSCRIBER_HPP
14#define IOX2_PORTFACTORY_SUBSCRIBER_HPP
15
17#include "iox2/bb/expected.hpp"
20#include "iox2/port_name.hpp"
21#include "iox2/service_type.hpp"
22#include "iox2/subscriber.hpp"
23
24#include <cstdint>
25
26namespace iox2 {
27
30template <ServiceType S, typename Payload, typename UserHeader>
32 public:
34#ifdef DOXYGEN_MACRO_FIX
35 auto buffer_size(const uint64_t value) -> decltype(auto);
36#else
38#endif
39
42#ifdef DOXYGEN_MACRO_FIX
43 auto history_request(const uint64_t value) -> decltype(auto);
44#else
46#endif
47
51#ifdef DOXYGEN_MACRO_FIX
52 auto name(const PortName value) -> decltype(auto);
53#else
55#endif
56
57 public:
63
71
74
75 private:
76 template <ServiceType, typename, typename>
78
79 explicit PortFactorySubscriber(iox2_port_factory_subscriber_builder_h handle);
80
81 iox2_port_factory_subscriber_builder_h m_handle = nullptr;
82 bb::Optional<DegradationHandler* const> m_degradation_handler;
83};
84
85template <ServiceType S, typename Payload, typename UserHeader>
87 iox2_port_factory_subscriber_builder_h handle)
88 : m_handle { handle } {
89}
90
91template <ServiceType S, typename Payload, typename UserHeader>
94 m_degradation_handler.emplace(handler);
95 return std::move(*this);
96}
97
98template <ServiceType S, typename Payload, typename UserHeader>
99inline auto
102 if (m_buffer_size.has_value()) {
103 iox2_port_factory_subscriber_builder_set_buffer_size(&m_handle, m_buffer_size.value());
104 }
105
106 if (m_history_request.has_value()) {
107 iox2_port_factory_subscriber_builder_set_history_request(&m_handle, m_history_request.value());
108 }
109
110 if (m_degradation_handler.has_value()) {
111 iox2_port_factory_subscriber_builder_set_degradation_handler(
112 &m_handle, detail::degradation_handler_delegate, static_cast<void*>(m_degradation_handler.value()));
113 }
114
115 if (m_name.has_value()) {
116 const auto* name_ptr = m_name.value().as_view().native_ptr();
117 iox2_port_factory_subscriber_builder_set_name(&m_handle, name_ptr);
118 }
119
120 iox2_subscriber_h sub_handle {};
121 auto result = iox2_port_factory_subscriber_builder_create(m_handle, nullptr, &sub_handle);
122
123 if (result == IOX2_OK) {
124 return Subscriber<S, Payload, UserHeader>(sub_handle);
125 }
126
127 return bb::err(bb::into<SubscriberCreateError>(result));
128}
129} // namespace iox2
130
131#endif
#define IOX2_BUILDER_OPTIONAL(type, name)
Definition builder.hpp:47
auto buffer_size(const uint64_t value) -> decltype(auto)
Defines the required buffer size of the [Subscriber]. Smallest possible value is 1.
auto operator=(const PortFactorySubscriber &) -> PortFactorySubscriber &=delete
auto operator=(PortFactorySubscriber &&) -> PortFactorySubscriber &=default
PortFactorySubscriber(PortFactorySubscriber &&)=default
auto set_degradation_handler(DegradationHandler *handler) &&-> PortFactorySubscriber &&
PortFactorySubscriber(const PortFactorySubscriber &)=delete
auto history_request(const uint64_t value) -> decltype(auto)
auto name(const PortName value) -> decltype(auto)
auto create() &&-> bb::Expected< Subscriber< S, Payload, UserHeader >, SubscriberCreateError >
Creates a new [Subscriber] or returns a [SubscriberCreateError] on failure.
Represent the name for a [Port].
Definition port_name.hpp:52
The receiving endpoint of a publish-subscribe communication.
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 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