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/service_type.hpp"
21#include "iox2/subscriber.hpp"
22
23#include <cstdint>
24
25namespace iox2 {
26
29template <ServiceType S, typename Payload, typename UserHeader>
31 public:
33#ifdef DOXYGEN_MACRO_FIX
34 auto buffer_size(const uint64_t value) -> decltype(auto);
35#else
37#endif
38
39 public:
45
53
56
57 private:
58 template <ServiceType, typename, typename>
60
61 explicit PortFactorySubscriber(iox2_port_factory_subscriber_builder_h handle);
62
63 iox2_port_factory_subscriber_builder_h m_handle = nullptr;
64 bb::Optional<DegradationHandler* const> m_degradation_handler;
65};
66
67template <ServiceType S, typename Payload, typename UserHeader>
69 iox2_port_factory_subscriber_builder_h handle)
70 : m_handle { handle } {
71}
72
73template <ServiceType S, typename Payload, typename UserHeader>
76 m_degradation_handler.emplace(handler);
77 return std::move(*this);
78}
79
80template <ServiceType S, typename Payload, typename UserHeader>
81inline auto
84 if (m_buffer_size.has_value()) {
85 iox2_port_factory_subscriber_builder_set_buffer_size(&m_handle, m_buffer_size.value());
86 }
87
88 if (m_degradation_handler.has_value()) {
89 iox2_port_factory_subscriber_builder_set_degradation_handler(
90 &m_handle, detail::degradation_handler_delegate, static_cast<void*>(m_degradation_handler.value()));
91 }
92
93 iox2_subscriber_h sub_handle {};
94 auto result = iox2_port_factory_subscriber_builder_create(m_handle, nullptr, &sub_handle);
95
96 if (result == IOX2_OK) {
97 return Subscriber<S, Payload, UserHeader>(sub_handle);
98 }
99
100 return bb::err(bb::into<SubscriberCreateError>(result));
101}
102} // namespace iox2
103
104#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 create() &&-> bb::Expected< Subscriber< S, Payload, UserHeader >, SubscriberCreateError >
Creates a new [Subscriber] or returns a [SubscriberCreateError] on failure.
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