Skip to content

Commit

Permalink
Refs #19760. Coexist fastcdr v1 and v2 [new approach]
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>
  • Loading branch information
richiware committed Nov 22, 2023
1 parent ea299be commit e0647ee
Show file tree
Hide file tree
Showing 86 changed files with 8,294 additions and 1,516 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,26 @@ project(DdsRecorderCommand)
find_package(fastcdr REQUIRED)
find_package(fastrtps REQUIRED)


set(${PROJECT_NAME}_FILES
DdsRecorderCommand.cxx
DdsRecorderCommandPubSubTypes.cxx
)

include_directories()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

#Create library for C++ types
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_FILES})
add_library(${PROJECT_NAME} SHARED
DdsRecorderCommand.cxx
DdsRecorderCommandv1.cxx
DdsRecorderCommandPubSubTypes.cxx
)
if(WIN32)
target_compile_definitions(${PROJECT_NAME} PRIVATE EPROSIMA_USER_DLL_EXPORT)
endif(WIN32)
target_link_libraries(${PROJECT_NAME} PUBLIC fastcdr fastrtps)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_include_directories(${PROJECT_NAME} PUBLIC
${PROJECT_SOURCE_DIR}
)
target_link_libraries(${PROJECT_NAME}
PUBLIC
fastcdr
fastrtps
)

###############################################################################
# Python bindings for type
Expand Down Expand Up @@ -70,17 +74,14 @@ SET_SOURCE_FILES_PROPERTIES(
USE_TARGET_INCLUDE_DIRECTORIES TRUE
)

include_directories(
${PROJECT_SOURCE_DIR}
)

set_property(SOURCE ${PROJECT_NAME}.i PROPERTY OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/")

SWIG_ADD_LIBRARY(${${PROJECT_NAME}_MODULE}
TYPE SHARED
LANGUAGE python
SOURCES ${${PROJECT_NAME}_MODULE_FILES})

set_property(TARGET ${${PROJECT_NAME}_MODULE} PROPERTY CXX_STANDARD 11)
if(UNIX AND CMAKE_SIZEOF_VOID_P EQUAL 8)
set_property(TARGET ${${PROJECT_NAME}_MODULE} PROPERTY SWIG_COMPILE_DEFINITIONS SWIGWORDSIZE64)
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,22 @@ char dummy;
#endif // _WIN32

#include "DdsRecorderCommand.h"
#include <fastdds/rtps/common/CdrSerialization.hpp>

#include <utility>
#if FASTCDR_VERSION_MAJOR > 1

// Include auxiliary functions like for serializing/deserializing.
#include "DdsRecorderCommandCdrAux.ipp"
#include <fastcdr/Cdr.h>


#include <fastcdr/exceptions/BadParamException.h>
using namespace eprosima::fastcdr::exception;

#include <utility>




DdsRecorderCommand::DdsRecorderCommand()
{

}

DdsRecorderCommand::~DdsRecorderCommand()
Expand Down Expand Up @@ -91,19 +94,6 @@ bool DdsRecorderCommand::operator !=(
return !(*this == x);
}

void DdsRecorderCommand::serialize(
eprosima::fastcdr::Cdr& scdr) const
{
eprosima::fastcdr::serialize(scdr, *this);
}

void DdsRecorderCommand::deserialize(
eprosima::fastcdr::Cdr& dcdr)
{
eprosima::fastcdr::deserialize(dcdr, *this);
}


/*!
* @brief This function copies the value in member command
* @param _command New value to be copied in member command
Expand Down Expand Up @@ -181,3 +171,8 @@ std::string& DdsRecorderCommand::args()
return m_args;
}


// Include auxiliary functions like for serializing/deserializing.
#include "DdsRecorderCommandCdrAux.ipp"

#endif // FASTCDR_VERSION_MAJOR > 1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
* This file was generated by the tool fastddsgen.
*/

#include <fastcdr/config.h>
#include "DdsRecorderCommandv1.h"

#if FASTCDR_VERSION_MAJOR > 1

#ifndef _FAST_DDS_GENERATED_DDSRECORDERCOMMAND_H_
#define _FAST_DDS_GENERATED_DDSRECORDERCOMMAND_H_

Expand All @@ -29,13 +34,9 @@
#include <string>
#include <vector>

#include <fastcdr/config.h>
#if FASTCDR_VERSION_MAJOR == 1
#include <fastdds/rtps/common/CdrSerialization.hpp>
#else
#include <fastcdr/cdr/fixed_size_string.hpp>
#include <fastcdr/xcdr/external.hpp>
#include <fastcdr/xcdr/optional.hpp>
#endif // FASTCDR_VERSION_MAJOR == 1



Expand Down Expand Up @@ -72,6 +73,8 @@ class CdrSizeCalculator;





/*!
* @brief This class represents the structure DdsRecorderCommand defined by the user in the IDL file.
* @ingroup DdsRecorderCommand
Expand Down Expand Up @@ -185,23 +188,6 @@ class DdsRecorderCommand
*/
eProsima_user_DllExport std::string& args();


/*!
* @brief This function serializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void serialize(
eprosima::fastcdr::Cdr& cdr) const;

/*!
* @brief This function deserializes an object using CDR serialization.
* @param cdr CDR serialization object.
*/
eProsima_user_DllExport void deserialize(
eprosima::fastcdr::Cdr& cdr);



private:

std::string m_command;
Expand All @@ -211,3 +197,6 @@ class DdsRecorderCommand

#endif // _FAST_DDS_GENERATED_DDSRECORDERCOMMAND_H_



#endif // FASTCDR_VERSION_MAJOR > 1
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,28 @@
#include <fastdds/dds/core/LoanableSequence.hpp>
%}

