Skip to content

Commit

Permalink
iceoryx2 crate 0.3 to 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
youngday committed Dec 9, 2024
1 parent 8658e5f commit 1405989
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 57 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
52 changes: 32 additions & 20 deletions config/iceoryx2.toml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 16 additions & 10 deletions examples/dds_iceoryx2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
18 changes: 9 additions & 9 deletions examples/dds_iceoryx2/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
let service_name = ServiceName::new("My/Funk/ServiceName")?;
let node = NodeBuilder::new().create::<ipc::Service>()?;

let service = zero_copy::Service::new(&service_name)
.publish_subscribe()
.open_or_create::<TransmissionData>()?;
let service = node
.service_builder(&"My/Funk/ServiceName".try_into()?)
.publish_subscribe::<TransmissionData>()
.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()?;

Expand All @@ -42,8 +43,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Send sample {} ...", counter);
}

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

Ok(())

}
23 changes: 12 additions & 11 deletions examples/dds_iceoryx2/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
let service_name = ServiceName::new("My/Funk/ServiceName")?;

let service = zero_copy::Service::new(&service_name)
.publish_subscribe()
.open_or_create::<TransmissionData>()?;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let node = NodeBuilder::new().create::<ipc::Service>()?;

let service = node
.service_builder(&"My/Funk/ServiceName".try_into()?)
.publish_subscribe::<TransmissionData>()
.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(())
}
6 changes: 3 additions & 3 deletions examples/mqtt/mqtt_asyncpubsub.rs
Original file line number Diff line number Diff line change
@@ -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<dyn Error>> {
Expand Down
18 changes: 18 additions & 0 deletions src/custom_header.rs
Original file line number Diff line number Diff line change
@@ -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,
}
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// #[macro_use] extern crate cli_log;

pub mod custom_header;
pub mod transmission_data;
pub mod zenoh_lib;
pub mod settings;
// mod build;
// #[cfg(unix)]
// pub mod filesystems;


// #[cfg(unix)]
// pub mod net;
// pub mod net;
// mod transmission_data;
pub use custom_header::CustomHeader;
pub use transmission_data::TransmissionData;

0 comments on commit 1405989

Please sign in to comment.