ROS 2 rclcpp + rcl - rolling  rolling-e615c7c3
ROS 2 C++ Client Library with ROS Client Library
create_generic_service.cpp
1 // Copyright 2024 Sony Group Corporation.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <string>
16 #include <memory>
17 
18 #include "rclcpp/create_generic_service.hpp"
19 #include "rclcpp/generic_service.hpp"
20 
21 namespace rclcpp
22 {
23 rclcpp::GenericService::SharedPtr
25  std::shared_ptr<node_interfaces::NodeBaseInterface> node_base,
26  std::shared_ptr<node_interfaces::NodeGraphInterface> node_graph,
27  std::shared_ptr<node_interfaces::NodeServicesInterface> node_services,
28  const std::string & service_name,
29  const std::string & service_type,
30  GenericServiceCallback any_callback,
31  const rclcpp::QoS & qos,
32  rclcpp::CallbackGroup::SharedPtr group)
33 {
35  options.qos = qos.get_rmw_qos_profile();
36 
37  auto srv = rclcpp::GenericService::make_shared(
38  node_base.get(),
39  node_graph,
40  service_name,
41  service_type,
42  any_callback,
43  options);
44 
45  auto srv_base_ptr = std::dynamic_pointer_cast<rclcpp::ServiceBase>(srv);
46  node_services->add_service(srv_base_ptr, group);
47  return srv;
48 }
49 } // namespace rclcpp
Encapsulation of Quality of Service settings.
Definition: qos.hpp:116
rmw_qos_profile_t & get_rmw_qos_profile()
Return the rmw qos profile.
Definition: qos.cpp:102
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
rclcpp::GenericService::SharedPtr create_generic_service(std::shared_ptr< node_interfaces::NodeBaseInterface > node_base, std::shared_ptr< node_interfaces::NodeServicesInterface > node_services, const std::string &service_name, const std::string &service_type, CallbackT &&callback, const rclcpp::QoS &qos, rclcpp::CallbackGroup::SharedPtr group)
Create a generic service with a given type.
RCL_PUBLIC RCL_WARN_UNUSED rcl_service_options_t rcl_service_get_default_options(void)
Return the default service options in a rcl_service_options_t.
Definition: service.c:286
Options available for a rcl service.
Definition: service.h:50
rmw_qos_profile_t qos
Middleware quality of service settings for the service.
Definition: service.h:52