Skip to content

Commit 5904a48

Browse files
committed
[#390] Address review comments
1 parent 3a93052 commit 5904a48

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

examples/rust/event_multiplexing/wait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4646
// attach all listeners to the waitset and store the guard
4747
for (service, listener) in &listeners {
4848
let guard = waitset.attach_notification(listener)?;
49-
listener_attachments.insert(guard.to_attachment_id(), (service, listener));
49+
listener_attachments.insert(AttachmentId::from_guard(&guard), (service, listener));
5050
guards.push(guard);
5151
}
5252

iceoryx2-bb/posix/tests/file_descriptor_set_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn file_descriptor_set_timed_wait_works() {
156156
}
157157

158158
#[test]
159-
fn file_descriptor_set_blocking_wait_works() {
159+
fn file_descriptor_set_blocking_wait_immediately_returns_notifications() {
160160
let socket_name = generate_socket_name();
161161

162162
let sut_receiver = UnixDatagramReceiverBuilder::new(&socket_name)

iceoryx2/src/port/waitset.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//! One example is a sensor that shall send an update every 100ms and the applications requires
2727
//! the sensor data latest after 120ms. If after 120ms an update
2828
//! is not available the application must wake up and take counter measures. If the update
29-
//! arrives already after 78ms, the timeout is reset back to 120ms.
29+
//! arrives within the timeout, the timeout is reset back to 120ms.
3030
//! * **Tick** - An interval after which the [`WaitSet`](crate::port::waitset::WaitSet)
3131
//! wakes up and informs the user that the interval time has passed by providing a tick.
3232
//! This is useful when a [`Publisher`](crate::port::publisher::Publisher) shall send an
@@ -164,8 +164,8 @@
164164
//! // attach all listeners to the waitset
165165
//! let guard_1 = waitset.attach_notification(&listener_1)?;
166166
//! let guard_2 = waitset.attach_notification(&listener_2)?;
167-
//! listeners.insert(guard_1.to_attachment_id(), &listener_1);
168-
//! listeners.insert(guard_2.to_attachment_id(), &listener_2);
167+
//! listeners.insert(AttachmentId::from_guard(&guard_1), &listener_1);
168+
//! listeners.insert(AttachmentId::from_guard(&guard_2), &listener_2);
169169
//!
170170
//! let on_event = |attachment_id| {
171171
//! if let Some(listener) = listeners.get(&attachment_id) {
@@ -280,6 +280,25 @@ pub struct AttachmentId<Service: crate::service::Service> {
280280
_data: PhantomData<Service>,
281281
}
282282

283+
impl<Service: crate::service::Service> AttachmentId<Service> {
284+
/// Creates an [`AttachmentId`] from a [`Guard`] that was returned via
285+
/// [`WaitSet::attach_interval()`], [`WaitSet::attach_notification()`] or
286+
/// [`WaitSet::attach_deadline()`].
287+
pub fn from_guard(guard: &Guard<Service>) -> Self {
288+
match &guard.guard_type {
289+
GuardType::Tick(t) => AttachmentId::tick(guard.waitset, t.index()),
290+
GuardType::Deadline(r, t) => AttachmentId::deadline(
291+
guard.waitset,
292+
unsafe { r.file_descriptor().native_handle() },
293+
t.index(),
294+
),
295+
GuardType::Notification(r) => AttachmentId::notification(guard.waitset, unsafe {
296+
r.file_descriptor().native_handle()
297+
}),
298+
}
299+
}
300+
}
301+
283302
impl<Service: crate::service::Service> PartialEq for AttachmentId<Service> {
284303
fn eq(&self, other: &Self) -> bool {
285304
self.attachment_type == other.attachment_type
@@ -333,7 +352,7 @@ impl<Service: crate::service::Service> AttachmentId<Service> {
333352
/// Returns true if an event was emitted from a notification or deadline attachment
334353
/// corresponding to [`Guard`].
335354
pub fn event_from(&self, other: &Guard<Service>) -> bool {
336-
let other_attachment = other.to_attachment_id();
355+
let other_attachment = AttachmentId::from_guard(other);
337356
if let AttachmentIdType::Deadline(other_waitset, other_reactor_idx, _) =
338357
other_attachment.attachment_type
339358
{
@@ -350,7 +369,7 @@ impl<Service: crate::service::Service> AttachmentId<Service> {
350369
/// Returns true if the deadline for the attachment corresponding to [`Guard`] was missed.
351370
pub fn deadline_from(&self, other: &Guard<Service>) -> bool {
352371
if let AttachmentIdType::Deadline(..) = self.attachment_type {
353-
self.attachment_type == other.to_attachment_id().attachment_type
372+
self.attachment_type == AttachmentId::from_guard(other).attachment_type
354373
} else {
355374
false
356375
}
@@ -379,25 +398,6 @@ where
379398
guard_type: GuardType<'waitset, 'attachment, Service>,
380399
}
381400

382-
impl<'waitset, 'attachment, Service: crate::service::Service>
383-
Guard<'waitset, 'attachment, Service>
384-
{
385-
/// Extracts the [`AttachmentId`] from the guard.
386-
pub fn to_attachment_id(&self) -> AttachmentId<Service> {
387-
match &self.guard_type {
388-
GuardType::Tick(t) => AttachmentId::tick(self.waitset, t.index()),
389-
GuardType::Deadline(r, t) => AttachmentId::deadline(
390-
self.waitset,
391-
unsafe { r.file_descriptor().native_handle() },
392-
t.index(),
393-
),
394-
GuardType::Notification(r) => AttachmentId::notification(self.waitset, unsafe {
395-
r.file_descriptor().native_handle()
396-
}),
397-
}
398-
}
399-
}
400-
401401
impl<'waitset, 'attachment, Service: crate::service::Service> Drop
402402
for Guard<'waitset, 'attachment, Service>
403403
{

0 commit comments

Comments
 (0)