Skip to content

Commit 55b2aaa

Browse files
Support topic instances (#178)
* Initial implementation of keyed instances support for DDS topics * Return correct max key size and serialize using correct endianness * Apply uncrustify * Fix Windows compilation and warning Signed-off-by: Francisco Gallego Salido <[email protected]> * Applied feedback Signed-off-by: Francisco Gallego Salido <[email protected]> --------- Signed-off-by: Francisco Gallego Salido <[email protected]>
1 parent 9dab06c commit 55b2aaa

File tree

8 files changed

+749
-144
lines changed

8 files changed

+749
-144
lines changed

rmw_connextdds_common/include/rmw_connextdds/rmw_impl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
rcutils_ret_t
4545
rcutils_uint8_array_copy(
4646
rcutils_uint8_array_t * const dst,
47-
const rcutils_uint8_array_t * const src);
47+
const rcutils_uint8_array_t * const src,
48+
const bool realloc_if_needed = true);
4849

4950
rmw_qos_policy_kind_t
5051
dds_qos_policy_to_rmw_qos_policy(const DDS_QosPolicyId_t last_policy_id);

rmw_connextdds_common/include/rmw_connextdds/type_support.hpp

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef RMW_CONNEXTDDS__TYPE_SUPPORT_HPP_
1616
#define RMW_CONNEXTDDS__TYPE_SUPPORT_HPP_
1717

18+
#include <cstdint>
1819
#include <string>
1920
#include <stdexcept>
2021

@@ -56,10 +57,16 @@ struct RMW_Connext_RequestReplyMessage
5657

5758
class RMW_Connext_MessageTypeSupport
5859
{
60+
const rosidl_message_type_support_t * _message_type_support;
5961
const rosidl_message_type_support_t * _type_support_fastrtps;
62+
message_type_support_key_callbacks_t _key_callbacks;
6063
bool _unbounded;
6164
bool _empty;
65+
bool _keyed;
66+
bool _unbounded_key;
67+
bool _is_cpp;
6268
uint32_t _serialized_size_max;
69+
uint32_t _key_serialized_size_max;
6370
std::string _type_name;
6471
RMW_Connext_MessageType _message_type;
6572
rmw_context_impl_t * const _ctx;
@@ -79,6 +86,11 @@ class RMW_Connext_MessageTypeSupport
7986
this->_type_support_fastrtps->data);
8087
}
8188

89+
const rosidl_message_type_support_t * message_type_support() const
90+
{
91+
return this->_message_type_support;
92+
}
93+
8294
rmw_context_impl_t * ctx() const
8395
{
8496
return this->_ctx;
@@ -99,6 +111,14 @@ class RMW_Connext_MessageTypeSupport
99111
return this->_serialized_size_max;
100112
}
101113

114+
uint32_t type_key_serialized_size_max() const
115+
{
116+
if (!this->_keyed) {
117+
return 0;
118+
}
119+
return this->_key_serialized_size_max;
120+
}
121+
102122
bool unbounded() const
103123
{
104124
return this->_unbounded;
@@ -109,6 +129,21 @@ class RMW_Connext_MessageTypeSupport
109129
return this->_empty;
110130
}
111131

132+
bool keyed() const
133+
{
134+
return this->_keyed;
135+
}
136+
137+
bool unbounded_key() const
138+
{
139+
return this->_unbounded_key;
140+
}
141+
142+
bool is_cpp() const
143+
{
144+
return this->_is_cpp;
145+
}
146+
112147
RMW_Connext_MessageType message_type() const
113148
{
114149
return this->_message_type;
@@ -139,14 +174,32 @@ class RMW_Connext_MessageTypeSupport
139174

140175
rmw_ret_t serialize(
141176
const void * const ros_msg,
142-
rcutils_uint8_array_t * const to_buffer);
177+
rcutils_uint8_array_t * const to_buffer,
178+
const bool include_encapsulation = true);
143179

144180
rmw_ret_t deserialize(
145181
void * const ros_msg,
146182
const rcutils_uint8_array_t * const from_buffer,
147-
size_t & size_out,
148183
const bool header_only = false);
149184

185+
rmw_ret_t serialize_key(
186+
const void * const ros_msg,
187+
rcutils_uint8_array_t * const to_buffer,
188+
RTIEncapsulationId encapsulation_id,
189+
const bool include_encapsulation = true);
190+
191+
// Not available in message_type_support_key_callbacks_t yet
192+
//
193+
// Because deserialize_key is not supported yet there will be errors receiving dispose samples
194+
// that have the serialized key as payload and the sample will be reported as lost.
195+
//
196+
// By default, dispose samples do not contain the serialized key, so this should only be a
197+
// problem if the DataWriterQos.protocol.serialize_key_with_dispose is set to true.
198+
//
199+
// rmw_ret_t deserialize_key(
200+
// void * const ros_msg,
201+
// const rcutils_uint8_array_t * const from_buffer);
202+
150203
static
151204
RMW_Connext_MessageTypeSupport *
152205
register_type_support(
@@ -174,7 +227,11 @@ class RMW_Connext_MessageTypeSupport
174227
const rosidl_message_type_support_t * const type_support,
175228
uint32_t & serialized_size_max,
176229
bool & unbounded,
177-
bool & empty);
230+
bool & empty,
231+
bool & keyed,
232+
bool & unbounded_key,
233+
message_type_support_key_callbacks_t & key_callbacks,
234+
uint32_t & key_serialized_size_max);
178235
};
179236

180237
struct RMW_Connext_Message

rmw_connextdds_common/src/common/rmw_impl.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,15 @@ rmw_connextdds_create_topic_name(
6969
rcutils_ret_t
7070
rcutils_uint8_array_copy(
7171
rcutils_uint8_array_t * const dst,
72-
const rcutils_uint8_array_t * const src)
72+
const rcutils_uint8_array_t * const src,
73+
const bool realloc_if_needed)
7374
{
7475
if (src->buffer_length > 0) {
7576
if (src->buffer_length > dst->buffer_capacity) {
77+
if (!realloc_if_needed) {
78+
return RCUTILS_RET_ERROR;
79+
}
80+
7681
rcutils_ret_t rc =
7782
rcutils_uint8_array_resize(dst, src->buffer_length);
7883

@@ -1844,12 +1849,9 @@ RMW_Connext_Subscriber::take_next(
18441849
// request header.
18451850
if (this->type_support->type_requestreply()) {
18461851
if (this->ctx->request_reply_mapping == RMW_Connext_RequestReplyMapping::Basic) {
1847-
size_t deserialized_size = 0;
1848-
UNUSED_ARG(deserialized_size);
1849-
18501852
if (RMW_RET_OK !=
18511853
this->type_support->deserialize(
1852-
ros_message, &msg->data_buffer, deserialized_size, true /* header_only */))
1854+
ros_message, &msg->data_buffer, true /* header_only */))
18531855
{
18541856
RMW_CONNEXT_LOG_ERROR_SET("failed to deserialize taken sample")
18551857
rc_exit = RMW_RET_ERROR;
@@ -1895,11 +1897,8 @@ RMW_Connext_Subscriber::take_next(
18951897
continue;
18961898
}
18971899
} else {
1898-
size_t deserialized_size = 0;
1899-
19001900
if (RMW_RET_OK !=
1901-
this->type_support->deserialize(
1902-
ros_message, &msg->data_buffer, deserialized_size))
1901+
this->type_support->deserialize(ros_message, &msg->data_buffer))
19031902
{
19041903
RMW_CONNEXT_LOG_ERROR_SET(
19051904
"failed to deserialize taken sample")

0 commit comments

Comments
 (0)