Skip to content

Commit 63e6e28

Browse files
authored
Replace rosbag2_cpp typesupport helpers with rclcpp typesupport helpers (#105)
* use rclcpp type support helpers instead of rosbag2_cpp ones Signed-off-by: Dominik Authaler <dominik.authaler@uni-ulm.de> * use rclcpp::get_message_typesupport_handle instead of deprecated rclcpp::get_typesupport_handle Signed-off-by: Dominik Authaler <dominik.authaler@uni-ulm.de> * fixed minor unused warnings Signed-off-by: Dominik Authaler <dominik.authaler@uni-ulm.de> * fix humble compatibility using typesupport wrapper Signed-off-by: Dominik Authaler <dominik.authaler@uni-ulm.de> * clang-format Signed-off-by: Dominik Authaler <dominik.authaler@uni-ulm.de> --------- Signed-off-by: Dominik Authaler <dominik.authaler@uni-ulm.de>
1 parent e88cef2 commit 63e6e28

7 files changed

Lines changed: 74 additions & 16 deletions

File tree

src/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ QT5_WRAP_UI ( COMMON_UI_SRC
1010

1111

1212
add_library( commonROS STATIC
13-
dialog_select_ros_topics.h
13+
dialog_select_ros_topics.h
1414
dialog_select_ros_topics.cpp
1515
dialog_with_itemlist.h
1616
publisher_select_dialog.h
1717
parser_configuration.cpp
1818
parser_configuration.h
1919
ros_parsers/ros2_parser.cpp
20+
typesupport_wrapper.cpp
2021
${COMMON_UI_SRC}
2122
)
2223

@@ -51,6 +52,7 @@ if("$ENV{ROS_DISTRO}" STREQUAL "humble")
5152
message(STATUS "Detected Humble")
5253
target_compile_definitions(DataLoadROS2 PUBLIC ROS_HUMBLE)
5354
target_compile_definitions(TopicPublisherROS2 PUBLIC ROS_HUMBLE)
55+
target_compile_definitions(commonROS PUBLIC ROS_HUMBLE)
5456
endif()
5557

5658
#######################################################################

src/DataLoadROS2/dataload_ros2.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <rosidl_typesupport_introspection_cpp/message_introspection.hpp>
1818
#include <rosidl_typesupport_introspection_cpp/field_types.hpp>
1919
#include <rosidl_typesupport_cpp/identifier.hpp>
20-
#include <rosbag2_cpp/typesupport_helpers.hpp>
2120
#include <rosbag2_cpp/types/introspection_message.hpp>
2221
#include <unordered_map>
2322
#include <rclcpp/rclcpp.hpp>
@@ -94,7 +93,6 @@ bool DataLoadROS2::readDataFromFile(PJ::FileLoadInfo* info, PJ::PlotDataMapRef&
9493
all_topics_qt.push_back({ QString::fromStdString(topic.name), QString::fromStdString(topic.type) });
9594
topicTypesByName.emplace(topic.name, topic.type);
9695

97-
const auto& typesupport_identifier = rosidl_typesupport_cpp::typesupport_identifier;
9896
try
9997
{
10098
topics_info.emplace_back(CreateTopicInfo(topic.name, topic.type));

src/TopicPublisherROS2/generic_publisher.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <rclcpp/rclcpp.hpp>
2121
#include <rclcpp/publisher_base.hpp>
2222

23+
#include "typesupport_wrapper.h"
24+
2325
class GenericPublisher : public rclcpp::PublisherBase
2426
{
2527
public:
@@ -48,8 +50,8 @@ class GenericPublisher : public rclcpp::PublisherBase
4850
static std::shared_ptr<GenericPublisher> create(rclcpp::Node& node, const std::string& topic_name,
4951
const std::string& topic_type)
5052
{
51-
auto library = std::move(rosbag2_cpp::get_typesupport_library(topic_type, "rosidl_typesupport_cpp"));
52-
auto type_support = rosbag2_cpp::get_typesupport_handle(topic_type, "rosidl_typesupport_cpp", library);
53+
auto library = std::move(wrapper::get_typesupport_library(topic_type, "rosidl_typesupport_cpp"));
54+
auto type_support = wrapper::get_message_typesupport_handle(topic_type, "rosidl_typesupport_cpp", library);
5355

5456
return std::make_shared<GenericPublisher>(node.get_node_base_interface().get(), topic_name, *type_support);
5557
}

src/ros_parsers/ros2_parser.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <rosidl_typesupport_introspection_cpp/identifier.hpp>
1111
#include <fmt/core.h>
1212

13+
#include "typesupport_wrapper.h"
14+
1315
bool TypeHasHeader(const rosidl_message_type_support_t* type_support)
1416
{
1517
auto members = static_cast<const rosidl_typesupport_introspection_cpp::MessageMembers*>(type_support->data);
@@ -35,17 +37,15 @@ bool TypeHasHeader(const rosidl_message_type_support_t* type_support)
3537
std::string CreateSchema(const std::string& base_type)
3638
{
3739
std::string schema;
38-
using TypeSupport = rosidl_message_type_support_t;
3940
using namespace rosidl_typesupport_introspection_cpp;
4041

4142
std::set<std::string> secondary_types_pending;
4243
std::set<std::string> secondary_types_done;
4344

4445
auto addTypeToSchema = [&](const std::string& type_name, bool add_header) {
45-
auto introspection_library =
46-
rosbag2_cpp::get_typesupport_library(type_name, "rosidl_typesupport_introspection_cpp");
47-
auto introspection_support =
48-
rosbag2_cpp::get_typesupport_handle(type_name, "rosidl_typesupport_introspection_cpp", introspection_library);
46+
auto introspection_library = wrapper::get_typesupport_library(type_name, "rosidl_typesupport_introspection_cpp");
47+
auto introspection_support = wrapper::get_message_typesupport_handle(
48+
type_name, "rosidl_typesupport_introspection_cpp", introspection_library);
4949

5050
if (add_header)
5151
{
@@ -147,13 +147,13 @@ TopicInfo CreateTopicInfo(const std::string& topic_name, const std::string& type
147147
info.topic_name = topic_name;
148148
info.type = type_name;
149149

150-
info.introspection_library = rosbag2_cpp::get_typesupport_library(type_name, "rosidl_typesupport_introspection_cpp");
151-
info.introspection_support = rosbag2_cpp::get_typesupport_handle(type_name, "rosidl_typesupport_introspection_cpp",
152-
info.introspection_library);
150+
info.introspection_library = wrapper::get_typesupport_library(type_name, "rosidl_typesupport_introspection_cpp");
151+
info.introspection_support = wrapper::get_message_typesupport_handle(
152+
type_name, "rosidl_typesupport_introspection_cpp", info.introspection_library);
153153

154154
auto identifier = rosidl_typesupport_cpp::typesupport_identifier;
155-
info.support_library = rosbag2_cpp::get_typesupport_library(type_name, identifier);
156-
info.type_support = rosbag2_cpp::get_typesupport_handle(type_name, identifier, info.support_library);
155+
info.support_library = wrapper::get_typesupport_library(type_name, identifier);
156+
info.type_support = wrapper::get_message_typesupport_handle(type_name, identifier, info.support_library);
157157

158158
info.has_header_stamp = TypeHasHeader(info.introspection_support);
159159
return info;

src/ros_parsers/ros2_parser.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "rclcpp/rclcpp.hpp"
44
#include "rmw/rmw.h"
55
#include "rmw/types.h"
6-
#include "rosbag2_cpp/typesupport_helpers.hpp"
76
#include "rosidl_typesupport_introspection_cpp/message_introspection.hpp"
87

98
#include <PlotJuggler/plotdata.h>

src/typesupport_wrapper.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
3+
#include "typesupport_wrapper.h"
4+
#include "rosidl_runtime_cpp/message_type_support_decl.hpp"
5+
6+
#ifdef ROS_HUMBLE
7+
#include "rosbag2_cpp/typesupport_helpers.hpp"
8+
#else
9+
#include "rclcpp/typesupport_helpers.hpp"
10+
#endif
11+
12+
namespace wrapper
13+
{
14+
std::shared_ptr<rcpputils::SharedLibrary> get_typesupport_library(const std::string& type,
15+
const std::string& typesupport_identifier)
16+
{
17+
#ifdef ROS_HUMBLE
18+
return rosbag2_cpp::get_typesupport_library(type, typesupport_identifier);
19+
#else
20+
return rclcpp::get_typesupport_library(type, typesupport_identifier);
21+
#endif
22+
}
23+
24+
const rosidl_message_type_support_t* get_message_typesupport_handle(const std::string& type,
25+
const std::string& typesupport_identifier,
26+
std::shared_ptr<rcpputils::SharedLibrary> library)
27+
{
28+
#ifdef ROS_HUMBLE
29+
return rosbag2_cpp::get_typesupport_handle(type, typesupport_identifier, library);
30+
#else
31+
return rclcpp::get_message_typesupport_handle(type, typesupport_identifier, *library);
32+
#endif
33+
}
34+
} // namespace wrapper

src/typesupport_wrapper.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Wrappers to keep compatibility with all active ROS versions as of 01/2026 (Kilted, Jazzy, Humble). Dropping of
3+
* this file should be reevaluated once Humble goes end of life (07/2027).
4+
*/
5+
6+
#ifndef TYPESUPPORT_WRAPPER_H
7+
#define TYPESUPPORT_WRAPPER_H
8+
9+
#include <memory>
10+
#include "rcpputils/shared_library.hpp"
11+
#include "rosidl_runtime_cpp/message_type_support_decl.hpp"
12+
13+
namespace wrapper
14+
{
15+
std::shared_ptr<rcpputils::SharedLibrary> get_typesupport_library(const std::string& type,
16+
const std::string& typesupport_identifier);
17+
18+
const rosidl_message_type_support_t* get_message_typesupport_handle(const std::string& type,
19+
const std::string& typesupport_identifier,
20+
std::shared_ptr<rcpputils::SharedLibrary> library);
21+
} // namespace wrapper
22+
23+
#endif // TYPESUPPORT_WRAPPER_H

0 commit comments

Comments
 (0)