From 60a556b4cc8260492402947d7ce3a18b09fe079f Mon Sep 17 00:00:00 2001 From: Artem Shein Date: Thu, 19 Mar 2026 16:40:17 +0100 Subject: [PATCH] Re-enable iceoryx2 backend in feo-com --- src/feo-com/BUILD.bazel | 24 +++++------- src/feo-com/src/iox2/mod.rs | 76 ++++++++++++++++++++++++------------- 2 files changed, 59 insertions(+), 41 deletions(-) diff --git a/src/feo-com/BUILD.bazel b/src/feo-com/BUILD.bazel index 69f747a..495b144 100644 --- a/src/feo-com/BUILD.bazel +++ b/src/feo-com/BUILD.bazel @@ -17,28 +17,25 @@ rust_library( name = "libfeo_com_rust_mw_com", srcs = [ "src/interface.rs", - # Disabled due to compilation error of iceoryx2 - # "src/iox2/mod.rs", + "src/iox2/mod.rs", "src/lib.rs", "src/linux_shm/mod.rs", "src/linux_shm/shared_memory.rs", "src/mw_com/mod.rs", ], crate_features = [ - # Disabled due to compilation error of iceoryx2 - # "ipc_iceoryx2", + "ipc_iceoryx2", "ipc_linux_shm", "ipc_mw_com", ], crate_name = "feo_com", visibility = ["//visibility:public"], deps = [ - # Disabled due to compilation error of iceoryx2 - # "@score_crates//:iceoryx2", - "@score_crates//:nix", - "@score_crates//:rand", "@score_baselibs_rust//src/log/score_log", "@score_communication//score/mw/com/impl/rust/com-api/com-api", + "@score_crates//:iceoryx2", + "@score_crates//:nix", + "@score_crates//:rand", ], ) @@ -46,24 +43,21 @@ rust_library( name = "libfeo_com_rust", srcs = [ "src/interface.rs", - # Disabled due to compilation error of iceoryx2 - # "src/iox2/mod.rs", + "src/iox2/mod.rs", "src/lib.rs", "src/linux_shm/mod.rs", "src/linux_shm/shared_memory.rs", ], crate_features = [ - # Disabled due to compilation error of iceoryx2 - # "ipc_iceoryx2", + "ipc_iceoryx2", "ipc_linux_shm", ], crate_name = "feo_com", visibility = ["//visibility:public"], deps = [ - # Disabled due to compilation error of iceoryx2 - # "@score_crates//:iceoryx2", + "@score_baselibs_rust//src/log/score_log", + "@score_crates//:iceoryx2", "@score_crates//:nix", "@score_crates//:rand", - "@score_baselibs_rust//src/log/score_log", ], ) diff --git a/src/feo-com/src/iox2/mod.rs b/src/feo-com/src/iox2/mod.rs index e940315..c1728a3 100644 --- a/src/feo-com/src/iox2/mod.rs +++ b/src/feo-com/src/iox2/mod.rs @@ -13,16 +13,16 @@ //! iceoryx2 com backend +use crate::interface::FeoComData; +use crate::interface::FeoComDefault; use crate::interface::{ ActivityInput, ActivityOutput, ActivityOutputDefault, Error, InputGuard, OutputGuard, OutputUninitGuard, Topic, TopicHandle, }; use alloc::boxed::Box; use alloc::format; -use core::fmt; use core::mem::MaybeUninit; use core::ops::{Deref, DerefMut}; -use feo_log::{error, info}; use iceoryx2::config::Config; use iceoryx2::node::{Node, NodeBuilder, NodeState}; use iceoryx2::port::publisher::Publisher; @@ -32,11 +32,15 @@ use iceoryx2::sample::Sample; use iceoryx2::sample_mut::SampleMut; use iceoryx2::sample_mut_uninit::SampleMutUninit; use iceoryx2::service::ipc; +use score_log::{error, info}; use std::process; /// Initialize topic with the given number of writers (publishers) and readers (subscribers). -pub fn init_topic(topic: Topic, writers: usize, readers: usize) -> TopicHandle { - info!("Initializing topic {topic} (Iceoryx2, {writers} writers and {readers} readers)"); +pub fn init_topic(topic: Topic, writers: usize, readers: usize) -> TopicHandle { + info!( + "Initializing topic {} (Iceoryx2, {} writers and {} readers)", + topic, writers, readers + ); let port_factory = ipc_node() .service_builder(&(*topic).try_into().unwrap_or_else(|_| panic!("invalid topic {topic}"))) .publish_subscribe::() @@ -53,14 +57,14 @@ pub fn init_topic(topic: Topic, writers: usize, r #[derive(Debug)] pub struct Iox2Input where - T: fmt::Debug + 'static, + T: FeoComData + 'static, { subscriber: Subscriber, } impl Iox2Input where - T: fmt::Debug + 'static, + T: FeoComData + 'static, { // Create a new instance for the given `topic` pub fn new(topic: &str) -> Self { @@ -78,9 +82,9 @@ where impl ActivityInput for Iox2Input where - T: fmt::Debug + 'static, + T: FeoComData + 'static, { - fn read(&self) -> Result, Error> { + fn read(&self) -> Result, Error> { match self.subscriber.receive() { Ok(Some(sample)) => Ok(InputGuard::Iox2(Iox2InputGuard { sample })), Ok(None) | Err(_) => Err(Error::NoEmptyBuffer), @@ -92,14 +96,14 @@ where #[derive(Debug)] pub struct Iox2Output where - T: fmt::Debug + 'static, + T: FeoComData + 'static, { publisher: Publisher, } impl Iox2Output where - T: fmt::Debug + 'static, + T: FeoComData + 'static, { // Create a new instance for the given `topic` pub fn new(topic: &str) -> Self { @@ -117,10 +121,10 @@ where impl ActivityOutput for Iox2Output where - T: fmt::Debug + 'static, + T: FeoComData + 'static, { /// Get a handle to an uninitialized buffer - fn write_uninit(&mut self) -> Result, Error> { + fn write_uninit(&mut self) -> Result, Error> { self.publisher .loan_uninit() .map(|sample| OutputUninitGuard::Iox2(Iox2OutputUninitGuard { sample })) @@ -130,10 +134,10 @@ where impl ActivityOutputDefault for Iox2Output where - T: fmt::Debug + Default + 'static, + T: FeoComData + FeoComDefault + 'static, { /// Get a handle to a buffer initialized with the [Default] trait - fn write_init(&mut self) -> Result, Error> { + fn write_init(&mut self) -> Result, Error> { self.publisher .loan() .map(|sample| OutputGuard::Iox2(Iox2OutputGuard { sample })) @@ -142,11 +146,11 @@ where } /// Handle to an input buffer -pub struct Iox2InputGuard { +pub struct Iox2InputGuard { sample: Sample, } -impl Deref for Iox2InputGuard { +impl Deref for Iox2InputGuard { type Target = T; fn deref(&self) -> &Self::Target { @@ -155,13 +159,13 @@ impl Deref for Iox2InputGuard { } /// Handle to an initialized output buffer -pub struct Iox2OutputGuard { +pub struct Iox2OutputGuard { sample: SampleMut, } impl Iox2OutputGuard where - T: fmt::Debug, + T: FeoComData, { /// Send this buffer, making it receivable as input and consuming the buffer pub(crate) fn send(self) -> Result<(), Error> { @@ -169,7 +173,7 @@ where } } -impl Deref for Iox2OutputGuard { +impl Deref for Iox2OutputGuard { type Target = T; fn deref(&self) -> &Self::Target { @@ -177,20 +181,20 @@ impl Deref for Iox2OutputGuard { } } -impl DerefMut for Iox2OutputGuard { +impl DerefMut for Iox2OutputGuard { fn deref_mut(&mut self) -> &mut Self::Target { self.sample.payload_mut() } } /// Handle to an uninitialized output buffer -pub struct Iox2OutputUninitGuard { +pub struct Iox2OutputUninitGuard { sample: SampleMutUninit, ()>, } impl Iox2OutputUninitGuard where - T: fmt::Debug, + T: FeoComData, { /// Assume the backing buffer is initialized /// @@ -211,7 +215,7 @@ where impl Iox2OutputUninitGuard where - T: fmt::Debug + Default, + T: FeoComData + FeoComDefault, { /// Initialize this buffer with its [Default] implementation pub(crate) fn init(self) -> Iox2OutputGuard { @@ -220,7 +224,7 @@ where } } -impl Deref for Iox2OutputUninitGuard { +impl Deref for Iox2OutputUninitGuard { type Target = MaybeUninit; fn deref(&self) -> &Self::Target { @@ -228,7 +232,7 @@ impl Deref for Iox2OutputUninitGuard { } } -impl DerefMut for Iox2OutputUninitGuard { +impl DerefMut for Iox2OutputUninitGuard { fn deref_mut(&mut self) -> &mut Self::Target { self.sample.payload_mut() } @@ -249,7 +253,10 @@ fn ipc_node() -> &'static Node { Node::::list(&config, |node_state| { if let NodeState::::Dead(view) = node_state { if let Err(e) = view.remove_stale_resources() { - error!("Failed to clean iceoryx2 resources: {:?}", e); + error!( + "Failed to clean iceoryx2 resources: {:?}", + NodeCleanupFailureScoreDebug(e) + ); } } CallbackProgression::Continue @@ -265,3 +272,20 @@ fn ipc_node() -> &'static Node { .expect("failed to create ipc node") }) } + +struct NodeCleanupFailureScoreDebug(iceoryx2::node::NodeCleanupFailure); + +impl score_log::fmt::ScoreDebug for NodeCleanupFailureScoreDebug { + fn fmt( + &self, + w: &mut dyn score_log::fmt::ScoreWrite, + spec: &score_log::fmt::FormatSpec, + ) -> Result<(), score_log::fmt::Error> { + use iceoryx2::node::NodeCleanupFailure; + match self.0 { + NodeCleanupFailure::Interrupt => w.write_str("interrupt", spec), + NodeCleanupFailure::InternalError => w.write_str("internal error", spec), + NodeCleanupFailure::InsufficientPermissions => w.write_str("insufficient permissions", spec), + } + } +}