Skip to content

Commit

Permalink
ported zstd_image_transport to image_transport::node_interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
authaldo committed Feb 11, 2024
1 parent d3041be commit 3a54139
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@

#include <sensor_msgs/msg/image.hpp>
#include <sensor_msgs/msg/compressed_image.hpp>
#include <image_transport/node_interfaces.hpp>
#include <image_transport/simple_publisher_plugin.hpp>

#include <rclcpp/node.hpp>

#include "zstd_image_transport/zstd_common.hpp"

namespace zstd_image_transport
Expand All @@ -62,7 +61,7 @@ class ZstdPublisher : public image_transport::SimplePublisherPlugin<CompressedIm
protected:
// Overridden to set up reconfigure server
void advertiseImpl(
rclcpp::Node * node,
image_transport::NodeInterfaces::SharedPtr node_interfaces,
const std::string & base_topic,
rmw_qos_profile_t custom_qos,
rclcpp::PublisherOptions options) override;
Expand All @@ -72,7 +71,7 @@ class ZstdPublisher : public image_transport::SimplePublisherPlugin<CompressedIm
const PublishFn & publish_fn) const override;

rclcpp::Logger logger_;
rclcpp::Node * node_;
image_transport::NodeInterfaces::SharedPtr node_interfaces_;

private:
std::vector<std::string> parameters_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
#include <string>
#include <vector>

#include <rclcpp/node.hpp>
#include <rclcpp/subscription_options.hpp>

#include <sensor_msgs/msg/image.hpp>
#include <sensor_msgs/msg/compressed_image.hpp>
#include <image_transport/node_interfaces.hpp>
#include <image_transport/simple_subscriber_plugin.hpp>

#include "zstd_image_transport/zstd_common.hpp"
Expand All @@ -62,7 +62,7 @@ class ZstdSubscriber final

protected:
void subscribeImpl(
rclcpp::Node *,
image_transport::NodeInterfaces::SharedPtr node_interfaces,
const std::string & base_topic,
const Callback & callback,
rmw_qos_profile_t custom_qos,
Expand All @@ -73,7 +73,7 @@ class ZstdSubscriber final
const Callback & user_cb) override;

rclcpp::Logger logger_;
rclcpp::Node * node_;
image_transport::NodeInterfaces::SharedPtr node_interfaces_;
};

} // namespace zstd_image_transport
Expand Down
15 changes: 8 additions & 7 deletions zstd_image_transport/src/zstd_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,18 @@ std::string ZstdPublisher::getTransportName() const
}

void ZstdPublisher::advertiseImpl(
rclcpp::Node * node,
image_transport::NodeInterfaces::SharedPtr node_interfaces,
const std::string & base_topic,
rmw_qos_profile_t custom_qos,
rclcpp::PublisherOptions options)
{
node_ = node;
node_interfaces_ = node_interfaces;
typedef image_transport::SimplePublisherPlugin<sensor_msgs::msg::CompressedImage> Base;
Base::advertiseImpl(node, base_topic, custom_qos, options);
Base::advertiseImpl(node_interfaces_, base_topic, custom_qos, options);

// Declare Parameters
uint ns_len = node->get_effective_namespace().length();
// TODO: original implementation uses get_effective_namespace of rclcpp::Node
uint ns_len = strlen(node_interfaces_->base->get_namespace());
std::string param_base_name = base_topic.substr(ns_len);
std::replace(param_base_name.begin(), param_base_name.end(), '/', '.');

Expand All @@ -97,7 +98,7 @@ void ZstdPublisher::publish(
const PublishFn & publish_fn) const
{
// Fresh Configuration
int cfg_zstd_level = node_->get_parameter(parameters_[ZSTD_LEVEL]).get_value<int64_t>();
int cfg_zstd_level = node_interfaces_->parameters->get_parameter(parameters_[ZSTD_LEVEL]).get_value<int64_t>();

zlib::Comp comp(static_cast<zlib::Comp::Level>(cfg_zstd_level), true);
auto g_compressed_data =
Expand Down Expand Up @@ -163,12 +164,12 @@ void ZstdPublisher::declareParameter(
rclcpp::ParameterValue param_value;

try {
param_value = node_->declare_parameter(
param_value = node_interfaces_->parameters->declare_parameter(
param_name, definition.defaultValue,
definition.descriptor);
} catch (const rclcpp::exceptions::ParameterAlreadyDeclaredException &) {
RCLCPP_DEBUG(logger_, "%s was previously declared", definition.descriptor.name.c_str());
param_value = node_->get_parameter(param_name).get_parameter_value();
param_value = node_interfaces_->parameters->get_parameter(param_name).get_parameter_value();
}
}
} // namespace zstd_image_transport
8 changes: 4 additions & 4 deletions zstd_image_transport/src/zstd_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ std::string ZstdSubscriber::getTransportName() const
}

void ZstdSubscriber::subscribeImpl(
rclcpp::Node * node,
image_transport::NodeInterfaces::SharedPtr node_interfaces,
const std::string & base_topic,
const Callback & callback,
rmw_qos_profile_t custom_qos,
rclcpp::SubscriptionOptions options)
{
node_ = node;
logger_ = node->get_logger();
node_interfaces_ = node_interfaces;
logger_ = node_interfaces_->logging->get_logger();
typedef image_transport::SimpleSubscriberPlugin<sensor_msgs::msg::CompressedImage> Base;
Base::subscribeImpl(node, base_topic, callback, custom_qos, options);
Base::subscribeImpl(node_interfaces_, base_topic, callback, custom_qos, options);
}

void ZstdSubscriber::internalCallback(
Expand Down

0 comments on commit 3a54139

Please sign in to comment.