rclcpp_action  master
C++ ROS Action Client Library
client_goal_handle_impl.hpp
Go to the documentation of this file.
1 // Copyright 2018 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCLCPP_ACTION__CLIENT_GOAL_HANDLE_IMPL_HPP_
16 #define RCLCPP_ACTION__CLIENT_GOAL_HANDLE_IMPL_HPP_
17 
18 #include <rcl_action/types.h>
19 
20 #include <memory>
21 
22 #include "rclcpp/logging.hpp"
25 
26 namespace rclcpp_action
27 {
28 
29 template<typename ActionT>
30 ClientGoalHandle<ActionT>::ClientGoalHandle(
31  const GoalInfo & info, FeedbackCallback callback)
32 : info_(info), result_future_(result_promise_.get_future()), feedback_callback_(callback)
33 {
34 }
35 
36 template<typename ActionT>
38 {
39 }
40 
41 template<typename ActionT>
42 const GoalID &
44 {
45  // return info_.goal_id;
46  return info_.goal_id.uuid;
47 }
48 
49 template<typename ActionT>
52 {
53  return info_.stamp;
54 }
55 
56 template<typename ActionT>
59 {
60  std::lock_guard<std::mutex> guard(handle_mutex_);
61  if (!is_result_aware_) {
63  }
64  return result_future_;
65 }
66 
67 template<typename ActionT>
68 void
70 {
71  std::lock_guard<std::mutex> guard(handle_mutex_);
72  status_ = static_cast<int8_t>(result.code);
73  result_promise_.set_value(result);
74 }
75 
76 template<typename ActionT>
77 void
79 {
80  std::lock_guard<std::mutex> guard(handle_mutex_);
81  feedback_callback_ = callback;
82 }
83 
84 template<typename ActionT>
85 int8_t
87 {
88  std::lock_guard<std::mutex> guard(handle_mutex_);
89  return status_;
90 }
91 
92 template<typename ActionT>
93 void
95 {
96  std::lock_guard<std::mutex> guard(handle_mutex_);
97  status_ = status;
98 }
99 
100 template<typename ActionT>
101 bool
103 {
104  std::lock_guard<std::mutex> guard(handle_mutex_);
105  return feedback_callback_ != nullptr;
106 }
107 
108 template<typename ActionT>
109 bool
111 {
112  std::lock_guard<std::mutex> guard(handle_mutex_);
113  return is_result_aware_;
114 }
115 
116 template<typename ActionT>
117 void
119 {
120  std::lock_guard<std::mutex> guard(handle_mutex_);
121  is_result_aware_ = awareness;
122 }
123 
124 template<typename ActionT>
125 void
127 {
128  std::lock_guard<std::mutex> guard(handle_mutex_);
129  status_ = GoalStatus::STATUS_UNKNOWN;
130  result_promise_.set_exception(std::make_exception_ptr(
132 }
133 
134 template<typename ActionT>
135 void
137  typename ClientGoalHandle<ActionT>::SharedPtr shared_this,
138  typename std::shared_ptr<const Feedback> feedback_message)
139 {
140  if (shared_this.get() != this) {
141  RCLCPP_ERROR(rclcpp::get_logger("rclcpp_action"), "Sent feedback to wrong goal handle.");
142  return;
143  }
144  std::lock_guard<std::mutex> guard(handle_mutex_);
145  if (nullptr == feedback_callback_) {
146  // Normal, some feedback messages may arrive after the goal result.
147  RCLCPP_DEBUG(rclcpp::get_logger("rclcpp_action"), "Received feedback but goal ignores it.");
148  return;
149  }
150  feedback_callback_(shared_this, feedback_message);
151 }
152 
153 } // namespace rclcpp_action
154 
155 #endif // RCLCPP_ACTION__CLIENT_GOAL_HANDLE_IMPL_HPP_
T make_exception_ptr(T... args)
int8_t get_status()
Definition: client_goal_handle_impl.hpp:86
Logger get_logger(const std::string &name)
virtual ~ClientGoalHandle()
Definition: client_goal_handle_impl.hpp:37
bool is_result_aware()
Definition: client_goal_handle_impl.hpp:110
#define RCLCPP_DEBUG(logger,...)
#define RCLCPP_ERROR(logger,...)
ResultCode code
A status to indicate if the goal was canceled, aborted, or suceeded.
Definition: client_goal_handle.hpp:60
rclcpp::Time get_goal_stamp() const
Definition: client_goal_handle_impl.hpp:51
Definition: client_goal_handle.hpp:55
action_msgs::msg::GoalInfo GoalInfo
Definition: types.hpp:34
Definition: client.hpp:44
Definition: client_goal_handle.hpp:49
bool is_feedback_aware()
Definition: client_goal_handle_impl.hpp:102
const GoalID & get_goal_id() const
Definition: client_goal_handle_impl.hpp:43
std::shared_future< Result > async_result()
Definition: client_goal_handle_impl.hpp:58