From 8c67b11c408459b695d15f1dd55cf41304e7c839 Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Mon, 25 Nov 2024 23:38:21 +0100 Subject: [PATCH] [#390] Fix typos; clearer structure for example --- examples/README.md | 2 +- .../event_based_communication/src/publisher.cpp | 14 +++++++++++++- .../event_based_communication/src/pubsub_event.hpp | 14 +++++++------- .../event_based_communication/src/subscriber.cpp | 12 ++++++++++++ .../rust/event_based_communication/publisher.rs | 2 +- examples/rust/event_multiplexing/wait.rs | 2 +- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/examples/README.md b/examples/README.md index 8ca30e5cb..dd5e051bc 100644 --- a/examples/README.md +++ b/examples/README.md @@ -77,7 +77,7 @@ These types are demonstrated in the complex data types example. | docker | [all](rust/docker) | Communicate between different docker containers and the host. | | domains | [C](c/domains) [C++](cxx/domains) [Rust](rust/domains) | Establish separate domains that operate independently from one another. | | event | [C](c/event) [C++](cxx/event) [Rust](rust/event) | Push notifications - send event signals to wakeup processes that are waiting for them. | -| event based communication | [C++](rust/event_based_communication) [Rust](rust/event_based_communication) | Define multiple events like publisher/subscriber created or removed, send sample, received sample, deliver history etc. and react on them for a fully event driven communication setup. | +| event based communication | [C++](cxx/event_based_communication) [Rust](rust/event_based_communication) | Define multiple events like publisher/subscriber created or removed, send sample, received sample, deliver history etc. and react on them for a fully event driven communication setup. | | event multiplexing | [C](c/event_multiplexing) [C++](cxx/event_multiplexing) [Rust](rust/event_multiplexing) | Wait on multiple listeners or sockets with a single call. The WaitSet demultiplexes incoming events and notifies the user. | | publish subscribe | [C](c/publish_subscribe) [C++](cxx/publish_subscribe) [Rust](rust/publish_subscribe) | Communication between multiple processes with a [publish subscribe messaging pattern](https://en.wikipedia.org/wiki/Publish–subscribe_pattern). | | publish subscribe dynamic data | [C++](cxx/publish_subscribe_dynamic_data) [Rust](rust/publish_subscribe_dynamic_data) | Communication between multiple processes with a [publish subscribe messaging pattern](https://en.wikipedia.org/wiki/Publish–subscribe_pattern) and payload data that has a dynamic size. | diff --git a/examples/cxx/event_based_communication/src/publisher.cpp b/examples/cxx/event_based_communication/src/publisher.cpp index dfb42db8a..d13584e83 100644 --- a/examples/cxx/event_based_communication/src/publisher.cpp +++ b/examples/cxx/event_based_communication/src/publisher.cpp @@ -31,6 +31,10 @@ using namespace iox2; constexpr iox::units::Duration CYCLE_TIME = iox::units::Duration::fromSeconds(1); constexpr uint64_t HISTORY_SIZE = 20; +/////////////////////////////////////////////// +/// START: EventBasedPublisher definition +/////////////////////////////////////////////// + // High-level publisher class that contains besides a publisher also a notifier and a listener. // The notifier is used to send events like `PubSubEvent::SentSample` or `PubSubEvent::SentHistory` // and the listener to wait for new subscribers. @@ -58,6 +62,10 @@ class EventBasedPublisher : public FileDescriptorBased { Notifier m_notifier; }; +/////////////////////////////////////////////// +/// START: main +/////////////////////////////////////////////// + auto main() -> int { auto node = NodeBuilder().create().expect("successful node creation"); auto publisher = EventBasedPublisher::create(node, ServiceName::create("My/Funk/ServiceName").expect("")); @@ -88,11 +96,15 @@ auto main() -> int { // event callback or an interrupt/termination signal was received. waitset.wait_and_process(on_event).expect(""); - std::cout << "exit ..." << std::endl; + std::cout << "exit" << std::endl; return 0; } +/////////////////////////////////////////////// +/// START: EventBasedPublisher implementation +/////////////////////////////////////////////// + EventBasedPublisher::EventBasedPublisher(Publisher&& publisher, Listener&& listener, Notifier&& notifier) diff --git a/examples/cxx/event_based_communication/src/pubsub_event.hpp b/examples/cxx/event_based_communication/src/pubsub_event.hpp index 082171e30..e180c1f12 100644 --- a/examples/cxx/event_based_communication/src/pubsub_event.hpp +++ b/examples/cxx/event_based_communication/src/pubsub_event.hpp @@ -38,19 +38,19 @@ constexpr auto from(const PubSubEvent value) noexcept -> si template <> constexpr auto from(const size_t value) noexcept -> PubSubEvent { switch (value) { - case from(PubSubEvent::PublisherConnected): + case into(PubSubEvent::PublisherConnected): return PubSubEvent::PublisherConnected; - case from(PubSubEvent::PublisherDisconnected): + case into(PubSubEvent::PublisherDisconnected): return PubSubEvent::PublisherDisconnected; - case from(PubSubEvent::SubscriberConnected): + case into(PubSubEvent::SubscriberConnected): return PubSubEvent::SubscriberConnected; - case from(PubSubEvent::SubscriberDisconnected): + case into(PubSubEvent::SubscriberDisconnected): return PubSubEvent::SubscriberDisconnected; - case from(PubSubEvent::SentSample): + case into(PubSubEvent::SentSample): return PubSubEvent::SentSample; - case from(PubSubEvent::ReceivedSample): + case into(PubSubEvent::ReceivedSample): return PubSubEvent::ReceivedSample; - case from(PubSubEvent::SentHistory): + case into(PubSubEvent::SentHistory): return PubSubEvent::SentHistory; default: return PubSubEvent::Unknown; diff --git a/examples/cxx/event_based_communication/src/subscriber.cpp b/examples/cxx/event_based_communication/src/subscriber.cpp index 89f2c5adf..43fa0147a 100644 --- a/examples/cxx/event_based_communication/src/subscriber.cpp +++ b/examples/cxx/event_based_communication/src/subscriber.cpp @@ -29,6 +29,10 @@ constexpr iox::units::Duration DEADLINE = iox::units::Duration::fromSeconds(2); using namespace iox2; +/////////////////////////////////////////////// +/// START: EventBasedSubscriber declaration +/////////////////////////////////////////////// + // 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 @@ -58,6 +62,10 @@ class EventBasedSubscriber : public FileDescriptorBased { Listener m_listener; }; +/////////////////////////////////////////////// +/// START: main +/////////////////////////////////////////////// + auto main() -> int { auto node = NodeBuilder().create().expect("successful node creation"); @@ -89,6 +97,10 @@ auto main() -> int { return 0; } +/////////////////////////////////////////////// +/// START: EventBasedSubscriber implementation +/////////////////////////////////////////////// + EventBasedSubscriber::EventBasedSubscriber(Subscriber&& subscriber, Notifier&& notifier, Listener&& listener) diff --git a/examples/rust/event_based_communication/publisher.rs b/examples/rust/event_based_communication/publisher.rs index 69f0388aa..834ac971c 100644 --- a/examples/rust/event_based_communication/publisher.rs +++ b/examples/rust/event_based_communication/publisher.rs @@ -54,7 +54,7 @@ fn main() -> Result<(), Box> { // event callback or an interrupt/termination signal was received. waitset.wait_and_process(on_event)?; - println!("exit ..."); + println!("exit"); Ok(()) } diff --git a/examples/rust/event_multiplexing/wait.rs b/examples/rust/event_multiplexing/wait.rs index 2506123bf..69ea220df 100644 --- a/examples/rust/event_multiplexing/wait.rs +++ b/examples/rust/event_multiplexing/wait.rs @@ -78,7 +78,7 @@ fn main() -> Result<(), Box> { // didn't add this to the example so feel free to play around with it. waitset.wait_and_process(on_event)?; - println!("Exit"); + println!("exit"); Ok(()) }