@@ -23,22 +23,28 @@ enum GoalStatus {
23
23
Aborted = 6 ,
24
24
}
25
25
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 >
27
33
where
28
- T : rosidl_runtime_rs:: Action ,
34
+ ActionT : rosidl_runtime_rs:: Action ,
29
35
{
30
36
rcl_handle : Arc < Mutex < rcl_action_goal_handle_t > > ,
31
- goal_request : Arc < T > ,
37
+ goal_request : Arc < ActionT :: Goal > ,
32
38
uuid : GoalUuid ,
33
39
}
34
40
35
- impl < T > ServerGoalHandle < T >
41
+ impl < ActionT > ServerGoalHandle < ActionT >
36
42
where
37
- T : rosidl_runtime_rs:: Action ,
43
+ ActionT : rosidl_runtime_rs:: Action ,
38
44
{
39
45
pub ( crate ) fn new (
40
46
rcl_handle : Arc < Mutex < rcl_action_goal_handle_t > > ,
41
- goal_request : Arc < T > ,
47
+ goal_request : Arc < ActionT :: Goal > ,
42
48
uuid : GoalUuid ,
43
49
) -> Self {
44
50
Self {
@@ -86,28 +92,52 @@ where
86
92
unsafe { rcl_action_update_goal_state ( & mut * rcl_handle, event) . ok ( ) }
87
93
}
88
94
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 > {
90
102
self . update_state ( rcl_action_goal_event_t:: GOAL_EVENT_ABORT ) ?;
91
103
92
104
// TODO: Invoke on_terminal_state callback
93
105
Ok ( ( ) )
94
106
}
95
107
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 > {
97
115
self . update_state ( rcl_action_goal_event_t:: GOAL_EVENT_SUCCEED ) ?;
98
116
99
117
// TODO: Invoke on_terminal_state callback
100
118
Ok ( ( ) )
101
119
}
102
120
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 > {
104
128
self . update_state ( rcl_action_goal_event_t:: GOAL_EVENT_CANCELED ) ?;
105
129
106
130
// TODO: Invoke on_terminal_state callback
107
131
Ok ( ( ) )
108
132
}
109
133
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 > {
111
141
self . update_state ( rcl_action_goal_event_t:: GOAL_EVENT_EXECUTE ) ?;
112
142
113
143
// TODO: Invoke on_executing callback
@@ -134,14 +164,20 @@ where
134
164
}
135
165
}
136
166
167
+ /// Get the unique identifier of the goal.
137
168
pub fn goal_id ( & self ) -> GoalUuid {
138
169
self . uuid
139
170
}
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
+ }
140
176
}
141
177
142
- impl < T > Drop for ServerGoalHandle < T >
178
+ impl < ActionT > Drop for ServerGoalHandle < ActionT >
143
179
where
144
- T : rosidl_runtime_rs:: Action ,
180
+ ActionT : rosidl_runtime_rs:: Action ,
145
181
{
146
182
/// Cancel the goal if its handle is dropped without reaching a terminal state.
147
183
fn drop ( & mut self ) {
0 commit comments