13#ifndef IOX2_SUBSCRIBER_HPP
14#define IOX2_SUBSCRIBER_HPP
19#include "iox2/iceoryx2.h"
28template <ServiceType S,
typename Payload,
typename UserHeader>
59 iox2_subscriber_h m_handle =
nullptr;
61template <
ServiceType S, typename Payload, typename UserHeader>
63 : m_handle { handle } {
66template <ServiceType S,
typename Payload,
typename UserHeader>
68 *
this = std::move(rhs);
71template <ServiceType S,
typename Payload,
typename UserHeader>
75 m_handle = rhs.m_handle;
76 rhs.m_handle =
nullptr;
82template <ServiceType S,
typename Payload,
typename UserHeader>
87template <ServiceType S,
typename Payload,
typename UserHeader>
89 if (m_handle !=
nullptr) {
90 iox2_subscriber_drop(m_handle);
95template <ServiceType S,
typename Payload,
typename UserHeader>
97 bool has_samples_result =
false;
98 auto result = iox2_subscriber_has_samples(&m_handle, &has_samples_result);
100 if (result == IOX2_OK) {
101 return has_samples_result;
104 return bb::err(bb::into<ConnectionFailure>(result));
107template <ServiceType S,
typename Payload,
typename UserHeader>
109 iox2_unique_subscriber_id_h id_handle =
nullptr;
111 iox2_subscriber_id(&m_handle,
nullptr, &id_handle);
115template <ServiceType S,
typename Payload,
typename UserHeader>
117 return iox2_subscriber_buffer_size(&m_handle);
120template <ServiceType S,
typename Payload,
typename UserHeader>
124 auto result = iox2_subscriber_receive(&m_handle, &sample.m_sample, &sample.m_handle);
126 if (result == IOX2_OK) {
127 if (sample.m_handle !=
nullptr) {
133 return bb::err(bb::into<ReceiveError>(result));
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 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