Skip to content

Commit

Permalink
Merge pull request #105 from elfenpiff/iox2-100-rc-owned-management-s…
Browse files Browse the repository at this point in the history
…tructs

[#100] rc owned management structs
  • Loading branch information
elfenpiff authored Jan 29, 2024
2 parents 9da8927 + 2855eb3 commit 477a193
Show file tree
Hide file tree
Showing 26 changed files with 252 additions and 277 deletions.
61 changes: 51 additions & 10 deletions doc/release-notes/iceoryx2-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

<!-- NOTE: Add new entries sorted by issue number to minimize the possibility of conflicts when merging. -->

* 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

Expand All @@ -35,8 +36,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

Expand All @@ -56,18 +57,58 @@
sample.send()?;
```

2. Port types renamed, `Impl` suffix was added to all ports
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
let publisher: Publisher<'_, '_, zero_copy::Service, u64> = service.publisher().create()?;
pub struct MyCustomServiceType<'config> {
state: ServiceState<'config, static_storage::whatever::Storage, dynamic_storage::whatever::Storage<WhateverConfig>>
}

impl<'config> crate::service::Service for MyCustomServiceType<'config> {
// ...
}

impl<'config> crate::service::Details for MyCustomServiceType<'config> {
// ...
}

// new
let publisher: PublisherImpl<'_, '_, zero_copy::Service, u64> = service.publisher().create()?;
pub struct MyCustomServiceType {
state: ServiceState<static_storage::whatever::Storage, dynamic_storage::whatever::Storage<WhateverConfig>>
}

// same applies also to:
// * `Subscriber` -> `SubscriberImpl`
// * `Listener` -> `ListenerImpl`
// * `Notifier` -> `NotifierImpl`
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<ServiceType: iceoryx2::service::Service>();
```
4 changes: 3 additions & 1 deletion iceoryx2-bb/system-types/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
//! 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;

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;

Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-cal/src/zero_copy_connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ impl ZeroCopyReceiver for Receiver {
}
}

#[derive(Debug)]
pub struct Connection {}

impl NamedConceptMgmt for Connection {
Expand Down
1 change: 1 addition & 0 deletions iceoryx2-cal/src/zero_copy_connection/process_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ impl ZeroCopyReceiver for Receiver {
}
}

#[derive(Debug)]
pub struct Connection {}

