Skip to content

Commit fbc8a5e

Browse files
emersonknappAlberto Soragna
authored and
Alberto Soragna
committed
Add type_hash to cpp TopicEndpointInfo (ros2#2137)
* Add type_hash to cpp TopicEndpointInfo Signed-off-by: Emerson Knapp <[email protected]>
1 parent 154b732 commit fbc8a5e

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

rclcpp/include/rclcpp/node_interfaces/node_graph_interface.hpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class TopicEndpointInfo
5656
node_namespace_(info.node_namespace),
5757
topic_type_(info.topic_type),
5858
endpoint_type_(static_cast<rclcpp::EndpointType>(info.endpoint_type)),
59-
qos_profile_({info.qos_profile.history, info.qos_profile.depth}, info.qos_profile)
59+
qos_profile_({info.qos_profile.history, info.qos_profile.depth}, info.qos_profile),
60+
topic_type_hash_(info.topic_type_hash)
6061
{
6162
std::copy(info.endpoint_gid, info.endpoint_gid + RMW_GID_STORAGE_SIZE, endpoint_gid_.begin());
6263
}
@@ -121,13 +122,24 @@ class TopicEndpointInfo
121122
const rclcpp::QoS &
122123
qos_profile() const;
123124

125+
/// Get a mutable reference to the type hash of the topic endpoint.
126+
RCLCPP_PUBLIC
127+
rosidl_type_hash_t &
128+
topic_type_hash();
129+
130+
/// Get a const reference to the type hash of the topic endpoint.
131+
RCLCPP_PUBLIC
132+
const rosidl_type_hash_t &
133+
topic_type_hash() const;
134+
124135
private:
125136
std::string node_name_;
126137
std::string node_namespace_;
127138
std::string topic_type_;
128139
rclcpp::EndpointType endpoint_type_;
129140
std::array<uint8_t, RMW_GID_STORAGE_SIZE> endpoint_gid_;
130141
rclcpp::QoS qos_profile_;
142+
rosidl_type_hash_t topic_type_hash_;
131143
};
132144

133145
namespace node_interfaces

rclcpp/src/rclcpp/node_interfaces/node_graph.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -789,3 +789,15 @@ rclcpp::TopicEndpointInfo::qos_profile() const
789789
{
790790
return qos_profile_;
791791
}
792+
793+
rosidl_type_hash_t &
794+
rclcpp::TopicEndpointInfo::topic_type_hash()
795+
{
796+
return topic_type_hash_;
797+
}
798+
799+
const rosidl_type_hash_t &
800+
rclcpp::TopicEndpointInfo::topic_type_hash() const
801+
{
802+
return topic_type_hash_;
803+
}

rclcpp/test/rclcpp/node_interfaces/test_node_graph.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "rclcpp/node_interfaces/node_graph.hpp"
2929
#include "rclcpp/rclcpp.hpp"
3030
#include "rcutils/strdup.h"
31+
#include "test_msgs/msg/empty.h"
3132
#include "test_msgs/msg/empty.hpp"
3233
#include "test_msgs/srv/empty.hpp"
3334

@@ -599,6 +600,18 @@ TEST_F(TestNodeGraph, get_info_by_topic)
599600
rclcpp::QoS const_actual_qos = const_publisher_endpoint_info.qos_profile();
600601
EXPECT_EQ(const_actual_qos.reliability(), rclcpp::ReliabilityPolicy::Reliable);
601602

603+
const rosidl_type_hash_t expected_type_hash = *test_msgs__msg__Empty__get_type_hash(nullptr);
604+
EXPECT_EQ(
605+
0, memcmp(
606+
&publisher_endpoint_info.topic_type_hash(),
607+
&expected_type_hash,
608+
sizeof(rosidl_type_hash_t)));
609+
EXPECT_EQ(
610+
0, memcmp(
611+
&const_publisher_endpoint_info.topic_type_hash(),
612+
&expected_type_hash,
613+
sizeof(rosidl_type_hash_t)));
614+
602615
auto endpoint_gid = publisher_endpoint_info.endpoint_gid();
603616
auto const_endpoint_gid = const_publisher_endpoint_info.endpoint_gid();
604617
bool endpoint_gid_is_all_zeros = true;

0 commit comments

Comments
 (0)