15 #ifndef NAV2_ROS_COMMON__SERVICE_SERVER_HPP_
16 #define NAV2_ROS_COMMON__SERVICE_SERVER_HPP_
20 #include "rclcpp/rclcpp.hpp"
21 #include "rclcpp_lifecycle/lifecycle_node.hpp"
22 #include "nav2_ros_common/node_utils.hpp"
31 template<
class ServiceT>
35 using RequestType =
typename ServiceT::Request;
36 using ResponseType =
typename ServiceT::Response;
37 using CallbackType = std::function<void(
const std::shared_ptr<rmw_request_id_t>,
38 const std::shared_ptr<RequestType>, std::shared_ptr<ResponseType>)>;
39 using SharedPtr = std::shared_ptr<ServiceServer<ServiceT>>;
40 using UniquePtr = std::unique_ptr<ServiceServer<ServiceT>>;
42 template<
typename NodeT>
44 const std::string & service_name,
46 CallbackType callback,
47 rclcpp::CallbackGroup::SharedPtr callback_group =
nullptr)
48 : service_name_(service_name), callback_(callback)
50 server_ = rclcpp::create_service<ServiceT>(
51 node->get_node_base_interface(),
52 node->get_node_services_interface(),
54 [
this](
const std::shared_ptr<rmw_request_id_t> request_header,
55 const std::shared_ptr<RequestType> request, std::shared_ptr<ResponseType> response) {
56 this->callback_(request_header, request, response);
58 rclcpp::ServicesQoS(),
61 nav2::setIntrospectionMode(this->server_,
62 node->get_node_parameters_interface(), node->get_clock());
66 std::string service_name_;
67 CallbackType callback_;
68 typename rclcpp::Service<ServiceT>::SharedPtr server_;
A simple wrapper on ROS2 services server.