From 093250e401bdf9c58a1f5e64a138c8ca8a2e9d03 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 26 Mar 2024 15:36:22 +0000 Subject: [PATCH 01/15] rmw_fastrtps_shared: adapt shared type support Signed-off-by: Mario Dominguez --- .../rmw_fastrtps_shared_cpp/TypeSupport.hpp | 20 +++++-- .../src/TypeSupport_impl.cpp | 53 +++++++++++++++++++ 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp index 476bf160db..7e7aea9f83 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp @@ -24,6 +24,7 @@ #include "fastcdr/FastBuffer.h" #include "fastcdr/Cdr.h" +#include "fastdds/utils/md5.hpp" #include "rcutils/logging_macros.h" @@ -60,15 +61,14 @@ class TypeSupport : public eprosima::fastdds::dds::TopicDataType virtual bool deserializeROSmessage( eprosima::fastcdr::Cdr & deser, void * ros_message, const void * impl) const = 0; + virtual bool get_key_hash_from_ros_message( + void * ros_message, eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const = 0; + RMW_FASTRTPS_SHARED_CPP_PUBLIC bool compute_key( const void * const data, eprosima::fastdds::rtps::InstanceHandle_t & ihandle, - bool force_md5 = false) override - { - (void)data; (void)ihandle; (void)force_md5; - return false; - } + bool force_md5 = false) override; RMW_FASTRTPS_SHARED_CPP_PUBLIC bool compute_key( @@ -124,6 +124,12 @@ class TypeSupport : public eprosima::fastdds::dds::TopicDataType return type_supports_; } + RMW_FASTRTPS_SHARED_CPP_PUBLIC + inline bool is_key_unbounded() const + { + return key_is_unbounded_; + } + RMW_FASTRTPS_SHARED_CPP_PUBLIC virtual ~TypeSupport() {} @@ -136,6 +142,10 @@ class TypeSupport : public eprosima::fastdds::dds::TopicDataType bool max_size_bound_ {false}; bool is_plain_ {false}; const rosidl_message_type_support_t * type_supports_ {nullptr}; + bool key_is_unbounded_ {false}; + mutable size_t key_max_serialized_size_ {0}; + mutable eprosima::fastdds::MD5 md5_; + mutable std::vector key_buffer_; }; } // namespace rmw_fastrtps_shared_cpp diff --git a/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp b/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp index 04539c3dbd..fac065f597 100644 --- a/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp +++ b/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp @@ -66,6 +66,59 @@ void * TypeSupport::create_data() return new eprosima::fastcdr::FastBuffer(); } +bool TypeSupport::compute_key( + const void * const data, + eprosima::fastdds::rtps::InstanceHandle_t & ihandle, + bool force_md5) +{ + assert(data); + + bool ret = false; + + if (!is_compute_key_provided) + { + return ret; + } + + auto ser_data = static_cast(data); + + switch (ser_data->type) + { + case FASTDDS_SERIALIZED_DATA_TYPE_ROS_MESSAGE: + { + ret = this->get_key_hash_from_ros_message(ser_data->data, &ihandle, force_md5, ser_data->impl); + break; + } + + case FASTDDS_SERIALIZED_DATA_TYPE_CDR_BUFFER: + { + // TODO + // We would need a get_key_hash_from_payload method + break; + } + + case FASTDDS_SERIALIZED_DATA_TYPE_DYNAMIC_MESSAGE: + { + + auto m_type = std::make_shared(); + + // Retrieves the key (ihandle) from the dynamic data stored in data->data + return m_type->compute_key( + static_cast(ser_data->data), + ihandle, + force_md5); + + break; + } + default: + { + break; + } + } + + return ret; +} + bool TypeSupport::serialize( const void * const data, eprosima::fastdds::rtps::SerializedPayload_t & payload, eprosima::fastdds::dds::DataRepresentationId_t data_representation) From a9369120232ee8558205111af13dcb29d56b05d8 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 26 Mar 2024 15:37:56 +0000 Subject: [PATCH 02/15] rmw_fastrtps_cpp: update type support and implementation for keys adoption Signed-off-by: Mario Dominguez --- .../include/rmw_fastrtps_cpp/TypeSupport.hpp | 4 ++ rmw_fastrtps_cpp/src/type_support_common.cpp | 72 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp index d0121eff0f..7e84811580 100644 --- a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp +++ b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp @@ -44,11 +44,15 @@ class TypeSupport : public rmw_fastrtps_shared_cpp::TypeSupport explicit TypeSupport(const rosidl_message_type_support_t * type_supports); + bool get_key_hash_from_ros_message( + void * ros_message, eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const override; + protected: void set_members(const message_type_support_callbacks_t * members); private: const message_type_support_callbacks_t * members_; + const message_type_support_key_callbacks_t* key_callbacks_; bool has_data_; }; diff --git a/rmw_fastrtps_cpp/src/type_support_common.cpp b/rmw_fastrtps_cpp/src/type_support_common.cpp index 7c31a950e1..79c233f59d 100644 --- a/rmw_fastrtps_cpp/src/type_support_common.cpp +++ b/rmw_fastrtps_cpp/src/type_support_common.cpp @@ -31,6 +31,11 @@ TypeSupport::TypeSupport( is_compute_key_provided = false; max_size_bound_ = false; is_plain_ = false; + key_is_unbounded_ = false; + key_max_serialized_size_ = 0; + members_ = nullptr; + key_callbacks_ = nullptr; + has_data_ = false; } void TypeSupport::set_members(const message_type_support_callbacks_t * members) @@ -60,6 +65,18 @@ void TypeSupport::set_members(const message_type_support_callbacks_t * members) max_serialized_type_size = 4 + data_size; // Account for RTPS submessage alignment max_serialized_type_size = (max_serialized_type_size + 3) & ~3; + + if (nullptr != members->key_callbacks) + { + key_callbacks_ = members->key_callbacks; + is_compute_key_provided = true; + + key_max_serialized_size_ = key_callbacks_->max_serialized_size_key(key_is_unbounded_); + if (!key_is_unbounded_) + { + key_buffer_.reserve(key_max_serialized_size_); + } + } } size_t TypeSupport::getEstimatedSerializedSize(const void * ros_message, const void * impl) const @@ -132,6 +149,61 @@ bool TypeSupport::deserializeROSmessage( return true; } +bool TypeSupport::get_key_hash_from_ros_message( + void * ros_message, + eprosima::fastdds::rtps::InstanceHandle_t * ihandle, + bool force_md5, + const void * impl) const +{ + assert(ros_message); + (void)impl; + + // retrieve estimated serialized size in case key is unbounded + if (key_is_unbounded_) + { + key_max_serialized_size_ = (std::max) ( + key_max_serialized_size_, + key_callbacks_->get_serialized_size_key(ros_message)); + key_buffer_.reserve(key_max_serialized_size_); + } + + eprosima::fastcdr::FastBuffer fast_buffer( + reinterpret_cast(key_buffer_.data()), + key_max_serialized_size_); + + eprosima::fastcdr::Cdr ser( + fast_buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::CdrVersion::XCDRv1); + + key_callbacks_->cdr_serialize_key(ros_message, ser); + + const size_t max_serialized_key_length = 16; + + auto ser_length = ser.get_serialized_data_length(); + + // check for md5 + if (force_md5 || key_max_serialized_size_ > max_serialized_key_length) + { + md5_.init(); + md5_.update(key_buffer_.data(), static_cast(ser_length)); + md5_.finalize(); + + for (uint8_t i = 0; i < max_serialized_key_length; ++i) + { + ihandle->value[i] = md5_.digest[i]; + } + } + else + { + memset(ihandle->value, 0, max_serialized_key_length); + for (uint8_t i = 0; i < ser_length; ++i) + { + ihandle->value[i] = key_buffer_[i]; + } + } + + return true; +} + MessageTypeSupport::MessageTypeSupport( const message_type_support_callbacks_t * members, const rosidl_message_type_support_t * type_supports) From 812a50d6bfa0048537411fd0653c6c8378187e39 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 26 Mar 2024 15:38:43 +0000 Subject: [PATCH 03/15] rmw_fastrtps_dynamic_cpp: update type support and implementation for keys adoption Signed-off-by: Mario Dominguez --- .../src/MessageTypeSupport_impl.hpp | 8 + .../src/ServiceTypeSupport_impl.hpp | 16 ++ rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp | 41 +++++ .../src/TypeSupport_impl.hpp | 163 +++++++++++++++++- .../src/type_support_proxy.cpp | 9 + 5 files changed, 232 insertions(+), 5 deletions(-) diff --git a/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp index 9646f2fff2..ca2c098c8f 100644 --- a/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp @@ -61,6 +61,14 @@ MessageTypeSupport::MessageTypeSupport( } else { this->max_serialized_type_size++; } + + if (this->members_->has_any_key_member_) + { + this->key_max_serialized_size_ = this->calculateMaxSerializedKeySize(members); + this->m_isGetKeyDefined = true; + this->key_buffer_.reserve(this->key_max_serialized_size_); + } + // Account for RTPS submessage alignment this->max_serialized_type_size = (this->max_serialized_type_size + 3) & ~3; } diff --git a/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp index f397174cb1..6ae2757189 100644 --- a/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp @@ -62,6 +62,14 @@ RequestTypeSupport::RequestTypeSupport( } else { this->max_serialized_type_size++; } + + if (this->members_->has_any_key_member_) + { + this->key_max_serialized_size_ = this->calculateMaxSerializedKeySize(this->members_); + this->m_isGetKeyDefined = true; + this->key_buffer_.reserve(this->key_max_serialized_size_); + } + // Account for RTPS submessage alignment this->max_serialized_type_size = (this->max_serialized_type_size + 3) & ~3; } @@ -98,6 +106,14 @@ ResponseTypeSupport::ResponseTypeSupport } else { this->max_serialized_type_size++; } + + if (this->members_->has_any_key_member_) + { + this->key_max_serialized_size_ = this->calculateMaxSerializedKeySize(this->members_); + this->m_isGetKeyDefined = true; + this->key_buffer_.reserve(this->key_max_serialized_size_); + } + // Account for RTPS submessage alignment this->max_serialized_type_size = (this->max_serialized_type_size + 3) & ~3; } diff --git a/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp b/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp index ae6b6f72c1..67c5ced78c 100644 --- a/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp @@ -138,6 +138,9 @@ class TypeSupportProxy : public rmw_fastrtps_shared_cpp::TypeSupport bool deserializeROSmessage( eprosima::fastcdr::Cdr & deser, void * ros_message, const void * impl) const override; + + bool get_key_hash_from_ros_message( + void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const override; }; class BaseTypeSupport : public rmw_fastrtps_shared_cpp::TypeSupport @@ -185,6 +188,9 @@ class TypeSupport : public BaseTypeSupport bool deserializeROSmessage( eprosima::fastcdr::Cdr & deser, void * ros_message, const void * impl) const override; + bool get_key_hash_from_ros_message( + void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const override; + protected: // Meant for messages typesupport explicit TypeSupport(const void * ros_type_support); @@ -195,24 +201,59 @@ class TypeSupport : public BaseTypeSupport const void * ros_message_type_supports); size_t calculateMaxSerializedSize(const MembersType * members, size_t current_alignment); + size_t calculateMaxSerializedKeySize(const MembersType * members); const MembersType * members_; private: + + size_t calculateMaxSerializedSize( + const MembersType * members, + size_t current_alignment, + bool compute_key, + bool& is_key_unbounded); + size_t getEstimatedSerializedSize( const MembersType * members, const void * ros_message, size_t current_alignment) const; + size_t getEstimatedSerializedKeySize( + const MembersType * members, + const void * ros_message) const; + + size_t getEstimatedSerializedSize( + const MembersType * members, + const void * ros_message, + size_t current_alignment, + bool compute_key) const; + bool serializeROSmessage( eprosima::fastcdr::Cdr & ser, const MembersType * members, const void * ros_message) const; + bool serializeKeyROSmessage( + eprosima::fastcdr::Cdr & ser, + const MembersType * members, + const void * ros_message) const; + + bool serializeROSmessage( + eprosima::fastcdr::Cdr & ser, + const MembersType * members, + const void * ros_message, + bool compute_key) const; + bool deserializeROSmessage( eprosima::fastcdr::Cdr & deser, const MembersType * members, void * ros_message) const; + + bool get_key_hash_from_ros_message( + const MembersType * members, + void * ros_message, + eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, + bool force_md5) const; }; } // namespace rmw_fastrtps_dynamic_cpp diff --git a/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp index 37a4141104..78ea574a90 100644 --- a/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp @@ -76,6 +76,7 @@ TypeSupport::TypeSupport( is_compute_key_provided = false; max_size_bound_ = false; is_plain_ = false; + key_is_unbounded_ = false; } // C++ specialization @@ -207,12 +208,37 @@ bool TypeSupport::serializeROSmessage( eprosima::fastcdr::Cdr & ser, const MembersType * members, const void * ros_message) const +{ + return serializeROSmessage(ser, members, ros_message, false); +} + +template +bool TypeSupport::serializeKeyROSmessage( + eprosima::fastcdr::Cdr & ser, + const MembersType * members, + const void * ros_message) const +{ + return serializeROSmessage(ser, members, ros_message, true); +} + +template +bool TypeSupport::serializeROSmessage( + eprosima::fastcdr::Cdr & ser, + const MembersType * members, + const void * ros_message, + bool compute_key) const { assert(members); assert(ros_message); for (uint32_t i = 0; i < members->member_count_; ++i) { const auto member = members->members_ + i; + + if (compute_key && !member->is_key_ && members->has_any_key_member_) + { + continue; + } + void * field = const_cast(static_cast(ros_message)) + member->offset_; switch (member->type_id_) { case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_BOOL: @@ -266,7 +292,7 @@ bool TypeSupport::serializeROSmessage( { auto sub_members = static_cast(member->members_->data); if (!member->is_array_) { - serializeROSmessage(ser, sub_members, field); + serializeROSmessage(ser, sub_members, field, compute_key); } else { size_t array_size = 0; @@ -288,7 +314,7 @@ bool TypeSupport::serializeROSmessage( return false; } for (size_t index = 0; index < array_size; ++index) { - serializeROSmessage(ser, sub_members, member->get_function(field, index)); + serializeROSmessage(ser, sub_members, member->get_function(field, index), compute_key); } } } @@ -301,6 +327,58 @@ bool TypeSupport::serializeROSmessage( return true; } +template +bool TypeSupport::get_key_hash_from_ros_message( + const MembersType * members, + void * ros_message, + eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, + bool force_md5) const +{ + assert(members); + assert(ros_message); + + // get estimated serialized size in case key is unbounded + if (this->key_is_unbounded_) + { + this->key_max_serialized_size_ = this->getEstimatedSerializedKeySize(members, ros_message); + key_buffer_.reserve(this->key_max_serialized_size_); + } + + eprosima::fastcdr::FastBuffer buffer( + reinterpret_cast(this->key_buffer_.data()), + this->key_max_serialized_size_); + + eprosima::fastcdr::Cdr ser( + buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::CdrVersion::XCDRv1); + + // serialize + serializeKeyROSmessage(ser, members_, ros_message); + + // check for md5 + if (force_md5 || this->key_max_serialized_size_ > 16) + { + md5_.init(); + + md5_.update(this->key_buffer_.data(), static_cast(ser.get_serialized_data_length())); + + md5_.finalize(); + + for (uint8_t i = 0; i < 16; ++i) + { + ihandle->value[i] = md5_.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + ihandle->value[i] = this->key_buffer_[i]; + } + } + + return true; +} + // C++ specialization template size_t next_field_align( @@ -470,6 +548,24 @@ size_t TypeSupport::getEstimatedSerializedSize( const MembersType * members, const void * ros_message, size_t current_alignment) const +{ + return getEstimatedSerializedSize(members, ros_message, current_alignment, false); +} + +template +size_t TypeSupport::getEstimatedSerializedKeySize( + const MembersType * members, + const void * ros_message) const +{ + return getEstimatedSerializedSize(members, ros_message, 0, true); +} + +template +size_t TypeSupport::getEstimatedSerializedSize( + const MembersType * members, + const void * ros_message, + size_t current_alignment, + bool compute_key) const { assert(members); assert(ros_message); @@ -479,6 +575,12 @@ size_t TypeSupport::getEstimatedSerializedSize( for (uint32_t i = 0; i < members->member_count_; ++i) { const auto member = members->members_ + i; void * field = const_cast(static_cast(ros_message)) + member->offset_; + + if (compute_key && !member->is_key_ && members->has_any_key_member_) + { + continue; + } + switch (member->type_id_) { case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_BOOL: current_alignment = next_field_align(member, field, current_alignment); @@ -525,7 +627,7 @@ size_t TypeSupport::getEstimatedSerializedSize( { auto sub_members = static_cast(member->members_->data); if (!member->is_array_) { - current_alignment += getEstimatedSerializedSize(sub_members, field, current_alignment); + current_alignment += getEstimatedSerializedSize(sub_members, field, current_alignment, compute_key); } else { size_t array_size = 0; @@ -550,7 +652,8 @@ size_t TypeSupport::getEstimatedSerializedSize( current_alignment += getEstimatedSerializedSize( sub_members, member->get_function(field, index), - current_alignment); + current_alignment, + compute_key); } } } @@ -812,6 +915,24 @@ bool TypeSupport::deserializeROSmessage( template size_t TypeSupport::calculateMaxSerializedSize( const MembersType * members, size_t current_alignment) +{ + bool is_key_unbounded{false}; //unused + return calculateMaxSerializedSize(members, current_alignment, false, is_key_unbounded); +} + +template +size_t TypeSupport::calculateMaxSerializedKeySize( + const MembersType * members) +{ + return calculateMaxSerializedSize(members, 0, true, this->key_is_unbounded_); +} + +template +size_t TypeSupport::calculateMaxSerializedSize( + const MembersType * members, + size_t current_alignment, + bool compute_key, + bool& is_key_unbounded) { assert(members); @@ -824,6 +945,12 @@ size_t TypeSupport::calculateMaxSerializedSize( const auto * member = members->members_ + i; size_t array_size = 1; + + if (compute_key && !member->is_key_ && members->has_any_key_member_) + { + continue; + } + if (member->is_array_) { array_size = member->array_size_; @@ -875,6 +1002,13 @@ size_t TypeSupport::calculateMaxSerializedSize( { this->max_size_bound_ = false; this->is_plain_ = false; + + if (compute_key) + { + std::cout << "Setting is key unbounded !" << std::endl; + is_key_unbounded = true; + } + size_t character_size = (member->type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_WSTRING) ? 4 : 1; size_t extra_char = @@ -890,7 +1024,7 @@ size_t TypeSupport::calculateMaxSerializedSize( { auto sub_members = static_cast(member->members_->data); for (size_t index = 0; index < array_size; ++index) { - size_t curr = calculateMaxSerializedSize(sub_members, current_alignment); + size_t curr = calculateMaxSerializedSize(sub_members, current_alignment, compute_key, is_key_unbounded); current_alignment += curr; last_member_size += curr; } @@ -990,6 +1124,25 @@ bool TypeSupport::deserializeROSmessage( return true; } +template +bool TypeSupport::get_key_hash_from_ros_message( + void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const +{ + + assert(ros_message); + assert(members_); + + bool ret = false; + + (void)impl; + if (members_->member_count_ != 0) + { + ret = TypeSupport::get_key_hash_from_ros_message(members_, ros_message, ihandle, force_md5); + } + + return ret; +} + } // namespace rmw_fastrtps_dynamic_cpp #endif // TYPESUPPORT_IMPL_HPP_ diff --git a/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp b/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp index 3f7c8123da..a36dcadc10 100644 --- a/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp @@ -24,6 +24,8 @@ TypeSupportProxy::TypeSupportProxy(rmw_fastrtps_shared_cpp::TypeSupport * inner_ max_serialized_type_size = inner_type->max_serialized_type_size; is_plain_ = inner_type->is_plain(eprosima::fastdds::dds::XCDR_DATA_REPRESENTATION); max_size_bound_ = inner_type->is_bounded(); + m_isGetKeyDefined = inner_type->m_isGetKeyDefined; + key_is_unbounded_ = inner_type->is_key_unbounded(); } size_t TypeSupportProxy::getEstimatedSerializedSize( @@ -47,4 +49,11 @@ bool TypeSupportProxy::deserializeROSmessage( return type_impl->deserializeROSmessage(deser, ros_message, impl); } +bool TypeSupportProxy::get_key_hash_from_ros_message( + void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const +{ + auto type_impl = static_cast(impl); + return type_impl->get_key_hash_from_ros_message(ros_message, ihandle, force_md5, impl); +} + } // namespace rmw_fastrtps_dynamic_cpp From 124d0fecee3afd62983c85be33e4d8e6b8fb8b4f Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 26 Mar 2024 15:40:02 +0000 Subject: [PATCH 04/15] rmw_fastrtps_shared_cpp: new apply_qos_resource_limits_for_keys() Signed-off-by: Mario Dominguez --- .../include/rmw_fastrtps_shared_cpp/utils.hpp | 15 +++++++++++++++ rmw_fastrtps_shared_cpp/src/utils.cpp | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/utils.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/utils.hpp index 9fd4bc9258..a2b27abe11 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/utils.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/utils.hpp @@ -126,6 +126,21 @@ create_datareader( CustomDataReaderListener * listener, eprosima::fastdds::dds::DataReader ** data_reader); +/** +* Apply specific resource limits when using keys. +* Max samples per instance is set to history depth if KEEP_LAST +* else UNLIMITED. +* +* \param[in] hitory_qos History entitiy QoS. +* \param[in, out] res_limits_qos Resource limits entitiy QoS. +* +*/ +RMW_FASTRTPS_SHARED_CPP_PUBLIC +void +apply_qos_resource_limits_for_keys( + const eprosima::fastdds::dds::HistoryQosPolicy & history_qos, + eprosima::fastdds::dds::ResourceLimitsQosPolicy & res_limits_qos); + } // namespace rmw_fastrtps_shared_cpp #endif // RMW_FASTRTPS_SHARED_CPP__UTILS_HPP_ diff --git a/rmw_fastrtps_shared_cpp/src/utils.cpp b/rmw_fastrtps_shared_cpp/src/utils.cpp index 53ee6b3812..7d53718eda 100644 --- a/rmw_fastrtps_shared_cpp/src/utils.cpp +++ b/rmw_fastrtps_shared_cpp/src/utils.cpp @@ -181,5 +181,21 @@ create_datareader( return true; } +void +apply_qos_resource_limits_for_keys( + const eprosima::fastdds::dds::HistoryQosPolicy & history_qos, + eprosima::fastdds::dds::ResourceLimitsQosPolicy & res_limits_qos) +{ + res_limits_qos.max_instances = 0; + res_limits_qos.max_samples = 0; + if (history_qos.kind == eprosima::fastdds::dds::KEEP_LAST_HISTORY_QOS) + { + res_limits_qos.max_samples_per_instance = history_qos.depth; + } + else + { + res_limits_qos.max_samples_per_instance = 0; + } +} } // namespace rmw_fastrtps_shared_cpp From 73fde5ed34d87ff5fbccce98d340b34ddda51034 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 26 Mar 2024 15:40:43 +0000 Subject: [PATCH 05/15] rmw_fastrtps_cpp: add apply_qos_resource_limits_for_keys() Signed-off-by: Mario Dominguez --- rmw_fastrtps_cpp/src/publisher.cpp | 9 +++++++++ rmw_fastrtps_cpp/src/rmw_client.cpp | 18 ++++++++++++++++++ rmw_fastrtps_cpp/src/rmw_service.cpp | 18 ++++++++++++++++++ rmw_fastrtps_cpp/src/subscription.cpp | 18 ++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/rmw_fastrtps_cpp/src/publisher.cpp b/rmw_fastrtps_cpp/src/publisher.cpp index f690916ddf..469cc092d2 100644 --- a/rmw_fastrtps_cpp/src/publisher.cpp +++ b/rmw_fastrtps_cpp/src/publisher.cpp @@ -259,6 +259,15 @@ rmw_fastrtps_cpp::create_publisher( return nullptr; } + // Apply resource limits QoS if the type is keyed + if (fastdds_type->m_isGetKeyDefined && + !participant_info->leave_middleware_default_qos) + { + rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( + writer_qos.history(), + writer_qos.resource_limits()); + } + // Creates DataWriter with a mask enabling publication_matched calls for the listener info->data_writer_ = publisher->create_datawriter( info->topic_, diff --git a/rmw_fastrtps_cpp/src/rmw_client.cpp b/rmw_fastrtps_cpp/src/rmw_client.cpp index ccb4fa3ec7..62e8124b6e 100644 --- a/rmw_fastrtps_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_cpp/src/rmw_client.cpp @@ -328,6 +328,15 @@ rmw_create_client( return nullptr; } + // Apply resource limits QoS if the type is keyed + if (response_fastdds_type->m_isGetKeyDefined && + !participant_info->leave_middleware_default_qos) + { + rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( + reader_qos.history(), + reader_qos.resource_limits()); + } + // Creates DataReader info->response_reader_ = subscriber->create_datareader( response_topic_desc, @@ -386,6 +395,15 @@ rmw_create_client( return nullptr; } + // Apply resource limits QoS if the type is keyed + if (request_fastdds_type->m_isGetKeyDefined && + !participant_info->leave_middleware_default_qos) + { + rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( + writer_qos.history(), + writer_qos.resource_limits()); + } + // Creates DataWriter with a mask enabling publication_matched calls for the listener info->request_writer_ = publisher->create_datawriter( info->request_topic_, diff --git a/rmw_fastrtps_cpp/src/rmw_service.cpp b/rmw_fastrtps_cpp/src/rmw_service.cpp index ed50828f04..a6e0f0c462 100644 --- a/rmw_fastrtps_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_cpp/src/rmw_service.cpp @@ -324,6 +324,15 @@ rmw_create_service( return nullptr; } + // Apply resource limits QoS if the type is keyed + if (request_fastdds_type->m_isGetKeyDefined && + !participant_info->leave_middleware_default_qos) + { + rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( + reader_qos.history(), + reader_qos.resource_limits()); + } + // Creates DataReader info->request_reader_ = subscriber->create_datareader( request_topic_desc, @@ -386,6 +395,15 @@ rmw_create_service( return nullptr; } + // Apply resource limits QoS if the type is keyed + if (response_fastdds_type->m_isGetKeyDefined && + !participant_info->leave_middleware_default_qos) + { + rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( + writer_qos.history(), + writer_qos.resource_limits()); + } + // Creates DataWriter with a mask enabling publication_matched calls for the listener info->response_writer_ = publisher->create_datawriter( info->response_topic_, diff --git a/rmw_fastrtps_cpp/src/subscription.cpp b/rmw_fastrtps_cpp/src/subscription.cpp index 5443ea1cc7..05b0ba4ad9 100644 --- a/rmw_fastrtps_cpp/src/subscription.cpp +++ b/rmw_fastrtps_cpp/src/subscription.cpp @@ -392,6 +392,15 @@ __create_dynamic_subscription( return nullptr; } + // Apply resource limits QoS if the type is keyed + if (fastdds_type->m_isGetKeyDefined && + !participant_info->leave_middleware_default_qos) + { + rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( + reader_qos.history(), + reader_qos.resource_limits()); + } + info->datareader_qos_ = reader_qos; // create_datareader @@ -654,6 +663,15 @@ __create_subscription( return nullptr; } + // Apply resource limits QoS if the type is keyed + if (fastdds_type->m_isGetKeyDefined && + !participant_info->leave_middleware_default_qos) + { + rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( + reader_qos.history(), + reader_qos.resource_limits()); + } + info->datareader_qos_ = reader_qos; // create_datareader From d63bd99886828a08939e52fd90efe013478f0da6 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 26 Mar 2024 15:40:57 +0000 Subject: [PATCH 06/15] rmw_fastrtps_dynamic_cpp: add apply_qos_resource_limits_for_keys() Signed-off-by: Mario Dominguez --- rmw_fastrtps_dynamic_cpp/src/publisher.cpp | 9 +++++++++ rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp | 18 ++++++++++++++++++ rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp | 18 ++++++++++++++++++ rmw_fastrtps_dynamic_cpp/src/subscription.cpp | 9 +++++++++ 4 files changed, 54 insertions(+) diff --git a/rmw_fastrtps_dynamic_cpp/src/publisher.cpp b/rmw_fastrtps_dynamic_cpp/src/publisher.cpp index 68ce03a0b3..b79bb3c79b 100644 --- a/rmw_fastrtps_dynamic_cpp/src/publisher.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/publisher.cpp @@ -271,6 +271,15 @@ rmw_fastrtps_dynamic_cpp::create_publisher( return nullptr; } + // Apply resource limits QoS if the type is keyed + if (fastdds_type->m_isGetKeyDefined && + !participant_info->leave_middleware_default_qos) + { + rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( + writer_qos.history(), + writer_qos.resource_limits()); + } + // Creates DataWriter (with publisher name to not change name policy) info->data_writer_ = publisher->create_datawriter( info->topic_, diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp index 32e9e26616..e328f0a677 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp @@ -357,6 +357,15 @@ rmw_create_client( return nullptr; } + // Apply resource limits QoS if the type is keyed + if (response_fastdds_type->m_isGetKeyDefined && + !participant_info->leave_middleware_default_qos) + { + rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( + reader_qos.history(), + reader_qos.resource_limits()); + } + // Creates DataReader info->response_reader_ = subscriber->create_datareader( response_topic_desc, @@ -415,6 +424,15 @@ rmw_create_client( return nullptr; } + // Apply resource limits QoS if the type is keyed + if (request_fastdds_type->m_isGetKeyDefined && + !participant_info->leave_middleware_default_qos) + { + rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( + writer_qos.history(), + writer_qos.resource_limits()); + } + // Creates DataWriter info->request_writer_ = publisher->create_datawriter( info->request_topic_, diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp index a93c14d345..a83b4a25ce 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp @@ -353,6 +353,15 @@ rmw_create_service( return nullptr; } + // Apply resource limits QoS if the type is keyed + if (request_fastdds_type->m_isGetKeyDefined && + !participant_info->leave_middleware_default_qos) + { + rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( + reader_qos.history(), + reader_qos.resource_limits()); + } + // Creates DataReader info->request_reader_ = subscriber->create_datareader( request_topic_desc, @@ -415,6 +424,15 @@ rmw_create_service( return nullptr; } + // Apply resource limits QoS if the type is keyed + if (response_fastdds_type->m_isGetKeyDefined && + !participant_info->leave_middleware_default_qos) + { + rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( + writer_qos.history(), + writer_qos.resource_limits()); + } + // Creates DataWriter info->response_writer_ = publisher->create_datawriter( info->response_topic_, diff --git a/rmw_fastrtps_dynamic_cpp/src/subscription.cpp b/rmw_fastrtps_dynamic_cpp/src/subscription.cpp index 64afb9229b..18fe9acb7f 100644 --- a/rmw_fastrtps_dynamic_cpp/src/subscription.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/subscription.cpp @@ -272,6 +272,15 @@ create_subscription( return nullptr; } + // Apply resource limits QoS if the type is keyed + if (fastdds_type->m_isGetKeyDefined && + !participant_info->leave_middleware_default_qos) + { + rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( + reader_qos.history(), + reader_qos.resource_limits()); + } + eprosima::fastdds::dds::DataReaderQos original_qos = reader_qos; switch (subscription_options->require_unique_network_flow_endpoints) { default: From 648e1823880c4f83584e3b7a8d41427df6cb325d Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Mon, 1 Apr 2024 10:10:38 +0000 Subject: [PATCH 07/15] Apply review changes Signed-off-by: Mario Dominguez --- rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp | 2 +- rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp | 3 +-- .../include/rmw_fastrtps_shared_cpp/TypeSupport.hpp | 1 + rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp index 7e84811580..77427d9601 100644 --- a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp +++ b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp @@ -52,7 +52,7 @@ class TypeSupport : public rmw_fastrtps_shared_cpp::TypeSupport private: const message_type_support_callbacks_t * members_; - const message_type_support_key_callbacks_t* key_callbacks_; + const message_type_support_key_callbacks_t * key_callbacks_; bool has_data_; }; diff --git a/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp index 78ea574a90..bf1f5a7371 100644 --- a/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp @@ -340,7 +340,7 @@ bool TypeSupport::get_key_hash_from_ros_message( // get estimated serialized size in case key is unbounded if (this->key_is_unbounded_) { - this->key_max_serialized_size_ = this->getEstimatedSerializedKeySize(members, ros_message); + this->key_max_serialized_size_ = (std::max) (this->key_max_serialized_size_, this->getEstimatedSerializedKeySize(members, ros_message)); key_buffer_.reserve(this->key_max_serialized_size_); } @@ -1005,7 +1005,6 @@ size_t TypeSupport::calculateMaxSerializedSize( if (compute_key) { - std::cout << "Setting is key unbounded !" << std::endl; is_key_unbounded = true; } diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp index 7e7aea9f83..ee7723c8a0 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp @@ -146,6 +146,7 @@ class TypeSupport : public eprosima::fastdds::dds::TopicDataType mutable size_t key_max_serialized_size_ {0}; mutable eprosima::fastdds::MD5 md5_; mutable std::vector key_buffer_; + mutable std::mutex mtx_; }; } // namespace rmw_fastrtps_shared_cpp diff --git a/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp b/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp index fac065f597..1a8b64cc79 100644 --- a/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp +++ b/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp @@ -86,6 +86,7 @@ bool TypeSupport::compute_key( { case FASTDDS_SERIALIZED_DATA_TYPE_ROS_MESSAGE: { + std::lock_guard lock(this->mtx_); ret = this->get_key_hash_from_ros_message(ser_data->data, &ihandle, force_md5, ser_data->impl); break; } From bdc159eb0b08a92debd4fbbcdec54db24b6e153f Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Mon, 1 Apr 2024 10:18:11 +0000 Subject: [PATCH 08/15] Linters Signed-off-by: Mario Dominguez --- .../include/rmw_fastrtps_cpp/TypeSupport.hpp | 5 +- rmw_fastrtps_cpp/src/publisher.cpp | 2 +- rmw_fastrtps_cpp/src/rmw_client.cpp | 4 +- rmw_fastrtps_cpp/src/rmw_service.cpp | 4 +- rmw_fastrtps_cpp/src/subscription.cpp | 4 +- rmw_fastrtps_cpp/src/type_support_common.cpp | 32 ++++----- .../src/MessageTypeSupport_impl.hpp | 3 +- .../src/ServiceTypeSupport_impl.hpp | 6 +- rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp | 9 +-- .../src/TypeSupport_impl.hpp | 68 +++++++++---------- rmw_fastrtps_dynamic_cpp/src/publisher.cpp | 2 +- rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp | 4 +- rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp | 4 +- rmw_fastrtps_dynamic_cpp/src/subscription.cpp | 2 +- .../src/type_support_proxy.cpp | 3 +- .../rmw_fastrtps_shared_cpp/TypeSupport.hpp | 3 +- .../src/TypeSupport_impl.cpp | 17 +++-- rmw_fastrtps_shared_cpp/src/utils.cpp | 7 +- 18 files changed, 84 insertions(+), 95 deletions(-) diff --git a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp index 77427d9601..792a7fb705 100644 --- a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp +++ b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp @@ -45,14 +45,15 @@ class TypeSupport : public rmw_fastrtps_shared_cpp::TypeSupport explicit TypeSupport(const rosidl_message_type_support_t * type_supports); bool get_key_hash_from_ros_message( - void * ros_message, eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const override; + void * ros_message, eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, + const void * impl) const override; protected: void set_members(const message_type_support_callbacks_t * members); private: const message_type_support_callbacks_t * members_; - const message_type_support_key_callbacks_t * key_callbacks_; + const message_type_support_key_callbacks_t * key_callbacks_; bool has_data_; }; diff --git a/rmw_fastrtps_cpp/src/publisher.cpp b/rmw_fastrtps_cpp/src/publisher.cpp index 469cc092d2..8ed920dad5 100644 --- a/rmw_fastrtps_cpp/src/publisher.cpp +++ b/rmw_fastrtps_cpp/src/publisher.cpp @@ -261,7 +261,7 @@ rmw_fastrtps_cpp::create_publisher( // Apply resource limits QoS if the type is keyed if (fastdds_type->m_isGetKeyDefined && - !participant_info->leave_middleware_default_qos) + !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( writer_qos.history(), diff --git a/rmw_fastrtps_cpp/src/rmw_client.cpp b/rmw_fastrtps_cpp/src/rmw_client.cpp index 62e8124b6e..228e931398 100644 --- a/rmw_fastrtps_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_cpp/src/rmw_client.cpp @@ -330,7 +330,7 @@ rmw_create_client( // Apply resource limits QoS if the type is keyed if (response_fastdds_type->m_isGetKeyDefined && - !participant_info->leave_middleware_default_qos) + !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( reader_qos.history(), @@ -397,7 +397,7 @@ rmw_create_client( // Apply resource limits QoS if the type is keyed if (request_fastdds_type->m_isGetKeyDefined && - !participant_info->leave_middleware_default_qos) + !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( writer_qos.history(), diff --git a/rmw_fastrtps_cpp/src/rmw_service.cpp b/rmw_fastrtps_cpp/src/rmw_service.cpp index a6e0f0c462..bd842b41cc 100644 --- a/rmw_fastrtps_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_cpp/src/rmw_service.cpp @@ -326,7 +326,7 @@ rmw_create_service( // Apply resource limits QoS if the type is keyed if (request_fastdds_type->m_isGetKeyDefined && - !participant_info->leave_middleware_default_qos) + !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( reader_qos.history(), @@ -397,7 +397,7 @@ rmw_create_service( // Apply resource limits QoS if the type is keyed if (response_fastdds_type->m_isGetKeyDefined && - !participant_info->leave_middleware_default_qos) + !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( writer_qos.history(), diff --git a/rmw_fastrtps_cpp/src/subscription.cpp b/rmw_fastrtps_cpp/src/subscription.cpp index 05b0ba4ad9..78dada920f 100644 --- a/rmw_fastrtps_cpp/src/subscription.cpp +++ b/rmw_fastrtps_cpp/src/subscription.cpp @@ -394,7 +394,7 @@ __create_dynamic_subscription( // Apply resource limits QoS if the type is keyed if (fastdds_type->m_isGetKeyDefined && - !participant_info->leave_middleware_default_qos) + !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( reader_qos.history(), @@ -665,7 +665,7 @@ __create_subscription( // Apply resource limits QoS if the type is keyed if (fastdds_type->m_isGetKeyDefined && - !participant_info->leave_middleware_default_qos) + !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( reader_qos.history(), diff --git a/rmw_fastrtps_cpp/src/type_support_common.cpp b/rmw_fastrtps_cpp/src/type_support_common.cpp index 79c233f59d..e15925df7a 100644 --- a/rmw_fastrtps_cpp/src/type_support_common.cpp +++ b/rmw_fastrtps_cpp/src/type_support_common.cpp @@ -66,14 +66,12 @@ void TypeSupport::set_members(const message_type_support_callbacks_t * members) // Account for RTPS submessage alignment max_serialized_type_size = (max_serialized_type_size + 3) & ~3; - if (nullptr != members->key_callbacks) - { + if (nullptr != members->key_callbacks) { key_callbacks_ = members->key_callbacks; is_compute_key_provided = true; key_max_serialized_size_ = key_callbacks_->max_serialized_size_key(key_is_unbounded_); - if (!key_is_unbounded_) - { + if (!key_is_unbounded_) { key_buffer_.reserve(key_max_serialized_size_); } } @@ -150,17 +148,16 @@ bool TypeSupport::deserializeROSmessage( } bool TypeSupport::get_key_hash_from_ros_message( - void * ros_message, - eprosima::fastdds::rtps::InstanceHandle_t * ihandle, - bool force_md5, - const void * impl) const + void * ros_message, + eprosima::fastdds::rtps::InstanceHandle_t * ihandle, + bool force_md5, + const void * impl) const { assert(ros_message); (void)impl; // retrieve estimated serialized size in case key is unbounded - if (key_is_unbounded_) - { + if (key_is_unbounded_) { key_max_serialized_size_ = (std::max) ( key_max_serialized_size_, key_callbacks_->get_serialized_size_key(ros_message)); @@ -181,23 +178,18 @@ bool TypeSupport::get_key_hash_from_ros_message( auto ser_length = ser.get_serialized_data_length(); // check for md5 - if (force_md5 || key_max_serialized_size_ > max_serialized_key_length) - { + if (force_md5 || key_max_serialized_size_ > max_serialized_key_length) { md5_.init(); md5_.update(key_buffer_.data(), static_cast(ser_length)); md5_.finalize(); - for (uint8_t i = 0; i < max_serialized_key_length; ++i) - { + for (uint8_t i = 0; i < max_serialized_key_length; ++i) { ihandle->value[i] = md5_.digest[i]; } - } - else - { + } else { memset(ihandle->value, 0, max_serialized_key_length); - for (uint8_t i = 0; i < ser_length; ++i) - { - ihandle->value[i] = key_buffer_[i]; + for (uint8_t i = 0; i < ser_length; ++i) { + ihandle->value[i] = key_buffer_[i]; } } diff --git a/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp index ca2c098c8f..724f3098b9 100644 --- a/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp @@ -62,8 +62,7 @@ MessageTypeSupport::MessageTypeSupport( this->max_serialized_type_size++; } - if (this->members_->has_any_key_member_) - { + if (this->members_->has_any_key_member_) { this->key_max_serialized_size_ = this->calculateMaxSerializedKeySize(members); this->m_isGetKeyDefined = true; this->key_buffer_.reserve(this->key_max_serialized_size_); diff --git a/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp index 6ae2757189..f11d00df93 100644 --- a/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp @@ -63,8 +63,7 @@ RequestTypeSupport::RequestTypeSupport( this->max_serialized_type_size++; } - if (this->members_->has_any_key_member_) - { + if (this->members_->has_any_key_member_) { this->key_max_serialized_size_ = this->calculateMaxSerializedKeySize(this->members_); this->m_isGetKeyDefined = true; this->key_buffer_.reserve(this->key_max_serialized_size_); @@ -107,8 +106,7 @@ ResponseTypeSupport::ResponseTypeSupport this->max_serialized_type_size++; } - if (this->members_->has_any_key_member_) - { + if (this->members_->has_any_key_member_) { this->key_max_serialized_size_ = this->calculateMaxSerializedKeySize(this->members_); this->m_isGetKeyDefined = true; this->key_buffer_.reserve(this->key_max_serialized_size_); diff --git a/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp b/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp index 67c5ced78c..0852aab26f 100644 --- a/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp @@ -140,7 +140,8 @@ class TypeSupportProxy : public rmw_fastrtps_shared_cpp::TypeSupport eprosima::fastcdr::Cdr & deser, void * ros_message, const void * impl) const override; bool get_key_hash_from_ros_message( - void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const override; + void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, + const void * impl) const override; }; class BaseTypeSupport : public rmw_fastrtps_shared_cpp::TypeSupport @@ -189,7 +190,8 @@ class TypeSupport : public BaseTypeSupport eprosima::fastcdr::Cdr & deser, void * ros_message, const void * impl) const override; bool get_key_hash_from_ros_message( - void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const override; + void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, + const void * impl) const override; protected: // Meant for messages typesupport @@ -206,12 +208,11 @@ class TypeSupport : public BaseTypeSupport const MembersType * members_; private: - size_t calculateMaxSerializedSize( const MembersType * members, size_t current_alignment, bool compute_key, - bool& is_key_unbounded); + bool & is_key_unbounded); size_t getEstimatedSerializedSize( const MembersType * members, diff --git a/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp index bf1f5a7371..38daa1b0d0 100644 --- a/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp @@ -234,8 +234,7 @@ bool TypeSupport::serializeROSmessage( for (uint32_t i = 0; i < members->member_count_; ++i) { const auto member = members->members_ + i; - if (compute_key && !member->is_key_ && members->has_any_key_member_) - { + if (compute_key && !member->is_key_ && members->has_any_key_member_) { continue; } @@ -314,7 +313,9 @@ bool TypeSupport::serializeROSmessage( return false; } for (size_t index = 0; index < array_size; ++index) { - serializeROSmessage(ser, sub_members, member->get_function(field, index), compute_key); + serializeROSmessage( + ser, sub_members, member->get_function(field, index), + compute_key); } } } @@ -338,9 +339,10 @@ bool TypeSupport::get_key_hash_from_ros_message( assert(ros_message); // get estimated serialized size in case key is unbounded - if (this->key_is_unbounded_) - { - this->key_max_serialized_size_ = (std::max) (this->key_max_serialized_size_, this->getEstimatedSerializedKeySize(members, ros_message)); + if (this->key_is_unbounded_) { + this->key_max_serialized_size_ = + (std::max) (this->key_max_serialized_size_, + this->getEstimatedSerializedKeySize(members, ros_message)); key_buffer_.reserve(this->key_max_serialized_size_); } @@ -355,25 +357,22 @@ bool TypeSupport::get_key_hash_from_ros_message( serializeKeyROSmessage(ser, members_, ros_message); // check for md5 - if (force_md5 || this->key_max_serialized_size_ > 16) - { - md5_.init(); + if (force_md5 || this->key_max_serialized_size_ > 16) { + md5_.init(); - md5_.update(this->key_buffer_.data(), static_cast(ser.get_serialized_data_length())); + md5_.update( + this->key_buffer_.data(), + static_cast(ser.get_serialized_data_length())); - md5_.finalize(); + md5_.finalize(); - for (uint8_t i = 0; i < 16; ++i) - { - ihandle->value[i] = md5_.digest[i]; - } - } - else - { - for (uint8_t i = 0; i < 16; ++i) - { - ihandle->value[i] = this->key_buffer_[i]; - } + for (uint8_t i = 0; i < 16; ++i) { + ihandle->value[i] = md5_.digest[i]; + } + } else { + for (uint8_t i = 0; i < 16; ++i) { + ihandle->value[i] = this->key_buffer_[i]; + } } return true; @@ -576,8 +575,7 @@ size_t TypeSupport::getEstimatedSerializedSize( const auto member = members->members_ + i; void * field = const_cast(static_cast(ros_message)) + member->offset_; - if (compute_key && !member->is_key_ && members->has_any_key_member_) - { + if (compute_key && !member->is_key_ && members->has_any_key_member_) { continue; } @@ -627,7 +625,9 @@ size_t TypeSupport::getEstimatedSerializedSize( { auto sub_members = static_cast(member->members_->data); if (!member->is_array_) { - current_alignment += getEstimatedSerializedSize(sub_members, field, current_alignment, compute_key); + current_alignment += getEstimatedSerializedSize( + sub_members, field, current_alignment, + compute_key); } else { size_t array_size = 0; @@ -932,7 +932,7 @@ size_t TypeSupport::calculateMaxSerializedSize( const MembersType * members, size_t current_alignment, bool compute_key, - bool& is_key_unbounded) + bool & is_key_unbounded) { assert(members); @@ -946,8 +946,7 @@ size_t TypeSupport::calculateMaxSerializedSize( size_t array_size = 1; - if (compute_key && !member->is_key_ && members->has_any_key_member_) - { + if (compute_key && !member->is_key_ && members->has_any_key_member_) { continue; } @@ -1003,8 +1002,7 @@ size_t TypeSupport::calculateMaxSerializedSize( this->max_size_bound_ = false; this->is_plain_ = false; - if (compute_key) - { + if (compute_key) { is_key_unbounded = true; } @@ -1023,7 +1021,9 @@ size_t TypeSupport::calculateMaxSerializedSize( { auto sub_members = static_cast(member->members_->data); for (size_t index = 0; index < array_size; ++index) { - size_t curr = calculateMaxSerializedSize(sub_members, current_alignment, compute_key, is_key_unbounded); + size_t curr = calculateMaxSerializedSize( + sub_members, current_alignment, compute_key, + is_key_unbounded); current_alignment += curr; last_member_size += curr; } @@ -1125,7 +1125,8 @@ bool TypeSupport::deserializeROSmessage( template bool TypeSupport::get_key_hash_from_ros_message( - void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const + void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, + const void * impl) const { assert(ros_message); @@ -1134,8 +1135,7 @@ bool TypeSupport::get_key_hash_from_ros_message( bool ret = false; (void)impl; - if (members_->member_count_ != 0) - { + if (members_->member_count_ != 0) { ret = TypeSupport::get_key_hash_from_ros_message(members_, ros_message, ihandle, force_md5); } diff --git a/rmw_fastrtps_dynamic_cpp/src/publisher.cpp b/rmw_fastrtps_dynamic_cpp/src/publisher.cpp index b79bb3c79b..c520959448 100644 --- a/rmw_fastrtps_dynamic_cpp/src/publisher.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/publisher.cpp @@ -273,7 +273,7 @@ rmw_fastrtps_dynamic_cpp::create_publisher( // Apply resource limits QoS if the type is keyed if (fastdds_type->m_isGetKeyDefined && - !participant_info->leave_middleware_default_qos) + !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( writer_qos.history(), diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp index e328f0a677..2d19572393 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp @@ -359,7 +359,7 @@ rmw_create_client( // Apply resource limits QoS if the type is keyed if (response_fastdds_type->m_isGetKeyDefined && - !participant_info->leave_middleware_default_qos) + !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( reader_qos.history(), @@ -426,7 +426,7 @@ rmw_create_client( // Apply resource limits QoS if the type is keyed if (request_fastdds_type->m_isGetKeyDefined && - !participant_info->leave_middleware_default_qos) + !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( writer_qos.history(), diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp index a83b4a25ce..aba11c10a8 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp @@ -355,7 +355,7 @@ rmw_create_service( // Apply resource limits QoS if the type is keyed if (request_fastdds_type->m_isGetKeyDefined && - !participant_info->leave_middleware_default_qos) + !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( reader_qos.history(), @@ -426,7 +426,7 @@ rmw_create_service( // Apply resource limits QoS if the type is keyed if (response_fastdds_type->m_isGetKeyDefined && - !participant_info->leave_middleware_default_qos) + !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( writer_qos.history(), diff --git a/rmw_fastrtps_dynamic_cpp/src/subscription.cpp b/rmw_fastrtps_dynamic_cpp/src/subscription.cpp index 18fe9acb7f..c6c15a3244 100644 --- a/rmw_fastrtps_dynamic_cpp/src/subscription.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/subscription.cpp @@ -274,7 +274,7 @@ create_subscription( // Apply resource limits QoS if the type is keyed if (fastdds_type->m_isGetKeyDefined && - !participant_info->leave_middleware_default_qos) + !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( reader_qos.history(), diff --git a/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp b/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp index a36dcadc10..0e7bb4c8bf 100644 --- a/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp @@ -50,7 +50,8 @@ bool TypeSupportProxy::deserializeROSmessage( } bool TypeSupportProxy::get_key_hash_from_ros_message( - void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const + void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, + const void * impl) const { auto type_impl = static_cast(impl); return type_impl->get_key_hash_from_ros_message(ros_message, ihandle, force_md5, impl); diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp index ee7723c8a0..6b6bb6eb28 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp @@ -62,7 +62,8 @@ class TypeSupport : public eprosima::fastdds::dds::TopicDataType eprosima::fastcdr::Cdr & deser, void * ros_message, const void * impl) const = 0; virtual bool get_key_hash_from_ros_message( - void * ros_message, eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const = 0; + void * ros_message, eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, + const void * impl) const = 0; RMW_FASTRTPS_SHARED_CPP_PUBLIC bool compute_key( diff --git a/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp b/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp index 1a8b64cc79..632364f8ff 100644 --- a/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp +++ b/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp @@ -67,27 +67,26 @@ void * TypeSupport::create_data() } bool TypeSupport::compute_key( - const void * const data, - eprosima::fastdds::rtps::InstanceHandle_t & ihandle, - bool force_md5) + const void * const data, + eprosima::fastdds::rtps::InstanceHandle_t & ihandle, + bool force_md5) { assert(data); bool ret = false; - if (!is_compute_key_provided) - { - return ret; + if (!is_compute_key_provided) { + return ret; } auto ser_data = static_cast(data); - switch (ser_data->type) - { + switch (ser_data->type) { case FASTDDS_SERIALIZED_DATA_TYPE_ROS_MESSAGE: { std::lock_guard lock(this->mtx_); - ret = this->get_key_hash_from_ros_message(ser_data->data, &ihandle, force_md5, ser_data->impl); + ret = + this->get_key_hash_from_ros_message(ser_data->data, &ihandle, force_md5, ser_data->impl); break; } diff --git a/rmw_fastrtps_shared_cpp/src/utils.cpp b/rmw_fastrtps_shared_cpp/src/utils.cpp index 7d53718eda..a781020107 100644 --- a/rmw_fastrtps_shared_cpp/src/utils.cpp +++ b/rmw_fastrtps_shared_cpp/src/utils.cpp @@ -188,12 +188,9 @@ apply_qos_resource_limits_for_keys( { res_limits_qos.max_instances = 0; res_limits_qos.max_samples = 0; - if (history_qos.kind == eprosima::fastdds::dds::KEEP_LAST_HISTORY_QOS) - { + if (history_qos.kind == eprosima::fastdds::dds::KEEP_LAST_HISTORY_QOS) { res_limits_qos.max_samples_per_instance = history_qos.depth; - } - else - { + } else { res_limits_qos.max_samples_per_instance = 0; } } From 328c6bf568abb42575bed65298389d1778eb8942 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Mon, 1 Apr 2024 13:31:20 +0000 Subject: [PATCH 09/15] Rev changes 2 Signed-off-by: Mario Dominguez --- rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp | 4 +++- rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp index 792a7fb705..620f31c40d 100644 --- a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp +++ b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp @@ -45,7 +45,9 @@ class TypeSupport : public rmw_fastrtps_shared_cpp::TypeSupport explicit TypeSupport(const rosidl_message_type_support_t * type_supports); bool get_key_hash_from_ros_message( - void * ros_message, eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, + void * ros_message, + eprosima::fastdds::rtps::InstanceHandle_t * ihandle, + bool force_md5, const void * impl) const override; protected: diff --git a/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp b/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp index 0852aab26f..0b08622527 100644 --- a/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp @@ -190,7 +190,9 @@ class TypeSupport : public BaseTypeSupport eprosima::fastcdr::Cdr & deser, void * ros_message, const void * impl) const override; bool get_key_hash_from_ros_message( - void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, + void * ros_message, + eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, + bool force_md5, const void * impl) const override; protected: From 75d01db7502d1c625e8a4dbe1971861c640dcb3b Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 1 Apr 2024 17:04:22 +0200 Subject: [PATCH 10/15] More linters Signed-off-by: Miguel Company --- rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp | 3 +-- .../include/rmw_fastrtps_shared_cpp/TypeSupport.hpp | 1 + rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp index 38daa1b0d0..6c645b6b8d 100644 --- a/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp @@ -916,7 +916,7 @@ template size_t TypeSupport::calculateMaxSerializedSize( const MembersType * members, size_t current_alignment) { - bool is_key_unbounded{false}; //unused + bool is_key_unbounded{false}; // unused return calculateMaxSerializedSize(members, current_alignment, false, is_key_unbounded); } @@ -1128,7 +1128,6 @@ bool TypeSupport::get_key_hash_from_ros_message( void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const { - assert(ros_message); assert(members_); diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp index 6b6bb6eb28..40701566f8 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp @@ -17,6 +17,7 @@ #include #include +#include #include "fastdds/dds/topic/TopicDataType.hpp" #include "fastdds/rtps/common/InstanceHandle.hpp" diff --git a/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp b/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp index 632364f8ff..206faf3d08 100644 --- a/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp +++ b/rmw_fastrtps_shared_cpp/src/TypeSupport_impl.cpp @@ -92,14 +92,13 @@ bool TypeSupport::compute_key( case FASTDDS_SERIALIZED_DATA_TYPE_CDR_BUFFER: { - // TODO - // We would need a get_key_hash_from_payload method + // TODO(MiguelCompany): In order to support keys in rmw_publish_serialized_message, + // we would need a get_key_hash_from_payload method break; } case FASTDDS_SERIALIZED_DATA_TYPE_DYNAMIC_MESSAGE: { - auto m_type = std::make_shared(); // Retrieves the key (ihandle) from the dynamic data stored in data->data From dba8030b589c43980d9ad0e4213be9d7914b2515 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 29 Oct 2024 15:02:15 +0100 Subject: [PATCH 11/15] Typo Signed-off-by: Mario Dominguez --- .../include/rmw_fastrtps_shared_cpp/utils.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/utils.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/utils.hpp index a2b27abe11..5293072246 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/utils.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/utils.hpp @@ -131,7 +131,7 @@ create_datareader( * Max samples per instance is set to history depth if KEEP_LAST * else UNLIMITED. * -* \param[in] hitory_qos History entitiy QoS. +* \param[in] history_qos History entitiy QoS. * \param[in, out] res_limits_qos Resource limits entitiy QoS. * */ From 4103bce439901a167ab3e68f0a65a0623e6b0898 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 5 Nov 2024 08:21:29 +0100 Subject: [PATCH 12/15] Add assert(ihandle) Signed-off-by: Mario Dominguez --- rmw_fastrtps_cpp/src/type_support_common.cpp | 1 + rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/rmw_fastrtps_cpp/src/type_support_common.cpp b/rmw_fastrtps_cpp/src/type_support_common.cpp index e15925df7a..316cc6cccd 100644 --- a/rmw_fastrtps_cpp/src/type_support_common.cpp +++ b/rmw_fastrtps_cpp/src/type_support_common.cpp @@ -154,6 +154,7 @@ bool TypeSupport::get_key_hash_from_ros_message( const void * impl) const { assert(ros_message); + assert(ihandle); (void)impl; // retrieve estimated serialized size in case key is unbounded diff --git a/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp index 6c645b6b8d..e7f101059a 100644 --- a/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp @@ -337,6 +337,7 @@ bool TypeSupport::get_key_hash_from_ros_message( { assert(members); assert(ros_message); + assert(ihandle); // get estimated serialized size in case key is unbounded if (this->key_is_unbounded_) { @@ -1129,6 +1130,7 @@ bool TypeSupport::get_key_hash_from_ros_message( const void * impl) const { assert(ros_message); + assert(ihandle); assert(members_); bool ret = false; From 5b21627a0e1be857ec7f5626af364d71c3f42cf4 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 5 Nov 2024 08:21:48 +0100 Subject: [PATCH 13/15] Align argument Signed-off-by: Mario Dominguez --- .../include/rmw_fastrtps_shared_cpp/utils.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/utils.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/utils.hpp index 5293072246..6a501c71da 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/utils.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/utils.hpp @@ -131,7 +131,7 @@ create_datareader( * Max samples per instance is set to history depth if KEEP_LAST * else UNLIMITED. * -* \param[in] history_qos History entitiy QoS. +* \param[in] history_qos History entitiy QoS. * \param[in, out] res_limits_qos Resource limits entitiy QoS. * */ From 44f3327447b5055b1967d2ea805622100832624a Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 2 Apr 2025 11:37:58 +0200 Subject: [PATCH 14/15] Fix build after rebase Signed-off-by: Miguel Company --- rmw_fastrtps_cpp/src/publisher.cpp | 2 +- rmw_fastrtps_cpp/src/rmw_client.cpp | 4 ++-- rmw_fastrtps_cpp/src/rmw_service.cpp | 4 ++-- rmw_fastrtps_cpp/src/subscription.cpp | 4 ++-- rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp | 2 +- rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp | 4 ++-- rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp | 6 +++--- rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp | 4 ++-- rmw_fastrtps_dynamic_cpp/src/publisher.cpp | 2 +- rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp | 4 ++-- rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp | 4 ++-- rmw_fastrtps_dynamic_cpp/src/subscription.cpp | 2 +- rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp | 4 ++-- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/rmw_fastrtps_cpp/src/publisher.cpp b/rmw_fastrtps_cpp/src/publisher.cpp index 8ed920dad5..3ad3139280 100644 --- a/rmw_fastrtps_cpp/src/publisher.cpp +++ b/rmw_fastrtps_cpp/src/publisher.cpp @@ -260,7 +260,7 @@ rmw_fastrtps_cpp::create_publisher( } // Apply resource limits QoS if the type is keyed - if (fastdds_type->m_isGetKeyDefined && + if (fastdds_type->is_compute_key_provided && !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( diff --git a/rmw_fastrtps_cpp/src/rmw_client.cpp b/rmw_fastrtps_cpp/src/rmw_client.cpp index 228e931398..4f052b73d6 100644 --- a/rmw_fastrtps_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_cpp/src/rmw_client.cpp @@ -329,7 +329,7 @@ rmw_create_client( } // Apply resource limits QoS if the type is keyed - if (response_fastdds_type->m_isGetKeyDefined && + if (response_fastdds_type->is_compute_key_provided && !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( @@ -396,7 +396,7 @@ rmw_create_client( } // Apply resource limits QoS if the type is keyed - if (request_fastdds_type->m_isGetKeyDefined && + if (request_fastdds_type->is_compute_key_provided && !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( diff --git a/rmw_fastrtps_cpp/src/rmw_service.cpp b/rmw_fastrtps_cpp/src/rmw_service.cpp index bd842b41cc..0dc457abdf 100644 --- a/rmw_fastrtps_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_cpp/src/rmw_service.cpp @@ -325,7 +325,7 @@ rmw_create_service( } // Apply resource limits QoS if the type is keyed - if (request_fastdds_type->m_isGetKeyDefined && + if (request_fastdds_type->is_compute_key_provided && !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( @@ -396,7 +396,7 @@ rmw_create_service( } // Apply resource limits QoS if the type is keyed - if (response_fastdds_type->m_isGetKeyDefined && + if (response_fastdds_type->is_compute_key_provided && !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( diff --git a/rmw_fastrtps_cpp/src/subscription.cpp b/rmw_fastrtps_cpp/src/subscription.cpp index 78dada920f..f4b4242ae5 100644 --- a/rmw_fastrtps_cpp/src/subscription.cpp +++ b/rmw_fastrtps_cpp/src/subscription.cpp @@ -393,7 +393,7 @@ __create_dynamic_subscription( } // Apply resource limits QoS if the type is keyed - if (fastdds_type->m_isGetKeyDefined && + if (fastdds_type->is_compute_key_provided && !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( @@ -664,7 +664,7 @@ __create_subscription( } // Apply resource limits QoS if the type is keyed - if (fastdds_type->m_isGetKeyDefined && + if (fastdds_type->is_compute_key_provided && !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( diff --git a/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp index 724f3098b9..84405be569 100644 --- a/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/MessageTypeSupport_impl.hpp @@ -64,7 +64,7 @@ MessageTypeSupport::MessageTypeSupport( if (this->members_->has_any_key_member_) { this->key_max_serialized_size_ = this->calculateMaxSerializedKeySize(members); - this->m_isGetKeyDefined = true; + this->is_compute_key_provided = true; this->key_buffer_.reserve(this->key_max_serialized_size_); } diff --git a/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp index f11d00df93..bed1661af5 100644 --- a/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/ServiceTypeSupport_impl.hpp @@ -65,7 +65,7 @@ RequestTypeSupport::RequestTypeSupport( if (this->members_->has_any_key_member_) { this->key_max_serialized_size_ = this->calculateMaxSerializedKeySize(this->members_); - this->m_isGetKeyDefined = true; + this->is_compute_key_provided = true; this->key_buffer_.reserve(this->key_max_serialized_size_); } @@ -108,7 +108,7 @@ ResponseTypeSupport::ResponseTypeSupport if (this->members_->has_any_key_member_) { this->key_max_serialized_size_ = this->calculateMaxSerializedKeySize(this->members_); - this->m_isGetKeyDefined = true; + this->is_compute_key_provided = true; this->key_buffer_.reserve(this->key_max_serialized_size_); } diff --git a/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp b/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp index 0b08622527..ffc7e5aa15 100644 --- a/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/TypeSupport.hpp @@ -140,7 +140,7 @@ class TypeSupportProxy : public rmw_fastrtps_shared_cpp::TypeSupport eprosima::fastcdr::Cdr & deser, void * ros_message, const void * impl) const override; bool get_key_hash_from_ros_message( - void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, + void * ros_message, eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const override; }; @@ -191,7 +191,7 @@ class TypeSupport : public BaseTypeSupport bool get_key_hash_from_ros_message( void * ros_message, - eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, + eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const override; @@ -255,7 +255,7 @@ class TypeSupport : public BaseTypeSupport bool get_key_hash_from_ros_message( const MembersType * members, void * ros_message, - eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, + eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5) const; }; diff --git a/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp index e7f101059a..210ba3d006 100644 --- a/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp @@ -332,7 +332,7 @@ template bool TypeSupport::get_key_hash_from_ros_message( const MembersType * members, void * ros_message, - eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, + eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5) const { assert(members); @@ -1126,7 +1126,7 @@ bool TypeSupport::deserializeROSmessage( template bool TypeSupport::get_key_hash_from_ros_message( - void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, + void * ros_message, eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const { assert(ros_message); diff --git a/rmw_fastrtps_dynamic_cpp/src/publisher.cpp b/rmw_fastrtps_dynamic_cpp/src/publisher.cpp index c520959448..5f3168e6cc 100644 --- a/rmw_fastrtps_dynamic_cpp/src/publisher.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/publisher.cpp @@ -272,7 +272,7 @@ rmw_fastrtps_dynamic_cpp::create_publisher( } // Apply resource limits QoS if the type is keyed - if (fastdds_type->m_isGetKeyDefined && + if (fastdds_type->is_compute_key_provided && !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp index 2d19572393..483c03cd42 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp @@ -358,7 +358,7 @@ rmw_create_client( } // Apply resource limits QoS if the type is keyed - if (response_fastdds_type->m_isGetKeyDefined && + if (response_fastdds_type->is_compute_key_provided && !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( @@ -425,7 +425,7 @@ rmw_create_client( } // Apply resource limits QoS if the type is keyed - if (request_fastdds_type->m_isGetKeyDefined && + if (request_fastdds_type->is_compute_key_provided && !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp index aba11c10a8..3c6201b182 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp @@ -354,7 +354,7 @@ rmw_create_service( } // Apply resource limits QoS if the type is keyed - if (request_fastdds_type->m_isGetKeyDefined && + if (request_fastdds_type->is_compute_key_provided && !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( @@ -425,7 +425,7 @@ rmw_create_service( } // Apply resource limits QoS if the type is keyed - if (response_fastdds_type->m_isGetKeyDefined && + if (response_fastdds_type->is_compute_key_provided && !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( diff --git a/rmw_fastrtps_dynamic_cpp/src/subscription.cpp b/rmw_fastrtps_dynamic_cpp/src/subscription.cpp index c6c15a3244..4c7f2acd9f 100644 --- a/rmw_fastrtps_dynamic_cpp/src/subscription.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/subscription.cpp @@ -273,7 +273,7 @@ create_subscription( } // Apply resource limits QoS if the type is keyed - if (fastdds_type->m_isGetKeyDefined && + if (fastdds_type->is_compute_key_provided && !participant_info->leave_middleware_default_qos) { rmw_fastrtps_shared_cpp::apply_qos_resource_limits_for_keys( diff --git a/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp b/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp index 0e7bb4c8bf..63a66cc8cd 100644 --- a/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp @@ -24,7 +24,7 @@ TypeSupportProxy::TypeSupportProxy(rmw_fastrtps_shared_cpp::TypeSupport * inner_ max_serialized_type_size = inner_type->max_serialized_type_size; is_plain_ = inner_type->is_plain(eprosima::fastdds::dds::XCDR_DATA_REPRESENTATION); max_size_bound_ = inner_type->is_bounded(); - m_isGetKeyDefined = inner_type->m_isGetKeyDefined; + is_compute_key_provided = inner_type->is_compute_key_provided; key_is_unbounded_ = inner_type->is_key_unbounded(); } @@ -50,7 +50,7 @@ bool TypeSupportProxy::deserializeROSmessage( } bool TypeSupportProxy::get_key_hash_from_ros_message( - void * ros_message, eprosima::fastrtps::rtps::InstanceHandle_t * ihandle, bool force_md5, + void * ros_message, eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, const void * impl) const { auto type_impl = static_cast(impl); From 06b640d83502867c1a20501f7321d96ad6380dc7 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 7 Apr 2025 08:29:03 +0200 Subject: [PATCH 15/15] Make `get_key_hash_from_ros_message` more modern and readable. Signed-off-by: Miguel Company --- rmw_fastrtps_cpp/src/type_support_common.cpp | 3 +-- rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp | 7 ++++--- rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp | 4 +++- .../include/rmw_fastrtps_shared_cpp/TypeSupport.hpp | 4 +++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/rmw_fastrtps_cpp/src/type_support_common.cpp b/rmw_fastrtps_cpp/src/type_support_common.cpp index 316cc6cccd..7b7f5ff2c8 100644 --- a/rmw_fastrtps_cpp/src/type_support_common.cpp +++ b/rmw_fastrtps_cpp/src/type_support_common.cpp @@ -151,11 +151,10 @@ bool TypeSupport::get_key_hash_from_ros_message( void * ros_message, eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, - const void * impl) const + const void * [[maybe_unused]] impl) const { assert(ros_message); assert(ihandle); - (void)impl; // retrieve estimated serialized size in case key is unbounded if (key_is_unbounded_) { diff --git a/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp index 210ba3d006..c27ebb386d 100644 --- a/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/TypeSupport_impl.hpp @@ -1126,8 +1126,10 @@ bool TypeSupport::deserializeROSmessage( template bool TypeSupport::get_key_hash_from_ros_message( - void * ros_message, eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, - const void * impl) const + void * ros_message, + eprosima::fastdds::rtps::InstanceHandle_t * ihandle, + bool force_md5, + const void * [[maybe_unused]] impl) const { assert(ros_message); assert(ihandle); @@ -1135,7 +1137,6 @@ bool TypeSupport::get_key_hash_from_ros_message( bool ret = false; - (void)impl; if (members_->member_count_ != 0) { ret = TypeSupport::get_key_hash_from_ros_message(members_, ros_message, ihandle, force_md5); } diff --git a/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp b/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp index 63a66cc8cd..335f15dd06 100644 --- a/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/type_support_proxy.cpp @@ -50,7 +50,9 @@ bool TypeSupportProxy::deserializeROSmessage( } bool TypeSupportProxy::get_key_hash_from_ros_message( - void * ros_message, eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, + void * ros_message, + eprosima::fastdds::rtps::InstanceHandle_t * ihandle, + bool force_md5, const void * impl) const { auto type_impl = static_cast(impl); diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp index 40701566f8..20726828c6 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/TypeSupport.hpp @@ -63,7 +63,9 @@ class TypeSupport : public eprosima::fastdds::dds::TopicDataType eprosima::fastcdr::Cdr & deser, void * ros_message, const void * impl) const = 0; virtual bool get_key_hash_from_ros_message( - void * ros_message, eprosima::fastdds::rtps::InstanceHandle_t * ihandle, bool force_md5, + void * ros_message, + eprosima::fastdds::rtps::InstanceHandle_t * ihandle, + bool force_md5, const void * impl) const = 0; RMW_FASTRTPS_SHARED_CPP_PUBLIC