15 #ifndef RCLCPP__CLIENT_HPP_ 16 #define RCLCPP__CLIENT_HPP_ 47 namespace node_interfaces
49 class NodeBaseInterface;
60 rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph);
63 virtual ~ClientBase();
67 get_service_name()
const;
75 get_client_handle()
const;
79 service_is_ready()
const;
81 template<
typename RepT =
int64_t,
typename RatioT = std::milli>
86 return wait_for_service_nanoseconds(
87 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
93 virtual void handle_response(
105 get_rcl_node_handle();
109 get_rcl_node_handle()
const;
118 template<
typename ServiceT>
140 rclcpp::node_interfaces::NodeBaseInterface * node_base,
141 rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph,
142 const
std::
string & service_name,
144 : ClientBase(node_base, node_graph)
146 using rosidl_typesupport_cpp::get_service_type_support_handle;
147 auto service_type_support_handle =
148 get_service_type_support_handle<ServiceT>();
150 this->get_client_handle().
get(),
151 this->get_rcl_node_handle(),
152 service_type_support_handle,
153 service_name.c_str(),
157 auto rcl_node_handle = this->get_rcl_node_handle();
195 int64_t sequence_number = request_header->sequence_number;
197 if (this->pending_requests_.count(sequence_number) == 0) {
200 "Received invalid sequence number. Ignoring...");
203 auto tuple = this->pending_requests_[sequence_number];
204 auto call_promise = std::get<0>(tuple);
205 auto callback = std::get<1>(tuple);
206 auto future = std::get<2>(tuple);
207 this->pending_requests_.erase(sequence_number);
211 call_promise->set_value(typed_response);
218 return async_send_request(request, [](
SharedFuture) {});
234 int64_t sequence_number;
242 pending_requests_[sequence_number] =
262 auto wrapping_cb = [future_with_request, promise, request, &cb](
SharedFuture future) {
263 auto response = future.
get();
265 cb(future_with_request);
268 async_send_request(request, wrapping_cb);
270 return future_with_request;
282 #endif // RCLCPP__CLIENT_HPP_ Definition: client.hpp:52
std::shared_ptr< rcl_client_t > client_handle_
Definition: client.hpp:115
std::shared_ptr< rclcpp::Context > context_
Definition: client.hpp:113
SharedFuture async_send_request(SharedRequest request)
Definition: client.hpp:216
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
bool wait_for_service(std::chrono::duration< RepT, RatioT > timeout=std::chrono::duration< RepT, RatioT >(-1))
Definition: client.hpp:83
void handle_response(std::shared_ptr< rmw_request_id_t > request_header, std::shared_ptr< void > response) override
Definition: client.hpp:189
std::shared_ptr< rmw_request_id_t > create_request_header() override
Definition: client.hpp:181
This header provides the get_node_topics_interface() template function.
Definition: allocator_common.hpp:24
typename rcl_interfaces::srv::GetParameters ::Request::SharedPtr SharedRequest
Definition: client.hpp:122
rcl_ret_t rcl_send_request(const rcl_client_t *client, const void *ros_request, int64_t *sequence_number)
std::string expand_topic_or_service_name(const std::string &name, const std::string &node_name, const std::string &namespace_, bool is_service=false)
Expand a topic or service name and throw if it is not valid.
Definition: client.hpp:119
rclcpp::node_interfaces::NodeGraphInterface::WeakPtr node_graph_
Definition: client.hpp:111
void throw_from_rcl_error(rcl_ret_t ret, const std::string &prefix="", const rcl_error_state_t *error_state=nullptr, void(*reset_error)()=rcl_reset_error)
Throw a C++ std::exception which was created based on an rcl error.
rcl_ret_t rcl_client_init(rcl_client_t *client, const rcl_node_t *node, const rosidl_service_type_support_t *type_support, const char *service_name, const rcl_client_options_t *options)
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
Definition: function_traits.hpp:143
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
T static_pointer_cast(T... args)
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...)
Definition: macros.hpp:51
#define RCUTILS_LOG_ERROR_NAMED(name,...)
SharedFuture async_send_request(SharedRequest request, CallbackT &&cb)
Definition: client.hpp:231
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
typename rcl_interfaces::srv::GetParameters ::Response::SharedPtr SharedResponse
Definition: client.hpp:123
virtual ~Client()
Definition: client.hpp:170
#define RCL_RET_SERVICE_NAME_INVALID
SharedFutureWithRequest async_send_request(SharedRequest request, CallbackT &&cb)
Definition: client.hpp:257
std::shared_ptr< void > create_response() override
Definition: client.hpp:175
const char * rcl_node_get_name(const rcl_node_t *node)
const char * rcl_node_get_namespace(const rcl_node_t *node)
std::shared_ptr< rcl_node_t > node_handle_
Definition: client.hpp:112