rclcpp  master
C++ ROS Client Library API
create_service.hpp
Go to the documentation of this file.
1 // Copyright 2018 Open Source Robotics Foundation, Inc.
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 #ifndef RCLCPP__CREATE_SERVICE_HPP_
16 #define RCLCPP__CREATE_SERVICE_HPP_
17 
18 #include <memory>
19 #include <string>
20 #include <utility>
21 
25 #include "rmw/rmw.h"
26 
27 namespace rclcpp
28 {
29 
32 template<typename ServiceT, typename CallbackT>
37  const std::string & service_name,
38  CallbackT && callback,
39  const rmw_qos_profile_t & qos_profile,
40  rclcpp::callback_group::CallbackGroup::SharedPtr group)
41 {
42  rclcpp::AnyServiceCallback<ServiceT> any_service_callback;
43  any_service_callback.set(std::forward<CallbackT>(callback));
44 
46  service_options.qos = qos_profile;
47 
49  node_base->get_shared_rcl_node_handle(),
50  service_name, any_service_callback, service_options);
51  auto serv_base_ptr = std::dynamic_pointer_cast<ServiceBase>(serv);
52  node_services->add_service(serv_base_ptr, group);
53  return serv;
54 }
55 
56 } // namespace rclcpp
57 
58 #endif // RCLCPP__CREATE_SERVICE_HPP_
Definition: allocator_common.hpp:24
Definition: service.hpp:88
void set(CallbackT callback)
Definition: any_service_callback.hpp:65
T dynamic_pointer_cast(T... args)
Definition: service.hpp:40
rcl_service_options_t rcl_service_get_default_options(void)
rmw_qos_profile_t qos
rclcpp::Service< ServiceT >::SharedPtr create_service(std::shared_ptr< node_interfaces::NodeBaseInterface > node_base, std::shared_ptr< node_interfaces::NodeServicesInterface > node_services, const std::string &service_name, CallbackT &&callback, const rmw_qos_profile_t &qos_profile, rclcpp::callback_group::CallbackGroup::SharedPtr group)
Definition: create_service.hpp:34
Definition: any_service_callback.hpp:31