|
26 | 26 | //! One example is a sensor that shall send an update every 100ms and the applications requires
|
27 | 27 | //! the sensor data latest after 120ms. If after 120ms an update
|
28 | 28 | //! 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. |
30 | 30 | //! * **Tick** - An interval after which the [`WaitSet`](crate::port::waitset::WaitSet)
|
31 | 31 | //! wakes up and informs the user that the interval time has passed by providing a tick.
|
32 | 32 | //! This is useful when a [`Publisher`](crate::port::publisher::Publisher) shall send an
|
@@ -280,6 +280,25 @@ pub struct AttachmentId<Service: crate::service::Service> {
|
280 | 280 | _data: PhantomData<Service>,
|
281 | 281 | }
|
282 | 282 |
|
| 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 | + |
283 | 302 | impl<Service: crate::service::Service> PartialEq for AttachmentId<Service> {
|
284 | 303 | fn eq(&self, other: &Self) -> bool {
|
285 | 304 | self.attachment_type == other.attachment_type
|
@@ -379,25 +398,6 @@ where
|
379 | 398 | guard_type: GuardType<'waitset, 'attachment, Service>,
|
380 | 399 | }
|
381 | 400 |
|
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 |
| - |
401 | 401 | impl<'waitset, 'attachment, Service: crate::service::Service> Drop
|
402 | 402 | for Guard<'waitset, 'attachment, Service>
|
403 | 403 | {
|
|
0 commit comments