mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
Loading...
Searching...
No Matches
service_server.hpp
1#ifndef MRS_LIB_SERVICE_SERVER_HPP_
2#define MRS_LIB_SERVICE_SERVER_HPP_
3
4#include <functional>
5#include <memory>
6#include <string_view>
7
8#include <rclcpp/callback_group.hpp>
9#include <rclcpp/node_interfaces/node_base_interface.hpp>
10#include <rclcpp/node_interfaces/node_clock_interface.hpp>
11#include <rclcpp/node_interfaces/node_interfaces.hpp>
12#include <rclcpp/node_interfaces/node_logging_interface.hpp>
13#include <rclcpp/node_interfaces/node_services_interface.hpp>
14#include <rclcpp/qos.hpp>
15
18
19namespace mrs_lib
20{
21
26 rclcpp::node_interfaces::NodeInterfaces<rclcpp::node_interfaces::NodeServicesInterface, rclcpp::node_interfaces::NodeBaseInterface,
27 rclcpp::node_interfaces::NodeLoggingInterface, rclcpp::node_interfaces::NodeClockInterface>;
28
33 {
36
38 rclcpp::QoS qos = rclcpp::ServicesQoS();
40 std::shared_ptr<rclcpp::CallbackGroup> callback_group = nullptr;
41 };
42
48 template <class ServiceType>
50 {
51 class Impl;
52
53 using Request = ServiceType::Request;
54 using Response = ServiceType::Response;
55
56 public:
58 using ServiceCallback = std::function<void(std::shared_ptr<const Request> req, std::shared_ptr<Response>)>;
59
61 using ServiceCoroCallback = CoroCallback<void(std::shared_ptr<const Request> req, std::shared_ptr<Response>)>;
62
70 ServiceServer(const ServiceServerOptions& options, std::string_view service_name, ServiceCallback callback);
71
79 ServiceServer(const ServiceServerOptions& options, std::string_view service_name, ServiceCoroCallback callback);
80
86 [[nodiscard]] std::string get_service_name() const;
87
93 [[nodiscard]] std::string get_unresolved_service_name() const;
94
95 private:
96 Pimpl<Impl> impl_;
97 };
98
99} // namespace mrs_lib
100
101
102#ifndef MRS_LIB_SERVICE_SERVER_IMPL_HPP_
103#include "mrs_lib/service_server.impl.hpp"
104#endif
105
106
107#endif // MRS_LIB_SERVICE_SERVER_HPP_
Base template for CoroCallback.
Definition callback.hpp:166
Owning pointer wrapper with move only value semantics. Usefull for implementing the pointer to implem...
Definition pimpl.hpp:39
std::string get_unresolved_service_name() const
Returns the unresolved name of the service handled by this service server.
Definition service_server.impl.hpp:123
ServiceServer(const ServiceServerOptions &options, std::string_view service_name, ServiceCallback callback)
Construct the service server with the specified callback.
Definition service_server.impl.hpp:105
CoroCallback< void(std::shared_ptr< const Request > req, std::shared_ptr< Response >)> ServiceCoroCallback
Type of the accepted coroutine callback.
Definition service_server.hpp:61
std::string get_service_name() const
Returns the resolved (full) name of the service handled by this service server.
Definition service_server.impl.hpp:117
std::function< void(std::shared_ptr< const Request > req, std::shared_ptr< Response >)> ServiceCallback
Type of the accepted callback.
Definition service_server.hpp:58
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition attitude_converter.h:24
rclcpp::node_interfaces::NodeInterfaces< rclcpp::node_interfaces::NodeServicesInterface, rclcpp::node_interfaces::NodeBaseInterface, rclcpp::node_interfaces::NodeLoggingInterface, rclcpp::node_interfaces::NodeClockInterface > ServiceServerNodeInterfaces
ROS node interfaces required by the ServiceServer.
Definition service_server.hpp:25
Options for configuring the ServiceServer.
Definition service_server.hpp:33
rclcpp::QoS qos
QOS settings for the service server.
Definition service_server.hpp:38
std::shared_ptr< rclcpp::CallbackGroup > callback_group
ROS callback group used by the service server callbacks.
Definition service_server.hpp:40
ServiceServerNodeInterfaces node_interfaces
ROS node interfaces used by the service server.
Definition service_server.hpp:35