Skip to content

Commit ecb81ef

Browse files
author
Abrar Rahman Protyasha
authored
Deprecate the void shared_ptr<MessageT> subscription callback signatures (#1713)
* Deprecated `shared_ptr<MessageT>` sub callbacks Addresses #1619. Signed-off-by: Abrar Rahman Protyasha <[email protected]> * Resolve deprecated subscription callbacks in tests Specifically, `void shared_ptr<MessageT>` subscription callbacks have been migrated to `void shared_ptr<const MessageT>` subscription callbacks. This change has been performed only on the test files that do not actually house unit tests for the `AnySubscriptionCallback` class. For unit tests that actually target the deprecated `set` functions, the deprecation warnings have to be avoided. This patch will be introduced in a separate commit. Signed-off-by: Abrar Rahman Protyasha <[email protected]> * Suppress deprecation warnings in unit tests This commit specifically introduces suppression of the deprecation warnings produced while compiling unit tests for the `AnySubscriptionCallback` class. The macro mechanics to conditionally include the `deprecated` attribute is not ideal, but the diagnostic pragma solution (`# pragma GCC diagnostic ignored`) did not work for these unit tests, possibly because of the way gtest is initializing the necessary `InstanceContext` objects. A `TODO` directive has been left to figure out a better way to address this warning suppression. Signed-off-by: Abrar Rahman Protyasha <[email protected]> * Fix shared ptr callback in wait_for_message Moving away from deprecated signatures. Signed-off-by: Abrar Rahman Protyasha <[email protected]> * `rclcpp_action`: Fix deprecated subscr. callbacks Signed-off-by: Abrar Rahman Protyasha <[email protected]> * `rclcpp_lifecycle`: Fix deprecated sub callbacks Signed-off-by: Abrar Rahman Protyasha <[email protected]>
1 parent d0cd6bb commit ecb81ef

File tree

8 files changed

+29
-25
lines changed

8 files changed

+29
-25
lines changed

rclcpp/include/rclcpp/any_subscription_callback.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,10 @@ class AnySubscriptionCallback
406406

407407
/// Function for shared_ptr to non-const MessageT, which is deprecated.
408408
template<typename SetT>
409-
// TODO(wjwwood): enable this deprecation after Galactic
410-
// [[deprecated(
411-
// "use 'void (std::shared_ptr<const MessageT>)' instead"
412-
// )]]
409+
#if !defined(RCLCPP_AVOID_DEPRECATIONS_FOR_UNIT_TESTS)
410+
// suppress deprecation warnings in `test_any_subscription_callback.cpp`
411+
[[deprecated("use 'void(std::shared_ptr<const MessageT>)' instead")]]
412+
#endif
413413
void
414414
set_deprecated(std::function<void(std::shared_ptr<SetT>)> callback)
415415
{
@@ -418,10 +418,12 @@ class AnySubscriptionCallback
418418

419419
/// Function for shared_ptr to non-const MessageT with MessageInfo, which is deprecated.
420420
template<typename SetT>
421-
// TODO(wjwwood): enable this deprecation after Galactic
422-
// [[deprecated(
423-
// "use 'void (std::shared_ptr<const MessageT>, const rclcpp::MessageInfo &)' instead"
424-
// )]]
421+
#if !defined(RCLCPP_AVOID_DEPRECATIONS_FOR_UNIT_TESTS)
422+
// suppress deprecation warnings in `test_any_subscription_callback.cpp`
423+
[[deprecated(
424+
"use 'void(std::shared_ptr<const MessageT>, const rclcpp::MessageInfo &)' instead"
425+
)]]
426+
#endif
425427
void
426428
set_deprecated(std::function<void(std::shared_ptr<SetT>, const rclcpp::MessageInfo &)> callback)
427429
{

rclcpp/include/rclcpp/wait_for_message.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ bool wait_for_message(
9090
const std::string & topic,
9191
std::chrono::duration<Rep, Period> time_to_wait = std::chrono::duration<Rep, Period>(-1))
9292
{
93-
auto sub = node->create_subscription<MsgT>(topic, 1, [](const std::shared_ptr<MsgT>) {});
93+
auto sub = node->create_subscription<MsgT>(topic, 1, [](const std::shared_ptr<const MsgT>) {});
9494
return wait_for_message<MsgT, Rep, Period>(
9595
out, sub, node->get_node_options().context(), time_to_wait);
9696
}

rclcpp/test/rclcpp/test_any_subscription_callback.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <string>
2020
#include <utility>
2121

22+
// TODO(aprotyas): Figure out better way to suppress deprecation warnings.
23+
#define RCLCPP_AVOID_DEPRECATIONS_FOR_UNIT_TESTS 1
2224
#include "rclcpp/any_subscription_callback.hpp"
2325
#include "test_msgs/msg/empty.hpp"
2426
#include "test_msgs/msg/empty.h"

rclcpp/test/rclcpp/test_generic_pubsub.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ TEST_F(RclcppGenericNodeFixture, generic_publisher_uses_qos)
187187
auto publisher = node_->create_generic_publisher(topic_name, topic_type, qos);
188188
auto subscription = node_->create_subscription<test_msgs::msg::Strings>(
189189
topic_name, qos,
190-
[](std::shared_ptr<test_msgs::msg::Strings>/* message */) {});
190+
[](std::shared_ptr<const test_msgs::msg::Strings>/* message */) {});
191191
auto connected = [publisher, subscription]() -> bool {
192192
return publisher->get_subscription_count() && subscription->get_publisher_count();
193193
};

rclcpp/test/rclcpp/test_publisher_with_type_adapter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ TEST_F(
191191

192192
auto callback =
193193
[message_data, &is_received](
194-
const rclcpp::msg::String::SharedPtr msg,
194+
const rclcpp::msg::String::ConstSharedPtr msg,
195195
const rclcpp::MessageInfo & message_info
196196
) -> void
197197
{

rclcpp/test/rclcpp/test_subscription.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ INSTANTIATE_TEST_SUITE_P(
510510
TEST_F(TestSubscription, get_network_flow_endpoints_errors) {
511511
initialize();
512512
const rclcpp::QoS subscription_qos(1);
513-
auto subscription_callback = [](test_msgs::msg::Empty::SharedPtr msg) {
513+
auto subscription_callback = [](test_msgs::msg::Empty::ConstSharedPtr msg) {
514514
(void)msg;
515515
};
516516
auto subscription = node->create_subscription<test_msgs::msg::Empty>(

rclcpp_action/test/test_server.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,10 @@ TEST_F(TestServer, publish_status_accepted)
485485
(void)as;
486486

487487
// Subscribe to status messages
488-
std::vector<action_msgs::msg::GoalStatusArray::SharedPtr> received_msgs;
488+
std::vector<action_msgs::msg::GoalStatusArray::ConstSharedPtr> received_msgs;
489489
auto subscriber = node->create_subscription<action_msgs::msg::GoalStatusArray>(
490490
"fibonacci/_action/status", 10,
491-
[&received_msgs](action_msgs::msg::GoalStatusArray::SharedPtr list)
491+
[&received_msgs](action_msgs::msg::GoalStatusArray::ConstSharedPtr list)
492492
{
493493
received_msgs.push_back(list);
494494
});
@@ -548,10 +548,10 @@ TEST_F(TestServer, publish_status_canceling)
548548
(void)as;
549549

550550
// Subscribe to status messages
551-
std::vector<action_msgs::msg::GoalStatusArray::SharedPtr> received_msgs;
551+
std::vector<action_msgs::msg::GoalStatusArray::ConstSharedPtr> received_msgs;
552552
auto subscriber = node->create_subscription<action_msgs::msg::GoalStatusArray>(
553553
"fibonacci/_action/status", 10,
554-
[&received_msgs](action_msgs::msg::GoalStatusArray::SharedPtr list)
554+
[&received_msgs](action_msgs::msg::GoalStatusArray::ConstSharedPtr list)
555555
{
556556
received_msgs.push_back(list);
557557
});
@@ -605,10 +605,10 @@ TEST_F(TestServer, publish_status_canceled)
605605
(void)as;
606606

607607
// Subscribe to status messages
608-
std::vector<action_msgs::msg::GoalStatusArray::SharedPtr> received_msgs;
608+
std::vector<action_msgs::msg::GoalStatusArray::ConstSharedPtr> received_msgs;
609609
auto subscriber = node->create_subscription<action_msgs::msg::GoalStatusArray>(
610610
"fibonacci/_action/status", 10,
611-
[&received_msgs](action_msgs::msg::GoalStatusArray::SharedPtr list)
611+
[&received_msgs](action_msgs::msg::GoalStatusArray::ConstSharedPtr list)
612612
{
613613
received_msgs.push_back(list);
614614
});
@@ -664,10 +664,10 @@ TEST_F(TestServer, publish_status_succeeded)
664664
(void)as;
665665

666666
// Subscribe to status messages
667-
std::vector<action_msgs::msg::GoalStatusArray::SharedPtr> received_msgs;
667+
std::vector<action_msgs::msg::GoalStatusArray::ConstSharedPtr> received_msgs;
668668
auto subscriber = node->create_subscription<action_msgs::msg::GoalStatusArray>(
669669
"fibonacci/_action/status", 10,
670-
[&received_msgs](action_msgs::msg::GoalStatusArray::SharedPtr list)
670+
[&received_msgs](action_msgs::msg::GoalStatusArray::ConstSharedPtr list)
671671
{
672672
received_msgs.push_back(list);
673673
});
@@ -721,10 +721,10 @@ TEST_F(TestServer, publish_status_aborted)
721721
(void)as;
722722

723723
// Subscribe to status messages
724-
std::vector<action_msgs::msg::GoalStatusArray::SharedPtr> received_msgs;
724+
std::vector<action_msgs::msg::GoalStatusArray::ConstSharedPtr> received_msgs;
725725
auto subscriber = node->create_subscription<action_msgs::msg::GoalStatusArray>(
726726
"fibonacci/_action/status", 10,
727-
[&received_msgs](action_msgs::msg::GoalStatusArray::SharedPtr list)
727+
[&received_msgs](action_msgs::msg::GoalStatusArray::ConstSharedPtr list)
728728
{
729729
received_msgs.push_back(list);
730730
});
@@ -779,9 +779,9 @@ TEST_F(TestServer, publish_feedback)
779779

780780
// Subscribe to feedback messages
781781
using FeedbackT = Fibonacci::Impl::FeedbackMessage;
782-
std::vector<FeedbackT::SharedPtr> received_msgs;
782+
std::vector<FeedbackT::ConstSharedPtr> received_msgs;
783783
auto subscriber = node->create_subscription<FeedbackT>(
784-
"fibonacci/_action/feedback", 10, [&received_msgs](FeedbackT::SharedPtr msg)
784+
"fibonacci/_action/feedback", 10, [&received_msgs](FeedbackT::ConstSharedPtr msg)
785785
{
786786
received_msgs.push_back(msg);
787787
});

rclcpp_lifecycle/test/test_lifecycle_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ TEST_F(TestDefaultStateMachine, bad_mood) {
416416
TEST_F(TestDefaultStateMachine, lifecycle_subscriber) {
417417
auto test_node = std::make_shared<MoodyLifecycleNode<GoodMood>>("testnode");
418418

419-
auto cb = [](const std::shared_ptr<lifecycle_msgs::msg::State> msg) {(void) msg;};
419+
auto cb = [](const std::shared_ptr<const lifecycle_msgs::msg::State> msg) {(void) msg;};
420420
auto lifecycle_sub =
421421
test_node->create_subscription<lifecycle_msgs::msg::State>("~/empty", 10, cb);
422422

0 commit comments

Comments
 (0)