pub mod event;
pub mod publish_subscribe;
pub mod message_type_details;
pub mod request_response;
pub mod messaging_pattern;
pub mod blackboard;
use alloc::format;
use iceoryx2_bb_derive_macros::ZeroCopySend;
use iceoryx2_bb_elementary_traits::zero_copy_send::ZeroCopySend;
use iceoryx2_cal::hash::Hash;
use iceoryx2_log::fatal_panic;
use serde::{Deserialize, Serialize};
use crate::{config, identifiers::UniqueServiceId, service::service_hash::ServiceHash};
use self::messaging_pattern::MessagingPattern;
use super::{attribute::AttributeSet, service_name::ServiceName};
#[derive(Debug, Eq, PartialEq, Clone, ZeroCopySend, Serialize, Deserialize)]
#[repr(C)]
pub struct StaticConfig {
service_hash: ServiceHash,
service_name: ServiceName,
unique_service_id: UniqueServiceId,
pub(crate) attributes: AttributeSet,
pub(crate) messaging_pattern: MessagingPattern,
}
impl StaticConfig {
pub(crate) fn new_request_response<Hasher: Hash>(
service_name: &ServiceName,
config: &config::Config,
) -> Self {
let messaging_pattern =
MessagingPattern::RequestResponse(request_response::StaticConfig::new(config));
Self {
service_hash: ServiceHash::new::<Hasher>(
service_name,
crate::service::messaging_pattern::MessagingPattern::RequestResponse,
),
unique_service_id: UniqueServiceId::new(),
service_name: *service_name,
messaging_pattern,
attributes: AttributeSet::new(),
}
}
pub(crate) fn new_event<Hasher: Hash>(
service_name: &ServiceName,
config: &config::Config,
) -> Self {
let messaging_pattern = MessagingPattern::Event(event::StaticConfig::new(config));
Self {
service_hash: ServiceHash::new::<Hasher>(
service_name,
crate::service::messaging_pattern::MessagingPattern::Event,
),
unique_service_id: UniqueServiceId::new(),
service_name: *service_name,
messaging_pattern,
attributes: AttributeSet::new(),
}
}
pub(crate) fn new_publish_subscribe<Hasher: Hash>(
service_name: &ServiceName,
config: &config::Config,
) -> Self {
let messaging_pattern =
MessagingPattern::PublishSubscribe(publish_subscribe::StaticConfig::new(config));
Self {
service_hash: ServiceHash::new::<Hasher>(
service_name,
crate::service::messaging_pattern::MessagingPattern::PublishSubscribe,
),
unique_service_id: UniqueServiceId::new(),
service_name: *service_name,
messaging_pattern,
attributes: AttributeSet::new(),
}
}
pub(crate) fn new_blackboard<Hasher: Hash>(
service_name: &ServiceName,
config: &config::Config,
) -> Self {
let messaging_pattern = MessagingPattern::Blackboard(blackboard::StaticConfig::new(config));
Self {
service_hash: ServiceHash::new::<Hasher>(
service_name,
crate::service::messaging_pattern::MessagingPattern::Blackboard,
),
unique_service_id: UniqueServiceId::new(),
service_name: *service_name,
messaging_pattern,
attributes: AttributeSet::new(),
}
}
pub fn attributes(&self) -> &AttributeSet {
&self.attributes
}
pub fn service_hash(&self) -> &ServiceHash {
&self.service_hash
}
pub fn unique_service_id(&self) -> UniqueServiceId {
self.unique_service_id
}
pub fn name(&self) -> &ServiceName {
&self.service_name
}
pub fn messaging_pattern(&self) -> &MessagingPattern {
&self.messaging_pattern
}
pub(crate) fn has_same_messaging_pattern(&self, rhs: &StaticConfig) -> bool {
self.messaging_pattern
.is_same_pattern(&rhs.messaging_pattern)
}
pub fn request_response(&self) -> &request_response::StaticConfig {
match &self.messaging_pattern {
MessagingPattern::RequestResponse(v) => v,
m => {
fatal_panic!(from self, "This should never happen! Trying to access request_response::StaticConfig when the messaging pattern is actually {:?}!", m)
}
}
}
pub(crate) fn request_response_mut(&mut self) -> &mut request_response::StaticConfig {
let origin = format!("{self:?}");
match &mut self.messaging_pattern {
MessagingPattern::RequestResponse(v) => v,
m => {
fatal_panic!(from origin, "This should never happen! Trying to access request_response::StaticConfig when the messaging pattern is actually {:?}!", m)
}
}
}
pub fn event(&self) -> &event::StaticConfig {
match &self.messaging_pattern {
MessagingPattern::Event(v) => v,
m => {
fatal_panic!(from self, "This should never happen! Trying to access event::StaticConfig when the messaging pattern is actually {:?}!", m)
}
}
}
pub(crate) fn event_mut(&mut self) -> &mut event::StaticConfig {
let origin = format!("{self:?}");
match &mut self.messaging_pattern {
MessagingPattern::Event(v) => v,
m => {
fatal_panic!(from origin, "This should never happen! Trying to access event::StaticConfig when the messaging pattern is actually {:?}!", m)
}
}
}
pub fn publish_subscribe(&self) -> &publish_subscribe::StaticConfig {
match &self.messaging_pattern {
MessagingPattern::PublishSubscribe(v) => v,
m => {
fatal_panic!(from self, "This should never happen! Trying to access publish_subscribe::StaticConfig when the messaging pattern is actually {:?}!", m)
}
}
}
pub(crate) fn publish_subscribe_mut(&mut self) -> &mut publish_subscribe::StaticConfig {
let origin = format!("{self:?}");
match &mut self.messaging_pattern {
MessagingPattern::PublishSubscribe(v) => v,
m => {
fatal_panic!(from origin, "This should never happen! Trying to access publish_subscribe::StaticConfig when the messaging pattern is actually {:?}!", m)
}
}
}
pub fn blackboard(&self) -> &blackboard::StaticConfig {
match &self.messaging_pattern {
MessagingPattern::Blackboard(v) => v,
m => {
fatal_panic!(from self, "This should never happen! Trying to access blackboard::StaticConfig when the messaging pattern is actually {:?}!", m)
}
}
}
pub(crate) fn blackboard_mut(&mut self) -> &mut blackboard::StaticConfig {
let origin = format!("{self:?}");
match &mut self.messaging_pattern {
MessagingPattern::Blackboard(v) => v,
m => {
fatal_panic!(from origin, "This should never happen! Trying to access blackboard::StaticConfig when the messaging pattern is actually {:?}!", m)
}
}
}
}