rclcpp  master
C++ ROS Client Library API
publisher_factory.hpp
Go to the documentation of this file.
1 // Copyright 2016 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__PUBLISHER_FACTORY_HPP_
16 #define RCLCPP__PUBLISHER_FACTORY_HPP_
17 
18 #include <functional>
19 #include <memory>
20 #include <string>
21 
22 #include "rcl/publisher.h"
23 
24 #include "rosidl_typesupport_cpp/message_type_support.hpp"
25 
26 #include "rclcpp/publisher.hpp"
30 #include "rclcpp/qos.hpp"
32 
33 namespace rclcpp
34 {
35 
37 
51 {
52  // Creates a PublisherT<MessageT, ...> publisher object and returns it as a PublisherBase.
54  rclcpp::PublisherBase::SharedPtr(
56  const std::string & topic_name,
57  const rclcpp::QoS & qos
58  )>;
59 
61 };
62 
64 template<typename MessageT, typename AllocatorT, typename PublisherT>
67 {
68  PublisherFactory factory {
69  // factory function that creates a MessageT specific PublisherT
70  [options](
72  const std::string & topic_name,
73  const rclcpp::QoS & qos
75  {
76  auto publisher = std::make_shared<PublisherT>(node_base, topic_name, qos, options);
77  // This is used for setting up things like intra process comms which
78  // require this->shared_from_this() which cannot be called from
79  // the constructor.
80  publisher->post_init_setup(node_base, topic_name, qos, options);
81  return publisher;
82  }
83  };
84 
85  // return the factory now that it is populated
86  return factory;
87 }
88 
89 } // namespace rclcpp
90 
91 #endif // RCLCPP__PUBLISHER_FACTORY_HPP_
std::string
std::shared_ptr
rclcpp::PublisherFactory
Factory with functions used to create a MessageT specific PublisherT.
Definition: publisher_factory.hpp:50
std::function
publisher.h
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
publisher.hpp
qos.hpp
rclcpp::node_interfaces::NodeBaseInterface
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
rclcpp::QoS
Encapsulation of Quality of Service settings.
Definition: qos.hpp:110
rclcpp::create_publisher_factory
PublisherFactory create_publisher_factory(const rclcpp::PublisherOptionsWithAllocator< AllocatorT > &options)
Return a PublisherFactory with functions setup for creating a PublisherT<MessageT,...
Definition: publisher_factory.hpp:66
publisher_options.hpp
node_base_interface.hpp
publisher_base.hpp
rclcpp::PublisherFactory::create_typed_publisher
const PublisherFactoryFunction create_typed_publisher
Definition: publisher_factory.hpp:60
rclcpp::PublisherOptionsWithAllocator
Structure containing optional configuration for Publishers.
Definition: publisher_options.hpp:65
visibility_control.hpp