rclcpp  master
C++ ROS Client Library API
publisher_options.hpp
Go to the documentation of this file.
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__PUBLISHER_OPTIONS_HPP_
16 #define RCLCPP__PUBLISHER_OPTIONS_HPP_
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 #include "rcl/publisher.h"
23 
27 #include "rclcpp/qos.hpp"
28 #include "rclcpp/qos_event.hpp"
30 
31 namespace rclcpp
32 {
33 
34 class CallbackGroup;
35 
38 {
41 
44 
46  bool use_default_callbacks = true;
47 
52 
55 
59 
61 };
62 
64 template<typename Allocator>
66 {
69 
71 
73  explicit PublisherOptionsWithAllocator(const PublisherOptionsBase & publisher_options_base)
74  : PublisherOptionsBase(publisher_options_base)
75  {}
76 
78  template<typename MessageT>
81  {
83  using AllocatorTraits = std::allocator_traits<Allocator>;
84  using MessageAllocatorT = typename AllocatorTraits::template rebind_alloc<MessageT>;
85  auto message_alloc = std::make_shared<MessageAllocatorT>(*this->get_allocator().get());
86  result.allocator = rclcpp::allocator::get_rcl_allocator<MessageT>(*message_alloc);
87  result.qos = qos.get_rmw_qos_profile();
90 
91  // Apply payload to rcl_publisher_options if necessary.
92  if (rmw_implementation_payload && rmw_implementation_payload->has_been_customized()) {
93  rmw_implementation_payload->modify_rmw_publisher_options(result.rmw_publisher_options);
94  }
95 
96  return result;
97  }
98 
99 
103  {
104  if (!this->allocator) {
105  return std::make_shared<Allocator>();
106  }
107  return this->allocator;
108  }
109 };
110 
112 
113 } // namespace rclcpp
114 
115 #endif // RCLCPP__PUBLISHER_OPTIONS_HPP_
rcl_publisher_options_t::rmw_publisher_options
rmw_publisher_options_t rmw_publisher_options
std::shared_ptr< rclcpp::CallbackGroup >
rclcpp::IntraProcessSetting::NodeDefault
@ NodeDefault
Take intraprocess configuration from the node.
rmw_publisher_options_t::require_unique_network_flow_endpoints
rmw_unique_network_flow_endpoints_requirement_t require_unique_network_flow_endpoints
rclcpp::QoS::get_rmw_qos_profile
rmw_qos_profile_t & get_rmw_qos_profile()
Return the rmw qos profile.
intra_process_setting.hpp
rclcpp::PublisherOptionsBase
Non-templated part of PublisherOptionsWithAllocator<Allocator>.
Definition: publisher_options.hpp:37
rclcpp::PublisherOptionsWithAllocator::to_rcl_publisher_options
rcl_publisher_options_t to_rcl_publisher_options(const rclcpp::QoS &qos) const
Convert this class, and a rclcpp::QoS, into an rcl_publisher_options_t.
Definition: publisher_options.hpp:80
std::allocator_traits
publisher.h
rclcpp::PublisherEventCallbacks
Contains callbacks for various types of events a Publisher can receive from the middleware.
Definition: qos_event.hpp:53
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
qos.hpp
rcl_publisher_options_t::qos
rmw_qos_profile_t qos
rclcpp::QosOverridingOptions
Options that are passed in subscription/publisher constructor to specify QoSConfigurability.
Definition: qos_overriding_options.hpp:89
rclcpp::PublisherOptionsBase::callback_group
std::shared_ptr< rclcpp::CallbackGroup > callback_group
Callback group in which the waitable items from the publisher should be placed.
Definition: publisher_options.hpp:54
rclcpp::QoS
Encapsulation of Quality of Service settings.
Definition: qos.hpp:110
allocator_common.hpp
rclcpp::PublisherOptionsBase::qos_overriding_options
QosOverridingOptions qos_overriding_options
Definition: publisher_options.hpp:60
rclcpp::PublisherOptionsBase::use_intra_process_comm
IntraProcessSetting use_intra_process_comm
Setting to explicitly set intraprocess communications.
Definition: publisher_options.hpp:40
qos_overriding_options.hpp
rclcpp::IntraProcessSetting
IntraProcessSetting
Used as argument in create_publisher and create_subscriber.
Definition: intra_process_setting.hpp:22
rclcpp::PublisherOptionsBase::use_default_callbacks
bool use_default_callbacks
Whether or not to use default callbacks when user doesn't supply any in event_callbacks.
Definition: publisher_options.hpp:46
rmw_implementation_specific_publisher_payload.hpp
rclcpp::PublisherOptionsBase::event_callbacks
PublisherEventCallbacks event_callbacks
Callbacks for various events related to publishers.
Definition: publisher_options.hpp:43
rclcpp::PublisherOptionsWithAllocator::allocator
std::shared_ptr< Allocator > allocator
Optional custom allocator.
Definition: publisher_options.hpp:68
rclcpp::PublisherOptionsWithAllocator
Structure containing optional configuration for Publishers.
Definition: publisher_options.hpp:65
rclcpp::PublisherOptionsBase::rmw_implementation_payload
std::shared_ptr< rclcpp::detail::RMWImplementationSpecificPublisherPayload > rmw_implementation_payload
Optional RMW implementation specific payload to be used during creation of the publisher.
Definition: publisher_options.hpp:58
rclcpp::PublisherOptionsBase::require_unique_network_flow_endpoints
rmw_unique_network_flow_endpoints_requirement_t require_unique_network_flow_endpoints
Definition: publisher_options.hpp:50
rmw_unique_network_flow_endpoints_requirement_t
enum RMW_PUBLIC_TYPE rmw_unique_network_flow_endpoints_requirement_t rmw_unique_network_flow_endpoints_requirement_t
rclcpp::PublisherOptionsWithAllocator::PublisherOptionsWithAllocator
PublisherOptionsWithAllocator(const PublisherOptionsBase &publisher_options_base)
Constructor using base class as input.
Definition: publisher_options.hpp:73
rclcpp::PublisherOptionsWithAllocator::get_allocator
std::shared_ptr< Allocator > get_allocator() const
Get the allocator, creating one if needed.
Definition: publisher_options.hpp:102
rcl_publisher_options_t::allocator
rcl_allocator_t allocator
RMW_UNIQUE_NETWORK_FLOW_ENDPOINTS_NOT_REQUIRED
RMW_UNIQUE_NETWORK_FLOW_ENDPOINTS_NOT_REQUIRED
rcl_publisher_options_t
qos_event.hpp
rcl_publisher_get_default_options
rcl_publisher_options_t rcl_publisher_get_default_options(void)