Skip to content

Commit 0d8fdc0

Browse files
committed
Implement goal expiration in action server
1 parent 410de38 commit 0d8fdc0

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

rclrs/src/action/server.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,32 @@ where
298298
}
299299

300300
fn execute_goal_expired(&self) -> Result<(), RclrsError> {
301-
todo!()
301+
// We assume here that only one goal expires at a time. If not, the only consequence is
302+
// that we'll call rcl_action_expire_goals() more than necessary.
303+
304+
// SAFETY: No preconditions
305+
let mut expired_goal = unsafe { rcl_action_get_zero_initialized_goal_info() };
306+
let mut num_expired = 1;
307+
308+
loop {
309+
unsafe {
310+
// SAFETY: The action server is locked through the handle. The `expired_goal`
311+
// argument points to an array of one rcl_action_goal_info_t and num_expired points
312+
// to a `size_t`.
313+
rcl_action_expire_goals(&*self.handle.lock(), &mut expired_goal, 1, &mut num_expired)
314+
}
315+
.ok()?;
316+
317+
if num_expired > 0 {
318+
// Clean up the expired goal.
319+
let uuid = GoalUuid(expired_goal.goal_id.uuid);
320+
self.goal_handles.lock().unwrap().remove(&uuid);
321+
} else {
322+
break
323+
}
324+
}
325+
326+
Ok(())
302327
}
303328

304329
fn publish_status(&self) -> Result<(), RclrsError> {

0 commit comments

Comments
 (0)