Skip to content

Commit

Permalink
PublisherBase and SubscriptionBase API change
Browse files Browse the repository at this point in the history
APIs we're using changed in ros2/rclcpp#2066
which is released in RCLCPP 18.0.0 in ROS ROlling. This PR uses the updated API.
  • Loading branch information
sloretz committed Feb 1, 2023
1 parent 7c14298 commit 8e9d2f8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
17 changes: 14 additions & 3 deletions drake_ros_core/src/publisher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include <string>

#include <rclcpp/version.h>

namespace drake_ros_core {
namespace internal {
namespace {
Expand All @@ -29,11 +31,20 @@ rcl_publisher_options_t publisher_options(const rclcpp::QoS& qos) {

Publisher::Publisher(rclcpp::node_interfaces::NodeBaseInterface* node_base,
const rosidl_message_type_support_t& type_support,
const std::string& topic_name, const rclcpp::QoS& qos)
const std::string& topic_name, const rclcpp::QoS& qos,
const rclcpp::PublisherOptionsBase& options)
#if RCLCPP_VERSION_GTE(18, 0, 0)
: rclcpp::PublisherBase(node_base, topic_name, type_support,
publisher_options(qos), options.event_callbacks,
options.use_default_callbacks){}
#else
: rclcpp::PublisherBase(node_base, topic_name, type_support,
publisher_options(qos)) {}
publisher_options(qos)) {
}
#endif

Publisher::~Publisher() {}
Publisher::~Publisher() {
}

void Publisher::publish(const rclcpp::SerializedMessage& serialized_msg) {
// TODO(sloretz) Copied from rosbag2_transport GenericPublisher, can it be
Expand Down
9 changes: 8 additions & 1 deletion drake_ros_core/src/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <string>

#include <rclcpp/publisher_base.hpp>
#include <rclcpp/publisher_options.hpp>
#include <rclcpp/qos.hpp>
#include <rclcpp/serialized_message.hpp>
#include <rosidl_runtime_c/message_type_support_struct.h>
Expand All @@ -29,7 +30,13 @@ class Publisher final : public rclcpp::PublisherBase {
public:
Publisher(rclcpp::node_interfaces::NodeBaseInterface* node_base,
const rosidl_message_type_support_t& ts,
const std::string& topic_name, const rclcpp::QoS& qos);
const std::string& topic_name, const rclcpp::QoS& qos)
: Publisher(node_base, ts, topic_name, qos, {}) {}

Publisher(rclcpp::node_interfaces::NodeBaseInterface* node_base,
const rosidl_message_type_support_t& ts,
const std::string& topic_name, const rclcpp::QoS& qos,
const rclcpp::PublisherOptionsBase& options);

~Publisher();

Expand Down
18 changes: 15 additions & 3 deletions drake_ros_core/src/subscription.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <memory>
#include <string>

#include <rclcpp/version.h>

namespace drake_ros_core {
namespace internal {
namespace {
Expand All @@ -32,12 +34,22 @@ Subscription::Subscription(
rclcpp::node_interfaces::NodeBaseInterface* node_base,
const rosidl_message_type_support_t& ts, const std::string& topic_name,
const rclcpp::QoS& qos,
std::function<void(std::shared_ptr<rclcpp::SerializedMessage>)> callback)
std::function<void(std::shared_ptr<rclcpp::SerializedMessage>)> callback,
const rclcpp::SubscriptionOptionsBase& options)
#if RCLCPP_VERSION_GTE(18, 0, 0)
: rclcpp::SubscriptionBase(
node_base, ts, topic_name, subscription_options(qos),
options.event_callbacks, options.use_default_callbacks, true),
callback_(callback){}
#else
: rclcpp::SubscriptionBase(node_base, ts, topic_name,
subscription_options(qos), true),
callback_(callback) {}
callback_(callback) {
}
#endif

Subscription::~Subscription() {}
Subscription::~Subscription() {
}

std::shared_ptr<void> Subscription::create_message() {
// Subscriber only does serialized messages
Expand Down
15 changes: 12 additions & 3 deletions drake_ros_core/src/subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
#include <memory>
#include <string>

#include "rclcpp/qos.hpp"
#include "rclcpp/subscription_base.hpp"
#include <rclcpp/qos.hpp>
#include <rclcpp/subscription_base.hpp>
#include <rclcpp/subscription_options.hpp>
#include <rmw/serialized_message.h>
#include <rosidl_runtime_c/message_type_support_struct.h>

Expand All @@ -31,7 +32,15 @@ class Subscription final : public rclcpp::SubscriptionBase {
rclcpp::node_interfaces::NodeBaseInterface* node_base,
const rosidl_message_type_support_t& ts, const std::string& topic_name,
const rclcpp::QoS& qos,
std::function<void(std::shared_ptr<rclcpp::SerializedMessage>)> callback);
std::function<void(std::shared_ptr<rclcpp::SerializedMessage>)> callback)
: Subscription(node_base, ts, topic_name, qos, callback, {}) {}

Subscription(
rclcpp::node_interfaces::NodeBaseInterface* node_base,
const rosidl_message_type_support_t& ts, const std::string& topic_name,
const rclcpp::QoS& qos,
std::function<void(std::shared_ptr<rclcpp::SerializedMessage>)> callback,
const rclcpp::SubscriptionOptionsBase& options);

~Subscription();

Expand Down

0 comments on commit 8e9d2f8

Please sign in to comment.