From 127154ae444b1354036c9e862b7666e172d621d8 Mon Sep 17 00:00:00 2001 From: adriancampo Date: Mon, 4 Mar 2024 10:29:57 +0100 Subject: [PATCH 1/3] Refs #20565: Added Annotation dependencies Signed-off-by: adriancampo --- .../TypeObjectRegistry.cpp | 135 ++++++++++++++++++ .../TypeObjectRegistry.hpp | 12 ++ 2 files changed, 147 insertions(+) diff --git a/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp b/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp index 63ad2e18d4b..8e0049062f8 100644 --- a/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp +++ b/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp @@ -518,30 +518,140 @@ ReturnCode_t TypeObjectRegistry::get_dependencies_from_type_object( { case TK_ALIAS: ret_code = get_alias_dependencies(type_object.complete().alias_type(), type_dependencies); + + if (ret_code == eprosima::fastdds::dds::RETCODE_OK && + type_object.complete().alias_type().header().detail().ann_custom().has_value()) + { + ret_code = get_custom_annotations_dependencies( + type_object.complete().alias_type().header().detail().ann_custom().value(), + type_dependencies); + } + + if (ret_code == eprosima::fastdds::dds::RETCODE_OK && + type_object.complete().alias_type().body().ann_custom().has_value()) + { + ret_code = get_custom_annotations_dependencies( + type_object.complete().alias_type().body().ann_custom().value(), + type_dependencies); + } break; case TK_ANNOTATION: ret_code = get_annotation_dependencies(type_object.complete().annotation_type(), type_dependencies); break; case TK_STRUCTURE: ret_code = get_structure_dependencies(type_object.complete().struct_type(), type_dependencies); + if (ret_code == eprosima::fastdds::dds::RETCODE_OK && + type_object.complete().struct_type().header().detail().ann_custom().has_value()) + { + ret_code = get_custom_annotations_dependencies( + type_object.complete().struct_type().header().detail().ann_custom().value(), + type_dependencies); + } + if (ret_code == eprosima::fastdds::dds::RETCODE_OK) + { + for (auto member : type_object.complete().struct_type().member_seq()) + { + if (member.detail().ann_custom().has_value()) + { + ret_code = get_custom_annotations_dependencies( + member.detail().ann_custom().value(), type_dependencies); + if (ret_code != eprosima::fastdds::dds::RETCODE_OK) + { + break; + } + } + } + } break; case TK_UNION: ret_code = get_union_dependencies(type_object.complete().union_type(), type_dependencies); + + if (ret_code == eprosima::fastdds::dds::RETCODE_OK && + type_object.complete().union_type().header().detail().ann_custom().has_value()) + { + ret_code = get_custom_annotations_dependencies( + type_object.complete().union_type().header().detail().ann_custom().value(), + type_dependencies); + } + + if (ret_code == eprosima::fastdds::dds::RETCODE_OK && + type_object.complete().union_type().discriminator().ann_custom().has_value()) + { + ret_code = get_custom_annotations_dependencies( + type_object.complete().union_type().discriminator().ann_custom().value(), + type_dependencies); + } + if (ret_code == eprosima::fastdds::dds::RETCODE_OK) + { + for (auto member : type_object.complete().union_type().member_seq()) + { + if (member.detail().ann_custom().has_value()) + { + ret_code = get_custom_annotations_dependencies( + member.detail().ann_custom().value(), type_dependencies); + if (ret_code != eprosima::fastdds::dds::RETCODE_OK) + { + break; + } + } + } + } break; case TK_SEQUENCE: ret_code = get_sequence_array_dependencies(type_object.complete().sequence_type(), type_dependencies); + //TODO Annotations are not currently supported, so their dependecies are ignored. break; case TK_ARRAY: ret_code = get_sequence_array_dependencies(type_object.complete().array_type(), type_dependencies); + //TODO Annotations are not currently supported, so their dependecies are ignored. break; case TK_MAP: ret_code = get_map_dependencies(type_object.complete().map_type(), type_dependencies); + //TODO Annotations are not currently supported, so their dependecies are ignored. break; // No dependencies case TK_BITSET: + if (ret_code == eprosima::fastdds::dds::RETCODE_OK && + type_object.complete().bitset_type().header().detail().ann_custom().has_value()) + { + ret_code = get_custom_annotations_dependencies( + type_object.complete().bitset_type().header().detail().ann_custom().value(), + type_dependencies); + } + if (ret_code == eprosima::fastdds::dds::RETCODE_OK) + { + for (auto member : type_object.complete().bitset_type().field_seq()) + { + if (member.detail().ann_custom().has_value()) + { + ret_code = get_custom_annotations_dependencies( + member.detail().ann_custom().value(), type_dependencies); + if (ret_code != eprosima::fastdds::dds::RETCODE_OK) + { + break; + } + } + } + } + break; case TK_ENUM: + if (ret_code == eprosima::fastdds::dds::RETCODE_OK && + type_object.complete().enumerated_type().header().detail().ann_custom().has_value()) + { + ret_code = get_custom_annotations_dependencies( + type_object.complete().enumerated_type().header().detail().ann_custom().value(), + type_dependencies); + } + break; case TK_BITMASK: + if (ret_code == eprosima::fastdds::dds::RETCODE_OK && + type_object.complete().bitmask_type().header().detail().ann_custom().has_value()) + { + ret_code = get_custom_annotations_dependencies( + type_object.complete().bitmask_type().header().detail().ann_custom().value(), + type_dependencies); + } break; } break; @@ -616,6 +726,31 @@ void TypeObjectRegistry::add_dependency( type_dependencies.insert(type_id_size); } +ReturnCode_t TypeObjectRegistry::get_custom_annotations_dependencies( + const AppliedAnnotationSeq& custom_annotation_seq, + std::unordered_set& type_dependencies) +{ + TypeIdentifierSeq type_ids; + for (auto ann : custom_annotation_seq) + { + TypeIdentifier type_id = ann.annotation_typeid(); + if (TypeObjectUtils::is_direct_hash_type_identifier(type_id)) + { + add_dependency(type_id, type_dependencies); + type_ids.push_back(type_id); + } + else if (TypeObjectUtils::is_indirect_hash_type_identifier(type_id)) + { + type_ids.push_back(type_id); + } + } + if (!type_ids.empty()) + { + return get_type_dependencies(type_ids, type_dependencies); + } + return eprosima::fastdds::dds::RETCODE_OK; +} + bool TypeObjectRegistry::is_builtin_annotation_name( const std::string& name) { diff --git a/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.hpp b/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.hpp index 2e70cae2ccf..32c99576a49 100644 --- a/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.hpp +++ b/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.hpp @@ -298,6 +298,18 @@ class TypeObjectRegistry : public ITypeObjectRegistry const TypeIdentifier& type_id, std::unordered_set& type_dependencies); + /** + * @brief Get the type dependencies of custom annotations. + * + * @param[in] custom_annotation_seq Sequence of custom annotations. + * @param[in out] type_dependencies Unordered set of TypeIdentifiers with related TypeObject serialized size. + * @return ReturnCode_t RETCODE_OK if the operation is successful. + * RETCODE_NO_DATA if any dependent TypeIdentifier is unknown to the registry. + */ + ReturnCode_t get_custom_annotations_dependencies( + const AppliedAnnotationSeq& custom_annotation_seq, + std::unordered_set& type_dependencies); + /** * @brief Get the type dependencies of plain sequences or arrays. * From e6bbcb4eef25966bbcbe8431ae140705ef498cea Mon Sep 17 00:00:00 2001 From: adriancampo Date: Wed, 20 Mar 2024 12:29:50 +0100 Subject: [PATCH 2/3] Refs #20565: Applied suggestions. Added missing enum and bitmask dependencies. Signed-off-by: adriancampo --- .../TypeObjectRegistry.cpp | 43 ++++++++++++++++--- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp b/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp index 8e0049062f8..379c9c6da7c 100644 --- a/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp +++ b/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp @@ -549,7 +549,7 @@ ReturnCode_t TypeObjectRegistry::get_dependencies_from_type_object( } if (ret_code == eprosima::fastdds::dds::RETCODE_OK) { - for (auto member : type_object.complete().struct_type().member_seq()) + for (CompleteStructMember member : type_object.complete().struct_type().member_seq()) { if (member.detail().ann_custom().has_value()) { @@ -583,7 +583,7 @@ ReturnCode_t TypeObjectRegistry::get_dependencies_from_type_object( } if (ret_code == eprosima::fastdds::dds::RETCODE_OK) { - for (auto member : type_object.complete().union_type().member_seq()) + for (CompleteUnionMember member : type_object.complete().union_type().member_seq()) { if (member.detail().ann_custom().has_value()) { @@ -600,17 +600,16 @@ ReturnCode_t TypeObjectRegistry::get_dependencies_from_type_object( case TK_SEQUENCE: ret_code = get_sequence_array_dependencies(type_object.complete().sequence_type(), type_dependencies); - //TODO Annotations are not currently supported, so their dependecies are ignored. + //TODO Collection nnotations are not currently supported, so their dependecies are ignored. break; case TK_ARRAY: ret_code = get_sequence_array_dependencies(type_object.complete().array_type(), type_dependencies); - //TODO Annotations are not currently supported, so their dependecies are ignored. + //TODO Collection nnotations are not currently supported, so their dependecies are ignored. break; case TK_MAP: ret_code = get_map_dependencies(type_object.complete().map_type(), type_dependencies); - //TODO Annotations are not currently supported, so their dependecies are ignored. + //TODO Collection nnotations are not currently supported, so their dependecies are ignored. break; - // No dependencies case TK_BITSET: if (ret_code == eprosima::fastdds::dds::RETCODE_OK && type_object.complete().bitset_type().header().detail().ann_custom().has_value()) @@ -621,7 +620,7 @@ ReturnCode_t TypeObjectRegistry::get_dependencies_from_type_object( } if (ret_code == eprosima::fastdds::dds::RETCODE_OK) { - for (auto member : type_object.complete().bitset_type().field_seq()) + for (CompleteBitfield member : type_object.complete().bitset_type().field_seq()) { if (member.detail().ann_custom().has_value()) { @@ -643,6 +642,21 @@ ReturnCode_t TypeObjectRegistry::get_dependencies_from_type_object( type_object.complete().enumerated_type().header().detail().ann_custom().value(), type_dependencies); } + if (ret_code == eprosima::fastdds::dds::RETCODE_OK) + { + for (CompleteEnumeratedLiteral member : type_object.complete().enumerated_type().literal_seq()) + { + if (member.detail().ann_custom().has_value()) + { + ret_code = get_custom_annotations_dependencies( + member.detail().ann_custom().value(), type_dependencies); + if (ret_code != eprosima::fastdds::dds::RETCODE_OK) + { + break; + } + } + } + } break; case TK_BITMASK: if (ret_code == eprosima::fastdds::dds::RETCODE_OK && @@ -652,6 +666,21 @@ ReturnCode_t TypeObjectRegistry::get_dependencies_from_type_object( type_object.complete().bitmask_type().header().detail().ann_custom().value(), type_dependencies); } + if (ret_code == eprosima::fastdds::dds::RETCODE_OK) + { + for (CompleteBitflag member : type_object.complete().bitmask_type().flag_seq()) + { + if (member.detail().ann_custom().has_value()) + { + ret_code = get_custom_annotations_dependencies( + member.detail().ann_custom().value(), type_dependencies); + if (ret_code != eprosima::fastdds::dds::RETCODE_OK) + { + break; + } + } + } + } break; } break; From ebe8b05e5a9dd94d69a3aa313e7b1a14ce5b3e93 Mon Sep 17 00:00:00 2001 From: adriancampo Date: Wed, 20 Mar 2024 12:56:54 +0100 Subject: [PATCH 3/3] Refs #20565: Typo. Signed-off-by: adriancampo --- .../xtypes/type_representation/TypeObjectRegistry.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp b/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp index 379c9c6da7c..807ac997a1b 100644 --- a/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp +++ b/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp @@ -600,15 +600,15 @@ ReturnCode_t TypeObjectRegistry::get_dependencies_from_type_object( case TK_SEQUENCE: ret_code = get_sequence_array_dependencies(type_object.complete().sequence_type(), type_dependencies); - //TODO Collection nnotations are not currently supported, so their dependecies are ignored. + //TODO Collection annotations are not currently supported, so their dependencies are ignored. break; case TK_ARRAY: ret_code = get_sequence_array_dependencies(type_object.complete().array_type(), type_dependencies); - //TODO Collection nnotations are not currently supported, so their dependecies are ignored. + //TODO Collection annotations are not currently supported, so their dependencies are ignored. break; case TK_MAP: ret_code = get_map_dependencies(type_object.complete().map_type(), type_dependencies); - //TODO Collection nnotations are not currently supported, so their dependecies are ignored. + //TODO Collection annotations are not currently supported, so their dependencies are ignored. break; case TK_BITSET: if (ret_code == eprosima::fastdds::dds::RETCODE_OK &&