Skip to content

Commit 0d1bec0

Browse files
committed
Document the ServerGoalHandle struct
1 parent e70f10a commit 0d1bec0

File tree

1 file changed

+48
-12
lines changed

1 file changed

+48
-12
lines changed

rclrs/src/action/server_goal_handle.rs

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,28 @@ enum GoalStatus {
2323
Aborted = 6,
2424
}
2525

26-
pub struct ServerGoalHandle<T>
26+
/// Handle to interact with goals on a server.
27+
///
28+
/// Use this to check the status of a goal and to set its result.
29+
///
30+
/// This type will only be created by an [`ActionServer`] when a goal is accepted and will be
31+
/// passed to the user in the associated `handle_accepted` callback.
32+
pub struct ServerGoalHandle<ActionT>
2733
where
28-
T: rosidl_runtime_rs::Action,
34+
ActionT: rosidl_runtime_rs::Action,
2935
{
3036
rcl_handle: Arc<Mutex<rcl_action_goal_handle_t>>,
31-
goal_request: Arc<T>,
37+
goal_request: Arc<ActionT::Goal>,
3238
uuid: GoalUuid,
3339
}
3440

35-
impl<T> ServerGoalHandle<T>
41+
impl<ActionT> ServerGoalHandle<ActionT>
3642
where
37-
T: rosidl_runtime_rs::Action,
43+
ActionT: rosidl_runtime_rs::Action,
3844
{
3945
pub(crate) fn new(
4046
rcl_handle: Arc<Mutex<rcl_action_goal_handle_t>>,
41-
goal_request: Arc<T>,
47+
goal_request: Arc<ActionT::Goal>,
4248
uuid: GoalUuid,
4349
) -> Self {
4450
Self {
@@ -86,28 +92,52 @@ where
8692
unsafe { rcl_action_update_goal_state(&mut *rcl_handle, event).ok() }
8793
}
8894

89-
pub fn abort(&self, result: &T::Result) -> Result<(), RclrsError> {
95+
/// Indicate that the goal could not be reached and has been aborted.
96+
///
97+
/// Only call this if the goal is executing but cannot be completed. This is a terminal state,
98+
/// so no more methods may be called on a goal handle after this is called.
99+
///
100+
/// Returns an error if the goal is in any state other than executing.
101+
pub fn abort(&self, result: &ActionT::Result) -> Result<(), RclrsError> {
90102
self.update_state(rcl_action_goal_event_t::GOAL_EVENT_ABORT)?;
91103

92104
// TODO: Invoke on_terminal_state callback
93105
Ok(())
94106
}
95107

96-
pub fn succeed(&self, result: &T::Result) -> Result<(), RclrsError> {
108+
/// Indicate that the goal has succeeded.
109+
///
110+
/// Only call this if the goal is executing and has reached the desired final state. This is a
111+
/// terminal state, so no more methods may be called on a goal handle after this is called.
112+
///
113+
/// Returns an error if the goal is in any state other than executing.
114+
pub fn succeed(&self, result: &ActionT::Result) -> Result<(), RclrsError> {
97115
self.update_state(rcl_action_goal_event_t::GOAL_EVENT_SUCCEED)?;
98116

99117
// TODO: Invoke on_terminal_state callback
100118
Ok(())
101119
}
102120

103-
pub fn canceled(&self, result: &T::Result) -> Result<(), RclrsError> {
121+
/// Indicate that the goal has been cancelled.
122+
///
123+
/// Only call this if the goal is executing or pending, but has been cancelled. This is a
124+
/// terminal state, so no more methods may be called on a goal handle after this is called.
125+
///
126+
/// Returns an error if the goal is in any state other than executing or pending.
127+
pub fn canceled(&self, result: &ActionT::Result) -> Result<(), RclrsError> {
104128
self.update_state(rcl_action_goal_event_t::GOAL_EVENT_CANCELED)?;
105129

106130
// TODO: Invoke on_terminal_state callback
107131
Ok(())
108132
}
109133

110-
pub fn execute(&self, result: &T::Result) -> Result<(), RclrsError> {
134+
/// Indicate that the server is starting to execute the goal.
135+
///
136+
/// Only call this if the goal is pending. This is a terminal state, so no more methods may be
137+
/// called on a goal handle after this is called.
138+
///
139+
/// Returns an error if the goal is in any state other than pending.
140+
pub fn execute(&self, result: &ActionT::Result) -> Result<(), RclrsError> {
111141
self.update_state(rcl_action_goal_event_t::GOAL_EVENT_EXECUTE)?;
112142

113143
// TODO: Invoke on_executing callback
@@ -134,14 +164,20 @@ where
134164
}
135165
}
136166

167+
/// Get the unique identifier of the goal.
137168
pub fn goal_id(&self) -> GoalUuid {
138169
self.uuid
139170
}
171+
172+
/// Get the user-provided message describing the goal.
173+
pub fn goal(&self) -> Arc<ActionT::Goal> {
174+
Arc::clone(&self.goal_request)
175+
}
140176
}
141177

142-
impl<T> Drop for ServerGoalHandle<T>
178+
impl<ActionT> Drop for ServerGoalHandle<ActionT>
143179
where
144-
T: rosidl_runtime_rs::Action,
180+
ActionT: rosidl_runtime_rs::Action,
145181
{
146182
/// Cancel the goal if its handle is dropped without reaching a terminal state.
147183
fn drop(&mut self) {

0 commit comments

Comments
 (0)