iceoryx2/service/static_config/
mod.rs1pub mod event;
17
18pub mod publish_subscribe;
22
23pub mod message_type_details;
26
27pub mod request_response;
28
29pub mod messaging_pattern;
30
31pub mod blackboard;
32
33use iceoryx2_bb_derive_macros::ZeroCopySend;
34use iceoryx2_bb_elementary_traits::zero_copy_send::ZeroCopySend;
35use iceoryx2_bb_log::fatal_panic;
36use iceoryx2_cal::hash::Hash;
37use serde::{Deserialize, Serialize};
38
39use crate::config;
40
41use self::messaging_pattern::MessagingPattern;
42
43use super::{attribute::AttributeSet, service_id::ServiceId, service_name::ServiceName};
44
45#[derive(Debug, Eq, PartialEq, Clone, ZeroCopySend, Serialize, Deserialize)]
47#[repr(C)]
48pub struct StaticConfig {
49 service_id: ServiceId,
50 service_name: ServiceName,
51 pub(crate) attributes: AttributeSet,
52 pub(crate) messaging_pattern: MessagingPattern,
53}
54
55impl StaticConfig {
56 pub(crate) fn new_request_response<Hasher: Hash>(
57 service_name: &ServiceName,
58 config: &config::Config,
59 ) -> Self {
60 let messaging_pattern =
61 MessagingPattern::RequestResponse(request_response::StaticConfig::new(config));
62 Self {
63 service_id: ServiceId::new::<Hasher>(
64 service_name,
65 crate::service::messaging_pattern::MessagingPattern::RequestResponse,
66 ),
67 service_name: service_name.clone(),
68 messaging_pattern,
69 attributes: AttributeSet::new(),
70 }
71 }
72
73 pub(crate) fn new_event<Hasher: Hash>(
74 service_name: &ServiceName,
75 config: &config::Config,
76 ) -> Self {
77 let messaging_pattern = MessagingPattern::Event(event::StaticConfig::new(config));
78 Self {
79 service_id: ServiceId::new::<Hasher>(
80 service_name,
81 crate::service::messaging_pattern::MessagingPattern::Event,
82 ),
83 service_name: service_name.clone(),
84 messaging_pattern,
85 attributes: AttributeSet::new(),
86 }
87 }
88
89 pub(crate) fn new_publish_subscribe<Hasher: Hash>(
90 service_name: &ServiceName,
91 config: &config::Config,
92 ) -> Self {
93 let messaging_pattern =
94 MessagingPattern::PublishSubscribe(publish_subscribe::StaticConfig::new(config));
95 Self {
96 service_id: ServiceId::new::<Hasher>(
97 service_name,
98 crate::service::messaging_pattern::MessagingPattern::PublishSubscribe,
99 ),
100 service_name: service_name.clone(),
101 messaging_pattern,
102 attributes: AttributeSet::new(),
103 }
104 }
105
106 pub(crate) fn new_blackboard<Hasher: Hash>(
107 service_name: &ServiceName,
108 config: &config::Config,
109 ) -> Self {
110 let messaging_pattern = MessagingPattern::Blackboard(blackboard::StaticConfig::new(config));
111 Self {
112 service_id: ServiceId::new::<Hasher>(
113 service_name,
114 crate::service::messaging_pattern::MessagingPattern::Blackboard,
115 ),
116 service_name: service_name.clone(),
117 messaging_pattern,
118 attributes: AttributeSet::new(),
119 }
120 }
121
122 pub fn attributes(&self) -> &AttributeSet {
124 &self.attributes
125 }
126
127 pub fn service_id(&self) -> &ServiceId {
129 &self.service_id
130 }
131
132 pub fn name(&self) -> &ServiceName {
134 &self.service_name
135 }
136
137 pub fn messaging_pattern(&self) -> &MessagingPattern {
139 &self.messaging_pattern
140 }
141
142 pub(crate) fn has_same_messaging_pattern(&self, rhs: &StaticConfig) -> bool {
143 self.messaging_pattern
144 .is_same_pattern(&rhs.messaging_pattern)
145 }
146
147 pub fn request_response(&self) -> &request_response::StaticConfig {
149 match &self.messaging_pattern {
150 MessagingPattern::RequestResponse(ref v) => v,
151 m => {
152 fatal_panic!(from self, "This should never happen! Trying to access request_response::StaticConfig when the messaging pattern is actually {:?}!", m)
153 }
154 }
155 }
156
157 pub(crate) fn request_response_mut(&mut self) -> &mut request_response::StaticConfig {
158 let origin = format!("{self:?}");
159 match &mut self.messaging_pattern {
160 MessagingPattern::RequestResponse(ref mut v) => v,
161 m => {
162 fatal_panic!(from origin, "This should never happen! Trying to access request_response::StaticConfig when the messaging pattern is actually {:?}!", m)
163 }
164 }
165 }
166
167 pub fn event(&self) -> &event::StaticConfig {
169 match &self.messaging_pattern {
170 MessagingPattern::Event(ref v) => v,
171 m => {
172 fatal_panic!(from self, "This should never happen! Trying to access event::StaticConfig when the messaging pattern is actually {:?}!", m)
173 }
174 }
175 }
176
177 pub(crate) fn event_mut(&mut self) -> &mut event::StaticConfig {
178 let origin = format!("{self:?}");
179 match &mut self.messaging_pattern {
180 MessagingPattern::Event(ref mut v) => v,
181 m => {
182 fatal_panic!(from origin, "This should never happen! Trying to access event::StaticConfig when the messaging pattern is actually {:?}!", m)
183 }
184 }
185 }
186
187 pub fn publish_subscribe(&self) -> &publish_subscribe::StaticConfig {
189 match &self.messaging_pattern {
190 MessagingPattern::PublishSubscribe(ref v) => v,
191 m => {
192 fatal_panic!(from self, "This should never happen! Trying to access publish_subscribe::StaticConfig when the messaging pattern is actually {:?}!", m)
193 }
194 }
195 }
196
197 pub(crate) fn publish_subscribe_mut(&mut self) -> &mut publish_subscribe::StaticConfig {
198 let origin = format!("{self:?}");
199 match &mut self.messaging_pattern {
200 MessagingPattern::PublishSubscribe(ref mut v) => v,
201 m => {
202 fatal_panic!(from origin, "This should never happen! Trying to access publish_subscribe::StaticConfig when the messaging pattern is actually {:?}!", m)
203 }
204 }
205 }
206
207 pub fn blackboard(&self) -> &blackboard::StaticConfig {
209 match &self.messaging_pattern {
210 MessagingPattern::Blackboard(ref v) => v,
211 m => {
212 fatal_panic!(from self, "This should never happen! Trying to access blackboard::StaticConfig when the messaging pattern is actually {:?}!", m)
213 }
214 }
215 }
216
217 pub(crate) fn blackboard_mut(&mut self) -> &mut blackboard::StaticConfig {
218 let origin = format!("{self:?}");
219 match &mut self.messaging_pattern {
220 MessagingPattern::Blackboard(ref mut v) => v,
221 m => {
222 fatal_panic!(from origin, "This should never happen! Trying to access blackboard::StaticConfig when the messaging pattern is actually {:?}!", m)
223 }
224 }
225 }
226}