Skip to content

Commit

Permalink
Automatic TypeObject representation registration for DynamicTypes (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
richiware authored May 20, 2024
1 parent 9585e20 commit f220474
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 48 deletions.
38 changes: 15 additions & 23 deletions types/KeylessShapeTypeTypeObjectSupport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ void register_KeylessShapeType_type_objects()
static std::once_flag once_flag;
std::call_once(once_flag, []()
{
shapes_demo_typesupport::idl::register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier();
TypeIdentifier type_id;
shapes_demo_typesupport::idl::register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier(type_id);

});
}

namespace shapes_demo_typesupport {
namespace idl {
void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier()
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier(
TypeIdentifier& type_id)
{
{
StructTypeFlag struct_flags_KeylessShapeType = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED,
Expand All @@ -71,8 +74,6 @@ void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier()

if (return_code_KeylessShapeType != eprosima::fastdds::dds::RETCODE_OK)
{
std::string type_id_kind_anonymous_string_unbounded("TI_STRING8_SMALL");
if (type_id_kind_anonymous_string_unbounded == "TI_STRING8_SMALL")
{
SBound bound = 0;
StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
Expand All @@ -84,31 +85,14 @@ void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier()
"anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
else if (type_id_kind_anonymous_string_unbounded == "TI_STRING8_LARGE")
{
LBound bound = 255;
StringLTypeDefn string_ldefn = TypeObjectUtils::build_string_l_type_defn(bound);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_l_string_type_identifier(string_ldefn,
"anonymous_string_unbounded"))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
else
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded: Unknown String kind.");
return;
}
return_code_KeylessShapeType =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_string_unbounded", type_ids_KeylessShapeType);
if (return_code_KeylessShapeType != eprosima::fastdds::dds::RETCODE_OK)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded: Given String TypeIdentifier unknown to TypeObjectRegistry.");
type_id = TypeIdentifier();
return;
}
}
Expand Down Expand Up @@ -156,6 +140,7 @@ void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"Structure color member TypeIdentifier inconsistent.");
type_id = TypeIdentifier();
return;
}
MemberName name_color = "color";
Expand All @@ -174,6 +159,7 @@ void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"x Structure member TypeIdentifier unknown to TypeObjectRegistry.");
type_id = TypeIdentifier();
return;
}
StructMemberFlag member_flags_x = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED,
Expand Down Expand Up @@ -220,6 +206,7 @@ void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"Structure x member TypeIdentifier inconsistent.");
type_id = TypeIdentifier();
return;
}
MemberName name_x = "x";
Expand All @@ -238,6 +225,7 @@ void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"y Structure member TypeIdentifier unknown to TypeObjectRegistry.");
type_id = TypeIdentifier();
return;
}
StructMemberFlag member_flags_y = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED,
Expand Down Expand Up @@ -284,6 +272,7 @@ void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"Structure y member TypeIdentifier inconsistent.");
type_id = TypeIdentifier();
return;
}
MemberName name_y = "y";
Expand All @@ -302,6 +291,7 @@ void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"shapesize Structure member TypeIdentifier unknown to TypeObjectRegistry.");
type_id = TypeIdentifier();
return;
}
StructMemberFlag member_flags_shapesize = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED,
Expand Down Expand Up @@ -348,6 +338,7 @@ void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"Structure shapesize member TypeIdentifier inconsistent.");
type_id = TypeIdentifier();
return;
}
MemberName name_shapesize = "shapesize";
Expand All @@ -359,7 +350,7 @@ void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier()
}
CompleteStructType struct_type_KeylessShapeType = TypeObjectUtils::build_complete_struct_type(struct_flags_KeylessShapeType, header_KeylessShapeType, member_seq_KeylessShapeType);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_struct_type_object(struct_type_KeylessShapeType, type_name_KeylessShapeType.to_string()))
TypeObjectUtils::build_and_register_struct_type_object(struct_type_KeylessShapeType, type_name_KeylessShapeType.to_string(), type_id))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"shapes_demo_typesupport::idl::KeylessShapeType already registered in TypeObjectRegistry for a different type.");
Expand All @@ -371,6 +362,7 @@ void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"shapes_demo_typesupport::idl::KeylessShapeType: Given Struct TypeIdentifier unknown to TypeObjectRegistry.");
type_id = TypeIdentifier();
return;
}
}
Expand Down
9 changes: 8 additions & 1 deletion types/KeylessShapeTypeTypeObjectSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef _FAST_DDS_GENERATED_SHAPES_DEMO_TYPESUPPORT_IDL_KEYLESSSHAPETYPE_TYPE_OBJECT_SUPPORT_HPP_
#define _FAST_DDS_GENERATED_SHAPES_DEMO_TYPESUPPORT_IDL_KEYLESSSHAPETYPE_TYPE_OBJECT_SUPPORT_HPP_

#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>


#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
Expand All @@ -47,8 +49,13 @@ namespace idl {
* Fully-descriptive TypeIdentifiers are directly registered.
* Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is
* indirectly registered as well.
*
* @param[out] TypeIdentifier of the registered type.
* The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers.
* Invalid TypeIdentifier is returned in case of error.
*/
eProsima_user_DllExport void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier();
eProsima_user_DllExport void register_shapes_demo_typesupport_idl_KeylessShapeType_type_identifier(
eprosima::fastdds::dds::xtypes::TypeIdentifier& type_id);

} // namespace idl

