Skip to content

Commit

Permalink
TypeObjectRegistry refactor (#792)
Browse files Browse the repository at this point in the history
* Refs #21044. Regenerate idl files

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #21044. Fix spelling

Signed-off-by: Ricardo González Moreno <[email protected]>

---------

Signed-off-by: Ricardo González Moreno <[email protected]>
  • Loading branch information
richiware authored Jun 14, 2024
1 parent 71c7c6e commit 4e4d3ca
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 137 deletions.
4 changes: 2 additions & 2 deletions code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ bool HelloWorldPubSubType::getKey(
return true;
}

void HelloWorldPubSubType::register_type_object_representation() const
void HelloWorldPubSubType::register_type_object_representation()
{
register_HelloWorld_type_objects();
register_HelloWorld_type_identifier(type_identifiers_);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class HelloWorldPubSubType : public eprosima::fastdds::dds::TopicDataType
void* data) override;

//Register TypeObject representation in Fast DDS TypeObjectRegistry
eProsima_user_DllExport void register_type_object_representation() const override;
eProsima_user_DllExport void register_type_object_representation() override;

#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
eProsima_user_DllExport inline bool is_bounded() const override
Expand Down
158 changes: 30 additions & 128 deletions code/Examples/C++/DDSHelloWorld/src/HelloWorldTypeObjectSupport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,19 @@

using namespace eprosima::fastdds::dds::xtypes;

void register_HelloWorld_type_objects()
{
static std::once_flag once_flag;
std::call_once(once_flag, []()
{
TypeIdentifier type_id;
register_HelloWorld_type_identifier(type_id);

});
}

// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_HelloWorld_type_identifier(
TypeIdentifier& type_id)
TypeIdentifierPair& type_ids_HelloWorld)
{

ReturnCode_t return_code_HelloWorld {eprosima::fastdds::dds::RETCODE_OK};
return_code_HelloWorld =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"HelloWorld", type_ids_HelloWorld);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_HelloWorld)
{
StructTypeFlag struct_flags_HelloWorld = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED,
StructTypeFlag struct_flags_HelloWorld = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
false, false);
ReturnCode_t return_code_HelloWorld;
TypeIdentifierPair type_ids_HelloWorld;
QualifiedTypeName type_name_HelloWorld = "HelloWorld";
eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_HelloWorld;
eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_HelloWorld;
Expand All @@ -66,62 +59,26 @@ void register_HelloWorld_type_identifier(
header_HelloWorld = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_HelloWorld);
CompleteStructMemberSeq member_seq_HelloWorld;
{
return_code_HelloWorld =
TypeIdentifierPair type_ids_index;
ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK};
return_code_index =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"_uint32_t", type_ids_HelloWorld);
"_uint32_t", type_ids_index);

