generic_client.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <future>
4 
5 #include <rclcpp/client.hpp>
6 #include <rclcpp/serialized_message.hpp>
7 #include <rcpputils/shared_library.hpp>
8 
9 namespace foxglove_bridge {
10 
11 class GenericClient : public rclcpp::ClientBase {
12 public:
13  using SharedRequest = std::shared_ptr<rclcpp::SerializedMessage>;
14  using SharedResponse = std::shared_ptr<rclcpp::SerializedMessage>;
15  using Promise = std::promise<SharedResponse>;
16  using PromiseWithRequest = std::promise<std::pair<SharedRequest, SharedResponse>>;
17  using SharedPromise = std::shared_ptr<Promise>;
18  using SharedPromiseWithRequest = std::shared_ptr<PromiseWithRequest>;
19  using SharedFuture = std::shared_future<SharedResponse>;
20  using SharedFutureWithRequest = std::shared_future<std::pair<SharedRequest, SharedResponse>>;
21  using CallbackType = std::function<void(SharedFuture)>;
22  using CallbackWithRequestType = std::function<void(SharedFutureWithRequest)>;
23 
24  RCLCPP_SMART_PTR_DEFINITIONS(GenericClient)
25 
26  GenericClient(rclcpp::node_interfaces::NodeBaseInterface* node_base,
27  rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph,
28  std::string service_name, std::string service_type,
29  rcl_client_options_t& client_options);
30  virtual ~GenericClient() {}
31 
32  std::shared_ptr<void> create_response() override;
33  std::shared_ptr<rmw_request_id_t> create_request_header() override;
34  void handle_response(std::shared_ptr<rmw_request_id_t> request_header,
35  std::shared_ptr<void> response) override;
38 
39 private:
40  RCLCPP_DISABLE_COPY(GenericClient)
41 
44  std::shared_ptr<rcpputils::SharedLibrary> _typeSupportLib;
45  std::shared_ptr<rcpputils::SharedLibrary> _typeIntrospectionLib;
46  const rosidl_service_type_support_t* _serviceTypeSupportHdl;
47  const rosidl_message_type_support_t* _requestTypeSupportHdl;
48  const rosidl_message_type_support_t* _responseTypeSupportHdl;
49  const rosidl_service_type_support_t* _typeIntrospectionHdl;
50 };
51 
52 } // namespace foxglove_bridge
foxglove_bridge::GenericClient::SharedPromiseWithRequest
std::shared_ptr< PromiseWithRequest > SharedPromiseWithRequest
Definition: generic_client.hpp:18
foxglove_bridge::GenericClient::Promise
std::promise< SharedResponse > Promise
Definition: generic_client.hpp:15
foxglove_bridge::GenericClient::SharedFuture
std::shared_future< SharedResponse > SharedFuture
Definition: generic_client.hpp:19
foxglove_bridge::GenericClient::_serviceTypeSupportHdl
const rosidl_service_type_support_t * _serviceTypeSupportHdl
Definition: generic_client.hpp:46
foxglove_bridge::GenericClient::SharedFutureWithRequest
std::shared_future< std::pair< SharedRequest, SharedResponse > > SharedFutureWithRequest
Definition: generic_client.hpp:20
foxglove_bridge::GenericClient::_typeSupportLib
std::shared_ptr< rcpputils::SharedLibrary > _typeSupportLib
Definition: generic_client.hpp:44
foxglove_bridge::GenericClient::~GenericClient
virtual ~GenericClient()
Definition: generic_client.hpp:30
foxglove_bridge::GenericClient::PromiseWithRequest
std::promise< std::pair< SharedRequest, SharedResponse > > PromiseWithRequest
Definition: generic_client.hpp:16
foxglove_bridge::GenericClient::SharedResponse
std::shared_ptr< rclcpp::SerializedMessage > SharedResponse
Definition: generic_client.hpp:14
foxglove_bridge::GenericClient::_typeIntrospectionHdl
const rosidl_service_type_support_t * _typeIntrospectionHdl
Definition: generic_client.hpp:49
foxglove_bridge::GenericClient::pending_requests_mutex_
std::mutex pending_requests_mutex_
Definition: generic_client.hpp:43
foxglove_bridge::GenericClient::pending_requests_
std::map< int64_t, std::tuple< SharedPromise, CallbackType, SharedFuture > > pending_requests_
Definition: generic_client.hpp:42
foxglove_bridge::GenericClient::create_response
std::shared_ptr< void > create_response() override
Definition: generic_client.cpp:155
foxglove_bridge
Definition: generic_service.hpp:9
foxglove_bridge::GenericClient::_requestTypeSupportHdl
const rosidl_message_type_support_t * _requestTypeSupportHdl
Definition: generic_client.hpp:47
foxglove_bridge::GenericClient::handle_response
void handle_response(std::shared_ptr< rmw_request_id_t > request_header, std::shared_ptr< void > response) override
Definition: generic_client.cpp:164
foxglove_bridge::GenericClient::async_send_request
SharedFuture async_send_request(SharedRequest request)
Definition: generic_client.cpp:194
foxglove_bridge::GenericClient::SharedPromise
std::shared_ptr< Promise > SharedPromise
Definition: generic_client.hpp:17
foxglove_bridge::GenericClient::CallbackType
std::function< void(SharedFuture)> CallbackType
Definition: generic_client.hpp:21
foxglove_bridge::GenericClient::GenericClient
GenericClient(rclcpp::node_interfaces::NodeBaseInterface *node_base, rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph, std::string service_name, std::string service_type, rcl_client_options_t &client_options)
Definition: generic_client.cpp:95
std
foxglove_bridge::GenericClient::create_request_header
std::shared_ptr< rmw_request_id_t > create_request_header() override
Definition: generic_client.cpp:160
foxglove_bridge::GenericClient::_responseTypeSupportHdl
const rosidl_message_type_support_t * _responseTypeSupportHdl
Definition: generic_client.hpp:48
foxglove_bridge::GenericClient
Definition: generic_client.hpp:11
foxglove_bridge::GenericClient::SharedRequest
std::shared_ptr< rclcpp::SerializedMessage > SharedRequest
Definition: generic_client.hpp:13
foxglove_bridge::GenericClient::CallbackWithRequestType
std::function< void(SharedFutureWithRequest)> CallbackWithRequestType
Definition: generic_client.hpp:22
foxglove_bridge::GenericClient::_typeIntrospectionLib
std::shared_ptr< rcpputils::SharedLibrary > _typeIntrospectionLib
Definition: generic_client.hpp:45


foxglove_bridge
Author(s): Foxglove
autogenerated on Wed Mar 5 2025 03:34:31