15 #ifndef NAV2_ROS_COMMON__SERVICE_SERVER_HPP_
16 #define NAV2_ROS_COMMON__SERVICE_SERVER_HPP_
20 #include "rclcpp/callback_group.hpp"
21 #include "rclcpp/create_service.hpp"
22 #include "rclcpp/qos.hpp"
23 #include "rclcpp/service.hpp"
24 #include "rclcpp_lifecycle/lifecycle_node.hpp"
25 #include "nav2_ros_common/node_utils.hpp"
34 template<
class ServiceT>
38 using RequestType =
typename ServiceT::Request;
39 using ResponseType =
typename ServiceT::Response;
40 using CallbackType = std::function<void (
const std::shared_ptr<rmw_request_id_t>,
41 const std::shared_ptr<RequestType>, std::shared_ptr<ResponseType>)>;
42 using SharedPtr = std::shared_ptr<ServiceServer<ServiceT>>;
43 using UniquePtr = std::unique_ptr<ServiceServer<ServiceT>>;
45 template<
typename NodeT>
47 const std::string & service_name,
49 CallbackType callback,
50 rclcpp::CallbackGroup::SharedPtr callback_group =
nullptr)
51 : service_name_(service_name), callback_(callback)
53 server_ = rclcpp::create_service<ServiceT>(
54 node->get_node_base_interface(),
55 node->get_node_services_interface(),
57 [
this](
const std::shared_ptr<rmw_request_id_t> request_header,
58 const std::shared_ptr<RequestType> request, std::shared_ptr<ResponseType> response) {
59 this->callback_(request_header, request, response);
61 rclcpp::ServicesQoS(),
64 nav2::setIntrospectionMode(
66 node->get_node_parameters_interface(), node->get_clock());
70 std::string service_name_;
71 CallbackType callback_;
72 typename rclcpp::Service<ServiceT>::SharedPtr server_;
A simple wrapper on ROS2 services server.