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 
48 template<typename ActionT>
50 {
51 public:
53 
54  // A wrapper that defines the result of an action
55  typedef struct Result
56  {
62  typename ActionT::Result::SharedPtr response;
63  } Result;
64 
65  using Feedback = typename ActionT::Feedback;
66  using FeedbackCallback =
67  std::function<void (
69 
70  virtual ~ClientGoalHandle();
71 
72  const GoalID &
73  get_goal_id() const;
74 
76  get_goal_stamp() const;
77 
79  async_result();
80 
81  int8_t
82  get_status();
83 
84  bool
85  is_feedback_aware();
86 
87  bool
88  is_result_aware();
89 
90 private:
91  // The templated Client creates goal handles
92  friend Client<ActionT>;
93 
94  ClientGoalHandle(const GoalInfo & info, FeedbackCallback callback);
95 
96  void
97  set_feedback_callback(FeedbackCallback callback);
98 
99  void
100  call_feedback_callback(
101  typename ClientGoalHandle<ActionT>::SharedPtr shared_this,
102  typename std::shared_ptr<const Feedback> feedback_message);
103 
104  void
105  set_result_awareness(bool awareness);
106 
107  void
108  set_status(int8_t status);
109 
110  void
111  set_result(const Result & result);
112 
113  void
114  invalidate();
115 
116  GoalInfo info_;
117 
118  bool is_result_aware_{false};
119  std::promise<Result> result_promise_;
120  std::shared_future<Result> result_future_;
121 
122  FeedbackCallback feedback_callback_{nullptr};
123  int8_t status_{GoalStatus::STATUS_ACCEPTED};
124 
125  std::mutex handle_mutex_;
126 };
127 } // namespace rclcpp_action
128 
129 #include <rclcpp_action/client_goal_handle_impl.hpp> // NOLINT(build/include_order)
130 #endif // RCLCPP_ACTION__CLIENT_GOAL_HANDLE_HPP_
Action Client.
Definition: client.hpp:255
ResultCode
The possible statuses that an action goal can finish with.
Definition: client_goal_handle.hpp:35
ResultCode code
A status to indicate if the goal was canceled, aborted, or suceeded.
Definition: client_goal_handle.hpp:60
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...)
Definition: client_goal_handle.hpp:55
action_msgs::msg::GoalInfo GoalInfo
Definition: types.hpp:34
Definition: client.hpp:44
ActionT::Result::SharedPtr response
User defined fields sent back with an action.
Definition: client_goal_handle.hpp:62
Definition: client_goal_handle.hpp:49
GoalID goal_id
The unique identifier of the goal.
Definition: client_goal_handle.hpp:58
typename ActionT::Feedback Feedback
Definition: client_goal_handle.hpp:65