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;
215template <
typename Payload,
typename UserHeader, ServiceType S>
217 iox2_service_builder_h handle)
218 : m_handle { iox2_service_builder_pub_sub(handle) } {
221template <
typename Payload,
typename UserHeader, ServiceType S>
223inline auto ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::set_type_definition_name_hint()
224 -> std::enable_if_t<has_flatbuffer_marker<U>(),
void> {
225 auto type_name = iox2::internal::get_type_name<typename Payload::ValueType>();
226 iox2_service_builder_pub_sub_type_definition_name_hint(
227 &m_handle, type_name.unchecked_access().c_str(), type_name.size(),
"", 0);
230template <
typename Payload,
typename UserHeader, ServiceType S>
232inline auto ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::set_type_definition_name_hint()
233 -> std::enable_if_t<!has_flatbuffer_marker<U>(),
void> {
236template <
typename Payload,
typename UserHeader, ServiceType S>
237inline void ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::set_parameters() {
238 if (m_enable_safe_overflow.has_value()) {
239 iox2_service_builder_pub_sub_set_enable_safe_overflow(&m_handle, m_enable_safe_overflow.value());
241 if (m_subscriber_max_borrowed_samples.has_value()) {
242 iox2_service_builder_pub_sub_set_subscriber_max_borrowed_samples(&m_handle,
243 m_subscriber_max_borrowed_samples.value());
245 if (m_history_size.has_value()) {
246 iox2_service_builder_pub_sub_set_history_size(&m_handle, m_history_size.value());
248 if (m_subscriber_max_buffer_size.has_value()) {
249 iox2_service_builder_pub_sub_set_subscriber_max_buffer_size(&m_handle, m_subscriber_max_buffer_size.value());
251 if (m_max_subscribers.has_value()) {
252 iox2_service_builder_pub_sub_set_max_subscribers(&m_handle, m_max_subscribers.value());
254 if (m_max_publishers.has_value()) {
255 iox2_service_builder_pub_sub_set_max_publishers(&m_handle, m_max_publishers.value());
257 if (m_payload_alignment.has_value()) {
258 iox2_service_builder_pub_sub_set_payload_alignment(&m_handle, m_payload_alignment.value());
260 if (m_max_nodes.has_value()) {
261 iox2_service_builder_pub_sub_set_max_nodes(&m_handle, m_max_nodes.value());
264 if (m_user_header_type_details_override.has_value()) {
265 override_user_header_type_details(m_user_header_type_details_override.value());
267 derive_user_header_type_details();
270 if (m_payload_type_details_override.has_value()) {
271 override_payload_type_details(m_payload_type_details_override.value());
273 derive_payload_type_details();
276 set_type_definition_name_hint();
279template <
typename Payload,
typename UserHeader, ServiceType S>
280inline void ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::derive_user_header_type_details() {
282 const auto header_layout = bb::Layout::from<UserHeader>();
283 const auto user_header_type_name = internal::get_type_name<UserHeader>();
286 iox2_service_builder_pub_sub_set_user_header_type_details(&m_handle,
287 iox2_type_variant_e_FIXED_SIZE,
288 user_header_type_name.unchecked_access().c_str(),
289 user_header_type_name.size(),
290 header_layout.size(),
291 header_layout.alignment());
293 if (result != IOX2_OK) {
294 IOX2_PANIC(
"This should never happen! Implementation failure while setting the User-Header-Type.");
298template <
typename Payload,
typename UserHeader, ServiceType S>
300ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::override_user_header_type_details(
const TypeDetail& value) {
302 const auto type_variant =
305 const auto result = iox2_service_builder_pub_sub_set_user_header_type_details(
306 &m_handle, type_variant, value.type_name(), std::strlen(value.type_name()), value.size(), value.alignment());
308 if (result != IOX2_OK) {
309 IOX2_PANIC(
"This should never happen! Implementation failure while setting the User-Header-Type.");
313template <
typename Payload,
typename UserHeader, ServiceType S>
314inline void ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::derive_payload_type_details() {
318 const auto payload_type_name = internal::get_type_name<Payload>();
319 const auto type_variant =
323 iox2_service_builder_pub_sub_set_payload_type_details(&m_handle,
325 payload_type_name.unchecked_access().c_str(),
326 payload_type_name.size(),
330 if (result != IOX2_OK) {
331 IOX2_PANIC(
"This should never happen! Implementation failure while setting the Payload-Type.");
335template <
typename Payload,
typename UserHeader, ServiceType S>
337ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::override_payload_type_details(
const TypeDetail& value) {
339 const auto type_variant =
342 const auto result = iox2_service_builder_pub_sub_set_payload_type_details(
343 &m_handle, type_variant, value.type_name(), std::strlen(value.type_name()), value.size(), value.alignment());
345 if (result != IOX2_OK) {
346 IOX2_PANIC(
"This should never happen! Implementation failure while setting the Payload-Type.");
351template <
typename Payload,
typename UserHeader, ServiceType S>
352template <
typename NewHeader>
361template <
typename Payload,
typename UserHeader, ServiceType S>
362template <
typename U,
typename>
365 iox2_service_builder_pub_sub_set_flatbuffer_schema_path(&m_handle, value.as_string().unchecked_access().c_str());
366 return std::move(*
this);
369template <
typename Payload,
typename UserHeader, ServiceType S>
372 return std::move(*
this);
375template <
typename Payload,
typename UserHeader, ServiceType S>
378 -> std::enable_if_t<std::is_same<UserHeader, CustomHeaderMarker>::value> {
382template <
typename Payload,
typename UserHeader, ServiceType S>
385 -> std::enable_if_t<std::is_same<Payload, bb::Slice<CustomPayloadMarker>>::value> {
389template <
typename Payload,
typename UserHeader, ServiceType S>
394 iox2_port_factory_pub_sub_h port_factory_handle {};
395 auto result = iox2_service_builder_pub_sub_open_or_create(m_handle,
nullptr, &port_factory_handle);
397 if (result == IOX2_OK) {
401 return bb::err(bb::into<PublishSubscribeOpenOrCreateError>(result));
404template <
typename Payload,
typename UserHeader, ServiceType S>
409 iox2_port_factory_pub_sub_h port_factory_handle {};
410 auto result = iox2_service_builder_pub_sub_open(m_handle,
nullptr, &port_factory_handle);
412 if (result == IOX2_OK) {
416 return bb::err(bb::into<PublishSubscribeOpenError>(result));
419template <
typename Payload,
typename UserHeader, ServiceType S>
424 iox2_port_factory_pub_sub_h port_factory_handle {};
425 auto result = iox2_service_builder_pub_sub_create(m_handle,
nullptr, &port_factory_handle);
427 if (result == IOX2_OK) {
431 return bb::err(bb::into<PublishSubscribeCreateError>(result));
434template <
typename Payload,
typename UserHeader, ServiceType S>
441 iox2_port_factory_pub_sub_h port_factory_handle {};
442 auto result = iox2_service_builder_pub_sub_open_or_create_with_attributes(
443 m_handle, &required_attributes.m_handle,
nullptr, &port_factory_handle);
445 if (result == IOX2_OK) {
449 return bb::err(bb::into<PublishSubscribeOpenOrCreateError>(result));
452template <
typename Payload,
typename UserHeader, ServiceType S>
459 iox2_port_factory_pub_sub_h port_factory_handle {};
460 auto result = iox2_service_builder_pub_sub_open_with_attributes(
461 m_handle, &required_attributes.m_handle,
nullptr, &port_factory_handle);
463 if (result == IOX2_OK) {
467 return bb::err(bb::into<PublishSubscribeOpenError>(result));
470template <
typename Payload,
typename UserHeader, ServiceType S>
476 iox2_port_factory_pub_sub_h port_factory_handle {};
477 auto result = iox2_service_builder_pub_sub_create_with_attributes(
478 m_handle, &attributes.m_handle,
nullptr, &port_factory_handle);
480 if (result == IOX2_OK) {
484 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