Skip to content

Commit

Permalink
[eclipse-iceoryx#550] Adjust rust API and add disable_ for events
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Dec 17, 2024
1 parent 89cce20 commit 3bfc42c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 40 deletions.
1 change: 1 addition & 0 deletions doc/release-notes/iceoryx2-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Make signal handling optional in `WaitSet` and `Node` [#528](https://github.com/eclipse-iceoryx/iceoryx2/issues/528)
* Support dynamic data with reallocation for publish-subscribe communication [#532](https://github.com/eclipse-iceoryx/iceoryx2/issues/532)
* Add benchmark for iceoryx2 queues [#535](https://github.com/eclipse-iceoryx/iceoryx2/issues/535)
* Add auto event mission for create, drop and dead notifiers [#550](https://github.com/eclipse-iceoryx/iceoryx2/issues/550)

### Bugfixes

Expand Down
42 changes: 24 additions & 18 deletions iceoryx2-ffi/ffi/src/api/service_builder_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,20 @@ unsafe fn iox2_service_builder_event_set_notifier_dead_event_impl(
ManuallyDrop::take(&mut service_builder_struct.value.as_mut().ipc);

let service_builder = ManuallyDrop::into_inner(service_builder.event);
service_builder_struct.set(ServiceBuilderUnion::new_ipc_event(
service_builder.notifier_dead_event(value),
));
service_builder_struct.set(ServiceBuilderUnion::new_ipc_event(match value {
Some(value) => service_builder.notifier_dead_event(value),
None => service_builder.disable_notifier_dead_event(),
}));
}
iox2_service_type_e::LOCAL => {
let service_builder =
ManuallyDrop::take(&mut service_builder_struct.value.as_mut().local);

let service_builder = ManuallyDrop::into_inner(service_builder.event);
service_builder_struct.set(ServiceBuilderUnion::new_local_event(
service_builder.notifier_dead_event(value),
));
service_builder_struct.set(ServiceBuilderUnion::new_local_event(match value {
Some(value) => service_builder.notifier_dead_event(value),
None => service_builder.disable_notifier_dead_event(),
}));
}
}
}
Expand Down Expand Up @@ -317,18 +319,20 @@ unsafe fn iox2_service_builder_event_set_notifier_created_event_impl(
ManuallyDrop::take(&mut service_builder_struct.value.as_mut().ipc);

let service_builder = ManuallyDrop::into_inner(service_builder.event);
service_builder_struct.set(ServiceBuilderUnion::new_ipc_event(
service_builder.notifier_created_event(value),
));
service_builder_struct.set(ServiceBuilderUnion::new_ipc_event(match value {
Some(value) => service_builder.notifier_created_event(value),
None => service_builder.disable_notifier_created_event(),
}));
}
iox2_service_type_e::LOCAL => {
let service_builder =
ManuallyDrop::take(&mut service_builder_struct.value.as_mut().local);

let service_builder = ManuallyDrop::into_inner(service_builder.event);
service_builder_struct.set(ServiceBuilderUnion::new_local_event(
service_builder.notifier_created_event(value),
));
service_builder_struct.set(ServiceBuilderUnion::new_local_event(match value {
Some(value) => service_builder.notifier_created_event(value),
None => service_builder.disable_notifier_created_event(),
}));
}
}
}
Expand Down Expand Up @@ -387,18 +391,20 @@ unsafe fn iox2_service_builder_event_set_notifier_dropped_event_impl(
ManuallyDrop::take(&mut service_builder_struct.value.as_mut().ipc);

let service_builder = ManuallyDrop::into_inner(service_builder.event);
service_builder_struct.set(ServiceBuilderUnion::new_ipc_event(
service_builder.notifier_dropped_event(value),
));
service_builder_struct.set(ServiceBuilderUnion::new_ipc_event(match value {
Some(value) => service_builder.notifier_dropped_event(value),
None => service_builder.disable_notifier_dropped_event(),
}));
}
iox2_service_type_e::LOCAL => {
let service_builder =
ManuallyDrop::take(&mut service_builder_struct.value.as_mut().local);

let service_builder = ManuallyDrop::into_inner(service_builder.event);
service_builder_struct.set(ServiceBuilderUnion::new_local_event(
service_builder.notifier_dropped_event(value),
));
service_builder_struct.set(ServiceBuilderUnion::new_local_event(match value {
Some(value) => service_builder.notifier_dropped_event(value),
None => service_builder.disable_notifier_dropped_event(),
}));
}
}
}
Expand Down
45 changes: 33 additions & 12 deletions iceoryx2/src/service/builder/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,28 +248,49 @@ impl<ServiceType: service::Service> Builder<ServiceType> {
}

