Skip to content

Commit

Permalink
[eclipse-iceoryx#550] Introduce special event ids in config
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Dec 19, 2024
1 parent c45062f commit 568bebb
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 13 deletions.
6 changes: 3 additions & 3 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ Adjusting `global` settings ensures a non-interfering setup.
* `defaults.event.max-nodes` - [int]: Maximum number of nodes.
* `defaults.event.event-id-max-value` - [int]: Greatest value an [`EventId`] can
have.
* `defaults.event.emit-event-id-with-new-notifier` - [Option\<int\>]: If defined,
* `defaults.event.notifier-created-event` - [Option\<int\>]: If defined,
it defines the event id that is emitted when a new notifier is created.
* `defaults.event.emit-event-id-with-notifier-drop` - [Option\<int\>]: If defined,
* `defaults.event.notifier-dropped-event` - [Option\<int\>]: If defined,
it defines the event id that is emitted when a notifier is destroyed.
* `defaults.event.emit-event-id-if-notifier-dead` - [Option\<int\>]: If defined,
* `defaults.event.notifier-dead-event` - [Option\<int\>]: If defined,
it defines the event id that is emitted when a dead notifier is cleaned up.

### Service: Publish Subscribe Messaging Pattern
Expand Down
6 changes: 3 additions & 3 deletions config/iceoryx2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ max-listeners = 16
max-notifiers = 16
max-nodes = 36
event-id-max-value = 4294967295
# emit-event-id-with-new-notifier = 1 # uncomment to enable setting
# emit-event-id-with-notifier-drop = 2 # uncomment to enable setting
# emit-event-id-if-notifier-dead = 3 # uncomment to enable setting
# notifier-created-event = 1 # uncomment to enable setting
# notifier-dropped-event = 2 # uncomment to enable setting
# notifier-dead-event = 3 # uncomment to enable setting
2 changes: 1 addition & 1 deletion iceoryx2-ffi/ffi/src/api/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub(super) struct ConfigOwner {
#[repr(C)]
#[repr(align(8))] // align_of<ConfigOwner>()
pub struct iox2_config_storage_t {
internal: [u8; 3560], // size_of<ConfigOwner>()
internal: [u8; 3608], // size_of<ConfigOwner>()
}

/// Contains the iceoryx2 config
Expand Down
15 changes: 15 additions & 0 deletions iceoryx2-ffi/ffi/src/api/service_builder_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ pub enum iox2_event_open_or_create_error_e {
O_INCOMPATIBLE_MESSAGING_PATTERN,
#[CustomString = "incompatible attributes"]
O_INCOMPATIBLE_ATTRIBUTES,
#[CustomString = "incompatible notifier_created_event"]
O_INCOMPATIBLE_NOTIFIER_CREATED_EVENT,
#[CustomString = "incompatible notifier_dropped_event"]
O_INCOMPATIBLE_NOTIFIER_DROPPED_EVENT,
#[CustomString = "incompatible notifier_dead_event"]
O_INCOMPATIBLE_NOTIFIER_DEAD_EVENT,
#[CustomString = "internal failure"]
O_INTERNAL_FAILURE,
#[CustomString = "hangs in creation"]
Expand Down Expand Up @@ -118,6 +124,15 @@ impl IntoCInt for EventOpenError {
EventOpenError::IsMarkedForDestruction => {
iox2_event_open_or_create_error_e::O_IS_MARKED_FOR_DESTRUCTION
}
EventOpenError::IncompatibleNotifierCreatedEvent => {
iox2_event_open_or_create_error_e::O_INCOMPATIBLE_NOTIFIER_CREATED_EVENT
}
EventOpenError::IncompatibleNotifierDroppedEvent => {
iox2_event_open_or_create_error_e::O_INCOMPATIBLE_NOTIFIER_DROPPED_EVENT
}
EventOpenError::IncompatibleNotifierDeadEvent => {
iox2_event_open_or_create_error_e::O_INCOMPATIBLE_NOTIFIER_DEAD_EVENT
}
}) as c_int
}
}
Expand Down
12 changes: 6 additions & 6 deletions iceoryx2/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ pub struct Event {
/// The largest event id supported by the event service
pub event_id_max_value: usize,
/// Defines the event id value that is emitted after a new notifier was created.
pub emit_event_id_with_new_notifier: Option<usize>,
pub notifier_created_event: Option<usize>,
/// Defines the event id value that is emitted before a new notifier is dropped.
pub emit_event_id_with_notifier_drop: Option<usize>,
pub notifier_dropped_event: Option<usize>,
/// Defines the event id value that is emitted if a notifier was identified as dead.
pub emit_event_id_if_notifier_dead: Option<usize>,
pub notifier_dead_event: Option<usize>,
}

