use core::fmt::Debug;
use crate::port::{
event_id::EventId, notifier::Notifier, notifier::NotifierCreateError, port_name::PortName,
};
use iceoryx2_log::fail;
use crate::service;
use super::event::PortFactory;
#[derive(Debug, Clone)]
pub(crate) struct NotifierConfig {
pub(crate) default_event_id: EventId,
pub(crate) port_name: PortName,
}
#[derive(Debug, Clone)]
pub struct PortFactoryNotifier<'factory, Service: service::Service> {
pub(crate) factory: &'factory PortFactory<Service>,
config: NotifierConfig,
}
unsafe impl<Service: service::Service> Send for PortFactoryNotifier<'_, Service> {}
impl<'factory, Service: service::Service> PortFactoryNotifier<'factory, Service> {
pub(crate) fn new(factory: &'factory PortFactory<Service>) -> Self {
Self {
factory,
config: NotifierConfig {
default_event_id: EventId::default(),
port_name: PortName::new_empty(),
},
}
}
pub fn default_event_id(mut self, value: EventId) -> Self {
self.config.default_event_id = value;
self
}
pub fn name(mut self, name: &PortName) -> Self {
self.config.port_name = *name;
self
}
pub fn create(self) -> Result<Notifier<Service>, NotifierCreateError> {
Ok(
fail!(from self, when Notifier::new(self.factory.service.clone(), self.config.clone()),
"Failed to create new Notifier port."),
)
}
}