Skip to content

Commit e70f10a

Browse files
committed
Make GoalUuid into a newtype
1 parent 16363a9 commit e70f10a

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

rclrs/src/action.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,37 @@ mod server;
33
mod server_goal_handle;
44

55
use crate::rcl_bindings::RCL_ACTION_UUID_SIZE;
6+
use std::fmt;
67

78
pub use client::{ActionClient, ActionClientBase};
89
pub use server::{ActionServer, ActionServerBase};
910
pub use server_goal_handle::ServerGoalHandle;
1011

11-
pub type GoalUUID = [u8; RCL_ACTION_UUID_SIZE];
12+
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
13+
pub struct GoalUuid(pub [u8; RCL_ACTION_UUID_SIZE]);
14+
15+
impl fmt::Display for GoalUuid {
16+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
17+
write!(f, "{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
18+
self.0[0],
19+
self.0[1],
20+
self.0[2],
21+
self.0[3],
22+
self.0[4],
23+
self.0[5],
24+
self.0[6],
25+
self.0[7],
26+
self.0[8],
27+
self.0[9],
28+
self.0[10],
29+
self.0[11],
30+
self.0[12],
31+
self.0[13],
32+
self.0[14],
33+
self.0[15],
34+
)
35+
}
36+
}
1237

1338
pub enum GoalResponse {
1439
Reject = 1,

rclrs/src/action/server_goal_handle.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{rcl_bindings::*, RclrsError, ToResult};
1+
use crate::{rcl_bindings::*, GoalUuid, RclrsError, ToResult};
22
use std::{
33
marker::PhantomData,
44
sync::{Arc, Mutex},
@@ -29,16 +29,22 @@ where
2929
{
3030
rcl_handle: Arc<Mutex<rcl_action_goal_handle_t>>,
3131
goal_request: Arc<T>,
32+
uuid: GoalUuid,
3233
}
3334

3435
impl<T> ServerGoalHandle<T>
3536
where
3637
T: rosidl_runtime_rs::Action,
3738
{
38-
pub fn new(rcl_handle: Arc<Mutex<rcl_action_goal_handle_t>>, goal_request: Arc<T>) -> Self {
39+
pub(crate) fn new(
40+
rcl_handle: Arc<Mutex<rcl_action_goal_handle_t>>,
41+
goal_request: Arc<T>,
42+
uuid: GoalUuid,
43+
) -> Self {
3944
Self {
4045
rcl_handle,
4146
goal_request: Arc::clone(&goal_request),
47+
uuid,
4248
}
4349
}
4450

@@ -127,6 +133,10 @@ where
127133
Ok(false)
128134
}
129135
}
136+
137+
pub fn goal_id(&self) -> GoalUuid {
138+
self.uuid
139+
}
130140
}
131141

132142
impl<T> Drop for ServerGoalHandle<T>

rclrs/src/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rosidl_runtime_rs::Message;
1414
pub use self::{builder::*, graph::*};
1515
use crate::{
1616
rcl_bindings::*, ActionClient, ActionServer, CancelResponse, Client, ClientBase, Clock,
17-
Context, ContextHandle, GoalResponse, GoalUUID, GuardCondition, ParameterBuilder,
17+
Context, ContextHandle, GoalResponse, GoalUuid, GuardCondition, ParameterBuilder,
1818
ParameterInterface, ParameterVariant, Parameters, Publisher, QoSProfile, RclrsError,
1919
ServerGoalHandle, Service, ServiceBase, Subscription, SubscriptionBase, SubscriptionCallback,
2020
TimeSource, ENTITY_LIFECYCLE_MUTEX,
@@ -232,7 +232,7 @@ impl Node {
232232
pub fn create_action_server<T>(
233233
&mut self,
234234
topic: &str,
235-
handle_goal: fn(&crate::action::GoalUUID, Arc<T::Goal>) -> GoalResponse,
235+
handle_goal: fn(&crate::action::GoalUuid, Arc<T::Goal>) -> GoalResponse,
236236
handle_cancel: fn(Arc<ServerGoalHandle<T>>) -> CancelResponse,
237237
handle_accepted: fn(Arc<ServerGoalHandle<T>>),
238238
) -> Result<Arc<ActionServer<T>>, RclrsError>

0 commit comments

Comments
 (0)