From 7f714a86010d3e2ce494f8810240e0b797659b80 Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Tue, 1 Nov 2016 15:07:58 -0700 Subject: [PATCH] open Node/Publisher API for allowing inheritance (#258) * (dev) template create_publisher with publisher type * (dev) template publisher type for dynamic publisher type instantiation * (dev) make Publisher::publish function virtual * (fix) uncrustify * different indentation of long template declaration --- rclcpp/include/rclcpp/node.hpp | 12 ++++++++---- rclcpp/include/rclcpp/node_impl.hpp | 14 +++++++------- rclcpp/include/rclcpp/publisher.hpp | 9 ++++----- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/rclcpp/include/rclcpp/node.hpp b/rclcpp/include/rclcpp/node.hpp index a9d9aa1..78bb01a 100644 --- a/rclcpp/include/rclcpp/node.hpp +++ b/rclcpp/include/rclcpp/node.hpp @@ -123,8 +123,10 @@ public: * \param[in] qos_history_depth The depth of the publisher message queue. * \return Shared pointer to the created publisher. */ - template> - typename rclcpp::publisher::Publisher::SharedPtr + template< + typename MessageT, typename Alloc = std::allocator, + typename PublisherT = ::rclcpp::publisher::Publisher> + std::shared_ptr create_publisher( const std::string & topic_name, size_t qos_history_depth, std::shared_ptr allocator = nullptr); @@ -135,8 +137,10 @@ public: * \param[in] qos_profile The quality of service profile to pass on to the rmw implementation. * \return Shared pointer to the created publisher. */ - template> - typename rclcpp::publisher::Publisher::SharedPtr + template< + typename MessageT, typename Alloc = std::allocator, + typename PublisherT = ::rclcpp::publisher::Publisher> + std::shared_ptr create_publisher( const std::string & topic_name, const rmw_qos_profile_t & qos_profile = rmw_qos_profile_default, diff --git a/rclcpp/include/rclcpp/node_impl.hpp b/rclcpp/include/rclcpp/node_impl.hpp index 654359e..2141096 100644 --- a/rclcpp/include/rclcpp/node_impl.hpp +++ b/rclcpp/include/rclcpp/node_impl.hpp @@ -50,8 +50,8 @@ namespace rclcpp namespace node { -template -typename rclcpp::publisher::Publisher::SharedPtr +template +std::shared_ptr Node::create_publisher( const std::string & topic_name, size_t qos_history_depth, std::shared_ptr allocator) @@ -61,11 +61,11 @@ Node::create_publisher( } rmw_qos_profile_t qos = rmw_qos_profile_default; qos.depth = qos_history_depth; - return this->create_publisher(topic_name, qos, allocator); + return this->create_publisher(topic_name, qos, allocator); } -template -typename publisher::Publisher::SharedPtr +template +std::shared_ptr Node::create_publisher( const std::string & topic_name, const rmw_qos_profile_t & qos_profile, std::shared_ptr allocator) @@ -78,12 +78,12 @@ Node::create_publisher( publisher_options.qos = qos_profile; auto message_alloc = - std::make_shared::MessageAlloc>( + std::make_shared( *allocator.get()); publisher_options.allocator = allocator::get_rcl_allocator( *message_alloc.get()); - auto publisher = publisher::Publisher::make_shared( + auto publisher = std::make_shared( node_handle_, topic_name, publisher_options, message_alloc); if (use_intra_process_comms_) { diff --git a/rclcpp/include/rclcpp/publisher.hpp b/rclcpp/include/rclcpp/publisher.hpp index e0a600b..3904d49 100644 --- a/rclcpp/include/rclcpp/publisher.hpp +++ b/rclcpp/include/rclcpp/publisher.hpp @@ -204,13 +204,12 @@ public: } } - /// Send a message to the topic for this publisher. /** * This function is templated on the input message type, MessageT. * \param[in] msg A shared pointer to the message to send. */ - void + virtual void publish(std::unique_ptr & msg) { this->do_inter_process_publish(msg.get()); @@ -242,7 +241,7 @@ public: } } - void + virtual void publish(const std::shared_ptr & msg) { // Avoid allocating when not using intra process. @@ -261,7 +260,7 @@ public: return this->publish(unique_msg); } - void + virtual void publish(std::shared_ptr msg) { // Avoid allocating when not using intra process. @@ -280,7 +279,7 @@ public: return this->publish(unique_msg); } - void + virtual void publish(const MessageT & msg) { // Avoid allocating when not using intra process.