impl NamedConceptMgmt for Connection {
Expand Down
33 changes: 16 additions & 17 deletions iceoryx2/src/port/details/publisher_connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -34,15 +34,14 @@ use iceoryx2_cal::{
};

#[derive(Debug)]
pub(crate) struct Connection<'config, Service: service::Details<'config>> {
pub(crate) receiver:
<<Service as service::Details<'config>>::Connection as ZeroCopyConnection>::Receiver,
pub(crate) struct Connection<Service: service::Service> {
pub(crate) receiver: <Service::Connection as ZeroCopyConnection>::Receiver,
pub(crate) data_segment: Service::SharedMemory,
}

impl<'config, Service: service::Details<'config>> Connection<'config, Service> {
impl<Service: service::Service> Connection<Service> {
fn new(
this: &PublisherConnections<'config, Service>,
this: &PublisherConnections<Service>,
publisher_id: UniquePublisherId,
) -> Result<Self, ConnectionFailure> {
let msg = format!(
Expand All @@ -51,9 +50,9 @@ impl<'config, Service: service::Details<'config>> Connection<'config, Service> {
);

let receiver = fail!(from this,
when <<Service as service::Details<'config>>::Connection as ZeroCopyConnection>::
when <Service::Connection as ZeroCopyConnection>::
Builder::new( &connection_name(publisher_id, this.subscriber_id))
.config(&connection_config::<Service>(this.config))
.config(&connection_config::<Service>(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)
Expand All @@ -63,7 +62,7 @@ impl<'config, Service: service::Details<'config>> Connection<'config, Service> {
let data_segment = fail!(from this,
when <Service::SharedMemory as SharedMemory<PoolAllocator>>::
Builder::new(&data_segment_name(publisher_id))
.config(&data_segment_config::<Service>(this.config))
.config(&data_segment_config::<Service>(this.config.as_ref()))
.open(),
"{} since the publishers data segment could not be mapped into the process.", msg);

Expand All @@ -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<UnsafeCell<Option<Connection<'config, Service>>>>,
pub(crate) struct PublisherConnections<Service: service::Service> {
connections: Vec<UnsafeCell<Option<Connection<Service>>>>,
subscriber_id: UniqueSubscriberId,
config: &'config config::Config,
config: Rc<config::Config>,
static_config: StaticConfig,
}

impl<'config, Service: service::Details<'config>> PublisherConnections<'config, Service> {
impl<Service: service::Service> PublisherConnections<Service> {
pub(crate) fn new(
capacity: usize,
subscriber_id: UniqueSubscriberId,
config: &'config config::Config,
config: &Rc<config::Config>,
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(),
}
}
Expand All @@ -100,13 +99,13 @@ impl<'config, Service: service::Details<'config>> PublisherConnections<'config,
self.subscriber_id
}

pub(crate) fn get(&self, index: usize) -> &Option<Connection<'config, Service>> {
pub(crate) fn get(&self, index: usize) -> &Option<Connection<Service>> {
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<Connection<'config, Service>> {
pub(crate) fn get_mut(&self, index: usize) -> &mut Option<Connection<Service>> {
#[deny(clippy::mut_from_ref)]
unsafe {
&mut *self.connections[index].get()
Expand Down
30 changes: 15 additions & 15 deletions iceoryx2/src/port/details/subscriber_connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,19 +28,18 @@ use crate::{
};

#[derive(Debug)]
pub(crate) struct Connection<'config, Service: service::Details<'config>> {
pub(crate) sender:
<<Service as service::Details<'config>>::Connection as ZeroCopyConnection>::Sender,
pub(crate) struct Connection<Service: service::Service> {
pub(crate) sender: <Service::Connection as ZeroCopyConnection>::Sender,
}

impl<'config, Service: service::Details<'config>> Connection<'config, Service> {
impl<Service: service::Service> Connection<Service> {
fn new(
this: &SubscriberConnections<'config, Service>,
this: &SubscriberConnections<Service>,
subscriber_id: UniqueSubscriberId,
) -> Result<Self, ZeroCopyCreationError> {
let sender = fail!(from this, when <<Service as service::Details<'config>>::Connection as ZeroCopyConnection>::
let sender = fail!(from this, when <Service::Connection as ZeroCopyConnection>::
Builder::new( &connection_name(this.port_id, subscriber_id))
.config(&connection_config::<Service>(this.config))
.config(&connection_config::<Service>(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)
Expand All @@ -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<UnsafeCell<Option<Connection<'config, Service>>>>,
pub(crate) struct SubscriberConnections<Service: service::Service> {
connections: Vec<UnsafeCell<Option<Connection<Service>>>>,
port_id: UniquePublisherId,
config: &'config config::Config,
config: Rc<config::Config>,
static_config: StaticConfig,
}

impl<'config, Service: service::Details<'config>> SubscriberConnections<'config, Service> {
impl<Service: service::Service> SubscriberConnections<Service> {
pub(crate) fn new(
capacity: usize,
config: &'config config::Config,
config: &Rc<config::Config>,
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<Connection<'config, Service>> {
pub(crate) fn get(&self, index: usize) -> &Option<Connection<Service>> {
unsafe { &(*self.connections[index].get()) }
}

// only used internally as convinience function
#[allow(clippy::mut_from_ref)]
fn get_mut(&self, index: usize) -> &mut Option<Connection<'config, Service>> {
fn get_mut(&self, index: usize) -> &mut Option<Connection<Service>> {
#[deny(clippy::mut_from_ref)]
unsafe {
&mut (*self.connections[index].get())
Expand Down
10 changes: 3 additions & 7 deletions iceoryx2/src/port/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UniqueIndex<'a>>,
listener: <Service::Event as iceoryx2_cal::event::Event<EventId>>::Listener,
cache: Vec<EventId>,
_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<Self, ListenerCreateError> {
let msg = "Failed to create listener";
let origin = "Listener::new()";
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
16 changes: 6 additions & 10 deletions iceoryx2/src/port/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ use super::{
};

#[derive(Debug, Default)]
struct ListenerConnections<'config, Service: service::Details<'config>> {
struct ListenerConnections<Service: service::Service> {
#[allow(clippy::type_complexity)]
connections:
Vec<UnsafeCell<Option<<Service::Event as iceoryx2_cal::event::Event<EventId>>::Notifier>>>,
}

impl<'config, Service: service::Details<'config>> ListenerConnections<'config, Service> {
impl<Service: service::Service> ListenerConnections<Service> {
fn new(size: usize) -> Self {
let mut new_self = Self {
connections: vec![],
Expand Down Expand Up @@ -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<Service>,
listener_list_state: UnsafeCell<ContainerState<'a, UniqueListenerId>>,
default_event_id: EventId,
_dynamic_config_guard: Option<UniqueIndex<'a>>,
_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,
Expand All @@ -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
Expand Down Expand Up @@ -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<usize, NotifierConnectionUpdateFailure> {
self.notify_with_custom_event_id(self.default_event_id)
}
Expand Down
Loading

0 comments on commit 477a193

Please sign in to comment.