Browse Source

Merge pull request #201 from dora-rs/remove-icoryx

Remove iceoryx dependency
tags/v0.2.0-candidate
Philipp Oppermann GitHub 2 years ago
parent
commit
8be922a74d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1 additions and 251 deletions
  1. +0
    -71
      Cargo.lock
  2. +1
    -6
      libraries/communication-layer/pub-sub/Cargo.toml
  3. +0
    -158
      libraries/communication-layer/pub-sub/src/iceoryx.rs
  4. +0
    -5
      libraries/communication-layer/pub-sub/src/lib.rs
  5. +0
    -11
      libraries/core/src/config.rs

+ 0
- 71
Cargo.lock View File

@@ -567,8 +567,6 @@ name = "communication-layer-pub-sub"
version = "0.1.3"
dependencies = [
"eyre",
"iceoryx-rs",
"iceoryx-sys",
"zenoh",
"zenoh-config",
]
@@ -611,56 +609,6 @@ version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"

[[package]]
name = "cpp"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dec5e86d4f6547f0218ad923d9508244a71ef83b763196e6698b4f70f3595185"
dependencies = [
"cpp_macros",
]

[[package]]
name = "cpp_build"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16f4d303b8ec35fb3afd7e963e2c898117f1e49930becb703e4a7ac528ad2dd0"
dependencies = [
"cc",
"cpp_common",
"lazy_static",
"proc-macro2",
"regex",
"syn",
"unicode-xid",
]

[[package]]
name = "cpp_common"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76071bb9c8c4dd2b5eb209907deab7b031323cf1be3dfdc6ec5d37f4f187d8a1"
dependencies = [
"lazy_static",
"proc-macro2",
"syn",
]

[[package]]
name = "cpp_macros"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fdaa01904c12a8989dbfa110b41ef27efc432ac9934f691b9732f01cb64dc01"
dependencies = [
"aho-corasick",
"byteorder",
"cpp_common",
"lazy_static",
"proc-macro2",
"quote",
"syn",
]

[[package]]
name = "cpufeatures"
version = "0.2.2"
@@ -1713,25 +1661,6 @@ dependencies = [
"tokio-native-tls",
]

[[package]]
name = "iceoryx-rs"
version = "0.1.0"
source = "git+https://github.com/eclipse-iceoryx/iceoryx-rs.git#68fbd034a77c6ed98cb75a939d406429ef26b0dd"
dependencies = [
"iceoryx-sys",
"thiserror",
]

[[package]]
name = "iceoryx-sys"
version = "0.1.0"
source = "git+https://github.com/eclipse-iceoryx/iceoryx-rs.git#68fbd034a77c6ed98cb75a939d406429ef26b0dd"
dependencies = [
"cpp",
"cpp_build",
"thiserror",
]

[[package]]
name = "idna"
version = "0.2.3"


+ 1
- 6
libraries/communication-layer/pub-sub/Cargo.toml View File

@@ -4,19 +4,14 @@ version.workspace = true
edition = "2021"

[features]
default = ["zenoh", "iceoryx"]
default = ["zenoh"]
zenoh = ["dep:zenoh", "dep:zenoh-config"]
iceoryx = ["dep:iceoryx-rs", "dep:iceoryx-sys"]

[dependencies]
eyre = "0.6.8"
zenoh = { git = "https://github.com/eclipse-zenoh/zenoh.git", rev = "79a136e4fd90b11ff5d775ced981af53c4f1071b", optional = true }
zenoh-config = { git = "https://github.com/eclipse-zenoh/zenoh.git", rev = "79a136e4fd90b11ff5d775ced981af53c4f1071b", optional = true }

[target.'cfg(unix)'.dependencies]
iceoryx-rs = { git = "https://github.com/eclipse-iceoryx/iceoryx-rs.git", optional = true }
iceoryx-sys = { git = "https://github.com/eclipse-iceoryx/iceoryx-rs.git", optional = true }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

+ 0
- 158
libraries/communication-layer/pub-sub/src/iceoryx.rs View File

@@ -1,158 +0,0 @@
//! Provides [`IceoryxCommunicationLayer`] to communicate over `iceoryx`.

use super::{CommunicationLayer, Publisher, Subscriber};
use crate::{BoxError, ReceivedSample};
use eyre::Context;
use std::{borrow::Cow, collections::HashMap, sync::Arc, time::Duration};

/// Enables local communication based on `iceoryx`.
pub struct IceoryxCommunicationLayer {
group_name: String,
instance_name: String,
publishers: HashMap<String, Arc<iceoryx_rs::Publisher<[u8]>>>,
}

impl IceoryxCommunicationLayer {
/// Initializes a new `iceoryx` connection with default configuration.
///
/// The given `app_name` must be unique. The `group_name` and
/// `instance_name` arguments are used to create an `iceoryx`
/// `ServiceDescription` in combination wiith topic names given to the
/// [`publisher`][Self::publisher] and [`subscriber`][Self::subscribe]
/// methods. See the
/// [`iceoryx` documentation](https://iceoryx.io/v2.0.1/getting-started/overview/#creating-service-descriptions-for-topics)
/// for details.
///
/// Note: In order to use iceoryx, you need to start its broker deamon called
/// [_RouDi_](https://iceoryx.io/v2.0.2/getting-started/overview/#roudi) first.
/// Its executable name is `iox-roudi`. See the
/// [`iceoryx` installation chapter](https://iceoryx.io/v2.0.2/getting-started/installation/)
/// for ways to install it.
pub fn init(
app_name: String,
group_name: String,
instance_name: String,
) -> Result<Self, BoxError> {
iceoryx_rs::Runtime::init(&app_name);

Ok(Self {
group_name,
instance_name,
publishers: Default::default(),
})
}
}

