rclcpp_action  master
C++ ROS Action Client Library
client_goal_handle.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_HPP_
16 #define RCLCPP_ACTION__CLIENT_GOAL_HANDLE_HPP_
17 
19 
20 #include <action_msgs/msg/goal_status.hpp>
21 #include <rclcpp/macros.hpp>
22 #include <rclcpp/time.hpp>
23 
24 #include <functional>
25 #include <future>
26 #include <memory>
27 #include <mutex>
28 
29 #include "rclcpp_action/types.hpp"
31 
32 namespace rclcpp_action
33 {
35 enum class ResultCode : int8_t
36 {
37  UNKNOWN = action_msgs::msg::GoalStatus::STATUS_UNKNOWN,
38  SUCCEEDED = action_msgs::msg::GoalStatus::STATUS_SUCCEEDED,
39  CANCELED = action_msgs::msg::GoalStatus::STATUS_CANCELED,
40  ABORTED = action_msgs::msg::GoalStatus::STATUS_ABORTED
41 };
42 
43 
44 // Forward declarations
45 template<typename ActionT>
46 class Client;
47 
49 
57 template<typename ActionT>
59 {
60 public:
62 
63  // A wrapper that defines the result of an action
64  typedef struct WrappedResult
65  {
71  typename ActionT::Result::SharedPtr result;
72  } WrappedResult;
73 
74  using Feedback = typename ActionT::Feedback;
75  using Result = typename ActionT::Result;
76  using FeedbackCallback =
77  std::function<void (
81 
82  virtual ~ClientGoalHandle();
83 
85  const GoalUUID &
86  get_goal_id() const;
87 
90  get_goal_stamp() const;
91 
93 
103  async_result();
104 
106  int8_t
107  get_status();
108 
110  bool
111  is_feedback_aware();
112 
114  bool
115  is_result_aware();
116 
117 private:
118  // The templated Client creates goal handles
119  friend Client<ActionT>;
120 
122  const GoalInfo & info,
123  FeedbackCallback feedback_callback,
124  ResultCallback result_callback);
125 
126  void
127  set_feedback_callback(FeedbackCallback callback);
128 
129  void
130  set_result_callback(ResultCallback callback);
131 
132  void
133  call_feedback_callback(
134  typename ClientGoalHandle<ActionT>::SharedPtr shared_this,
135  typename std::shared_ptr<const Feedback> feedback_message);
136 
137  void
138  set_result_awareness(bool awareness);
139 
140  void
141  set_status(int8_t status);
142 
143  void
144  set_result(const WrappedResult & wrapped_result);
145 
146  void
147  invalidate();
148 
149  GoalInfo info_;
150 
151  bool is_result_aware_{false};
152  std::promise<WrappedResult> result_promise_;
153  std::shared_future<WrappedResult> result_future_;
154 
155  FeedbackCallback feedback_callback_{nullptr};
156  ResultCallback result_callback_{nullptr};
157  int8_t status_{GoalStatus::STATUS_ACCEPTED};
158 
159  std::mutex handle_mutex_;
160 };
161 } // namespace rclcpp_action
162 
163 #include <rclcpp_action/client_goal_handle_impl.hpp> // NOLINT(build/include_order)
164 #endif // RCLCPP_ACTION__CLIENT_GOAL_HANDLE_HPP_
ActionT::Result::SharedPtr result
User defined fields sent back with an action.
Definition: client_goal_handle.hpp:71
Definition: client_goal_handle.hpp:64
Action Client.
Definition: client.hpp:255
GoalUUID goal_id
The unique identifier of the goal.
Definition: client_goal_handle.hpp:67
ResultCode
The possible statuses that an action goal can finish with.
Definition: client_goal_handle.hpp:35
typename ActionT::Result Result
Definition: client_goal_handle.hpp:75
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...)
ResultCode code
A status to indicate if the goal was canceled, aborted, or suceeded.
Definition: client_goal_handle.hpp:69
action_msgs::msg::GoalInfo GoalInfo
Definition: types.hpp:34
Definition: client.hpp:44
Class for interacting with goals sent from action clients.
Definition: client_goal_handle.hpp:58
typename ActionT::Feedback Feedback
Definition: client_goal_handle.hpp:74