diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d6490502433..de35eb6c149 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -13,7 +13,9 @@ # limitations under the License. set(fastdds_FOUND TRUE) + add_subdirectory(cpp/configuration) +add_subdirectory(cpp/content_filter) add_subdirectory(cpp/custom_payload_pool) add_subdirectory(cpp/dds) add_subdirectory(cpp/hello_world) diff --git a/examples/cpp/content_filter/Application.cpp b/examples/cpp/content_filter/Application.cpp new file mode 100644 index 00000000000..e2b0192ee41 --- /dev/null +++ b/examples/cpp/content_filter/Application.cpp @@ -0,0 +1,58 @@ +// Copyright 2024 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 Application.cpp + * + */ + +#include "Application.hpp" + +#include "CLIParser.hpp" +#include "SubscriberApp.hpp" +#include "PublisherApp.hpp" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace content_filter { + +//! Factory method to create a publisher or subscriber +std::shared_ptr Application::make_app( + const CLIParser::content_filter_config& config, + const std::string& topic_name) +{ + std::shared_ptr entity; + switch (config.entity) + { + case CLIParser::EntityKind::PUBLISHER: + entity = std::make_shared(config.pub_config, topic_name); + break; + case CLIParser::EntityKind::SUBSCRIBER: + entity = std::make_shared(config.sub_config, topic_name); + break; + case CLIParser::EntityKind::UNDEFINED: + default: + throw std::runtime_error("Entity initialization failed"); + break; + } + return entity; +} + +} // namespace content_filter +} // namespace examples +} // namespace fastdds +} // namespace eprosima diff --git a/examples/cpp/content_filter/Application.hpp b/examples/cpp/content_filter/Application.hpp new file mode 100644 index 00000000000..ea70fb8766a --- /dev/null +++ b/examples/cpp/content_filter/Application.hpp @@ -0,0 +1,56 @@ +// Copyright 2024 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 Application.hpp + * + */ + +#ifndef _FASTDDS_CONTENT_FILTER_APPLICATION_HPP_ +#define _FASTDDS_CONTENT_FILTER_APPLICATION_HPP_ + +#include + +#include "CLIParser.hpp" + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace content_filter { + +class Application +{ +public: + + //! Virtual destructor + virtual ~Application() = default; + + //! Run application + virtual void run() = 0; + + //! Trigger the end of execution + virtual void stop() = 0; + + //! Factory method to create applications based on configuration + static std::shared_ptr make_app( + const CLIParser::content_filter_config& config, + const std::string& topic_name); +}; + +} // namespace content_filter +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif /* _FASTDDS_CONTEN_FILTER_APPLICATION_HPP_ */ diff --git a/examples/cpp/content_filter/CLIParser.hpp b/examples/cpp/content_filter/CLIParser.hpp new file mode 100644 index 00000000000..9e483a3ba20 --- /dev/null +++ b/examples/cpp/content_filter/CLIParser.hpp @@ -0,0 +1,468 @@ +// Copyright 2024 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. + +#include +#include +#include +#include + +#include + +#ifndef _FASTDDS_CONTENT_FILTER_CLI_PARSER_HPP_ +#define _FASTDDS_CONTENT_FILTER_CLI_PARSER_HPP_ + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace content_filter { + +using dds::Log; + +class CLIParser +{ +public: + + CLIParser() = delete; + + //! Entity kind enumeration + enum class EntityKind : uint8_t + { + PUBLISHER, + SUBSCRIBER, + UNDEFINED + }; + + //! Filter kind enumeration + enum class FilterKind : uint8_t + { + DEFAULT, + CUSTOM, + NONE + }; + + //! Publisher configuration structure + struct publisher_config + { + uint16_t samples = 0; + uint16_t interval = 100; + uint16_t max_reader_filters = 32; + bool reliable{false}; + bool transient_local{false}; + }; + + //! Subscriber application configuration structure + struct subscriber_config + { + CLIParser::FilterKind filter_kind = CLIParser::FilterKind::DEFAULT; + std::string filter_expression = "index between %0 and %1"; + std::string upper_bound = "9"; + std::string lower_bound = "5"; + bool reliable{false}; + bool transient_local{false}; + }; + + //! Configuration structure for the application + struct content_filter_config + { + CLIParser::EntityKind entity = CLIParser::EntityKind::UNDEFINED; + publisher_config pub_config; + subscriber_config sub_config; + }; + + /** + * @brief Print usage help message and exit with the given return code + * + * @param return_code return code to exit with + * + * @warning This method finishes the execution of the program with the input return code + */ + static void print_help( + uint8_t return_code) + { + std::cout << "Usage: content_filter [options]" << std::endl; + std::cout << "" << std::endl; + std::cout << "Entities:" << std::endl; + std::cout << " publisher Run a publisher entity" << std::endl; + std::cout << " subscriber Run a subscriber entity" << std::endl; + std::cout << "" << std::endl; + std::cout << "Common options:" << std::endl; + std::cout << " -h, --help Print this help message" << std::endl; + std::cout << " --reliable Set Reliability QoS as reliable" << std::endl; + std::cout << " (Default: Best effort)" << std::endl; + std::cout << " --transient-local Set Durability QoS as transient local" << std::endl; + std::cout << " (Default: Volatile)" << std::endl; + std::cout << "Publisher options:" << std::endl; + std::cout << " -s , --samples Number of samples to send" << std::endl; + std::cout << " (Default: 0 [unlimited])" << std::endl; + std::cout << " -i , --interval Time between samples in milliseconds" << std::endl; + std::cout << " --reader-filters Set the maximum number of readers that the" << std::endl; + std::cout << " writer evaluates for applying the filter" << std::endl; + std::cout << " (Default: 32)" << std::endl; + std::cout << "Subscriber options:" << std::endl; + std::cout << " --filter-kind Kind of Content Filter to use" << std::endl; + std::cout << " (Default: default SQL filter)" << std::endl; + std::cout << " --filter-expression Filter Expression of default SQL filter" << std::endl; + std::cout << " (Default: \"index between %0 and %1\"," << std::endl; + std::cout << " where %0 and %1 are the indeces of the" << std::endl; + std::cout << " parameters, i.e. lb and ub)" << std::endl; + std::cout << " -lb , --lower-bound Lower bound of the data range to filter." << std::endl; + std::cout << " (Default: 5)" << std::endl; + std::cout << " -up , --upper-bound Upper bound of the data range to filter." << std::endl; + std::cout << " (Default: 9)" << std::endl; + std::exit(return_code); + } + + /** + * @brief Parse the command line options and return the configuration_config object + * + * @param argc number of arguments + * @param argv array of arguments + * @return configuration_config object with the parsed options + * + * @warning This method finishes the execution of the program if the input arguments are invalid + */ + static content_filter_config parse_cli_options( + int argc, + char* argv[]) + { + content_filter_config config; + + if (argc < 2) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "missing entity argument"); + print_help(EXIT_FAILURE); + } + + std::string first_argument = argv[1]; + + if (first_argument == "publisher" ) + { + config.entity = CLIParser::EntityKind::PUBLISHER; + } + else if (first_argument == "subscriber") + { + config.entity = CLIParser::EntityKind::SUBSCRIBER; + } + else if (first_argument == "-h" || first_argument == "--help") + { + print_help(EXIT_SUCCESS); + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing entity argument " + first_argument); + print_help(EXIT_FAILURE); + } + + for (int i = 2; i < argc; ++i) + { + std::string arg = argv[i]; + if (arg == "-h" || arg == "--help") + { + print_help(EXIT_SUCCESS); + } + else if (arg == "-s" || arg == "--samples") + { + if (i + 1 < argc) + { + try + { + int input = std::stoi(argv[++i]); + if (input < std::numeric_limits::min() || + input > std::numeric_limits::max()) + { + throw std::out_of_range("sample argument out of range"); + } + else + { + if (config.entity == CLIParser::EntityKind::PUBLISHER) + { + config.pub_config.samples = static_cast(input); + } + else if (config.entity == CLIParser::EntityKind::SUBSCRIBER) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, + "samples option option can only be used with the Publisher"); + print_help(EXIT_FAILURE); + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "entity not specified for --sample argument"); + print_help(EXIT_FAILURE); + } + } + } + catch (const std::invalid_argument& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid sample argument for " + arg + ": " + e.what()); + print_help(EXIT_FAILURE); + } + catch (const std::out_of_range& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "sample argument out of range for " + arg + ": " + e.what()); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg); + print_help(EXIT_FAILURE); + } + } + else if (arg == "-i" || arg == "--interval") + { + + if (i + 1 < argc) + { + int input = std::stoi(argv[++i]); + if (config.entity == CLIParser::EntityKind::PUBLISHER) + { + config.pub_config.interval = static_cast(input); + } + else if (config.entity == CLIParser::EntityKind::SUBSCRIBER) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "interval option can only be used with the Publisher"); + print_help(EXIT_FAILURE); + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "entity not specified for --sample argument"); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg); + print_help(EXIT_FAILURE); + } + } + else if (arg == "--reader-filters") + { + if (i + 1 < argc) + { + if (config.entity == CLIParser::EntityKind::PUBLISHER) + { + config.pub_config.max_reader_filters = static_cast(std::stoi(argv[++i])); + } + else if (config.entity == CLIParser::EntityKind::SUBSCRIBER) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "--reader-filters is only valid for publisher entity"); + print_help(EXIT_FAILURE); + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "entity not specified for --reader-filters argument"); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg); + print_help(EXIT_FAILURE); + } + } + else if (arg == "--reliable") + { + config.pub_config.reliable = true; + config.sub_config.reliable = true; + } + else if (arg == "--transient-local") + { + config.pub_config.transient_local = true; + config.sub_config.transient_local = true; + } + else if (arg == "--filter-kind") + { + if (i + 1 < argc) + { + if (config.entity == CLIParser::EntityKind::SUBSCRIBER) + { + std::string filter_type = argv[++i]; + if (filter_type == "custom") + { + config.sub_config.filter_kind = CLIParser::FilterKind::CUSTOM; + } + else if (filter_type == "default") + { + config.sub_config.filter_kind = CLIParser::FilterKind::DEFAULT; + } + else if (filter_type == "none") + { + config.sub_config.filter_kind = CLIParser::FilterKind::NONE; + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "unknown --filter argument"); + print_help(EXIT_FAILURE); + } + } + else if (config.entity == CLIParser::EntityKind::PUBLISHER) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "--filter is only valid for subscriber entity"); + print_help(EXIT_FAILURE); + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "entity not specified for --filter argument"); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg); + print_help(EXIT_FAILURE); + } + } + else if (arg == "--filter-expression") + { + if (i + 1 < argc) + { + if (config.entity == CLIParser::EntityKind::SUBSCRIBER) + { + std::string filter_expression = argv[++i]; + config.sub_config.filter_expression = filter_expression; + + } + else if (config.entity == CLIParser::EntityKind::PUBLISHER) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "--filter is only valid for subscriber entity"); + print_help(EXIT_FAILURE); + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "entity not specified for --filter argument"); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg); + print_help(EXIT_FAILURE); + } + } + + else if (arg == "-lb" || arg == "--lower-bound") + { + if (i + 1 < argc) + { + if (config.entity == CLIParser::EntityKind::SUBSCRIBER) + { + config.sub_config.lower_bound = argv[++i]; + } + else if (config.entity == CLIParser::EntityKind::PUBLISHER) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "lower-bound option can only be used with the Subscriber"); + print_help(EXIT_FAILURE); + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "entity not specified for --filter argument"); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg); + print_help(EXIT_FAILURE); + } + } + else if (arg == "-ub" || arg == "--upper-bound") + { + if (i + 1 < argc) + { + if (config.entity == CLIParser::EntityKind::SUBSCRIBER) + { + config.sub_config.upper_bound = argv[++i]; + } + else if (config.entity == CLIParser::EntityKind::PUBLISHER) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "upper-bound option can only be used with the Subscriber"); + print_help(EXIT_FAILURE); + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "entity not specified for --filter argument"); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "unknown option " + arg); + print_help(EXIT_FAILURE); + } + } + + return config; + } + + /** + * @brief Parse the signal number into the signal name + * + * @param signum signal number + * @return std::string signal name + */ + static std::string parse_signal( + const int& signum) + { + switch (signum) + { + case SIGINT: + return "SIGINT"; + case SIGTERM: + return "SIGTERM"; +#ifndef _WIN32 + case SIGQUIT: + return "SIGQUIT"; + case SIGHUP: + return "SIGHUP"; +#endif // _WIN32 + default: + return "UNKNOWN SIGNAL"; + } + } + + /** + * @brief Parse the entity kind into std::string + * + * @param entity entity kind + * @return std::string entity kind + */ + static std::string parse_entity_kind( + const EntityKind& entity) + { + switch (entity) + { + case EntityKind::PUBLISHER: + return "Publisher"; + case EntityKind::SUBSCRIBER: + return "Subscriber"; + case EntityKind::UNDEFINED: + default: + return "Undefined entity"; + } + } + +}; + +} // namespace content_filter +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif // _FASTDDS_CONTENT_FILTER_CLI_PARSER_HPP_ diff --git a/examples/cpp/dds/ContentFilteredTopicExample/CMakeLists.txt b/examples/cpp/content_filter/CMakeLists.txt similarity index 52% rename from examples/cpp/dds/ContentFilteredTopicExample/CMakeLists.txt rename to examples/cpp/content_filter/CMakeLists.txt index 0eb3d11b4fc..4d50fdcdbde 100644 --- a/examples/cpp/dds/ContentFilteredTopicExample/CMakeLists.txt +++ b/examples/cpp/content_filter/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# Copyright 2024 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. @@ -14,7 +14,7 @@ cmake_minimum_required(VERSION 3.20) -project("ContentFilterTopic" VERSION 1 LANGUAGES CXX) +project(fastdds_content_filter_example VERSION 1 LANGUAGES CXX) # Find requirements if(NOT fastcdr_FOUND) @@ -25,22 +25,17 @@ if(NOT fastdds_FOUND) find_package(fastdds 3 REQUIRED) endif() -message(STATUS "Configuring ContentFilterTopic examples...") +message(STATUS "Configuring content filter example...") -set(CFT_COMMON_SOURCES - ContentFilteredTopicExample_main.cpp - ContentFilteredTopicExamplePublisher.cpp - ContentFilteredTopicExampleSubscriber.cpp - HelloWorldPubSubTypes.cxx - HelloWorldTypeObjectSupport.cxx - ) +file(GLOB CONTENT_FILTER_SOURCES_CXX "*.cxx") +file(GLOB CONTENT_FILTER_SOURCES_CPP "*.cpp") -add_executable(DDSContentFilteredTopicExample ${CFT_COMMON_SOURCES}) -target_compile_definitions(DDSContentFilteredTopicExample PRIVATE +add_executable(content_filter ${CONTENT_FILTER_SOURCES_CXX} ${CONTENT_FILTER_SOURCES_CPP}) +target_compile_definitions(content_filter PRIVATE $<$>,$>:__DEBUG> $<$:__INTERNALDEBUG> # Internal debug activated. ) -target_compile_features(DDSContentFilteredTopicExample PRIVATE cxx_std_11) -target_link_libraries(DDSContentFilteredTopicExample fastdds fastcdr fastdds::optionparser) -install(TARGETS DDSContentFilteredTopicExample - RUNTIME DESTINATION examples/cpp/dds/ContentFilteredTopicExample/${BIN_INSTALL_DIR}) +target_compile_features(content_filter PRIVATE cxx_std_11) +target_link_libraries(content_filter fastdds fastcdr fastdds::optionparser) +install(TARGETS content_filter + RUNTIME DESTINATION ${DATA_INSTALL_DIR}/fastdds/examples/cpp/content_filter/${BIN_INSTALL_DIR}) diff --git a/examples/cpp/dds/ContentFilteredTopicExample/MyCustomFilter.hpp b/examples/cpp/content_filter/CustomContentFilter.hpp similarity index 85% rename from examples/cpp/dds/ContentFilteredTopicExample/MyCustomFilter.hpp rename to examples/cpp/content_filter/CustomContentFilter.hpp index 2e2fe952921..69ac5f49af6 100644 --- a/examples/cpp/dds/ContentFilteredTopicExample/MyCustomFilter.hpp +++ b/examples/cpp/content_filter/CustomContentFilter.hpp @@ -1,5 +1,5 @@ -#ifndef _CONTENTFILTEREDTOPICEXAMPLE_MYCUSTOMFILTER_HPP_ -#define _CONTENTFILTEREDTOPICEXAMPLE_MYCUSTOMFILTER_HPP_ +#ifndef _FASTDDS_CONTENT_FILTER_CUSTOM_FILTER_HPP_ +#define _FASTDDS_CONTENT_FILTER_CUSTOM_FILTER_HPP_ #include @@ -9,17 +9,17 @@ //! Custom filter class //! It requieres two parameters 'low_mark_' and 'high_mark_'. //! Filter samples which index is lower than 'low_mark_' and higher than 'high_mark_'. -class MyCustomFilter : public eprosima::fastdds::dds::IContentFilter +class CustomContentFilter : public eprosima::fastdds::dds::IContentFilter { public: /** - * @brief Construct a new MyCustomFilter object + * @brief Construct a new CustomContentFilter object * * @param low_mark * @param high_mark */ - MyCustomFilter( + CustomContentFilter( int low_mark, int high_mark) : low_mark_(low_mark) @@ -28,7 +28,7 @@ class MyCustomFilter : public eprosima::fastdds::dds::IContentFilter } //! Destructor - virtual ~MyCustomFilter() = default; + virtual ~CustomContentFilter() = default; /** * @brief Evaluate filter discriminating whether the sample is relevant or not, i.e. whether it meets the filtering @@ -78,4 +78,4 @@ class MyCustomFilter : public eprosima::fastdds::dds::IContentFilter }; -#endif // _CONTENTFILTEREDTOPICEXAMPLE_MYCUSTOMFILTER_HPP_ +#endif // _FASTDDS_CONTENT_FILTER_CUSTOM_FILTER_HPP_ diff --git a/examples/cpp/dds/ContentFilteredTopicExample/MyCustomFilterFactory.hpp b/examples/cpp/content_filter/CustomContentFilterFactory.hpp similarity index 82% rename from examples/cpp/dds/ContentFilteredTopicExample/MyCustomFilterFactory.hpp rename to examples/cpp/content_filter/CustomContentFilterFactory.hpp index 606a37d3226..ea65f1394e5 100644 --- a/examples/cpp/dds/ContentFilteredTopicExample/MyCustomFilterFactory.hpp +++ b/examples/cpp/content_filter/CustomContentFilterFactory.hpp @@ -1,14 +1,14 @@ -#ifndef _CONTENTFILTEREDTOPICEXAMPLE_MYCUSTOMFILTERFACTORY_HPP_ -#define _CONTENTFILTEREDTOPICEXAMPLE_MYCUSTOMFILTERFACTORY_HPP_ +#ifndef _FASTDDS_CONTENT_FILTER_CUSTOM_FILTER_FACTORY_HPP_ +#define _FASTDDS_CONTENT_FILTER_CUSTOM_FILTER_FACTORY_HPP_ #include #include #include -#include "MyCustomFilter.hpp" +#include "CustomContentFilter.hpp" //! Custom filter factory -class MyCustomFilterFactory : public eprosima::fastdds::dds::IContentFilterFactory +class CustomContentFilterFactory : public eprosima::fastdds::dds::IContentFilterFactory { public: @@ -35,7 +35,7 @@ class MyCustomFilterFactory : public eprosima::fastdds::dds::IContentFilterFacto eprosima::fastdds::dds::IContentFilter*& filter_instance) override { // Check the ContentFilteredTopic should be created by this factory. - if (0 != strcmp(filter_class_name, "MY_CUSTOM_FILTER") || + if (0 != strcmp(filter_class_name, "CUSTOM_FILTER") || // Check the ContentFilteredTopic is created for the unique type this Custom Filter supports. 0 != strcmp(type_name, "HelloWorld") || // Check that the two mandatory filter parameters were set. @@ -47,11 +47,11 @@ class MyCustomFilterFactory : public eprosima::fastdds::dds::IContentFilterFacto // If there is an update, delete previous instance. if (nullptr != filter_instance) { - delete(dynamic_cast(filter_instance)); + delete(dynamic_cast(filter_instance)); } // Instantiation of the Custom Filter. - filter_instance = new MyCustomFilter(std::stoi(filter_parameters[0]), std::stoi(filter_parameters[1])); + filter_instance = new CustomContentFilter(std::stoi(filter_parameters[0]), std::stoi(filter_parameters[1])); return eprosima::fastdds::dds::RETCODE_OK; } @@ -71,7 +71,7 @@ class MyCustomFilterFactory : public eprosima::fastdds::dds::IContentFilterFacto eprosima::fastdds::dds::IContentFilter* filter_instance) override { // Check the ContentFilteredTopic should be created by this factory. - if (0 != strcmp(filter_class_name, "MY_CUSTOM_FILTER") || + if (0 != strcmp(filter_class_name, "CUSTOM_FILTER") || // Check the filter instance is valid nullptr != filter_instance) { @@ -81,11 +81,11 @@ class MyCustomFilterFactory : public eprosima::fastdds::dds::IContentFilterFacto // Deletion of the Custom Filter. if (nullptr != filter_instance) { - delete(dynamic_cast(filter_instance)); + delete(dynamic_cast(filter_instance)); } return eprosima::fastdds::dds::RETCODE_OK; } }; -#endif // _CONTENTFILTEREDTOPICEXAMPLE_MYCUSTOMFILTERFACTORY_HPP_ +#endif // _FASTDDS_CONTENT_FILTER_CUSTOM_FILTER_FACTORY_HPP_ diff --git a/examples/cpp/dds/ContentFilteredTopicExample/HelloWorld.hpp b/examples/cpp/content_filter/HelloWorld.hpp similarity index 100% rename from examples/cpp/dds/ContentFilteredTopicExample/HelloWorld.hpp rename to examples/cpp/content_filter/HelloWorld.hpp diff --git a/examples/cpp/dds/ContentFilteredTopicExample/HelloWorld.idl b/examples/cpp/content_filter/HelloWorld.idl similarity index 100% rename from examples/cpp/dds/ContentFilteredTopicExample/HelloWorld.idl rename to examples/cpp/content_filter/HelloWorld.idl diff --git a/examples/cpp/dds/ContentFilteredTopicExample/HelloWorldCdrAux.hpp b/examples/cpp/content_filter/HelloWorldCdrAux.hpp similarity index 100% rename from examples/cpp/dds/ContentFilteredTopicExample/HelloWorldCdrAux.hpp rename to examples/cpp/content_filter/HelloWorldCdrAux.hpp diff --git a/examples/cpp/dds/ContentFilteredTopicExample/HelloWorldCdrAux.ipp b/examples/cpp/content_filter/HelloWorldCdrAux.ipp similarity index 100% rename from examples/cpp/dds/ContentFilteredTopicExample/HelloWorldCdrAux.ipp rename to examples/cpp/content_filter/HelloWorldCdrAux.ipp diff --git a/examples/cpp/dds/BasicConfigurationExample/HelloWorldPubSubTypes.cxx b/examples/cpp/content_filter/HelloWorldPubSubTypes.cxx similarity index 100% rename from examples/cpp/dds/BasicConfigurationExample/HelloWorldPubSubTypes.cxx rename to examples/cpp/content_filter/HelloWorldPubSubTypes.cxx diff --git a/examples/cpp/dds/ContentFilteredTopicExample/HelloWorldPubSubTypes.h b/examples/cpp/content_filter/HelloWorldPubSubTypes.h similarity index 100% rename from examples/cpp/dds/ContentFilteredTopicExample/HelloWorldPubSubTypes.h rename to examples/cpp/content_filter/HelloWorldPubSubTypes.h diff --git a/examples/cpp/dds/ContentFilteredTopicExample/HelloWorldTypeObjectSupport.cxx b/examples/cpp/content_filter/HelloWorldTypeObjectSupport.cxx similarity index 100% rename from examples/cpp/dds/ContentFilteredTopicExample/HelloWorldTypeObjectSupport.cxx rename to examples/cpp/content_filter/HelloWorldTypeObjectSupport.cxx diff --git a/examples/cpp/dds/BasicConfigurationExample/HelloWorldTypeObjectSupport.hpp b/examples/cpp/content_filter/HelloWorldTypeObjectSupport.hpp similarity index 100% rename from examples/cpp/dds/BasicConfigurationExample/HelloWorldTypeObjectSupport.hpp rename to examples/cpp/content_filter/HelloWorldTypeObjectSupport.hpp diff --git a/examples/cpp/content_filter/PublisherApp.cpp b/examples/cpp/content_filter/PublisherApp.cpp new file mode 100644 index 00000000000..6ec5608ca0e --- /dev/null +++ b/examples/cpp/content_filter/PublisherApp.cpp @@ -0,0 +1,197 @@ +// Copyright 2024 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 PublisherApp.cpp + * + */ + +#include "PublisherApp.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "HelloWorldTypeObjectSupport.hpp" + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace content_filter { + +PublisherApp::PublisherApp( + const CLIParser::publisher_config& config, + const std::string& topic_name) + : participant_(nullptr) + , publisher_(nullptr) + , topic_(nullptr) + , writer_(nullptr) + , type_(new HelloWorldPubSubType()) + , matched_(0) + , samples_(config.samples) + , stop_(false) + , period_ms_(config.interval) +{ + // Initialize internal variables + matched_ = 0; + + // Initialize data sample + hello_.index(0); + hello_.message("HelloWorld"); + + // Set DomainParticipant name + DomainParticipantQos pqos; + pqos.name("Participant_pub"); + + // Get DomainParticipantFactory + auto factory = DomainParticipantFactory::get_instance(); + + // Create DomainParticipant in domain 0 + participant_ = factory->create_participant(1, pqos); + if (participant_ == nullptr) + { + throw std::runtime_error("Participant initialization failed"); + } + + // Register the type + type_.register_type(participant_); + + // Create the Publisher + publisher_ = participant_->create_publisher(PUBLISHER_QOS_DEFAULT, nullptr); + if (publisher_ == nullptr) + { + throw std::runtime_error("Publisher initialization failed"); + } + + // Create the Topic + topic_ = participant_->create_topic(topic_name, type_.get_type_name(), TOPIC_QOS_DEFAULT); + if (topic_ == nullptr) + { + throw std::runtime_error("Topic initialization failed"); + } + + // Create the DataWriter + DataWriterQos wqos = DATAWRITER_QOS_DEFAULT; + wqos.data_sharing().off(); + wqos.writer_resource_limits().reader_filters_allocation.initial = 0; + wqos.writer_resource_limits().reader_filters_allocation.maximum = config.max_reader_filters; + wqos.writer_resource_limits().reader_filters_allocation.increment = 1; + if (!config.transient_local) + { + wqos.durability().kind = VOLATILE_DURABILITY_QOS; + } + if (!config.reliable) + { + wqos.reliability().kind = BEST_EFFORT_RELIABILITY_QOS; + } + writer_ = publisher_->create_datawriter(topic_, wqos, this); + if (writer_ == nullptr) + { + throw std::runtime_error("DataWriter initialization failed"); + } +} + +PublisherApp::~PublisherApp() +{ + if (participant_ != nullptr) + { + // Delete DDS entities contained within the DomainParticipant + participant_->delete_contained_entities(); + // Delete DomainParticipant + DomainParticipantFactory::get_instance()->delete_participant(participant_); + } +} + +void PublisherApp::on_publication_matched( + DataWriter*, + const PublicationMatchedStatus& info) +{ + if (info.current_count_change == 1) + { + matched_ = static_cast(info.current_count); + std::cout << "Publisher matched." << std::endl; + cv_.notify_one(); + } + else if (info.current_count_change == -1) + { + matched_ = static_cast(info.current_count); + std::cout << "Publisher unmatched." << std::endl; + } + else + { + std::cout << info.current_count_change + << " is not a valid value for PublicationMatchedStatus current count change" << std::endl; + } +} + +void PublisherApp::run() +{ + while (!is_stopped() && ((samples_ == 0) || (hello_.index() < samples_))) + { + if (publish()) + { + std::cout << "Message: '" << hello_.message() << "' with index: '" << hello_.index() + << "' SENT" << std::endl; + } + // Wait for period or stop event + std::unique_lock period_lock(mutex_); + cv_.wait_for(period_lock, std::chrono::milliseconds(period_ms_), [&]() + { + return is_stopped(); + }); + } +} + +bool PublisherApp::publish() +{ + bool ret = false; + // Wait for the data endpoints discovery + std::unique_lock matched_lock(mutex_); + cv_.wait(matched_lock, [&]() + { + // at least one has been discovered + return ((matched_ > 0) || is_stopped()); + }); + + if (!is_stopped()) + { + hello_.index(hello_.index() + 1); + ret = writer_->write(&hello_); + } + return ret; +} + +bool PublisherApp::is_stopped() +{ + return stop_.load(); +} + +void PublisherApp::stop() +{ + stop_.store(true); + cv_.notify_one(); +} + +} // namespace content_filter +} // namespace examples +} // namespace fastdds +} // namespace eprosima diff --git a/examples/cpp/content_filter/PublisherApp.hpp b/examples/cpp/content_filter/PublisherApp.hpp new file mode 100644 index 00000000000..94188951228 --- /dev/null +++ b/examples/cpp/content_filter/PublisherApp.hpp @@ -0,0 +1,98 @@ +// Copyright 2024 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 PublisherApp.hpp + * + */ + +#ifndef _FASTDDS_CONTENT_FILTER_PUBLISHER_APP_HPP_ +#define _FASTDDS_CONTENT_FILTER_PUBLISHER_APP_HPP_ + +#include + +#include +#include +#include + +#include "Application.hpp" +#include "CLIParser.hpp" +#include "HelloWorldPubSubTypes.h" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace content_filter { +class PublisherApp : public Application, public DataWriterListener +{ +public: + + PublisherApp( + const CLIParser::publisher_config& config, + const std::string& topic_name); + + ~PublisherApp(); + + //! Publisher matched method + void on_publication_matched( + DataWriter* writer, + const PublicationMatchedStatus& info) override; + + //! Run publisher + void run() override; + + //! Stop publisher + void stop() override; + +private: + + //! Return the current state of execution + bool is_stopped(); + + //! Publish a sample + bool publish(); + + HelloWorld hello_; + + DomainParticipant* participant_; + + Publisher* publisher_; + + Topic* topic_; + + DataWriter* writer_; + + TypeSupport type_; + + int16_t matched_; + + uint16_t samples_; + + std::mutex mutex_; + + std::condition_variable cv_; + + std::atomic stop_; + + uint16_t period_ms_ = 100; // in ms +}; + +} // namespace content_filter +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif // _FASTDDS_CONTENT_FILTER_PUBLISHER_APP_HPP_ diff --git a/examples/cpp/content_filter/README.md b/examples/cpp/content_filter/README.md new file mode 100644 index 00000000000..e53314d62ef --- /dev/null +++ b/examples/cpp/content_filter/README.md @@ -0,0 +1,143 @@ +# Content filter example + +The *eProsima Fast DDS content filter* example is a simple application intended to demonstrate how to use Content Filtered Topics. + +This example is part of the suite of examples designed by eProsima that aims to illustrate the features and possible configurations of DDS deployments through *eProsima Fast DDS*. + +In this case, the *content filter* example show how to use Content Filtered Topics by including two different Filter Factories: the default SQL filter and a custom filter defined in the example. + +* [Description of the example](#description-of-the-example) +* [Run the example](#run-the-example) + +## Description of the example + +Each example application (publisher and subscriber) creates different nested DDS entities: domain participant, publisher, and data writer; and domain participant, subscriber, and data reader, respectively. +In both cases, the three DDS entities (domain participant, publisher/subscriber and data writer/data reader) load their default configuration from the environment. + +Content filters can be applied on either the DataWriter's or the DataReader's side. The filter is defined on the DataReader side and during discovery, the DataWriter can retrieve the filter expression from the DataReader. Applying the filter on the writer side can reduce network bandwidth usage but may lead to higher CPU usage on the writer. + +This example shows how to define two different types of filter on DataReader side; i.e. the default SQL filter and a custom filter: + +* The default SQL filter is a default filter of Fast DDS, whose behaviour is defined by a filter expression, a string using a subset of SQL syntax. For further information regarding default SQL filters please refer to the [Default SQL-like filter](https://fast-dds.docs.eprosima.com/en/latest/fastdds/dds_layer/topic/contentFilteredTopic/defaultFilter.html#the-default-sql-like-filter) documentation. +The filter expression is passed as argument during the filter creation and, in this example, the user can set the expression through CLI. +The default expression is keeping only the messages with index between %0 and %1, where %0 and %1 are the indeces of the parameter list passed as argument during the filter creation. +In the example, they correspond to *lower_bound* and *upper_bound*. + +* The custom filter is defined in CustomContentFilter.hpp. It filters out all the messages whose index number is between *lower_bound* and *upper_bound*, keeping only the ones outside the defined range. For further information regarding fustom fontent filters please refer to the [Using custom filters](https://fast-dds.docs.eprosima.com/en/latest/fastdds/dds_layer/topic/contentFilteredTopic/customFilters.html#using-custom-filters) + +For both filters, the user can set the upper and lower bound of the range to filter through CLI with the arguments ``--lower-bound`` and ``--upper-bound``. +By default, *lower_bound* = 5 and *upper_bound* = 9. + +A DataWriter will take on the responsibility of filter evaluation instead of the DataReader when all the following criteria are met; otherwise, the DataReader will receive all the samples and then will filter them out: + +* The DataWriter has infinite liveliness, as defined by the LivelinessQosPolicy. + +* The communication between the DataWriter and the DataReader is neither intra-process nor involves data-sharing. + +* The DataReader is not utilizing multicast (`default_multicast_locator_list` is empty). + +* The number of DataReaders the DataWriter is filtering for does not exceed the limit set in the `reader_filters_allocation`. Setting a maximum value of 0 disables filter evaluation on the writer side. + +For further information regarding content filtering on writer side please refer to the [Conditions for writer side filtering](https://fast-dds.docs.eprosima.com/en/latest/fastdds/dds_layer/topic/contentFilteredTopic/writerFiltering.html#conditions-for-writer-side-filtering) + +By default, in this example, the filtering is performed on both DataReader and DataWriter side. + +## Run the example + +To launch this example, two different terminals are required. +One of them will run the publisher example application, and the other will run the subscriber application. + +### Content filter publisher + +* Ubuntu ( / MacOS ) + + ```shell + user@machine:example_path$ ./content_filter publisher + Publisher running. Please press Ctrl+C to stop the Publisher at any time. + ``` + +* Windows + + ```powershell + example_path> content_filter.exe publisher + Publisher running. Please press Ctrl+C to stop the Publisher at any time. + ``` + +### Content filter subscriber + +* Ubuntu ( / MacOS ) + + ```shell + user@machine:example_path$ ./content_filter subscriber + Subscriber running. Please press Ctrl+C to stop the Subscriber at any time. + ``` + +* Windows + + ```powershell + example_path> content_filter.exe subscriber + Subscriber running. Please press Ctrl+C to stop the Subscriber at any time. + ``` + +All the example available flags can be queried running the executable with the ``-h`` or ``--help`` flag. + +### Expected output + +Regardless of which application is run first, since the publisher will not start sending data until a subscriber is discovered, the expected output both for publishers and subscribers is a first displayed message acknowledging the match, followed by the amount of samples sent or received until Ctrl+C is pressed. + +### Content filter publisher + +```shell +user@machine:example_path$ ./content_filter publisher + +Publisher running. Please press Ctrl+C to stop the Publisher at any time. +Publisher matched. +Message: 'Hello world' with index: '1' SENT +Message: 'Hello world' with index: '2' SENT +Message: 'Hello world' with index: '3' SENT +... +``` + +### Content filter subscriber: default filter + +```shell +user@machine:example_path$ ./content_filter subscriber + +Subscriber running. Please press Ctrl+C to stop the Subscriber at any time. +Subscriber matched. +Message: 'Hello world' with index: '5' RECEIVED +Message: 'Hello world' with index: '6' RECEIVED +Message: 'Hello world' with index: '7' RECEIVED +Message: 'Hello world' with index: '8' RECEIVED +Message: 'Hello world' with index: '9' RECEIVED +``` + +### Content filter subscriber: default filter with expression + +```shell +user@machine:example_path$ ./content_filter subscriber --filter-expression "index > %0" -lb 7 + +Subscriber running. Please press Ctrl+C to stop the Subscriber at any time. +Subscriber matched. +Message: 'Hello world' with index: '8' RECEIVED +Message: 'Hello world' with index: '9' RECEIVED +Message: 'Hello world' with index: '10' RECEIVED +Message: 'Hello world' with index: '11' RECEIVED +... +``` + +### Content filter subscriber: custom filter + +```shell +user@machine:example_path$ ./content_filter subscriber --filter-kind custom + +Subscriber running. Please press Ctrl+C to stop the Subscriber at any time. +Subscriber matched. +Message: 'Hello world' with index: '1' RECEIVED +Message: 'Hello world' with index: '2' RECEIVED +Message: 'Hello world' with index: '3' RECEIVED +Message: 'Hello world' with index: '4' RECEIVED +Message: 'Hello world' with index: '10' RECEIVED +Message: 'Hello world' with index: '11' RECEIVED +... +``` diff --git a/examples/cpp/content_filter/SubscriberApp.cpp b/examples/cpp/content_filter/SubscriberApp.cpp new file mode 100644 index 00000000000..48f769659e5 --- /dev/null +++ b/examples/cpp/content_filter/SubscriberApp.cpp @@ -0,0 +1,232 @@ +// Copyright 2024 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 SubscriberApp.cpp + * + */ + +#include "SubscriberApp.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "HelloWorldTypeObjectSupport.hpp" + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace content_filter { +SubscriberApp::SubscriberApp( + const CLIParser::subscriber_config& config, + const std::string& topic_name) + : participant_(nullptr) + , subscriber_(nullptr) + , topic_(nullptr) + , reader_(nullptr) + , type_(new HelloWorldPubSubType()) + , filter_topic_(nullptr) + , stop_(false) +{ + // Set DomainParticipant name + DomainParticipantQos pqos; + pqos.name("Participant_sub"); + + // Get DomainParticipantFactory instance + auto factory = DomainParticipantFactory::get_instance(); + // Set intraprocess to OFF + LibrarySettings library_settings; + library_settings.intraprocess_delivery = IntraprocessDeliveryType::INTRAPROCESS_OFF; + factory->set_library_settings(library_settings); + pqos.transport().use_builtin_transports = false; + std::shared_ptr udp_descriptor = + std::make_shared(); + pqos.transport().user_transports.push_back(udp_descriptor); + + // Create DomainParticipant + participant_ = factory->create_participant(1, pqos); + if (participant_ == nullptr) + { + throw std::runtime_error("Participant initialization failed"); + } + + // If using the custom filter + if (config.filter_kind == CLIParser::FilterKind::CUSTOM) + { + // Register the filter factory + if (eprosima::fastdds::dds::RETCODE_OK != + participant_->register_content_filter_factory("CUSTOM_FILTER", &filter_factory)) + { + throw std::runtime_error("Custom filter initialization failed"); + } + } + + // Register the type + type_.register_type(participant_); + + // Create the Subscriber + subscriber_ = participant_->create_subscriber(SUBSCRIBER_QOS_DEFAULT, nullptr); + if (subscriber_ == nullptr) + { + throw std::runtime_error("Subscriber initialization failed"); + } + + // Create the Topic + topic_ = participant_->create_topic(topic_name, type_.get_type_name(), TOPIC_QOS_DEFAULT); + if (topic_ == nullptr) + { + throw std::runtime_error("Topic initialization failed"); + } + + // Create the ContentFilteredTopic + std::string expression; + std::vector parameters; + if (config.filter_kind == CLIParser::FilterKind::CUSTOM) + { + // Custom filter: reject samples where index > parameters[0] and index < parameters[1]. + // Custom filter does not use expression. However, an empty expression disables filtering, so some expression + // must be set. + expression = " "; + parameters.push_back(config.lower_bound); + parameters.push_back(config.upper_bound); + filter_topic_ = + participant_->create_contentfilteredtopic("HelloWorldFilteredTopic1", topic_, expression, parameters, + "CUSTOM_FILTER"); + } + else if (config.filter_kind == CLIParser::FilterKind::DEFAULT) + { + // Default filter: accept samples meeting the given expression: index between the two given parameters + expression = config.filter_expression; + parameters.push_back(config.lower_bound); + parameters.push_back(config.upper_bound); + filter_topic_ = + participant_->create_contentfilteredtopic("HelloWorldFilteredTopic1", topic_, expression, parameters); + } + else if (config.filter_kind == CLIParser::FilterKind::NONE) + { + // An empty expression disables filtering + expression = ""; + filter_topic_ = + participant_->create_contentfilteredtopic("HelloWorldFilteredTopic1", topic_, expression, parameters); + } + + if (filter_topic_ == nullptr) + { + throw std::runtime_error("Filter Topic initialization failed"); + } + + // Create the DataReader + DataReaderQos rqos = DATAREADER_QOS_DEFAULT; + rqos.data_sharing().off(); + // In order to receive all samples, DataReader is configured as RELIABLE and TRANSIENT_LOCAL (ensure reception even + // if DataReader matching is after DataWriter one) + if (config.reliable) + { + rqos.reliability().kind = RELIABLE_RELIABILITY_QOS; + } + if (config.transient_local) + { + rqos.durability().kind = TRANSIENT_LOCAL_DURABILITY_QOS; + } + reader_ = subscriber_->create_datareader(filter_topic_, rqos, this); + if (reader_ == nullptr) + { + throw std::runtime_error("Data Reader initialization failed"); + } +} + +SubscriberApp::~SubscriberApp() +{ + if (participant_ != nullptr) + { + // Delete DDS entities contained within the DomainParticipant + participant_->delete_contained_entities(); + // Delete DomainParticipant + DomainParticipantFactory::get_instance()->delete_participant(participant_); + } +} + +void SubscriberApp::on_subscription_matched( + DataReader*, + const SubscriptionMatchedStatus& info) +{ + // New remote DataWriter discovered + if (info.current_count_change == 1) + { + std::cout << "Subscriber matched." << std::endl; + } + // New remote DataWriter undiscovered + else if (info.current_count_change == -1) + { + std::cout << "Subscriber unmatched." << std::endl; + } + // Non-valid option + else + { + std::cout << info.current_count_change + << " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl; + } +} + +void SubscriberApp::on_data_available( + DataReader* reader) +{ + SampleInfo info; + // Take next sample from DataReader's history + while ((!is_stopped()) && (eprosima::fastdds::dds::RETCODE_OK == reader->take_next_sample(&hello_, &info))) + { + // Some samples only update the instance state. Only if it is a valid sample (with data) + if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) + { + samples_++; + // Print structure data + std::cout << "Message: '" << hello_.message() << "' with index: '" << hello_.index() + << "' RECEIVED" << std::endl; + } + } +} + +void SubscriberApp::run() +{ + std::unique_lock lck(terminate_cv_mtx_); + terminate_cv_.wait(lck, [&] + { + return is_stopped(); + }); +} + +bool SubscriberApp::is_stopped() +{ + return stop_.load(); +} + +void SubscriberApp::stop() +{ + stop_.store(true); + terminate_cv_.notify_all(); +} + +} // namespace content_filter +} // namespace examples +} // namespace fastdds +} // namespace eprosima diff --git a/examples/cpp/content_filter/SubscriberApp.hpp b/examples/cpp/content_filter/SubscriberApp.hpp new file mode 100644 index 00000000000..b90d5fc26fa --- /dev/null +++ b/examples/cpp/content_filter/SubscriberApp.hpp @@ -0,0 +1,110 @@ +// Copyright 2024 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 SubscriberApp.hpp + * + */ + +#ifndef _FASTDDS_CONTENT_FILTER_SUBSCRIBER_APP_HPP_ +#define _FASTDDS_CONTENT_FILTER_SUBSCRIBER_APP_HPP_ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Application.hpp" +#include "CLIParser.hpp" +#include "HelloWorldPubSubTypes.h" +#include "CustomContentFilterFactory.hpp" + +using namespace eprosima::fastdds::dds; +namespace eprosima { +namespace fastdds { +namespace examples { +namespace content_filter { +class SubscriberApp : public Application, public DataReaderListener +{ +public: + + //! Constructor + SubscriberApp( + const CLIParser::subscriber_config& config, + const std::string& topic_name); + + //! Destructor + ~SubscriberApp(); + + //! Subscription callback + void on_data_available( + DataReader* reader) override; + + //! Subscriber matched method + void on_subscription_matched( + DataReader* reader, + const SubscriptionMatchedStatus& info) override; + + //! Run subscriber + void run() override; + + //! Trigger the end of execution + void stop() override; + +private: + + //! Return the current state of execution + bool is_stopped(); + + HelloWorld hello_; + + DomainParticipant* participant_; + + Subscriber* subscriber_; + + Topic* topic_; + + DataReader* reader_; + + TypeSupport type_; + + uint16_t samples_; + + //! DDS ContentFilteredTopic pointer + ContentFilteredTopic* filter_topic_; + + //! Custom filter factory + CustomContentFilterFactory filter_factory; + + std::atomic stop_; + + mutable std::mutex terminate_cv_mtx_; + + std::condition_variable terminate_cv_; +}; + +} // namespace content_filter +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif // _FASTDDS_CONTENT_FILTER_SUBSCRIBER_APP_HPP_ diff --git a/examples/cpp/content_filter/main.cpp b/examples/cpp/content_filter/main.cpp new file mode 100644 index 00000000000..20becf69166 --- /dev/null +++ b/examples/cpp/content_filter/main.cpp @@ -0,0 +1,108 @@ +// Copyright 2024 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 main.cpp + * + */ + +#include +#include +#include + +#include +#include + +#include "Application.hpp" +#include "CLIParser.hpp" + +using namespace eprosima::fastdds::examples::content_filter; +using eprosima::fastdds::dds::Log; + +std::function stop_app_handler; +void signal_handler( + int signum) +{ + stop_app_handler(signum); +} + +int main( + int argc, + char** argv) +{ + auto ret = EXIT_SUCCESS; + const std::string topic_name = "content_filter_topic"; + CLIParser::content_filter_config config = CLIParser::parse_cli_options(argc, argv); + + // Initialize variables with default values + uint16_t samples = 0; + + switch (config.entity) + { + case CLIParser::EntityKind::PUBLISHER: + samples = config.pub_config.samples; + break; + default: + break; + } + + std::string app_name = CLIParser::parse_entity_kind(config.entity); + std::shared_ptr app; + + try + { + app = Application::make_app(config, topic_name); + } + catch (const std::runtime_error& e) + { + EPROSIMA_LOG_ERROR(app_name, e.what()); + ret = EXIT_FAILURE; + } + + if (EXIT_FAILURE != ret) + { + std::thread thread(&Application::run, app); + + if (samples == 0) + { + std::cout << app_name << " running. Please press Ctrl+C to stop the " + << app_name << " at any time." << std::endl; + } + else + { + std::cout << app_name << " running for " << samples << " samples. Please press Ctrl+C to stop the " + << app_name << " at any time." << std::endl; + } + + stop_app_handler = [&](int signum) + { + std::cout << "\n" << CLIParser::parse_signal(signum) << " received, stopping " << app_name + << " execution." << std::endl; + app->stop(); + }; + + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); + #ifndef _WIN32 + signal(SIGQUIT, signal_handler); + signal(SIGHUP, signal_handler); + #endif // _WIN32 + + thread.join(); + } + + // Flush Fast DDS Log before closing application + Log::Reset(); + return ret; +} diff --git a/examples/cpp/dds/AdvancedConfigurationExample/AdvancedConfigurationPubSubTypes.cxx b/examples/cpp/dds/AdvancedConfigurationExample/AdvancedConfigurationPubSubTypes.cxx deleted file mode 100644 index 1f39315124a..00000000000 --- a/examples/cpp/dds/AdvancedConfigurationExample/AdvancedConfigurationPubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// 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 AdvancedConfigurationPubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - -#include "AdvancedConfigurationPubSubTypes.h" - -#include -#include - -#include "AdvancedConfigurationCdrAux.hpp" -#include "AdvancedConfigurationTypeObjectSupport.hpp" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; -using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; - -AdvancedConfigurationPubSubType::AdvancedConfigurationPubSubType() -{ - setName("AdvancedConfiguration"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(AdvancedConfiguration::getMaxCdrSerializedSize()); -#else - AdvancedConfiguration_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = AdvancedConfiguration_max_key_cdr_typesize > 16 ? AdvancedConfiguration_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -AdvancedConfigurationPubSubType::~AdvancedConfigurationPubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool AdvancedConfigurationPubSubType::serialize( - void* data, - SerializedPayload_t* payload, - DataRepresentationId_t data_representation) -{ - AdvancedConfiguration* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool AdvancedConfigurationPubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - AdvancedConfiguration* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function AdvancedConfigurationPubSubType::getSerializedSizeProvider( - void* data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* AdvancedConfigurationPubSubType::createData() -{ - return reinterpret_cast(new AdvancedConfiguration()); -} - -void AdvancedConfigurationPubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool AdvancedConfigurationPubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - AdvancedConfiguration* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - AdvancedConfiguration_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || AdvancedConfiguration_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - 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; -} - -void AdvancedConfigurationPubSubType::register_type_object_representation() -{ - register_AdvancedConfiguration_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "AdvancedConfigurationCdrAux.ipp" diff --git a/examples/cpp/dds/AdvancedConfigurationExample/AdvancedConfigurationPubSubTypes.h b/examples/cpp/dds/AdvancedConfigurationExample/AdvancedConfigurationPubSubTypes.h deleted file mode 100644 index a34a56358e2..00000000000 --- a/examples/cpp/dds/AdvancedConfigurationExample/AdvancedConfigurationPubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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 AdvancedConfigurationPubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_ADVANCEDCONFIGURATION_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_ADVANCEDCONFIGURATION_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "AdvancedConfiguration.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated AdvancedConfiguration is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type AdvancedConfiguration defined by the user in the IDL file. - * @ingroup AdvancedConfiguration - */ -class AdvancedConfigurationPubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef AdvancedConfiguration type; - - eProsima_user_DllExport AdvancedConfigurationPubSubType(); - - eProsima_user_DllExport ~AdvancedConfigurationPubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_ADVANCEDCONFIGURATION_PUBSUBTYPES_H_ - diff --git a/examples/cpp/dds/AdvancedConfigurationExample/AdvancedConfigurationTypeObjectSupport.cxx b/examples/cpp/dds/AdvancedConfigurationExample/AdvancedConfigurationTypeObjectSupport.cxx deleted file mode 100644 index 1402c7ada5c..00000000000 --- a/examples/cpp/dds/AdvancedConfigurationExample/AdvancedConfigurationTypeObjectSupport.cxx +++ /dev/null @@ -1,226 +0,0 @@ -// 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 AdvancedConfigurationTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "AdvancedConfigurationTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "AdvancedConfiguration.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_AdvancedConfiguration_type_identifier( - TypeIdentifierPair& type_ids_AdvancedConfiguration) -{ - - ReturnCode_t return_code_AdvancedConfiguration {eprosima::fastdds::dds::RETCODE_OK}; - return_code_AdvancedConfiguration = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "AdvancedConfiguration", type_ids_AdvancedConfiguration); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_AdvancedConfiguration) - { - StructTypeFlag struct_flags_AdvancedConfiguration = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_AdvancedConfiguration = "AdvancedConfiguration"; - eprosima::fastcdr::optional type_ann_builtin_AdvancedConfiguration; - eprosima::fastcdr::optional ann_custom_AdvancedConfiguration; - CompleteTypeDetail detail_AdvancedConfiguration = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_AdvancedConfiguration, ann_custom_AdvancedConfiguration, type_name_AdvancedConfiguration.to_string()); - CompleteStructHeader header_AdvancedConfiguration; - header_AdvancedConfiguration = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_AdvancedConfiguration); - CompleteStructMemberSeq member_seq_AdvancedConfiguration; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_uint32_t", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_index = 0x00000000; - bool common_index_ec {false}; - CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; - if (!common_index_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); - return; - } - MemberName name_index = "index"; - eprosima::fastcdr::optional member_ann_builtin_index; - ann_custom_AdvancedConfiguration.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_AdvancedConfiguration); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_AdvancedConfiguration, member_index); - } - { - TypeIdentifierPair type_ids_message; - ReturnCode_t return_code_message {eprosima::fastdds::dds::RETCODE_OK}; - return_code_message = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "anonymous_array_char_20", type_ids_message); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_message) - { - return_code_message = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_char", type_ids_message); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_message) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "Array element TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - bool element_identifier_anonymous_array_char_20_ec {false}; - TypeIdentifier* element_identifier_anonymous_array_char_20 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, element_identifier_anonymous_array_char_20_ec))}; - if (!element_identifier_anonymous_array_char_20_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Array element TypeIdentifier inconsistent."); - return; - } - EquivalenceKind equiv_kind_anonymous_array_char_20 = EK_COMPLETE; - if (TK_NONE == type_ids_message.type_identifier2()._d()) - { - equiv_kind_anonymous_array_char_20 = EK_BOTH; - } - CollectionElementFlag element_flags_anonymous_array_char_20 = 0; - PlainCollectionHeader header_anonymous_array_char_20 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_array_char_20, element_flags_anonymous_array_char_20); - { - SBoundSeq array_bound_seq; - TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast(20)); - - PlainArraySElemDefn array_sdefn = TypeObjectUtils::build_plain_array_s_elem_defn(header_anonymous_array_char_20, array_bound_seq, - eprosima::fastcdr::external(element_identifier_anonymous_array_char_20)); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_s_array_type_identifier(array_sdefn, "anonymous_array_char_20", type_ids_message)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "anonymous_array_char_20 already registered in TypeObjectRegistry for a different type."); - } - } - } - StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_message = 0x00000001; - bool common_message_ec {false}; - CommonStructMember common_message {TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, common_message_ec))}; - if (!common_message_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure message member TypeIdentifier inconsistent."); - return; - } - MemberName name_message = "message"; - eprosima::fastcdr::optional member_ann_builtin_message; - ann_custom_AdvancedConfiguration.reset(); - CompleteMemberDetail detail_message = TypeObjectUtils::build_complete_member_detail(name_message, member_ann_builtin_message, ann_custom_AdvancedConfiguration); - CompleteStructMember member_message = TypeObjectUtils::build_complete_struct_member(common_message, detail_message); - TypeObjectUtils::add_complete_struct_member(member_seq_AdvancedConfiguration, member_message); - } - { - TypeIdentifierPair type_ids_data; - ReturnCode_t return_code_data {eprosima::fastdds::dds::RETCODE_OK}; - return_code_data = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "anonymous_sequence_uint8_t_unbounded", type_ids_data); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_data) - { - return_code_data = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_byte", type_ids_data); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_data) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "Sequence element TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - bool element_identifier_anonymous_sequence_uint8_t_unbounded_ec {false}; - TypeIdentifier* element_identifier_anonymous_sequence_uint8_t_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_data, element_identifier_anonymous_sequence_uint8_t_unbounded_ec))}; - if (!element_identifier_anonymous_sequence_uint8_t_unbounded_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Sequence element TypeIdentifier inconsistent."); - return; - } - EquivalenceKind equiv_kind_anonymous_sequence_uint8_t_unbounded = EK_COMPLETE; - if (TK_NONE == type_ids_data.type_identifier2()._d()) - { - equiv_kind_anonymous_sequence_uint8_t_unbounded = EK_BOTH; - } - CollectionElementFlag element_flags_anonymous_sequence_uint8_t_unbounded = 0; - PlainCollectionHeader header_anonymous_sequence_uint8_t_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_sequence_uint8_t_unbounded, element_flags_anonymous_sequence_uint8_t_unbounded); - { - SBound bound = 0; - PlainSequenceSElemDefn seq_sdefn = TypeObjectUtils::build_plain_sequence_s_elem_defn(header_anonymous_sequence_uint8_t_unbounded, bound, - eprosima::fastcdr::external(element_identifier_anonymous_sequence_uint8_t_unbounded)); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_s_sequence_type_identifier(seq_sdefn, "anonymous_sequence_uint8_t_unbounded", type_ids_data)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "anonymous_sequence_uint8_t_unbounded already registered in TypeObjectRegistry for a different type."); - } - } - } - StructMemberFlag member_flags_data = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_data = 0x00000002; - bool common_data_ec {false}; - CommonStructMember common_data {TypeObjectUtils::build_common_struct_member(member_id_data, member_flags_data, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_data, common_data_ec))}; - if (!common_data_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure data member TypeIdentifier inconsistent."); - return; - } - MemberName name_data = "data"; - eprosima::fastcdr::optional member_ann_builtin_data; - ann_custom_AdvancedConfiguration.reset(); - CompleteMemberDetail detail_data = TypeObjectUtils::build_complete_member_detail(name_data, member_ann_builtin_data, ann_custom_AdvancedConfiguration); - CompleteStructMember member_data = TypeObjectUtils::build_complete_struct_member(common_data, detail_data); - TypeObjectUtils::add_complete_struct_member(member_seq_AdvancedConfiguration, member_data); - } - CompleteStructType struct_type_AdvancedConfiguration = TypeObjectUtils::build_complete_struct_type(struct_flags_AdvancedConfiguration, header_AdvancedConfiguration, member_seq_AdvancedConfiguration); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_AdvancedConfiguration, type_name_AdvancedConfiguration.to_string(), type_ids_AdvancedConfiguration)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "AdvancedConfiguration already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/AdvancedConfigurationExample/AdvancedConfigurationTypeObjectSupport.hpp b/examples/cpp/dds/AdvancedConfigurationExample/AdvancedConfigurationTypeObjectSupport.hpp deleted file mode 100644 index 0766bc97e14..00000000000 --- a/examples/cpp/dds/AdvancedConfigurationExample/AdvancedConfigurationTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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 AdvancedConfigurationTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef _FAST_DDS_GENERATED_ADVANCEDCONFIGURATION_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_ADVANCEDCONFIGURATION_TYPE_OBJECT_SUPPORT_HPP_ - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register AdvancedConfiguration related TypeIdentifier. - * 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_AdvancedConfiguration_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // _FAST_DDS_GENERATED_ADVANCEDCONFIGURATION_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/examples/cpp/dds/BasicConfigurationExample/HelloWorldPubSubTypes.h b/examples/cpp/dds/BasicConfigurationExample/HelloWorldPubSubTypes.h deleted file mode 100644 index 4b09a679ee5..00000000000 --- a/examples/cpp/dds/BasicConfigurationExample/HelloWorldPubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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 fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_HELLOWORLD_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_HELLOWORLD_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "HelloWorld.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated HelloWorld is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type HelloWorld defined by the user in the IDL file. - * @ingroup HelloWorld - */ -class HelloWorldPubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef HelloWorld type; - - eProsima_user_DllExport HelloWorldPubSubType(); - - eProsima_user_DllExport ~HelloWorldPubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return true; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_HELLOWORLD_PUBSUBTYPES_H_ - diff --git a/examples/cpp/dds/BasicConfigurationExample/HelloWorldTypeObjectSupport.cxx b/examples/cpp/dds/BasicConfigurationExample/HelloWorldTypeObjectSupport.cxx deleted file mode 100644 index 83279c5d000..00000000000 --- a/examples/cpp/dds/BasicConfigurationExample/HelloWorldTypeObjectSupport.cxx +++ /dev/null @@ -1,164 +0,0 @@ -// 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 HelloWorldTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "HelloWorldTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "HelloWorld.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_HelloWorld_type_identifier( - TypeIdentifierPair& type_ids_HelloWorld) -{ - - ReturnCode_t return_code_HelloWorld {eprosima::fastdds::dds::RETCODE_OK}; - return_code_HelloWorld = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "HelloWorld", type_ids_HelloWorld); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_HelloWorld) - { - StructTypeFlag struct_flags_HelloWorld = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_HelloWorld = "HelloWorld"; - eprosima::fastcdr::optional type_ann_builtin_HelloWorld; - eprosima::fastcdr::optional ann_custom_HelloWorld; - CompleteTypeDetail detail_HelloWorld = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_HelloWorld, ann_custom_HelloWorld, type_name_HelloWorld.to_string()); - CompleteStructHeader header_HelloWorld; - header_HelloWorld = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_HelloWorld); - CompleteStructMemberSeq member_seq_HelloWorld; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_uint32_t", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_index = 0x00000000; - bool common_index_ec {false}; - CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; - if (!common_index_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); - return; - } - MemberName name_index = "index"; - eprosima::fastcdr::optional member_ann_builtin_index; - ann_custom_HelloWorld.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_HelloWorld); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_HelloWorld, member_index); - } - { - TypeIdentifierPair type_ids_message; - ReturnCode_t return_code_message {eprosima::fastdds::dds::RETCODE_OK}; - return_code_message = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "anonymous_array_char_20", type_ids_message); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_message) - { - return_code_message = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_char", type_ids_message); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_message) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "Array element TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - bool element_identifier_anonymous_array_char_20_ec {false}; - TypeIdentifier* element_identifier_anonymous_array_char_20 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, element_identifier_anonymous_array_char_20_ec))}; - if (!element_identifier_anonymous_array_char_20_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Array element TypeIdentifier inconsistent."); - return; - } - EquivalenceKind equiv_kind_anonymous_array_char_20 = EK_COMPLETE; - if (TK_NONE == type_ids_message.type_identifier2()._d()) - { - equiv_kind_anonymous_array_char_20 = EK_BOTH; - } - CollectionElementFlag element_flags_anonymous_array_char_20 = 0; - PlainCollectionHeader header_anonymous_array_char_20 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_array_char_20, element_flags_anonymous_array_char_20); - { - SBoundSeq array_bound_seq; - TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast(20)); - - PlainArraySElemDefn array_sdefn = TypeObjectUtils::build_plain_array_s_elem_defn(header_anonymous_array_char_20, array_bound_seq, - eprosima::fastcdr::external(element_identifier_anonymous_array_char_20)); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_s_array_type_identifier(array_sdefn, "anonymous_array_char_20", type_ids_message)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "anonymous_array_char_20 already registered in TypeObjectRegistry for a different type."); - } - } - } - StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_message = 0x00000001; - bool common_message_ec {false}; - CommonStructMember common_message {TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, common_message_ec))}; - if (!common_message_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure message member TypeIdentifier inconsistent."); - return; - } - MemberName name_message = "message"; - eprosima::fastcdr::optional member_ann_builtin_message; - ann_custom_HelloWorld.reset(); - CompleteMemberDetail detail_message = TypeObjectUtils::build_complete_member_detail(name_message, member_ann_builtin_message, ann_custom_HelloWorld); - CompleteStructMember member_message = TypeObjectUtils::build_complete_struct_member(common_message, detail_message); - TypeObjectUtils::add_complete_struct_member(member_seq_HelloWorld, member_message); - } - CompleteStructType struct_type_HelloWorld = TypeObjectUtils::build_complete_struct_type(struct_flags_HelloWorld, header_HelloWorld, member_seq_HelloWorld); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_HelloWorld, type_name_HelloWorld.to_string(), type_ids_HelloWorld)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "HelloWorld already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/CMakeLists.txt b/examples/cpp/dds/CMakeLists.txt index f0dc65eec91..8585624b003 100644 --- a/examples/cpp/dds/CMakeLists.txt +++ b/examples/cpp/dds/CMakeLists.txt @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -add_subdirectory(ContentFilteredTopicExample) add_subdirectory(DiscoveryServerExample) add_subdirectory(DynamicHelloWorldExample) add_subdirectory(FlowControlExample) diff --git a/examples/cpp/dds/Configurability/samplePubSubTypes.cxx b/examples/cpp/dds/Configurability/samplePubSubTypes.cxx deleted file mode 100644 index 321f250d975..00000000000 --- a/examples/cpp/dds/Configurability/samplePubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// 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 samplePubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - -#include "samplePubSubTypes.h" - -#include -#include - -#include "sampleCdrAux.hpp" -#include "sampleTypeObjectSupport.hpp" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; -using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; - -samplePubSubType::samplePubSubType() -{ - setName("sample"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(sample::getMaxCdrSerializedSize()); -#else - sample_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = true; - uint32_t keyLength = sample_max_key_cdr_typesize > 16 ? sample_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -samplePubSubType::~samplePubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool samplePubSubType::serialize( - void* data, - SerializedPayload_t* payload, - DataRepresentationId_t data_representation) -{ - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool samplePubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function samplePubSubType::getSerializedSizeProvider( - void* data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* samplePubSubType::createData() -{ - return reinterpret_cast(new sample()); -} - -void samplePubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool samplePubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - sample_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || sample_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - 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; -} - -void samplePubSubType::register_type_object_representation() -{ - register_sample_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "sampleCdrAux.ipp" diff --git a/examples/cpp/dds/Configurability/samplePubSubTypes.h b/examples/cpp/dds/Configurability/samplePubSubTypes.h deleted file mode 100644 index 1ec6375ba7f..00000000000 --- a/examples/cpp/dds/Configurability/samplePubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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 samplePubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "sample.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated sample is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type sample defined by the user in the IDL file. - * @ingroup sample - */ -class samplePubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef sample type; - - eProsima_user_DllExport samplePubSubType(); - - eProsima_user_DllExport ~samplePubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return true; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ - diff --git a/examples/cpp/dds/Configurability/sampleTypeObjectSupport.cxx b/examples/cpp/dds/Configurability/sampleTypeObjectSupport.cxx deleted file mode 100644 index e9dcd1a977b..00000000000 --- a/examples/cpp/dds/Configurability/sampleTypeObjectSupport.cxx +++ /dev/null @@ -1,143 +0,0 @@ -// 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 sampleTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "sampleTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "sample.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_sample_type_identifier( - TypeIdentifierPair& type_ids_sample) -{ - - ReturnCode_t return_code_sample {eprosima::fastdds::dds::RETCODE_OK}; - return_code_sample = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "sample", type_ids_sample); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_sample) - { - StructTypeFlag struct_flags_sample = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_sample = "sample"; - eprosima::fastcdr::optional type_ann_builtin_sample; - eprosima::fastcdr::optional ann_custom_sample; - CompleteTypeDetail detail_sample = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_sample, ann_custom_sample, type_name_sample.to_string()); - CompleteStructHeader header_sample; - header_sample = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_sample); - CompleteStructMemberSeq member_seq_sample; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_byte", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_index = 0x00000000; - bool common_index_ec {false}; - CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; - if (!common_index_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); - return; - } - MemberName name_index = "index"; - eprosima::fastcdr::optional member_ann_builtin_index; - ann_custom_sample.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_sample); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_sample, member_index); - } - { - TypeIdentifierPair type_ids_key_value; - ReturnCode_t return_code_key_value {eprosima::fastdds::dds::RETCODE_OK}; - return_code_key_value = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_byte", type_ids_key_value); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_key_value) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "key_value Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_key_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, true, false); - MemberId member_id_key_value = 0x00000001; - bool common_key_value_ec {false}; - CommonStructMember common_key_value {TypeObjectUtils::build_common_struct_member(member_id_key_value, member_flags_key_value, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_key_value, common_key_value_ec))}; - if (!common_key_value_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure key_value member TypeIdentifier inconsistent."); - return; - } - MemberName name_key_value = "key_value"; - eprosima::fastcdr::optional member_ann_builtin_key_value; - ann_custom_sample.reset(); - AppliedAnnotationSeq tmp_ann_custom_key_value; - eprosima::fastcdr::optional unit_key_value; - eprosima::fastcdr::optional min_key_value; - eprosima::fastcdr::optional max_key_value; - eprosima::fastcdr::optional hash_id_key_value; - if (unit_key_value.has_value() || min_key_value.has_value() || max_key_value.has_value() || hash_id_key_value.has_value()) - { - member_ann_builtin_key_value = TypeObjectUtils::build_applied_builtin_member_annotations(unit_key_value, min_key_value, max_key_value, hash_id_key_value); - } - if (!tmp_ann_custom_key_value.empty()) - { - ann_custom_sample = tmp_ann_custom_key_value; - } - CompleteMemberDetail detail_key_value = TypeObjectUtils::build_complete_member_detail(name_key_value, member_ann_builtin_key_value, ann_custom_sample); - CompleteStructMember member_key_value = TypeObjectUtils::build_complete_struct_member(common_key_value, detail_key_value); - TypeObjectUtils::add_complete_struct_member(member_seq_sample, member_key_value); - } - CompleteStructType struct_type_sample = TypeObjectUtils::build_complete_struct_type(struct_flags_sample, header_sample, member_seq_sample); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_sample, type_name_sample.to_string(), type_ids_sample)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "sample already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/Configurability/sampleTypeObjectSupport.hpp b/examples/cpp/dds/Configurability/sampleTypeObjectSupport.hpp deleted file mode 100644 index 013609fa263..00000000000 --- a/examples/cpp/dds/Configurability/sampleTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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 sampleTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register sample related TypeIdentifier. - * 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_sample_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExamplePublisher.cpp b/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExamplePublisher.cpp deleted file mode 100644 index 77e35423bce..00000000000 --- a/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExamplePublisher.cpp +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright 2022 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 ContentFilteredTopicExamplePublisher.cpp - * - */ - -#include "ContentFilteredTopicExamplePublisher.hpp" - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "HelloWorldTypeObjectSupport.hpp" - -using namespace eprosima::fastdds::dds; - -bool ContentFilteredTopicExamplePublisher::init() -{ - // Initialize internal variables - matched_ = 0; - - // Initialize data sample - hello_.index(0); - hello_.message("HelloWorld"); - - // Set DomainParticipant name - DomainParticipantQos pqos; - pqos.name("Participant_pub"); - // Create DomainParticipant in domain 0 - participant_ = DomainParticipantFactory::get_instance()->create_participant(0, pqos); - if (nullptr == participant_) - { - return false; - } - - // Register the type - type_.register_type(participant_); - - // Create the Publisher - publisher_ = participant_->create_publisher(PUBLISHER_QOS_DEFAULT, nullptr); - if (nullptr == publisher_) - { - return false; - } - - // Create the Topic - topic_ = participant_->create_topic("HelloWorldTopic", type_->getName(), TOPIC_QOS_DEFAULT); - if (nullptr == topic_) - { - return false; - } - - // Create the DataWriter - writer_ = publisher_->create_datawriter(topic_, DATAWRITER_QOS_DEFAULT, this); - if (nullptr == writer_) - { - return false; - } - return true; -} - -ContentFilteredTopicExamplePublisher::~ContentFilteredTopicExamplePublisher() -{ - // Delete DDS entities contained within the DomainParticipant - participant_->delete_contained_entities(); - // Delete DomainParticipant - DomainParticipantFactory::get_instance()->delete_participant(participant_); -} - -void ContentFilteredTopicExamplePublisher::on_publication_matched( - DataWriter*, - const PublicationMatchedStatus& info) -{ - // New remote DataReader discovered - if (info.current_count_change == 1) - { - matched_ = info.current_count; - first_connected_ = true; - std::cout << "Publisher matched." << std::endl; - } - // New remote DataReader undiscovered - else if (info.current_count_change == -1) - { - matched_ = info.current_count; - std::cout << "Publisher unmatched." << std::endl; - } - // Non-valid option - else - { - std::cout << info.current_count_change - << " is not a valid value for PublicationMatchedStatus current count change" << std::endl; - } -} - -void ContentFilteredTopicExamplePublisher::runThread( - uint32_t samples, - uint32_t sleep) -{ - // Publish samples continously until stopped by the user - if (samples == 0) - { - while (!stop_) - { - if (publish(false)) - { - std::cout << "Message: " << hello_.message() << " with index: " << hello_.index() - << " SENT" << std::endl; - } - std::this_thread::sleep_for(std::chrono::milliseconds(sleep)); - } - } - // Publish given number of samples - else - { - for (uint32_t i = 0; i < samples; ++i) - { - if (!publish()) - { - --i; - } - else - { - std::cout << "Message: " << hello_.message() << " with index: " << hello_.index() - << " SENT" << std::endl; - } - std::this_thread::sleep_for(std::chrono::milliseconds(sleep)); - } - } -} - -void ContentFilteredTopicExamplePublisher::run( - uint32_t samples, - uint32_t sleep) -{ - // Spawn publisher application thread - stop_ = false; - std::thread thread(&ContentFilteredTopicExamplePublisher::runThread, this, samples, sleep); - // Thread runs indefinitely until stopped by the user - if (samples == 0) - { - std::cout << "Publisher running. Please press enter to stop the Publisher at any time." << std::endl; - std::cin.ignore(); - stop_ = true; - } - // Thread runs only for the given samples - else - { - std::cout << "Publisher running " << samples << " samples." << std::endl; - } - thread.join(); -} - -bool ContentFilteredTopicExamplePublisher::publish( - bool wait_for_listener) -{ - // Wait until there is a matched DataReader, unless wait_for_listener flag is set to false - if (first_connected_ || !wait_for_listener || matched_ > 0) - { - // Update sample - hello_.index(hello_.index() + 1); - // Write sample - writer_->write(&hello_); - return true; - } - return false; -} diff --git a/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExamplePublisher.hpp b/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExamplePublisher.hpp deleted file mode 100644 index ff076dbb364..00000000000 --- a/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExamplePublisher.hpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2022 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 ContentFilteredTopicExamplePublisher.hpp - * - */ - -#ifndef _CONTENTFILTEREDTOPICEXAMPLEPUBLISHER_H_ -#define _CONTENTFILTEREDTOPICEXAMPLEPUBLISHER_H_ - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "HelloWorldPubSubTypes.h" - -//! Publisher application class -class ContentFilteredTopicExamplePublisher : public eprosima::fastdds::dds::DataWriterListener -{ -public: - - //! Constructor - ContentFilteredTopicExamplePublisher() = default; - - //! Destructor - virtual ~ContentFilteredTopicExamplePublisher(); - - //! Initialize - bool init(); - - //! Publish a sample - bool publish( - bool wait_for_listener = true); - - //! Run for the given number of samples (0 => infinite samples) - void run( - uint32_t number, - uint32_t sleep); - -private: - - //! Data type - HelloWorld hello_; - - //! DDS DomainParticipant pointer - eprosima::fastdds::dds::DomainParticipant* participant_ = nullptr; - - //! DDS Publisher pointer - eprosima::fastdds::dds::Publisher* publisher_ = nullptr; - - //! DDS Topic pointer - eprosima::fastdds::dds::Topic* topic_ = nullptr; - - //! DDS DataWriter pointer - eprosima::fastdds::dds::DataWriter* writer_ = nullptr; - - //! DDS TypeSupport pointer - eprosima::fastdds::dds::TypeSupport type_ = eprosima::fastdds::dds::TypeSupport(new HelloWorldPubSubType()); - - //! Flag to terminate application - std::atomic stop_; - - //! Number of DataReaders matched with the publisher application - std::atomic matched_; - - //! Flag set once the first subscriber is discovered and matched - std::atomic first_connected_; - - //! Discovery callback specialization when the DataWriter received discovery information from a remote DataReader - void on_publication_matched( - eprosima::fastdds::dds::DataWriter* writer, - const eprosima::fastdds::dds::PublicationMatchedStatus& info) override; - - //! Publisher application thread - void runThread( - uint32_t number, - uint32_t sleep); - -}; - -#endif // _CONTENTFILTEREDTOPICEXAMPLEPUBLISHER_H_ diff --git a/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExampleSubscriber.cpp b/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExampleSubscriber.cpp deleted file mode 100644 index b116074dfe4..00000000000 --- a/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExampleSubscriber.cpp +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright 2022 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 ContentFilteredTopicExampleSubscriber.cpp - * - */ - -#include "ContentFilteredTopicExampleSubscriber.hpp" - -#include -#include -#include -#include -#include -#include -#include - -#include "HelloWorldTypeObjectSupport.hpp" - -using namespace eprosima::fastdds::dds; - -bool ContentFilteredTopicExampleSubscriber::init( - bool custom_filter) -{ - // Initialize internal variables - matched_ = 0; - - // Set DomainParticipant name - DomainParticipantQos pqos; - pqos.name("Participant_sub"); - // Create DomainParticipant - participant_ = DomainParticipantFactory::get_instance()->create_participant(0, pqos); - if (nullptr == participant_) - { - return false; - } - - // If using the custom filter - if (custom_filter) - { - // Register the filter factory - if (eprosima::fastdds::dds::RETCODE_OK != - participant_->register_content_filter_factory("MY_CUSTOM_FILTER", &filter_factory)) - { - return false; - } - } - - // Register the type - type_.register_type(participant_); - - // Create the Subscriber - subscriber_ = participant_->create_subscriber(SUBSCRIBER_QOS_DEFAULT, nullptr); - if (nullptr == subscriber_) - { - return false; - } - - // Create the Topic - topic_ = participant_->create_topic("HelloWorldTopic", type_->getName(), TOPIC_QOS_DEFAULT); - if (nullptr == topic_) - { - return false; - } - - // Create the ContentFilteredTopic - std::string expression; - std::vector parameters; - if (custom_filter) - { - // Custom filter: reject samples where index > parameters[0] and index < parameters[1]. - // Custom filter does not use expression. However, an empty expression disables filtering, so some expression - // must be set. - expression = " "; - parameters.push_back("3"); - parameters.push_back("5"); - filter_topic_ = - participant_->create_contentfilteredtopic("HelloWorldFilteredTopic1", topic_, expression, parameters, - "MY_CUSTOM_FILTER"); - } - else - { - // Default filter: accept samples meeting the given expression: index between the two given parameters - expression = "index between %0 and %1"; - parameters.push_back("5"); - parameters.push_back("9"); - filter_topic_ = - participant_->create_contentfilteredtopic("HelloWorldFilteredTopic1", topic_, expression, parameters); - } - if (nullptr == filter_topic_) - { - return false; - } - - // Create the DataReader - DataReaderQos rqos = DATAREADER_QOS_DEFAULT; - // In order to receive all samples, DataReader is configured as RELIABLE and TRANSIENT_LOCAL (ensure reception even - // if DataReader matching is after DataWriter one) - rqos.reliability().kind = RELIABLE_RELIABILITY_QOS; - rqos.durability().kind = TRANSIENT_LOCAL_DURABILITY_QOS; - reader_ = subscriber_->create_datareader(filter_topic_, rqos, this); - if (nullptr == reader_) - { - return false; - } - return true; -} - -ContentFilteredTopicExampleSubscriber::~ContentFilteredTopicExampleSubscriber() -{ - // Delete DDS entities contained within the DomainParticipant - participant_->delete_contained_entities(); - // Delete DomainParticipant - DomainParticipantFactory::get_instance()->delete_participant(participant_); -} - -void ContentFilteredTopicExampleSubscriber::on_subscription_matched( - DataReader*, - const SubscriptionMatchedStatus& info) -{ - // New remote DataWriter discovered - if (info.current_count_change == 1) - { - matched_ = info.current_count; - std::cout << "Subscriber matched." << std::endl; - } - // New remote DataWriter undiscovered - else if (info.current_count_change == -1) - { - matched_ = info.current_count; - std::cout << "Subscriber unmatched." << std::endl; - } - // Non-valid option - else - { - std::cout << info.current_count_change - << " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl; - } -} - -void ContentFilteredTopicExampleSubscriber::on_data_available( - DataReader* reader) -{ - SampleInfo info; - // Take next sample from DataReader's history - if (eprosima::fastdds::dds::RETCODE_OK == reader->take_next_sample(&hello_, &info)) - { - // Some samples only update the instance state. Only if it is a valid sample (with data) - if (ALIVE_INSTANCE_STATE == info.instance_state) - { - samples_++; - // Print structure data - std::cout << "Message " << hello_.message() << " " << hello_.index() << " RECEIVED" << std::endl; - } - } -} - -void ContentFilteredTopicExampleSubscriber::run() -{ - // Subscriber application thread running until stopped by the user - std::cout << "Subscriber running. Please press enter to stop the Subscriber" << std::endl; - std::cin.ignore(); -} diff --git a/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExampleSubscriber.hpp b/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExampleSubscriber.hpp deleted file mode 100644 index 1876fe94296..00000000000 --- a/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExampleSubscriber.hpp +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2022 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 ContentFilteredTopicExampleSubscriber.hpp - * - */ - -#ifndef _CONTENTFILTEREDTOPICEXAMPLESUBSCRIBER_HPP_ -#define _CONTENTFILTEREDTOPICEXAMPLESUBSCRIBER_HPP_ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "HelloWorldPubSubTypes.h" -#include "MyCustomFilterFactory.hpp" - -// Subscriber application class -class ContentFilteredTopicExampleSubscriber : public eprosima::fastdds::dds::DataReaderListener -{ -public: - - //! Constructor - ContentFilteredTopicExampleSubscriber() = default; - - //! Destructor - virtual ~ContentFilteredTopicExampleSubscriber(); - - /** - * @brief Initialize the subscriber - * - * @param custom_filter Whether the default SQL filter or the custom defined filter is used. - * By default the SQL filter is used. - * @return true if correctly initialized. - * @return false otherwise. - */ - bool init( - bool custom_filter = false); - - //! Run the subscriber application - void run(); - -private: - - //! DDS DomainParticipant pointer - eprosima::fastdds::dds::DomainParticipant* participant_ = nullptr; - - //! DDS Subscriber pointer - eprosima::fastdds::dds::Subscriber* subscriber_ = nullptr; - - //! DDS Topic pointer - eprosima::fastdds::dds::Topic* topic_ = nullptr; - - //! DDS ContentFilteredTopic pointer - eprosima::fastdds::dds::ContentFilteredTopic* filter_topic_ = nullptr; - - //! DDS DataReader pointer - eprosima::fastdds::dds::DataReader* reader_ = nullptr; - - //! DDS TypeSupport pointer - eprosima::fastdds::dds::TypeSupport type_ = eprosima::fastdds::dds::TypeSupport(new HelloWorldPubSubType()); - - //! Custom filter factory - MyCustomFilterFactory filter_factory; - - //! Data type - HelloWorld hello_; - - //! Number of DataWriters matched with the subscriber application - std::atomic matched_; - - //! Number of received samples - uint32_t samples_ = 0; - - //! Callback specialization when data is notified to the DataReader - void on_data_available( - eprosima::fastdds::dds::DataReader* reader) override; - - //! Discovery callback specialization when the DataReader receives discovery information from a remote DataWriter - void on_subscription_matched( - eprosima::fastdds::dds::DataReader* reader, - const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) override; - -}; - -#endif // _CONTENTFILTEREDTOPICEXAMPLESUBSCRIBER_HPP_ diff --git a/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExample_main.cpp b/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExample_main.cpp deleted file mode 100644 index 06881a6775d..00000000000 --- a/examples/cpp/dds/ContentFilteredTopicExample/ContentFilteredTopicExample_main.cpp +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright 2022 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 CustomFilter_main.cpp - * - */ - -#include - -#include -#include - -#include "ContentFilteredTopicExamplePublisher.hpp" -#include "ContentFilteredTopicExampleSubscriber.hpp" - -using eprosima::fastdds::dds::Log; -namespace option = eprosima::option; - -// Argument checkers -struct Arg : public option::Arg -{ - // Auxiliary method for printing errors while checking arguments - static void print_error( - const char* msg1, - const option::Option& opt, - const char* msg2) - { - fprintf(stderr, "%s", msg1); - fwrite(opt.name, opt.namelen, 1, stderr); - fprintf(stderr, "%s", msg2); - } - - // Argument checker for numeric options - static option::ArgStatus Numeric( - const option::Option& option, - bool msg) - { - char* endptr = 0; - if (nullptr != option.arg) - { - strtol(option.arg, &endptr, 10); - if (endptr != option.arg && *endptr == 0) - { - return option::ARG_OK; - } - } - if (msg) - { - print_error("Option '", option, "' requires a numeric argument\n"); - } - return option::ARG_ILLEGAL; - } - - // Argument checker for string options - static option::ArgStatus String( - const option::Option& option, - bool msg) - { - if (nullptr != option.arg) - { - return option::ARG_OK; - } - if (msg) - { - print_error("Option '", option, "' requires a string argument\n"); - } - return option::ARG_ILLEGAL; - } - -}; - -// Possible options -enum optionIndex -{ - UNKNOWN_OPTION, - HELP, - PUBLISHER, - SUBSCRIBER, - SAMPLES, - INTERVAL, - FILTER -}; - -// Usage description -const option::Descriptor usage[] = { - { UNKNOWN_OPTION, 0, "", "", Arg::None, - "Usage: ContentFilteredTopicExample [--publisher|--subscriber] [OPTIONS]\n\nGeneral options:" }, - { HELP, 0, "h", "help", Arg::None, " -h\t--help\tProduce help message." }, - { PUBLISHER, 0, "", "publisher", Arg::None, "\t--publisher\tLaunch publisher application." }, - { SUBSCRIBER, 0, "", "subscriber", Arg::None, "\t--subscriber\tLaunch subscriber application." }, - - { UNKNOWN_OPTION, 0, "", "", Arg::None, "\nPublisher options:" }, - { SAMPLES, 0, "s", "samples", Arg::Numeric, - " -s \t--samples=\tNumber of samples (Default: 0 => infinite samples)." }, - { INTERVAL, 0, "i", "interval", Arg::Numeric, - " -i \t--interval=\tTime between samples in milliseconds (Default: 100 ms)." }, - - { UNKNOWN_OPTION, 0, "", "", Arg::None, "\nSubscriber options:" }, - { FILTER, 0, "f", "filter", Arg::String, - " -f \t--filter=\tKind of Content Filter to use (Default: DDS SQL default filter" - }, - - { 0, 0, 0, 0, 0, 0 } -}; - -int main( - int argc, - char** argv) -{ - // Parse arguments using optionparser - // skip program name argv[0] if present (optionparser limitation) - argc -= (argc > 0); - argv += (argc > 0); - option::Stats stats(usage, argc, argv); - std::vector options(stats.options_max); - std::vector buffer(stats.buffer_max); - option::Parser parse(usage, argc, argv, &options[0], &buffer[0]); - if (parse.error()) - { - return 1; - } - - // If help option selected, print usage description and exit - if (options[HELP]) - { - option::printUsage(fwrite, stdout, usage); - return 0; - } - // If option is not recognized, print usage description and exit with error code - else if (options[UNKNOWN_OPTION]) - { - std::cerr << "ERROR: " << options[UNKNOWN_OPTION].name << " is not a valid argument." << std::endl; - option::printUsage(fwrite, stdout, usage); - return 1; - } - - // Initialize variables with default values - int type = 1; - int count = 0; - int sleep = 100; - bool custom_filter = false; - // If both publisher and subscriber options are selected, print usage description and exit with error code - if (options[PUBLISHER] && options[SUBSCRIBER]) - { - std::cerr << "ERROR: select either '--publisher' or '--subscriber' option" << std::endl; - option::printUsage(fwrite, stdout, usage); - return 1; - } - // Publisher option selected - else if (options[PUBLISHER]) - { - // If any subscriber option is selected, print usage description and exit with error code - if (options[FILTER]) - { - std::cerr << "ERROR: option filter is a subscriber option" << std::endl; - option::printUsage(fwrite, stdout, usage); - return 1; - } - // If any optional publisher option is selected, set the corresponding value - if (options[SAMPLES]) - { - count = strtol(options[SAMPLES].arg, nullptr, 10); - } - if (options[INTERVAL]) - { - sleep = strtol(options[INTERVAL].arg, nullptr, 10); - } - } - // Subscriber option selected - else if (options[SUBSCRIBER]) - { - type = 2; - // If any publisher option is selected, print usage description and exit with error code - if (options[SAMPLES] || options[INTERVAL]) - { - std::cerr << "ERROR: options samples and interval are publisher options" << std::endl; - option::printUsage(fwrite, stdout, usage); - return 1; - } - // If any optional subscriber option is selected, set the corresponding value - if (options[FILTER]) - { - if (0 == strcmp(options[FILTER].arg, "custom")) - { - custom_filter = true; - } - // If filter option does not have one of the expected values, print usage description and exit with error - // code - else if (0 != strcmp(options[FILTER].arg, "default")) - { - std::cerr << "ERROR: filter option should be either 'custom' or 'default'" << std::endl; - option::printUsage(fwrite, stdout, usage); - return 1; - } - } - } - // If no publisher or subscriber option has been selected, print usage description and exit with error code - else - { - std::cerr << "ERROR: select either '--publisher' or '--subscriber' option" << std::endl; - option::printUsage(fwrite, stdout, usage); - return 1; - } - - switch (type) - { - case 1: - { - // Initialize and run publisher application - ContentFilteredTopicExamplePublisher mypub; - if (mypub.init()) - { - mypub.run(static_cast(count), static_cast(sleep)); - } - break; - } - case 2: - { - // Initialize and run subscriber application - ContentFilteredTopicExampleSubscriber mysub; - if (mysub.init(custom_filter)) - { - mysub.run(); - } - break; - } - } - // Flush Fast DDS Log before closing application - Log::Reset(); - return 0; -} diff --git a/examples/cpp/dds/ContentFilteredTopicExample/HelloWorldPubSubTypes.cxx b/examples/cpp/dds/ContentFilteredTopicExample/HelloWorldPubSubTypes.cxx deleted file mode 100644 index aa161b2e163..00000000000 --- a/examples/cpp/dds/ContentFilteredTopicExample/HelloWorldPubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// 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 fastddsgen. - */ - -#include "HelloWorldPubSubTypes.h" - -#include -#include - -#include "HelloWorldCdrAux.hpp" -#include "HelloWorldTypeObjectSupport.hpp" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; -using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; - -HelloWorldPubSubType::HelloWorldPubSubType() -{ - setName("HelloWorld"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(HelloWorld::getMaxCdrSerializedSize()); -#else - HelloWorld_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = HelloWorld_max_key_cdr_typesize > 16 ? HelloWorld_max_key_cdr_typesize : 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, - DataRepresentationId_t data_representation) -{ - HelloWorld* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool HelloWorldPubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - HelloWorld* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function HelloWorldPubSubType::getSerializedSizeProvider( - void* data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -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); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - HelloWorld_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || HelloWorld_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - 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; -} - -void HelloWorldPubSubType::register_type_object_representation() -{ - register_HelloWorld_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "HelloWorldCdrAux.ipp" diff --git a/examples/cpp/dds/ContentFilteredTopicExample/HelloWorldTypeObjectSupport.hpp b/examples/cpp/dds/ContentFilteredTopicExample/HelloWorldTypeObjectSupport.hpp deleted file mode 100644 index 2eba797b07f..00000000000 --- a/examples/cpp/dds/ContentFilteredTopicExample/HelloWorldTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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 HelloWorldTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef _FAST_DDS_GENERATED_HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP_ - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register HelloWorld related TypeIdentifier. - * 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_HelloWorld_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // _FAST_DDS_GENERATED_HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/examples/cpp/dds/ContentFilteredTopicExample/README.md b/examples/cpp/dds/ContentFilteredTopicExample/README.md deleted file mode 100644 index d60e9ece821..00000000000 --- a/examples/cpp/dds/ContentFilteredTopicExample/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# Content Filtered Topic Example - -This example extends the HelloWorld example to show how to use Content Filtered Topics. -It does so by including two different Filter Factories: on the one hand, the default SQL filter; on the other hand, a custom filter defined in the example. - -## Execution instructions (Linux platform) - -To launch this example, open three different terminals: - -In the first one, launch the Subscriber using the default SQL filter: - -``` -./DDSContentFilteredTopicExample --subscriber -``` - -In the second one, launch the Subscriber using the custom filter: - -``` -./DDSContentFilteredTopicExample --subscriber -f custom -``` - -Finally, in the third terminal launch the Publisher: - -``` -./DDSContentFilteredTopicExample --publisher -``` - -The Subscriber with the default filter should received only the samples between indexes 5 and 9, while the Subscriber with the custom filter should received samples which index is lower than 3 or greater than 5. - -In order to know further possible arguments please run: - -``` -./DDSContentFilteredTopicExample --help -``` diff --git a/examples/cpp/dds/CustomListenerExample/TopicPubSubTypes.cxx b/examples/cpp/dds/CustomListenerExample/TopicPubSubTypes.cxx deleted file mode 100644 index 70697eb1c1d..00000000000 --- a/examples/cpp/dds/CustomListenerExample/TopicPubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// 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 TopicPubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - -#include "TopicPubSubTypes.h" - -#include -#include - -#include "TopicCdrAux.hpp" -#include "TopicTypeObjectSupport.hpp" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; -using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; - -TopicPubSubType::TopicPubSubType() -{ - setName("Topic"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(Topic::getMaxCdrSerializedSize()); -#else - Topic_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = Topic_max_key_cdr_typesize > 16 ? Topic_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -TopicPubSubType::~TopicPubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool TopicPubSubType::serialize( - void* data, - SerializedPayload_t* payload, - DataRepresentationId_t data_representation) -{ - Topic* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool TopicPubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - Topic* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function TopicPubSubType::getSerializedSizeProvider( - void* data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* TopicPubSubType::createData() -{ - return reinterpret_cast(new Topic()); -} - -void TopicPubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool TopicPubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - Topic* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - Topic_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || Topic_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - 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; -} - -void TopicPubSubType::register_type_object_representation() -{ - register_Topic_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "TopicCdrAux.ipp" diff --git a/examples/cpp/dds/CustomListenerExample/TopicPubSubTypes.h b/examples/cpp/dds/CustomListenerExample/TopicPubSubTypes.h deleted file mode 100644 index 8af82d4fcdf..00000000000 --- a/examples/cpp/dds/CustomListenerExample/TopicPubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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 TopicPubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_TOPIC_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_TOPIC_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "Topic.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated Topic is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type Topic defined by the user in the IDL file. - * @ingroup Topic - */ -class TopicPubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef Topic type; - - eProsima_user_DllExport TopicPubSubType(); - - eProsima_user_DllExport ~TopicPubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_TOPIC_PUBSUBTYPES_H_ - diff --git a/examples/cpp/dds/CustomListenerExample/TopicTypeObjectSupport.cxx b/examples/cpp/dds/CustomListenerExample/TopicTypeObjectSupport.cxx deleted file mode 100644 index ec70f284376..00000000000 --- a/examples/cpp/dds/CustomListenerExample/TopicTypeObjectSupport.cxx +++ /dev/null @@ -1,138 +0,0 @@ -// 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 TopicTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "TopicTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Topic.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_Topic_type_identifier( - TypeIdentifierPair& type_ids_Topic) -{ - - ReturnCode_t return_code_Topic {eprosima::fastdds::dds::RETCODE_OK}; - return_code_Topic = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "Topic", type_ids_Topic); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_Topic) - { - StructTypeFlag struct_flags_Topic = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_Topic = "Topic"; - eprosima::fastcdr::optional type_ann_builtin_Topic; - eprosima::fastcdr::optional ann_custom_Topic; - CompleteTypeDetail detail_Topic = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_Topic, ann_custom_Topic, type_name_Topic.to_string()); - CompleteStructHeader header_Topic; - header_Topic = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_Topic); - CompleteStructMemberSeq member_seq_Topic; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_uint32_t", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_index = 0x00000000; - bool common_index_ec {false}; - CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; - if (!common_index_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); - return; - } - MemberName name_index = "index"; - eprosima::fastcdr::optional member_ann_builtin_index; - ann_custom_Topic.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_Topic); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_Topic, member_index); - } - { - TypeIdentifierPair type_ids_message; - ReturnCode_t return_code_message {eprosima::fastdds::dds::RETCODE_OK}; - return_code_message = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "anonymous_string_unbounded", type_ids_message); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_message) - { - { - SBound bound = 0; - StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, - "anonymous_string_unbounded", type_ids_message)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); - } - } - } - StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_message = 0x00000001; - bool common_message_ec {false}; - CommonStructMember common_message {TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, common_message_ec))}; - if (!common_message_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure message member TypeIdentifier inconsistent."); - return; - } - MemberName name_message = "message"; - eprosima::fastcdr::optional member_ann_builtin_message; - ann_custom_Topic.reset(); - CompleteMemberDetail detail_message = TypeObjectUtils::build_complete_member_detail(name_message, member_ann_builtin_message, ann_custom_Topic); - CompleteStructMember member_message = TypeObjectUtils::build_complete_struct_member(common_message, detail_message); - TypeObjectUtils::add_complete_struct_member(member_seq_Topic, member_message); - } - CompleteStructType struct_type_Topic = TypeObjectUtils::build_complete_struct_type(struct_flags_Topic, header_Topic, member_seq_Topic); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_Topic, type_name_Topic.to_string(), type_ids_Topic)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "Topic already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/CustomListenerExample/TopicTypeObjectSupport.hpp b/examples/cpp/dds/CustomListenerExample/TopicTypeObjectSupport.hpp deleted file mode 100644 index 6b3e255eba0..00000000000 --- a/examples/cpp/dds/CustomListenerExample/TopicTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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 TopicTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef _FAST_DDS_GENERATED_TOPIC_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_TOPIC_TYPE_OBJECT_SUPPORT_HPP_ - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register Topic related TypeIdentifier. - * 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_Topic_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // _FAST_DDS_GENERATED_TOPIC_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/examples/cpp/dds/CustomPayloadPoolExample/CustomPayloadPoolDataTypeObjectSupport.cxx b/examples/cpp/dds/CustomPayloadPoolExample/CustomPayloadPoolDataTypeObjectSupport.cxx deleted file mode 100644 index 80a797f7f94..00000000000 --- a/examples/cpp/dds/CustomPayloadPoolExample/CustomPayloadPoolDataTypeObjectSupport.cxx +++ /dev/null @@ -1,138 +0,0 @@ -// 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 CustomPayloadPoolDataTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "CustomPayloadPoolDataTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "CustomPayloadPoolData.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_CustomPayloadPoolData_type_identifier( - TypeIdentifierPair& type_ids_CustomPayloadPoolData) -{ - - ReturnCode_t return_code_CustomPayloadPoolData {eprosima::fastdds::dds::RETCODE_OK}; - return_code_CustomPayloadPoolData = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "CustomPayloadPoolData", type_ids_CustomPayloadPoolData); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_CustomPayloadPoolData) - { - StructTypeFlag struct_flags_CustomPayloadPoolData = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, - false, false); - QualifiedTypeName type_name_CustomPayloadPoolData = "CustomPayloadPoolData"; - eprosima::fastcdr::optional type_ann_builtin_CustomPayloadPoolData; - eprosima::fastcdr::optional ann_custom_CustomPayloadPoolData; - CompleteTypeDetail detail_CustomPayloadPoolData = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_CustomPayloadPoolData, ann_custom_CustomPayloadPoolData, type_name_CustomPayloadPoolData.to_string()); - CompleteStructHeader header_CustomPayloadPoolData; - header_CustomPayloadPoolData = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_CustomPayloadPoolData); - CompleteStructMemberSeq member_seq_CustomPayloadPoolData; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_uint32_t", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, - false, false, false, false); - MemberId member_id_index = 0x00000000; - bool common_index_ec {false}; - CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; - if (!common_index_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); - return; - } - MemberName name_index = "index"; - eprosima::fastcdr::optional member_ann_builtin_index; - ann_custom_CustomPayloadPoolData.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_CustomPayloadPoolData); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_CustomPayloadPoolData, member_index); - } - { - TypeIdentifierPair type_ids_message; - ReturnCode_t return_code_message {eprosima::fastdds::dds::RETCODE_OK}; - return_code_message = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "anonymous_string_unbounded", type_ids_message); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_message) - { - { - SBound bound = 0; - StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, - "anonymous_string_unbounded", type_ids_message)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); - } - } - } - StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, - false, false, false, false); - MemberId member_id_message = 0x00000001; - bool common_message_ec {false}; - CommonStructMember common_message {TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, common_message_ec))}; - if (!common_message_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure message member TypeIdentifier inconsistent."); - return; - } - MemberName name_message = "message"; - eprosima::fastcdr::optional member_ann_builtin_message; - ann_custom_CustomPayloadPoolData.reset(); - CompleteMemberDetail detail_message = TypeObjectUtils::build_complete_member_detail(name_message, member_ann_builtin_message, ann_custom_CustomPayloadPoolData); - CompleteStructMember member_message = TypeObjectUtils::build_complete_struct_member(common_message, detail_message); - TypeObjectUtils::add_complete_struct_member(member_seq_CustomPayloadPoolData, member_message); - } - CompleteStructType struct_type_CustomPayloadPoolData = TypeObjectUtils::build_complete_struct_type(struct_flags_CustomPayloadPoolData, header_CustomPayloadPoolData, member_seq_CustomPayloadPoolData); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_CustomPayloadPoolData, type_name_CustomPayloadPoolData.to_string(), type_ids_CustomPayloadPoolData)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "CustomPayloadPoolData already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/DeadlineQoSExample/deadlinepayloadPubSubTypes.cxx b/examples/cpp/dds/DeadlineQoSExample/deadlinepayloadPubSubTypes.cxx deleted file mode 100644 index 4039df4d417..00000000000 --- a/examples/cpp/dds/DeadlineQoSExample/deadlinepayloadPubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// 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 deadlinepayloadPubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - -#include "deadlinepayloadPubSubTypes.h" - -#include -#include - -#include "deadlinepayloadCdrAux.hpp" -#include "deadlinepayloadTypeObjectSupport.hpp" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; -using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; - -HelloMsgPubSubType::HelloMsgPubSubType() -{ - setName("HelloMsg"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(HelloMsg::getMaxCdrSerializedSize()); -#else - HelloMsg_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = true; - uint32_t keyLength = HelloMsg_max_key_cdr_typesize > 16 ? HelloMsg_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -HelloMsgPubSubType::~HelloMsgPubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool HelloMsgPubSubType::serialize( - void* data, - SerializedPayload_t* payload, - DataRepresentationId_t data_representation) -{ - HelloMsg* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool HelloMsgPubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - HelloMsg* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function HelloMsgPubSubType::getSerializedSizeProvider( - void* data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* HelloMsgPubSubType::createData() -{ - return reinterpret_cast(new HelloMsg()); -} - -void HelloMsgPubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool HelloMsgPubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - HelloMsg* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - HelloMsg_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || HelloMsg_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - 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; -} - -void HelloMsgPubSubType::register_type_object_representation() -{ - register_HelloMsg_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "deadlinepayloadCdrAux.ipp" diff --git a/examples/cpp/dds/DeadlineQoSExample/deadlinepayloadPubSubTypes.h b/examples/cpp/dds/DeadlineQoSExample/deadlinepayloadPubSubTypes.h deleted file mode 100644 index 7a354e84055..00000000000 --- a/examples/cpp/dds/DeadlineQoSExample/deadlinepayloadPubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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 deadlinepayloadPubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_DEADLINEPAYLOAD_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_DEADLINEPAYLOAD_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "deadlinepayload.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated deadlinepayload is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type HelloMsg defined by the user in the IDL file. - * @ingroup deadlinepayload - */ -class HelloMsgPubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef HelloMsg type; - - eProsima_user_DllExport HelloMsgPubSubType(); - - eProsima_user_DllExport ~HelloMsgPubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return true; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_DEADLINEPAYLOAD_PUBSUBTYPES_H_ - diff --git a/examples/cpp/dds/DeadlineQoSExample/deadlinepayloadTypeObjectSupport.cxx b/examples/cpp/dds/DeadlineQoSExample/deadlinepayloadTypeObjectSupport.cxx deleted file mode 100644 index b9768d78f93..00000000000 --- a/examples/cpp/dds/DeadlineQoSExample/deadlinepayloadTypeObjectSupport.cxx +++ /dev/null @@ -1,151 +0,0 @@ -// 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 deadlinepayloadTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "deadlinepayloadTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "deadlinepayload.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_HelloMsg_type_identifier( - TypeIdentifierPair& type_ids_HelloMsg) -{ - - ReturnCode_t return_code_HelloMsg {eprosima::fastdds::dds::RETCODE_OK}; - return_code_HelloMsg = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "HelloMsg", type_ids_HelloMsg); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_HelloMsg) - { - StructTypeFlag struct_flags_HelloMsg = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_HelloMsg = "HelloMsg"; - eprosima::fastcdr::optional type_ann_builtin_HelloMsg; - eprosima::fastcdr::optional ann_custom_HelloMsg; - CompleteTypeDetail detail_HelloMsg = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_HelloMsg, ann_custom_HelloMsg, type_name_HelloMsg.to_string()); - CompleteStructHeader header_HelloMsg; - header_HelloMsg = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_HelloMsg); - CompleteStructMemberSeq member_seq_HelloMsg; - { - TypeIdentifierPair type_ids_deadlinekey; - ReturnCode_t return_code_deadlinekey {eprosima::fastdds::dds::RETCODE_OK}; - return_code_deadlinekey = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_uint16_t", type_ids_deadlinekey); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_deadlinekey) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "deadlinekey Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_deadlinekey = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, true, false); - MemberId member_id_deadlinekey = 0x00000000; - bool common_deadlinekey_ec {false}; - CommonStructMember common_deadlinekey {TypeObjectUtils::build_common_struct_member(member_id_deadlinekey, member_flags_deadlinekey, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_deadlinekey, common_deadlinekey_ec))}; - if (!common_deadlinekey_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure deadlinekey member TypeIdentifier inconsistent."); - return; - } - MemberName name_deadlinekey = "deadlinekey"; - eprosima::fastcdr::optional member_ann_builtin_deadlinekey; - ann_custom_HelloMsg.reset(); - AppliedAnnotationSeq tmp_ann_custom_deadlinekey; - eprosima::fastcdr::optional unit_deadlinekey; - eprosima::fastcdr::optional min_deadlinekey; - eprosima::fastcdr::optional max_deadlinekey; - eprosima::fastcdr::optional hash_id_deadlinekey; - if (unit_deadlinekey.has_value() || min_deadlinekey.has_value() || max_deadlinekey.has_value() || hash_id_deadlinekey.has_value()) - { - member_ann_builtin_deadlinekey = TypeObjectUtils::build_applied_builtin_member_annotations(unit_deadlinekey, min_deadlinekey, max_deadlinekey, hash_id_deadlinekey); - } - if (!tmp_ann_custom_deadlinekey.empty()) - { - ann_custom_HelloMsg = tmp_ann_custom_deadlinekey; - } - CompleteMemberDetail detail_deadlinekey = TypeObjectUtils::build_complete_member_detail(name_deadlinekey, member_ann_builtin_deadlinekey, ann_custom_HelloMsg); - CompleteStructMember member_deadlinekey = TypeObjectUtils::build_complete_struct_member(common_deadlinekey, detail_deadlinekey); - TypeObjectUtils::add_complete_struct_member(member_seq_HelloMsg, member_deadlinekey); - } - { - TypeIdentifierPair type_ids_payload; - ReturnCode_t return_code_payload {eprosima::fastdds::dds::RETCODE_OK}; - return_code_payload = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "anonymous_string_256", type_ids_payload); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_payload) - { - { - LBound bound = 256; - 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_256", type_ids_payload)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "anonymous_string_256 already registered in TypeObjectRegistry for a different type."); - } - } - } - StructMemberFlag member_flags_payload = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_payload = 0x00000001; - bool common_payload_ec {false}; - CommonStructMember common_payload {TypeObjectUtils::build_common_struct_member(member_id_payload, member_flags_payload, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_payload, common_payload_ec))}; - if (!common_payload_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure payload member TypeIdentifier inconsistent."); - return; - } - MemberName name_payload = "payload"; - eprosima::fastcdr::optional member_ann_builtin_payload; - ann_custom_HelloMsg.reset(); - CompleteMemberDetail detail_payload = TypeObjectUtils::build_complete_member_detail(name_payload, member_ann_builtin_payload, ann_custom_HelloMsg); - CompleteStructMember member_payload = TypeObjectUtils::build_complete_struct_member(common_payload, detail_payload); - TypeObjectUtils::add_complete_struct_member(member_seq_HelloMsg, member_payload); - } - CompleteStructType struct_type_HelloMsg = TypeObjectUtils::build_complete_struct_type(struct_flags_HelloMsg, header_HelloMsg, member_seq_HelloMsg); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_HelloMsg, type_name_HelloMsg.to_string(), type_ids_HelloMsg)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "HelloMsg already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/DisablePositiveACKs/TopicTypeObjectSupport.cxx b/examples/cpp/dds/DisablePositiveACKs/TopicTypeObjectSupport.cxx deleted file mode 100644 index ec70f284376..00000000000 --- a/examples/cpp/dds/DisablePositiveACKs/TopicTypeObjectSupport.cxx +++ /dev/null @@ -1,138 +0,0 @@ -// 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 TopicTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "TopicTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Topic.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_Topic_type_identifier( - TypeIdentifierPair& type_ids_Topic) -{ - - ReturnCode_t return_code_Topic {eprosima::fastdds::dds::RETCODE_OK}; - return_code_Topic = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "Topic", type_ids_Topic); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_Topic) - { - StructTypeFlag struct_flags_Topic = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_Topic = "Topic"; - eprosima::fastcdr::optional type_ann_builtin_Topic; - eprosima::fastcdr::optional ann_custom_Topic; - CompleteTypeDetail detail_Topic = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_Topic, ann_custom_Topic, type_name_Topic.to_string()); - CompleteStructHeader header_Topic; - header_Topic = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_Topic); - CompleteStructMemberSeq member_seq_Topic; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_uint32_t", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_index = 0x00000000; - bool common_index_ec {false}; - CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; - if (!common_index_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); - return; - } - MemberName name_index = "index"; - eprosima::fastcdr::optional member_ann_builtin_index; - ann_custom_Topic.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_Topic); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_Topic, member_index); - } - { - TypeIdentifierPair type_ids_message; - ReturnCode_t return_code_message {eprosima::fastdds::dds::RETCODE_OK}; - return_code_message = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "anonymous_string_unbounded", type_ids_message); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_message) - { - { - SBound bound = 0; - StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, - "anonymous_string_unbounded", type_ids_message)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); - } - } - } - StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_message = 0x00000001; - bool common_message_ec {false}; - CommonStructMember common_message {TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, common_message_ec))}; - if (!common_message_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure message member TypeIdentifier inconsistent."); - return; - } - MemberName name_message = "message"; - eprosima::fastcdr::optional member_ann_builtin_message; - ann_custom_Topic.reset(); - CompleteMemberDetail detail_message = TypeObjectUtils::build_complete_member_detail(name_message, member_ann_builtin_message, ann_custom_Topic); - CompleteStructMember member_message = TypeObjectUtils::build_complete_struct_member(common_message, detail_message); - TypeObjectUtils::add_complete_struct_member(member_seq_Topic, member_message); - } - CompleteStructType struct_type_Topic = TypeObjectUtils::build_complete_struct_type(struct_flags_Topic, header_Topic, member_seq_Topic); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_Topic, type_name_Topic.to_string(), type_ids_Topic)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "Topic already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/DisablePositiveACKs/TopicTypeObjectSupport.hpp b/examples/cpp/dds/DisablePositiveACKs/TopicTypeObjectSupport.hpp deleted file mode 100644 index 6b3e255eba0..00000000000 --- a/examples/cpp/dds/DisablePositiveACKs/TopicTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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 TopicTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef _FAST_DDS_GENERATED_TOPIC_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_TOPIC_TYPE_OBJECT_SUPPORT_HPP_ - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register Topic related TypeIdentifier. - * 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_Topic_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // _FAST_DDS_GENERATED_TOPIC_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/examples/cpp/dds/Filtering/FilteringExamplePubSubTypes.cxx b/examples/cpp/dds/Filtering/FilteringExamplePubSubTypes.cxx deleted file mode 100644 index fb77a83726d..00000000000 --- a/examples/cpp/dds/Filtering/FilteringExamplePubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// 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 FilteringExamplePubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - -#include "FilteringExamplePubSubTypes.h" - -#include -#include - -#include "FilteringExampleCdrAux.hpp" -#include "FilteringExampleTypeObjectSupport.hpp" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; -using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; - -FilteringExamplePubSubType::FilteringExamplePubSubType() -{ - setName("FilteringExample"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(FilteringExample::getMaxCdrSerializedSize()); -#else - FilteringExample_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = FilteringExample_max_key_cdr_typesize > 16 ? FilteringExample_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -FilteringExamplePubSubType::~FilteringExamplePubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool FilteringExamplePubSubType::serialize( - void* data, - SerializedPayload_t* payload, - DataRepresentationId_t data_representation) -{ - FilteringExample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool FilteringExamplePubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - FilteringExample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function FilteringExamplePubSubType::getSerializedSizeProvider( - void* data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* FilteringExamplePubSubType::createData() -{ - return reinterpret_cast(new FilteringExample()); -} - -void FilteringExamplePubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool FilteringExamplePubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - FilteringExample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - FilteringExample_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || FilteringExample_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - 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; -} - -void FilteringExamplePubSubType::register_type_object_representation() -{ - register_FilteringExample_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "FilteringExampleCdrAux.ipp" diff --git a/examples/cpp/dds/Filtering/FilteringExamplePubSubTypes.h b/examples/cpp/dds/Filtering/FilteringExamplePubSubTypes.h deleted file mode 100644 index 379c2b76c26..00000000000 --- a/examples/cpp/dds/Filtering/FilteringExamplePubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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 FilteringExamplePubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_FILTERINGEXAMPLE_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_FILTERINGEXAMPLE_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "FilteringExample.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated FilteringExample is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type FilteringExample defined by the user in the IDL file. - * @ingroup FilteringExample - */ -class FilteringExamplePubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef FilteringExample type; - - eProsima_user_DllExport FilteringExamplePubSubType(); - - eProsima_user_DllExport ~FilteringExamplePubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return true; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_FILTERINGEXAMPLE_PUBSUBTYPES_H_ - diff --git a/examples/cpp/dds/Filtering/FilteringExampleTypeObjectSupport.cxx b/examples/cpp/dds/Filtering/FilteringExampleTypeObjectSupport.cxx deleted file mode 100644 index 25a58904bf2..00000000000 --- a/examples/cpp/dds/Filtering/FilteringExampleTypeObjectSupport.cxx +++ /dev/null @@ -1,100 +0,0 @@ -// 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 FilteringExampleTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "FilteringExampleTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "FilteringExample.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_FilteringExample_type_identifier( - TypeIdentifierPair& type_ids_FilteringExample) -{ - - ReturnCode_t return_code_FilteringExample {eprosima::fastdds::dds::RETCODE_OK}; - return_code_FilteringExample = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "FilteringExample", type_ids_FilteringExample); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_FilteringExample) - { - StructTypeFlag struct_flags_FilteringExample = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_FilteringExample = "FilteringExample"; - eprosima::fastcdr::optional type_ann_builtin_FilteringExample; - eprosima::fastcdr::optional ann_custom_FilteringExample; - CompleteTypeDetail detail_FilteringExample = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_FilteringExample, ann_custom_FilteringExample, type_name_FilteringExample.to_string()); - CompleteStructHeader header_FilteringExample; - header_FilteringExample = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_FilteringExample); - CompleteStructMemberSeq member_seq_FilteringExample; - { - TypeIdentifierPair type_ids_sampleNumber; - ReturnCode_t return_code_sampleNumber {eprosima::fastdds::dds::RETCODE_OK}; - return_code_sampleNumber = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_int32_t", type_ids_sampleNumber); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_sampleNumber) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "sampleNumber Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_sampleNumber = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_sampleNumber = 0x00000000; - bool common_sampleNumber_ec {false}; - CommonStructMember common_sampleNumber {TypeObjectUtils::build_common_struct_member(member_id_sampleNumber, member_flags_sampleNumber, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_sampleNumber, common_sampleNumber_ec))}; - if (!common_sampleNumber_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure sampleNumber member TypeIdentifier inconsistent."); - return; - } - MemberName name_sampleNumber = "sampleNumber"; - eprosima::fastcdr::optional member_ann_builtin_sampleNumber; - ann_custom_FilteringExample.reset(); - CompleteMemberDetail detail_sampleNumber = TypeObjectUtils::build_complete_member_detail(name_sampleNumber, member_ann_builtin_sampleNumber, ann_custom_FilteringExample); - CompleteStructMember member_sampleNumber = TypeObjectUtils::build_complete_struct_member(common_sampleNumber, detail_sampleNumber); - TypeObjectUtils::add_complete_struct_member(member_seq_FilteringExample, member_sampleNumber); - } - CompleteStructType struct_type_FilteringExample = TypeObjectUtils::build_complete_struct_type(struct_flags_FilteringExample, header_FilteringExample, member_seq_FilteringExample); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_FilteringExample, type_name_FilteringExample.to_string(), type_ids_FilteringExample)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "FilteringExample already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/Filtering/FilteringExampleTypeObjectSupport.hpp b/examples/cpp/dds/Filtering/FilteringExampleTypeObjectSupport.hpp deleted file mode 100644 index 458f0657204..00000000000 --- a/examples/cpp/dds/Filtering/FilteringExampleTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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 FilteringExampleTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef _FAST_DDS_GENERATED_FILTERINGEXAMPLE_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_FILTERINGEXAMPLE_TYPE_OBJECT_SUPPORT_HPP_ - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register FilteringExample related TypeIdentifier. - * 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_FilteringExample_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // _FAST_DDS_GENERATED_FILTERINGEXAMPLE_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/examples/cpp/dds/HistoryKind/samplePubSubTypes.cxx b/examples/cpp/dds/HistoryKind/samplePubSubTypes.cxx deleted file mode 100644 index 321f250d975..00000000000 --- a/examples/cpp/dds/HistoryKind/samplePubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// 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 samplePubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - -#include "samplePubSubTypes.h" - -#include -#include - -#include "sampleCdrAux.hpp" -#include "sampleTypeObjectSupport.hpp" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; -using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; - -samplePubSubType::samplePubSubType() -{ - setName("sample"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(sample::getMaxCdrSerializedSize()); -#else - sample_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = true; - uint32_t keyLength = sample_max_key_cdr_typesize > 16 ? sample_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -samplePubSubType::~samplePubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool samplePubSubType::serialize( - void* data, - SerializedPayload_t* payload, - DataRepresentationId_t data_representation) -{ - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool samplePubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function samplePubSubType::getSerializedSizeProvider( - void* data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* samplePubSubType::createData() -{ - return reinterpret_cast(new sample()); -} - -void samplePubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool samplePubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - sample_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || sample_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - 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; -} - -void samplePubSubType::register_type_object_representation() -{ - register_sample_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "sampleCdrAux.ipp" diff --git a/examples/cpp/dds/HistoryKind/samplePubSubTypes.h b/examples/cpp/dds/HistoryKind/samplePubSubTypes.h deleted file mode 100644 index 1ec6375ba7f..00000000000 --- a/examples/cpp/dds/HistoryKind/samplePubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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 samplePubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "sample.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated sample is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type sample defined by the user in the IDL file. - * @ingroup sample - */ -class samplePubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef sample type; - - eProsima_user_DllExport samplePubSubType(); - - eProsima_user_DllExport ~samplePubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return true; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ - diff --git a/examples/cpp/dds/HistoryKind/sampleTypeObjectSupport.cxx b/examples/cpp/dds/HistoryKind/sampleTypeObjectSupport.cxx deleted file mode 100644 index e9dcd1a977b..00000000000 --- a/examples/cpp/dds/HistoryKind/sampleTypeObjectSupport.cxx +++ /dev/null @@ -1,143 +0,0 @@ -// 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 sampleTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "sampleTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "sample.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_sample_type_identifier( - TypeIdentifierPair& type_ids_sample) -{ - - ReturnCode_t return_code_sample {eprosima::fastdds::dds::RETCODE_OK}; - return_code_sample = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "sample", type_ids_sample); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_sample) - { - StructTypeFlag struct_flags_sample = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_sample = "sample"; - eprosima::fastcdr::optional type_ann_builtin_sample; - eprosima::fastcdr::optional ann_custom_sample; - CompleteTypeDetail detail_sample = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_sample, ann_custom_sample, type_name_sample.to_string()); - CompleteStructHeader header_sample; - header_sample = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_sample); - CompleteStructMemberSeq member_seq_sample; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_byte", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_index = 0x00000000; - bool common_index_ec {false}; - CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; - if (!common_index_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); - return; - } - MemberName name_index = "index"; - eprosima::fastcdr::optional member_ann_builtin_index; - ann_custom_sample.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_sample); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_sample, member_index); - } - { - TypeIdentifierPair type_ids_key_value; - ReturnCode_t return_code_key_value {eprosima::fastdds::dds::RETCODE_OK}; - return_code_key_value = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_byte", type_ids_key_value); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_key_value) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "key_value Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_key_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, true, false); - MemberId member_id_key_value = 0x00000001; - bool common_key_value_ec {false}; - CommonStructMember common_key_value {TypeObjectUtils::build_common_struct_member(member_id_key_value, member_flags_key_value, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_key_value, common_key_value_ec))}; - if (!common_key_value_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure key_value member TypeIdentifier inconsistent."); - return; - } - MemberName name_key_value = "key_value"; - eprosima::fastcdr::optional member_ann_builtin_key_value; - ann_custom_sample.reset(); - AppliedAnnotationSeq tmp_ann_custom_key_value; - eprosima::fastcdr::optional unit_key_value; - eprosima::fastcdr::optional min_key_value; - eprosima::fastcdr::optional max_key_value; - eprosima::fastcdr::optional hash_id_key_value; - if (unit_key_value.has_value() || min_key_value.has_value() || max_key_value.has_value() || hash_id_key_value.has_value()) - { - member_ann_builtin_key_value = TypeObjectUtils::build_applied_builtin_member_annotations(unit_key_value, min_key_value, max_key_value, hash_id_key_value); - } - if (!tmp_ann_custom_key_value.empty()) - { - ann_custom_sample = tmp_ann_custom_key_value; - } - CompleteMemberDetail detail_key_value = TypeObjectUtils::build_complete_member_detail(name_key_value, member_ann_builtin_key_value, ann_custom_sample); - CompleteStructMember member_key_value = TypeObjectUtils::build_complete_struct_member(common_key_value, detail_key_value); - TypeObjectUtils::add_complete_struct_member(member_seq_sample, member_key_value); - } - CompleteStructType struct_type_sample = TypeObjectUtils::build_complete_struct_type(struct_flags_sample, header_sample, member_seq_sample); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_sample, type_name_sample.to_string(), type_ids_sample)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "sample already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/HistoryKind/sampleTypeObjectSupport.hpp b/examples/cpp/dds/HistoryKind/sampleTypeObjectSupport.hpp deleted file mode 100644 index 013609fa263..00000000000 --- a/examples/cpp/dds/HistoryKind/sampleTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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 sampleTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register sample related TypeIdentifier. - * 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_sample_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/examples/cpp/dds/LateJoiners/samplePubSubTypes.cxx b/examples/cpp/dds/LateJoiners/samplePubSubTypes.cxx deleted file mode 100644 index 321f250d975..00000000000 --- a/examples/cpp/dds/LateJoiners/samplePubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// 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 samplePubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - -#include "samplePubSubTypes.h" - -#include -#include - -#include "sampleCdrAux.hpp" -#include "sampleTypeObjectSupport.hpp" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; -using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; - -samplePubSubType::samplePubSubType() -{ - setName("sample"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(sample::getMaxCdrSerializedSize()); -#else - sample_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = true; - uint32_t keyLength = sample_max_key_cdr_typesize > 16 ? sample_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -samplePubSubType::~samplePubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool samplePubSubType::serialize( - void* data, - SerializedPayload_t* payload, - DataRepresentationId_t data_representation) -{ - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool samplePubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function samplePubSubType::getSerializedSizeProvider( - void* data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* samplePubSubType::createData() -{ - return reinterpret_cast(new sample()); -} - -void samplePubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool samplePubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - sample_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || sample_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - 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; -} - -void samplePubSubType::register_type_object_representation() -{ - register_sample_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "sampleCdrAux.ipp" diff --git a/examples/cpp/dds/LateJoiners/samplePubSubTypes.h b/examples/cpp/dds/LateJoiners/samplePubSubTypes.h deleted file mode 100644 index 1ec6375ba7f..00000000000 --- a/examples/cpp/dds/LateJoiners/samplePubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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 samplePubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "sample.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated sample is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type sample defined by the user in the IDL file. - * @ingroup sample - */ -class samplePubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef sample type; - - eProsima_user_DllExport samplePubSubType(); - - eProsima_user_DllExport ~samplePubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return true; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ - diff --git a/examples/cpp/dds/LateJoiners/sampleTypeObjectSupport.cxx b/examples/cpp/dds/LateJoiners/sampleTypeObjectSupport.cxx deleted file mode 100644 index e9dcd1a977b..00000000000 --- a/examples/cpp/dds/LateJoiners/sampleTypeObjectSupport.cxx +++ /dev/null @@ -1,143 +0,0 @@ -// 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 sampleTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "sampleTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "sample.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_sample_type_identifier( - TypeIdentifierPair& type_ids_sample) -{ - - ReturnCode_t return_code_sample {eprosima::fastdds::dds::RETCODE_OK}; - return_code_sample = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "sample", type_ids_sample); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_sample) - { - StructTypeFlag struct_flags_sample = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_sample = "sample"; - eprosima::fastcdr::optional type_ann_builtin_sample; - eprosima::fastcdr::optional ann_custom_sample; - CompleteTypeDetail detail_sample = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_sample, ann_custom_sample, type_name_sample.to_string()); - CompleteStructHeader header_sample; - header_sample = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_sample); - CompleteStructMemberSeq member_seq_sample; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_byte", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_index = 0x00000000; - bool common_index_ec {false}; - CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; - if (!common_index_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); - return; - } - MemberName name_index = "index"; - eprosima::fastcdr::optional member_ann_builtin_index; - ann_custom_sample.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_sample); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_sample, member_index); - } - { - TypeIdentifierPair type_ids_key_value; - ReturnCode_t return_code_key_value {eprosima::fastdds::dds::RETCODE_OK}; - return_code_key_value = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_byte", type_ids_key_value); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_key_value) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "key_value Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_key_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, true, false); - MemberId member_id_key_value = 0x00000001; - bool common_key_value_ec {false}; - CommonStructMember common_key_value {TypeObjectUtils::build_common_struct_member(member_id_key_value, member_flags_key_value, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_key_value, common_key_value_ec))}; - if (!common_key_value_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure key_value member TypeIdentifier inconsistent."); - return; - } - MemberName name_key_value = "key_value"; - eprosima::fastcdr::optional member_ann_builtin_key_value; - ann_custom_sample.reset(); - AppliedAnnotationSeq tmp_ann_custom_key_value; - eprosima::fastcdr::optional unit_key_value; - eprosima::fastcdr::optional min_key_value; - eprosima::fastcdr::optional max_key_value; - eprosima::fastcdr::optional hash_id_key_value; - if (unit_key_value.has_value() || min_key_value.has_value() || max_key_value.has_value() || hash_id_key_value.has_value()) - { - member_ann_builtin_key_value = TypeObjectUtils::build_applied_builtin_member_annotations(unit_key_value, min_key_value, max_key_value, hash_id_key_value); - } - if (!tmp_ann_custom_key_value.empty()) - { - ann_custom_sample = tmp_ann_custom_key_value; - } - CompleteMemberDetail detail_key_value = TypeObjectUtils::build_complete_member_detail(name_key_value, member_ann_builtin_key_value, ann_custom_sample); - CompleteStructMember member_key_value = TypeObjectUtils::build_complete_struct_member(common_key_value, detail_key_value); - TypeObjectUtils::add_complete_struct_member(member_seq_sample, member_key_value); - } - CompleteStructType struct_type_sample = TypeObjectUtils::build_complete_struct_type(struct_flags_sample, header_sample, member_seq_sample); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_sample, type_name_sample.to_string(), type_ids_sample)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "sample already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/LateJoiners/sampleTypeObjectSupport.hpp b/examples/cpp/dds/LateJoiners/sampleTypeObjectSupport.hpp deleted file mode 100644 index 013609fa263..00000000000 --- a/examples/cpp/dds/LateJoiners/sampleTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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 sampleTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register sample related TypeIdentifier. - * 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_sample_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/examples/cpp/dds/LifespanQoSExample/LifespanPubSubTypes.cxx b/examples/cpp/dds/LifespanQoSExample/LifespanPubSubTypes.cxx deleted file mode 100644 index 30d909b77f5..00000000000 --- a/examples/cpp/dds/LifespanQoSExample/LifespanPubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// 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 LifespanPubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - -#include "LifespanPubSubTypes.h" - -#include -#include - -#include "LifespanCdrAux.hpp" -#include "LifespanTypeObjectSupport.hpp" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; -using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; - -LifespanPubSubType::LifespanPubSubType() -{ - setName("Lifespan"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(Lifespan::getMaxCdrSerializedSize()); -#else - Lifespan_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = Lifespan_max_key_cdr_typesize > 16 ? Lifespan_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -LifespanPubSubType::~LifespanPubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool LifespanPubSubType::serialize( - void* data, - SerializedPayload_t* payload, - DataRepresentationId_t data_representation) -{ - Lifespan* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool LifespanPubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - Lifespan* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function LifespanPubSubType::getSerializedSizeProvider( - void* data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* LifespanPubSubType::createData() -{ - return reinterpret_cast(new Lifespan()); -} - -void LifespanPubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool LifespanPubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - Lifespan* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - Lifespan_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || Lifespan_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - 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; -} - -void LifespanPubSubType::register_type_object_representation() -{ - register_Lifespan_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "LifespanCdrAux.ipp" diff --git a/examples/cpp/dds/LifespanQoSExample/LifespanPubSubTypes.h b/examples/cpp/dds/LifespanQoSExample/LifespanPubSubTypes.h deleted file mode 100644 index 1314dbb2e9f..00000000000 --- a/examples/cpp/dds/LifespanQoSExample/LifespanPubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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 LifespanPubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_LIFESPAN_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_LIFESPAN_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "Lifespan.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated Lifespan is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type Lifespan defined by the user in the IDL file. - * @ingroup Lifespan - */ -class LifespanPubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef Lifespan type; - - eProsima_user_DllExport LifespanPubSubType(); - - eProsima_user_DllExport ~LifespanPubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_LIFESPAN_PUBSUBTYPES_H_ - diff --git a/examples/cpp/dds/LifespanQoSExample/LifespanTypeObjectSupport.cxx b/examples/cpp/dds/LifespanQoSExample/LifespanTypeObjectSupport.cxx deleted file mode 100644 index 9306797b046..00000000000 --- a/examples/cpp/dds/LifespanQoSExample/LifespanTypeObjectSupport.cxx +++ /dev/null @@ -1,138 +0,0 @@ -// 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 LifespanTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "LifespanTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Lifespan.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_Lifespan_type_identifier( - TypeIdentifierPair& type_ids_Lifespan) -{ - - ReturnCode_t return_code_Lifespan {eprosima::fastdds::dds::RETCODE_OK}; - return_code_Lifespan = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "Lifespan", type_ids_Lifespan); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_Lifespan) - { - StructTypeFlag struct_flags_Lifespan = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_Lifespan = "Lifespan"; - eprosima::fastcdr::optional type_ann_builtin_Lifespan; - eprosima::fastcdr::optional ann_custom_Lifespan; - CompleteTypeDetail detail_Lifespan = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_Lifespan, ann_custom_Lifespan, type_name_Lifespan.to_string()); - CompleteStructHeader header_Lifespan; - header_Lifespan = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_Lifespan); - CompleteStructMemberSeq member_seq_Lifespan; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_uint32_t", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_index = 0x00000000; - bool common_index_ec {false}; - CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; - if (!common_index_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); - return; - } - MemberName name_index = "index"; - eprosima::fastcdr::optional member_ann_builtin_index; - ann_custom_Lifespan.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_Lifespan); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_Lifespan, member_index); - } - { - TypeIdentifierPair type_ids_message; - ReturnCode_t return_code_message {eprosima::fastdds::dds::RETCODE_OK}; - return_code_message = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "anonymous_string_unbounded", type_ids_message); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_message) - { - { - SBound bound = 0; - StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, - "anonymous_string_unbounded", type_ids_message)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); - } - } - } - StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_message = 0x00000001; - bool common_message_ec {false}; - CommonStructMember common_message {TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, common_message_ec))}; - if (!common_message_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure message member TypeIdentifier inconsistent."); - return; - } - MemberName name_message = "message"; - eprosima::fastcdr::optional member_ann_builtin_message; - ann_custom_Lifespan.reset(); - CompleteMemberDetail detail_message = TypeObjectUtils::build_complete_member_detail(name_message, member_ann_builtin_message, ann_custom_Lifespan); - CompleteStructMember member_message = TypeObjectUtils::build_complete_struct_member(common_message, detail_message); - TypeObjectUtils::add_complete_struct_member(member_seq_Lifespan, member_message); - } - CompleteStructType struct_type_Lifespan = TypeObjectUtils::build_complete_struct_type(struct_flags_Lifespan, header_Lifespan, member_seq_Lifespan); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_Lifespan, type_name_Lifespan.to_string(), type_ids_Lifespan)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "Lifespan already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/LifespanQoSExample/LifespanTypeObjectSupport.hpp b/examples/cpp/dds/LifespanQoSExample/LifespanTypeObjectSupport.hpp deleted file mode 100644 index 9ddc11df87d..00000000000 --- a/examples/cpp/dds/LifespanQoSExample/LifespanTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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 LifespanTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef _FAST_DDS_GENERATED_LIFESPAN_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_LIFESPAN_TYPE_OBJECT_SUPPORT_HPP_ - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register Lifespan related TypeIdentifier. - * 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_Lifespan_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // _FAST_DDS_GENERATED_LIFESPAN_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/examples/cpp/dds/LivelinessQoS/TopicPubSubTypes.cxx b/examples/cpp/dds/LivelinessQoS/TopicPubSubTypes.cxx deleted file mode 100644 index 70697eb1c1d..00000000000 --- a/examples/cpp/dds/LivelinessQoS/TopicPubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// 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 TopicPubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - -#include "TopicPubSubTypes.h" - -#include -#include - -#include "TopicCdrAux.hpp" -#include "TopicTypeObjectSupport.hpp" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; -using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; - -TopicPubSubType::TopicPubSubType() -{ - setName("Topic"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(Topic::getMaxCdrSerializedSize()); -#else - Topic_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = Topic_max_key_cdr_typesize > 16 ? Topic_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -TopicPubSubType::~TopicPubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool TopicPubSubType::serialize( - void* data, - SerializedPayload_t* payload, - DataRepresentationId_t data_representation) -{ - Topic* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool TopicPubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - Topic* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function TopicPubSubType::getSerializedSizeProvider( - void* data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* TopicPubSubType::createData() -{ - return reinterpret_cast(new Topic()); -} - -void TopicPubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool TopicPubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - Topic* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - Topic_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || Topic_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - 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; -} - -void TopicPubSubType::register_type_object_representation() -{ - register_Topic_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "TopicCdrAux.ipp" diff --git a/examples/cpp/dds/LivelinessQoS/TopicPubSubTypes.h b/examples/cpp/dds/LivelinessQoS/TopicPubSubTypes.h deleted file mode 100644 index 8af82d4fcdf..00000000000 --- a/examples/cpp/dds/LivelinessQoS/TopicPubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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 TopicPubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_TOPIC_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_TOPIC_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "Topic.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated Topic is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type Topic defined by the user in the IDL file. - * @ingroup Topic - */ -class TopicPubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef Topic type; - - eProsima_user_DllExport TopicPubSubType(); - - eProsima_user_DllExport ~TopicPubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_TOPIC_PUBSUBTYPES_H_ - diff --git a/examples/cpp/dds/LivelinessQoS/TopicTypeObjectSupport.cxx b/examples/cpp/dds/LivelinessQoS/TopicTypeObjectSupport.cxx deleted file mode 100644 index ec70f284376..00000000000 --- a/examples/cpp/dds/LivelinessQoS/TopicTypeObjectSupport.cxx +++ /dev/null @@ -1,138 +0,0 @@ -// 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 TopicTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "TopicTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Topic.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_Topic_type_identifier( - TypeIdentifierPair& type_ids_Topic) -{ - - ReturnCode_t return_code_Topic {eprosima::fastdds::dds::RETCODE_OK}; - return_code_Topic = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "Topic", type_ids_Topic); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_Topic) - { - StructTypeFlag struct_flags_Topic = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_Topic = "Topic"; - eprosima::fastcdr::optional type_ann_builtin_Topic; - eprosima::fastcdr::optional ann_custom_Topic; - CompleteTypeDetail detail_Topic = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_Topic, ann_custom_Topic, type_name_Topic.to_string()); - CompleteStructHeader header_Topic; - header_Topic = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_Topic); - CompleteStructMemberSeq member_seq_Topic; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_uint32_t", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_index = 0x00000000; - bool common_index_ec {false}; - CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; - if (!common_index_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); - return; - } - MemberName name_index = "index"; - eprosima::fastcdr::optional member_ann_builtin_index; - ann_custom_Topic.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_Topic); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_Topic, member_index); - } - { - TypeIdentifierPair type_ids_message; - ReturnCode_t return_code_message {eprosima::fastdds::dds::RETCODE_OK}; - return_code_message = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "anonymous_string_unbounded", type_ids_message); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_message) - { - { - SBound bound = 0; - StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, - "anonymous_string_unbounded", type_ids_message)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); - } - } - } - StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_message = 0x00000001; - bool common_message_ec {false}; - CommonStructMember common_message {TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, common_message_ec))}; - if (!common_message_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure message member TypeIdentifier inconsistent."); - return; - } - MemberName name_message = "message"; - eprosima::fastcdr::optional member_ann_builtin_message; - ann_custom_Topic.reset(); - CompleteMemberDetail detail_message = TypeObjectUtils::build_complete_member_detail(name_message, member_ann_builtin_message, ann_custom_Topic); - CompleteStructMember member_message = TypeObjectUtils::build_complete_struct_member(common_message, detail_message); - TypeObjectUtils::add_complete_struct_member(member_seq_Topic, member_message); - } - CompleteStructType struct_type_Topic = TypeObjectUtils::build_complete_struct_type(struct_flags_Topic, header_Topic, member_seq_Topic); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_Topic, type_name_Topic.to_string(), type_ids_Topic)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "Topic already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/LivelinessQoS/TopicTypeObjectSupport.hpp b/examples/cpp/dds/LivelinessQoS/TopicTypeObjectSupport.hpp deleted file mode 100644 index 6b3e255eba0..00000000000 --- a/examples/cpp/dds/LivelinessQoS/TopicTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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 TopicTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef _FAST_DDS_GENERATED_TOPIC_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_TOPIC_TYPE_OBJECT_SUPPORT_HPP_ - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register Topic related TypeIdentifier. - * 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_Topic_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // _FAST_DDS_GENERATED_TOPIC_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthPubSubTypes.cxx b/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthPubSubTypes.cxx deleted file mode 100644 index 21831e3b34e..00000000000 --- a/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthPubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// 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 OwnershipStrengthPubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - -#include "OwnershipStrengthPubSubTypes.h" - -#include -#include - -#include "OwnershipStrengthCdrAux.hpp" -#include "OwnershipStrengthTypeObjectSupport.hpp" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; -using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; - -ExampleMessagePubSubType::ExampleMessagePubSubType() -{ - setName("ExampleMessage"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(ExampleMessage::getMaxCdrSerializedSize()); -#else - ExampleMessage_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = ExampleMessage_max_key_cdr_typesize > 16 ? ExampleMessage_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -ExampleMessagePubSubType::~ExampleMessagePubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool ExampleMessagePubSubType::serialize( - void* data, - SerializedPayload_t* payload, - DataRepresentationId_t data_representation) -{ - ExampleMessage* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool ExampleMessagePubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - ExampleMessage* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function ExampleMessagePubSubType::getSerializedSizeProvider( - void* data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* ExampleMessagePubSubType::createData() -{ - return reinterpret_cast(new ExampleMessage()); -} - -void ExampleMessagePubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool ExampleMessagePubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - ExampleMessage* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - ExampleMessage_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || ExampleMessage_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - 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; -} - -void ExampleMessagePubSubType::register_type_object_representation() -{ - register_ExampleMessage_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "OwnershipStrengthCdrAux.ipp" diff --git a/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthPubSubTypes.h b/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthPubSubTypes.h deleted file mode 100644 index 21f51bc127f..00000000000 --- a/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthPubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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 OwnershipStrengthPubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_OWNERSHIPSTRENGTH_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_OWNERSHIPSTRENGTH_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "OwnershipStrength.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated OwnershipStrength is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type ExampleMessage defined by the user in the IDL file. - * @ingroup OwnershipStrength - */ -class ExampleMessagePubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef ExampleMessage type; - - eProsima_user_DllExport ExampleMessagePubSubType(); - - eProsima_user_DllExport ~ExampleMessagePubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_OWNERSHIPSTRENGTH_PUBSUBTYPES_H_ - diff --git a/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthTypeObjectSupport.cxx b/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthTypeObjectSupport.cxx deleted file mode 100644 index 9c4650ab567..00000000000 --- a/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthTypeObjectSupport.cxx +++ /dev/null @@ -1,168 +0,0 @@ -// 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 OwnershipStrengthTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "OwnershipStrengthTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "OwnershipStrength.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_ExampleMessage_type_identifier( - TypeIdentifierPair& type_ids_ExampleMessage) -{ - - ReturnCode_t return_code_ExampleMessage {eprosima::fastdds::dds::RETCODE_OK}; - return_code_ExampleMessage = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "ExampleMessage", type_ids_ExampleMessage); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_ExampleMessage) - { - StructTypeFlag struct_flags_ExampleMessage = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_ExampleMessage = "ExampleMessage"; - eprosima::fastcdr::optional type_ann_builtin_ExampleMessage; - eprosima::fastcdr::optional ann_custom_ExampleMessage; - CompleteTypeDetail detail_ExampleMessage = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_ExampleMessage, ann_custom_ExampleMessage, type_name_ExampleMessage.to_string()); - CompleteStructHeader header_ExampleMessage; - header_ExampleMessage = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_ExampleMessage); - CompleteStructMemberSeq member_seq_ExampleMessage; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_uint32_t", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_index = 0x00000000; - bool common_index_ec {false}; - CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; - if (!common_index_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); - return; - } - MemberName name_index = "index"; - eprosima::fastcdr::optional member_ann_builtin_index; - ann_custom_ExampleMessage.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_ExampleMessage); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_ExampleMessage, member_index); - } - { - TypeIdentifierPair type_ids_ownershipStrength; - ReturnCode_t return_code_ownershipStrength {eprosima::fastdds::dds::RETCODE_OK}; - return_code_ownershipStrength = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_uint32_t", type_ids_ownershipStrength); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_ownershipStrength) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "ownershipStrength Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_ownershipStrength = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_ownershipStrength = 0x00000001; - bool common_ownershipStrength_ec {false}; - CommonStructMember common_ownershipStrength {TypeObjectUtils::build_common_struct_member(member_id_ownershipStrength, member_flags_ownershipStrength, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_ownershipStrength, common_ownershipStrength_ec))}; - if (!common_ownershipStrength_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure ownershipStrength member TypeIdentifier inconsistent."); - return; - } - MemberName name_ownershipStrength = "ownershipStrength"; - eprosima::fastcdr::optional member_ann_builtin_ownershipStrength; - ann_custom_ExampleMessage.reset(); - CompleteMemberDetail detail_ownershipStrength = TypeObjectUtils::build_complete_member_detail(name_ownershipStrength, member_ann_builtin_ownershipStrength, ann_custom_ExampleMessage); - CompleteStructMember member_ownershipStrength = TypeObjectUtils::build_complete_struct_member(common_ownershipStrength, detail_ownershipStrength); - TypeObjectUtils::add_complete_struct_member(member_seq_ExampleMessage, member_ownershipStrength); - } - { - TypeIdentifierPair type_ids_message; - ReturnCode_t return_code_message {eprosima::fastdds::dds::RETCODE_OK}; - return_code_message = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "anonymous_string_unbounded", type_ids_message); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_message) - { - { - SBound bound = 0; - StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, - "anonymous_string_unbounded", type_ids_message)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); - } - } - } - StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_message = 0x00000002; - bool common_message_ec {false}; - CommonStructMember common_message {TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, common_message_ec))}; - if (!common_message_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure message member TypeIdentifier inconsistent."); - return; - } - MemberName name_message = "message"; - eprosima::fastcdr::optional member_ann_builtin_message; - ann_custom_ExampleMessage.reset(); - CompleteMemberDetail detail_message = TypeObjectUtils::build_complete_member_detail(name_message, member_ann_builtin_message, ann_custom_ExampleMessage); - CompleteStructMember member_message = TypeObjectUtils::build_complete_struct_member(common_message, detail_message); - TypeObjectUtils::add_complete_struct_member(member_seq_ExampleMessage, member_message); - } - CompleteStructType struct_type_ExampleMessage = TypeObjectUtils::build_complete_struct_type(struct_flags_ExampleMessage, header_ExampleMessage, member_seq_ExampleMessage); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_ExampleMessage, type_name_ExampleMessage.to_string(), type_ids_ExampleMessage)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "ExampleMessage already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthTypeObjectSupport.hpp b/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthTypeObjectSupport.hpp deleted file mode 100644 index df3ccd0dab7..00000000000 --- a/examples/cpp/dds/OwnershipStrengthQoSExample/OwnershipStrengthTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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 OwnershipStrengthTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef _FAST_DDS_GENERATED_OWNERSHIPSTRENGTH_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_OWNERSHIPSTRENGTH_TYPE_OBJECT_SUPPORT_HPP_ - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register ExampleMessage related TypeIdentifier. - * 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_ExampleMessage_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // _FAST_DDS_GENERATED_OWNERSHIPSTRENGTH_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/examples/cpp/dds/SampleConfig_Controller/samplePubSubTypes.cxx b/examples/cpp/dds/SampleConfig_Controller/samplePubSubTypes.cxx deleted file mode 100644 index 321f250d975..00000000000 --- a/examples/cpp/dds/SampleConfig_Controller/samplePubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// 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 samplePubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - -#include "samplePubSubTypes.h" - -#include -#include - -#include "sampleCdrAux.hpp" -#include "sampleTypeObjectSupport.hpp" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; -using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; - -samplePubSubType::samplePubSubType() -{ - setName("sample"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(sample::getMaxCdrSerializedSize()); -#else - sample_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = true; - uint32_t keyLength = sample_max_key_cdr_typesize > 16 ? sample_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -samplePubSubType::~samplePubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool samplePubSubType::serialize( - void* data, - SerializedPayload_t* payload, - DataRepresentationId_t data_representation) -{ - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool samplePubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function samplePubSubType::getSerializedSizeProvider( - void* data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* samplePubSubType::createData() -{ - return reinterpret_cast(new sample()); -} - -void samplePubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool samplePubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - sample_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || sample_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - 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; -} - -void samplePubSubType::register_type_object_representation() -{ - register_sample_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "sampleCdrAux.ipp" diff --git a/examples/cpp/dds/SampleConfig_Controller/samplePubSubTypes.h b/examples/cpp/dds/SampleConfig_Controller/samplePubSubTypes.h deleted file mode 100644 index 1ec6375ba7f..00000000000 --- a/examples/cpp/dds/SampleConfig_Controller/samplePubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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 samplePubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "sample.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated sample is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type sample defined by the user in the IDL file. - * @ingroup sample - */ -class samplePubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef sample type; - - eProsima_user_DllExport samplePubSubType(); - - eProsima_user_DllExport ~samplePubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return true; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ - diff --git a/examples/cpp/dds/SampleConfig_Controller/sampleTypeObjectSupport.cxx b/examples/cpp/dds/SampleConfig_Controller/sampleTypeObjectSupport.cxx deleted file mode 100644 index e9dcd1a977b..00000000000 --- a/examples/cpp/dds/SampleConfig_Controller/sampleTypeObjectSupport.cxx +++ /dev/null @@ -1,143 +0,0 @@ -// 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 sampleTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "sampleTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "sample.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_sample_type_identifier( - TypeIdentifierPair& type_ids_sample) -{ - - ReturnCode_t return_code_sample {eprosima::fastdds::dds::RETCODE_OK}; - return_code_sample = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "sample", type_ids_sample); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_sample) - { - StructTypeFlag struct_flags_sample = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_sample = "sample"; - eprosima::fastcdr::optional type_ann_builtin_sample; - eprosima::fastcdr::optional ann_custom_sample; - CompleteTypeDetail detail_sample = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_sample, ann_custom_sample, type_name_sample.to_string()); - CompleteStructHeader header_sample; - header_sample = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_sample); - CompleteStructMemberSeq member_seq_sample; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_byte", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_index = 0x00000000; - bool common_index_ec {false}; - CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; - if (!common_index_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); - return; - } - MemberName name_index = "index"; - eprosima::fastcdr::optional member_ann_builtin_index; - ann_custom_sample.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_sample); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_sample, member_index); - } - { - TypeIdentifierPair type_ids_key_value; - ReturnCode_t return_code_key_value {eprosima::fastdds::dds::RETCODE_OK}; - return_code_key_value = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_byte", type_ids_key_value); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_key_value) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "key_value Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_key_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, true, false); - MemberId member_id_key_value = 0x00000001; - bool common_key_value_ec {false}; - CommonStructMember common_key_value {TypeObjectUtils::build_common_struct_member(member_id_key_value, member_flags_key_value, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_key_value, common_key_value_ec))}; - if (!common_key_value_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure key_value member TypeIdentifier inconsistent."); - return; - } - MemberName name_key_value = "key_value"; - eprosima::fastcdr::optional member_ann_builtin_key_value; - ann_custom_sample.reset(); - AppliedAnnotationSeq tmp_ann_custom_key_value; - eprosima::fastcdr::optional unit_key_value; - eprosima::fastcdr::optional min_key_value; - eprosima::fastcdr::optional max_key_value; - eprosima::fastcdr::optional hash_id_key_value; - if (unit_key_value.has_value() || min_key_value.has_value() || max_key_value.has_value() || hash_id_key_value.has_value()) - { - member_ann_builtin_key_value = TypeObjectUtils::build_applied_builtin_member_annotations(unit_key_value, min_key_value, max_key_value, hash_id_key_value); - } - if (!tmp_ann_custom_key_value.empty()) - { - ann_custom_sample = tmp_ann_custom_key_value; - } - CompleteMemberDetail detail_key_value = TypeObjectUtils::build_complete_member_detail(name_key_value, member_ann_builtin_key_value, ann_custom_sample); - CompleteStructMember member_key_value = TypeObjectUtils::build_complete_struct_member(common_key_value, detail_key_value); - TypeObjectUtils::add_complete_struct_member(member_seq_sample, member_key_value); - } - CompleteStructType struct_type_sample = TypeObjectUtils::build_complete_struct_type(struct_flags_sample, header_sample, member_seq_sample); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_sample, type_name_sample.to_string(), type_ids_sample)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "sample already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/SampleConfig_Controller/sampleTypeObjectSupport.hpp b/examples/cpp/dds/SampleConfig_Controller/sampleTypeObjectSupport.hpp deleted file mode 100644 index 013609fa263..00000000000 --- a/examples/cpp/dds/SampleConfig_Controller/sampleTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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 sampleTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register sample related TypeIdentifier. - * 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_sample_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/examples/cpp/dds/SampleConfig_Events/samplePubSubTypes.cxx b/examples/cpp/dds/SampleConfig_Events/samplePubSubTypes.cxx deleted file mode 100644 index 321f250d975..00000000000 --- a/examples/cpp/dds/SampleConfig_Events/samplePubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// 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 samplePubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - -#include "samplePubSubTypes.h" - -#include -#include - -#include "sampleCdrAux.hpp" -#include "sampleTypeObjectSupport.hpp" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; -using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; - -samplePubSubType::samplePubSubType() -{ - setName("sample"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(sample::getMaxCdrSerializedSize()); -#else - sample_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = true; - uint32_t keyLength = sample_max_key_cdr_typesize > 16 ? sample_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -samplePubSubType::~samplePubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool samplePubSubType::serialize( - void* data, - SerializedPayload_t* payload, - DataRepresentationId_t data_representation) -{ - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool samplePubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function samplePubSubType::getSerializedSizeProvider( - void* data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* samplePubSubType::createData() -{ - return reinterpret_cast(new sample()); -} - -void samplePubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool samplePubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - sample_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || sample_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - 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; -} - -void samplePubSubType::register_type_object_representation() -{ - register_sample_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "sampleCdrAux.ipp" diff --git a/examples/cpp/dds/SampleConfig_Events/samplePubSubTypes.h b/examples/cpp/dds/SampleConfig_Events/samplePubSubTypes.h deleted file mode 100644 index 1ec6375ba7f..00000000000 --- a/examples/cpp/dds/SampleConfig_Events/samplePubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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 samplePubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "sample.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated sample is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type sample defined by the user in the IDL file. - * @ingroup sample - */ -class samplePubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef sample type; - - eProsima_user_DllExport samplePubSubType(); - - eProsima_user_DllExport ~samplePubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return true; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ - diff --git a/examples/cpp/dds/SampleConfig_Events/sampleTypeObjectSupport.cxx b/examples/cpp/dds/SampleConfig_Events/sampleTypeObjectSupport.cxx deleted file mode 100644 index e9dcd1a977b..00000000000 --- a/examples/cpp/dds/SampleConfig_Events/sampleTypeObjectSupport.cxx +++ /dev/null @@ -1,143 +0,0 @@ -// 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 sampleTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "sampleTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "sample.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_sample_type_identifier( - TypeIdentifierPair& type_ids_sample) -{ - - ReturnCode_t return_code_sample {eprosima::fastdds::dds::RETCODE_OK}; - return_code_sample = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "sample", type_ids_sample); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_sample) - { - StructTypeFlag struct_flags_sample = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_sample = "sample"; - eprosima::fastcdr::optional type_ann_builtin_sample; - eprosima::fastcdr::optional ann_custom_sample; - CompleteTypeDetail detail_sample = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_sample, ann_custom_sample, type_name_sample.to_string()); - CompleteStructHeader header_sample; - header_sample = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_sample); - CompleteStructMemberSeq member_seq_sample; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_byte", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_index = 0x00000000; - bool common_index_ec {false}; - CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; - if (!common_index_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); - return; - } - MemberName name_index = "index"; - eprosima::fastcdr::optional member_ann_builtin_index; - ann_custom_sample.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_sample); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_sample, member_index); - } - { - TypeIdentifierPair type_ids_key_value; - ReturnCode_t return_code_key_value {eprosima::fastdds::dds::RETCODE_OK}; - return_code_key_value = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_byte", type_ids_key_value); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_key_value) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "key_value Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_key_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, true, false); - MemberId member_id_key_value = 0x00000001; - bool common_key_value_ec {false}; - CommonStructMember common_key_value {TypeObjectUtils::build_common_struct_member(member_id_key_value, member_flags_key_value, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_key_value, common_key_value_ec))}; - if (!common_key_value_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure key_value member TypeIdentifier inconsistent."); - return; - } - MemberName name_key_value = "key_value"; - eprosima::fastcdr::optional member_ann_builtin_key_value; - ann_custom_sample.reset(); - AppliedAnnotationSeq tmp_ann_custom_key_value; - eprosima::fastcdr::optional unit_key_value; - eprosima::fastcdr::optional min_key_value; - eprosima::fastcdr::optional max_key_value; - eprosima::fastcdr::optional hash_id_key_value; - if (unit_key_value.has_value() || min_key_value.has_value() || max_key_value.has_value() || hash_id_key_value.has_value()) - { - member_ann_builtin_key_value = TypeObjectUtils::build_applied_builtin_member_annotations(unit_key_value, min_key_value, max_key_value, hash_id_key_value); - } - if (!tmp_ann_custom_key_value.empty()) - { - ann_custom_sample = tmp_ann_custom_key_value; - } - CompleteMemberDetail detail_key_value = TypeObjectUtils::build_complete_member_detail(name_key_value, member_ann_builtin_key_value, ann_custom_sample); - CompleteStructMember member_key_value = TypeObjectUtils::build_complete_struct_member(common_key_value, detail_key_value); - TypeObjectUtils::add_complete_struct_member(member_seq_sample, member_key_value); - } - CompleteStructType struct_type_sample = TypeObjectUtils::build_complete_struct_type(struct_flags_sample, header_sample, member_seq_sample); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_sample, type_name_sample.to_string(), type_ids_sample)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "sample already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/SampleConfig_Events/sampleTypeObjectSupport.hpp b/examples/cpp/dds/SampleConfig_Events/sampleTypeObjectSupport.hpp deleted file mode 100644 index 013609fa263..00000000000 --- a/examples/cpp/dds/SampleConfig_Events/sampleTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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 sampleTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register sample related TypeIdentifier. - * 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_sample_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/examples/cpp/dds/SampleConfig_Multimedia/samplePubSubTypes.cxx b/examples/cpp/dds/SampleConfig_Multimedia/samplePubSubTypes.cxx deleted file mode 100644 index 321f250d975..00000000000 --- a/examples/cpp/dds/SampleConfig_Multimedia/samplePubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// 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 samplePubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - -#include "samplePubSubTypes.h" - -#include -#include - -#include "sampleCdrAux.hpp" -#include "sampleTypeObjectSupport.hpp" - -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; -using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; - -samplePubSubType::samplePubSubType() -{ - setName("sample"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(sample::getMaxCdrSerializedSize()); -#else - sample_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = true; - uint32_t keyLength = sample_max_key_cdr_typesize > 16 ? sample_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -samplePubSubType::~samplePubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool samplePubSubType::serialize( - void* data, - SerializedPayload_t* payload, - DataRepresentationId_t data_representation) -{ - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool samplePubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function samplePubSubType::getSerializedSizeProvider( - void* data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* samplePubSubType::createData() -{ - return reinterpret_cast(new sample()); -} - -void samplePubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool samplePubSubType::getKey( - void* data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - sample* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - sample_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || sample_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - 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; -} - -void samplePubSubType::register_type_object_representation() -{ - register_sample_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "sampleCdrAux.ipp" diff --git a/examples/cpp/dds/SampleConfig_Multimedia/samplePubSubTypes.h b/examples/cpp/dds/SampleConfig_Multimedia/samplePubSubTypes.h deleted file mode 100644 index 1ec6375ba7f..00000000000 --- a/examples/cpp/dds/SampleConfig_Multimedia/samplePubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// 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 samplePubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "sample.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated sample is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type sample defined by the user in the IDL file. - * @ingroup sample - */ -class samplePubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef sample type; - - eProsima_user_DllExport samplePubSubType(); - - eProsima_user_DllExport ~samplePubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, - void* data) override; - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return true; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_SAMPLE_PUBSUBTYPES_H_ - diff --git a/examples/cpp/dds/SampleConfig_Multimedia/sampleTypeObjectSupport.cxx b/examples/cpp/dds/SampleConfig_Multimedia/sampleTypeObjectSupport.cxx deleted file mode 100644 index e9dcd1a977b..00000000000 --- a/examples/cpp/dds/SampleConfig_Multimedia/sampleTypeObjectSupport.cxx +++ /dev/null @@ -1,143 +0,0 @@ -// 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 sampleTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "sampleTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "sample.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_sample_type_identifier( - TypeIdentifierPair& type_ids_sample) -{ - - ReturnCode_t return_code_sample {eprosima::fastdds::dds::RETCODE_OK}; - return_code_sample = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "sample", type_ids_sample); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_sample) - { - StructTypeFlag struct_flags_sample = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::NOT_APPLIED, - false, false); - QualifiedTypeName type_name_sample = "sample"; - eprosima::fastcdr::optional type_ann_builtin_sample; - eprosima::fastcdr::optional ann_custom_sample; - CompleteTypeDetail detail_sample = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_sample, ann_custom_sample, type_name_sample.to_string()); - CompleteStructHeader header_sample; - header_sample = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_sample); - CompleteStructMemberSeq member_seq_sample; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_byte", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, false, false); - MemberId member_id_index = 0x00000000; - bool common_index_ec {false}; - CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))}; - if (!common_index_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent."); - return; - } - MemberName name_index = "index"; - eprosima::fastcdr::optional member_ann_builtin_index; - ann_custom_sample.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_sample); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_sample, member_index); - } - { - TypeIdentifierPair type_ids_key_value; - ReturnCode_t return_code_key_value {eprosima::fastdds::dds::RETCODE_OK}; - return_code_key_value = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_byte", type_ids_key_value); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_key_value) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "key_value Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_key_value = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructKind::NOT_APPLIED, - false, false, true, false); - MemberId member_id_key_value = 0x00000001; - bool common_key_value_ec {false}; - CommonStructMember common_key_value {TypeObjectUtils::build_common_struct_member(member_id_key_value, member_flags_key_value, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_key_value, common_key_value_ec))}; - if (!common_key_value_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure key_value member TypeIdentifier inconsistent."); - return; - } - MemberName name_key_value = "key_value"; - eprosima::fastcdr::optional member_ann_builtin_key_value; - ann_custom_sample.reset(); - AppliedAnnotationSeq tmp_ann_custom_key_value; - eprosima::fastcdr::optional unit_key_value; - eprosima::fastcdr::optional min_key_value; - eprosima::fastcdr::optional max_key_value; - eprosima::fastcdr::optional hash_id_key_value; - if (unit_key_value.has_value() || min_key_value.has_value() || max_key_value.has_value() || hash_id_key_value.has_value()) - { - member_ann_builtin_key_value = TypeObjectUtils::build_applied_builtin_member_annotations(unit_key_value, min_key_value, max_key_value, hash_id_key_value); - } - if (!tmp_ann_custom_key_value.empty()) - { - ann_custom_sample = tmp_ann_custom_key_value; - } - CompleteMemberDetail detail_key_value = TypeObjectUtils::build_complete_member_detail(name_key_value, member_ann_builtin_key_value, ann_custom_sample); - CompleteStructMember member_key_value = TypeObjectUtils::build_complete_struct_member(common_key_value, detail_key_value); - TypeObjectUtils::add_complete_struct_member(member_seq_sample, member_key_value); - } - CompleteStructType struct_type_sample = TypeObjectUtils::build_complete_struct_type(struct_flags_sample, header_sample, member_seq_sample); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_sample, type_name_sample.to_string(), type_ids_sample)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "sample already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/SampleConfig_Multimedia/sampleTypeObjectSupport.hpp b/examples/cpp/dds/SampleConfig_Multimedia/sampleTypeObjectSupport.hpp deleted file mode 100644 index 013609fa263..00000000000 --- a/examples/cpp/dds/SampleConfig_Multimedia/sampleTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 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 sampleTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register sample related TypeIdentifier. - * 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_sample_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // _FAST_DDS_GENERATED_SAMPLE_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/test/examples/content_filter.compose.yml b/test/examples/content_filter.compose.yml new file mode 100644 index 00000000000..f5aeac590c7 --- /dev/null +++ b/test/examples/content_filter.compose.yml @@ -0,0 +1,28 @@ +# Copyright 2024 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. +version: "3" + +services: + subscriber: + image: @DOCKER_IMAGE_NAME@ + volumes: + - @PROJECT_BINARY_DIR@:@PROJECT_BINARY_DIR@ + - @fastcdr_LIB_DIR@:@fastcdr_LIB_DIR@ + @TINYXML2_LIB_DIR_COMPOSE_VOLUME@ + environment: + # TODO(eduponz): LD_LIBRARY_PATH is not the correct variable for Windows + LD_LIBRARY_PATH: @PROJECT_BINARY_DIR@/src/cpp:@fastcdr_LIB_DIR@@TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH@ + EXAMPLE_DIR: @PROJECT_BINARY_DIR@/examples/cpp/content_filter@FILE_EXTENSION@ + SUBSCRIBER_ADDITIONAL_ARGUMENTS: ${SUB_ARGS} + command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/content_filter@FILE_EXTENSION@ subscriber $${SUBSCRIBER_ADDITIONAL_ARGUMENTS} --lower-bound 4 --upper-bound 8 --reliable --transient-local & $${EXAMPLE_DIR}/content_filter@FILE_EXTENSION@ publisher --samples 15 --interval 100 --reliable --transient-local" diff --git a/test/examples/custom_payload_pool.compose.yml b/test/examples/custom_payload_pool.compose.yml index 51255be654d..bbccefb3c2e 100644 --- a/test/examples/custom_payload_pool.compose.yml +++ b/test/examples/custom_payload_pool.compose.yml @@ -1,4 +1,16 @@ -# FASTDDS_TODO_BEFORE(3, 0, "This compose file should be used for the future configuration example"); +# Copyright 2024 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. version: "3" services: diff --git a/test/examples/test_configuration.py b/test/examples/test_configuration.py index 74abb86aa65..30dc10de7bd 100644 --- a/test/examples/test_configuration.py +++ b/test/examples/test_configuration.py @@ -14,6 +14,7 @@ import subprocess import pytest +import re config_test_cases = [ ('--keep-last 10 --transport DEFAULT', '--keep-last 10 --transport DEFAULT'), # Builtin transports diff --git a/test/examples/test_content_filter.py b/test/examples/test_content_filter.py new file mode 100644 index 00000000000..6925ffbe2d5 --- /dev/null +++ b/test/examples/test_content_filter.py @@ -0,0 +1,79 @@ +# Copyright 2024 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. + +import subprocess +import pytest +import re + +custom_filter_test_cases = [ + ('', True), + ('', False), + ('--reader-filters 0', True), + ('--reader-filters 0', False)] +@pytest.mark.parametrize("pub_reader_filters, sub_custom_filter", custom_filter_test_cases) +def test_content_filter(pub_reader_filters, sub_custom_filter): + """.""" + ret = False + out = '' + if (sub_custom_filter): + command_prerequisites = 'PUB_ARGS="' + ' ' + pub_reader_filters + '" SUB_ARGS="' + ' --filter-kind custom" ' + else: + command_prerequisites = 'PUB_ARGS="' + ' ' + pub_reader_filters + '" SUB_ARGS="' + ' --filter-kind default" ' + + try: + out = subprocess.check_output(command_prerequisites + + '@DOCKER_EXECUTABLE@ compose -f content_filter.compose.yml up', + stderr=subprocess.STDOUT, + shell=True, + timeout=30 + ).decode().split('\n') + + sent = 0 + received = 0 + data = [] + for line in out: + if 'SENT' in line: + sent += 1 + continue + + if 'RECEIVED' in line: + received += 1 + match = re.search(r'index:\s+(\d+)', line) + if match: + number = int(match.group(1)) + data.append(number) + continue + + ret = True + if sent != 0 and received != 0: + for elem in data: + if (sub_custom_filter): + if not (elem < 3 and elem > 8): + ret = False + else: + if not (elem >= 4 or elem <= 8): + ret = False + else: + print('ERROR: sent: ' + str(sent) + ', received: ' + str(received) + + ' but data are out of the filtered range') + raise subprocess.CalledProcessError(1, '') + + except subprocess.CalledProcessError: + for l in out: + print(l) + except subprocess.TimeoutExpired: + print('TIMEOUT') + print(out) + + assert(ret) diff --git a/test/examples/test_custom_payload_pool.py b/test/examples/test_custom_payload_pool.py index d0173bf28e6..431599d1c75 100644 --- a/test/examples/test_custom_payload_pool.py +++ b/test/examples/test_custom_payload_pool.py @@ -1,3 +1,17 @@ +# Copyright 2024 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. + import subprocess import pytest def test_custom_payload_pool(): diff --git a/versions.md b/versions.md index e38b5bb94a4..42bd14fc5a7 100644 --- a/versions.md +++ b/versions.md @@ -43,6 +43,7 @@ Forthcoming * Configuration example that condenses multiple QoS examples. Multiple configurations allowed through argument parsing. * Custom payload pool example that uses a user-defined payload pool instead of the default * X-Types example with dynamic type discovery and Hello world example compatibility. + * Custom Content filter example * Removed `TypeConsistencyQos` from DataReader, and included `TypeConsistencyEnforcementQosPolicy` and `DataRepresentationQosPolicy` * Added new `flow_controller_descriptor_list` XML configuration, remove `ThroughtputController`. * Migrate `#define`s within `BuiltinEndpoints.hpp` to namespaced `constexpr` variables.