From 8b87df689273d5090f314943f74dce40e5fe5f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Wed, 14 Feb 2024 15:46:00 +0100 Subject: [PATCH] Fixed clang issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alejandro Hernández Cordero --- .../point_cloud_transport.hpp | 8 +++---- .../publisher_plugin.hpp | 4 +++- .../point_cloud_transport/raw_publisher.hpp | 10 ++++---- .../point_cloud_transport/raw_subscriber.hpp | 2 +- .../simple_publisher_plugin.hpp | 23 ++++++++++++++++++- point_cloud_transport/src/publisher.cpp | 2 +- .../src/publisher_plugin.cpp | 2 +- point_cloud_transport/src/republish.cpp | 2 +- 8 files changed, 38 insertions(+), 15 deletions(-) diff --git a/point_cloud_transport/include/point_cloud_transport/point_cloud_transport.hpp b/point_cloud_transport/include/point_cloud_transport/point_cloud_transport.hpp index 2e8fc72..239d6cf 100644 --- a/point_cloud_transport/include/point_cloud_transport/point_cloud_transport.hpp +++ b/point_cloud_transport/include/point_cloud_transport/point_cloud_transport.hpp @@ -264,12 +264,12 @@ class PointCloudTransport : public PointCloudTransportLoader const std::string & base_topic, rmw_qos_profile_t custom_qos, void (T::* fp)(const sensor_msgs::msg::PointCloud2::ConstSharedPtr &) const, T * obj, const point_cloud_transport::TransportHints * transport_hints = nullptr, - bool allow_concurrent_callbacks = false) + bool /*allow_concurrent_callbacks*/ = false) { return subscribe( base_topic, custom_qos, std::bind( fp, - obj.get(), std::placeholders::_1), VoidPtr(), transport_hints); + obj, std::placeholders::_1), VoidPtr(), transport_hints); } template @@ -277,12 +277,12 @@ class PointCloudTransport : public PointCloudTransportLoader const std::string & base_topic, uint32_t queue_size, void (T::* fp)(const sensor_msgs::msg::PointCloud2::ConstSharedPtr &) const, T * obj, const point_cloud_transport::TransportHints * transport_hints = nullptr, - bool allow_concurrent_callbacks = false) + bool /*allow_concurrent_callbacks*/ = false) { return subscribe( base_topic, queue_size, std::bind( fp, - obj.get(), std::placeholders::_1), VoidPtr(), transport_hints); + obj, std::placeholders::_1), VoidPtr(), transport_hints); } //! Subscribe to a point cloud topic, version for class member function with shared_ptr. diff --git a/point_cloud_transport/include/point_cloud_transport/publisher_plugin.hpp b/point_cloud_transport/include/point_cloud_transport/publisher_plugin.hpp index f845599..46f5659 100644 --- a/point_cloud_transport/include/point_cloud_transport/publisher_plugin.hpp +++ b/point_cloud_transport/include/point_cloud_transport/publisher_plugin.hpp @@ -59,6 +59,8 @@ class PublisherPlugin PublisherPlugin(const PublisherPlugin &) = delete; PublisherPlugin & operator=(const PublisherPlugin &) = delete; + virtual ~PublisherPlugin() {} + //! Get a string identifier for the transport provided by this plugin virtual std::string getTransportName() const = 0; @@ -92,7 +94,7 @@ class PublisherPlugin //! Publish a point cloud using the transport associated with this PublisherPlugin. POINT_CLOUD_TRANSPORT_PUBLIC - virtual void publish(const sensor_msgs::msg::PointCloud2::ConstSharedPtr & message) const; + virtual void publishPtr(const sensor_msgs::msg::PointCloud2::ConstSharedPtr & message) const; //! Shutdown any advertisements associated with this PublisherPlugin. virtual void shutdown() = 0; diff --git a/point_cloud_transport/include/point_cloud_transport/raw_publisher.hpp b/point_cloud_transport/include/point_cloud_transport/raw_publisher.hpp index db2c4dc..d903761 100644 --- a/point_cloud_transport/include/point_cloud_transport/raw_publisher.hpp +++ b/point_cloud_transport/include/point_cloud_transport/raw_publisher.hpp @@ -51,7 +51,7 @@ class RawPublisher public: virtual ~RawPublisher() {} - virtual std::string getTransportName() const + virtual std::string getTransportName() const override { return "raw"; } @@ -65,7 +65,7 @@ class RawPublisher { } - RawPublisher::TypedEncodeResult encodeTyped(const sensor_msgs::msg::PointCloud2 & raw) const + RawPublisher::TypedEncodeResult encodeTyped(const sensor_msgs::msg::PointCloud2 & raw) const override { return raw; } @@ -73,19 +73,19 @@ class RawPublisher protected: virtual void publish( const sensor_msgs::msg::PointCloud2 & message, - const PublishFn & publish_fn) const + const PublishFn & publish_fn) const override { publish_fn(message); } virtual void publish( const sensor_msgs::msg::PointCloud2::ConstSharedPtr & message_ptr, - const PublishFn & publish_fn) const + const PublishFn & publish_fn) const override { publish_fn(*message_ptr); } - virtual std::string getTopicToAdvertise(const std::string & base_topic) const + virtual std::string getTopicToAdvertise(const std::string & base_topic) const override { return base_topic; } diff --git a/point_cloud_transport/include/point_cloud_transport/raw_subscriber.hpp b/point_cloud_transport/include/point_cloud_transport/raw_subscriber.hpp index 89b8c59..3f4aac2 100644 --- a/point_cloud_transport/include/point_cloud_transport/raw_subscriber.hpp +++ b/point_cloud_transport/include/point_cloud_transport/raw_subscriber.hpp @@ -62,7 +62,7 @@ class RawSubscriber POINT_CLOUD_TRANSPORT_PUBLIC SubscriberPlugin::DecodeResult decodeTyped( - const sensor_msgs::msg::PointCloud2 & compressed) const; + const sensor_msgs::msg::PointCloud2 & compressed) const override; POINT_CLOUD_TRANSPORT_PUBLIC std::string getDataType() const override; diff --git a/point_cloud_transport/include/point_cloud_transport/simple_publisher_plugin.hpp b/point_cloud_transport/include/point_cloud_transport/simple_publisher_plugin.hpp index a5f850f..445b4bc 100644 --- a/point_cloud_transport/include/point_cloud_transport/simple_publisher_plugin.hpp +++ b/point_cloud_transport/include/point_cloud_transport/simple_publisher_plugin.hpp @@ -199,7 +199,7 @@ class SimplePublisherPlugin : public point_cloud_transport::PublisherPlugin virtual void advertiseImpl( std::shared_ptr node, const std::string & base_topic, rmw_qos_profile_t custom_qos, - const rclcpp::PublisherOptions & options) + const rclcpp::PublisherOptions & options) override { std::string transport_topic = getTopicToAdvertise(base_topic); simple_impl_ = std::make_unique(node); @@ -237,6 +237,27 @@ class SimplePublisherPlugin : public point_cloud_transport::PublisherPlugin } } + /// + /// \brief Publish a point cloud using the specified publish function. + /// + /// The PublishFn publishes the transport-specific message type. This indirection allows + /// SimplePublisherPlugin to use this function for both normal broadcast publishing and + /// single subscriber publishing (in subscription callbacks). + /// + virtual void publish( + const sensor_msgs::msg::PointCloud2::ConstSharedPtr & message, + const PublishFn & publish_fn) const + { + const auto res = this->encodeTyped(*message.get()); + if (!res) { + RCLCPP_ERROR( + this->getLogger(), "Error encoding message by transport %s: %s.", + this->getTransportName().c_str(), res.error().c_str()); + } else if (res.value()) { + publish_fn(res.value().value()); + } + } + /// /// \brief Return the communication topic name for a given base topic. /// diff --git a/point_cloud_transport/src/publisher.cpp b/point_cloud_transport/src/publisher.cpp index c6ba16e..deac37c 100644 --- a/point_cloud_transport/src/publisher.cpp +++ b/point_cloud_transport/src/publisher.cpp @@ -209,7 +209,7 @@ void Publisher::publish(const sensor_msgs::msg::PointCloud2::ConstSharedPtr & me for (const auto & pub : impl_->publishers_) { if (pub->getNumSubscribers() > 0) { - pub->publish(message); + pub->publishPtr(message); } } } diff --git a/point_cloud_transport/src/publisher_plugin.cpp b/point_cloud_transport/src/publisher_plugin.cpp index 62d8514..f6df1d7 100644 --- a/point_cloud_transport/src/publisher_plugin.cpp +++ b/point_cloud_transport/src/publisher_plugin.cpp @@ -53,7 +53,7 @@ void PublisherPlugin::advertise( advertiseImpl(node, base_topic, custom_qos, options); } -void PublisherPlugin::publish(const sensor_msgs::msg::PointCloud2::ConstSharedPtr & message) const +void PublisherPlugin::publishPtr(const sensor_msgs::msg::PointCloud2::ConstSharedPtr & message) const { publish(*message); } diff --git a/point_cloud_transport/src/republish.cpp b/point_cloud_transport/src/republish.cpp index b7e8666..a452d04 100644 --- a/point_cloud_transport/src/republish.cpp +++ b/point_cloud_transport/src/republish.cpp @@ -147,7 +147,7 @@ void Republisher::initialize() typedef void (point_cloud_transport::PublisherPlugin::* PublishMemFn)( const sensor_msgs::msg:: PointCloud2::ConstSharedPtr &) const; - PublishMemFn pub_mem_fn = &point_cloud_transport::PublisherPlugin::publish; + PublishMemFn pub_mem_fn = &point_cloud_transport::PublisherPlugin::publishPtr; RCLCPP_INFO(this->get_logger(), "Loading %s subscriber", in_topic.c_str());