use core::fmt::Debug;
use core::time::Duration;
use tiny_fn::tiny_fn;
use update_connections::ConnectionFailure;
pub(crate) mod details;
pub use details::data_segment::DataSegmentType;
pub mod client;
pub mod event_id;
pub mod listener;
pub mod notifier;
pub mod publisher;
pub mod reader;
pub mod server;
pub mod subscriber;
pub mod update_connections;
pub mod writer;
pub mod backpressure_strategy;
pub use iceoryx2_cal::zero_copy_connection::BackpressureToReceiverAction;
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum BackpressureAction {
FollowBackpressureyStrategy,
Retry,
DiscardData,
DiscardDataAndFail,
}
impl From<BackpressureAction> for BackpressureToReceiverAction {
fn from(value: BackpressureAction) -> Self {
match value {
BackpressureAction::FollowBackpressureyStrategy => {
BackpressureToReceiverAction::FollowBackpressureyStrategy
}
BackpressureAction::Retry => BackpressureToReceiverAction::Retry,
BackpressureAction::DiscardData => BackpressureToReceiverAction::DiscardPointerOffset,
BackpressureAction::DiscardDataAndFail => {
BackpressureToReceiverAction::DiscardPointerOffsetAndFail
}
}
}
}
pub struct BackpressureInfo {
pub service_id: u128,
pub sender_port_id: u128,
pub receiver_port_id: u128,
pub retries: u64,
pub elapsed_time: Duration,
}
pub trait BackpressureFn: Fn(&BackpressureInfo) -> BackpressureAction + Send {}
impl<F: Fn(&BackpressureInfo) -> BackpressureAction + Send> BackpressureFn for F {}
tiny_fn! {
pub struct BackpressureHandler = Fn(info: &BackpressureInfo) -> BackpressureAction;
}
unsafe impl Send for BackpressureHandler<'_> {}
impl Debug for BackpressureHandler<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "")
}
}
impl BackpressureHandler<'_> {
pub fn new_with(action: BackpressureAction) -> Self {
Self::new(move |_| action)
}
}
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum DegradationAction {
Ignore,
Warn,
DegradeAndFail,
}
pub enum DegradationCause {
FailedToEstablishConnection,
ConnectionCorrupted,
}
pub struct DegradationInfo {
pub service_id: u128,
pub sender_port_id: u128,
pub receiver_port_id: u128,
}
pub trait DegradationFn:
Fn(DegradationCause, &DegradationInfo) -> DegradationAction + Send
{
}
impl<F: Fn(DegradationCause, &DegradationInfo) -> DegradationAction + Send> DegradationFn for F {}
tiny_fn! {
pub struct DegradationHandler = Fn(cause: DegradationCause, context: &DegradationInfo) -> DegradationAction;
}
unsafe impl Send for DegradationHandler<'_> {}
impl Debug for DegradationHandler<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "")
}
}
impl DegradationHandler<'_> {
pub fn new_with(action: DegradationAction) -> Self {
Self::new(move |_, _| action)
}
}
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
pub enum LoanError {
OutOfMemory,
ExceedsMaxLoans,
ExceedsMaxLoanSize,
InternalFailure,
}
impl core::fmt::Display for LoanError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "LoanError::{self:?}")
}
}
impl core::error::Error for LoanError {}
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum SendError {
ConnectionBrokenSinceSenderNoLongerExists,
ConnectionCorrupted,
LoanError(LoanError),
ConnectionError(ConnectionFailure),
UnableToDeliver,
InternalError,
}
impl From<LoanError> for SendError {
fn from(value: LoanError) -> Self {
SendError::LoanError(value)
}
}
impl From<ConnectionFailure> for SendError {
fn from(value: ConnectionFailure) -> Self {
SendError::ConnectionError(value)
}
}
impl core::fmt::Display for SendError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "SendError::{self:?}")
}
}
impl core::error::Error for SendError {}
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum ReceiveError {
ExceedsMaxBorrows,
ConnectionFailure(ConnectionFailure),
}
impl From<ConnectionFailure> for ReceiveError {
fn from(value: ConnectionFailure) -> Self {
ReceiveError::ConnectionFailure(value)
}
}
impl core::fmt::Display for ReceiveError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "ReceiveError::{self:?}")
}
}
impl core::error::Error for ReceiveError {}