Refactor server goal handle's try_canceling() function (#603)
Makes use of rcl_action_goal_handle_is_cancelable() for one less rcl_action call.
This commit is contained in:
parent
22abd62e31
commit
5c92811739
1 changed files with 6 additions and 17 deletions
|
@ -111,30 +111,19 @@ bool
|
||||||
ServerGoalHandleBase::try_canceling() noexcept
|
ServerGoalHandleBase::try_canceling() noexcept
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(rcl_handle_mutex_);
|
std::lock_guard<std::mutex> lock(rcl_handle_mutex_);
|
||||||
// Check if the goal reached a terminal state already
|
|
||||||
const bool active = rcl_action_goal_handle_is_active(rcl_handle_.get());
|
|
||||||
if (!active) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
rcl_ret_t ret;
|
rcl_ret_t ret;
|
||||||
|
// Check if the goal is cancelable
|
||||||
// Get the current state
|
const bool is_cancelable = rcl_action_goal_handle_is_cancelable(rcl_handle_.get());
|
||||||
rcl_action_goal_state_t state = GOAL_STATE_UNKNOWN;
|
if (is_cancelable) {
|
||||||
ret = rcl_action_goal_handle_get_status(rcl_handle_.get(), &state);
|
// Transition to CANCELING
|
||||||
if (RCL_RET_OK != ret) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it's not already canceling then transition to that state
|
|
||||||
if (GOAL_STATE_CANCELING != state) {
|
|
||||||
ret = rcl_action_update_goal_state(rcl_handle_.get(), GOAL_EVENT_CANCEL);
|
ret = rcl_action_update_goal_state(rcl_handle_.get(), GOAL_EVENT_CANCEL);
|
||||||
if (RCL_RET_OK != ret) {
|
if (RCL_RET_OK != ret) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the state again
|
rcl_action_goal_state_t state = GOAL_STATE_UNKNOWN;
|
||||||
|
// Get the current state
|
||||||
ret = rcl_action_goal_handle_get_status(rcl_handle_.get(), &state);
|
ret = rcl_action_goal_handle_get_status(rcl_handle_.get(), &state);
|
||||||
if (RCL_RET_OK != ret) {
|
if (RCL_RET_OK != ret) {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue