From 7c046c94daf7fd5e03f1afc29649d619dcb48fac Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Tue, 24 Dec 2024 09:41:20 +0100 Subject: [PATCH] [#566] Fix event based comm cxx example --- .../src/custom_publisher.hpp | 4 ++-- .../src/custom_subscriber.hpp | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/cxx/event_based_communication/src/custom_publisher.hpp b/examples/cxx/event_based_communication/src/custom_publisher.hpp index 5dcc63f7a..8b96e1fce 100644 --- a/examples/cxx/event_based_communication/src/custom_publisher.hpp +++ b/examples/cxx/event_based_communication/src/custom_publisher.hpp @@ -41,8 +41,8 @@ class CustomPublisher : public iox2::FileDescriptorBased { .expect(""); } - static auto create(iox2::Node& node, const iox2::ServiceName& service_name) - -> CustomPublisher { + static auto create(iox2::Node& node, + const iox2::ServiceName& service_name) -> CustomPublisher { auto pubsub_service = node.service_builder(service_name) .publish_subscribe() .history_size(HISTORY_SIZE) diff --git a/examples/cxx/event_based_communication/src/custom_subscriber.hpp b/examples/cxx/event_based_communication/src/custom_subscriber.hpp index 31d684085..65639e041 100644 --- a/examples/cxx/event_based_communication/src/custom_subscriber.hpp +++ b/examples/cxx/event_based_communication/src/custom_subscriber.hpp @@ -23,6 +23,8 @@ #include "pubsub_event.hpp" #include "transmission_data.hpp" +constexpr uint64_t HISTORY_SIZE = 20; + // High-level subscriber class that contains besides a subscriber also a notifier // and a listener. The notifier is used to send events like // `PubSubEvent::ReceivedSample` or to notify the publisher that a new subscriber @@ -43,10 +45,14 @@ class CustomSubscriber : public iox2::FileDescriptorBased { auto operator=(const CustomSubscriber&) -> CustomSubscriber& = delete; auto operator=(CustomSubscriber&&) -> CustomSubscriber& = default; - static auto create(iox2::Node& node, const iox2::ServiceName& service_name) - -> CustomSubscriber { - auto pubsub_service = - node.service_builder(service_name).publish_subscribe().open_or_create().expect(""); + static auto create(iox2::Node& node, + const iox2::ServiceName& service_name) -> CustomSubscriber { + auto pubsub_service = node.service_builder(service_name) + .publish_subscribe() + .history_size(HISTORY_SIZE) + .subscriber_max_buffer_size(HISTORY_SIZE) + .open_or_create() + .expect(""); auto event_service = node.service_builder(service_name).event().open_or_create().expect(""); auto listener = event_service.listener_builder().create().expect("");