Skip to content

Commit

Permalink
[#100] Fix docu and remove PayloadMut trait
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Feb 19, 2024
1 parent e4fc3d6 commit 65913ef
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 268 deletions.
3 changes: 0 additions & 3 deletions iceoryx2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ pub(crate) mod raw_sample;
/// The payload that is received by a [`crate::port::subscriber::Subscriber`].
pub mod sample;

/// The interface for the payload that is sent by a [`crate::port::publisher::Publisher`].
pub mod payload_mut;

/// The payload that is sent by a [`crate::port::publisher::Publisher`].
pub mod sample_mut;

Expand Down
216 changes: 0 additions & 216 deletions iceoryx2/src/payload_mut.rs

This file was deleted.

5 changes: 0 additions & 5 deletions iceoryx2/src/port/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ use crate::service;
/// Defines the action a port shall take when an internal failure occurs. Can happen when the
/// system is corrupted and files are modified by non-iceoryx2 instances. Is used as return value of
/// the [`DegrationCallback`] to define a custom behavior.
///
/// Can be set with:
///
/// * [`publisher::Publisher::set_degration_callback()`]
/// * [`subscriber::Subscriber::set_degration_callback()`]
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum DegrationAction {
/// Ignore the degration completely
Expand Down
31 changes: 20 additions & 11 deletions iceoryx2/src/port/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@
use std::cell::UnsafeCell;
use std::fmt::Debug;
use std::rc::Rc;
use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering};
use std::{alloc::Layout, marker::PhantomData, mem::MaybeUninit};

use super::port_identifiers::{UniquePublisherId, UniqueSubscriberId};
use crate::message::Message;
use crate::payload_mut::{internal::PayloadMgmt, PayloadMut, UninitPayloadMut};
use crate::port::details::subscriber_connections::*;
use crate::port::update_connections::{ConnectionFailure, UpdateConnections};
use crate::port::DegrationAction;
Expand Down Expand Up @@ -91,7 +90,7 @@ use iceoryx2_cal::zero_copy_connection::{
ZeroCopyConnection, ZeroCopyCreationError, ZeroCopySendError, ZeroCopySender,
};

/// Defines a failure that can occur when a [`Publish`] is created with
/// Defines a failure that can occur when a [`Publisher`] is created with
/// [`crate::service::port_factory::publisher::PortFactoryPublisher`].
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum PublisherCreateError {
Expand All @@ -107,8 +106,8 @@ impl std::fmt::Display for PublisherCreateError {

impl std::error::Error for PublisherCreateError {}

/// Defines a failure that can occur in [`DefaultLoan::loan()`] and [`UninitLoan::loan_uninit()`]
/// or is part of [`PublisherSendError`] emitted in [`SendCopy::send_copy()`].
/// Defines a failure that can occur in [`Publisher::loan()`] and [`Publisher::loan_uninit()`]
/// or is part of [`PublisherSendError`] emitted in [`Publisher::send_copy()`].
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
pub enum PublisherLoanError {
OutOfMemory,
Expand All @@ -127,6 +126,8 @@ impl std::error::Error for PublisherLoanError {}
enum_gen! {
/// Failure that can be emitted when a [`crate::sample::Sample`] is sent via [`Publisher::send()`].
PublisherSendError
entry:
ConnectionBrokenSincePublisherNoLongerExists
mapping:
PublisherLoanError to LoanError,
ConnectionFailure to ConnectionError
Expand Down Expand Up @@ -155,6 +156,7 @@ pub(crate) struct DataSegment<Service: service::Service> {
history: Option<UnsafeCell<Queue<usize>>>,
static_config: crate::service::static_config::StaticConfig,
loan_counter: AtomicUsize,
is_active: AtomicBool,
}

impl<Service: service::Service> DataSegment<Service> {
Expand Down Expand Up @@ -362,9 +364,15 @@ impl<Service: service::Service> DataSegment<Service> {
}
}

pub(crate) fn send_sample(&self, address_to_chunk: usize) -> Result<usize, ConnectionFailure> {
pub(crate) fn send_sample(&self, address_to_chunk: usize) -> Result<usize, PublisherSendError> {
let msg = "Unable to send sample";
if !self.is_active.load(Ordering::Relaxed) {
fail!(from self, with PublisherSendError::ConnectionBrokenSincePublisherNoLongerExists,
"{} since the connections could not be updated.", msg);
}

fail!(from self, when self.update_connections(),
"Unable to send sample since the connections could not be updated.");
"{} since the connections could not be updated.", msg);

self.retrieve_returned_samples();
self.add_sample_to_history(address_to_chunk);
Expand Down Expand Up @@ -436,6 +444,7 @@ impl<Service: service::Service, MessageType: Debug> Publisher<Service, MessageTy

let new_self = Self {
data_segment: Rc::new(DataSegment {
is_active: AtomicBool::new(true),
memory: data_segment,
message_size: std::mem::size_of::<Message<Header, MessageType>>(),
message_type_layout: Layout::new::<MessageType>(),
Expand Down Expand Up @@ -523,12 +532,12 @@ impl<Service: service::Service, MessageType: Debug> Publisher<Service, MessageTy

sample.payload_mut().write(value);
Ok(
fail!(from self, when self.data_segment.send_sample(sample.offset_to_chunk().value()),
fail!(from self, when self.data_segment.send_sample(sample.offset_to_chunk.value()),
"{} since the underlying send operation failed.", msg),
)
}

/// Loans/allocates a [`crate::sample_mut::SampleMut`] from the underlying data segment of the [`Publish`]er.
/// Loans/allocates a [`crate::sample_mut::SampleMut`] from the underlying data segment of the [`Publisher`].
/// The user has to initialize the payload before it can be sent.
///
/// On failure it returns [`PublisherLoanError`] describing the failure.
Expand Down Expand Up @@ -608,8 +617,8 @@ impl<Service: service::Service, MessageType: Debug> Publisher<Service, MessageTy
}

impl<Service: service::Service, MessageType: Default + Debug> Publisher<Service, MessageType> {
/// Loans/allocates a [`crate::sample_mut::SampleMut`] from the underlying data segment of the [`Publish`]
/// and initialize it with the default value. This can be a performance hit and [`UninitLoan::loan_uninit`]
/// Loans/allocates a [`crate::sample_mut::SampleMut`] from the underlying data segment of the [`Publisher`]
/// and initialize it with the default value. This can be a performance hit and [`Publisher::loan_uninit`]
/// can be used to loan a [`core::mem::MaybeUninit<MessageType>`].
///
/// On failure it returns [`PublisherLoanError`] describing the failure.
Expand Down
4 changes: 2 additions & 2 deletions iceoryx2/src/port/update_connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ impl std::error::Error for ConnectionFailure {}
pub trait UpdateConnections {
/// Explicitly updates all connections to the [`crate::port::subscriber::Subscriber`]s. This is
/// required to be called whenever a new [`crate::port::subscriber::Subscriber`] connected to
/// the service. It is done implicitly whenever [`crate::payload_mut::PayloadMut::send()`] or
/// [`crate::port::publish::SendCopy::send_copy()`] is called.
/// the service. It is done implicitly whenever [`crate::sample_mut::SampleMut::send()`] or
/// [`crate::port::publisher::Publisher::send_copy()`] is called.
/// When a [`crate::port::subscriber::Subscriber`] is connected that requires a history this
/// call will deliver it.
///
Expand Down
1 change: 0 additions & 1 deletion iceoryx2/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@

pub use crate::iox2::Iox2;
pub use crate::iox2::Iox2Event;
pub use crate::payload_mut::{PayloadMut, UninitPayloadMut};
pub use crate::port::event_id::EventId;
pub use crate::service::{process_local, service_name::ServiceName, zero_copy, Service};
Loading

0 comments on commit 65913ef

Please sign in to comment.