/// If the [`Service`] is created it defines the event that shall be emitted by every newly
/// created [`Notifier`](crate::port::notifier::Notifier). If [`None`] is provided a new
/// [`Notifier`](crate::port::notifier::Notifier) will not emit an event.
pub fn notifier_created_event(mut self, value: Option<EventId>) -> Self {
self.config_details().notifier_created_event = value.map(|e| e.as_value());
/// created [`Notifier`](crate::port::notifier::Notifier).
pub fn notifier_created_event(mut self, value: EventId) -> Self {
self.config_details().notifier_created_event = Some(value.as_value());
self.verify_notifier_created_event = true;
self
}

/// If the [`Service`] is created it disables the event that shall be emitted by every newly
/// created [`Notifier`](crate::port::notifier::Notifier).
pub fn disable_notifier_created_event(mut self) -> Self {
self.config_details().notifier_created_event = None;
self.verify_notifier_created_event = true;
self
}

/// If the [`Service`] is created it defines the event that shall be emitted by every
/// [`Notifier`](crate::port::notifier::Notifier) before it is dropped. If [`None`] is
/// provided a [`Notifier`](crate::port::notifier::Notifier) will not emit an event.
pub fn notifier_dropped_event(mut self, value: Option<EventId>) -> Self {
self.config_details().notifier_dropped_event = value.map(|e| e.as_value());
/// [`Notifier`](crate::port::notifier::Notifier) before it is dropped.
pub fn notifier_dropped_event(mut self, value: EventId) -> Self {
self.config_details().notifier_dropped_event = Some(value.as_value());
self.verify_notifier_dropped_event = true;
self
}

/// If the [`Service`] is created it disables the event that shall be emitted by every
/// [`Notifier`](crate::port::notifier::Notifier) before it is dropped.
pub fn disable_notifier_dropped_event(mut self) -> Self {
self.config_details().notifier_dropped_event = None;
self.verify_notifier_dropped_event = true;
self
}

/// If the [`Service`] is created it defines the event that shall be emitted when a
/// [`Notifier`](crate::port::notifier::Notifier) is identified as dead. If [`None`] is
/// provided no event will be emitted.
pub fn notifier_dead_event(mut self, value: Option<EventId>) -> Self {
self.config_details().notifier_dead_event = value.map(|e| e.as_value());
/// [`Notifier`](crate::port::notifier::Notifier) is identified as dead.
pub fn notifier_dead_event(mut self, value: EventId) -> Self {
self.config_details().notifier_dead_event = Some(value.as_value());
self.verify_notifier_dead_event = true;
self
}

/// If the [`Service`] is created it disables the event that shall be emitted when a
/// [`Notifier`](crate::port::notifier::Notifier) is identified as dead.
pub fn disable_notifier_dead_event(mut self) -> Self {
self.config_details().notifier_dead_event = None;
self.verify_notifier_dead_event = true;
self
}
Expand Down
6 changes: 3 additions & 3 deletions iceoryx2/tests/node_death_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ mod node_death_tests {
let dead_service = dead_node
.service_builder(&service_name)
.event()
.notifier_dead_event(Some(notifier_dead_event))
.notifier_created_event(Some(EventId::new(0)))
.notifier_dropped_event(Some(EventId::new(0)))
.notifier_dead_event(notifier_dead_event)
.notifier_created_event(EventId::new(0))
.notifier_dropped_event(EventId::new(0))
.create()
.unwrap();
let dead_notifier = dead_service.notifier_builder().create().unwrap();
Expand Down
14 changes: 7 additions & 7 deletions iceoryx2/tests/service_event_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ mod service_event {
.max_nodes(7)
.max_notifiers(4)
.max_listeners(5)
.notifier_dead_event(Some(EventId::new(8)))
.notifier_dropped_event(Some(EventId::new(9)))
.notifier_created_event(Some(EventId::new(10)))
.notifier_dead_event(EventId::new(8))
.notifier_dropped_event(EventId::new(9))
.notifier_created_event(EventId::new(10))
.create()
.unwrap();
assert_that!(sut.static_config().max_nodes(), eq 7);
Expand Down Expand Up @@ -404,8 +404,8 @@ mod service_event {
let sut = node
.service_builder(&service_name)
.event()
.notifier_created_event(None)
.notifier_dropped_event(None)
.disable_notifier_created_event()
.disable_notifier_dropped_event()
.create()
.unwrap();

Expand Down Expand Up @@ -440,8 +440,8 @@ mod service_event {
let sut = node
.service_builder(&service_name)
.event()
.notifier_created_event(Some(notifier_created))
.notifier_dropped_event(Some(notifier_dropped))
.notifier_created_event(notifier_created)
.notifier_dropped_event(notifier_dropped)
.create()
.unwrap();

Expand Down

0 comments on commit 3bfc42c

Please sign in to comment.