|
17 | 17 |
|
18 | 18 | use crate::error::{to_rclrs_result, RclReturnCode, RclrsError, ToResult};
|
19 | 19 | use crate::rcl_bindings::*;
|
20 |
| -use crate::Context; |
| 20 | +use crate::{Client, Context, Service, Subscription}; |
21 | 21 |
|
22 | 22 | use std::sync::Arc;
|
23 | 23 | use std::time::Duration;
|
@@ -126,6 +126,60 @@ impl WaitSet {
|
126 | 126 | })
|
127 | 127 | }
|
128 | 128 |
|
| 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 | + |
129 | 183 | /// Removes all entities from the wait set.
|
130 | 184 | ///
|
131 | 185 | /// This effectively resets the wait set to the state it was in after being created by
|
|
0 commit comments