13#ifndef IOX2_SERVICE_BUILDER_PUBLISH_SUBSCRIBE_HPP
14#define IOX2_SERVICE_BUILDER_PUBLISH_SUBSCRIBE_HPP
38template <
typename Payload,
typename UserHeader, ServiceType S>
39class ServiceBuilderPublishSubscribe;
50template <
typename Payload,
typename UserHeader, ServiceType S>
51auto set_payload_type_details(ServiceBuilderPublishSubscribe<Payload, UserHeader, S>& builder,
const TypeDetail& value)
52 -> std::enable_if_t<std::is_same<Payload, bb::Slice<CustomPayloadMarker>>::value>;
63template <
typename Payload,
typename UserHeader, ServiceType S>
65 const TypeDetail& value)
66 -> std::enable_if_t<std::is_same<UserHeader, CustomHeaderMarker>::value>;
69template <
typename Payload,
typename UserHeader, ServiceType S>
76#ifdef DOXYGEN_MACRO_FIX
84#ifdef DOXYGEN_MACRO_FIX
93#ifdef DOXYGEN_MACRO_FIX
102#ifdef DOXYGEN_MACRO_FIX
110#ifdef DOXYGEN_MACRO_FIX
119#ifdef DOXYGEN_MACRO_FIX
128#ifdef DOXYGEN_MACRO_FIX
137#ifdef DOXYGEN_MACRO_FIX
145 template <
typename NewHeader>
182 template <ServiceType>
185 template <
typename P,
typename U, ServiceType St>
187 -> std::enable_if_t<std::is_same<P, bb::Slice<CustomPayloadMarker>>::value>;
188 template <
typename P,
typename U, ServiceType St>
190 -> std::enable_if_t<std::is_same<U, CustomHeaderMarker>::value>;
194 void set_parameters();
195 void derive_payload_type_details();
196 void override_payload_type_details(
const TypeDetail& value);
197 void derive_user_header_type_details();
198 void override_user_header_type_details(
const TypeDetail& value);
200 iox2_service_builder_pub_sub_h m_handle =
nullptr;
205template <
typename Payload,
typename UserHeader, ServiceType S>
207 iox2_service_builder_h handle)
208 : m_handle { iox2_service_builder_pub_sub(handle) } {
211template <
typename Payload,
typename UserHeader, ServiceType S>
212inline void ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::set_parameters() {
213 if (m_enable_safe_overflow.has_value()) {
214 iox2_service_builder_pub_sub_set_enable_safe_overflow(&m_handle, m_enable_safe_overflow.value());
216 if (m_subscriber_max_borrowed_samples.has_value()) {
217 iox2_service_builder_pub_sub_set_subscriber_max_borrowed_samples(&m_handle,
218 m_subscriber_max_borrowed_samples.value());
220 if (m_history_size.has_value()) {
221 iox2_service_builder_pub_sub_set_history_size(&m_handle, m_history_size.value());
223 if (m_subscriber_max_buffer_size.has_value()) {
224 iox2_service_builder_pub_sub_set_subscriber_max_buffer_size(&m_handle, m_subscriber_max_buffer_size.value());
226 if (m_max_subscribers.has_value()) {
227 iox2_service_builder_pub_sub_set_max_subscribers(&m_handle, m_max_subscribers.value());
229 if (m_max_publishers.has_value()) {
230 iox2_service_builder_pub_sub_set_max_publishers(&m_handle, m_max_publishers.value());
232 if (m_payload_alignment.has_value()) {
233 iox2_service_builder_pub_sub_set_payload_alignment(&m_handle, m_payload_alignment.value());
235 if (m_max_nodes.has_value()) {
236 iox2_service_builder_pub_sub_set_max_nodes(&m_handle, m_max_nodes.value());
239 if (m_user_header_type_details_override.has_value()) {
240 override_user_header_type_details(m_user_header_type_details_override.value());
242 derive_user_header_type_details();
245 if (m_payload_type_details_override.has_value()) {
246 override_payload_type_details(m_payload_type_details_override.value());
248 derive_payload_type_details();
252template <
typename Payload,
typename UserHeader, ServiceType S>
253inline void ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::derive_user_header_type_details() {
255 const auto header_layout = bb::Layout::from<UserHeader>();
256 const auto user_header_type_name = internal::get_type_name<UserHeader>();
259 iox2_service_builder_pub_sub_set_user_header_type_details(&m_handle,
260 iox2_type_variant_e_FIXED_SIZE,
261 user_header_type_name.unchecked_access().c_str(),
262 user_header_type_name.size(),
263 header_layout.size(),
264 header_layout.alignment());
266 if (result != IOX2_OK) {
267 IOX2_PANIC(
"This should never happen! Implementation failure while setting the User-Header-Type.");
271template <
typename Payload,
typename UserHeader, ServiceType S>
273ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::override_user_header_type_details(
const TypeDetail& value) {
275 const auto type_variant =
278 const auto result = iox2_service_builder_pub_sub_set_user_header_type_details(
279 &m_handle, type_variant, value.type_name(), std::strlen(value.type_name()), value.size(), value.alignment());
281 if (result != IOX2_OK) {
282 IOX2_PANIC(
"This should never happen! Implementation failure while setting the User-Header-Type.");
286template <
typename Payload,
typename UserHeader, ServiceType S>
287inline void ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::derive_payload_type_details() {
291 const auto payload_type_name = internal::get_type_name<Payload>();
292 const auto type_variant =
296 iox2_service_builder_pub_sub_set_payload_type_details(&m_handle,
298 payload_type_name.unchecked_access().c_str(),
299 payload_type_name.size(),
303 if (result != IOX2_OK) {
304 IOX2_PANIC(
"This should never happen! Implementation failure while setting the Payload-Type.");
308template <
typename Payload,
typename UserHeader, ServiceType S>
310ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::override_payload_type_details(
const TypeDetail& value) {
312 const auto type_variant =
315 const auto result = iox2_service_builder_pub_sub_set_payload_type_details(
316 &m_handle, type_variant, value.type_name(), std::strlen(value.type_name()), value.size(), value.alignment());
318 if (result != IOX2_OK) {
319 IOX2_PANIC(
"This should never happen! Implementation failure while setting the Payload-Type.");
324template <
typename Payload,
typename UserHeader, ServiceType S>
325template <
typename NewHeader>
333template <
typename Payload,
typename UserHeader, ServiceType S>
336 return std::move(*
this);
339template <
typename Payload,
typename UserHeader, ServiceType S>
342 -> std::enable_if_t<std::is_same<UserHeader, CustomHeaderMarker>::value> {
346template <
typename Payload,
typename UserHeader, ServiceType S>
349 -> std::enable_if_t<std::is_same<Payload, bb::Slice<CustomPayloadMarker>>::value> {
353template <
typename Payload,
typename UserHeader, ServiceType S>
358 iox2_port_factory_pub_sub_h port_factory_handle {};
359 auto result = iox2_service_builder_pub_sub_open_or_create(m_handle,
nullptr, &port_factory_handle);
361 if (result == IOX2_OK) {
365 return bb::err(bb::into<PublishSubscribeOpenOrCreateError>(result));
368template <
typename Payload,
typename UserHeader, ServiceType S>
373 iox2_port_factory_pub_sub_h port_factory_handle {};
374 auto result = iox2_service_builder_pub_sub_open(m_handle,
nullptr, &port_factory_handle);
376 if (result == IOX2_OK) {
380 return bb::err(bb::into<PublishSubscribeOpenError>(result));
383template <
typename Payload,
typename UserHeader, ServiceType S>
388 iox2_port_factory_pub_sub_h port_factory_handle {};
389 auto result = iox2_service_builder_pub_sub_create(m_handle,
nullptr, &port_factory_handle);
391 if (result == IOX2_OK) {
395 return bb::err(bb::into<PublishSubscribeCreateError>(result));
398template <
typename Payload,
typename UserHeader, ServiceType S>
405 iox2_port_factory_pub_sub_h port_factory_handle {};
406 auto result = iox2_service_builder_pub_sub_open_or_create_with_attributes(
407 m_handle, &required_attributes.m_handle,
nullptr, &port_factory_handle);
409 if (result == IOX2_OK) {
413 return bb::err(bb::into<PublishSubscribeOpenOrCreateError>(result));
416template <
typename Payload,
typename UserHeader, ServiceType S>
423 iox2_port_factory_pub_sub_h port_factory_handle {};
424 auto result = iox2_service_builder_pub_sub_open_with_attributes(
425 m_handle, &required_attributes.m_handle,
nullptr, &port_factory_handle);
427 if (result == IOX2_OK) {
431 return bb::err(bb::into<PublishSubscribeOpenError>(result));
434template <
typename Payload,
typename UserHeader, ServiceType S>
440 iox2_port_factory_pub_sub_h port_factory_handle {};
441 auto result = iox2_service_builder_pub_sub_create_with_attributes(
442 m_handle, &attributes.m_handle,
nullptr, &port_factory_handle);
444 if (result == IOX2_OK) {
448 return bb::err(bb::into<PublishSubscribeCreateError>(result));
#define IOX2_PANIC(message)
calls panic handler and does not return
#define IOX2_BUILDER_OPTIONAL(type, name)
Builder to create new [MessagingPattern::PublishSubscribe] based [Service]s.
auto user_header() &&-> ServiceBuilderPublishSubscribe< Payload, NewHeader, S > &&
Sets the user header type of the [Service].
auto open_or_create_with_attributes(const AttributeVerifier &required_attributes) &&-> bb::Expected< PortFactoryPublishSubscribe< S, Payload, UserHeader >, PublishSubscribeOpenOrCreateError >
auto max_publishers(const uint64_t value) -> decltype(auto)
auto open_with_attributes(const AttributeVerifier &required_attributes) &&-> bb::Expected< PortFactoryPublishSubscribe< S, Payload, UserHeader >, PublishSubscribeOpenError >
auto history_size(const uint64_t value) -> decltype(auto)
auto subscriber_max_borrowed_samples(const uint64_t value) -> decltype(auto)
auto create_with_attributes(const AttributeSpecifier &attributes) &&-> bb::Expected< PortFactoryPublishSubscribe< S, Payload, UserHeader >, PublishSubscribeCreateError >
Creates a new [Service] with a set of attributes.
auto open_or_create() &&-> bb::Expected< PortFactoryPublishSubscribe< S, Payload, UserHeader >, PublishSubscribeOpenOrCreateError >
auto open() &&-> bb::Expected< PortFactoryPublishSubscribe< S, Payload, UserHeader >, PublishSubscribeOpenError >
Opens an existing [Service].
auto max_nodes(const uint64_t value) -> decltype(auto)
auto max_subscribers(const uint64_t value) -> decltype(auto)
auto payload_alignment(const uint64_t value) -> decltype(auto)
auto resume_build() &-> ServiceBuilderPublishSubscribe< Payload, UserHeader, S > &&
auto enable_safe_overflow(const bool value) -> decltype(auto)
friend auto set_user_header_type_details(ServiceBuilderPublishSubscribe< P, U, St > &builder, const TypeDetail &value) -> std::enable_if_t< std::is_same< U, CustomHeaderMarker >::value >
auto subscriber_max_buffer_size(const uint64_t value) -> decltype(auto)
auto create() &&-> bb::Expected< PortFactoryPublishSubscribe< S, Payload, UserHeader >, PublishSubscribeCreateError >
Creates a new [Service].
friend auto set_payload_type_details(ServiceBuilderPublishSubscribe< P, U, St > &builder, const TypeDetail &value) -> std::enable_if_t< std::is_same< P, bb::Slice< CustomPayloadMarker > >::value >
Builder to create or open [Service]s.
constexpr auto err(const E &error) -> Unexpected< E >
iox2::bb::variation::Optional< T > Optional
iox2::bb::variation::Expected< T, E > Expected
PublishSubscribeOpenOrCreateError
auto set_payload_type_details(ServiceBuilderPublishSubscribe< Payload, UserHeader, S > &builder, const TypeDetail &value) -> std::enable_if_t< std::is_same< Payload, bb::Slice< CustomPayloadMarker > >::value >
PublishSubscribeCreateError
Errors that can occur when a new [MessagingPattern::PublishSubscribe] [Service] shall be created.
auto set_user_header_type_details(ServiceBuilderPublishSubscribe< Payload, UserHeader, S > &builder, const TypeDetail &value) -> std::enable_if_t< std::is_same< UserHeader, CustomHeaderMarker >::value >
@ FixedSize
A fixed size type like [u64].
PublishSubscribeOpenError
Errors that can occur when an existing [MessagingPattern::PublishSubscribe] [Service] shall be opened...
static constexpr bool VALUE