iceoryx2-cal 0.10.0

iceoryx2: [internal] high-level traits and implementations that represents OS primitives in an exchangeable fashion
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
// Copyright (c) 2026 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::{
    dynamic_storage::{
        DynamicStorage, DynamicStorageBuilder, DynamicStorageCreateError, DynamicStorageOpenError,
    },
    event::{
        DEFAULT_MAX_EVENT_ID, Event, EventId, Listener, ListenerBuilder, ListenerCreateError,
        ListenerWaitError, NamedConcept, NamedConceptBuilder, NamedConceptMgmt, Notifier,
        NotifierBuilder, NotifierNotifyError, NotifierOpenError,
        event_state::{EventActivation, EventState},
        trigger::{HandlerInterface, State, WaiterInterface, stub::Stub},
    },
    named_concept::NamedConceptConfiguration,
};
use alloc::vec::Vec;
use core::fmt::Debug;
use core::{marker::PhantomData, mem::MaybeUninit, ptr::NonNull, time::Duration};
use iceoryx2_bb_concurrency::atomic::{AtomicU8, Ordering};
use iceoryx2_bb_container::semantic_string::SemanticString;
use iceoryx2_bb_elementary_traits::{
    testing::abandonable::Abandonable, zero_copy_send::ZeroCopySend,
};
use iceoryx2_bb_posix::{
    file::AccessMode, file_descriptor::FileDescriptorBased,
    file_descriptor_set::SynchronousMultiplexing,
};
use iceoryx2_bb_system_types::file_name::FileName;
use iceoryx2_bb_system_types::path::Path;
use iceoryx2_log::{debug, fail};

const NOTIFICATION_STATE_IDLE: u8 = 0;
const NOTIFICATION_STATE_PENDING: u8 = 1;
const NOTIFICATION_STATE_NOTIFIED: u8 = 2;