if (return_code_HelloWorld != eprosima::fastdds::dds::RETCODE_OK)
if (eprosima::fastdds::dds::RETCODE_OK != return_code_index)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"index Structure member TypeIdentifier unknown to TypeObjectRegistry.");
type_id = TypeIdentifier();
return;
}
StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED,
StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
CommonStructMember common_index;
MemberId member_id_index = 0x00000000;
if (EK_COMPLETE == type_ids_HelloWorld.type_identifier1()._d() || TK_NONE == type_ids_HelloWorld.type_identifier2()._d() ||
(TI_PLAIN_SEQUENCE_SMALL == type_ids_HelloWorld.type_identifier1()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier1().seq_sdefn().header().equiv_kind()) ||
(TI_PLAIN_SEQUENCE_LARGE == type_ids_HelloWorld.type_identifier1()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier1().seq_ldefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_SMALL == type_ids_HelloWorld.type_identifier1()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier1().array_sdefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_LARGE == type_ids_HelloWorld.type_identifier1()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier1().array_ldefn().header().equiv_kind()) ||
(TI_PLAIN_MAP_SMALL == type_ids_HelloWorld.type_identifier1()._d() &&
(EK_COMPLETE == type_ids_HelloWorld.type_identifier1().map_sdefn().header().equiv_kind() ||
EK_COMPLETE == type_ids_HelloWorld.type_identifier1().map_sdefn().key_identifier()->_d())) ||
(TI_PLAIN_MAP_LARGE == type_ids_HelloWorld.type_identifier1()._d() &&
(EK_COMPLETE == type_ids_HelloWorld.type_identifier1().map_ldefn().header().equiv_kind() ||
EK_COMPLETE == type_ids_HelloWorld.type_identifier1().map_ldefn().key_identifier()->_d())))
bool common_index_ec {false};
CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))};
if (!common_index_ec)
{
common_index = TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, type_ids_HelloWorld.type_identifier1());
}
else if (EK_COMPLETE == type_ids_HelloWorld.type_identifier2()._d() ||
(TI_PLAIN_SEQUENCE_SMALL == type_ids_HelloWorld.type_identifier2()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier2().seq_sdefn().header().equiv_kind()) ||
(TI_PLAIN_SEQUENCE_LARGE == type_ids_HelloWorld.type_identifier2()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier2().seq_ldefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_SMALL == type_ids_HelloWorld.type_identifier2()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier2().array_sdefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_LARGE == type_ids_HelloWorld.type_identifier2()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier2().array_ldefn().header().equiv_kind()) ||
(TI_PLAIN_MAP_SMALL == type_ids_HelloWorld.type_identifier2()._d() &&
(EK_COMPLETE == type_ids_HelloWorld.type_identifier2().map_sdefn().header().equiv_kind() ||
EK_COMPLETE == type_ids_HelloWorld.type_identifier2().map_sdefn().key_identifier()->_d())) ||
(TI_PLAIN_MAP_LARGE == type_ids_HelloWorld.type_identifier2()._d() &&
(EK_COMPLETE == type_ids_HelloWorld.type_identifier2().map_ldefn().header().equiv_kind() ||
EK_COMPLETE == type_ids_HelloWorld.type_identifier2().map_ldefn().key_identifier()->_d())))
{
common_index = TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, type_ids_HelloWorld.type_identifier2());
}
else
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"Structure index member TypeIdentifier inconsistent.");
type_id = TypeIdentifier();
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent.");
return;
}
MemberName name_index = "index";
Expand All @@ -132,79 +89,34 @@ void register_HelloWorld_type_identifier(
TypeObjectUtils::add_complete_struct_member(member_seq_HelloWorld, member_index);
}
{
return_code_HelloWorld =
TypeIdentifierPair type_ids_message;
ReturnCode_t return_code_message {eprosima::fastdds::dds::RETCODE_OK};
return_code_message =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_string_unbounded", type_ids_HelloWorld);
"anonymous_string_unbounded", type_ids_message);

