.. _program_listing_file_include_rclcpp_publisher_options.hpp: Program Listing for File publisher_options.hpp ============================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/rclcpp/publisher_options.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2019 Open Source Robotics Foundation, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef RCLCPP__PUBLISHER_OPTIONS_HPP_ #define RCLCPP__PUBLISHER_OPTIONS_HPP_ #include #include #include #include #include "rcl/publisher.h" #include "rclcpp/allocator/allocator_common.hpp" #include "rclcpp/detail/rmw_implementation_specific_publisher_payload.hpp" #include "rclcpp/intra_process_setting.hpp" #include "rclcpp/qos.hpp" #include "rclcpp/qos_event.hpp" #include "rclcpp/qos_overriding_options.hpp" namespace rclcpp { class CallbackGroup; struct PublisherOptionsBase { IntraProcessSetting use_intra_process_comm = IntraProcessSetting::NodeDefault; PublisherEventCallbacks event_callbacks; bool use_default_callbacks = true; rmw_unique_network_flow_endpoints_requirement_t require_unique_network_flow_endpoints = RMW_UNIQUE_NETWORK_FLOW_ENDPOINTS_NOT_REQUIRED; std::shared_ptr callback_group; std::shared_ptr rmw_implementation_payload = nullptr; QosOverridingOptions qos_overriding_options; }; template struct PublisherOptionsWithAllocator : public PublisherOptionsBase { static_assert( std::is_void_v::value_type>, "Publisher allocator value type must be void"); std::shared_ptr allocator = nullptr; PublisherOptionsWithAllocator() {} explicit PublisherOptionsWithAllocator(const PublisherOptionsBase & publisher_options_base) : PublisherOptionsBase(publisher_options_base) {} template rcl_publisher_options_t to_rcl_publisher_options(const rclcpp::QoS & qos) const { rcl_publisher_options_t result = rcl_publisher_get_default_options(); result.allocator = this->get_rcl_allocator(); result.qos = qos.get_rmw_qos_profile(); result.rmw_publisher_options.require_unique_network_flow_endpoints = this->require_unique_network_flow_endpoints; // Apply payload to rcl_publisher_options if necessary. if (rmw_implementation_payload && rmw_implementation_payload->has_been_customized()) { rmw_implementation_payload->modify_rmw_publisher_options(result.rmw_publisher_options); } return result; } std::shared_ptr get_allocator() const { if (!this->allocator) { if (!allocator_storage_) { allocator_storage_ = std::make_shared(); } return allocator_storage_; } return this->allocator; } private: using PlainAllocator = typename std::allocator_traits::template rebind_alloc; rcl_allocator_t get_rcl_allocator() const { if (!plain_allocator_storage_) { plain_allocator_storage_ = std::make_shared(*this->get_allocator()); } return rclcpp::allocator::get_rcl_allocator(*plain_allocator_storage_); } // This is a temporal workaround, to make sure that get_allocator() // always returns a copy of the same allocator. mutable std::shared_ptr allocator_storage_; // This is a temporal workaround, to keep the plain allocator that backs // up the rcl allocator returned in rcl_publisher_options_t alive. mutable std::shared_ptr plain_allocator_storage_; }; using PublisherOptions = PublisherOptionsWithAllocator>; } // namespace rclcpp #endif // RCLCPP__PUBLISHER_OPTIONS_HPP_