Skip to content

Commit

Permalink
[#390] Fix typos; clearer structure for example
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Nov 25, 2024
1 parent cb41a30 commit 8c67b11
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
14 changes: 13 additions & 1 deletion examples/cxx/event_based_communication/src/publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -58,6 +62,10 @@ class EventBasedPublisher : public FileDescriptorBased {
Notifier<ServiceType::Ipc> m_notifier;
};

///////////////////////////////////////////////
/// START: main
///////////////////////////////////////////////

auto main() -> int {
auto node = NodeBuilder().create<ServiceType::Ipc>().expect("successful node creation");
auto publisher = EventBasedPublisher::create(node, ServiceName::create("My/Funk/ServiceName").expect(""));
Expand Down Expand Up @@ -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<ServiceType::Ipc, TransmissionData, void>&& publisher,
Listener<ServiceType::Ipc>&& listener,
Notifier<ServiceType::Ipc>&& notifier)
Expand Down
14 changes: 7 additions & 7 deletions examples/cxx/event_based_communication/src/pubsub_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ constexpr auto from<PubSubEvent, size_t>(const PubSubEvent value) noexcept -> si
template <>
constexpr auto from<size_t, PubSubEvent>(const size_t value) noexcept -> PubSubEvent {
switch (value) {
case from<PubSubEvent, size_t>(PubSubEvent::PublisherConnected):
case into<size_t>(PubSubEvent::PublisherConnected):
return PubSubEvent::PublisherConnected;
case from<PubSubEvent, size_t>(PubSubEvent::PublisherDisconnected):
case into<size_t>(PubSubEvent::PublisherDisconnected):
return PubSubEvent::PublisherDisconnected;
case from<PubSubEvent, size_t>(PubSubEvent::SubscriberConnected):
case into<size_t>(PubSubEvent::SubscriberConnected):
return PubSubEvent::SubscriberConnected;
case from<PubSubEvent, size_t>(PubSubEvent::SubscriberDisconnected):
case into<size_t>(PubSubEvent::SubscriberDisconnected):
return PubSubEvent::SubscriberDisconnected;
case from<PubSubEvent, size_t>(PubSubEvent::SentSample):
case into<size_t>(PubSubEvent::SentSample):
return PubSubEvent::SentSample;
case from<PubSubEvent, size_t>(PubSubEvent::ReceivedSample):
case into<size_t>(PubSubEvent::ReceivedSample):
return PubSubEvent::ReceivedSample;
case from<PubSubEvent, size_t>(PubSubEvent::SentHistory):
case into<size_t>(PubSubEvent::SentHistory):
return PubSubEvent::SentHistory;
default:
return PubSubEvent::Unknown;
Expand Down
12 changes: 12 additions & 0 deletions examples/cxx/event_based_communication/src/subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,6 +62,10 @@ class EventBasedSubscriber : public FileDescriptorBased {
Listener<ServiceType::Ipc> m_listener;
};

///////////////////////////////////////////////
/// START: main
///////////////////////////////////////////////

auto main() -> int {
auto node = NodeBuilder().create<ServiceType::Ipc>().expect("successful node creation");

Expand Down Expand Up @@ -89,6 +97,10 @@ auto main() -> int {
return 0;
}

///////////////////////////////////////////////
/// START: EventBasedSubscriber implementation
///////////////////////////////////////////////

EventBasedSubscriber::EventBasedSubscriber(Subscriber<ServiceType::Ipc, TransmissionData, void>&& subscriber,
Notifier<ServiceType::Ipc>&& notifier,
Listener<ServiceType::Ipc>&& listener)
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/event_based_communication/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// event callback or an interrupt/termination signal was received.
waitset.wait_and_process(on_event)?;

println!("exit ...");
println!("exit");

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/event_multiplexing/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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(())
}
Expand Down

0 comments on commit 8c67b11

Please sign in to comment.