ROS 2 rclcpp + rcl - rolling  rolling-a919a6e5
ROS 2 C++ Client Library with ROS Client Library
create_client.hpp
1 // Copyright 2019 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_CLIENT_HPP_
16 #define RCLCPP__CREATE_CLIENT_HPP_
17 
18 #include <memory>
19 #include <string>
20 
21 #include "rclcpp/node_interfaces/node_base_interface.hpp"
22 #include "rclcpp/node_interfaces/node_services_interface.hpp"
23 #include "rclcpp/qos.hpp"
24 #include "rmw/rmw.h"
25 
26 namespace rclcpp
27 {
29 
41 template<typename ServiceT>
44  std::shared_ptr<node_interfaces::NodeBaseInterface> node_base,
45  std::shared_ptr<node_interfaces::NodeGraphInterface> node_graph,
46  std::shared_ptr<node_interfaces::NodeServicesInterface> node_services,
47  const std::string & service_name,
48  const rclcpp::QoS & qos = rclcpp::ServicesQoS(),
49  rclcpp::CallbackGroup::SharedPtr group = nullptr)
50 {
52  options.qos = qos.get_rmw_qos_profile();
53 
55  node_base.get(),
56  node_graph,
57  service_name,
58  options);
59 
60  auto cli_base_ptr = std::dynamic_pointer_cast<rclcpp::ClientBase>(cli);
61  node_services->add_client(cli_base_ptr, group);
62  return cli;
63 }
64 } // namespace rclcpp
65 
66 #endif // RCLCPP__CREATE_CLIENT_HPP_
Encapsulation of Quality of Service settings.
Definition: qos.hpp:116
RCL_PUBLIC RCL_WARN_UNUSED rcl_client_options_t rcl_client_get_default_options(void)
Return the default client options in a rcl_client_options_t.
Definition: client.c:280
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
rclcpp::Client< ServiceT >::SharedPtr create_client(std::shared_ptr< node_interfaces::NodeBaseInterface > node_base, std::shared_ptr< node_interfaces::NodeGraphInterface > node_graph, std::shared_ptr< node_interfaces::NodeServicesInterface > node_services, const std::string &service_name, const rclcpp::QoS &qos=rclcpp::ServicesQoS(), rclcpp::CallbackGroup::SharedPtr group=nullptr)
Create a service client with a given type.
Options available for a rcl_client_t.
Definition: client.h:50
rmw_qos_profile_t qos
Middleware quality of service settings for the client.
Definition: client.h:52