Skip to content

Commit

Permalink
Added Annotation dependencies (#4497)
Browse files Browse the repository at this point in the history
* Refs #20565: Added Annotation dependencies

Signed-off-by: adriancampo <adriancampo@eprosima.com>

* Refs #20565: Applied suggestions. Added missing enum and bitmask dependencies.

Signed-off-by: adriancampo <adriancampo@eprosima.com>

* Refs #20565: Typo.

Signed-off-by: adriancampo <adriancampo@eprosima.com>

---------

Signed-off-by: adriancampo <adriancampo@eprosima.com>
  • Loading branch information
adriancampo authored Mar 21, 2024
1 parent 3a75413 commit 45ea8b7
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 1 deletion.
166 changes: 165 additions & 1 deletion src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,30 +518,169 @@ 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 (CompleteStructMember 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 (CompleteUnionMember 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 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 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 annotations are not currently supported, so their dependencies 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 (CompleteBitfield 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);
}
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 &&
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);
}
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;
Expand Down Expand Up @@ -616,6 +755,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<TypeIdentfierWithSize>& 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)
{
Expand Down
12 changes: 12 additions & 0 deletions src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,18 @@ class TypeObjectRegistry : public ITypeObjectRegistry
const TypeIdentifier& type_id,
std::unordered_set<TypeIdentfierWithSize>& 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<TypeIdentfierWithSize>& type_dependencies);

/**
* @brief Get the type dependencies of plain sequences or arrays.
*
Expand Down

0 comments on commit 45ea8b7

Please sign in to comment.