13#ifndef IOX2_SUBSCRIBER_HPP
14#define IOX2_SUBSCRIBER_HPP
19#include "iox2/iceoryx2.h"
29template <ServiceType S,
typename Payload,
typename UserHeader>
63 iox2_subscriber_h m_handle =
nullptr;
65template <
ServiceType S, typename Payload, typename UserHeader>
67 : m_handle { handle } {
70template <ServiceType S,
typename Payload,
typename UserHeader>
72 *
this = std::move(rhs);
75template <ServiceType S,
typename Payload,
typename UserHeader>
79 m_handle = rhs.m_handle;
80 rhs.m_handle =
nullptr;
86template <ServiceType S,
typename Payload,
typename UserHeader>
91template <ServiceType S,
typename Payload,
typename UserHeader>
93 if (m_handle !=
nullptr) {
94 iox2_subscriber_drop(m_handle);
99template <ServiceType S,
typename Payload,
typename UserHeader>
101 bool has_samples_result =
false;
102 auto result = iox2_subscriber_has_samples(&m_handle, &has_samples_result);
104 if (result == IOX2_OK) {
105 return has_samples_result;
108 return bb::err(bb::into<ConnectionFailure>(result));
111template <ServiceType S,
typename Payload,
typename UserHeader>
113 iox2_unique_subscriber_id_h id_handle =
nullptr;
115 iox2_subscriber_id(&m_handle,
nullptr, &id_handle);
119template <ServiceType S,
typename Payload,
typename UserHeader>
121 const auto* port_name_ptr = iox2_subscriber_name(&m_handle);
125template <ServiceType S,
typename Payload,
typename UserHeader>
127 return iox2_subscriber_buffer_size(&m_handle);
130template <ServiceType S,
typename Payload,
typename UserHeader>
134 auto result = iox2_subscriber_receive(&m_handle, &sample.m_sample, &sample.m_handle);
136 if (result == IOX2_OK) {
137 if (sample.m_handle !=
nullptr) {
143 return bb::err(bb::into<ReceiveError>(result));
Non-owning view of a [PortName].
static auto from_native_ptr(iox2_port_name_ptr m_ptr) -> PortNameView
Creates a [PortNameView] from a native [iox2_port_name_ptr].
The receiving endpoint of a publish-subscribe communication.
Subscriber(Subscriber &&rhs) noexcept
auto has_samples() const -> bb::Expected< bool, ConnectionFailure >
auto receive() const -> bb::Expected< bb::Optional< Sample< S, Payload, UserHeader > >, ReceiveError >
auto operator=(Subscriber &&rhs) noexcept -> Subscriber &
auto id() const -> UniqueSubscriberId
Returns the [UniqueSubscriberId] of the [Subscriber].
auto operator=(const Subscriber &) -> Subscriber &=delete
auto name() const -> PortNameView
Returns the [PortNameView] of the [Subscriber].
auto buffer_size() const -> uint64_t
Returns the internal buffer size of the [Subscriber].
Subscriber(const Subscriber &)=delete
The system-wide unique id of a [Subscriber].
constexpr NulloptT NULLOPT
constexpr auto err(const E &error) -> Unexpected< E >
iox2::bb::variation::Optional< T > Optional