Skip to content

Commit 5c59592

Browse files
committed
Big cleanup
Signed-off-by: Michael X. Grey <[email protected]>
1 parent d395f5f commit 5c59592

File tree

12 files changed

+228
-169
lines changed

12 files changed

+228
-169
lines changed

rclrs/src/client.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::{
1010
error::ToResult,
1111
rcl_bindings::*,
1212
MessageCow, Node, RclrsError, RclReturnCode, Promise, ENTITY_LIFECYCLE_MUTEX,
13-
Executable, QoSProfile, Waitable, WaitableLifecycle,
14-
ExecutableHandle, ExecutableKind, ServiceInfo,
13+
RclPrimitive, QoSProfile, Waitable, WaitableLifecycle,
14+
RclPrimitiveHandle, RclPrimitiveKind, ServiceInfo,
1515
};
1616

1717
mod client_async_callback;
@@ -251,20 +251,20 @@ where
251251
board: Arc<Mutex<ClientRequestBoard<T>>>
252252
}
253253

254-
impl<T> Executable for ClientExecutable<T>
254+
impl<T> RclPrimitive for ClientExecutable<T>
255255
where
256256
T: rosidl_runtime_rs::Service,
257257
{
258258
fn execute(&mut self) -> Result<(), RclrsError> {
259259
self.board.lock().unwrap().execute(&self.handle)
260260
}
261261

262-
fn handle(&self) -> ExecutableHandle {
263-
ExecutableHandle::Client(self.handle.lock())
262+
fn handle(&self) -> RclPrimitiveHandle {
263+
RclPrimitiveHandle::Client(self.handle.lock())
264264
}
265265

266-
fn kind(&self) -> ExecutableKind {
267-
ExecutableKind::Client
266+
fn kind(&self) -> RclPrimitiveKind {
267+
RclPrimitiveKind::Client
268268
}
269269
}
270270

rclrs/src/client/client_async_callback.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ pub trait ClientAsyncCallback<T, Args>: Send + 'static
1313
where
1414
T: Service,
1515
{
16+
/// This represents the type of task (Future) that will be produced by the callback
1617
type Task: Future<Output = ()> + Send;
18+
19+
/// Trigger the callback to run
1720
fn run_client_async_callback(self, response: T::Response, info: ServiceInfo) -> Self::Task;
1821
}
1922

rclrs/src/client/client_callback.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub trait ClientCallback<T, Args>: Send + 'static
1111
where
1212
T: Service,
1313
{
14+
/// Trigger the callback to run
1415
fn run_client_callback(self, response: T::Response, info: ServiceInfo);
1516
}
1617

rclrs/src/client/client_output.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ use crate::{
1313
///
1414
/// Users never need to use this trait directly.
1515
pub trait ClientOutput<Response>: Sized {
16+
/// Create the appropriate type of channel to send the information that the
17+
/// user asked for.
1618
fn create_channel() -> (AnyClientOutputSender<Response>, Promise<Self>);
1719
}
1820

1921
impl<Response: Message> ClientOutput<Response> for Response {
2022
fn create_channel() -> (AnyClientOutputSender<Response>, Promise<Self>) {
2123
let (sender, receiver) = channel();
22-
(AnyClientOutputSender::RequestOnly(sender), receiver)
24+
(AnyClientOutputSender::ResponseOnly(sender), receiver)
2325
}
2426
}
2527

@@ -39,8 +41,11 @@ impl<Response: Message> ClientOutput<Response> for (Response, ServiceInfo) {
3941

4042
/// Can send any kind of response for a client call.
4143
pub enum AnyClientOutputSender<Response> {
42-
RequestOnly(Sender<Response>),
44+
/// The user only asked for the response.
45+
ResponseOnly(Sender<Response>),
46+
/// The user also asked for the RequestId
4347
WithId(Sender<(Response, RequestId)>),
48+
/// The user also asked for the ServiceInfo
4449
WithServiceInfo(Sender<(Response, ServiceInfo)>),
4550
}
4651

@@ -51,17 +56,17 @@ impl<Response: Message> AnyClientOutputSender<Response> {
5156
service_info: rmw_service_info_t,
5257
) {
5358
match self {
54-
Self::RequestOnly(sender) => {
55-
sender.send(response);
59+
Self::ResponseOnly(sender) => {
60+
let _ = sender.send(response);
5661
}
5762
Self::WithId(sender) => {
58-
sender.send((
63+
let _ = sender.send((
5964
response,
6065
RequestId::from_rmw_request_id(&service_info.request_id),
6166
));
6267
}
6368
Self::WithServiceInfo(sender) => {
64-
sender.send((
69+
let _ = sender.send((
6570
response,
6671
ServiceInfo::from_rmw_service_info(&service_info),
6772
));

rclrs/src/executor/basic_executor.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
use futures::{
2-
future::{BoxFuture, FutureExt},
2+
future::BoxFuture,
33
task::{waker_ref, ArcWake},
44
channel::{oneshot, mpsc::UnboundedSender},
55
};
66
use std::{
7-
future::Future,
87
sync::{
98
mpsc::{Sender, Receiver, channel},
109
atomic::{AtomicBool, Ordering},
1110
Arc, Mutex,
1211
},
1312
task::Context as TaskContext,
14-
time::Duration,
1513
};
1614

1715
use crate::{

rclrs/src/service.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
error::ToResult,
99
rcl_bindings::*,
1010
NodeHandle, RclrsError, Waitable, WaitableLifecycle, QoSProfile,
11-
Executable, ExecutableKind, ExecutableHandle, ENTITY_LIFECYCLE_MUTEX, ExecutorCommands,
11+
RclPrimitive, RclPrimitiveKind, RclPrimitiveHandle, ENTITY_LIFECYCLE_MUTEX, ExecutorCommands,
1212
};
1313

1414
mod any_service_callback;
@@ -44,6 +44,7 @@ where
4444
callback: Arc<Mutex<AnyServiceCallback<T>>>,
4545
/// Holding onto this keeps the waiter for this service alive in the wait
4646
/// set of the executor.
47+
#[allow(unused)]
4748
lifecycle: WaitableLifecycle,
4849
}
4950

@@ -162,7 +163,7 @@ struct ServiceExecutable<T: rosidl_runtime_rs::Service> {
162163
commands: Arc<ExecutorCommands>,
163164
}
164165

165-
impl<T> Executable for ServiceExecutable<T>
166+
impl<T> RclPrimitive for ServiceExecutable<T>
166167
where
167168
T: rosidl_runtime_rs::Service,
168169
{
@@ -174,12 +175,12 @@ where
174175
Ok(())
175176
}
176177

177-
fn kind(&self) -> crate::ExecutableKind {
178-
ExecutableKind::Service
178+
fn kind(&self) -> crate::RclPrimitiveKind {
179+
RclPrimitiveKind::Service
179180
}
180181

181-
fn handle(&self) -> ExecutableHandle {
182-
ExecutableHandle::Service(self.handle.lock())
182+
fn handle(&self) -> RclPrimitiveHandle {
183+
RclPrimitiveHandle::Service(self.handle.lock())
183184
}
184185
}
185186

rclrs/src/subscription.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::{
99
error::ToResult,
1010
qos::QoSProfile,
1111
rcl_bindings::*,
12-
ExecutorCommands, NodeHandle, RclrsError, Waitable, Executable, ExecutableHandle,
13-
ExecutableKind, WaitableLifecycle, ENTITY_LIFECYCLE_MUTEX,
12+
ExecutorCommands, NodeHandle, RclrsError, Waitable, RclPrimitive, RclPrimitiveHandle,
13+
RclPrimitiveKind, WaitableLifecycle, ENTITY_LIFECYCLE_MUTEX,
1414
};
1515

1616
mod any_subscription_callback;
@@ -57,6 +57,7 @@ where
5757
callback: Arc<Mutex<AnySubscriptionCallback<T>>>,
5858
/// Holding onto this keeps the waiter for this subscription alive in the
5959
/// wait set of the executor.
60+
#[allow(unused)]
6061
lifecycle: WaitableLifecycle,
6162
}
6263

@@ -172,20 +173,20 @@ struct SubscriptionExecutable<T: Message> {
172173
commands: Arc<ExecutorCommands>,
173174
}
174175

175-
impl<T> Executable for SubscriptionExecutable<T>
176+
impl<T> RclPrimitive for SubscriptionExecutable<T>
176177
where
177178
T: Message,
178179
{
179180
fn execute(&mut self) -> Result<(), RclrsError> {
180181
self.callback.lock().unwrap().execute(&self.handle, &self.commands)
181182
}
182183

183-
fn kind(&self) -> crate::ExecutableKind {
184-
ExecutableKind::Subscription
184+
fn kind(&self) -> crate::RclPrimitiveKind {
185+
RclPrimitiveKind::Subscription
185186
}
186187

187-
fn handle(&self) -> ExecutableHandle {
188-
ExecutableHandle::Subscription(self.handle.lock())
188+
fn handle(&self) -> RclPrimitiveHandle {
189+
RclPrimitiveHandle::Subscription(self.handle.lock())
189190
}
190191
}
191192

rclrs/src/subscription/any_subscription_callback.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,27 @@ impl<T: Message> AnySubscriptionCallback<T> {
5050
match self {
5151
AnySubscriptionCallback::Regular(cb) => {
5252
let (msg, _) = Self::take(handle)?;
53-
commands.run(cb(msg));
53+
let _ = commands.run(cb(msg));
5454
}
5555
AnySubscriptionCallback::RegularWithMessageInfo(cb) => {
5656
let (msg, msg_info) = Self::take(handle)?;
57-
commands.run(cb(msg, msg_info));
57+
let _ = commands.run(cb(msg, msg_info));
5858
}
5959
AnySubscriptionCallback::Boxed(cb) => {
6060
let (msg, _) = Self::take_boxed(handle)?;
61-
commands.run(cb(msg));
61+
let _ = commands.run(cb(msg));
6262
}
6363
AnySubscriptionCallback::BoxedWithMessageInfo(cb) => {
6464
let (msg, msg_info) = Self::take_boxed(handle)?;
65-
commands.run(cb(msg, msg_info));
65+
let _ = commands.run(cb(msg, msg_info));
6666
}
6767
AnySubscriptionCallback::Loaned(cb) => {
6868
let (msg, _) = Self::take_loaned(handle)?;
69-
commands.run(cb(msg));
69+
let _ = commands.run(cb(msg));
7070
}
7171
AnySubscriptionCallback::LoanedWithMessageInfo(cb) => {
7272
let (msg, msg_info) = Self::take_loaned(handle)?;
73-
commands.run(cb(msg, msg_info));
73+
let _ = commands.run(cb(msg, msg_info));
7474
}
7575
}
7676
Ok(())

rclrs/src/wait_set.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ use crate::{
2626
mod guard_condition;
2727
pub use guard_condition::*;
2828

29+
mod rcl_primitive;
30+
pub use rcl_primitive::*;
31+
2932
mod waitable;
3033
pub use waitable::*;
3134

@@ -34,7 +37,7 @@ pub use wait_set_runner::*;
3437

3538
/// A struct for waiting on subscriptions and other waitable entities to become ready.
3639
pub struct WaitSet {
37-
primitives: HashMap<ExecutableKind, Vec<Waitable>>,
40+
primitives: HashMap<RclPrimitiveKind, Vec<Waitable>>,
3841
handle: WaitSetHandle,
3942
}
4043

@@ -70,7 +73,7 @@ impl WaitSet {
7073
if entity.in_wait_set() {
7174
return Err(RclrsError::AlreadyAddedToWaitSet);
7275
}
73-
let kind = entity.executable.kind();
76+
let kind = entity.primitive.kind();
7477
self.primitives.entry(kind).or_default().push(entity);
7578
}
7679
self.resize_rcl_containers()?;
@@ -116,7 +119,7 @@ impl WaitSet {
116119
pub fn wait(
117120
&mut self,
118121
timeout: Option<Duration>,
119-
mut f: impl FnMut(&mut dyn Executable) -> Result<(), RclrsError>,
122+
mut f: impl FnMut(&mut dyn RclPrimitive) -> Result<(), RclrsError>,
120123
) -> Result<(), RclrsError> {
121124
let timeout_ns = match timeout.map(|d| d.as_nanos()) {
122125
None => -1,
@@ -153,7 +156,7 @@ impl WaitSet {
153156
// the callback for those that were.
154157
for waiter in self.primitives.values_mut().flat_map(|v| v) {
155158
if waiter.is_ready(&self.handle.rcl_wait_set) {
156-
f(&mut *waiter.executable)?;
159+
f(&mut *waiter.primitive)?;
157160
}
158161
}
159162

rclrs/src/wait_set/guard_condition.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::{
55

66
use crate::{
77
rcl_bindings::*,
8-
ContextHandle, RclrsError, ToResult, WaitableLifecycle, Executable,
9-
Waitable, ExecutableKind, ExecutableHandle,
8+
ContextHandle, RclrsError, ToResult, WaitableLifecycle, RclPrimitive,
9+
Waitable, RclPrimitiveKind, RclPrimitiveHandle,
1010
};
1111

1212
/// A waitable entity used for waking up a wait set manually.
@@ -135,28 +135,41 @@ struct GuardConditionHandle {
135135
/// from rcl and either have static lifetimes or lifetimes that depend on
136136
/// something else.
137137
pub enum InnerGuardConditionHandle {
138+
/// This variant means the guard condition was created and owned by rclrs.
139+
/// Its memory is managed by us.
138140
Owned(rcl_guard_condition_t),
141+
/// This variant means the guard condition was created and owned by rcl.
142+
/// The owner object represents something that the lifecycle of the guard
143+
/// condition depends on, such as the rcl_node that created it.
139144
Unowned {
145+
/// This is the unowned guard condition pointer. We must not deallocate
146+
/// it.
140147
handle: *const rcl_guard_condition_t,
148+
/// This somehow holds a shared reference to the owner of the guard
149+
/// condition. We need to hold onto this to ensure the guard condition
150+
/// remains valid.
141151
owner: Box<dyn Any>,
142152
},
143153
}
144154

145155
impl InnerGuardConditionHandle {
156+
/// Get the handle if it is owned by rclrs
146157
pub fn owned(&self) -> Option<&rcl_guard_condition_t> {
147158
match self {
148159
Self::Owned(handle) => Some(handle),
149160
_ => None,
150161
}
151162
}
152163

164+
/// Get the handle if it is owned by rclrs
153165
pub fn owned_mut(&mut self) -> Option<&mut rcl_guard_condition_t> {
154166
match self {
155167
Self::Owned(handle) => Some(handle),
156168
_ => None,
157169
}
158170
}
159171

172+
/// Apply a function to the handle
160173
pub fn use_handle<Out>(&self, f: impl FnOnce(&rcl_guard_condition_t) -> Out) -> Out {
161174
match self {
162175
Self::Owned(handle) => f(handle),
@@ -191,20 +204,20 @@ struct GuardConditionExecutable {
191204
callback: Option<Box<dyn FnMut() + Send + Sync>>,
192205
}
193206

194-
impl Executable for GuardConditionExecutable {
207+
impl RclPrimitive for GuardConditionExecutable {
195208
fn execute(&mut self) -> Result<(), RclrsError> {
196209
if let Some(callback) = &mut self.callback {
197210
callback();
198211
}
199212
Ok(())
200213
}
201214

202-
fn kind(&self) -> ExecutableKind {
203-
ExecutableKind::GuardCondition
215+
fn kind(&self) -> RclPrimitiveKind {
216+
RclPrimitiveKind::GuardCondition
204217
}
205218

206-
fn handle(&self) -> ExecutableHandle {
207-
ExecutableHandle::GuardCondition(
219+
fn handle(&self) -> RclPrimitiveHandle {
220+
RclPrimitiveHandle::GuardCondition(
208221
self.handle.rcl_guard_condition.lock().unwrap()
209222
)
210223
}

0 commit comments

Comments
 (0)