From a3282fe7bbca04668616f8edc6b6ee00d0f47d8b Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Sun, 28 Jan 2024 15:11:19 +0100 Subject: [PATCH 1/3] [#100] Config is stored inside Rc --- iceoryx2-cal/src/zero_copy_connection/mod.rs | 2 +- .../posix_shared_memory.rs | 1 + .../src/zero_copy_connection/process_local.rs | 1 + .../src/port/details/publisher_connections.rs | 33 +++++---- .../port/details/subscriber_connections.rs | 30 ++++---- iceoryx2/src/port/listener.rs | 10 +-- iceoryx2/src/port/notifier.rs | 16 ++--- iceoryx2/src/port/publisher.rs | 48 +++++++------ iceoryx2/src/port/subscriber.rs | 20 +++--- iceoryx2/src/prelude.rs | 2 +- iceoryx2/src/service/builder/event.rs | 18 +++-- iceoryx2/src/service/builder/mod.rs | 70 +++++++++---------- .../src/service/builder/publish_subscribe.rs | 26 ++++--- iceoryx2/src/service/config_scheme.rs | 8 +-- iceoryx2/src/service/mod.rs | 37 ++++------ iceoryx2/src/service/port_factory/event.rs | 19 ++--- iceoryx2/src/service/port_factory/listener.rs | 10 ++- iceoryx2/src/service/port_factory/notifier.rs | 12 ++-- .../service/port_factory/publish_subscribe.rs | 24 +++---- .../src/service/port_factory/publisher.rs | 19 ++--- .../src/service/port_factory/subscriber.rs | 15 ++-- iceoryx2/src/service/process_local.rs | 17 ++--- iceoryx2/src/service/zero_copy.rs | 17 ++--- iceoryx2/tests/service_event_tests.rs | 3 + .../tests/service_publish_subscribe_tests.rs | 12 ++-- 25 files changed, 208 insertions(+), 262 deletions(-) diff --git a/iceoryx2-cal/src/zero_copy_connection/mod.rs b/iceoryx2-cal/src/zero_copy_connection/mod.rs index b8e655dbf..7fec361e5 100644 --- a/iceoryx2-cal/src/zero_copy_connection/mod.rs +++ b/iceoryx2-cal/src/zero_copy_connection/mod.rs @@ -123,7 +123,7 @@ pub trait ZeroCopyReceiver: Debug + ZeroCopyPortDetails + NamedConcept { fn release(&self, ptr: PointerOffset) -> Result<(), ZeroCopyReleaseError>; } -pub trait ZeroCopyConnection: Sized + NamedConceptMgmt { +pub trait ZeroCopyConnection: Debug + Sized + NamedConceptMgmt { type Sender: ZeroCopySender; type Receiver: ZeroCopyReceiver; type Builder: ZeroCopyConnectionBuilder; diff --git a/iceoryx2-cal/src/zero_copy_connection/posix_shared_memory.rs b/iceoryx2-cal/src/zero_copy_connection/posix_shared_memory.rs index 4de1d2238..098c577ef 100644 --- a/iceoryx2-cal/src/zero_copy_connection/posix_shared_memory.rs +++ b/iceoryx2-cal/src/zero_copy_connection/posix_shared_memory.rs @@ -554,6 +554,7 @@ impl ZeroCopyReceiver for Receiver { } } +#[derive(Debug)] pub struct Connection {} impl NamedConceptMgmt for Connection { diff --git a/iceoryx2-cal/src/zero_copy_connection/process_local.rs b/iceoryx2-cal/src/zero_copy_connection/process_local.rs index 401d55013..b4a96c7f8 100644 --- a/iceoryx2-cal/src/zero_copy_connection/process_local.rs +++ b/iceoryx2-cal/src/zero_copy_connection/process_local.rs @@ -469,6 +469,7 @@ impl ZeroCopyReceiver for Receiver { } } +#[derive(Debug)] pub struct Connection {} impl NamedConceptMgmt for Connection { diff --git a/iceoryx2/src/port/details/publisher_connections.rs b/iceoryx2/src/port/details/publisher_connections.rs index 0edcedb17..f8ddc72ed 100644 --- a/iceoryx2/src/port/details/publisher_connections.rs +++ b/iceoryx2/src/port/details/publisher_connections.rs @@ -10,7 +10,7 @@ // // SPDX-License-Identifier: Apache-2.0 OR MIT -use std::cell::UnsafeCell; +use std::{cell::UnsafeCell, rc::Rc}; use crate::{ config, @@ -34,15 +34,14 @@ use iceoryx2_cal::{ }; #[derive(Debug)] -pub(crate) struct Connection<'config, Service: service::Details<'config>> { - pub(crate) receiver: - <>::Connection as ZeroCopyConnection>::Receiver, +pub(crate) struct Connection { + pub(crate) receiver: ::Receiver, pub(crate) data_segment: Service::SharedMemory, } -impl<'config, Service: service::Details<'config>> Connection<'config, Service> { +impl Connection { fn new( - this: &PublisherConnections<'config, Service>, + this: &PublisherConnections, publisher_id: UniquePublisherId, ) -> Result { let msg = format!( @@ -51,9 +50,9 @@ impl<'config, Service: service::Details<'config>> Connection<'config, Service> { ); let receiver = fail!(from this, - when <>::Connection as ZeroCopyConnection>:: + when :: Builder::new( &connection_name(publisher_id, this.subscriber_id)) - .config(&connection_config::(this.config)) + .config(&connection_config::(this.config.as_ref())) .buffer_size(this.static_config.subscriber_max_buffer_size) .receiver_max_borrowed_samples(this.static_config.subscriber_max_borrowed_samples) .enable_safe_overflow(this.static_config.enable_safe_overflow) @@ -63,7 +62,7 @@ impl<'config, Service: service::Details<'config>> Connection<'config, Service> { let data_segment = fail!(from this, when >:: Builder::new(&data_segment_name(publisher_id)) - .config(&data_segment_config::(this.config)) + .config(&data_segment_config::(this.config.as_ref())) .open(), "{} since the publishers data segment could not be mapped into the process.", msg); @@ -74,24 +73,24 @@ impl<'config, Service: service::Details<'config>> Connection<'config, Service> { } } #[derive(Debug)] -pub(crate) struct PublisherConnections<'config, Service: service::Details<'config>> { - connections: Vec>>>, +pub(crate) struct PublisherConnections { + connections: Vec>>>, subscriber_id: UniqueSubscriberId, - config: &'config config::Config, + config: Rc, static_config: StaticConfig, } -impl<'config, Service: service::Details<'config>> PublisherConnections<'config, Service> { +impl PublisherConnections { pub(crate) fn new( capacity: usize, subscriber_id: UniqueSubscriberId, - config: &'config config::Config, + config: &Rc, static_config: &StaticConfig, ) -> Self { Self { connections: (0..capacity).map(|_| UnsafeCell::new(None)).collect(), subscriber_id, - config, + config: Rc::clone(config), static_config: static_config.clone(), } } @@ -100,13 +99,13 @@ impl<'config, Service: service::Details<'config>> PublisherConnections<'config, self.subscriber_id } - pub(crate) fn get(&self, index: usize) -> &Option> { + pub(crate) fn get(&self, index: usize) -> &Option> { unsafe { &*self.connections[index].get() } } // only used internally as convinience function #[allow(clippy::mut_from_ref)] - pub(crate) fn get_mut(&self, index: usize) -> &mut Option> { + pub(crate) fn get_mut(&self, index: usize) -> &mut Option> { #[deny(clippy::mut_from_ref)] unsafe { &mut *self.connections[index].get() diff --git a/iceoryx2/src/port/details/subscriber_connections.rs b/iceoryx2/src/port/details/subscriber_connections.rs index de102ed99..f7025e7e4 100644 --- a/iceoryx2/src/port/details/subscriber_connections.rs +++ b/iceoryx2/src/port/details/subscriber_connections.rs @@ -11,6 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT use std::cell::UnsafeCell; +use std::rc::Rc; use iceoryx2_bb_log::fail; use iceoryx2_cal::named_concept::NamedConceptBuilder; @@ -27,19 +28,18 @@ use crate::{ }; #[derive(Debug)] -pub(crate) struct Connection<'config, Service: service::Details<'config>> { - pub(crate) sender: - <>::Connection as ZeroCopyConnection>::Sender, +pub(crate) struct Connection { + pub(crate) sender: ::Sender, } -impl<'config, Service: service::Details<'config>> Connection<'config, Service> { +impl Connection { fn new( - this: &SubscriberConnections<'config, Service>, + this: &SubscriberConnections, subscriber_id: UniqueSubscriberId, ) -> Result { - let sender = fail!(from this, when <>::Connection as ZeroCopyConnection>:: + let sender = fail!(from this, when :: Builder::new( &connection_name(this.port_id, subscriber_id)) - .config(&connection_config::(this.config)) + .config(&connection_config::(this.config.as_ref())) .buffer_size(this.static_config.subscriber_max_buffer_size) .receiver_max_borrowed_samples(this.static_config.subscriber_max_borrowed_samples) .enable_safe_overflow(this.static_config.enable_safe_overflow) @@ -52,35 +52,35 @@ impl<'config, Service: service::Details<'config>> Connection<'config, Service> { } #[derive(Debug)] -pub(crate) struct SubscriberConnections<'config, Service: service::Details<'config>> { - connections: Vec>>>, +pub(crate) struct SubscriberConnections { + connections: Vec>>>, port_id: UniquePublisherId, - config: &'config config::Config, + config: Rc, static_config: StaticConfig, } -impl<'config, Service: service::Details<'config>> SubscriberConnections<'config, Service> { +impl SubscriberConnections { pub(crate) fn new( capacity: usize, - config: &'config config::Config, + config: &Rc, port_id: UniquePublisherId, static_config: &StaticConfig, ) -> Self { Self { connections: (0..capacity).map(|_| UnsafeCell::new(None)).collect(), - config, + config: Rc::clone(config), port_id, static_config: static_config.clone(), } } - pub(crate) fn get(&self, index: usize) -> &Option> { + pub(crate) fn get(&self, index: usize) -> &Option> { unsafe { &(*self.connections[index].get()) } } // only used internally as convinience function #[allow(clippy::mut_from_ref)] - fn get_mut(&self, index: usize) -> &mut Option> { + fn get_mut(&self, index: usize) -> &mut Option> { #[deny(clippy::mut_from_ref)] unsafe { &mut (*self.connections[index].get()) diff --git a/iceoryx2/src/port/listener.rs b/iceoryx2/src/port/listener.rs index c236692c9..26523adcf 100644 --- a/iceoryx2/src/port/listener.rs +++ b/iceoryx2/src/port/listener.rs @@ -47,15 +47,14 @@ use super::listen::{Listen, ListenerCreateError}; /// Represents the receiving endpoint of an event based communication. #[derive(Debug)] -pub struct Listener<'a, 'config: 'a, Service: service::Details<'config>> { +pub struct Listener<'a, Service: service::Service> { _dynamic_config_guard: Option>, listener: >::Listener, cache: Vec, _phantom_a: PhantomData<&'a Service>, - _phantom_b: PhantomData<&'config ()>, } -impl<'a, 'config: 'a, Service: service::Details<'config>> Listener<'a, 'config, Service> { +impl<'a, Service: service::Service> Listener<'a, Service> { pub(crate) fn new(service: &'a Service) -> Result { let msg = "Failed to create listener"; let origin = "Listener::new()"; @@ -72,7 +71,6 @@ impl<'a, 'config: 'a, Service: service::Details<'config>> Listener<'a, 'config, listener, cache: vec![], _phantom_a: PhantomData, - _phantom_b: PhantomData, }; // !MUST! be the last task otherwise a listener is added to the dynamic config without @@ -110,9 +108,7 @@ impl<'a, 'config: 'a, Service: service::Details<'config>> Listener<'a, 'config, } } -impl<'a, 'config: 'a, Service: service::Details<'config>> Listen - for Listener<'a, 'config, Service> -{ +impl<'a, Service: service::Service> Listen for Listener<'a, Service> { fn cache(&self) -> &[EventId] { &self.cache } diff --git a/iceoryx2/src/port/notifier.rs b/iceoryx2/src/port/notifier.rs index 8ed1816a5..f900a54b8 100644 --- a/iceoryx2/src/port/notifier.rs +++ b/iceoryx2/src/port/notifier.rs @@ -54,13 +54,13 @@ use super::{ }; #[derive(Debug, Default)] -struct ListenerConnections<'config, Service: service::Details<'config>> { +struct ListenerConnections { #[allow(clippy::type_complexity)] connections: Vec>::Notifier>>>, } -impl<'config, Service: service::Details<'config>> ListenerConnections<'config, Service> { +impl ListenerConnections { fn new(size: usize) -> Self { let mut new_self = Self { connections: vec![], @@ -112,16 +112,15 @@ impl<'config, Service: service::Details<'config>> ListenerConnections<'config, S /// Represents the sending endpoint of an event based communication. #[derive(Debug)] -pub struct Notifier<'a, 'config: 'a, Service: service::Details<'config>> { - listener_connections: ListenerConnections<'config, Service>, +pub struct Notifier<'a, Service: service::Service> { + listener_connections: ListenerConnections, listener_list_state: UnsafeCell>, default_event_id: EventId, _dynamic_config_guard: Option>, _phantom_a: PhantomData<&'a Service>, - _phantom_b: PhantomData<&'config ()>, } -impl<'a, 'config: 'a, Service: service::Details<'config>> Notifier<'a, 'config, Service> { +impl<'a, Service: service::Service> Notifier<'a, Service> { pub(crate) fn new( service: &'a Service, default_event_id: EventId, @@ -138,7 +137,6 @@ impl<'a, 'config: 'a, Service: service::Details<'config>> Notifier<'a, 'config, listener_list_state: unsafe { UnsafeCell::new(listener_list.get_state()) }, _dynamic_config_guard: None, _phantom_a: PhantomData, - _phantom_b: PhantomData, }; // !MUST! be the last task otherwise a publisher is added to the dynamic config without the @@ -204,9 +202,7 @@ impl<'a, 'config: 'a, Service: service::Details<'config>> Notifier<'a, 'config, } } -impl<'a, 'config: 'a, Service: service::Details<'config>> Notify - for Notifier<'a, 'config, Service> -{ +impl<'a, Service: service::Service> Notify for Notifier<'a, Service> { fn notify(&self) -> Result { self.notify_with_custom_event_id(self.default_event_id) } diff --git a/iceoryx2/src/port/publisher.rs b/iceoryx2/src/port/publisher.rs index caf3c8595..fa2f3b697 100644 --- a/iceoryx2/src/port/publisher.rs +++ b/iceoryx2/src/port/publisher.rs @@ -95,13 +95,13 @@ use iceoryx2_cal::zero_copy_connection::{ /// Sending endpoint of a publish-subscriber based communication. #[derive(Debug)] -pub struct Publisher<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> { +pub struct Publisher<'a, Service: service::Service, MessageType: Debug> { port_id: UniquePublisherId, pub(crate) sample_reference_counter: Vec, pub(crate) data_segment: Service::SharedMemory, config: LocalPublisherConfig, - subscriber_connections: SubscriberConnections<'config, Service>, + subscriber_connections: SubscriberConnections, subscriber_list_state: UnsafeCell>, history: Option>>, service: &'a Service, @@ -111,9 +111,7 @@ pub struct Publisher<'a, 'config: 'a, Service: service::Details<'config>, Messag _phantom_message_type: PhantomData, } -impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> - Publisher<'a, 'config, Service, MessageType> -{ +impl<'a, Service: service::Service, MessageType: Debug> Publisher<'a, Service, MessageType> { pub(crate) fn new( service: &'a Service, static_config: &publish_subscribe::StaticConfig, @@ -135,7 +133,7 @@ impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> .messaging_pattern .required_amount_of_samples_per_data_segment(config.max_loaned_samples); - let data_segment = fail!(from origin, when Self::create_data_segment(port_id, service.state().global_config, number_of_samples), + let data_segment = fail!(from origin, when Self::create_data_segment(port_id, service.state().global_config.as_ref(), number_of_samples), with PublisherCreateError::UnableToCreateDataSegment, "{} since the data segment could not be acquired.", msg); @@ -160,7 +158,7 @@ impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> port_id, subscriber_connections: SubscriberConnections::new( subscriber_list.capacity(), - service.state().global_config, + &service.state().global_config, port_id, static_config, ), @@ -244,7 +242,7 @@ impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> Ok(()) } - fn deliver_history(&self, connection: &Connection<'config, Service>) { + fn deliver_history(&self, connection: &Connection) { match &self.history { None => (), Some(history) => { @@ -272,7 +270,7 @@ impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> fn create_data_segment( port_id: UniquePublisherId, - global_config: &'config config::Config, + global_config: &config::Config, number_of_samples: usize, ) -> Result { let allocator_config = shm_allocator::pool_allocator::Config { @@ -308,8 +306,12 @@ impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> fn deliver_sample(&self, address_to_chunk: usize) -> usize { let deliver_call = match self.config.unable_to_deliver_strategy { - UnableToDeliverStrategy::Block => <>::Connection as ZeroCopyConnection>::Sender::blocking_send, - UnableToDeliverStrategy::DiscardSample => <>::Connection as ZeroCopyConnection>::Sender::try_send, + UnableToDeliverStrategy::Block => { + ::Sender::blocking_send + } + UnableToDeliverStrategy::DiscardSample => { + ::Sender::try_send + } }; let mut number_of_recipients = 0; @@ -411,13 +413,13 @@ impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> } } } -impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug + Default> - Publish for Publisher<'a, 'config, Service, MessageType> +impl<'a, Service: service::Service, MessageType: Debug + Default> Publish + for Publisher<'a, Service, MessageType> { } -impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> UpdateConnections - for Publisher<'a, 'config, Service, MessageType> +impl<'a, Service: service::Service, MessageType: Debug> UpdateConnections + for Publisher<'a, Service, MessageType> { fn update_connections(&self) -> Result<(), ConnectionFailure> { if unsafe { (*self.subscriber_list_state.get()).update() } { @@ -429,8 +431,8 @@ impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> Up } } -impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> SendCopy - for Publisher<'a, 'config, Service, MessageType> +impl<'a, Service: service::Service, MessageType: Debug> SendCopy + for Publisher<'a, Service, MessageType> { fn send_copy(&self, value: MessageType) -> Result { let msg = "Unable to send copy of message"; @@ -445,8 +447,8 @@ impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> Se } } -impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> - UninitLoan for Publisher<'a, 'config, Service, MessageType> +impl<'a, Service: service::Service, MessageType: Debug> UninitLoan + for Publisher<'a, Service, MessageType> { fn loan_uninit(&self) -> Result>, PublisherLoanError> { self.retrieve_returned_samples(); @@ -503,8 +505,8 @@ impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> } } -impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> PublishMgmt - for Publisher<'a, 'config, Service, MessageType> +impl<'a, Service: service::Service, MessageType: Debug> PublishMgmt + for Publisher<'a, Service, MessageType> { fn return_loaned_sample(&self, distance_to_chunk: PointerOffset) { self.release_sample(distance_to_chunk); @@ -520,8 +522,8 @@ impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> Pu } } -impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Default + Debug> - DefaultLoan for Publisher<'a, 'config, Service, MessageType> +impl<'a, Service: service::Service, MessageType: Default + Debug> DefaultLoan + for Publisher<'a, Service, MessageType> { fn loan(&self) -> Result, PublisherLoanError> { Ok(self.loan_uninit()?.write_payload(MessageType::default())) diff --git a/iceoryx2/src/port/subscriber.rs b/iceoryx2/src/port/subscriber.rs index 6d0634692..05e9e9bda 100644 --- a/iceoryx2/src/port/subscriber.rs +++ b/iceoryx2/src/port/subscriber.rs @@ -57,9 +57,9 @@ use super::DegrationCallback; /// The receiving endpoint of a publish-subscribe communication. #[derive(Debug)] -pub struct Subscriber<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> { +pub struct Subscriber<'a, Service: service::Service, MessageType: Debug> { dynamic_config_guard: Option>, - publisher_connections: PublisherConnections<'config, Service>, + publisher_connections: PublisherConnections, service: &'a Service, degration_callback: Option>, @@ -67,9 +67,7 @@ pub struct Subscriber<'a, 'config: 'a, Service: service::Details<'config>, Messa _phantom_message_type: PhantomData, } -impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> - Subscriber<'a, 'config, Service, MessageType> -{ +impl<'a, Service: service::Service, MessageType: Debug> Subscriber<'a, Service, MessageType> { pub(crate) fn new( service: &'a Service, static_config: &StaticConfig, @@ -89,7 +87,7 @@ impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> publisher_connections: PublisherConnections::new( publisher_list.capacity(), port_id, - service.state().global_config, + &service.state().global_config, static_config, ), publisher_list_state: UnsafeCell::new(unsafe { publisher_list.get_state() }), @@ -171,7 +169,7 @@ impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> fn receive_from_connection<'subscriber>( &'subscriber self, channel_id: usize, - connection: &mut Connection<'config, Service>, + connection: &mut Connection, ) -> Result>, SubscriberReceiveError> { let msg = "Unable to receive another sample"; match connection.receiver.receive() { @@ -220,8 +218,8 @@ impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> } } -impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> Subscribe - for Subscriber<'a, 'config, Service, MessageType> +impl<'a, Service: service::Service, MessageType: Debug> Subscribe + for Subscriber<'a, Service, MessageType> { fn receive(&self) -> Result>, SubscriberReceiveError> { if let Err(e) = self.update_connections() { @@ -254,8 +252,8 @@ impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> Su } } -impl<'a, 'config: 'a, Service: service::Details<'config>, MessageType: Debug> SubscribeMgmt - for Subscriber<'a, 'config, Service, MessageType> +impl<'a, Service: service::Service, MessageType: Debug> SubscribeMgmt + for Subscriber<'a, Service, MessageType> { fn release_sample(&self, channel_id: usize, sample: usize) { match self.publisher_connections.get(channel_id) { diff --git a/iceoryx2/src/prelude.rs b/iceoryx2/src/prelude.rs index b23d05173..208573573 100644 --- a/iceoryx2/src/prelude.rs +++ b/iceoryx2/src/prelude.rs @@ -18,4 +18,4 @@ pub use crate::port::{ event_id::EventId, listen::Listen, notify::Notify, publish::DefaultLoan, publish::Publish, publish::SendCopy, publish::UninitLoan, subscribe::Subscribe, }; -pub use crate::service::{process_local, service_name::ServiceName, zero_copy, Details, Service}; +pub use crate::service::{process_local, service_name::ServiceName, zero_copy, Service}; diff --git a/iceoryx2/src/service/builder/event.rs b/iceoryx2/src/service/builder/event.rs index 1fe43d034..f17576340 100644 --- a/iceoryx2/src/service/builder/event.rs +++ b/iceoryx2/src/service/builder/event.rs @@ -88,14 +88,14 @@ impl std::error::Error for EventOpenOrCreateError {} /// /// See [`crate::service`] #[derive(Debug)] -pub struct Builder<'config, ServiceType: service::Details<'config>> { - base: builder::BuilderWithServiceType<'config, ServiceType>, +pub struct Builder { + base: builder::BuilderWithServiceType, verify_max_notifiers: bool, verify_max_listeners: bool, } -impl<'config, ServiceType: service::Details<'config>> Builder<'config, ServiceType> { - pub(crate) fn new(base: builder::BuilderWithServiceType<'config, ServiceType>) -> Self { +impl Builder { + pub(crate) fn new(base: builder::BuilderWithServiceType) -> Self { let mut new_self = Self { base, verify_max_notifiers: false, @@ -103,7 +103,7 @@ impl<'config, ServiceType: service::Details<'config>> Builder<'config, ServiceTy }; new_self.base.service_config.messaging_pattern = MessagingPattern::Event( - static_config::event::StaticConfig::new(new_self.base.global_config), + static_config::event::StaticConfig::new(new_self.base.global_config.as_ref()), ); new_self @@ -138,9 +138,7 @@ impl<'config, ServiceType: service::Details<'config>> Builder<'config, ServiceTy /// If the [`Service`] exists, it will be opened otherwise a new [`Service`] will be /// created. - pub fn open_or_create( - self, - ) -> Result, EventOpenOrCreateError> { + pub fn open_or_create(self) -> Result, EventOpenOrCreateError> { let msg = "Unable to open or create event service"; match self.base.is_service_available() { @@ -163,7 +161,7 @@ impl<'config, ServiceType: service::Details<'config>> Builder<'config, ServiceTy } /// Opens an existing [`Service`]. - pub fn open(mut self) -> Result, EventOpenError> { + pub fn open(mut self) -> Result, EventOpenError> { let msg = "Unable to open event service"; let mut adaptive_wait = fail!(from self, when AdaptiveWaitBuilder::new().create(), @@ -223,7 +221,7 @@ impl<'config, ServiceType: service::Details<'config>> Builder<'config, ServiceTy } /// Creates a new [`Service`]. - pub fn create(mut self) -> Result, EventCreateError> { + pub fn create(mut self) -> Result, EventCreateError> { self.adjust_properties_to_meaningful_values(); let msg = "Unable to create event service"; diff --git a/iceoryx2/src/service/builder/mod.rs b/iceoryx2/src/service/builder/mod.rs index 41b25625d..85554fee4 100644 --- a/iceoryx2/src/service/builder/mod.rs +++ b/iceoryx2/src/service/builder/mod.rs @@ -38,6 +38,7 @@ use iceoryx2_cal::named_concept::NamedConceptMgmt; use iceoryx2_cal::serialize::Serialize; use iceoryx2_cal::static_storage::*; use std::marker::PhantomData; +use std::rc::Rc; use super::config_scheme::dynamic_config_storage_config; use super::config_scheme::static_config_storage_config; @@ -108,10 +109,10 @@ impl Builder { /// Create a new builder to create a /// [`MessagingPattern::PublishSubscribe`](crate::service::messaging_pattern::MessagingPattern::PublishSubscribe) [`Service`]. - pub fn publish_subscribe<'config>( - self, - ) -> publish_subscribe::Builder<'config, S::Type<'config>> { - self.publish_subscribe_with_custom_config(config::Config::get_global_config()) + pub fn publish_subscribe(self) -> publish_subscribe::Builder { + self.publish_subscribe_with_custom_config(&Rc::new( + config::Config::get_global_config().clone(), + )) } /// Create a new builder to create a @@ -119,35 +120,31 @@ impl Builder { /// with a custom [`config::Config`] pub fn publish_subscribe_with_custom_config( self, - config: &config::Config, - ) -> publish_subscribe::Builder<'_, S::Type<'_>> { + config: &Rc, + ) -> publish_subscribe::Builder { BuilderWithServiceType::new( - StaticConfig::new_publish_subscribe::< - <::Type<'_> as service::Details<'_>>::ServiceNameHasher, - >(&self.name, config), - config, + StaticConfig::new_publish_subscribe::( + &self.name, + config.as_ref(), + ), + Rc::clone(config), ) .publish_subscribe() } /// Create a new builder to create a /// [`MessagingPattern::Event`](crate::service::messaging_pattern::MessagingPattern::Event) [`Service`]. - pub fn event<'config>(self) -> event::Builder<'config, S::Type<'config>> { - self.event_with_custom_config(config::Config::get_global_config()) + pub fn event(self) -> event::Builder { + self.event_with_custom_config(&Rc::new(config::Config::get_global_config().clone())) } /// Create a new builder to create a /// [`MessagingPattern::Event`](crate::service::messaging_pattern::MessagingPattern::Event) [`Service`]. /// with a custom [`config::Config`] - pub fn event_with_custom_config( - self, - config: &config::Config, - ) -> event::Builder<'_, S::Type<'_>> { + pub fn event_with_custom_config(self, config: &Rc) -> event::Builder { BuilderWithServiceType::new( - StaticConfig::new_event::< - <::Type<'_> as service::Details<'_>>::ServiceNameHasher, - >(&self.name, config), - config, + StaticConfig::new_event::(&self.name, config.as_ref()), + Rc::clone(config), ) .event() } @@ -155,28 +152,26 @@ impl Builder { #[doc(hidden)] #[derive(Debug)] -pub struct BuilderWithServiceType<'config, ServiceType: service::Details<'config>> { +pub struct BuilderWithServiceType { service_config: StaticConfig, - global_config: &'config config::Config, + global_config: Rc, _phantom_data: PhantomData, - _phantom_lifetime_b: PhantomData<&'config ()>, } -impl<'config, ServiceType: service::Details<'config>> BuilderWithServiceType<'config, ServiceType> { - fn new(service_config: StaticConfig, global_config: &'config config::Config) -> Self { +impl BuilderWithServiceType { + fn new(service_config: StaticConfig, global_config: Rc) -> Self { Self { service_config, global_config, _phantom_data: PhantomData, - _phantom_lifetime_b: PhantomData, } } - fn publish_subscribe(self) -> publish_subscribe::Builder<'config, ServiceType> { + fn publish_subscribe(self) -> publish_subscribe::Builder { publish_subscribe::Builder::new(self) } - fn event(self) -> event::Builder<'config, ServiceType> { + fn event(self) -> event::Builder { event::Builder::new(self) } @@ -184,7 +179,8 @@ impl<'config, ServiceType: service::Details<'config>> BuilderWithServiceType<'co &self, ) -> Result, ServiceState> { let msg = "Unable to check if the service is available"; - let static_storage_config = static_config_storage_config::(self.global_config); + let static_storage_config = + static_config_storage_config::(self.global_config.as_ref()); let file_name_uuid = fatal_panic!(from self, when FileName::new(self.service_config.uuid().as_bytes()), "This should never happen! The uuid should be always a valid file name."); @@ -200,7 +196,7 @@ impl<'config, ServiceType: service::Details<'config>> BuilderWithServiceType<'co } Ok(true) => { let storage = if let Ok(v) = <::Builder as NamedConceptBuilder< - ::StaticStorage>> + ServiceType::StaticStorage>> ::new(&file_name_uuid) .has_ownership(false) .config(&static_storage_config) @@ -255,7 +251,7 @@ impl<'config, ServiceType: service::Details<'config>> BuilderWithServiceType<'co >>::Builder as NamedConceptBuilder< ServiceType::DynamicStorage, >>::new(&dynamic_config_storage_name(&self.service_config)) - .config(&dynamic_config_storage_config::(self.global_config)) + .config(&dynamic_config_storage_config::(self.global_config.as_ref())) .supplementary_size(additional_size) .has_ownership(false) .create_and_initialize(DynamicConfig::new_uninit(messaging_pattern), @@ -281,7 +277,7 @@ impl<'config, ServiceType: service::Details<'config>> BuilderWithServiceType<'co >>::Builder as NamedConceptBuilder< ServiceType::DynamicStorage, >>::new(&dynamic_config_storage_name(&self.service_config)) - .config(&dynamic_config_storage_config::(self.global_config)) + .config(&dynamic_config_storage_config::(self.global_config.as_ref())) .has_ownership(false) .open(), "{} since the dynamic storage could not be opened.", msg); @@ -295,16 +291,14 @@ impl<'config, ServiceType: service::Details<'config>> BuilderWithServiceType<'co fn create_static_config_storage( &self, - ) -> Result< - <>::StaticStorage as StaticStorage>::Locked, - StaticStorageCreateError, - > { + ) -> Result<::Locked, StaticStorageCreateError> + { Ok( fail!(from self, when <::Builder as NamedConceptBuilder< - ::StaticStorage, + ServiceType::StaticStorage, >>::new(&static_config_storage_name(self.service_config.uuid())) .config(&static_config_storage_config::( - self.global_config, + self.global_config.as_ref(), )) .has_ownership(false) .create_locked(), diff --git a/iceoryx2/src/service/builder/publish_subscribe.rs b/iceoryx2/src/service/builder/publish_subscribe.rs index c74868073..e79458fc9 100644 --- a/iceoryx2/src/service/builder/publish_subscribe.rs +++ b/iceoryx2/src/service/builder/publish_subscribe.rs @@ -104,8 +104,8 @@ impl std::error::Error for PublishSubscribeOpenOrCreateError {} /// /// See [`crate::service`] #[derive(Debug)] -pub struct Builder<'config, ServiceType: service::Details<'config>> { - base: builder::BuilderWithServiceType<'config, ServiceType>, +pub struct Builder { + base: builder::BuilderWithServiceType, verify_number_of_subscribers: bool, verify_number_of_publishers: bool, verify_subscriber_max_buffer_size: bool, @@ -114,8 +114,8 @@ pub struct Builder<'config, ServiceType: service::Details<'config>> { verify_enable_safe_overflow: bool, } -impl<'config, ServiceType: service::Details<'config>> Builder<'config, ServiceType> { - pub(crate) fn new(base: builder::BuilderWithServiceType<'config, ServiceType>) -> Self { +impl Builder { + pub(crate) fn new(base: builder::BuilderWithServiceType) -> Self { let mut new_self = Self { base, verify_number_of_publishers: false, @@ -127,7 +127,9 @@ impl<'config, ServiceType: service::Details<'config>> Builder<'config, ServiceTy }; new_self.base.service_config.messaging_pattern = MessagingPattern::PublishSubscribe( - static_config::publish_subscribe::StaticConfig::new(new_self.base.global_config), + static_config::publish_subscribe::StaticConfig::new( + new_self.base.global_config.as_ref(), + ), ); new_self @@ -228,7 +230,7 @@ impl<'config, ServiceType: service::Details<'config>> Builder<'config, ServiceTy pub fn open_or_create( mut self, ) -> Result< - publish_subscribe::PortFactory<'config, ServiceType, MessageType>, + publish_subscribe::PortFactory, PublishSubscribeOpenOrCreateError, > { let msg = "Unable to open or create publish subscribe service"; @@ -264,10 +266,8 @@ impl<'config, ServiceType: service::Details<'config>> Builder<'config, ServiceTy /// Opens an existing [`Service`]. pub fn open( mut self, - ) -> Result< - publish_subscribe::PortFactory<'config, ServiceType, MessageType>, - PublishSubscribeOpenError, - > { + ) -> Result, PublishSubscribeOpenError> + { let msg = "Unable to open publish subscribe service"; self.config_details_mut().type_name = std::any::type_name::().to_string(); @@ -338,10 +338,8 @@ impl<'config, ServiceType: service::Details<'config>> Builder<'config, ServiceTy /// Creates a new [`Service`]. pub fn create( mut self, - ) -> Result< - publish_subscribe::PortFactory<'config, ServiceType, MessageType>, - PublishSubscribeCreateError, - > { + ) -> Result, PublishSubscribeCreateError> + { self.adjust_properties_to_meaningful_values(); let msg = "Unable to create publish subscribe service"; diff --git a/iceoryx2/src/service/config_scheme.rs b/iceoryx2/src/service/config_scheme.rs index 095f461e6..89eabc5c7 100644 --- a/iceoryx2/src/service/config_scheme.rs +++ b/iceoryx2/src/service/config_scheme.rs @@ -45,7 +45,7 @@ fn generate_default_config( .path_hint(*path_hint) } -pub(crate) fn dynamic_config_storage_config<'config, Service: crate::service::Details<'config>>( +pub(crate) fn dynamic_config_storage_config( global_config: &config::Config, ) -> ::Configuration { generate_default_config::<::Configuration>( @@ -56,7 +56,7 @@ pub(crate) fn dynamic_config_storage_config<'config, Service: crate::service::De ) } -pub(crate) fn static_config_storage_config<'config, Service: crate::service::Details<'config>>( +pub(crate) fn static_config_storage_config( global_config: &config::Config, ) -> ::Configuration { let origin = "static_config_storage_config"; @@ -79,7 +79,7 @@ pub(crate) fn static_config_storage_config<'config, Service: crate::service::Det ) } -pub(crate) fn connection_config<'config, Service: crate::service::Details<'config>>( +pub(crate) fn connection_config( global_config: &config::Config, ) -> ::Configuration { generate_default_config::<::Configuration>( @@ -90,7 +90,7 @@ pub(crate) fn connection_config<'config, Service: crate::service::Details<'confi ) } -pub(crate) fn data_segment_config<'config, Service: crate::service::Details<'config>>( +pub(crate) fn data_segment_config( global_config: &config::Config, ) -> ::Configuration { generate_default_config::<::Configuration>( diff --git a/iceoryx2/src/service/mod.rs b/iceoryx2/src/service/mod.rs index 30b25ef4e..1a981352f 100644 --- a/iceoryx2/src/service/mod.rs +++ b/iceoryx2/src/service/mod.rs @@ -139,6 +139,7 @@ pub(crate) mod config_scheme; pub(crate) mod naming_scheme; use std::fmt::Debug; +use std::rc::Rc; use crate::config; use crate::port::event_id::EventId; @@ -195,19 +196,17 @@ impl std::error::Error for ServiceListError {} /// Represents the [`Service`]s state. #[derive(Debug)] -pub struct ServiceState<'config, Static: StaticStorage, Dynamic: DynamicStorage> { +pub struct ServiceState> { pub(crate) static_config: StaticConfig, - pub(crate) global_config: &'config config::Config, + pub(crate) global_config: Rc, pub(crate) dynamic_storage: Dynamic, pub(crate) static_storage: Static, } -impl<'config, Static: StaticStorage, Dynamic: DynamicStorage> - ServiceState<'config, Static, Dynamic> -{ +impl> ServiceState { pub(crate) fn new( static_config: StaticConfig, - global_config: &'config config::Config, + global_config: Rc, dynamic_storage: Dynamic, static_storage: Static, ) -> Self { @@ -222,8 +221,8 @@ impl<'config, Static: StaticStorage, Dynamic: DynamicStorage> } } -impl<'config, Static: StaticStorage, Dynamic: DynamicStorage> Drop - for ServiceState<'config, Static, Dynamic> +impl> Drop + for ServiceState { fn drop(&mut self) { match self.dynamic_storage.get().decrement_reference_counter() { @@ -240,18 +239,14 @@ impl<'config, Static: StaticStorage, Dynamic: DynamicStorage> Dro } /// Represents a service. Used to create or open new services with the [`Builder`]. -pub trait Service: Sized { - type Type<'a>: Details<'a>; - +/// Contains the building blocks a [`Service`] requires to create the underlying resources and +/// establish communication. +pub trait Service: Debug + Sized { /// Creates a new [`Builder`] for a given service name fn new(name: &ServiceName) -> Builder { Builder::new(name) } -} -/// Contains the building blocks a [`Service`] requires to create the underlying resources and -/// establish communication. -pub trait Details<'config>: Debug + Sized { /// Every service name will be hashed, to allow arbitrary [`ServiceName`]s with as less /// restrictions as possible. The hash of the [`ServiceName`] is the [`Service`]s uuid. type ServiceNameHasher: Hash; @@ -276,15 +271,13 @@ pub trait Details<'config>: Debug + Sized { type Event: Event; #[doc(hidden)] - fn from_state(state: ServiceState<'config, Self::StaticStorage, Self::DynamicStorage>) -> Self; + fn from_state(state: ServiceState) -> Self; #[doc(hidden)] - fn state(&self) -> &ServiceState<'config, Self::StaticStorage, Self::DynamicStorage>; + fn state(&self) -> &ServiceState; #[doc(hidden)] - fn state_mut( - &mut self, - ) -> &mut ServiceState<'config, Self::StaticStorage, Self::DynamicStorage>; + fn state_mut(&mut self) -> &mut ServiceState; /// Checks if a service with the name exists. /// @@ -320,7 +313,7 @@ pub trait Details<'config>: Debug + Sized { /// ``` fn does_exist_with_custom_config( service_name: &ServiceName, - config: &'config config::Config, + config: &config::Config, ) -> Result { let msg = format!("Unable to verify if \"{}\" exists", service_name); let origin = "Service::does_exist_from_config()"; @@ -419,7 +412,7 @@ pub trait Details<'config>: Debug + Sized { /// # } /// ``` fn list_with_custom_config( - config: &'config config::Config, + config: &config::Config, ) -> Result, ServiceListError> { let msg = "Unable to list all services"; let origin = "Service::list_from_config()"; diff --git a/iceoryx2/src/service/port_factory/event.rs b/iceoryx2/src/service/port_factory/event.rs index c4e3d54ed..a6d7036cc 100644 --- a/iceoryx2/src/service/port_factory/event.rs +++ b/iceoryx2/src/service/port_factory/event.rs @@ -37,7 +37,6 @@ use iceoryx2_cal::dynamic_storage::DynamicStorage; use crate::service::{self, static_config}; use crate::service::{dynamic_config, ServiceName}; -use std::marker::PhantomData; use super::listener::PortFactoryListener; use super::notifier::PortFactoryNotifier; @@ -47,20 +46,16 @@ use super::notifier::PortFactoryNotifier; /// acquire dynamic and static service informations and create [`crate::port::notifier::Notifier`] /// or [`crate::port::listener::Listener`] ports. #[derive(Debug)] -pub struct PortFactory<'config, Service: service::Details<'config>> { +pub struct PortFactory { pub(crate) service: Service, - _phantom_lifetime_b: PhantomData<&'config ()>, } -unsafe impl<'config, Service: service::Details<'config>> Send for PortFactory<'config, Service> {} -unsafe impl<'config, Service: service::Details<'config>> Sync for PortFactory<'config, Service> {} +unsafe impl Send for PortFactory {} +unsafe impl Sync for PortFactory {} -impl<'config, Service: service::Details<'config>> PortFactory<'config, Service> { +impl PortFactory { pub(crate) fn new(service: Service) -> Self { - Self { - service, - _phantom_lifetime_b: PhantomData, - } + Self { service } } /// Returns the [`ServiceName`] of the [`crate::service::Service`] @@ -102,7 +97,7 @@ impl<'config, Service: service::Details<'config>> PortFactory<'config, Service> /// # Ok(()) /// # } /// ``` - pub fn notifier<'a>(&'a self) -> PortFactoryNotifier<'a, 'config, Service> { + pub fn notifier<'a>(&'a self) -> PortFactoryNotifier<'a, Service> { PortFactoryNotifier::new(self) } @@ -123,7 +118,7 @@ impl<'config, Service: service::Details<'config>> PortFactory<'config, Service> /// # Ok(()) /// # } /// ``` - pub fn listener<'a>(&'a self) -> PortFactoryListener<'a, 'config, Service> { + pub fn listener<'a>(&'a self) -> PortFactoryListener<'a, Service> { PortFactoryListener { factory: self } } } diff --git a/iceoryx2/src/service/port_factory/listener.rs b/iceoryx2/src/service/port_factory/listener.rs index 265f96c7c..9a1b995e3 100644 --- a/iceoryx2/src/service/port_factory/listener.rs +++ b/iceoryx2/src/service/port_factory/listener.rs @@ -38,15 +38,13 @@ use super::event::PortFactory; /// [`MessagingPattern::Event`](crate::service::messaging_pattern::MessagingPattern::Event) based /// communication. #[derive(Debug)] -pub struct PortFactoryListener<'factory, 'config, Service: service::Details<'config>> { - pub(crate) factory: &'factory PortFactory<'config, Service>, +pub struct PortFactoryListener<'factory, Service: service::Service> { + pub(crate) factory: &'factory PortFactory, } -impl<'factory, 'config, Service: service::Details<'config>> - PortFactoryListener<'factory, 'config, Service> -{ +impl<'factory, Service: service::Service> PortFactoryListener<'factory, Service> { /// Creates the [`Listener`] port or returns a [`ListenerCreateError`] on failure. - pub fn create(&self) -> Result, ListenerCreateError> { + pub fn create(&self) -> Result, ListenerCreateError> { Ok(fail!(from self, when Listener::new(&self.factory.service), "Failed to create new Listener port.")) } diff --git a/iceoryx2/src/service/port_factory/notifier.rs b/iceoryx2/src/service/port_factory/notifier.rs index 0a04c718d..d0f10eb12 100644 --- a/iceoryx2/src/service/port_factory/notifier.rs +++ b/iceoryx2/src/service/port_factory/notifier.rs @@ -41,15 +41,13 @@ use super::event::PortFactory; /// [`MessagingPattern::Event`](crate::service::messaging_pattern::MessagingPattern::Event) based /// communication. #[derive(Debug)] -pub struct PortFactoryNotifier<'factory, 'config, Service: service::Details<'config>> { - pub(crate) factory: &'factory PortFactory<'config, Service>, +pub struct PortFactoryNotifier<'factory, Service: service::Service> { + pub(crate) factory: &'factory PortFactory, default_event_id: EventId, } -impl<'factory, 'config, Service: service::Details<'config>> - PortFactoryNotifier<'factory, 'config, Service> -{ - pub(crate) fn new(factory: &'factory PortFactory<'config, Service>) -> Self { +impl<'factory, Service: service::Service> PortFactoryNotifier<'factory, Service> { + pub(crate) fn new(factory: &'factory PortFactory) -> Self { Self { factory, default_event_id: EventId::default(), @@ -64,7 +62,7 @@ impl<'factory, 'config, Service: service::Details<'config>> } /// Creates a new [`Notifier`] port or returns a [`NotifierCreateError`] on failure. - pub fn create(&self) -> Result, NotifierCreateError> { + pub fn create(&self) -> Result, NotifierCreateError> { Ok( fail!(from self, when Notifier::new(&self.factory.service, self.default_event_id), "Failed to create new Notifier port."), diff --git a/iceoryx2/src/service/port_factory/publish_subscribe.rs b/iceoryx2/src/service/port_factory/publish_subscribe.rs index 139c4df0f..b0452cf9e 100644 --- a/iceoryx2/src/service/port_factory/publish_subscribe.rs +++ b/iceoryx2/src/service/port_factory/publish_subscribe.rs @@ -55,29 +55,25 @@ use super::{publisher::PortFactoryPublisher, subscriber::PortFactorySubscriber}; /// [`crate::port::publisher::Publisher`] /// or [`crate::port::subscriber::Subscriber`] ports. #[derive(Debug)] -pub struct PortFactory<'config, Service: service::Details<'config>, MessageType: Debug> { +pub struct PortFactory { pub(crate) service: Service, _phantom_message_type: PhantomData, - _phantom_lifetime_b: PhantomData<&'config ()>, } -unsafe impl<'config, Service: service::Details<'config>, MessageType: Debug> Send - for PortFactory<'config, Service, MessageType> +unsafe impl Send + for PortFactory { } -unsafe impl<'config, Service: service::Details<'config>, MessageType: Debug> Sync - for PortFactory<'config, Service, MessageType> +unsafe impl Sync + for PortFactory { } -impl<'config, Service: service::Details<'config>, MessageType: Debug> - PortFactory<'config, Service, MessageType> -{ +impl PortFactory { pub(crate) fn new(service: Service) -> Self { Self { service, _phantom_message_type: PhantomData, - _phantom_lifetime_b: PhantomData, } } @@ -126,7 +122,9 @@ impl<'config, Service: service::Details<'config>, MessageType: Debug> /// # Ok(()) /// # } /// ``` - pub fn subscriber<'a>(&'a self) -> PortFactorySubscriber<'a, 'config, Service, MessageType> { + pub fn subscriber<'factory>( + &'factory self, + ) -> PortFactorySubscriber<'factory, Service, MessageType> { PortFactorySubscriber { factory: self } } @@ -153,7 +151,9 @@ impl<'config, Service: service::Details<'config>, MessageType: Debug> /// # Ok(()) /// # } /// ``` - pub fn publisher<'a>(&'a self) -> PortFactoryPublisher<'a, 'config, Service, MessageType> { + pub fn publisher<'factory>( + &'factory self, + ) -> PortFactoryPublisher<'factory, Service, MessageType> { PortFactoryPublisher::new(self) } } diff --git a/iceoryx2/src/service/port_factory/publisher.rs b/iceoryx2/src/service/port_factory/publisher.rs index a841798c9..eabbdea1e 100644 --- a/iceoryx2/src/service/port_factory/publisher.rs +++ b/iceoryx2/src/service/port_factory/publisher.rs @@ -103,20 +103,15 @@ pub(crate) struct LocalPublisherConfig { /// [`MessagingPattern::PublishSubscribe`](crate::service::messaging_pattern::MessagingPattern::PublishSubscribe) based /// communication. #[derive(Debug)] -pub struct PortFactoryPublisher< - 'factory, - 'config, - Service: service::Details<'config>, - MessageType: Debug, -> { +pub struct PortFactoryPublisher<'factory, Service: service::Service, MessageType: Debug> { config: LocalPublisherConfig, - pub(crate) factory: &'factory PortFactory<'config, Service, MessageType>, + pub(crate) factory: &'factory PortFactory, } -impl<'factory, 'config, Service: service::Details<'config>, MessageType: Debug> - PortFactoryPublisher<'factory, 'config, Service, MessageType> +impl<'factory, Service: service::Service, MessageType: Debug> + PortFactoryPublisher<'factory, Service, MessageType> { - pub(crate) fn new(factory: &'factory PortFactory<'config, Service, MessageType>) -> Self { + pub(crate) fn new(factory: &'factory PortFactory) -> Self { Self { config: LocalPublisherConfig { max_loaned_samples: factory @@ -153,9 +148,7 @@ impl<'factory, 'config, Service: service::Details<'config>, MessageType: Debug> } /// Creates a new [`Publisher`] or returns a [`PublisherCreateError`] on failure. - pub fn create( - self, - ) -> Result, PublisherCreateError> { + pub fn create(self) -> Result, PublisherCreateError> { Ok( fail!(from self, when Publisher::new(&self.factory.service, self.factory.service.state().static_config.publish_subscribe(), &self.config), "Failed to create new Publisher port."), diff --git a/iceoryx2/src/service/port_factory/subscriber.rs b/iceoryx2/src/service/port_factory/subscriber.rs index b6aa5c990..16d3d9bc5 100644 --- a/iceoryx2/src/service/port_factory/subscriber.rs +++ b/iceoryx2/src/service/port_factory/subscriber.rs @@ -41,22 +41,17 @@ use super::publish_subscribe::PortFactory; /// [`MessagingPattern::PublishSubscribe`](crate::service::messaging_pattern::MessagingPattern::PublishSubscribe) based /// communication. #[derive(Debug)] -pub struct PortFactorySubscriber< - 'factory, - 'config, - Service: service::Details<'config>, - MessageType: Debug, -> { - pub(crate) factory: &'factory PortFactory<'config, Service, MessageType>, +pub struct PortFactorySubscriber<'factory, Service: service::Service, MessageType: Debug> { + pub(crate) factory: &'factory PortFactory, } -impl<'factory, 'config, Service: service::Details<'config>, MessageType: Debug> - PortFactorySubscriber<'factory, 'config, Service, MessageType> +impl<'factory, Service: service::Service, MessageType: Debug> + PortFactorySubscriber<'factory, Service, MessageType> { /// Creates a new [`Subscriber`] or returns a [`SubscriberCreateError`] on failure. pub fn create( &self, - ) -> Result, SubscriberCreateError> { + ) -> Result, SubscriberCreateError> { Ok( fail!(from self, when Subscriber::new(&self.factory.service, self.factory.service.state().static_config.publish_subscribe()), "Failed to create new Subscriber port."), diff --git a/iceoryx2/src/service/process_local.rs b/iceoryx2/src/service/process_local.rs index 9adc7708c..e598ce367 100644 --- a/iceoryx2/src/service/process_local.rs +++ b/iceoryx2/src/service/process_local.rs @@ -39,19 +39,14 @@ use super::ServiceState; /// Defines a process local or single address space communication setup. #[derive(Debug)] -pub struct Service<'config> { +pub struct Service { state: ServiceState< - 'config, static_storage::process_local::Storage, dynamic_storage::process_local::Storage, >, } -impl<'config> crate::service::Service for Service<'config> { - type Type<'b> = Service<'b>; -} - -impl<'config> crate::service::Details<'config> for Service<'config> { +impl crate::service::Service for Service { type StaticStorage = static_storage::process_local::Storage; type ConfigSerializer = serialize::toml::Toml; type DynamicStorage = dynamic_storage::process_local::Storage; @@ -60,17 +55,15 @@ impl<'config> crate::service::Details<'config> for Service<'config> { type Connection = zero_copy_connection::process_local::Connection; type Event = event::process_local::EventImpl; - fn from_state(state: ServiceState<'config, Self::StaticStorage, Self::DynamicStorage>) -> Self { + fn from_state(state: ServiceState) -> Self { Self { state } } - fn state(&self) -> &ServiceState<'config, Self::StaticStorage, Self::DynamicStorage> { + fn state(&self) -> &ServiceState { &self.state } - fn state_mut( - &mut self, - ) -> &mut ServiceState<'config, Self::StaticStorage, Self::DynamicStorage> { + fn state_mut(&mut self) -> &mut ServiceState { &mut self.state } } diff --git a/iceoryx2/src/service/zero_copy.rs b/iceoryx2/src/service/zero_copy.rs index cfd63279d..029942562 100644 --- a/iceoryx2/src/service/zero_copy.rs +++ b/iceoryx2/src/service/zero_copy.rs @@ -39,19 +39,14 @@ use super::ServiceState; /// Defines a zero copy inter-process communication setup based on posix mechanisms. #[derive(Debug)] -pub struct Service<'config> { +pub struct Service { state: ServiceState< - 'config, static_storage::file::Storage, dynamic_storage::posix_shared_memory::Storage, >, } -impl<'config> crate::service::Service for Service<'config> { - type Type<'b> = Service<'b>; -} - -impl<'config> crate::service::Details<'config> for Service<'config> { +impl crate::service::Service for Service { type StaticStorage = static_storage::file::Storage; type ConfigSerializer = serialize::toml::Toml; type DynamicStorage = dynamic_storage::posix_shared_memory::Storage; @@ -60,17 +55,15 @@ impl<'config> crate::service::Details<'config> for Service<'config> { type Connection = zero_copy_connection::posix_shared_memory::Connection; type Event = event::unix_datagram_socket::EventImpl; - fn from_state(state: ServiceState<'config, Self::StaticStorage, Self::DynamicStorage>) -> Self { + fn from_state(state: ServiceState) -> Self { Self { state } } - fn state(&self) -> &ServiceState<'config, Self::StaticStorage, Self::DynamicStorage> { + fn state(&self) -> &ServiceState { &self.state } - fn state_mut( - &mut self, - ) -> &mut ServiceState<'config, Self::StaticStorage, Self::DynamicStorage> { + fn state_mut(&mut self) -> &mut ServiceState { &mut self.state } } diff --git a/iceoryx2/tests/service_event_tests.rs b/iceoryx2/tests/service_event_tests.rs index a35e1b8d8..cb22f37f2 100644 --- a/iceoryx2/tests/service_event_tests.rs +++ b/iceoryx2/tests/service_event_tests.rs @@ -12,6 +12,8 @@ #[generic_tests::define] mod service_event { + use std::rc::Rc; + use iceoryx2::config::Config; use iceoryx2::prelude::*; use iceoryx2::service::builder::event::{EventCreateError, EventOpenError}; @@ -138,6 +140,7 @@ mod service_event { let mut custom_config = Config::default(); custom_config.defaults.event.max_notifiers = 9; custom_config.defaults.event.max_listeners = 10; + let custom_config = Rc::new(custom_config); let sut = Sut::new(&service_name) .event_with_custom_config(&custom_config) diff --git a/iceoryx2/tests/service_publish_subscribe_tests.rs b/iceoryx2/tests/service_publish_subscribe_tests.rs index e3dc8626e..ebf3bb2d4 100644 --- a/iceoryx2/tests/service_publish_subscribe_tests.rs +++ b/iceoryx2/tests/service_publish_subscribe_tests.rs @@ -12,6 +12,8 @@ #[generic_tests::define] mod service_publish_subscribe { + use std::rc::Rc; + use iceoryx2::config::Config; use iceoryx2::port::publish::{PublisherCreateError, PublisherLoanError}; use iceoryx2::port::subscribe::SubscriberCreateError; @@ -21,7 +23,7 @@ mod service_publish_subscribe { use iceoryx2::service::builder::publish_subscribe::PublishSubscribeOpenError; use iceoryx2::service::port_factory::publisher::UnableToDeliverStrategy; use iceoryx2::service::static_config::StaticConfig; - use iceoryx2::service::{Details, Service}; + use iceoryx2::service::Service; use iceoryx2_bb_posix::unique_system_id::UniqueSystemId; use iceoryx2_bb_testing::assert_that; @@ -348,7 +350,7 @@ mod service_publish_subscribe { .subscriber_max_buffer_size = 13; let sut = Sut::new(&service_name) - .publish_subscribe_with_custom_config(&custom_config) + .publish_subscribe_with_custom_config(&Rc::new(custom_config)) .create::() .unwrap(); @@ -1051,7 +1053,7 @@ mod service_publish_subscribe { } #[test] - fn does_exist_works_single>() { + fn does_exist_works_single() { let service_name = generate_name(); assert_that!(Sut::does_exist(&service_name).unwrap(), eq false); @@ -1069,7 +1071,7 @@ mod service_publish_subscribe { } #[test] - fn does_exist_works_many>() { + fn does_exist_works_many() { const NUMBER_OF_SERVICES: usize = 8; let mut services = vec![]; @@ -1110,7 +1112,7 @@ mod service_publish_subscribe { } #[test] - fn list_works>() { + fn list_works() { const NUMBER_OF_SERVICES: usize = 8; let mut services = vec![]; From d87872c033056fc8e38b2437212b618f8b27db66 Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Sun, 28 Jan 2024 17:38:57 +0100 Subject: [PATCH 2/3] [#100] Fix docu and do not make Rc part of the public API --- doc/release-notes/iceoryx2-unreleased.md | 19 ++--------------- iceoryx2-bb/system-types/src/path.rs | 4 +++- iceoryx2/src/service/builder/mod.rs | 21 +++++++------------ iceoryx2/src/service/mod.rs | 8 +++---- iceoryx2/tests/service_event_tests.rs | 3 --- .../tests/service_publish_subscribe_tests.rs | 4 +--- 6 files changed, 18 insertions(+), 41 deletions(-) diff --git a/doc/release-notes/iceoryx2-unreleased.md b/doc/release-notes/iceoryx2-unreleased.md index 30ee3313c..11a7afc4c 100644 --- a/doc/release-notes/iceoryx2-unreleased.md +++ b/doc/release-notes/iceoryx2-unreleased.md @@ -35,8 +35,8 @@ * Add `FixedSizeByteString::from_bytes_truncated` [#56](https://github.com/eclipse-iceoryx/iceoryx2/issues/56) * Add `Deref`, `DerefMut`, `Clone`, `Eq`, `PartialEq` and `extend_from_slice` to (FixedSize)Vec [#58](https://github.com/eclipse-iceoryx/iceoryx2/issues/58) * `MessagingPattern` implements `Display` [#64](https://github.com/eclipse-iceoryx/iceoryx2/issues/64) - * Introduce traits for all ports (`Listener`, `Notifier`, `Publisher`, `PublisherLoan`, `Subscriber`) - and for samples (`SampleMut`, `Sample`) [#69](https://github.com/eclipse-iceoryx/iceoryx2/issues/69) + * Introduce traits for all ports (`Listen`, `Notify`, `Publish`, `DefaultLoan`, `UninitLoan`, `Subscribe`) + and for samples (`PayloadMut`, `Payload`) [#69](https://github.com/eclipse-iceoryx/iceoryx2/issues/69) ### API Breaking Changes @@ -56,18 +56,3 @@ sample.send()?; ``` -2. Port types renamed, `Impl` suffix was added to all ports - - ```rust - // old - let publisher: Publisher<'_, '_, zero_copy::Service, u64> = service.publisher().create()?; - - // new - let publisher: PublisherImpl<'_, '_, zero_copy::Service, u64> = service.publisher().create()?; - - // same applies also to: - // * `Subscriber` -> `SubscriberImpl` - // * `Listener` -> `ListenerImpl` - // * `Notifier` -> `NotifierImpl` - ``` - diff --git a/iceoryx2-bb/system-types/src/path.rs b/iceoryx2-bb/system-types/src/path.rs index 56fe18199..5ded9bd92 100644 --- a/iceoryx2-bb/system-types/src/path.rs +++ b/iceoryx2-bb/system-types/src/path.rs @@ -27,6 +27,8 @@ //! assert!(invalid_name.is_err()); //! ``` +pub use iceoryx2_bb_container::semantic_string::SemanticString; + use iceoryx2_bb_container::byte_string::FixedSizeByteString; use iceoryx2_bb_container::semantic_string; @@ -34,7 +36,7 @@ use iceoryx2_bb_log::fail; use iceoryx2_pal_configuration::{FILENAME_LENGTH, PATH_SEPARATOR, ROOT}; use crate::file_path::FilePath; -use iceoryx2_bb_container::semantic_string::*; +use iceoryx2_bb_container::semantic_string::SemanticStringError; const PATH_LENGTH: usize = iceoryx2_pal_configuration::PATH_LENGTH; diff --git a/iceoryx2/src/service/builder/mod.rs b/iceoryx2/src/service/builder/mod.rs index 85554fee4..5e8c6dec5 100644 --- a/iceoryx2/src/service/builder/mod.rs +++ b/iceoryx2/src/service/builder/mod.rs @@ -110,9 +110,7 @@ impl Builder { /// Create a new builder to create a /// [`MessagingPattern::PublishSubscribe`](crate::service::messaging_pattern::MessagingPattern::PublishSubscribe) [`Service`]. pub fn publish_subscribe(self) -> publish_subscribe::Builder { - self.publish_subscribe_with_custom_config(&Rc::new( - config::Config::get_global_config().clone(), - )) + self.publish_subscribe_with_custom_config(config::Config::get_global_config()) } /// Create a new builder to create a @@ -120,14 +118,11 @@ impl Builder { /// with a custom [`config::Config`] pub fn publish_subscribe_with_custom_config( self, - config: &Rc, + config: &config::Config, ) -> publish_subscribe::Builder { BuilderWithServiceType::new( - StaticConfig::new_publish_subscribe::( - &self.name, - config.as_ref(), - ), - Rc::clone(config), + StaticConfig::new_publish_subscribe::(&self.name, config), + Rc::new(config.clone()), ) .publish_subscribe() } @@ -135,16 +130,16 @@ impl Builder { /// Create a new builder to create a /// [`MessagingPattern::Event`](crate::service::messaging_pattern::MessagingPattern::Event) [`Service`]. pub fn event(self) -> event::Builder { - self.event_with_custom_config(&Rc::new(config::Config::get_global_config().clone())) + self.event_with_custom_config(config::Config::get_global_config()) } /// Create a new builder to create a /// [`MessagingPattern::Event`](crate::service::messaging_pattern::MessagingPattern::Event) [`Service`]. /// with a custom [`config::Config`] - pub fn event_with_custom_config(self, config: &Rc) -> event::Builder { + pub fn event_with_custom_config(self, config: &config::Config) -> event::Builder { BuilderWithServiceType::new( - StaticConfig::new_event::(&self.name, config.as_ref()), - Rc::clone(config), + StaticConfig::new_event::(&self.name, config), + Rc::new(config.clone()), ) .event() } diff --git a/iceoryx2/src/service/mod.rs b/iceoryx2/src/service/mod.rs index 1a981352f..5212519b0 100644 --- a/iceoryx2/src/service/mod.rs +++ b/iceoryx2/src/service/mod.rs @@ -162,8 +162,8 @@ use self::builder::Builder; use self::dynamic_config::DecrementReferenceCounterResult; use self::service_name::ServiceName; -/// Failure that can be reported by [`Details::does_exist()`] or -/// [`Details::does_exist_with_custom_config()`]. +/// Failure that can be reported by [`Service::does_exist()`] or +/// [`Service::does_exist_with_custom_config()`]. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ServiceDoesExistError { InsufficientPermissions, @@ -178,8 +178,8 @@ impl std::fmt::Display for ServiceDoesExistError { impl std::error::Error for ServiceDoesExistError {} -/// Failure that can be reported by [`Details::list()`] or -/// [`Details::list_with_custom_config()`]. +/// Failure that can be reported by [`Service::list()`] or +/// [`Service::list_with_custom_config()`]. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ServiceListError { InsufficientPermissions, diff --git a/iceoryx2/tests/service_event_tests.rs b/iceoryx2/tests/service_event_tests.rs index cb22f37f2..a35e1b8d8 100644 --- a/iceoryx2/tests/service_event_tests.rs +++ b/iceoryx2/tests/service_event_tests.rs @@ -12,8 +12,6 @@ #[generic_tests::define] mod service_event { - use std::rc::Rc; - use iceoryx2::config::Config; use iceoryx2::prelude::*; use iceoryx2::service::builder::event::{EventCreateError, EventOpenError}; @@ -140,7 +138,6 @@ mod service_event { let mut custom_config = Config::default(); custom_config.defaults.event.max_notifiers = 9; custom_config.defaults.event.max_listeners = 10; - let custom_config = Rc::new(custom_config); let sut = Sut::new(&service_name) .event_with_custom_config(&custom_config) diff --git a/iceoryx2/tests/service_publish_subscribe_tests.rs b/iceoryx2/tests/service_publish_subscribe_tests.rs index ebf3bb2d4..690e01885 100644 --- a/iceoryx2/tests/service_publish_subscribe_tests.rs +++ b/iceoryx2/tests/service_publish_subscribe_tests.rs @@ -12,8 +12,6 @@ #[generic_tests::define] mod service_publish_subscribe { - use std::rc::Rc; - use iceoryx2::config::Config; use iceoryx2::port::publish::{PublisherCreateError, PublisherLoanError}; use iceoryx2::port::subscribe::SubscriberCreateError; @@ -350,7 +348,7 @@ mod service_publish_subscribe { .subscriber_max_buffer_size = 13; let sut = Sut::new(&service_name) - .publish_subscribe_with_custom_config(&Rc::new(custom_config)) + .publish_subscribe_with_custom_config(&custom_config) .create::() .unwrap(); From 2855eb3d566b0a8588c920a2c18fd39219aaac6c Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Sun, 28 Jan 2024 17:57:54 +0100 Subject: [PATCH 3/3] [#100] Fix clippy warnings and update changelog --- doc/release-notes/iceoryx2-unreleased.md | 58 ++++++++++++++++++- iceoryx2/src/service/builder/event.rs | 4 +- .../src/service/builder/publish_subscribe.rs | 4 +- iceoryx2/src/service/port_factory/event.rs | 4 +- .../service/port_factory/publish_subscribe.rs | 8 +-- 5 files changed, 65 insertions(+), 13 deletions(-) diff --git a/doc/release-notes/iceoryx2-unreleased.md b/doc/release-notes/iceoryx2-unreleased.md index 11a7afc4c..c2757f89b 100644 --- a/doc/release-notes/iceoryx2-unreleased.md +++ b/doc/release-notes/iceoryx2-unreleased.md @@ -20,7 +20,8 @@ - * Example text [#1](https://github.com/eclipse-iceoryx/iceoryx2/issues/1) + * Replace `iceoryx2::service::Service` with `iceoryx2::service::Details` [#100](https://github.com/eclipse-iceoryx/iceoryx2/issues/100) + * Remove `'config` lifetime from all structs [#100](https://github.com/eclipse-iceoryx/iceoryx2/issues/100) ### Workflow @@ -56,3 +57,58 @@ sample.send()?; ``` +2. All port `Publisher`, `Subscriber`, `Listener` and `Notifier` no longer have a generic + `'config` lifetime parameter. + + ```rust + // old + let publisher: Publisher<'service, 'config, iceoryx2::service::zero_copy::Service::Type<'config>, MessageType> = ..; + let subscriber: Subscriber<'service, 'config, iceoryx2::service::zero_copy::Service::Type<'config>, MessageType> = ..; + let notifier: Notifier<'service, 'config, iceoryx2::service::zero_copy::Service::Type<'config>> = ..; + let listener: Listener<'service, 'config, iceoryx2::service::zero_copy::Service::Type<'config>> = ..; + + // new + let publisher: Publisher<'service, iceoryx2::service::zero_copy::Service, MessageType> = ..; + let subscriber: Subscriber<'service, iceoryx2::service::zero_copy::Service, MessageType> = ..; + let notifier: Notifier<'service, iceoryx2::service::zero_copy::Service> = ..; + let listener: Listener<'service, iceoryx2::service::zero_copy::Service> = ..; + ``` + +3. `iceoryx2::service::Details` no longer has a generic `'config` lifetime parameter. + `iceoryx2::service::Details` replaced `iceoryx2::service::Service`. All custom services need + to implement `iceoryx2::service::Service`. + + ```rust + // old + pub struct MyCustomServiceType<'config> { + state: ServiceState<'config, static_storage::whatever::Storage, dynamic_storage::whatever::Storage> + } + + impl<'config> crate::service::Service for MyCustomServiceType<'config> { + // ... + } + + impl<'config> crate::service::Details for MyCustomServiceType<'config> { + // ... + } + + // new + pub struct MyCustomServiceType { + state: ServiceState> + } + + impl crate::service::Service for MyCustomServiceType { + // ... + } + ``` + +4. Writing functions with generic service parameter no longer require `Service + Details<'config>`. + Now it suffices to just use `Service` + + ```rust + // old + fn my_generic_service_function<'config, ServiceType: iceoryx2::service::Service + iceoryx2::service::Details<'config>>(); + + // new + fn my_generic_service_function(); + ``` diff --git a/iceoryx2/src/service/builder/event.rs b/iceoryx2/src/service/builder/event.rs index f17576340..3561e955b 100644 --- a/iceoryx2/src/service/builder/event.rs +++ b/iceoryx2/src/service/builder/event.rs @@ -257,14 +257,14 @@ impl Builder { with EventCreateError::Corrupted, "{} since the configuration could not be written to the static storage.", msg); - return Ok(event::PortFactory::new(ServiceType::from_state( + Ok(event::PortFactory::new(ServiceType::from_state( service::ServiceState::new( self.base.service_config.clone(), self.base.global_config, dynamic_config, unlocked_static_details, ), - ))); + ))) } Ok(Some(_)) | Err(ServiceState::IncompatibleMessagingPattern) => { fail!(from self, with EventCreateError::AlreadyExists, diff --git a/iceoryx2/src/service/builder/publish_subscribe.rs b/iceoryx2/src/service/builder/publish_subscribe.rs index e79458fc9..867f740b9 100644 --- a/iceoryx2/src/service/builder/publish_subscribe.rs +++ b/iceoryx2/src/service/builder/publish_subscribe.rs @@ -391,14 +391,14 @@ impl Builder { with PublishSubscribeCreateError::Corrupted, "{} since the configuration could not be written to the static storage.", msg); - return Ok(publish_subscribe::PortFactory::new( + Ok(publish_subscribe::PortFactory::new( ServiceType::from_state(service::ServiceState::new( self.base.service_config.clone(), self.base.global_config, dynamic_config, unlocked_static_details, )), - )); + )) } Ok(Some(_)) | Err(ServiceAvailabilityState::IncompatibleTypes) diff --git a/iceoryx2/src/service/port_factory/event.rs b/iceoryx2/src/service/port_factory/event.rs index a6d7036cc..220f3c908 100644 --- a/iceoryx2/src/service/port_factory/event.rs +++ b/iceoryx2/src/service/port_factory/event.rs @@ -97,7 +97,7 @@ impl PortFactory { /// # Ok(()) /// # } /// ``` - pub fn notifier<'a>(&'a self) -> PortFactoryNotifier<'a, Service> { + pub fn notifier(&self) -> PortFactoryNotifier { PortFactoryNotifier::new(self) } @@ -118,7 +118,7 @@ impl PortFactory { /// # Ok(()) /// # } /// ``` - pub fn listener<'a>(&'a self) -> PortFactoryListener<'a, Service> { + pub fn listener(&self) -> PortFactoryListener { PortFactoryListener { factory: self } } } diff --git a/iceoryx2/src/service/port_factory/publish_subscribe.rs b/iceoryx2/src/service/port_factory/publish_subscribe.rs index b0452cf9e..4f8114a7a 100644 --- a/iceoryx2/src/service/port_factory/publish_subscribe.rs +++ b/iceoryx2/src/service/port_factory/publish_subscribe.rs @@ -122,9 +122,7 @@ impl PortFactory( - &'factory self, - ) -> PortFactorySubscriber<'factory, Service, MessageType> { + pub fn subscriber(&self) -> PortFactorySubscriber { PortFactorySubscriber { factory: self } } @@ -151,9 +149,7 @@ impl PortFactory( - &'factory self, - ) -> PortFactoryPublisher<'factory, Service, MessageType> { + pub fn publisher(&self) -> PortFactoryPublisher { PortFactoryPublisher::new(self) } }