/// Represents the configuration that iceoryx2 will utilize. It is divided into two sections:
Expand Down Expand Up @@ -339,9 +339,9 @@ impl Default for Config {
max_notifiers: 16,
max_nodes: 36,
event_id_max_value: 4294967295,
emit_event_id_with_new_notifier: None,
emit_event_id_with_notifier_drop: None,
emit_event_id_if_notifier_dead: None,
notifier_created_event: None,
notifier_dropped_event: None,
notifier_dead_event: None,
},
},
}
Expand Down
66 changes: 66 additions & 0 deletions iceoryx2/src/service/builder/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ pub enum EventOpenError {
IncompatibleAttributes,
/// Errors that indicate either an implementation issue or a wrongly configured system.
InternalFailure,
/// The event id that is emitted for a newly created [`Notifier`](crate::port::notifier::Notifier)
/// does not fit the required event id.
IncompatibleNotifierCreatedEvent,
/// The event id that is emitted if a [`Notifier`](crate::port::notifier::Notifier) is dropped
/// does not fit the required event id.
IncompatibleNotifierDroppedEvent,
/// The event id that is emitted if a [`Notifier`](crate::port::notifier::Notifier) is
/// identified as dead does not fit the required event id.
IncompatibleNotifierDeadEvent,
/// The [`Service`]s creation timeout has passed and it is still not initialized. Can be caused
/// by a process that crashed during [`Service`] creation.
HangsInCreation,
Expand Down Expand Up @@ -168,6 +177,9 @@ pub struct Builder<ServiceType: service::Service> {
verify_max_listeners: bool,
verify_max_nodes: bool,
verify_event_id_max_value: bool,
verify_notifier_created_event: bool,
verify_notifier_dropped_event: bool,
verify_notifier_dead_event: bool,
}

impl<ServiceType: service::Service> Builder<ServiceType> {
Expand All @@ -178,6 +190,9 @@ impl<ServiceType: service::Service> Builder<ServiceType> {
verify_max_listeners: false,
verify_max_nodes: false,
verify_event_id_max_value: false,
verify_notifier_dead_event: false,
verify_notifier_created_event: false,
verify_notifier_dropped_event: false,
};

new_self.base.service_config.messaging_pattern = MessagingPattern::Event(
Expand Down Expand Up @@ -232,6 +247,33 @@ impl<ServiceType: service::Service> Builder<ServiceType> {
self
}

/// 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<usize>) -> Self {
self.config_details().notifier_created_event = value;
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<usize>) -> Self {
self.config_details().notifier_dropped_event = value;
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<usize>) -> Self {
self.config_details().notifier_dead_event = value;
self.verify_notifier_dead_event = true;
self
}

/// If the [`Service`] exists, it will be opened otherwise a new [`Service`] will be
/// created.
pub fn open_or_create(self) -> Result<event::PortFactory<ServiceType>, EventOpenOrCreateError> {
Expand Down Expand Up @@ -522,6 +564,30 @@ impl<ServiceType: service::Service> Builder<ServiceType> {
msg, existing_settings.max_nodes, required_settings.max_nodes);
}

if self.verify_notifier_created_event
&& existing_settings.notifier_created_event != required_settings.notifier_created_event
{
fail!(from self, with EventOpenError::IncompatibleNotifierCreatedEvent,
"{} since the notifier_created_event id is {:?} but the value {:?} is required.",
msg, existing_settings.notifier_created_event, required_settings.notifier_created_event);
}

if self.verify_notifier_dropped_event
&& existing_settings.notifier_dropped_event != required_settings.notifier_dropped_event
{
fail!(from self, with EventOpenError::IncompatibleNotifierDroppedEvent,
"{} since the notifier_dropped_event id is {:?} but the value {:?} is required.",
msg, existing_settings.notifier_dropped_event, required_settings.notifier_dropped_event);
}

if self.verify_notifier_dead_event
&& existing_settings.notifier_dead_event != required_settings.notifier_dead_event
{
fail!(from self, with EventOpenError::IncompatibleNotifierDeadEvent,
"{} since the notifier_dead_event id is {:?} but the value {:?} is required.",
msg, existing_settings.notifier_dead_event, required_settings.notifier_dead_event);
}

Ok(*existing_settings)
}
}
6 changes: 6 additions & 0 deletions iceoryx2/src/service/static_config/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub struct StaticConfig {
pub(crate) max_listeners: usize,
pub(crate) max_nodes: usize,
pub(crate) event_id_max_value: usize,
pub(crate) notifier_created_event: Option<usize>,
pub(crate) notifier_dropped_event: Option<usize>,
pub(crate) notifier_dead_event: Option<usize>,
}

impl StaticConfig {
Expand All @@ -49,6 +52,9 @@ impl StaticConfig {
max_listeners: config.defaults.event.max_listeners,
max_nodes: config.defaults.event.max_nodes,
event_id_max_value: config.defaults.event.event_id_max_value,
notifier_created_event: config.defaults.event.notifier_created_event,
notifier_dropped_event: config.defaults.event.notifier_dropped_event,
notifier_dead_event: config.defaults.event.notifier_dead_event,
}
}

Expand Down

0 comments on commit 568bebb

Please sign in to comment.