diff --git a/recipes/fast-dds/all/CMakeLists.txt b/recipes/fast-dds/all/CMakeLists.txt new file mode 100644 index 0000000000000..8b9014fcee176 --- /dev/null +++ b/recipes/fast-dds/all/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.1) +project(cmake_wrapper) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_subdirectory("source_subfolder") diff --git a/recipes/fast-dds/all/conandata.yml b/recipes/fast-dds/all/conandata.yml new file mode 100644 index 0000000000000..87b1380fe91ab --- /dev/null +++ b/recipes/fast-dds/all/conandata.yml @@ -0,0 +1,8 @@ +sources: + "2.3.2": + url: "https://github.com/eProsima/Fast-DDS/archive/refs/tags/v2.3.2.tar.gz" + sha256: "4D8183CF4D37C3DE9E6FD28D2850DD08023A9079001C4880B23C95F0D8C0B5CE" +patches: + "2.3.2": + - base_path: "source_subfolder" + patch_file: "patches/2.3.2-0001-fix-find-asio-and-tinyxml2.patch" diff --git a/recipes/fast-dds/all/conanfile.py b/recipes/fast-dds/all/conanfile.py new file mode 100644 index 0000000000000..8c3b540be9e20 --- /dev/null +++ b/recipes/fast-dds/all/conanfile.py @@ -0,0 +1,210 @@ +from conans import ConanFile, CMake, tools +import os +from conans.errors import ConanInvalidConfiguration +import textwrap + +class FastDDSConan(ConanFile): + + name = "fast-dds" + license = "Apache-2.0" + homepage = "https://fast-dds.docs.eprosima.com/" + url = "https://github.com/conan-io/conan-center-index" + description = "The most complete OSS DDS implementation for embedded systems." + topics = ("DDS", "Middleware", "IPC") + settings = "os", "compiler", "build_type", "arch" + options = { + "shared": [True, False], + "fPIC": [True, False], + "with_ssl": [True, False] + } + default_options = { + "shared": False, + "fPIC": True, + "with_ssl": False + } + generators = "cmake", "cmake_find_package" + _cmake = None + exports_sources = ["patches/**", "CMakeLists.txt"] + + @property + def _pkg_share(self): + return os.path.join( + self.package_folder, + "share" + ) + + @property + def _pkg_tools(self): + return os.path.join( + self.package_folder, + "tools" + ) + + @property + def _pkg_bin(self): + return os.path.join( + self.package_folder, + "bin" + ) + + @property + def _module_subfolder(self): + return os.path.join( + "lib", + "cmake" + ) + + @property + def _module_file_rel_path(self): + return os.path.join( + self._module_subfolder, + "conan-target-properties.cmake" + ) + + @property + def _minimum_cpp_standard(self): + return 11 + + @property + def _minimum_compilers_version(self): + return { + "Visual Studio": "16", + "gcc": "5", + "clang": "3.9", + "apple-clang": "8", + } + + @staticmethod + def _create_cmake_module_alias_targets(module_file, targets): + content = "" + for alias, aliased in targets.items(): + content += textwrap.dedent("""\ + if(TARGET {aliased} AND NOT TARGET {alias}) + add_library({alias} INTERFACE IMPORTED) + set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased}) + endif() + """.format(alias=alias, aliased=aliased)) + tools.save(module_file, content) + + @property + def _source_subfolder(self): + return "source_subfolder" + + def _patch_sources(self): + for patch in self.conan_data["patches"][self.version]: + tools.patch(**patch) + + def configure(self): + if self.options.shared: + del self.options.fPIC + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def _configure_cmake(self): + if not self._cmake: + self._cmake = CMake(self) + self._cmake.definitions["BUILD_MEMORY_TOOLS"] = False + self._cmake.definitions["NO_TLS"] = not self.options.with_ssl + self._cmake.definitions["SECURITY"] = self.options.with_ssl + self._cmake.definitions["EPROSIMA_INSTALLER_MINION"] = False + self._cmake.configure() + return self._cmake + + def requirements(self): + self.requires("tinyxml2/7.1.0") + self.requires("asio/1.18.2") + self.requires("fast-cdr/1.0.21") + self.requires("foonathan-memory/0.7.0") + self.requires("boost/1.73.0") + if self.options.with_ssl: + self.requires("openssl/1.1.1k") + + def source(self): + tools.get(**self.conan_data["sources"][self.version], strip_root=True, + destination=self._source_subfolder) + + def validate(self): + if self.settings.compiler.get_safe("cppstd"): + tools.check_min_cppstd(self, self._minimum_cpp_standard) + min_version = self._minimum_compilers_version.get(str(self.settings.compiler)) + if not min_version: + self.output.warn("{} recipe lacks information about the {} compiler support.".format( + self.name, self.settings.compiler)) + else: + if tools.Version(self.settings.compiler.version) < min_version: + raise ConanInvalidConfiguration("{} requires C++{} support. The current compiler {} {} does not support it.".format( + self.name, self._minimum_cpp_standard, self.settings.compiler, self.settings.compiler.version)) + if self.settings.os == "Windows": + if ("MT" in self.settings.compiler.runtime and self.options.shared): + # This combination leads to an fast-dds error when linking + # linking dynamic '*.dll' and static MT runtime + raise ConanInvalidConfiguration("Mixing a dll {} library with a static runtime is a bad idea".format(self.name)) + + + def build(self): + self._patch_sources() + cmake = self._configure_cmake() + cmake.build() + + def package(self): + cmake = self._configure_cmake() + cmake.install() + tools.rmdir(self._pkg_share) + self.copy("LICENSE", src=self._source_subfolder, dst="licenses") + tools.rename( + src=self._pkg_tools, + dst=os.path.join(self._pkg_bin, "tools") + ) + tools.remove_files_by_mask( + directory=os.path.join(self.package_folder, "lib"), + pattern="*.pdb" + ) + tools.remove_files_by_mask( + directory=os.path.join(self.package_folder, "bin"), + pattern="*.pdb" + ) + self._create_cmake_module_alias_targets( + os.path.join(self.package_folder, self._module_file_rel_path), + {"fastrtps": "fastdds::fastrtps"} + ) + + def package_info(self): + self.cpp_info.names["cmake_find_package"] = "fastdds" + self.cpp_info.names["cmake_find_multi_package"] = "fastdds" + # component fastrtps + self.cpp_info.components["fastrtps"].name = "fastrtps" + self.cpp_info.components["fastrtps"].libs = tools.collect_libs(self) + self.cpp_info.components["fastrtps"].requires = [ + "fast-cdr::fast-cdr", + "asio::asio", + "tinyxml2::tinyxml2", + "foonathan-memory::foonathan-memory", + "boost::boost" + ] + if self.settings.os in ["Linux", "Macos", "Neutrino"]: + self.cpp_info.components["fastrtps"].system_libs.append("pthread") + if self.settings.os == "Linux": + self.cpp_info.components["fastrtps"].system_libs.extend(["rt", "dl", "atomic"]) + elif self.settings.os == "Windows": + self.cpp_info.components["fastrtps"].system_libs.extend(["iphlpapi","shlwapi"]) + if self.options.shared: + self.cpp_info.components["fastrtps"].defines.append("FASTRTPS_DYN_LINK") + if self.options.with_ssl: + self.cpp_info.components["fastrtps"].requires.append("openssl::openssl") + self.cpp_info.components["fastrtps"].builddirs.append(self._module_subfolder) + self.cpp_info.components["fastrtps"].build_modules["cmake_find_package"] = [self._module_file_rel_path] + self.cpp_info.components["fastrtps"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path] + # component fast-discovery + self.cpp_info.components["fast-discovery"].name = "fast-discovery" + self.cpp_info.components["fast-discovery"].bindirs = ["bin"] + bin_path = os.path.join(self.package_folder, "bin") + self.output.info("Appending PATH env var for fast-dds::fast-discovery with : {}".format(bin_path)), + self.env_info.PATH.append(bin_path) + # component tools + self.cpp_info.components["tools"].name = "tools" + self.cpp_info.components["tools"].bindirs = [os.path.join("bin","tools")] + bin_path = os.path.join(self._pkg_bin, "tools") + self.output.info("Appending PATH env var for fast-dds::tools with : {}".format(bin_path)), + self.env_info.PATH.append(bin_path) diff --git a/recipes/fast-dds/all/patches/2.3.2-0001-fix-find-asio-and-tinyxml2.patch b/recipes/fast-dds/all/patches/2.3.2-0001-fix-find-asio-and-tinyxml2.patch new file mode 100644 index 0000000000000..4530f0222378b --- /dev/null +++ b/recipes/fast-dds/all/patches/2.3.2-0001-fix-find-asio-and-tinyxml2.patch @@ -0,0 +1,28 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 8a9cb0209..400c681e7 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -225,8 +225,8 @@ if(NOT BUILD_SHARED_LIBS) + endif() + + eprosima_find_package(fastcdr REQUIRED) +-eprosima_find_thirdparty(Asio asio VERSION 1.10.8) +-eprosima_find_thirdparty(TinyXML2 tinyxml2) ++eprosima_find_thirdparty(asio REQUIRED) ++eprosima_find_thirdparty(tinyxml2 REQUIRED) + + find_package(foonathan_memory REQUIRED) + message(STATUS "Found foonathan_memory: ${foonathan_memory_DIR}") +diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt +index 04d313bf2..c7d64f04d 100644 +--- a/src/cpp/CMakeLists.txt ++++ b/src/cpp/CMakeLists.txt +@@ -455,7 +455,7 @@ elseif(NOT EPROSIMA_INSTALLER) + # Link library to external libraries. + target_link_libraries(${PROJECT_NAME} ${PRIVACY} fastcdr foonathan_memory + ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS} +- ${TINYXML2_LIBRARY} ++ tinyxml2::tinyxml2 + $<$:OpenSSL::SSL$OpenSSL::Crypto> + $<$:iphlpapi$Shlwapi> + ${THIRDPARTY_BOOST_LINK_LIBS} diff --git a/recipes/fast-dds/all/test_package/CMakeLists.txt b/recipes/fast-dds/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..33450e84a9e7a --- /dev/null +++ b/recipes/fast-dds/all/test_package/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.1) +project(PackageTest CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +find_package(fastdds REQUIRED) + +add_executable(test_package + test_package.cpp + msg/HelloWorld.cxx + msg/HelloWorldPubSubTypes.cxx +) + +set_property(TARGET test_package PROPERTY CXX_STANDARD 11) + +target_link_libraries(test_package + fastrtps +) diff --git a/recipes/fast-dds/all/test_package/conanfile.py b/recipes/fast-dds/all/test_package/conanfile.py new file mode 100644 index 0000000000000..23ba95e79f465 --- /dev/null +++ b/recipes/fast-dds/all/test_package/conanfile.py @@ -0,0 +1,16 @@ +from conans import ConanFile, CMake, tools +import os + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self.settings): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/fast-dds/all/test_package/msg/HelloWorld.cxx b/recipes/fast-dds/all/test_package/msg/HelloWorld.cxx new file mode 100644 index 0000000000000..b850b450127bf --- /dev/null +++ b/recipes/fast-dds/all/test_package/msg/HelloWorld.cxx @@ -0,0 +1,207 @@ +// 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; } +#endif + +#include "HelloWorld.h" +#include + +#include +using namespace eprosima::fastcdr::exception; + +#include + +HelloWorld::HelloWorld() +{ + // m_index com.eprosima.idl.parser.typecode.PrimitiveTypeCode@1622f1b + m_index = 0; + // m_message com.eprosima.idl.parser.typecode.StringTypeCode@70e8f8e + m_message =""; + +} + +HelloWorld::~HelloWorld() +{ + + +} + +HelloWorld::HelloWorld(const HelloWorld &x) +{ + m_index = x.m_index; + m_message = x.m_message; +} + +HelloWorld::HelloWorld(HelloWorld &&x) +{ + 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) +{ + + m_index = x.m_index; + m_message = std::move(x.m_message); + + return *this; +} + +size_t HelloWorld::getMaxCdrSerializedSize(size_t current_alignment) +{ + size_t initial_alignment = current_alignment; + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4); + + + current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1; + + + return current_alignment - initial_alignment; +} + +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 += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.message().size() + 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::string &_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::string &&_message) +{ +m_message = std::move(_message); +} + +/*! + * @brief This function returns a constant reference to member message + * @return Constant reference to member message + */ +const std::string& HelloWorld::message() const +{ + return m_message; +} + +/*! + * @brief This function returns a reference to member message + * @return Reference to member message + */ +std::string& HelloWorld::message() +{ + return m_message; +} + +size_t HelloWorld::getKeyMaxCdrSerializedSize(size_t current_alignment) +{ + size_t current_align = current_alignment; + + + + + + return current_align; +} + +bool HelloWorld::isKeyDefined() +{ + return false; +} + +void HelloWorld::serializeKey(eprosima::fastcdr::Cdr &scdr) const +{ + (void) scdr; + + +} diff --git a/recipes/fast-dds/all/test_package/msg/HelloWorld.h b/recipes/fast-dds/all/test_package/msg/HelloWorld.h new file mode 100644 index 0000000000000..380f487456147 --- /dev/null +++ b/recipes/fast-dds/all/test_package/msg/HelloWorld.h @@ -0,0 +1,206 @@ +// 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.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifndef _HELLOWORLD_H_ +#define _HELLOWORLD_H_ + +// TODO Poner en el contexto. + +#include +#include +#include +#include +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif +#else +#define eProsima_user_DllExport +#endif + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(HelloWorld_SOURCE) +#define HelloWorld_DllAPI __declspec( dllexport ) +#else +#define HelloWorld_DllAPI __declspec( dllimport ) +#endif // HelloWorld_SOURCE +#else +#define HelloWorld_DllAPI +#endif +#else +#define HelloWorld_DllAPI +#endif // _WIN32 + +namespace eprosima +{ + namespace fastcdr + { + class Cdr; + } +} + + +/*! + * @brief This class represents the structure HelloWorld defined by the user in the IDL file. + * @ingroup HELLOWORLD + */ +class HelloWorld +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport HelloWorld(); + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~HelloWorld(); + + /*! + * @brief Copy constructor. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld(const HelloWorld &x); + + /*! + * @brief Move constructor. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld(HelloWorld &&x); + + /*! + * @brief Copy assignment. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld& operator=(const HelloWorld &x); + + /*! + * @brief Move assignment. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld& operator=(HelloWorld &&x); + + /*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ + eProsima_user_DllExport void index(uint32_t _index); + + /*! + * @brief This function returns the value of member index + * @return Value of member index + */ + eProsima_user_DllExport uint32_t index() const; + + /*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ + eProsima_user_DllExport uint32_t& index(); + + /*! + * @brief This function copies the value in member message + * @param _message New value to be copied in member message + */ + eProsima_user_DllExport void message(const std::string &_message); + + /*! + * @brief This function moves the value in member message + * @param _message New value to be moved in member message + */ + eProsima_user_DllExport void message(std::string &&_message); + + /*! + * @brief This function returns a constant reference to member message + * @return Constant reference to member message + */ + eProsima_user_DllExport const std::string& message() const; + + /*! + * @brief This function returns a reference to member message + * @return Reference to member message + */ + eProsima_user_DllExport std::string& message(); + + /*! + * @brief This function returns the maximum serialized size of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getMaxCdrSerializedSize(size_t current_alignment = 0); + + /*! + * @brief This function returns the serialized size of a data depending on the buffer alignment. + * @param data Data which is calculated its serialized size. + * @param current_alignment Buffer alignment. + * @return Serialized size. + */ + eProsima_user_DllExport static size_t getCdrSerializedSize(const HelloWorld& data, size_t current_alignment = 0); + + + /*! + * @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); + + + + /*! + * @brief This function returns the maximum serialized size of the Key of an object + * depending on the buffer alignment. + * @param current_alignment Buffer alignment. + * @return Maximum serialized size. + */ + eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize(size_t current_alignment = 0); + + /*! + * @brief This function tells you if the Key has been defined for this type + */ + eProsima_user_DllExport static bool isKeyDefined(); + + /*! + * @brief This function serializes the key members of an object using CDR serialization. + * @param cdr CDR serialization object. + */ + eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const; + +private: + uint32_t m_index; + std::string m_message; +}; + +#endif // _HELLOWORLD_H_ diff --git a/recipes/fast-dds/all/test_package/msg/HelloWorld.idl b/recipes/fast-dds/all/test_package/msg/HelloWorld.idl new file mode 100644 index 0000000000000..0fd2c355aeefa --- /dev/null +++ b/recipes/fast-dds/all/test_package/msg/HelloWorld.idl @@ -0,0 +1,5 @@ +struct HelloWorld +{ + unsigned long index; + string message; +}; diff --git a/recipes/fast-dds/all/test_package/msg/HelloWorldPubSubTypes.cxx b/recipes/fast-dds/all/test_package/msg/HelloWorldPubSubTypes.cxx new file mode 100644 index 0000000000000..89e89cc8581e8 --- /dev/null +++ b/recipes/fast-dds/all/test_package/msg/HelloWorldPubSubTypes.cxx @@ -0,0 +1,133 @@ +// 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 HelloWorldPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastcdrgen. + */ + + +#include +#include + +#include "HelloWorldPubSubTypes.h" + +using namespace eprosima::fastrtps; +using namespace eprosima::fastrtps::rtps; + +HelloWorldPubSubType::HelloWorldPubSubType() +{ + setName("HelloWorld"); + m_typeSize = static_cast(HelloWorld::getMaxCdrSerializedSize()) + 4 /*encapsulation*/; + m_isGetKeyDefined = HelloWorld::isKeyDefined(); + size_t keyLength = HelloWorld::getKeyMaxCdrSerializedSize()>16 ? HelloWorld::getKeyMaxCdrSerializedSize() : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +HelloWorldPubSubType::~HelloWorldPubSubType() +{ + if(m_keyBuffer!=nullptr) + free(m_keyBuffer); +} + +bool HelloWorldPubSubType::serialize(void *data, SerializedPayload_t *payload) +{ + HelloWorld *p_type = static_cast(data); + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); // Object that manages the raw buffer. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data. + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + // Serialize encapsulation + ser.serialize_encapsulation(); + + try + { + p_type->serialize(ser); // Serialize the object: + } + catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) + { + return false; + } + + payload->length = static_cast(ser.getSerializedDataLength()); //Get the serialized length + return true; +} + +bool HelloWorldPubSubType::deserialize(SerializedPayload_t* payload, void* data) +{ + HelloWorld* p_type = static_cast(data); //Convert DATA to pointer of your type + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); // Object that manages the raw buffer. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + eprosima::fastcdr::Cdr::DDS_CDR); // Object that deserializes the data. + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + try + { + p_type->deserialize(deser); //Deserialize the object: + } + catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/) + { + return false; + } + + return true; +} + +std::function HelloWorldPubSubType::getSerializedSizeProvider(void* data) +{ + return [data]() -> uint32_t + { + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + 4 /*encapsulation*/; + }; +} + +void* HelloWorldPubSubType::createData() +{ + return reinterpret_cast(new HelloWorld()); +} + +void HelloWorldPubSubType::deleteData(void* data) +{ + delete(reinterpret_cast(data)); +} + +bool HelloWorldPubSubType::getKey(void *data, InstanceHandle_t* handle, bool force_md5) +{ + if(!m_isGetKeyDefined) + return false; + HelloWorld* p_type = static_cast(data); + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer),HelloWorld::getKeyMaxCdrSerializedSize()); // Object that manages the raw buffer. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS); // Object that serializes the data. + p_type->serializeKey(ser); + if(force_md5 || HelloWorld::getKeyMaxCdrSerializedSize()>16) { + m_md5.init(); + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); + m_md5.finalize(); + for(uint8_t i = 0;i<16;++i) { + handle->value[i] = m_md5.digest[i]; + } + } + else { + for(uint8_t i = 0;i<16;++i) { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + diff --git a/recipes/fast-dds/all/test_package/msg/HelloWorldPubSubTypes.h b/recipes/fast-dds/all/test_package/msg/HelloWorldPubSubTypes.h new file mode 100644 index 0000000000000..7afa612cc5925 --- /dev/null +++ b/recipes/fast-dds/all/test_package/msg/HelloWorldPubSubTypes.h @@ -0,0 +1,57 @@ +// 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 HelloWorldPubSubTypes.h + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastcdrgen. + */ + + +#ifndef _HELLOWORLD_PUBSUBTYPES_H_ +#define _HELLOWORLD_PUBSUBTYPES_H_ + +#include +#include + +#include "HelloWorld.h" + +#if !defined(GEN_API_VER) || (GEN_API_VER != 1) +#error Generated HelloWorld is not compatible with current installed Fast-RTPS. Please, regenerate it with fastrtpsgen. +#endif + +/*! + * @brief This class represents the TopicDataType of the type HelloWorld defined by the user in the IDL file. + * @ingroup HELLOWORLD + */ +class HelloWorldPubSubType : public eprosima::fastrtps::TopicDataType { +public: + typedef HelloWorld type; + + eProsima_user_DllExport HelloWorldPubSubType(); + + eProsima_user_DllExport virtual ~HelloWorldPubSubType(); + eProsima_user_DllExport virtual bool serialize(void *data, eprosima::fastrtps::rtps::SerializedPayload_t *payload) override; + eProsima_user_DllExport virtual bool deserialize(eprosima::fastrtps::rtps::SerializedPayload_t *payload, void *data) override; + eProsima_user_DllExport virtual std::function getSerializedSizeProvider(void* data) override; + eProsima_user_DllExport virtual bool getKey(void *data, eprosima::fastrtps::rtps::InstanceHandle_t *ihandle, + bool force_md5 = false) override; + eProsima_user_DllExport virtual void* createData() override; + eProsima_user_DllExport virtual void deleteData(void * data) override; + MD5 m_md5; + unsigned char* m_keyBuffer; +}; + +#endif // _HELLOWORLD_PUBSUBTYPES_H_ diff --git a/recipes/fast-dds/all/test_package/test_package.cpp b/recipes/fast-dds/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..89ac973375f14 --- /dev/null +++ b/recipes/fast-dds/all/test_package/test_package.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +#include + +#include "msg/HelloWorld.h" +#include "msg/HelloWorldPubSubTypes.h" + +int main() +{ + // Define msg to send + HelloWorld hello; + hello.index(0); + hello.message("HelloWorld"); + + eprosima::fastrtps::Participant *participant; + eprosima::fastrtps::Publisher *publisher; + + eprosima::fastrtps::ParticipantAttributes PParam; + PParam.rtps.setName("Participant_pub"); + participant = eprosima::fastrtps::Domain::createParticipant(PParam); + + if (participant == nullptr) + { + return 1; + } + + HelloWorldPubSubType type; + + eprosima::fastrtps::Domain::registerType(participant, &type); + + //CREATE THE PUBLISHER + eprosima::fastrtps::PublisherAttributes Wparam; + Wparam.topic.topicKind = eprosima::fastrtps::rtps::TopicKind_t::NO_KEY; + Wparam.topic.topicDataType = "HelloWorld"; + Wparam.topic.topicName = "HelloWorldTopic"; + Wparam.topic.historyQos.kind = eprosima::fastrtps::KEEP_LAST_HISTORY_QOS; + Wparam.topic.historyQos.depth = 30; + Wparam.topic.resourceLimitsQos.max_samples = 50; + Wparam.topic.resourceLimitsQos.allocated_samples = 20; + Wparam.times.heartbeatPeriod.seconds = 2; + Wparam.times.heartbeatPeriod.nanosec = 200 * 1000 * 1000; + publisher = eprosima::fastrtps::Domain::createPublisher(participant, Wparam); + if (publisher == nullptr) + { + return 1; + } + + publisher->write((void*)&hello); + + eprosima::fastrtps::Domain::removeParticipant(participant); + + return 0; +} diff --git a/recipes/fast-dds/config.yml b/recipes/fast-dds/config.yml new file mode 100644 index 0000000000000..aee8de619ec30 --- /dev/null +++ b/recipes/fast-dds/config.yml @@ -0,0 +1,3 @@ +versions: + "2.3.2": + folder: all