Expand Down
38 changes: 15 additions & 23 deletions types/ShapeTypeObjectSupport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ void register_Shape_type_objects()
static std::once_flag once_flag;
std::call_once(once_flag, []()
{
register_ShapeType_type_identifier();
TypeIdentifier type_id;
register_ShapeType_type_identifier(type_id);

});
}

void register_ShapeType_type_identifier()
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_ShapeType_type_identifier(
TypeIdentifier& type_id)
{
{
StructTypeFlag struct_flags_ShapeType = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
Expand Down Expand Up @@ -76,8 +79,6 @@ void register_ShapeType_type_identifier()

if (return_code_ShapeType != eprosima::fastdds::dds::RETCODE_OK)
{
std::string type_id_kind_anonymous_string_unbounded("TI_STRING8_SMALL");
if (type_id_kind_anonymous_string_unbounded == "TI_STRING8_SMALL")
{
SBound bound = 0;
StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
Expand All @@ -89,31 +90,14 @@ void register_ShapeType_type_identifier()
"anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
else if (type_id_kind_anonymous_string_unbounded == "TI_STRING8_LARGE")
{
LBound bound = 255;
StringLTypeDefn string_ldefn = TypeObjectUtils::build_string_l_type_defn(bound);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_l_string_type_identifier(string_ldefn,
"anonymous_string_unbounded"))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
else
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded: Unknown String kind.");
return;
}
return_code_ShapeType =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_string_unbounded", type_ids_ShapeType);
if (return_code_ShapeType != eprosima::fastdds::dds::RETCODE_OK)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded: Given String TypeIdentifier unknown to TypeObjectRegistry.");
type_id = TypeIdentifier();
return;
}
}
Expand Down Expand Up @@ -161,6 +145,7 @@ void register_ShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"Structure color member TypeIdentifier inconsistent.");
type_id = TypeIdentifier();
return;
}
MemberName name_color = "color";
Expand Down Expand Up @@ -192,6 +177,7 @@ void register_ShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"x Structure member TypeIdentifier unknown to TypeObjectRegistry.");
type_id = TypeIdentifier();
return;
}
StructMemberFlag member_flags_x = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED,
Expand Down Expand Up @@ -238,6 +224,7 @@ void register_ShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"Structure x member TypeIdentifier inconsistent.");
type_id = TypeIdentifier();
return;
}
MemberName name_x = "x";
Expand All @@ -256,6 +243,7 @@ void register_ShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"y Structure member TypeIdentifier unknown to TypeObjectRegistry.");
type_id = TypeIdentifier();
return;
}
StructMemberFlag member_flags_y = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED,
Expand Down Expand Up @@ -302,6 +290,7 @@ void register_ShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"Structure y member TypeIdentifier inconsistent.");
type_id = TypeIdentifier();
return;
}
MemberName name_y = "y";
Expand All @@ -320,6 +309,7 @@ void register_ShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"shapesize Structure member TypeIdentifier unknown to TypeObjectRegistry.");
type_id = TypeIdentifier();
return;
}
StructMemberFlag member_flags_shapesize = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED,
Expand Down Expand Up @@ -366,6 +356,7 @@ void register_ShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"Structure shapesize member TypeIdentifier inconsistent.");
type_id = TypeIdentifier();
return;
}
MemberName name_shapesize = "shapesize";
Expand All @@ -377,7 +368,7 @@ void register_ShapeType_type_identifier()
}
CompleteStructType struct_type_ShapeType = TypeObjectUtils::build_complete_struct_type(struct_flags_ShapeType, header_ShapeType, member_seq_ShapeType);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_struct_type_object(struct_type_ShapeType, type_name_ShapeType.to_string()))
TypeObjectUtils::build_and_register_struct_type_object(struct_type_ShapeType, type_name_ShapeType.to_string(), type_id))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"ShapeType already registered in TypeObjectRegistry for a different type.");
Expand All @@ -389,6 +380,7 @@ void register_ShapeType_type_identifier()
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"ShapeType: Given Struct TypeIdentifier unknown to TypeObjectRegistry.");
type_id = TypeIdentifier();
return;
}
}
Expand Down
9 changes: 8 additions & 1 deletion types/ShapeTypeObjectSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef _FAST_DDS_GENERATED_SHAPE_TYPE_OBJECT_SUPPORT_HPP_
#define _FAST_DDS_GENERATED_SHAPE_TYPE_OBJECT_SUPPORT_HPP_

#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>


#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
Expand All @@ -45,8 +47,13 @@ eProsima_user_DllExport void register_Shape_type_objects();
* Fully-descriptive TypeIdentifiers are directly registered.
* Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is
* indirectly registered as well.
*
* @param[out] TypeIdentifier of the registered type.
* The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers.
* Invalid TypeIdentifier is returned in case of error.
*/
eProsima_user_DllExport void register_ShapeType_type_identifier();
eProsima_user_DllExport void register_ShapeType_type_identifier(
eprosima::fastdds::dds::xtypes::TypeIdentifier& type_id);


#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
Expand Down

0 comments on commit f220474

Please sign in to comment.