From 15f2f3562a536ca24a87728e1c66d5c90a56812e Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Sun, 24 Nov 2024 16:19:48 +0100 Subject: [PATCH] [#390] Add readme --- .../cxx/event_based_communication/README.md | 36 ++++++++++++++++++- .../src/pubsub_event.hpp | 4 +-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/examples/cxx/event_based_communication/README.md b/examples/cxx/event_based_communication/README.md index 9656f4804..868c4151e 100644 --- a/examples/cxx/event_based_communication/README.md +++ b/examples/cxx/event_based_communication/README.md @@ -1 +1,35 @@ -# asd +# Event-Based Communication + +## Running The Example + +This example demonstrates iceoryx2's event multiplexing mechanism in a more +complex setup. The iceoryx2 `Publisher` and `Subscriber` are integrated into +custom `ExamplePublisher` and `ExampleSubscriber` classes, which also +incorporate an additional iceoryx2 `Notifier` and `Listener`. This setup +enables automatic event emission whenever an `ExamplePublisher` or +`ExampleSubscriber` is created or dropped. Additionally, events are emitted +whenever a new `Sample` is sent or received. + +When a `class` inherits from `FileDescriptorBased`, it can be attached to a +`WaitSet`. Both `ExamplePublisher` and `ExampleSubscriber` implement this +interface by forwarding calls to their underlying `Listener`, which already +provides an implementation of `FileDescriptorBased`. + +The `WaitSet` notifies the user of the origin of an event notification. The +user can then acquire the `EventId` from the `Listener`. Based on the value of +the `EventId`, the user can identify the specific event that occurred and take +appropriate action. + +### Terminal 1 + +```sh +./target/ffi/build/examples/cxx/event_based_communication/example_cxx_event_based_communication_publisher +``` + +### Terminal 2 + +```sh +./target/ffi/build/examples/cxx/event_based_communication/example_cxx_event_based_communication_subscriber +``` + +Feel free to run multiple publishers or subscribers in parallel. diff --git a/examples/cxx/event_based_communication/src/pubsub_event.hpp b/examples/cxx/event_based_communication/src/pubsub_event.hpp index 553f59376..082171e30 100644 --- a/examples/cxx/event_based_communication/src/pubsub_event.hpp +++ b/examples/cxx/event_based_communication/src/pubsub_event.hpp @@ -31,12 +31,12 @@ enum class PubSubEvent : uint8_t { namespace iox { template <> -inline constexpr auto from(const PubSubEvent value) noexcept -> size_t { +constexpr auto from(const PubSubEvent value) noexcept -> size_t { return static_cast(value); } template <> -inline constexpr auto from(const size_t value) noexcept -> PubSubEvent { +constexpr auto from(const size_t value) noexcept -> PubSubEvent { switch (value) { case from(PubSubEvent::PublisherConnected): return PubSubEvent::PublisherConnected;