use core::time::Duration;
use crate::{config, prelude::EventId};
use iceoryx2_bb_container::relocatable_option::RelocatableOption;
use iceoryx2_bb_derive_macros::ZeroCopySend;
use iceoryx2_bb_elementary_traits::zero_copy_send::ZeroCopySend;
use iceoryx2_bb_posix::clock::{RelocatableDuration, Time};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq, ZeroCopySend, Serialize, Deserialize)]
#[repr(C)]
pub(crate) struct Deadline {
pub(crate) creation_time: Time,
pub(crate) value: RelocatableDuration,
}
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq, ZeroCopySend, Serialize, Deserialize)]
#[repr(C)]
pub struct StaticConfig {
pub(crate) max_notifiers: usize,
pub(crate) max_listeners: usize,
pub(crate) max_nodes: usize,
pub(crate) event_id_max_value: usize,
pub(crate) deadline: RelocatableOption<Deadline>,
pub(crate) notifier_created_event: RelocatableOption<usize>,
pub(crate) notifier_dropped_event: RelocatableOption<usize>,
pub(crate) notifier_dead_event: RelocatableOption<usize>,
}
impl StaticConfig {
pub(crate) fn new(config: &config::Config) -> Self {
Self {
max_notifiers: config.defaults.event.max_notifiers,
max_listeners: config.defaults.event.max_listeners,
max_nodes: config.defaults.event.max_nodes,
deadline: config
.defaults
.event
.deadline
.map(|v| Deadline {
creation_time: Time::default(),
value: v.into(),
})
.into(),
event_id_max_value: config.defaults.event.event_id_max_value,
notifier_created_event: config.defaults.event.notifier_created_event.into(),
notifier_dropped_event: config.defaults.event.notifier_dropped_event.into(),
notifier_dead_event: config.defaults.event.notifier_dead_event.into(),
}
}
pub fn deadline(&self) -> Option<Duration> {
self.deadline.as_option_ref().map(|v| v.value.into())
}
pub fn max_nodes(&self) -> usize {
self.max_nodes
}
pub fn max_notifiers(&self) -> usize {
self.max_notifiers
}
pub fn max_listeners(&self) -> usize {
self.max_listeners
}
pub fn event_id_max_value(&self) -> usize {
self.event_id_max_value
}
pub fn notifier_created_event(&self) -> Option<EventId> {
self.notifier_created_event
.as_option_ref()
.map(|v| EventId::new(*v))
}
pub fn notifier_dropped_event(&self) -> Option<EventId> {
self.notifier_dropped_event
.as_option_ref()
.map(|v| EventId::new(*v))
}
pub fn notifier_dead_event(&self) -> Option<EventId> {
self.notifier_dead_event
.as_option_ref()
.map(|v| EventId::new(*v))
}
}