|
24 | 24 |
|
25 | 25 | #include "action_msgs/msg/goal_status.hpp" |
26 | 26 |
|
| 27 | +#include "rclcpp/logging.hpp" |
| 28 | + |
27 | 29 | #include "rclcpp_action/visibility_control.hpp" |
28 | 30 | #include "rclcpp_action/types.hpp" |
29 | 31 |
|
@@ -103,11 +105,19 @@ class ServerGoalHandleBase |
103 | 105 | _execute(); |
104 | 106 |
|
105 | 107 | /// Transition the goal to canceled state if it never reached a terminal state. |
| 108 | + /// Returns true if transitioned to canceled, else false. |
106 | 109 | /// \internal |
107 | 110 | RCLCPP_ACTION_PUBLIC |
108 | 111 | bool |
109 | 112 | try_canceling() noexcept; |
110 | 113 |
|
| 114 | + /// Transition the goal to aborted state if it never reached a terminal state. |
| 115 | + /// Returns true if transitioned to aborted, else false. |
| 116 | + /// \internal |
| 117 | + RCLCPP_ACTION_PUBLIC |
| 118 | + bool |
| 119 | + try_aborting() noexcept; |
| 120 | + |
111 | 121 | // End API for communication between ServerGoalHandleBase and ServerGoalHandle<> |
112 | 122 | // ----------------------------------------------------------------------------- |
113 | 123 |
|
@@ -243,11 +253,22 @@ class ServerGoalHandle : public ServerGoalHandleBase |
243 | 253 |
|
244 | 254 | virtual ~ServerGoalHandle() |
245 | 255 | { |
246 | | - // Cancel goal if handle was allowed to destruct without reaching a terminal state |
247 | | - if (try_canceling()) { |
248 | | - auto null_result = std::make_shared<typename ActionT::Impl::GetResultService::Response>(); |
249 | | - null_result->status = action_msgs::msg::GoalStatus::STATUS_CANCELED; |
250 | | - on_terminal_state_(uuid_, null_result); |
| 256 | + try { |
| 257 | + // Abort goal if handle was allowed to destruct without reaching a terminal state |
| 258 | + if (try_aborting()) { |
| 259 | + auto null_result = std::make_shared<typename ActionT::Impl::GetResultService::Response>(); |
| 260 | + null_result->status = action_msgs::msg::GoalStatus::STATUS_ABORTED; |
| 261 | + on_terminal_state_(uuid_, null_result); |
| 262 | + } else if (try_canceling()) { |
| 263 | + // Cancel goal if handle was allowed to destruct without reaching a terminal state |
| 264 | + auto null_result = std::make_shared<typename ActionT::Impl::GetResultService::Response>(); |
| 265 | + null_result->status = action_msgs::msg::GoalStatus::STATUS_CANCELED; |
| 266 | + on_terminal_state_(uuid_, null_result); |
| 267 | + } |
| 268 | + } catch (const std::exception & ex) { |
| 269 | + RCLCPP_DEBUG( |
| 270 | + rclcpp::get_logger("rclcpp_action"), |
| 271 | + "Failed to abort/cancel goal handler in destructor: %s", ex.what()); |
251 | 272 | } |
252 | 273 | } |
253 | 274 |
|
|
0 commit comments