impl IceoryxCommunicationLayer {
fn get_or_create_publisher(
&mut self,
topic: &str,
) -> eyre::Result<Arc<iceoryx_rs::Publisher<[u8]>>> {
match self.publishers.get(topic) {
Some(p) => Ok(p.clone()),
None => {
let publisher =
Self::create_publisher(&self.group_name, &self.instance_name, topic)
.context("failed to create iceoryx publisher")?;

let publisher = Arc::new(publisher);
self.publishers.insert(topic.to_owned(), publisher.clone());
Ok(publisher)
}
}
}

fn create_publisher(
group: &str,
instance: &str,
topic: &str,
) -> Result<iceoryx_rs::Publisher<[u8]>, iceoryx_rs::IceoryxError> {
iceoryx_rs::PublisherBuilder::new(group, instance, topic).create()
}
}

impl CommunicationLayer for IceoryxCommunicationLayer {
fn publisher(&mut self, topic: &str) -> Result<Box<dyn Publisher>, crate::BoxError> {
let publisher = self
.get_or_create_publisher(topic)
.map_err(BoxError::from)?;

Ok(Box::new(IceoryxPublisher { publisher }))
}

fn subscribe(&mut self, topic: &str) -> Result<Box<dyn Subscriber>, crate::BoxError> {
let (subscriber, token) =
iceoryx_rs::SubscriberBuilder::new(&self.group_name, &self.instance_name, topic)
.queue_capacity(5)
.create_mt()
.context("failed to create iceoryx subscriber")
.map_err(BoxError::from)?;
let receiver = subscriber.get_sample_receiver(token);

Ok(Box::new(IceoryxReceiver { receiver }))
}
}

#[derive(Clone)]
struct IceoryxPublisher {
publisher: Arc<iceoryx_rs::Publisher<[u8]>>,
}

impl Publisher for IceoryxPublisher {
fn prepare(&self, len: usize) -> Result<Box<dyn crate::PublishSample + '_>, BoxError> {
let sample = self
.publisher
.loan_slice(len)
.context("failed to loan iceoryx slice for publishing")
.map_err(BoxError::from)?;
Ok(Box::new(IceoryxPublishSample {
sample,
publisher: self.publisher.clone(),
}))
}

fn dyn_clone(&self) -> Box<dyn Publisher> {
Box::new(self.clone())
}
}

struct IceoryxPublishSample<'a> {
publisher: Arc<iceoryx_rs::Publisher<[u8]>>,
sample: iceoryx_rs::SampleMut<'a, [u8]>,
}

impl<'a> crate::PublishSample<'a> for IceoryxPublishSample<'a> {
fn as_mut_slice(&mut self) -> &mut [u8] {
&mut self.sample
}

fn publish(self: Box<Self>) -> Result<(), BoxError> {
self.publisher.publish(self.sample);
Ok(())
}
}

struct IceoryxReceiver {
receiver: iceoryx_rs::mt::SampleReceiver<[u8]>,
}

impl Subscriber for IceoryxReceiver {
fn recv(&mut self) -> Result<Option<Box<dyn ReceivedSample>>, BoxError> {
self.receiver
.wait_for_samples(Duration::from_secs(u64::MAX));
match self.receiver.take() {
Some(sample) => Ok(Some(Box::new(IceoryxReceivedSample { sample }))),
None => Ok(None),
}
}
}

struct IceoryxReceivedSample {
sample: iceoryx_rs::Sample<[u8], iceoryx_sys::SubscriberArc>,
}

impl ReceivedSample for IceoryxReceivedSample {
fn get(&self) -> Cow<[u8]> {
Cow::Borrowed(&self.sample)
}
}

+ 0
- 5
libraries/communication-layer/pub-sub/src/lib.rs View File

@@ -9,14 +9,9 @@
//! - **[Zenoh](https://zenoh.io/):** The zenoh project implements a distributed
//! publisher/subscriber system with automated routing. To use zenoh, use the
//! [`ZenohCommunicationLayer`][zenoh::ZenohCommunicationLayer] struct.
//! - **[Iceoryx](https://iceoryx.io/):** The Eclipse iceoryx™ project provides an IPC middleware
//! based on shared memory. It is very fast, but it only supports local communication. To use
//! iceoryx, use the [`IceoryxCommunicationLayer`][iceoryx::IceoryxCommunicationLayer] struct.

use std::borrow::Cow;

#[cfg(all(unix, feature = "iceoryx"))]
pub mod iceoryx;
#[cfg(feature = "zenoh")]
pub mod zenoh;



+ 0
- 11
libraries/core/src/config.rs View File

@@ -257,11 +257,6 @@ pub enum CommunicationConfig {
config: Box<zenoh_config::Config>,
prefix: String,
},
Iceoryx {
app_name_prefix: String,
#[serde(default)]
topic_prefix: String,
},
}

impl CommunicationConfig {
@@ -273,12 +268,6 @@ impl CommunicationConfig {
} => {
write!(zenoh_prefix, "/{}", prefix).unwrap();
}
CommunicationConfig::Iceoryx { topic_prefix, .. } => {
if !topic_prefix.is_empty() {
topic_prefix.push('-');
}
topic_prefix.push_str(prefix);
}
}
}
}

Loading…
Cancel
Save