From 4e4d3ca825eab676bca53f94c8f55c5de0172ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez?= Date: Fri, 14 Jun 2024 06:59:51 +0200 Subject: [PATCH] TypeObjectRegistry refactor (#792) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refs #21044. Regenerate idl files Signed-off-by: Ricardo González Moreno * Refs #21044. Fix spelling Signed-off-by: Ricardo González Moreno --------- Signed-off-by: Ricardo González Moreno --- .../src/HelloWorldPubSubTypes.cxx | 4 +- .../DDSHelloWorld/src/HelloWorldPubSubTypes.h | 2 +- .../src/HelloWorldTypeObjectSupport.cxx | 158 ++++-------------- .../src/HelloWorldTypeObjectSupport.hpp | 7 +- .../api_reference/spelling_wordlist.txt | 1 + 5 files changed, 35 insertions(+), 137 deletions(-) diff --git a/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.cxx b/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.cxx index db018e697..aa161b2e1 100644 --- a/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.cxx +++ b/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.cxx @@ -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_); } diff --git a/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.h b/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.h index a9b4ac119..7c83d2b30 100644 --- a/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.h +++ b/code/Examples/C++/DDSHelloWorld/src/HelloWorldPubSubTypes.h @@ -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 diff --git a/code/Examples/C++/DDSHelloWorld/src/HelloWorldTypeObjectSupport.cxx b/code/Examples/C++/DDSHelloWorld/src/HelloWorldTypeObjectSupport.cxx index fe783982b..58928b6f0 100644 --- a/code/Examples/C++/DDSHelloWorld/src/HelloWorldTypeObjectSupport.cxx +++ b/code/Examples/C++/DDSHelloWorld/src/HelloWorldTypeObjectSupport.cxx @@ -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 type_ann_builtin_HelloWorld; eprosima::fastcdr::optional ann_custom_HelloWorld; @@ -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"; @@ -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"; @@ -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; - } } } diff --git a/code/Examples/C++/DDSHelloWorld/src/HelloWorldTypeObjectSupport.hpp b/code/Examples/C++/DDSHelloWorld/src/HelloWorldTypeObjectSupport.hpp index 4d5de07cb..2eba797b0 100644 --- a/code/Examples/C++/DDSHelloWorld/src/HelloWorldTypeObjectSupport.hpp +++ b/code/Examples/C++/DDSHelloWorld/src/HelloWorldTypeObjectSupport.hpp @@ -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 /** @@ -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 diff --git a/docs/fastdds/api_reference/spelling_wordlist.txt b/docs/fastdds/api_reference/spelling_wordlist.txt index c536acb05..b05dd9c9e 100644 --- a/docs/fastdds/api_reference/spelling_wordlist.txt +++ b/docs/fastdds/api_reference/spelling_wordlist.txt @@ -276,6 +276,7 @@ typedef typeid TypeIdentfierWithSizePubSubType TypeIdentifier +TypeIdentifierPair TypeIdentifierPairPubSubType TypeIdentifierTypeObjectPairPubSubType TypeIdentifierWithDependenciesPubSubType