13#ifndef IOX2_SERVICE_BUILDER_PUBLISH_SUBSCRIBE_HPP
14#define IOX2_SERVICE_BUILDER_PUBLISH_SUBSCRIBE_HPP
37template <
typename Payload,
typename UserHeader, ServiceType S>
38class ServiceBuilderPublishSubscribe;
49template <
typename Payload,
typename UserHeader, ServiceType S>
50auto set_payload_type_details(ServiceBuilderPublishSubscribe<Payload, UserHeader, S>& builder,
const TypeDetail& value)
51 -> std::enable_if_t<std::is_same<Payload, bb::Slice<CustomPayloadMarker>>::value>;
62template <
typename Payload,
typename UserHeader, ServiceType S>
64 const TypeDetail& value)
65 -> std::enable_if_t<std::is_same<UserHeader, CustomHeaderMarker>::value>;
68template <
typename Payload,
typename UserHeader, ServiceType S>
75#ifdef DOXYGEN_MACRO_FIX
83#ifdef DOXYGEN_MACRO_FIX
92#ifdef DOXYGEN_MACRO_FIX
101#ifdef DOXYGEN_MACRO_FIX
109#ifdef DOXYGEN_MACRO_FIX
118#ifdef DOXYGEN_MACRO_FIX
127#ifdef DOXYGEN_MACRO_FIX
136#ifdef DOXYGEN_MACRO_FIX
146 template <typename U = Payload, typename = std::enable_if_t<has_flatbuffer_marker<U>(),
void>>
150 template <
typename NewHeader>
187 template <ServiceType>
190 template <
typename P,
typename U, ServiceType St>
192 -> std::enable_if_t<std::is_same<P, bb::Slice<CustomPayloadMarker>>::value>;
193 template <
typename P,
typename U, ServiceType St>
195 -> std::enable_if_t<std::is_same<U, CustomHeaderMarker>::value>;
199 template <
typename U = Payload>
200 auto set_type_definition_name_hint() -> std::enable_if_t<has_flatbuffer_marker<U>(),
void>;
201 template <
typename U = Payload>
202 auto set_type_definition_name_hint() -> std::enable_if_t<!has_flatbuffer_marker<U>(),
void>;
204 void set_parameters();
205 void derive_payload_type_details();
206 void override_payload_type_details(
const TypeDetail& value);
207 void derive_user_header_type_details();
208 void override_user_header_type_details(
const TypeDetail& value);
210 iox2_service_builder_pub_sub_h m_handle =
nullptr;
211 bool m_has_flatbuffer_schema_defined =
false;
216template <
typename Payload,
typename UserHeader, ServiceType S>
218 iox2_service_builder_h handle)
219 : m_handle { iox2_service_builder_pub_sub(handle) } {
222template <
typename Payload,
typename UserHeader, ServiceType S>
224inline auto ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::set_type_definition_name_hint()
225 -> std::enable_if_t<has_flatbuffer_marker<U>(),
void> {
226 auto type_name = iox2::internal::get_type_name<typename Payload::ValueType>();
227 iox2_service_builder_pub_sub_type_definition_name_hint(
228 &m_handle, type_name.unchecked_access().c_str(), type_name.size(),
"", 0);
231template <
typename Payload,
typename UserHeader, ServiceType S>
233inline auto ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::set_type_definition_name_hint()
234 -> std::enable_if_t<!has_flatbuffer_marker<U>(),
void> {
237template <
typename Payload,
typename UserHeader, ServiceType S>
238inline void ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::set_parameters() {
239 if (m_enable_safe_overflow.has_value()) {
240 iox2_service_builder_pub_sub_set_enable_safe_overflow(&m_handle, m_enable_safe_overflow.value());
242 if (m_subscriber_max_borrowed_samples.has_value()) {
243 iox2_service_builder_pub_sub_set_subscriber_max_borrowed_samples(&m_handle,
244 m_subscriber_max_borrowed_samples.value());
246 if (m_history_size.has_value()) {
247 iox2_service_builder_pub_sub_set_history_size(&m_handle, m_history_size.value());
249 if (m_subscriber_max_buffer_size.has_value()) {
250 iox2_service_builder_pub_sub_set_subscriber_max_buffer_size(&m_handle, m_subscriber_max_buffer_size.value());
252 if (m_max_subscribers.has_value()) {
253 iox2_service_builder_pub_sub_set_max_subscribers(&m_handle, m_max_subscribers.value());
255 if (m_max_publishers.has_value()) {
256 iox2_service_builder_pub_sub_set_max_publishers(&m_handle, m_max_publishers.value());
258 if (m_payload_alignment.has_value()) {
259 iox2_service_builder_pub_sub_set_payload_alignment(&m_handle, m_payload_alignment.value());
261 if (m_max_nodes.has_value()) {
262 iox2_service_builder_pub_sub_set_max_nodes(&m_handle, m_max_nodes.value());
265 if (m_user_header_type_details_override.has_value()) {
266 override_user_header_type_details(m_user_header_type_details_override.value());
268 derive_user_header_type_details();
271 if (m_payload_type_details_override.has_value()) {
272 override_payload_type_details(m_payload_type_details_override.value());
274 derive_payload_type_details();
277 set_type_definition_name_hint();
280template <
typename Payload,
typename UserHeader, ServiceType S>
281inline void ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::derive_user_header_type_details() {
283 const auto header_layout = bb::Layout::from<UserHeader>();
284 const auto user_header_type_name = internal::get_type_name<UserHeader>();
287 iox2_service_builder_pub_sub_set_user_header_type_details(&m_handle,
288 iox2_type_variant_e_FIXED_SIZE,
289 user_header_type_name.unchecked_access().c_str(),
290 user_header_type_name.size(),
291 header_layout.size(),
292 header_layout.alignment());
294 if (result != IOX2_OK) {
295 IOX2_PANIC(
"This should never happen! Implementation failure while setting the User-Header-Type.");
299template <
typename Payload,
typename UserHeader, ServiceType S>
301ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::override_user_header_type_details(
const TypeDetail& value) {
303 const auto type_variant =
306 const auto result = iox2_service_builder_pub_sub_set_user_header_type_details(
307 &m_handle, type_variant, value.type_name(), std::strlen(value.type_name()), value.size(), value.alignment());
309 if (result != IOX2_OK) {
310 IOX2_PANIC(
"This should never happen! Implementation failure while setting the User-Header-Type.");
314template <
typename Payload,
typename UserHeader, ServiceType S>
315inline void ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::derive_payload_type_details() {
319 const auto payload_type_name = internal::get_type_name<Payload>();
320 const auto type_variant =
324 iox2_service_builder_pub_sub_set_payload_type_details(&m_handle,
326 payload_type_name.unchecked_access().c_str(),
327 payload_type_name.size(),
331 if (result != IOX2_OK) {
332 IOX2_PANIC(
"This should never happen! Implementation failure while setting the Payload-Type.");
336template <
typename Payload,
typename UserHeader, ServiceType S>
338ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::override_payload_type_details(
const TypeDetail& value) {
340 const auto type_variant =
343 const auto result = iox2_service_builder_pub_sub_set_payload_type_details(
344 &m_handle, type_variant, value.type_name(), std::strlen(value.type_name()), value.size(), value.alignment());
346 if (result != IOX2_OK) {
347 IOX2_PANIC(
"This should never happen! Implementation failure while setting the Payload-Type.");
352template <
typename Payload,
typename UserHeader, ServiceType S>
353template <
typename NewHeader>
362template <
typename Payload,
typename UserHeader, ServiceType S>
363template <
typename U,
typename>
366 iox2_service_builder_pub_sub_set_flatbuffer_schema_path(&m_handle, value.as_string().unchecked_access().c_str());
367 m_has_flatbuffer_schema_defined =
true;
368 return std::move(*
this);
371template <
typename Payload,
typename UserHeader, ServiceType S>
374 return std::move(*
this);
377template <
typename Payload,
typename UserHeader, ServiceType S>
380 -> std::enable_if_t<std::is_same<UserHeader, CustomHeaderMarker>::value> {
384template <
typename Payload,
typename UserHeader, ServiceType S>
387 -> std::enable_if_t<std::is_same<Payload, bb::Slice<CustomPayloadMarker>>::value> {
391template <
typename Payload,
typename UserHeader, ServiceType S>
396 iox2_port_factory_pub_sub_h port_factory_handle {};
397 auto result = iox2_service_builder_pub_sub_open_or_create(m_handle,
nullptr, &port_factory_handle);
399 if (result == IOX2_OK) {
403 return bb::err(bb::into<PublishSubscribeOpenOrCreateError>(result));
406template <
typename Payload,
typename UserHeader, ServiceType S>
411 iox2_port_factory_pub_sub_h port_factory_handle {};
412 auto result = iox2_service_builder_pub_sub_open(m_handle,
nullptr, &port_factory_handle);
414 if (result == IOX2_OK) {
418 return bb::err(bb::into<PublishSubscribeOpenError>(result));
421template <
typename Payload,
typename UserHeader, ServiceType S>
426 iox2_port_factory_pub_sub_h port_factory_handle {};
427 auto result = iox2_service_builder_pub_sub_create(m_handle,
nullptr, &port_factory_handle);
429 if (result == IOX2_OK) {
433 return bb::err(bb::into<PublishSubscribeCreateError>(result));
436template <
typename Payload,
typename UserHeader, ServiceType S>
443 iox2_port_factory_pub_sub_h port_factory_handle {};
444 auto result = iox2_service_builder_pub_sub_open_or_create_with_attributes(
445 m_handle, &required_attributes.m_handle,
nullptr, &port_factory_handle);
447 if (result == IOX2_OK) {
451 return bb::err(bb::into<PublishSubscribeOpenOrCreateError>(result));
454template <
typename Payload,
typename UserHeader, ServiceType S>
461 iox2_port_factory_pub_sub_h port_factory_handle {};
462 auto result = iox2_service_builder_pub_sub_open_with_attributes(
463 m_handle, &required_attributes.m_handle,
nullptr, &port_factory_handle);
465 if (result == IOX2_OK) {
469 return bb::err(bb::into<PublishSubscribeOpenError>(result));
472template <
typename Payload,
typename UserHeader, ServiceType S>
478 iox2_port_factory_pub_sub_h port_factory_handle {};
479 auto result = iox2_service_builder_pub_sub_create_with_attributes(
480 m_handle, &attributes.m_handle,
nullptr, &port_factory_handle);
482 if (result == IOX2_OK) {
486 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 flatbuffer_schema_path(const bb::FilePath &value) &&-> ServiceBuilderPublishSubscribe< U, UserHeader, S > &&
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.
Represents a path to a file. It is not allowed to end with a path separator since this would then be ...
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