From 911b2206bb53b9fe01c4ffed382a52159832018d Mon Sep 17 00:00:00 2001 From: NirAz Date: Tue, 22 Nov 2022 17:26:43 +0200 Subject: [PATCH] fix deprecated API --- realsense2_camera/CMakeLists.txt | 2 +- .../include/base_realsense_node.h | 6 ++++++ realsense2_camera/include/ros_param_backend.h | 10 ++++++++- .../src/ros_param_backend_dashing.cpp | 2 +- .../src/ros_param_backend_foxy.cpp | 2 +- .../src/ros_param_backend_rolling.cpp | 21 +++++++++++++++++++ 6 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 realsense2_camera/src/ros_param_backend_rolling.cpp diff --git a/realsense2_camera/CMakeLists.txt b/realsense2_camera/CMakeLists.txt index 89c11ada74..84de9fd5dc 100644 --- a/realsense2_camera/CMakeLists.txt +++ b/realsense2_camera/CMakeLists.txt @@ -156,7 +156,7 @@ elseif("$ENV{ROS_DISTRO}" STREQUAL "humble") elseif("$ENV{ROS_DISTRO}" STREQUAL "rolling") message(STATUS "Build for ROS2 Rolling") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DROLLING") - set(SOURCES "${SOURCES}" src/ros_param_backend_foxy.cpp) + set(SOURCES "${SOURCES}" src/ros_param_backend_rolling.cpp) else() message(FATAL_ERROR "Unsupported ROS Distribution: " "$ENV{ROS_DISTRO}") endif() diff --git a/realsense2_camera/include/base_realsense_node.h b/realsense2_camera/include/base_realsense_node.h index 934f81ef2f..4a88f9496e 100755 --- a/realsense2_camera/include/base_realsense_node.h +++ b/realsense2_camera/include/base_realsense_node.h @@ -6,7 +6,13 @@ #include #include #include "constants.h" + +// cv_bridge.h last supported version is humble +#if defined(ROLLING) +#include +#else #include +#endif #include #include diff --git a/realsense2_camera/include/ros_param_backend.h b/realsense2_camera/include/ros_param_backend.h index 74b70b95e3..aba3423cb8 100644 --- a/realsense2_camera/include/ros_param_backend.h +++ b/realsense2_camera/include/ros_param_backend.h @@ -15,7 +15,15 @@ namespace realsense2_camera _logger(node.get_logger()) {}; ~ParametersBackend(); - void add_on_set_parameters_callback(rclcpp::node_interfaces::NodeParametersInterface::OnParametersSetCallbackType callback); + + + #if defined( ROLLING ) + using ros2_param_callback_type = rclcpp::node_interfaces::NodeParametersInterface::OnSetParametersCallbackType; + #else + using ros2_param_callback_type = rclcpp::node_interfaces::NodeParametersInterface::OnParametersSetCallbackType; + #endif + + void add_on_set_parameters_callback(ros2_param_callback_type callback); private: diff --git a/realsense2_camera/src/ros_param_backend_dashing.cpp b/realsense2_camera/src/ros_param_backend_dashing.cpp index b76ff63e77..4afdb53b23 100644 --- a/realsense2_camera/src/ros_param_backend_dashing.cpp +++ b/realsense2_camera/src/ros_param_backend_dashing.cpp @@ -5,7 +5,7 @@ namespace realsense2_camera { - void ParametersBackend::add_on_set_parameters_callback(rclcpp::node_interfaces::NodeParametersInterface::OnParametersSetCallbackType callback) + void ParametersBackend::add_on_set_parameters_callback(ros2_param_callback_type callback) { rclcpp::Node::OnParametersSetCallbackType prev_callback = _node.set_on_parameters_set_callback(callback); if (prev_callback) diff --git a/realsense2_camera/src/ros_param_backend_foxy.cpp b/realsense2_camera/src/ros_param_backend_foxy.cpp index a36766b5b8..daceb7e171 100644 --- a/realsense2_camera/src/ros_param_backend_foxy.cpp +++ b/realsense2_camera/src/ros_param_backend_foxy.cpp @@ -5,7 +5,7 @@ namespace realsense2_camera { - void ParametersBackend::add_on_set_parameters_callback(rclcpp::node_interfaces::NodeParametersInterface::OnParametersSetCallbackType callback) + void ParametersBackend::add_on_set_parameters_callback(ros2_param_callback_type callback) { _ros_callback = _node.add_on_set_parameters_callback(callback); } diff --git a/realsense2_camera/src/ros_param_backend_rolling.cpp b/realsense2_camera/src/ros_param_backend_rolling.cpp new file mode 100644 index 0000000000..daceb7e171 --- /dev/null +++ b/realsense2_camera/src/ros_param_backend_rolling.cpp @@ -0,0 +1,21 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2022 Intel Corporation. All Rights Reserved. + +#include "ros_param_backend.h" + +namespace realsense2_camera +{ + void ParametersBackend::add_on_set_parameters_callback(ros2_param_callback_type callback) + { + _ros_callback = _node.add_on_set_parameters_callback(callback); + } + + ParametersBackend::~ParametersBackend() + { + if (_ros_callback) + { + _node.remove_on_set_parameters_callback((rclcpp::node_interfaces::OnSetParametersCallbackHandle*)(_ros_callback.get())); + _ros_callback.reset(); + } + } +}