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 template <class ServiceType>
19 class ServiceClientHandler;
20
21 namespace internal
22 {
23 template <typename ServiceType>
24 requires(rosidl_generator_traits::is_service<ServiceType>::value)
25 class [[nodiscard("This service call is only performed when `co_await`ed.")]] ServiceAwaitable;
26 }
27
28 /* class ServiceClientHandler //{ */
29
33 template <class ServiceType>
35 {
36
37 public:
49 ServiceClientHandler(rclcpp::Node::SharedPtr& node, const std::string& address, const rclcpp::QoS& qos = rclcpp::ServicesQoS());
50
58
69 ServiceClientHandler(rclcpp::Node::SharedPtr& node, const std::string& address, const rclcpp::QoS& qos,
70 const rclcpp::CallbackGroup::SharedPtr& callback_group);
71
81 ServiceClientHandler(rclcpp::Node::SharedPtr& node, const std::string& address, const rclcpp::CallbackGroup::SharedPtr& callback_group);
82
96 std::optional<std::shared_ptr<typename ServiceType::Response>> callSync(const std::shared_ptr<typename ServiceType::Request>& request);
97
105 std::optional<std::shared_future<std::shared_ptr<typename ServiceType::Response>>> callAsync(const std::shared_ptr<typename ServiceType::Request>& request);
106
123 Task<std::optional<std::shared_ptr<typename ServiceType::Response>>> callAwaitable(std::shared_ptr<typename ServiceType::Request> request);
124
130 std::string getServiceName() const;
131
141 template <typename RepT = int64_t, typename RatioT = std::milli>
142 bool waitForService(std::chrono::duration<RepT, RatioT> timeout = std::chrono::seconds(1));
143
149 bool isServiceReady() const;
150
151 private:
152 class Impl;
153 std::shared_ptr<Impl> impl_;
154 };
155
156 //}
157
158} // namespace mrs_lib
159
implementation of the service client handler
Definition service_client_handler.hpp:308
user wrapper of the service client handler implementation
Definition service_client_handler.h:35
ServiceClientHandler()
Default constructor to avoid having to use pointers.
Definition service_client_handler.hpp:187
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:211
std::string getServiceName() const
Returns the name of the service this client connects to.
Definition service_client_handler.hpp:255
bool waitForService(std::chrono::duration< RepT, RatioT > timeout=std::chrono::seconds(1))
Waits for the service to be available.
Definition service_client_handler.hpp:271
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:227
bool isServiceReady() const
Checks if the service is available.
Definition service_client_handler.hpp:285
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:241
Task type for creating coroutines.
Definition task.hpp:313
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.