From 140598928e013ffe830d8500696065e5256f68c0 Mon Sep 17 00:00:00 2001 From: youngday Date: Mon, 9 Dec 2024 22:59:28 +0800 Subject: [PATCH] iceoryx2 crate 0.3 to 0.4 --- Cargo.toml | 4 +-- config/iceoryx2.toml | 52 ++++++++++++++++++----------- examples/dds_iceoryx2/README.md | 26 +++++++++------ examples/dds_iceoryx2/publisher.rs | 18 +++++----- examples/dds_iceoryx2/subscriber.rs | 23 +++++++------ examples/mqtt/mqtt_asyncpubsub.rs | 6 ++-- src/custom_header.rs | 18 ++++++++++ src/lib.rs | 7 ++-- 8 files changed, 97 insertions(+), 57 deletions(-) create mode 100644 src/custom_header.rs diff --git a/Cargo.toml b/Cargo.toml index e00ed4e..d84dec0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,8 +49,8 @@ futures-util = { version = "0.3", default-features = false, features = ["sink", tmq = { version = "0.5" } -rumqttc = "0.24.0" -rumqttd="0.19.0" +rumqttc = "0.24" +rumqttd="0.19" base64 = "0.22" ndarray = "0.16" diff --git a/config/iceoryx2.toml b/config/iceoryx2.toml index 132eecc..e97d446 100644 --- a/config/iceoryx2.toml +++ b/config/iceoryx2.toml @@ -1,28 +1,40 @@ [global] -root_path_unix = '/tmp/iceoryx2/' -root_path_windows = 'c:\Temp\iceoryx2\' +root-path-unix = '/tmp/iceoryx2/' +root-path-windows = 'c:\Temp\iceoryx2\' prefix = 'iox2_' +[global.node] +directory = 'nodes' +monitor-suffix = '.node_monitor' +static-config-suffix = '.details' +service-tag-suffix = '.service_tag' +cleanup-dead-nodes-on-creation = true +cleanup-dead-nodes-on-destruction = true + [global.service] directory = 'services' -publisher_data_segment_suffix = '.publisher_data' -static_config_storage_suffix = '.service' -dynamic_config_storage_suffix = '.dynamic' -connection_suffix = '.connection' -creation_timeout.secs = 0 -creation_timeout.nanos = 500000000 +publisher-data-segment-suffix = '.publisher_data' +static-config-storage-suffix = '.service' +dynamic-config-storage-suffix = '.dynamic' +event-connection-suffix = '.event' +connection-suffix = '.connection' +creation-timeout.secs = 0 +creation-timeout.nanos = 500000000 -[defaults.publish_subscribe] -max_subscribers = 8 -max_publishers = 2 -publisher_history_size = 1 -subscriber_max_buffer_size = 2 -subscriber_max_borrowed_samples = 2 -publisher_max_loaned_samples = 2 -enable_safe_overflow = true -unable_to_deliver_strategy = 'block' # or 'discard_sample' +[defaults.publish-subscribe] +max-subscribers = 8 +max-publishers = 2 +max-nodes = 20 +publisher-history-size = 1 +subscriber-max-buffer-size = 2 +subscriber-max-borrowed-samples = 2 +publisher-max-loaned-samples = 2 +enable-safe-overflow = true +unable-to-deliver-strategy = 'Block' # or 'DiscardSample' +subscriber-expired-connection-buffer = 128 [defaults.event] -max_listeners = 2 -max_notifiers = 16 -event_id_max_value = 32 +max-listeners = 2 +max-notifiers = 16 +max-nodes = 36 +event-id-max-value = 32 diff --git a/examples/dds_iceoryx2/README.md b/examples/dds_iceoryx2/README.md index 0cb4ace..f24ddc3 100644 --- a/examples/dds_iceoryx2/README.md +++ b/examples/dds_iceoryx2/README.md @@ -2,28 +2,34 @@ ## Running The Example -This example vividly illustrates a robust publisher-subscriber communication -pattern between two separate processes. The publisher diligently sends two -messages every second, each containing essential [`TransmissionData`]. On the -receiving end, the subscriber checks for new data every second. +This example illustrates a robust publisher-subscriber communication pattern +between two separate processes. The publisher sends two messages every second, +each containing [`TransmissionData`]. On the receiving end, the subscriber +checks for new data every second. The subscriber is printing the sample on the console whenever new data arrives. -To observe this dynamic communication in action, open two separate terminals -and execute the following commands: +To observe this dynamic communication in action, open two separate terminals and +execute the following commands: -**Terminal 1** +### Terminal 1 ```sh cargo run --example publish_subscribe_subscriber ``` -**Terminal 2** +### Terminal 2 ```sh cargo run --example publish_subscribe_publisher ``` Feel free to run multiple instances of publisher or subscriber processes -simultaneously to explore how Iceoryx2 handles publisher-subscriber communication -efficiently. +simultaneously to explore how iceoryx2 handles publisher-subscriber +communication efficiently. + +You may hit the maximum supported number of ports when too many publisher or +subscriber processes run. Take a look at the [iceoryx2 config](../../../config) +to set the limits globally or at the +[API of the Service builder](https://docs.rs/iceoryx2/latest/iceoryx2/service/index.html) +to set them for a single service. diff --git a/examples/dds_iceoryx2/publisher.rs b/examples/dds_iceoryx2/publisher.rs index e29461b..11d5605 100644 --- a/examples/dds_iceoryx2/publisher.rs +++ b/examples/dds_iceoryx2/publisher.rs @@ -11,23 +11,24 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT use core::time::Duration; +use easy_example::TransmissionData; use iceoryx2::prelude::*; -use easy_example::transmission_data::TransmissionData; const CYCLE_TIME: Duration = Duration::from_secs(1); fn main() -> Result<(), Box> { - let service_name = ServiceName::new("My/Funk/ServiceName")?; + let node = NodeBuilder::new().create::()?; - let service = zero_copy::Service::new(&service_name) - .publish_subscribe() - .open_or_create::()?; + let service = node + .service_builder(&"My/Funk/ServiceName".try_into()?) + .publish_subscribe::() + .open_or_create()?; - let publisher = service.publisher().create()?; + let publisher = service.publisher_builder().create()?; let mut counter: u64 = 0; - while let Iox2Event::Tick = Iox2::wait(CYCLE_TIME) { + while let NodeEvent::Tick = node.wait(CYCLE_TIME) { counter += 1; let sample = publisher.loan_uninit()?; @@ -42,8 +43,7 @@ fn main() -> Result<(), Box> { println!("Send sample {} ...", counter); } - println!("exit ..."); + println!("exit"); Ok(()) - } diff --git a/examples/dds_iceoryx2/subscriber.rs b/examples/dds_iceoryx2/subscriber.rs index 3b2005e..3d6c45b 100644 --- a/examples/dds_iceoryx2/subscriber.rs +++ b/examples/dds_iceoryx2/subscriber.rs @@ -9,29 +9,30 @@ // which is available at https://opensource.org/licenses/MIT. // // SPDX-License-Identifier: Apache-2.0 OR MIT -// mod transmission_data; + use core::time::Duration; +use easy_example::TransmissionData; use iceoryx2::prelude::*; -use easy_example::transmission_data::TransmissionData; const CYCLE_TIME: Duration = Duration::from_secs(1); -#[tokio::main] -async fn main() -> Result<(), Box> { - let service_name = ServiceName::new("My/Funk/ServiceName")?; - let service = zero_copy::Service::new(&service_name) - .publish_subscribe() - .open_or_create::()?; +fn main() -> Result<(), Box> { + let node = NodeBuilder::new().create::()?; + + let service = node + .service_builder(&"My/Funk/ServiceName".try_into()?) + .publish_subscribe::() + .open_or_create()?; - let subscriber = service.subscriber().create()?; + let subscriber = service.subscriber_builder().create()?; - while let Iox2Event::Tick = Iox2::wait(CYCLE_TIME) { + while let NodeEvent::Tick = node.wait(CYCLE_TIME) { while let Some(sample) = subscriber.receive()? { println!("received: {:?}", *sample); } } - println!("exit ..."); + println!("exit"); Ok(()) } diff --git a/examples/mqtt/mqtt_asyncpubsub.rs b/examples/mqtt/mqtt_asyncpubsub.rs index 3c11e44..71ce011 100644 --- a/examples/mqtt/mqtt_asyncpubsub.rs +++ b/examples/mqtt/mqtt_asyncpubsub.rs @@ -1,12 +1,12 @@ -use log::{debug, error, info, trace, warn}; +// use log::{debug, error, info, trace, warn}; +use log::info; use log4rs; use tokio::{task, time}; use std::error::Error; use std::time::Duration; -use rumqttc::v5::mqttbytes::QoS; -use rumqttc::v5::{AsyncClient, MqttOptions}; +use rumqttc::v5::{AsyncClient, MqttOptions,mqttbytes::QoS}; #[tokio::main(flavor = "current_thread")] async fn main() -> Result<(), Box> { diff --git a/src/custom_header.rs b/src/custom_header.rs new file mode 100644 index 0000000..ffe056b --- /dev/null +++ b/src/custom_header.rs @@ -0,0 +1,18 @@ +// Copyright (c) 2024 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available under the +// terms of the Apache Software License 2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license +// which is available at https://opensource.org/licenses/MIT. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT + +#[derive(Default, Debug)] +#[repr(C)] +pub struct CustomHeader { + pub version: i32, + pub timestamp: u64, +} diff --git a/src/lib.rs b/src/lib.rs index 09b8840..e57d1d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ // #[macro_use] extern crate cli_log; +pub mod custom_header; pub mod transmission_data; pub mod zenoh_lib; pub mod settings; @@ -7,6 +8,8 @@ pub mod settings; // #[cfg(unix)] // pub mod filesystems; - // #[cfg(unix)] -// pub mod net; \ No newline at end of file +// pub mod net; +// mod transmission_data; +pub use custom_header::CustomHeader; +pub use transmission_data::TransmissionData;