19 template <
class ServiceType>
21 : impl_(std::make_shared<
Impl>(node, address, qos, node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive)))
25 template <
class ServiceType>
31 template <
class ServiceType>
33 : impl_(std::make_shared<
Impl>(node, address, qos, callback_group))
37 template <
class ServiceType>
47 template <
class ServiceType>
52 RCLCPP_ERROR(rclcpp::get_logger(
"ServiceClientHandler"),
"Not initialized, cannot use callSync()!");
55 return impl_->callSync(request);
62 template <
class ServiceType>
67 RCLCPP_ERROR(rclcpp::get_logger(
"ServiceClientHandler"),
"Not initialized, cannot use callSync()!");
70 return impl_->callAsync(request);
84 template <
class ServiceType>
97 Impl(rclcpp::Node::SharedPtr& node,
const std::string& address,
const rclcpp::QoS& qos,
const rclcpp::CallbackGroup::SharedPtr& callback_group)
98 : callback_group_(callback_group),
99 service_client_(node->create_client<ServiceType>(address, qos, callback_group))
110 std::optional<std::shared_ptr<typename ServiceType::Response>>
callSync(
const std::shared_ptr<typename ServiceType::Request>& request)
113 if (!service_client_->service_is_ready())
117 const auto future_msg = service_client_->async_send_request(request).future.share();
121 if (!future_msg.valid())
125 return future_msg.get();
135 std::optional<std::shared_future<std::shared_ptr<typename ServiceType::Response>>>
callAsync(
const std::shared_ptr<typename ServiceType::Request>& request)
138 if (!service_client_->service_is_ready())
141 const auto future = service_client_->async_send_request(request).future.share();
152 rclcpp::CallbackGroup::SharedPtr callback_group_;
153 typename rclcpp::Client<ServiceType>::SharedPtr service_client_;
implementation of the service client handler
Definition service_client_handler.hpp:85
std::optional< std::shared_future< std::shared_ptr< typename ServiceType::Response > > > callAsync(const std::shared_ptr< typename ServiceType::Request > &request)
asynchronous service call
Definition service_client_handler.hpp:135
std::optional< std::shared_ptr< typename ServiceType::Response > > callSync(const std::shared_ptr< typename ServiceType::Request > &request)
"classic" synchronous service call
Definition service_client_handler.hpp:110
Impl(rclcpp::Node::SharedPtr &node, const std::string &address, const rclcpp::QoS &qos, const rclcpp::CallbackGroup::SharedPtr &callback_group)
constructor
Definition service_client_handler.hpp:97
user wrapper of the service client handler implementation
Definition service_client_handler.h:22
ServiceClientHandler()
Default constructor to avoid having to use pointers.
Definition service_client_handler.hpp:26
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:48
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:63
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition attitude_converter.h:24
Defines ServiceClientHandler and related convenience classes for upgrading the ROS service client.