Skip to content

Commit 5295dd4

Browse files
emersonknappBarry-Xu-2018
authored andcommitted
Add type_hash to cpp TopicEndpointInfo (ros2#2137)
* Add type_hash to cpp TopicEndpointInfo Signed-off-by: Emerson Knapp <[email protected]>
1 parent 27cd369 commit 5295dd4

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class TopicEndpointInfo
5757
node_namespace_(info.node_namespace),
5858
topic_type_(info.topic_type),
5959
endpoint_type_(static_cast<rclcpp::EndpointType>(info.endpoint_type)),
60-
qos_profile_({info.qos_profile.history, info.qos_profile.depth}, info.qos_profile)
60+
qos_profile_({info.qos_profile.history, info.qos_profile.depth}, info.qos_profile),
61+
topic_type_hash_(info.topic_type_hash)
6162
{
6263
std::copy(info.endpoint_gid, info.endpoint_gid + RMW_GID_STORAGE_SIZE, endpoint_gid_.begin());
6364
}
@@ -122,13 +123,24 @@ class TopicEndpointInfo
122123
const rclcpp::QoS &
123124
qos_profile() const;
124125

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

134146
namespace node_interfaces

rclcpp/src/rclcpp/node_interfaces/node_graph.cpp

Lines changed: 12 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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)