mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
Loading...
Searching...
No Matches
service_client_handler.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <rclcpp/rclcpp.hpp>
9
10#include <string>
11#include <future>
12
13#include <mrs_lib/coro/internal/thread_local_continuation_scheduler.hpp>
14#include <mrs_lib/coro/task.hpp>
15
16namespace mrs_lib
17{
18
19 /* class ServiceClientHandler //{ */
20
24 template <class ServiceType>
26 {
27
28 public:
40 ServiceClientHandler(rclcpp::Node::SharedPtr& node, const std::string& address, const rclcpp::QoS& qos = rclcpp::ServicesQoS());
41
49
60 ServiceClientHandler(rclcpp::Node::SharedPtr& node, const std::string& address, const rclcpp::QoS& qos,
61 const rclcpp::CallbackGroup::SharedPtr& callback_group);
62
72 ServiceClientHandler(rclcpp::Node::SharedPtr& node, const std::string& address, const rclcpp::CallbackGroup::SharedPtr& callback_group);
73
87 std::optional<std::shared_ptr<typename ServiceType::Response>> callSync(const std::shared_ptr<typename ServiceType::Request>& request);
88
96 std::optional<std::shared_future<std::shared_ptr<typename ServiceType::Response>>> callAsync(const std::shared_ptr<typename ServiceType::Request>& request);
97
114 Task<std::optional<std::shared_ptr<typename ServiceType::Response>>> callAwaitable(std::shared_ptr<typename ServiceType::Request> request);
115
121 std::string getServiceName() const;
122
132 template <typename RepT = int64_t, typename RatioT = std::milli>
133 bool waitForService(std::chrono::duration<RepT, RatioT> timeout = std::chrono::seconds(1));
134
140 bool isServiceReady() const;
141
152 size_t prunePendingRequests();
153
154 private:
155 class Impl;
156 std::shared_ptr<Impl> impl_;
157 };
158
159 //}
160
161} // namespace mrs_lib
162
implementation of the service client handler
Definition service_client_handler.hpp:161
user wrapper of the service client handler implementation
Definition service_client_handler.h:26
ServiceClientHandler()
Default constructor to avoid having to use pointers.
Definition service_client_handler.hpp:28
std::optional< std::shared_ptr< typename ServiceType::Response > > callSync(const std::shared_ptr< typename ServiceType::Request > &request)
Synchronous (blocking) call of the service.
Definition service_client_handler.hpp:52
std::string getServiceName() const
Returns the name of the service this client connects to.
Definition service_client_handler.hpp:96
bool waitForService(std::chrono::duration< RepT, RatioT > timeout=std::chrono::seconds(1))
Waits for the service to be available.
Definition service_client_handler.hpp:112
std::optional< std::shared_future< std::shared_ptr< typename ServiceType::Response > > > callAsync(const std::shared_ptr< typename ServiceType::Request > &request)
Asynchronous (non-blocking) call of the service.
Definition service_client_handler.hpp:68
size_t prunePendingRequests()
Clean all pending requests.
Definition service_client_handler.hpp:139
bool isServiceReady() const
Checks if the service is available.
Definition service_client_handler.hpp:126
Task< std::optional< std::shared_ptr< typename ServiceType::Response > > > callAwaitable(std::shared_ptr< typename ServiceType::Request > request)
Awaitable call of the service.
Definition service_client_handler.hpp:82
Task type for creating coroutines.
Definition task.hpp:268
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition attitude_converter.h:24
Implements ServiceClientHandler and related convenience classes for upgrading the ROS service client.