pub mod file;
pub mod process_local;
pub mod recommended;
use core::{fmt::Debug, time::Duration};
use iceoryx2_bb_elementary_traits::testing::abandonable::Abandonable;
use iceoryx2_bb_system_types::file_name::*;
use iceoryx2_log::fail;
use crate::named_concept::{
NamedConcept, NamedConceptBuilder, NamedConceptConfiguration, NamedConceptMgmt,
};
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub enum StaticStorageCreateError {
AlreadyExists,
Creation,
Write,
InsufficientPermissions,
InternalError,
}
impl core::fmt::Display for StaticStorageCreateError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "StaticStorageCreateError::{self:?}")
}
}
impl core::error::Error for StaticStorageCreateError {}
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub enum StaticStorageOpenError {
DoesNotExist,
Read,
InitializationNotYetFinalized,
InternalError,
}
impl core::fmt::Display for StaticStorageOpenError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "StaticStorageOpenError::{self:?}")
}
}
impl core::error::Error for StaticStorageOpenError {}
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub enum StaticStorageReadError {
BufferTooSmall,
ReadError,
StaticStorageWasModified,
CreationNotComplete,
}
impl core::fmt::Display for StaticStorageReadError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "StaticStorageReadError::{self:?}")
}
}
impl core::error::Error for StaticStorageReadError {}
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub enum StaticStorageUnlockError {
InsufficientPermissions,
NoSpaceLeft,
InternalError,
}
impl core::fmt::Display for StaticStorageUnlockError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "StaticStorageUnlockError::{self:?}")
}
}
impl core::error::Error for StaticStorageUnlockError {}
pub trait StaticStorageConfiguration: Clone + Default + NamedConceptConfiguration {}
pub trait StaticStorageBuilder<T: StaticStorage>: Sized + NamedConceptBuilder<T> {
fn has_ownership(self, value: bool) -> Self;
fn create(self, contents: &[u8]) -> Result<T, StaticStorageCreateError> {
let locked_storage = self.create_locked()?;
Ok(
fail!(from "StaticStorageBuilder::create", when locked_storage.unlock(contents),
with StaticStorageCreateError::Write,
"Unable to unlock static storage with content"),
)
}
fn create_locked(self) -> Result<T::Locked, StaticStorageCreateError>;
fn open(self, timeout: Duration) -> Result<T, StaticStorageOpenError>;
}
pub trait StaticStorageLocked<T: StaticStorage>: Sized + NamedConcept + Abandonable {
fn unlock(self, contents: &[u8]) -> Result<T, StaticStorageUnlockError>;
}
pub trait StaticStorage:
Debug + Sized + NamedConceptMgmt + NamedConcept + Send + Sync + Abandonable
{
type Builder: StaticStorageBuilder<Self> + NamedConceptBuilder<Self>;
type Locked: StaticStorageLocked<Self>;
fn len(&self) -> u64;
fn is_empty(&self) -> bool;
fn read(&self, content: &mut [u8]) -> Result<(), StaticStorageReadError>;
fn release_ownership(&self);
fn acquire_ownership(&self);
fn default_suffix() -> FileName {
unsafe { FileName::new_unchecked(b".static_storage") }
}
}