Skip to content

Commit fe30da2

Browse files
committed
fix humble compatibility using typesupport wrapper
Signed-off-by: Dominik Authaler <dominik.authaler@uni-ulm.de>
1 parent 3d45f50 commit fe30da2

6 files changed

Lines changed: 72 additions & 12 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/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:
@@ -49,8 +51,8 @@ class GenericPublisher : public rclcpp::PublisherBase
4951
const std::string& topic_type)
5052
{
5153

52-
auto library = std::move(rclcpp::get_typesupport_library(topic_type, "rosidl_typesupport_cpp"));
53-
auto type_support = rclcpp::get_message_typesupport_handle(topic_type, "rosidl_typesupport_cpp", *library);
54+
auto library = std::move(wrapper::get_typesupport_library(topic_type, "rosidl_typesupport_cpp"));
55+
auto type_support = wrapper::get_message_typesupport_handle(topic_type, "rosidl_typesupport_cpp", library);
5456

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

src/ros_parsers/ros2_parser.cpp

Lines changed: 10 additions & 8 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);
@@ -42,9 +44,9 @@ std::string CreateSchema(const std::string& base_type)
4244

4345
auto addTypeToSchema = [&](const std::string& type_name, bool add_header)
4446
{
45-
auto introspection_library = rclcpp::get_typesupport_library(type_name, "rosidl_typesupport_introspection_cpp");
46-
auto introspection_support = rclcpp::get_message_typesupport_handle(
47-
type_name, "rosidl_typesupport_introspection_cpp", *introspection_library);
47+
auto introspection_library = wrapper::get_typesupport_library(type_name, "rosidl_typesupport_introspection_cpp");
48+
auto introspection_support = wrapper::get_message_typesupport_handle(
49+
type_name, "rosidl_typesupport_introspection_cpp", introspection_library);
4850

4951
if (add_header)
5052
{
@@ -146,13 +148,13 @@ TopicInfo CreateTopicInfo(const std::string& topic_name, const std::string& type
146148
info.topic_name = topic_name;
147149
info.type = type_name;
148150

149-
info.introspection_library = rclcpp::get_typesupport_library(type_name, "rosidl_typesupport_introspection_cpp");
150-
info.introspection_support = rclcpp::get_message_typesupport_handle(type_name, "rosidl_typesupport_introspection_cpp",
151-
*info.introspection_library);
151+
info.introspection_library = wrapper::get_typesupport_library(type_name, "rosidl_typesupport_introspection_cpp");
152+
info.introspection_support = wrapper::get_message_typesupport_handle(type_name, "rosidl_typesupport_introspection_cpp",
153+
info.introspection_library);
152154

153155
auto identifier = rosidl_typesupport_cpp::typesupport_identifier;
154-
info.support_library = rclcpp::get_typesupport_library(type_name, identifier);
155-
info.type_support = rclcpp::get_message_typesupport_handle(type_name, identifier, *info.support_library);
156+
info.support_library = wrapper::get_typesupport_library(type_name, identifier);
157+
info.type_support = wrapper::get_message_typesupport_handle(type_name, identifier, info.support_library);
156158

157159
info.has_header_stamp = TypeHasHeader(info.introspection_support);
158160
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 "rclcpp/typesupport_helpers.hpp"
76
#include "rosidl_typesupport_introspection_cpp/message_introspection.hpp"
87

98
#include <PlotJuggler/plotdata.h>

src/typesupport_wrapper.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
std::shared_ptr<rcpputils::SharedLibrary>
14+
get_typesupport_library(const std::string & type, const std::string & typesupport_identifier) {
15+
#ifdef ROS_HUMBLE
16+
return rosbag2_cpp::get_typesupport_library(type, typesupport_identifier);
17+
#else
18+
return rclcpp::get_typesupport_library(type, typesupport_identifier);
19+
#endif
20+
}
21+
22+
const rosidl_message_type_support_t *
23+
get_message_typesupport_handle(const std::string &type,
24+
const std::string &typesupport_identifier,
25+
std::shared_ptr<rcpputils::SharedLibrary> library) {
26+
#ifdef ROS_HUMBLE
27+
return rosbag2_cpp::get_typesupport_handle(type, typesupport_identifier, library);
28+
#else
29+
return rclcpp::get_message_typesupport_handle(type, typesupport_identifier, *library);
30+
#endif
31+
}
32+
}

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+
std::shared_ptr<rcpputils::SharedLibrary>
15+
get_typesupport_library(const std::string & type, const std::string & typesupport_identifier);
16+
17+
const rosidl_message_type_support_t *
18+
get_message_typesupport_handle(const std::string &type,
19+
const std::string &typesupport_identifier,
20+
std::shared_ptr<rcpputils::SharedLibrary> library);
21+
}
22+
23+
#endif //TYPESUPPORT_WRAPPER_H

0 commit comments

Comments
 (0)