diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e916ec..4e4f2b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,15 +59,24 @@ jobs: - name: Code format check run: cargo fmt --check -- --config "unstable_features=true,imports_granularity=Crate,group_imports=StdExternalCrate" - name: Clippy without Cargo.lock + if: ${{ !startsWith(matrix.os, 'windows') }} run: | rm Cargo.lock cargo clippy --workspace --all-targets --features stats,dynamic_plugin,dds_shm -- --deny warnings git restore Cargo.lock + - name: Clippy without Cargo.lock (Windows, no dds_shm) + if: startsWith(matrix.os, 'windows') + run: | + rm Cargo.lock + cargo clippy --workspace --all-targets --features stats,dynamic_plugin -- --deny warnings + git restore Cargo.lock + - name: Build zenoh-plugin-ros2dds run: cargo build -p zenoh-plugin-ros2dds --verbose --all-targets - name: Build zenoh-plugin-ros2dds (with dds_shm) + if: ${{ !startsWith(matrix.os, 'windows') }} run: cargo build -p zenoh-plugin-ros2dds --features dds_shm --verbose --all-targets - name: Build zenoh-plugin-ros2dds (with prefix_symbols) @@ -77,6 +86,7 @@ jobs: run: cargo build -p zenoh-bridge-ros2dds --verbose --all-targets - name: Build zenoh-bridge-ros2dds (with dds_shm) + if: ${{ !startsWith(matrix.os, 'windows') }} run: cargo build -p zenoh-bridge-ros2dds --features dds_shm --verbose --all-targets - name: Build zenoh-bridge-ros2dds (with prefix_symbols) @@ -86,6 +96,7 @@ jobs: run: cargo test --verbose - name: Run tests (with dds_shm) + if: ${{ !startsWith(matrix.os, 'windows') }} run: cargo test --features dds_shm --verbose - name: Run tests (with prefix_symbols) diff --git a/Cargo.lock b/Cargo.lock index ccc5ab5..d28164e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1054,14 +1054,15 @@ dependencies = [ [[package]] name = "cyclors" -version = "0.2.7" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5ffb0648538c6d90a2848d4d622ce8e430788bfadfaaf9ebacfa785a2200134" +checksum = "ec736c2dd53e4ab504b3b88376e2cde17d9db2eb616218db703ca115ab10f089" dependencies = [ "bincode", "bindgen", "cmake", "derivative", + "home", "libc", "log", "serde", @@ -1730,11 +1731,11 @@ dependencies = [ [[package]] name = "home" -version = "0.5.12" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -5135,6 +5136,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.60.2" diff --git a/Cargo.toml b/Cargo.toml index 7f12150..ac5498b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ async-trait = "0.1.66" bincode = "1.3.3" cdr = "0.2.4" clap = "4.4.11" -cyclors = "=0.2.7" +cyclors = "=0.3.10" derivative = "2.2.0" flume = "0.11.0" futures = "0.3.26" diff --git a/zenoh-plugin-ros2dds/src/dds_types.rs b/zenoh-plugin-ros2dds/src/dds_types.rs index 0733eb2..bf88b1a 100644 --- a/zenoh-plugin-ros2dds/src/dds_types.rs +++ b/zenoh-plugin-ros2dds/src/dds_types.rs @@ -42,87 +42,25 @@ impl Drop for TypeInfo { unsafe impl Send for TypeInfo {} unsafe impl Sync for TypeInfo {} -#[cfg(feature = "dds_shm")] -#[derive(Clone, Copy)] -struct IoxChunk { - ptr: *mut std::ffi::c_void, - header: *mut iceoryx_header_t, -} - -#[cfg(feature = "dds_shm")] -impl IoxChunk { - fn as_slice(&self) -> &[u8] { - unsafe { slice::from_raw_parts(self.ptr as *const u8, (*self.header).data_size as usize) } - } - - fn len(&self) -> usize { - unsafe { (*self.header).data_size as usize } - } -} - pub struct DDSRawSample { sdref: *mut ddsi_serdata, data: ddsrt_iovec_t, - #[cfg(feature = "dds_shm")] - iox_chunk: Option, } impl DDSRawSample { pub unsafe fn create(serdata: *const ddsi_serdata) -> DDSRawSample { - let mut sdref: *mut ddsi_serdata = std::ptr::null_mut(); let mut data = ddsrt_iovec_t { iov_base: std::ptr::null_mut(), iov_len: 0, }; - #[cfg(feature = "dds_shm")] - let iox_chunk: Option = match ((*serdata).iox_chunk).is_null() { - false => { - let iox_chunk_ptr = (*serdata).iox_chunk; - let header = iceoryx_header_from_chunk(iox_chunk_ptr); - - // If the Iceoryx chunk contains raw sample data this needs to be serialized before forwading to Zenoh - if (*header).shm_data_state == iox_shm_data_state_t_IOX_CHUNK_CONTAINS_RAW_DATA { - let serialized_serdata = ddsi_serdata_from_sample( - (*serdata).type_, - (*serdata).kind, - (*serdata).iox_chunk, - ); - - let size = ddsi_serdata_size(serialized_serdata); - sdref = - ddsi_serdata_to_ser_ref(serialized_serdata, 0, size as usize, &mut data); - ddsi_serdata_unref(serialized_serdata); - - // IoxChunk not needed where raw data has been serialized - None - } else { - Some(IoxChunk { - ptr: iox_chunk_ptr, - header, - }) - } - } - true => None, - }; + // With cyclors 0.3.x / CycloneDDS PSMX, shared memory transport is handled + // transparently by CycloneDDS. Data is always available in serialized form + // through ddsi_serdata_to_ser_ref, regardless of the underlying transport. + let size = ddsi_serdata_size(serdata); + let sdref = ddsi_serdata_to_ser_ref(serdata, 0, size as usize, &mut data); - // At this point sdref will be null if: - // - // * Iceoryx was not enabled/used - in this case data will contain the CDR header and payload - // * Iceoryx chunk contained serialized data - in this case data will contain the CDR header - if sdref.is_null() { - let size = ddsi_serdata_size(serdata); - sdref = ddsi_serdata_to_ser_ref(serdata, 0, size as usize, &mut data); - } - - #[cfg(feature = "dds_shm")] - return DDSRawSample { - sdref, - data, - iox_chunk, - }; - #[cfg(not(feature = "dds_shm"))] - return DDSRawSample { sdref, data }; + DDSRawSample { sdref, data } } fn data_as_slice(&self) -> &[u8] { @@ -136,12 +74,6 @@ impl DDSRawSample { pub fn payload_as_slice(&self) -> &[u8] { unsafe { - #[cfg(feature = "dds_shm")] - { - if let Some(iox_chunk) = self.iox_chunk.as_ref() { - return iox_chunk.as_slice(); - } - } &slice::from_raw_parts( self.data.iov_base as *const u8, ddsrt_iov_len_to_usize(self.data.iov_len).unwrap(), @@ -150,29 +82,10 @@ impl DDSRawSample { } pub fn hex_encode(&self) -> String { - let mut encoded = String::new(); - let data_encoded = hex::encode(self.data_as_slice()); - encoded.push_str(data_encoded.as_str()); - - #[cfg(feature = "dds_shm")] - { - if let Some(iox_chunk) = self.iox_chunk.as_ref() { - let iox_encoded = hex::encode(iox_chunk.as_slice()); - encoded.push_str(iox_encoded.as_str()); - } - } - - encoded + hex::encode(self.data_as_slice()) } pub fn len(&self) -> usize { - #[cfg(feature = "dds_shm")] - { - TryInto::::try_into(self.data.iov_len).unwrap() - + self.iox_chunk.as_ref().map(IoxChunk::len).unwrap_or(0) - } - - #[cfg(not(feature = "dds_shm"))] ddsrt_iov_len_to_usize(self.data.iov_len).unwrap() } } @@ -187,36 +100,12 @@ impl Drop for DDSRawSample { impl fmt::Debug for DDSRawSample { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - #[cfg(feature = "dds_shm")] - { - // Where data was received via Iceoryx write both the header (contained in buf.data) and - // payload (contained in buf.iox_chunk) to the formatter. - if let Some(iox_chunk) = self.iox_chunk { - return write!( - f, - "[{:02x?}, {:02x?}]", - self.data_as_slice(), - iox_chunk.as_slice() - ); - } - } write!(f, "{:02x?}", self.data_as_slice()) } } impl From<&DDSRawSample> for ZBytes { fn from(buf: &DDSRawSample) -> Self { - #[cfg(feature = "dds_shm")] - { - // Where data was received via Iceoryx return both the header (contained in buf.data) and - // payload (contained in buf.iox_chunk) in a buffer. - if let Some(iox_chunk) = buf.iox_chunk { - let mut buf_and_iox_chunk = buf.data_as_slice().to_vec(); - buf_and_iox_chunk.append(&mut iox_chunk.as_slice().to_vec()); - let z_bytes = ZBytes::from(buf_and_iox_chunk); - return z_bytes; - } - } buf.data_as_slice().into() } }