if (return_code_HelloWorld != eprosima::fastdds::dds::RETCODE_OK)
if (eprosima::fastdds::dds::RETCODE_OK != return_code_message)
{
{
SBound bound = 0;
StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
"anonymous_string_unbounded"))
"anonymous_string_unbounded", type_ids_message))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
return_code_HelloWorld =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_string_unbounded", type_ids_HelloWorld);
if (return_code_HelloWorld != eprosima::fastdds::dds::RETCODE_OK)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded: Given String TypeIdentifier unknown to TypeObjectRegistry.");
type_id = TypeIdentifier();
return;
}
}
StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED,
StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
CommonStructMember common_message;
MemberId member_id_message = 0x00000001;
if (EK_COMPLETE == type_ids_HelloWorld.type_identifier1()._d() || TK_NONE == type_ids_HelloWorld.type_identifier2()._d() ||
(TI_PLAIN_SEQUENCE_SMALL == type_ids_HelloWorld.type_identifier1()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier1().seq_sdefn().header().equiv_kind()) ||
(TI_PLAIN_SEQUENCE_LARGE == type_ids_HelloWorld.type_identifier1()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier1().seq_ldefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_SMALL == type_ids_HelloWorld.type_identifier1()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier1().array_sdefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_LARGE == type_ids_HelloWorld.type_identifier1()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier1().array_ldefn().header().equiv_kind()) ||
(TI_PLAIN_MAP_SMALL == type_ids_HelloWorld.type_identifier1()._d() &&
(EK_COMPLETE == type_ids_HelloWorld.type_identifier1().map_sdefn().header().equiv_kind() ||
EK_COMPLETE == type_ids_HelloWorld.type_identifier1().map_sdefn().key_identifier()->_d())) ||
(TI_PLAIN_MAP_LARGE == type_ids_HelloWorld.type_identifier1()._d() &&
(EK_COMPLETE == type_ids_HelloWorld.type_identifier1().map_ldefn().header().equiv_kind() ||
EK_COMPLETE == type_ids_HelloWorld.type_identifier1().map_ldefn().key_identifier()->_d())))
{
common_message = TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, type_ids_HelloWorld.type_identifier1());
}
else if (EK_COMPLETE == type_ids_HelloWorld.type_identifier2()._d() ||
(TI_PLAIN_SEQUENCE_SMALL == type_ids_HelloWorld.type_identifier2()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier2().seq_sdefn().header().equiv_kind()) ||
(TI_PLAIN_SEQUENCE_LARGE == type_ids_HelloWorld.type_identifier2()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier2().seq_ldefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_SMALL == type_ids_HelloWorld.type_identifier2()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier2().array_sdefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_LARGE == type_ids_HelloWorld.type_identifier2()._d() &&
EK_COMPLETE == type_ids_HelloWorld.type_identifier2().array_ldefn().header().equiv_kind()) ||
(TI_PLAIN_MAP_SMALL == type_ids_HelloWorld.type_identifier2()._d() &&
(EK_COMPLETE == type_ids_HelloWorld.type_identifier2().map_sdefn().header().equiv_kind() ||
EK_COMPLETE == type_ids_HelloWorld.type_identifier2().map_sdefn().key_identifier()->_d())) ||
(TI_PLAIN_MAP_LARGE == type_ids_HelloWorld.type_identifier2()._d() &&
(EK_COMPLETE == type_ids_HelloWorld.type_identifier2().map_ldefn().header().equiv_kind() ||
EK_COMPLETE == type_ids_HelloWorld.type_identifier2().map_ldefn().key_identifier()->_d())))
{
common_message = TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, type_ids_HelloWorld.type_identifier2());
}
else
bool common_message_ec {false};
CommonStructMember common_message {TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, common_message_ec))};
if (!common_message_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"Structure message member TypeIdentifier inconsistent.");
type_id = TypeIdentifier();
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure message member TypeIdentifier inconsistent.");
return;
}
MemberName name_message = "message";
Expand All @@ -216,21 +128,11 @@ void register_HelloWorld_type_identifier(
}
CompleteStructType struct_type_HelloWorld = TypeObjectUtils::build_complete_struct_type(struct_flags_HelloWorld, header_HelloWorld, member_seq_HelloWorld);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_struct_type_object(struct_type_HelloWorld, type_name_HelloWorld.to_string(), type_id))
TypeObjectUtils::build_and_register_struct_type_object(struct_type_HelloWorld, type_name_HelloWorld.to_string(), type_ids_HelloWorld))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"HelloWorld already registered in TypeObjectRegistry for a different type.");
}
return_code_HelloWorld =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"HelloWorld", type_ids_HelloWorld);
if (return_code_HelloWorld != eprosima::fastdds::dds::RETCODE_OK)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"HelloWorld: Given Struct TypeIdentifier unknown to TypeObjectRegistry.");
type_id = TypeIdentifier();
return;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@
#define eProsima_user_DllExport
#endif // _WIN32

/**
* @brief Register every TypeObject representation defined in the IDL file in Fast DDS TypeObjectRegistry.
*/
eProsima_user_DllExport void register_HelloWorld_type_objects();

#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

/**
Expand All @@ -53,7 +48,7 @@ eProsima_user_DllExport void register_HelloWorld_type_objects();
* Invalid TypeIdentifier is returned in case of error.
*/
eProsima_user_DllExport void register_HelloWorld_type_identifier(
eprosima::fastdds::dds::xtypes::TypeIdentifier& type_id);
eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids);


#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
Expand Down
1 change: 1 addition & 0 deletions docs/fastdds/api_reference/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ typedef
typeid
TypeIdentfierWithSizePubSubType
TypeIdentifier
TypeIdentifierPair
TypeIdentifierPairPubSubType
TypeIdentifierTypeObjectPairPubSubType
TypeIdentifierWithDependenciesPubSubType
Expand Down

0 comments on commit 4e4d3ca

Please sign in to comment.