Skip to content

Commit d3497a3

Browse files
committed
Introduce ServiceWaitable/ClientWaitable/SubscriptionWaitable
1 parent 00f0d5b commit d3497a3

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

rclrs/src/node.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub use self::service::*;
1010
pub use self::subscription::*;
1111

1212
use crate::rcl_bindings::*;
13-
use crate::{Context, ParameterOverrideMap, QoSProfile, RclrsError, ToResult, Waitable};
13+
use crate::{Context, ParameterOverrideMap, QoSProfile, RclrsError, ToResult};
1414

1515
use std::cmp::PartialEq;
1616
use std::ffi::CStr;
@@ -72,9 +72,9 @@ unsafe impl Send for rcl_node_t {}
7272
pub struct Node {
7373
rcl_node_mtx: Arc<Mutex<rcl_node_t>>,
7474
pub(crate) rcl_context_mtx: Arc<Mutex<rcl_context_t>>,
75-
pub(crate) clients: Vec<Weak<dyn Waitable>>,
76-
pub(crate) services: Vec<Weak<dyn Waitable>>,
77-
pub(crate) subscriptions: Vec<Weak<dyn Waitable>>,
75+
pub(crate) clients: Vec<Weak<dyn ClientWaitable>>,
76+
pub(crate) services: Vec<Weak<dyn ServiceWaitable>>,
77+
pub(crate) subscriptions: Vec<Weak<dyn SubscriptionWaitable>>,
7878
_parameter_map: ParameterOverrideMap,
7979
}
8080

@@ -193,7 +193,7 @@ impl Node {
193193
{
194194
let client = Arc::new(crate::node::client::Client::<T>::new(self, topic)?);
195195
self.clients
196-
.push(Arc::downgrade(&client) as Weak<dyn Waitable>);
196+
.push(Arc::downgrade(&client) as Weak<dyn ClientWaitable>);
197197
Ok(client)
198198
}
199199

@@ -229,7 +229,7 @@ impl Node {
229229
self, topic, callback,
230230
)?);
231231
self.services
232-
.push(Arc::downgrade(&service) as Weak<dyn Waitable>);
232+
.push(Arc::downgrade(&service) as Weak<dyn ServiceWaitable>);
233233
Ok(service)
234234
}
235235

@@ -249,23 +249,23 @@ impl Node {
249249
{
250250
let subscription = Arc::new(Subscription::<T>::new(self, topic, qos, callback)?);
251251
self.subscriptions
252-
.push(Arc::downgrade(&subscription) as Weak<dyn Waitable>);
252+
.push(Arc::downgrade(&subscription) as Weak<dyn SubscriptionWaitable>);
253253
Ok(subscription)
254254
}
255255

256256
/// Returns the subscriptions that have not been dropped yet.
257-
pub(crate) fn live_subscriptions(&self) -> Vec<Arc<dyn Waitable>> {
257+
pub(crate) fn live_subscriptions(&self) -> Vec<Arc<dyn SubscriptionWaitable>> {
258258
self.subscriptions
259259
.iter()
260260
.filter_map(Weak::upgrade)
261261
.collect()
262262
}
263263

264-
pub(crate) fn live_clients(&self) -> Vec<Arc<dyn Waitable>> {
264+
pub(crate) fn live_clients(&self) -> Vec<Arc<dyn ClientWaitable>> {
265265
self.clients.iter().filter_map(Weak::upgrade).collect()
266266
}
267267

268-
pub(crate) fn live_services(&self) -> Vec<Arc<dyn Waitable>> {
268+
pub(crate) fn live_services(&self) -> Vec<Arc<dyn ServiceWaitable>> {
269269
self.services.iter().filter_map(Weak::upgrade).collect()
270270
}
271271

rclrs/src/node/client.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ where
8585
}
8686
}
8787

88+
/// A marker trait to distinguish `Client` waitables from other [`Waitable`]s.
89+
pub(crate) trait ClientWaitable: Waitable {}
90+
91+
impl<T> ClientWaitable for Client<T> where T: rosidl_runtime_rs::Service {}
92+
8893
impl<T> Client<T>
8994
where
9095
T: rosidl_runtime_rs::Service,

rclrs/src/node/service.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ where
8989
}
9090
}
9191

92+
/// A marker trait to distinguish `Service` waitables from other [`Waitable`]s.
93+
pub(crate) trait ServiceWaitable: Waitable {}
94+
95+
impl<T> ServiceWaitable for Service<T> where T: rosidl_runtime_rs::Service {}
96+
9297
impl<T> Service<T>
9398
where
9499
T: rosidl_runtime_rs::Service,

rclrs/src/node/subscription.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ where
8585
}
8686
}
8787

88+
/// A marker trait to distinguish `Subscription` waitables from other [`Waitable`]s.
89+
pub(crate) trait SubscriptionWaitable: Waitable {}
90+
91+
impl<T> SubscriptionWaitable for Subscription<T> where T: Message {}
92+
8893
impl<T> Subscription<T>
8994
where
9095
T: Message,

0 commit comments

Comments
 (0)