Skip to content

Commit

Permalink
Review - Apply suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: tempate <danieldiaz@eprosima.com>
  • Loading branch information
Tempate committed Jul 11, 2024
1 parent 802a6d9 commit 890c285
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 60 deletions.
2 changes: 1 addition & 1 deletion include/fastdds/dds/xtypes/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum class DynamicDataJsonFormat
* @brief Serializes a @ref DynamicType into its IDL representation.
*
* @param [in] dynamic_type The @ref DynamicType to serialize.
* @param [in,out] output The IDL representation.
* @param [in,out] output \c std::ostream reference containing the IDL representation.
* @retval RETCODE_OK when serialization fully succeeds, and inner (member serialization) failing code otherwise.
*/
FASTDDS_EXPORTED_API ReturnCode_t idl_serialize(
Expand Down
10 changes: 5 additions & 5 deletions src/cpp/fastdds/xtypes/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ ReturnCode_t idl_serialize(
ReturnCode_t ret = RETCODE_OK;

// Create a tree representation of the dynamic type
utilities::collections::TreeNode<TreeNodeType> parent_type;
ret = dyn_type_to_tree(dynamic_type, "PARENT", parent_type);
utilities::collections::TreeNode<TreeNodeType> root;
ret = dyn_type_to_tree(dynamic_type, "ROOT", root);

if (ret != RETCODE_OK)
{
EPROSIMA_LOG_WARNING(XTYPES_UTILS,
EPROSIMA_LOG_ERROR(XTYPES_UTILS,
"Failed to convert DynamicType to tree.");
return ret;
}

// Serialize the tree to IDL
ret = dyn_type_tree_to_idl(parent_type, output);
ret = dyn_type_tree_to_idl(root, output);

if (ret != RETCODE_OK)
{
EPROSIMA_LOG_WARNING(XTYPES_UTILS,
EPROSIMA_LOG_ERROR(XTYPES_UTILS,
"Failed to convert DynamicType tree to IDL.");
return ret;
}
Expand Down
70 changes: 18 additions & 52 deletions test/unittest/dds/xtypes/serializers/idl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/types/alias_struct/alias_struct.idl
${CMAKE_CURRENT_BINARY_DIR}/types/alias_struct/alias_struct.idl
COPYONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/types/array_struct/array_struct.idl
${CMAKE_CURRENT_BINARY_DIR}/types/array_struct/array_struct.idl
COPYONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/types/bitmask_struct/bitmask_struct.idl
${CMAKE_CURRENT_BINARY_DIR}/types/bitmask_struct/bitmask_struct.idl
COPYONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/types/bitset_struct/bitset_struct.idl
${CMAKE_CURRENT_BINARY_DIR}/types/bitset_struct/bitset_struct.idl
COPYONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/types/enum_struct/enum_struct.idl
${CMAKE_CURRENT_BINARY_DIR}/types/enum_struct/enum_struct.idl
COPYONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/types/extensibility_struct/extensibility_struct.idl
${CMAKE_CURRENT_BINARY_DIR}/types/extensibility_struct/extensibility_struct.idl
COPYONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/types/key_struct/key_struct.idl
${CMAKE_CURRENT_BINARY_DIR}/types/key_struct/key_struct.idl
COPYONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/types/map_struct/map_struct.idl
${CMAKE_CURRENT_BINARY_DIR}/types/map_struct/map_struct.idl
COPYONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/types/primitives_struct/primitives_struct.idl
${CMAKE_CURRENT_BINARY_DIR}/types/primitives_struct/primitives_struct.idl
COPYONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/types/sequence_struct/sequence_struct.idl
${CMAKE_CURRENT_BINARY_DIR}/types/sequence_struct/sequence_struct.idl
COPYONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/types/string_struct/string_struct.idl
${CMAKE_CURRENT_BINARY_DIR}/types/string_struct/string_struct.idl
COPYONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/types/struct_struct/struct_struct.idl
${CMAKE_CURRENT_BINARY_DIR}/types/struct_struct/struct_struct.idl
COPYONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/types/union_struct/union_struct.idl
${CMAKE_CURRENT_BINARY_DIR}/types/union_struct/union_struct.idl
COPYONLY)
# Recursively find all .idl files in the types directory
file(GLOB_RECURSE IDL_FILES ${CMAKE_CURRENT_SOURCE_DIR}/types/*.idl)

# Iterate over each .idl file found
foreach(IDL_FILE ${IDL_FILES})
# Get the relative path of the .idl file
file(RELATIVE_PATH RELATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${IDL_FILE})

# Determine the destination directory
set(DEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/${RELATIVE_PATH})
get_filename_component(DEST_DIR ${DEST_DIR} DIRECTORY)

# Ensure the destination directory exists
file(MAKE_DIRECTORY ${DEST_DIR})

# Copy the .idl file to the destination directory
configure_file(${IDL_FILE} ${DEST_DIR} COPYONLY)
endforeach()

set(RESOURCEDYNTYPETOIDLTESTS_SOURCE
DynTypeIDLTests.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ typedef short MyShort;

typedef MyShort MyRecursiveShort;

typedef boolean MyBoolean;

typedef MyBoolean MyRecursiveBoolean;

struct AliasStruct
{
MyLong my_long;
MyRecursiveShort my_recursive_short;
MyRecursiveBoolean my_recursive_boolean;
MyBoolean my_boolean;
};
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ typedef int16_t MyShort;

typedef MyShort MyRecursiveShort;

typedef bool MyBoolean;

typedef MyBoolean MyRecursiveBoolean;

/*!
* @brief This class represents the structure AliasStruct defined by the user in the IDL file.
* @ingroup alias_struct
Expand Down Expand Up @@ -88,6 +92,10 @@ class AliasStruct

m_my_recursive_short = x.m_my_recursive_short;

m_my_recursive_boolean = x.m_my_recursive_boolean;

m_my_boolean = x.m_my_boolean;

}

/*!
Expand All @@ -99,6 +107,8 @@ class AliasStruct
{
m_my_long = x.m_my_long;
m_my_recursive_short = x.m_my_recursive_short;
m_my_recursive_boolean = x.m_my_recursive_boolean;
m_my_boolean = x.m_my_boolean;
}

/*!
Expand All @@ -113,6 +123,10 @@ class AliasStruct

m_my_recursive_short = x.m_my_recursive_short;

m_my_recursive_boolean = x.m_my_recursive_boolean;

m_my_boolean = x.m_my_boolean;

return *this;
}

Expand All @@ -126,6 +140,8 @@ class AliasStruct

m_my_long = x.m_my_long;
m_my_recursive_short = x.m_my_recursive_short;
m_my_recursive_boolean = x.m_my_recursive_boolean;
m_my_boolean = x.m_my_boolean;
return *this;
}

Expand All @@ -137,7 +153,9 @@ class AliasStruct
const AliasStruct& x) const
{
return (m_my_long == x.m_my_long &&
m_my_recursive_short == x.m_my_recursive_short);
m_my_recursive_short == x.m_my_recursive_short &&
m_my_recursive_boolean == x.m_my_recursive_boolean &&
m_my_boolean == x.m_my_boolean);
}

/*!
Expand Down Expand Up @@ -208,11 +226,71 @@ class AliasStruct
}


/*!
* @brief This function sets a value in member my_recursive_boolean
* @param _my_recursive_boolean New value for member my_recursive_boolean
*/
eProsima_user_DllExport void my_recursive_boolean(
MyRecursiveBoolean _my_recursive_boolean)
{
m_my_recursive_boolean = _my_recursive_boolean;
}

/*!
* @brief This function returns the value of member my_recursive_boolean
* @return Value of member my_recursive_boolean
*/
eProsima_user_DllExport MyRecursiveBoolean my_recursive_boolean() const
{
return m_my_recursive_boolean;
}

/*!
* @brief This function returns a reference to member my_recursive_boolean
* @return Reference to member my_recursive_boolean
*/
eProsima_user_DllExport MyRecursiveBoolean& my_recursive_boolean()
{
return m_my_recursive_boolean;
}


/*!
* @brief This function sets a value in member my_boolean
* @param _my_boolean New value for member my_boolean
*/
eProsima_user_DllExport void my_boolean(
MyBoolean _my_boolean)
{
m_my_boolean = _my_boolean;
}

/*!
* @brief This function returns the value of member my_boolean
* @return Value of member my_boolean
*/
eProsima_user_DllExport MyBoolean my_boolean() const
{
return m_my_boolean;
}

/*!
* @brief This function returns a reference to member my_boolean
* @return Reference to member my_boolean
*/
eProsima_user_DllExport MyBoolean& my_boolean()
{
return m_my_boolean;
}



private:

MyLong m_my_long{0};
MyRecursiveShort m_my_recursive_short{0};
MyRecursiveBoolean m_my_recursive_boolean{false};
MyBoolean m_my_boolean{false};

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@

#include "alias_struct.hpp"

constexpr uint32_t AliasStruct_max_cdr_typesize {10UL};
constexpr uint32_t AliasStruct_max_cdr_typesize {12UL};
constexpr uint32_t AliasStruct_max_key_cdr_typesize {0UL};







namespace eprosima {
namespace fastcdr {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ eProsima_user_DllExport size_t calculate_serialized_size(
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1),
data.my_recursive_short(), current_alignment);

calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2),
data.my_recursive_boolean(), current_alignment);

calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(3),
data.my_boolean(), current_alignment);


calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment);

Expand All @@ -76,6 +82,8 @@ eProsima_user_DllExport void serialize(
scdr
<< eprosima::fastcdr::MemberId(0) << data.my_long()
<< eprosima::fastcdr::MemberId(1) << data.my_recursive_short()
<< eprosima::fastcdr::MemberId(2) << data.my_recursive_boolean()
<< eprosima::fastcdr::MemberId(3) << data.my_boolean()
;
scdr.end_serialize_type(current_state);
}
Expand All @@ -101,6 +109,14 @@ eProsima_user_DllExport void deserialize(
dcdr >> data.my_recursive_short();
break;

case 2:
dcdr >> data.my_recursive_boolean();
break;

case 3:
dcdr >> data.my_boolean();
break;

default:
ret_value = false;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
typedef uint32_t MyLong;
typedef int16_t MyShort;
typedef MyShort MyRecursiveShort;
typedef bool MyBoolean;
typedef MyBoolean MyRecursiveBoolean;

/*!
* @brief This class represents the TopicDataType of the type AliasStruct defined by the user in the IDL file.
Expand Down
Loading

0 comments on commit 890c285

Please sign in to comment.