rclcpp
master
C++ ROS Client Library API
|
Go to the documentation of this file.
15 #ifndef RCLCPP__CLIENT_HPP_
16 #define RCLCPP__CLIENT_HPP_
28 #include "rcl/error_handling.h"
48 namespace node_interfaces
50 class NodeBaseInterface;
61 rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph);
124 template<
typename RepT =
int64_t,
typename RatioT = std::milli>
130 std::chrono::duration_cast<std::chrono::nanoseconds>(timeout)
177 template<
typename ServiceT>
210 rclcpp::node_interfaces::NodeBaseInterface * node_base,
211 rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph,
212 const
std::
string & service_name,
216 using rosidl_typesupport_cpp::get_service_type_support_handle;
217 auto service_type_support_handle =
218 get_service_type_support_handle<ServiceT>();
222 service_type_support_handle,
223 service_name.c_str(),
296 auto typed_response = std::static_pointer_cast<typename ServiceT::Response>(response);
297 int64_t sequence_number = request_header->sequence_number;
299 if (this->pending_requests_.count(sequence_number) == 0) {
302 "Received invalid sequence number. Ignoring...");
305 auto tuple = this->pending_requests_[sequence_number];
306 auto call_promise = std::get<0>(tuple);
307 auto callback = std::get<1>(tuple);
308 auto future = std::get<2>(tuple);
309 this->pending_requests_.erase(sequence_number);
313 call_promise->set_value(typed_response);
336 int64_t sequence_number;
344 pending_requests_[sequence_number] =
364 auto wrapping_cb = [future_with_request, promise, request,
365 cb = std::forward<CallbackWithRequestType>(cb)](
SharedFuture future) {
366 auto response = future.get();
368 cb(future_with_request);
373 return future_with_request;
385 #endif // RCLCPP__CLIENT_HPP_
std::shared_ptr< rmw_request_id_t > create_request_header() override
Create a shared pointer with a rmw_request_id_t.
Definition: client.hpp:278
const char * rcl_node_get_name(const rcl_node_t *node)
#define RCL_RET_SERVICE_NAME_INVALID
const char * rcl_node_get_namespace(const rcl_node_t *node)
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
ClientBase(rclcpp::node_interfaces::NodeBaseInterface *node_base, rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph)
virtual void handle_response(std::shared_ptr< rmw_request_id_t > request_header, std::shared_ptr< void > response)=0
virtual ~Client()
Definition: client.hpp:240
std::atomic< bool > in_use_by_wait_set_
Definition: client.hpp:174
std::shared_ptr< rcl_client_t > get_client_handle()
Return the rcl_client_t client handle in a std::shared_ptr.
std::shared_ptr< rcl_node_t > node_handle_
Definition: client.hpp:169
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
SharedFuture async_send_request(SharedRequest request)
Definition: client.hpp:318
virtual std::shared_ptr< void > create_response()=0
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
std::function< void(SharedFutureWithRequest)> CallbackWithRequestType
Definition: client.hpp:194
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
std::function< void(SharedFuture)> CallbackType
Definition: client.hpp:193
rcl_ret_t rcl_send_request(const rcl_client_t *client, const void *ros_request, int64_t *sequence_number)
void handle_response(std::shared_ptr< rmw_request_id_t > request_header, std::shared_ptr< void > response) override
Handle a server response.
Definition: client.hpp:291
#define RCUTILS_LOG_ERROR_NAMED(name,...)
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.
SharedFutureWithRequest async_send_request(SharedRequest request, CallbackT &&cb)
Definition: client.hpp:359
Definition: client.hpp:53
virtual std::shared_ptr< rmw_request_id_t > create_request_header()=0
std::shared_ptr< rcl_client_t > client_handle_
Definition: client.hpp:172
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)
std::shared_ptr< void > create_response() override
Create a shared pointer with the response type.
Definition: client.hpp:268
bool service_is_ready() const
Return if the service is ready.
Definition: function_traits.hpp:159
bool exchange_in_use_by_wait_set_state(bool in_use_state)
Exchange the "in use by wait set" state for this client.
Definition: client.hpp:178
const char * get_service_name() const
Return the name of the service.
std::shared_future< std::pair< SharedRequest, SharedResponse > > SharedFutureWithRequest
Definition: client.hpp:191
bool wait_for_service(std::chrono::duration< RepT, RatioT > timeout=std::chrono::duration< RepT, RatioT >(-1))
Wait for a service to be ready.
Definition: client.hpp:126
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...)
Definition: macros.hpp:51
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.
bool wait_for_service_nanoseconds(std::chrono::nanoseconds timeout)
std::shared_future< SharedResponse > SharedFuture
Definition: client.hpp:190
bool take_type_erased_response(void *response_out, rmw_request_id_t &request_header_out)
Take the next response for this client as a type erased pointer.
typename rcl_interfaces::srv::GetParameters ::Response::SharedPtr SharedResponse
Definition: client.hpp:182
typename rcl_interfaces::srv::GetParameters ::Request::SharedPtr SharedRequest
Definition: client.hpp:181
rcl_node_t * get_rcl_node_handle()
SharedFuture async_send_request(SharedRequest request, CallbackT &&cb)
Definition: client.hpp:333
rclcpp::node_interfaces::NodeGraphInterface::WeakPtr node_graph_
Definition: client.hpp:168
bool take_response(typename ServiceT::Response &response_out, rmw_request_id_t &request_header_out)
Take the next response for this client.
Definition: client.hpp:258
std::shared_ptr< rclcpp::Context > context_
Definition: client.hpp:170