Skip to content

Commit 91952c9

Browse files
committed
Add back the add_subscription() etc. methods to WaitSet
1 parent ddbbca4 commit 91952c9

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

rclrs/src/wait.rs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use crate::error::{to_rclrs_result, RclReturnCode, RclrsError, ToResult};
1919
use crate::rcl_bindings::*;
20-
use crate::Context;
20+
use crate::{Client, Context, Service, Subscription};
2121

2222
use std::sync::Arc;
2323
use std::time::Duration;
@@ -126,6 +126,60 @@ impl WaitSet {
126126
})
127127
}
128128

129+
/// Adds a client to the wait set.
130+
///
131+
/// It is possible, but not useful, to add the same client twice.
132+
///
133+
/// This will return an error if the number of clients in the wait set is larger than the
134+
/// capacity set in [`WaitSet::new`].
135+
///
136+
/// The same client must not be added to multiple wait sets, because that would make it
137+
/// unsafe to simultaneously wait on those wait sets.
138+
pub fn add_client<T: rosidl_runtime_rs::Service>(
139+
&mut self,
140+
client: Arc<Client<T>>,
141+
) -> Result<(), RclrsError> {
142+
// SAFETY: The implementation of this trait for clients checks that the client
143+
// has not already been added to a different wait set.
144+
unsafe { client.add_to_wait_set(self) }
145+
}
146+
147+
/// Adds a service to the wait set.
148+
///
149+
/// It is possible, but not useful, to add the same service twice.
150+
///
151+
/// This will return an error if the number of services in the wait set is larger than the
152+
/// capacity set in [`WaitSet::new`].
153+
///
154+
/// The same service must not be added to multiple wait sets, because that would make it
155+
/// unsafe to simultaneously wait on those wait sets.
156+
pub fn add_service<T: rosidl_runtime_rs::Service>(
157+
&mut self,
158+
service: Arc<Service<T>>,
159+
) -> Result<(), RclrsError> {
160+
// SAFETY: The implementation of this trait for services checks that the service
161+
// has not already been added to a different wait set.
162+
unsafe { service.add_to_wait_set(self) }
163+
}
164+
165+
/// Adds a subscription to the wait set.
166+
///
167+
/// It is possible, but not useful, to add the same subscription twice.
168+
///
169+
/// This will return an error if the number of subscriptions in the wait set is larger than the
170+
/// capacity set in [`WaitSet::new`].
171+
///
172+
/// The same subscription must not be added to multiple wait sets, because that would make it
173+
/// unsafe to simultaneously wait on those wait sets.
174+
pub fn add_subscription<T: rosidl_runtime_rs::Message>(
175+
&mut self,
176+
subscription: Arc<Subscription<T>>,
177+
) -> Result<(), RclrsError> {
178+
// SAFETY: The implementation of this trait for subscriptions checks that the subscription
179+
// has not already been added to a different wait set.
180+
unsafe { subscription.add_to_wait_set(self) }
181+
}
182+
129183
/// Removes all entities from the wait set.
130184
///
131185
/// This effectively resets the wait set to the state it was in after being created by

0 commit comments

Comments
 (0)