pub mod posix_shared_memory;
pub mod process_local;
pub mod recommended;
pub mod unix_datagram;
use core::fmt::Debug;
use iceoryx2_bb_elementary_traits::testing::abandonable::Abandonable;
use iceoryx2_bb_system_types::file_name::*;
use iceoryx2_bb_system_types::path::Path;
use crate::named_concept::{NamedConcept, NamedConceptBuilder, NamedConceptMgmt};
pub const DEFAULT_RECEIVER_BUFFER_SIZE: usize = 8;
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub enum CommunicationChannelSendError {
ConnectionBroken,
MessageTooLarge,
ReceiverCacheIsFull,
InternalFailure,
}
impl core::fmt::Display for CommunicationChannelSendError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "CommunicationChannelSendError::{self:?}")
}
}
impl core::error::Error for CommunicationChannelSendError {}
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub enum CommunicationChannelReceiveError {
ConnectionBroken,
MessageCorrupt,
InternalFailure,
}
impl core::fmt::Display for CommunicationChannelReceiveError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "CommunicationChannelReceiveError::{self:?}")
}
}
impl core::error::Error for CommunicationChannelReceiveError {}
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub enum CommunicationChannelCreateError {
AlreadyExists,
SafeOverflowNotSupported,
CustomBufferSizeNotSupported,
InternalFailure,
}
impl core::fmt::Display for CommunicationChannelCreateError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "CommunicationChannelCreateError::{self:?}")
}
}
impl core::error::Error for CommunicationChannelCreateError {}
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub enum CommunicationChannelOpenError {
InternalFailure,
AnotherInstanceIsAlreadyConnected,
DoesNotExist,
}
impl core::fmt::Display for CommunicationChannelOpenError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "CommunicationChannelOpenError::{self:?}")
}
}
impl core::error::Error for CommunicationChannelOpenError {}
pub trait CommunicationChannelCreator<T, C: CommunicationChannel<T> + Sized>:
NamedConceptBuilder<C>
{
fn enable_safe_overflow(self) -> Self;
fn buffer_size(self, value: usize) -> Self;
fn create_receiver(self) -> Result<C::Receiver, CommunicationChannelCreateError>;
}
pub trait CommunicationChannelConnector<T, C: CommunicationChannel<T> + Sized>:
NamedConceptBuilder<C>
{
fn open_sender(self) -> Result<C::Sender, CommunicationChannelOpenError>;
fn try_open_sender(self) -> Result<C::Sender, CommunicationChannelOpenError>;
}
pub trait CommunicationChannelParticipant {
fn does_enable_safe_overflow(&self) -> bool;
}
pub trait CommunicationChannelSender<T>:
Debug + CommunicationChannelParticipant + NamedConcept + Abandonable
{
fn send(&self, data: &T) -> Result<Option<T>, CommunicationChannelSendError>;
fn try_send(&self, data: &T) -> Result<Option<T>, CommunicationChannelSendError>;
}
pub trait CommunicationChannelReceiver<T>:
Debug + CommunicationChannelParticipant + NamedConcept + Abandonable
{
fn buffer_size(&self) -> usize;
fn receive(&self) -> Result<Option<T>, CommunicationChannelReceiveError>;
}
pub trait CommunicationChannel<T>: Sized + Debug + NamedConceptMgmt {
type Sender: CommunicationChannelSender<T>;
type Receiver: CommunicationChannelReceiver<T>;
type Creator: CommunicationChannelCreator<T, Self>;
type Connector: CommunicationChannelConnector<T, Self>;
fn does_support_safe_overflow() -> bool {
false
}
fn has_configurable_buffer_size() -> bool {
false
}
fn default_suffix() -> FileName {
unsafe { FileName::new_unchecked(b".com") }
}
}