%include <fastcdr/config.h>
#if FASTCDR_VERSION_MAJOR > 1
%import(module="fastdds") "fastcdr/xcdr/optional.hpp"
#endif
%import(module="fastdds") "fastdds/dds/core/LoanableCollection.hpp"
%import(module="fastdds") "fastdds/dds/core/LoanableTypedCollection.hpp"
%import(module="fastdds") "fastdds/dds/core/LoanableSequence.hpp"

%define %traits_penumn(Type...)
%fragment(SWIG_Traits_frag(Type),"header",
fragment="StdTraits") {
namespace swig {
template <> struct traits< Type > {
typedef value_category category;
static const char* type_name() { return #Type; }
};
}
}
%enddef



////////////////////////////////////////////////////////
// Binding for class DdsRecorderCommand
////////////////////////////////////////////////////////
Expand All @@ -68,6 +86,7 @@
%rename("%s") DdsRecorderCommand::command() const;



%ignore DdsRecorderCommand::args(std::string&&);

// Overloaded getter methods shadow each other and are equivalent in python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace fastcdr {
class Cdr;
class CdrSizeCalculator;



eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const DdsRecorderCommand& data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
#include "DdsRecorderCommandCdrAux.hpp"

#include <fastcdr/Cdr.h>
#if FASTCDR_VERSION_MAJOR > 1
#include <fastcdr/CdrSizeCalculator.hpp>
#endif // FASTCDR_VERSION_MAJOR > 1



#include <fastcdr/exceptions/BadParamException.h>
Expand All @@ -37,6 +34,8 @@ using namespace eprosima::fastcdr::exception;
namespace eprosima {
namespace fastcdr {



template<>
eProsima_user_DllExport size_t calculate_serialized_size(
eprosima::fastcdr::CdrSizeCalculator& calculator,
Expand All @@ -45,24 +44,6 @@ eProsima_user_DllExport size_t calculate_serialized_size(
{
static_cast<void>(data);

#if FASTCDR_VERSION_MAJOR == 1

static_cast<void>(calculator);
static_cast<void>(current_alignment);

size_t initial_alignment {current_alignment};

current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.command().size() + 1;


current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.args().size() + 1;



return current_alignment - initial_alignment;

#else

eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding();
size_t calculated_size {calculator.begin_calculate_type_serialized_size(
eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ?
Expand All @@ -81,54 +62,31 @@ eProsima_user_DllExport size_t calculate_serialized_size(
calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment);

return calculated_size;

#endif // FASTCDR_VERSION_MAJOR == 1
}

template<>
eProsima_user_DllExport void serialize(
eprosima::fastcdr::Cdr& scdr,
const DdsRecorderCommand& data)
{
#if FASTCDR_VERSION_MAJOR > 1
eprosima::fastcdr::Cdr::state current_state(scdr);
scdr.begin_serialize_type(current_state,
eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);
#endif // FASTCDR_VERSION_MAJOR > 1

#if FASTCDR_VERSION_MAJOR == 1
scdr << data.command()
;


scdr << data.args()
;


#else
scdr
<< eprosima::fastcdr::MemberId(0) << data.command()
<< eprosima::fastcdr::MemberId(1) << data.args()
;
#endif // FASTCDR_VERSION_MAJOR == 1

#if FASTCDR_VERSION_MAJOR > 1
scdr.end_serialize_type(current_state);
#endif // FASTCDR_VERSION_MAJOR > 1
}

template<>
eProsima_user_DllExport void deserialize(
eprosima::fastcdr::Cdr& cdr,
DdsRecorderCommand& data)
{
#if FASTCDR_VERSION_MAJOR == 1
cdr >> data.command();
cdr >> data.args();
;
#else
cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
Expand All @@ -151,7 +109,6 @@ eProsima_user_DllExport void deserialize(
}
return ret_value;
});
#endif // FASTCDR_VERSION_MAJOR == 1
}

void serialize_key(
Expand Down
Loading

0 comments on commit e0647ee

Please sign in to comment.