#[derive(PartialEq, Eq, Debug)]
pub struct Configuration<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
> {
    value: Storage::Configuration,
    _data_1: PhantomData<E>,
    _data_2: PhantomData<Mgmt>,
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
> Clone for Configuration<E, Mgmt, Storage>
{
    fn clone(&self) -> Self {
        Self {
            value: self.value.clone(),
            _data_1: PhantomData,
            _data_2: PhantomData,
        }
    }
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
> Default for Configuration<E, Mgmt, Storage>
{
    fn default() -> Self {
        Self {
            value: Storage::Configuration::default()
                .path_hint(&EventImpl::<E, Mgmt, Storage, Stub, Stub>::default_path_hint())
                .suffix(&EventImpl::<E, Mgmt, Storage, Stub, Stub>::default_suffix())
                .prefix(&EventImpl::<E, Mgmt, Storage, Stub, Stub>::default_prefix()),
            _data_1: PhantomData,
            _data_2: PhantomData,
        }
    }
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
> Configuration<E, Mgmt, Storage>
{
    fn to_storage_config(&self) -> Storage::Configuration {
        let mut suffix = *self.get_suffix();
        suffix.push_bytes(b"_mgmt").unwrap();
        self.value.clone().suffix(&suffix)
    }

    fn to_trigger_config(&self) -> super::trigger::Configuration {
        super::trigger::Configuration {
            suffix: *self.get_suffix(),
            prefix: *self.get_prefix(),
            path_hint: *self.get_path_hint(),
        }
    }
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
> NamedConceptConfiguration for Configuration<E, Mgmt, Storage>
{
    fn prefix(mut self, value: &FileName) -> Self {
        self.value = self.value.prefix(value);
        self
    }

    fn get_prefix(&self) -> &FileName {
        self.value.get_prefix()
    }

    fn suffix(mut self, value: &FileName) -> Self {
        self.value = self.value.suffix(value);
        self
    }

    fn get_suffix(&self) -> &FileName {
        self.value.get_suffix()
    }

    fn path_hint(mut self, value: &Path) -> Self {
        self.value = self.value.path_hint(value);
        self
    }

    fn get_path_hint(&self) -> &Path {
        self.value.get_path_hint()
    }
}

#[derive(Debug)]
pub struct EventImpl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage>,
    W: WaiterInterface<E, Mgmt, Storage>,
> {
    _data_1: PhantomData<E>,
    _data_2: PhantomData<Mgmt>,
    _data_3: PhantomData<Storage>,
    _data_4: PhantomData<H>,
    _data_5: PhantomData<W>,
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage>,
    W: WaiterInterface<E, Mgmt, Storage>,
> NamedConceptMgmt for EventImpl<E, Mgmt, Storage, H, W>
{
    type Configuration = Configuration<E, Mgmt, Storage>;

    fn does_exist_cfg(
        name: &FileName,
        cfg: &Self::Configuration,
    ) -> Result<bool, crate::named_concept::NamedConceptDoesExistError> {
        Storage::does_exist_cfg(name, &cfg.to_storage_config())
    }

    fn list_cfg(
        cfg: &Self::Configuration,
    ) -> Result<Vec<FileName>, crate::named_concept::NamedConceptListError> {
        Storage::list_cfg(&cfg.to_storage_config())
    }

    unsafe fn remove_cfg(
        name: &FileName,
        cfg: &Self::Configuration,
    ) -> Result<bool, crate::named_concept::NamedConceptRemoveError> {
        let origin = "EventImpl::remove_cfg()";
        let msg = "Failed to remove event";
        let result = unsafe { W::remove(name, &cfg.to_trigger_config()) }.inspect_err(|e| {
            debug!(from origin, "{msg} since the trigger mechanism could not be removed. [{e:?}]");
        });

        match unsafe { Storage::remove_cfg(name, &cfg.to_storage_config()) }.inspect_err(|e| {
            debug!(from origin, "{msg} since the management storage could not be removed. [{e:?}]");
        }) {
            Ok(true) => result,
            Ok(false) => {
                if result.is_err() {
                    result
                } else {
                    Ok(false)
                }
            }
            Err(e) => Err(e),
        }
    }

    fn remove_path_hint(
        value: &Path,
    ) -> Result<(), crate::named_concept::NamedConceptPathHintRemoveError> {
        let _ = Storage::remove_path_hint(value);
        W::remove_path_hint(value)
    }
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage>,
    W: WaiterInterface<E, Mgmt, Storage>,
> Event<E> for EventImpl<E, Mgmt, Storage, H, W>
{
    type Listener = Waiter<E, Mgmt, Storage, W>;
    type ListenerBuilder = WaiterBuilder<E, Mgmt, Storage, H, W>;
    type Notifier = Handle<E, Mgmt, Storage, H>;
    type NotifierBuilder = HandleBuilder<E, Mgmt, Storage, H, W>;

    fn does_support_persistency() -> bool {
        Storage::does_support_persistency()
    }
}

#[derive(Debug)]
pub struct Handle<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage>,
> {
    handle: H,
    storage: Storage,
    fail_when_buffer_is_full: bool,
    _data_1: PhantomData<E>,
    _data_2: PhantomData<Mgmt>,
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage> + FileDescriptorBased,
> FileDescriptorBased for Handle<E, Mgmt, Storage, H>
{
    fn file_descriptor(&self) -> &iceoryx2_bb_posix::file_descriptor::FileDescriptor {
        self.handle.file_descriptor()
    }
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage> + SynchronousMultiplexing,
> SynchronousMultiplexing for Handle<E, Mgmt, Storage, H>
{
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage>,
> Abandonable for Handle<E, Mgmt, Storage, H>
{
    unsafe fn abandon_in_place(mut this: NonNull<Self>) {
        let this = unsafe { this.as_mut() };
        unsafe { H::abandon_in_place(NonNull::from_mut(&mut this.handle)) };
        unsafe { Storage::abandon_in_place(NonNull::from_mut(&mut this.storage)) };
    }
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage>,
> NamedConcept for Handle<E, Mgmt, Storage, H>
{
    fn name(&self) -> &FileName {
        self.storage.name()
    }
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage>,
> Notifier<E> for Handle<E, Mgmt, Storage, H>
{
    fn event_id_max(&self) -> EventId {
        self.storage.get().event_id_max
    }

    fn max_event_count(&self) -> u64 {
        self.storage.get().event.max_event_count()
    }

    fn notify(&self, event_id: EventId) -> Result<(), super::NotifierNotifyError> {
        let msg = "Unable to notify";
        let mgmt = self.storage.get();

        fail!(from self,
              when mgmt.event.activate(event_id),
              "{msg} with {event_id:?} since the activation failed.");

        let set_state_to_notified = || {
            let _ = mgmt.notification_state.compare_exchange(
                NOTIFICATION_STATE_PENDING,
                NOTIFICATION_STATE_NOTIFIED,
                Ordering::SeqCst,
                Ordering::SeqCst,
            );
        };
        let notify = || -> Result<(), NotifierNotifyError> {
            match self.handle.notify() {
                Ok(()) => {
                    set_state_to_notified();
                    Ok(())
                }
                Err(NotifierNotifyError::BufferIsFull) => {
                    if self.fail_when_buffer_is_full {
                        fail!(from self, with NotifierNotifyError::BufferIsFull,
                        "{msg} with {event_id:?} since the buffer is full.");
                    } else {
                        set_state_to_notified();
                        Ok(())
                    }
                }
                Err(e) => {
                    fail!(from self, with e,
                            "{msg} with {event_id:?} due to {e:?}.");
                }
            }
        };

        match mgmt.notification_state.compare_exchange(
            NOTIFICATION_STATE_IDLE,
            NOTIFICATION_STATE_PENDING,
            Ordering::SeqCst,
            Ordering::SeqCst,
        ) {
            Err(NOTIFICATION_STATE_NOTIFIED) => Ok(()),
            Ok(_) | Err(_) => notify(),
        }
    }
}

#[derive(Debug)]
pub struct Waiter<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    W: WaiterInterface<E, Mgmt, Storage>,
> {
    waiter: W,
    storage: Storage,
    _data_1: PhantomData<E>,
    _data_2: PhantomData<Mgmt>,
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    W: WaiterInterface<E, Mgmt, Storage> + FileDescriptorBased,
> FileDescriptorBased for Waiter<E, Mgmt, Storage, W>
{
    fn file_descriptor(&self) -> &iceoryx2_bb_posix::file_descriptor::FileDescriptor {
        self.waiter.file_descriptor()
    }
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    W: WaiterInterface<E, Mgmt, Storage> + SynchronousMultiplexing,
> SynchronousMultiplexing for Waiter<E, Mgmt, Storage, W>
{
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    W: WaiterInterface<E, Mgmt, Storage>,
> Abandonable for Waiter<E, Mgmt, Storage, W>
{
    unsafe fn abandon_in_place(mut this: NonNull<Self>) {
        let this = unsafe { this.as_mut() };
        unsafe { W::abandon_in_place(NonNull::from_mut(&mut this.waiter)) };
        unsafe { Storage::abandon_in_place(NonNull::from_mut(&mut this.storage)) };
    }
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    W: WaiterInterface<E, Mgmt, Storage>,
> NamedConcept for Waiter<E, Mgmt, Storage, W>
{
    fn name(&self) -> &FileName {
        self.storage.name()
    }
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    W: WaiterInterface<E, Mgmt, Storage>,
> Waiter<E, Mgmt, Storage, W>
{
    fn drain_events<F: FnMut(EventActivation), Fw: FnMut() -> Result<(), ListenerWaitError>>(
        &self,
        msg: &str,
        mut callback: F,
        mut wait_call: Fw,
    ) -> Result<u64, ListenerWaitError> {
        let mgmt = self.storage.get();

        let mut drain = || -> Result<u64, ListenerWaitError> {
            fail!(from self, when self.waiter.empty_buffer(),
                "{msg} since the wait buffer could not be emptied.");
            Ok(self.storage.get().event.drain(&mut callback))
        };

        if mgmt
            .notification_state
            .compare_exchange(
                NOTIFICATION_STATE_NOTIFIED,
                NOTIFICATION_STATE_IDLE,
                Ordering::SeqCst,
                Ordering::SeqCst,
            )
            .is_ok()
        {
            return drain();
        }

        fail!(from self, when wait_call(),
            "{msg} since the underlying wait call failed.");
        mgmt.notification_state
            .store(NOTIFICATION_STATE_IDLE, Ordering::SeqCst);
        drain()
    }
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    W: WaiterInterface<E, Mgmt, Storage>,
> Listener<E> for Waiter<E, Mgmt, Storage, W>
{
    const IS_FILE_DESCRIPTOR_BASED: bool = W::IS_FILE_DESCRIPTOR_BASED;

    fn max_event_count(&self) -> u64 {
        self.storage.get().event.max_event_count()
    }

    fn try_wait<F: FnMut(EventActivation)>(&self, callback: F) -> Result<u64, ListenerWaitError> {
        let msg = "Failed to try wait and acquire all event notifications";
        self.drain_events(msg, callback, || self.waiter.try_wait())
    }

    fn timed_wait<F: FnMut(EventActivation)>(
        &self,
        callback: F,
        timeout: Duration,
    ) -> Result<u64, ListenerWaitError> {
        let msg = "Failed to wait with timeout and acquire all event notifications";
        self.drain_events(msg, callback, || self.waiter.timed_wait(timeout))
    }

    fn blocking_wait<F: FnMut(EventActivation)>(
        &self,
        callback: F,
    ) -> Result<u64, ListenerWaitError> {
        let msg = "Failed to wait with timeout and acquire all event notifications";
        self.drain_events(msg, callback, || self.waiter.blocking_wait())
    }
}

#[derive(Debug)]
pub struct HandleBuilder<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage>,
    W: WaiterInterface<E, Mgmt, Storage>,
> {
    name: FileName,
    config: Configuration<E, Mgmt, Storage>,
    fail_when_buffer_is_full: bool,
    timeout: Duration,
    _data_1: PhantomData<H>,
    _data_2: PhantomData<W>,
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage>,
    W: WaiterInterface<E, Mgmt, Storage>,
> NamedConceptBuilder<EventImpl<E, Mgmt, Storage, H, W>> for HandleBuilder<E, Mgmt, Storage, H, W>
{
    fn new(name: &FileName) -> Self {
        Self {
            name: *name,
            timeout: Duration::ZERO,
            fail_when_buffer_is_full: false,
            config: Configuration::default(),
            _data_1: PhantomData,
            _data_2: PhantomData,
        }
    }

    fn config(
        mut self,
        config: &<EventImpl<E, Mgmt, Storage, H, W> as NamedConceptMgmt>::Configuration,
    ) -> Self {
        self.config = config.clone();
        self
    }
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage>,
    W: WaiterInterface<E, Mgmt, Storage>,
> NotifierBuilder<E, EventImpl<E, Mgmt, Storage, H, W>> for HandleBuilder<E, Mgmt, Storage, H, W>
{
    fn timeout(mut self, timeout: Duration) -> Self {
        self.timeout = timeout;
        self
    }

    fn fail_when_buffer_is_full(mut self, value: bool) -> Self {
        self.fail_when_buffer_is_full = value;
        self
    }

    fn open(
        self,
    ) -> Result<<EventImpl<E, Mgmt, Storage, H, W> as Event<E>>::Notifier, NotifierOpenError> {
        let msg = "Failed to open notifier";
        let storage = match Storage::Builder::new(&self.name)
            .config(&self.config.to_storage_config())
            .has_ownership(false)
            .timeout(self.timeout)
            .open(AccessMode::ReadWrite)
        {
            Ok(storage) => storage,
            Err(DynamicStorageOpenError::DoesNotExist) => {
                fail!(from self, with NotifierOpenError::DoesNotExist,
                    "{msg} since the corresponding listener does not exist.");
            }
            Err(DynamicStorageOpenError::InitializationNotYetFinalized) => {
                fail!(from self, with NotifierOpenError::InitializationNotYetFinalized,
                    "{msg} since the initialization of the listener is not yet finalized.");
            }
            Err(DynamicStorageOpenError::VersionMismatch) => {
                fail!(from self, with NotifierOpenError::VersionMismatch,
                    "{msg} since the iceoryx2 version of the listener does not match.");
            }
            Err(DynamicStorageOpenError::InternalError) => {
                fail!(from self, with NotifierOpenError::InternalFailure,
                    "{msg} due to an internal failure.");
            }
        };

        let handle = H::open(&self.name, &self.config.to_trigger_config(), unsafe {
            storage.get().handle.assume_init_ref()
        })?;

        Ok(Handle {
            storage,
            handle,
            fail_when_buffer_is_full: self.fail_when_buffer_is_full,
            _data_1: PhantomData,
            _data_2: PhantomData,
        })
    }
}

#[derive(Debug)]
pub struct WaiterBuilder<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage>,
    W: WaiterInterface<E, Mgmt, Storage>,
> {
    name: FileName,
    event_id_max: EventId,
    config: Configuration<E, Mgmt, Storage>,
    _data_1: PhantomData<H>,
    _data_2: PhantomData<W>,
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage>,
    W: WaiterInterface<E, Mgmt, Storage>,
> NamedConceptBuilder<EventImpl<E, Mgmt, Storage, H, W>> for WaiterBuilder<E, Mgmt, Storage, H, W>
{
    fn new(name: &FileName) -> Self {
        Self {
            name: *name,
            event_id_max: DEFAULT_MAX_EVENT_ID,
            config: Configuration::default(),
            _data_1: PhantomData,
            _data_2: PhantomData,
        }
    }

    fn config(
        mut self,
        config: &<EventImpl<E, Mgmt, Storage, H, W> as NamedConceptMgmt>::Configuration,
    ) -> Self {
        self.config = config.clone();
        self
    }
}

impl<
    E: EventState,
    Mgmt: ZeroCopySend + Send + Sync + Debug,
    Storage: DynamicStorage<State<E, Mgmt>>,
    H: HandlerInterface<E, Mgmt, Storage>,
    W: WaiterInterface<E, Mgmt, Storage>,
> ListenerBuilder<E, EventImpl<E, Mgmt, Storage, H, W>> for WaiterBuilder<E, Mgmt, Storage, H, W>
{
    fn event_id_max(mut self, id: EventId) -> Self {
        self.event_id_max = id;
        self
    }

    fn create(
        self,
    ) -> Result<<EventImpl<E, Mgmt, Storage, H, W> as Event<E>>::Listener, ListenerCreateError>
    {
        let msg = "Failed to create listener";
        let state_size = E::memory_size(self.event_id_max.as_value() + 1);
        let mut waiter = None;
        let storage = match Storage::Builder::new(&self.name)
            .config(&self.config.to_storage_config())
            .has_ownership(true)
            .supplementary_size(state_size)
            .initializer(|value, allocator| {
                value.write(State {
                    event: unsafe { E::new_uninit(self.event_id_max.as_value() + 1) },
                    handle: MaybeUninit::uninit(),
                    event_id_max: self.event_id_max,
                    notification_state: AtomicU8::new(NOTIFICATION_STATE_IDLE)
                });

                unsafe { value.assume_init_mut().event.init(allocator).unwrap() };
                match W::create(
                    &self.name,
                    &self.config.to_trigger_config(),
                    &mut unsafe { value.assume_init_mut() }.handle,
                ) {
                    Ok(w) => waiter = Some(w),
                    Err(e) => {
                        debug!(from self, "{msg} since the underlying mechanism could not be initialized. [{e:?}]");
                        return false;
                    }
                };

                true
            })
            .create()
        {
            Ok(storage) => storage,
            Err(DynamicStorageCreateError::AlreadyExists) => {
                fail!(from self, with ListenerCreateError::AlreadyExists,
                    "{msg} since it already exists.");
            }
            Err(DynamicStorageCreateError::RootDirectoryCreationFailure,) => {
                fail!(from self, with ListenerCreateError::RootDirectoryCreationFailure,
                    "{msg} since the creation of the underlying iceoryx2 root directory failed.");
            }
            Err(DynamicStorageCreateError::InsufficientPermissions) => {
                fail!(from self, with ListenerCreateError::InsufficientPermissions,
                    "{msg} due to insufficient permissions.");
            }
            Err(DynamicStorageCreateError::InitializationFailed) => {
                fail!(from self, with ListenerCreateError::InternalFailure,
                    "{msg} since the initialization of the underlying waiter failed.");
            }
            Err(DynamicStorageCreateError::InternalError) => {
                fail!(from self, with ListenerCreateError::InternalFailure,
                    "{msg} due to an internal error.");
            }
        };

        Ok(Waiter {
            storage,
            waiter: waiter.unwrap(),
            _data_1: PhantomData,
            _data_2: PhantomData,
        })
    }
}