Skip to content

Commit

Permalink
Add support for FastDDS versions earlier than 2.13 (#67)
Browse files Browse the repository at this point in the history
Signed-off-by: Irene Bandera <[email protected]>
  • Loading branch information
irenebm authored Jan 25, 2024
1 parent 3b76649 commit 4f2af4f
Show file tree
Hide file tree
Showing 17 changed files with 815 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
#include <fastdds/dds/publisher/DataWriterListener.hpp>
#include <fastdds/dds/topic/TypeSupport.hpp>

#include "HelloWorldPubSubTypes.h"
#if FASTRTPS_VERSION_MAJOR <= 2 && FASTRTPS_VERSION_MINOR < 13
#include "types/v1/HelloWorldPubSubTypes.h"
#else
#include "types/v2/HelloWorldPubSubTypes.h"
#endif // if FASTRTPS_VERSION_MAJOR <= 2 && FASTRTPS_VERSION_MINOR < 13

#include "types.hpp"

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/subscriber/DataReaderListener.hpp>

#include "HelloWorldPubSubTypes.h"
#if FASTRTPS_VERSION_MAJOR <= 2 && FASTRTPS_VERSION_MINOR < 13
#include "types/v1/HelloWorldPubSubTypes.h"
#else
#include "types/v2/HelloWorldPubSubTypes.h"
#endif // if FASTRTPS_VERSION_MAJOR <= 2 && FASTRTPS_VERSION_MINOR < 13

#include "types.hpp"

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ project(AdvancedConfigurationExample VERSION 1 LANGUAGES CXX)

# Find requirements
if(NOT fastcdr_FOUND)
find_package(fastcdr 2 REQUIRED)
find_package(fastcdr REQUIRED)
endif()

if(NOT fastrtps_FOUND)
find_package(fastrtps 2.12 REQUIRED)
find_package(fastrtps REQUIRED)
endif()

#Check C++11
Expand All @@ -35,9 +35,24 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
endif()
endif()

# Determine Fast DDS version
if ("${fastrtps_VERSION}" VERSION_LESS 2.13)
set(DDS_TYPES_VERSION "v1")
else()
set(DDS_TYPES_VERSION "v2")
endif()

message(STATUS "Configuring AdvancedConfiguration example...")
file(GLOB ADVANCED_CONFIG_EXAMPLE_SOURCES_CXX "*.cxx")
file(GLOB ADVANCED_CONFIG_EXAMPLE_SOURCES_CPP "*.cpp")
file(
GLOB ADVANCED_CONFIG_EXAMPLE_SOURCES_CXX
"*.cxx"
"types/${DDS_TYPES_VERSION}/*.cxx"
)
file(
GLOB ADVANCED_CONFIG_EXAMPLE_SOURCES_CPP
"*.cpp"
"types/${DDS_TYPES_VERSION}/*.cpp"
)

add_executable(${PROJECT_NAME} ${ADVANCED_CONFIG_EXAMPLE_SOURCES_CXX} ${ADVANCED_CONFIG_EXAMPLE_SOURCES_CPP})
target_compile_definitions(${PROJECT_NAME} PRIVATE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
* @file HelloWorld.cpp
* This source file contains the definition of the described types in the IDL file.
*
* This file was generated by the tool gen.
*/

#ifdef _WIN32
// Remove linker warning LNK4221 on Visual Studio
namespace {
char dummy;
} // namespace
#endif // _WIN32

#include "HelloWorld.h"
#include <fastcdr/Cdr.h>

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

#include <utility>

#define HelloWorld_max_cdr_typesize 24ULL;
#define HelloWorld_max_key_cdr_typesize 0ULL;

HelloWorld::HelloWorld()
{
// unsigned long m_index
m_index = 0;
// char m_message
memset(&m_message, 0, (20) * 1);

}

HelloWorld::~HelloWorld()
{


}

HelloWorld::HelloWorld(
const HelloWorld& x)
{
m_index = x.m_index;
m_message = x.m_message;
}

HelloWorld::HelloWorld(
HelloWorld&& x) noexcept
{
m_index = x.m_index;
m_message = std::move(x.m_message);
}

HelloWorld& HelloWorld::operator =(
const HelloWorld& x)
{

m_index = x.m_index;
m_message = x.m_message;

return *this;
}

HelloWorld& HelloWorld::operator =(
HelloWorld&& x) noexcept
{

m_index = x.m_index;
m_message = std::move(x.m_message);

return *this;
}

bool HelloWorld::operator ==(
const HelloWorld& x) const
{

return (m_index == x.m_index && m_message == x.m_message);
}

bool HelloWorld::operator !=(
const HelloWorld& x) const
{
return !(*this == x);
}

size_t HelloWorld::getMaxCdrSerializedSize(
size_t current_alignment)
{
static_cast<void>(current_alignment);
return HelloWorld_max_cdr_typesize;
}

size_t HelloWorld::getCdrSerializedSize(
const HelloWorld& data,
size_t current_alignment)
{
(void)data;
size_t initial_alignment = current_alignment;


current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);


current_alignment += ((20) * 1) + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);


return current_alignment - initial_alignment;
}

void HelloWorld::serialize(
eprosima::fastcdr::Cdr& scdr) const
{

scdr << m_index;
scdr << m_message;


}

void HelloWorld::deserialize(
eprosima::fastcdr::Cdr& dcdr)
{

dcdr >> m_index;
dcdr >> m_message;

}

/*!
* @brief This function sets a value in member index
* @param _index New value for member index
*/
void HelloWorld::index(
uint32_t _index)
{
m_index = _index;
}

/*!
* @brief This function returns the value of member index
* @return Value of member index
*/
uint32_t HelloWorld::index() const
{
return m_index;
}

/*!
* @brief This function returns a reference to member index
* @return Reference to member index
*/
uint32_t& HelloWorld::index()
{
return m_index;
}

/*!
* @brief This function copies the value in member message
* @param _message New value to be copied in member message
*/
void HelloWorld::message(
const std::array<char, 20>& _message)
{
m_message = _message;
}

/*!
* @brief This function moves the value in member message
* @param _message New value to be moved in member message
*/
void HelloWorld::message(
std::array<char, 20>&& _message)
{
m_message = std::move(_message);
}

/*!
* @brief This function returns a constant reference to member message
* @return Constant reference to member message
*/
const std::array<char, 20>& HelloWorld::message() const
{
return m_message;
}

/*!
* @brief This function returns a reference to member message
* @return Reference to member message
*/
std::array<char, 20>& HelloWorld::message()
{
return m_message;
}

size_t HelloWorld::getKeyMaxCdrSerializedSize(
size_t current_alignment)
{
static_cast<void>(current_alignment);
return HelloWorld_max_key_cdr_typesize;
}

bool HelloWorld::isKeyDefined()
{
return false;
}

void HelloWorld::serializeKey(
eprosima::fastcdr::Cdr& scdr) const
{
(void) scdr;
}
Loading

0 comments on commit 4f2af4f

Please sign in to comment.