diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e891987f1e..16ed27b32b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -14,6 +14,7 @@ set(fastdds_FOUND TRUE) +add_subdirectory(cpp/benchmark) add_subdirectory(cpp/configuration) add_subdirectory(cpp/content_filter) add_subdirectory(cpp/custom_payload_pool) diff --git a/examples/cpp/benchmark/Application.cpp b/examples/cpp/benchmark/Application.cpp new file mode 100644 index 0000000000..808d84af0c --- /dev/null +++ b/examples/cpp/benchmark/Application.cpp @@ -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.cpp + * + */ + +#include "Application.hpp" + +#include "SubscriberApp.hpp" +#include "PublisherApp.hpp" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace benchmark { + +//! Factory method to create a publisher or subscriber +std::shared_ptr Application::make_app( + const CLIParser::benchmark_config& config) +{ + std::shared_ptr entity; + switch (config.entity) + { + case CLIParser::EntityKind::PUBLISHER: + entity = std::make_shared(config.pub_config); + break; + case CLIParser::EntityKind::SUBSCRIBER: + entity = std::make_shared(config.sub_config); + break; + case CLIParser::EntityKind::UNDEFINED: + default: + throw std::runtime_error("Entity initialization failed"); + break; + } + return entity; +} + +} // namespace benchmark +} // namespace examples +} // namespace fastdds +} // namespace eprosima diff --git a/examples/cpp/benchmark/Application.hpp b/examples/cpp/benchmark/Application.hpp new file mode 100644 index 0000000000..803a52ab1c --- /dev/null +++ b/examples/cpp/benchmark/Application.hpp @@ -0,0 +1,55 @@ +// 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_EXAMPLES_CPP_BENCHMARK__APPLICATION_HPP +#define FASTDDS_EXAMPLES_CPP_BENCHMARK__APPLICATION_HPP + +#include + +#include "CLIParser.hpp" + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace benchmark { + +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::benchmark_config& config); +}; + +} // namespace benchmark +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_EXAMPLES_CPP_BENCHMARK__APPLICATION_HPP diff --git a/examples/cpp/benchmark/CLIParser.hpp b/examples/cpp/benchmark/CLIParser.hpp new file mode 100644 index 0000000000..b99742065f --- /dev/null +++ b/examples/cpp/benchmark/CLIParser.hpp @@ -0,0 +1,570 @@ +// 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 +#include +#include + +#ifndef FASTDDS_EXAMPLES_CPP_BENCHMARK__CLIPARSER_HPP +#define FASTDDS_EXAMPLES_CPP_BENCHMARK__CLIPARSER_HPP + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace benchmark { + +using namespace eprosima::fastdds::dds; +using dds::Log; + +class CLIParser +{ + +public: + + CLIParser() = delete; + + //! Entity kind enumeration + enum class EntityKind : uint8_t + { + PUBLISHER, + SUBSCRIBER, + UNDEFINED + }; + + //! Message size kind enumeration + enum class MsgSizeKind : uint8_t + { + NONE, + SMALL, + MEDIUM, + BIG + }; + + //! Entity benchmark structure (shared for both publisher and subscriber applications) + struct entity_config + { + uint8_t ttl = 1; + uint32_t domain = 0; + std::string topic_name = "benchmark_topic"; + uint16_t samples = 0; + eprosima::fastdds::rtps::BuiltinTransports transport = eprosima::fastdds::rtps::BuiltinTransports::DEFAULT; + ReliabilityQosPolicyKind reliability = ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS; + DurabilityQosPolicyKind durability = DurabilityQosPolicyKind::VOLATILE_DURABILITY_QOS; + CLIParser::MsgSizeKind msg_size = CLIParser::MsgSizeKind::NONE; + }; + + //! Publisher application benchmark structure + struct publisher_config : public entity_config + { + uint16_t interval = 100; + uint16_t timeout = 10000; + }; + + //! Subscriber application benchmark structure + struct subscriber_config : public entity_config + { + }; + + //! Benchmark structure for the application + struct benchmark_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: benchmark [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 << " -d , --domain Domain ID number [0 <= <= 232]" << std::endl; + std::cout << " (Default: 0)" << std::endl; + std::cout << " -n , --name Custom topic name" << std::endl; + std::cout << " (Default: benchmark_topic)" << std::endl; + std::cout << " -r, --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 << " -m , --msg-size Size of the message" << std::endl; + std::cout << " · NONE: Only an int value" << std::endl; + std::cout << " · SMALL: int value + array of 16Kb" << std::endl; + std::cout << " · MEDIUM: int value + array of 512Kb" << std::endl; + std::cout << " · BIG: int value + array of 8Mb" << std::endl; + std::cout << " (Default: NONE)" << std::endl; + std::cout << " -s , --samples Number of samples to send/receive" << std::endl; + std::cout << " If a value is given timeout is ignore" << std::endl; + std::cout << " [0 <= <= 65535]" << std::endl; + std::cout << " (Default: 0 [unlimited])" << std::endl; + std::cout << " -t , --transport Select builtin transport :" << std::endl; + std::cout << " · DEFAULT: SHM & UDPv4 (SHM prior UDP)" << std::endl; + std::cout << " · SHM: Shared Memory Transport only" << std::endl; + std::cout << " · UDPv4: UDP over IPv4 only" << std::endl; + std::cout << " · LARGE_DATA: Large data mode" << std::endl; + std::cout << " (refer to Fast DDS documentation)" << std::endl; + std::cout << " (Default: DEFAULT)" << std::endl; + std::cout << " --ttl Number of multicast discovery Time To Live" << std::endl; + std::cout << " hops [0 <= <= 255]" << std::endl; + std::cout << " (Default: 1)" << std::endl; + std::cout << "" << std::endl; + std::cout << "Publisher options:" << std::endl; + std::cout << " -i , --interval Time between samples in milliseconds" << std::endl; + std::cout << " [1 <= <= 4294967]" << std::endl; + std::cout << " (Default: 100 [0.1s])" << std::endl; + std::cout << " -to , --timeout Time running the example in milliseconds" << std::endl; + std::cout << " [1 <= <= 4294967]" << std::endl; + std::cout << " (Default: 10000 [10s])" << std::endl; + std::cout << "" << std::endl; + std::exit(return_code); + } + + /** + * @brief Parse the command line options and return the benchmark_config object + * + * @param argc number of arguments + * @param argv array of arguments + * @return benchmark_config object with the parsed options + * + * @warning This method finishes the execution of the program if the input arguments are invalid + */ + static benchmark_config parse_cli_options( + int argc, + char* argv[]) + { + benchmark_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); + } + + // max value allowed taking into account that the input is receiving millisecond values + uint32_t max_duration = static_cast(floor(std::numeric_limits::max() * 1e-3)); // = 4294967 + + for (int i = 2; i < argc; ++i) + { + std::string arg = argv[i]; + + if (arg == "-h" || arg == "--help") + { + print_help(EXIT_SUCCESS); + } + else if (arg == "-d" || arg == "--domain") + { + if (++i < argc) + { + try + { + int input = std::stoi(argv[i]); + if (input < 0 || input > 232) + { + throw std::out_of_range("domain argument " + std::string( + argv[i]) + " out of range [0, 232]."); + } + else + { + config.pub_config.domain = static_cast(input); + config.sub_config.domain = static_cast(input); + } + } + catch (const std::invalid_argument& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid domain argument " + std::string( + argv[i]) + ": " + std::string(e.what())); + print_help(EXIT_FAILURE); + } + catch (const std::out_of_range& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, std::string(e.what())); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing domain argument"); + print_help(EXIT_FAILURE); + } + } + else if (arg == "-n" || arg == "--name") + { + if (++i < argc) + { + config.pub_config.topic_name = argv[i]; + config.sub_config.topic_name = argv[i]; + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing name argument"); + print_help(EXIT_FAILURE); + } + } + else if (arg == "-r" || arg == "--reliable") + { + config.pub_config.reliability = ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS; + config.sub_config.reliability = ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS; + } + else if (arg == "-m" || arg == "--msg-size") + { + if (++i < argc) + { + std::string size = argv[i]; + if (size == "NONE") + { + config.pub_config.msg_size = CLIParser::MsgSizeKind::NONE; + config.sub_config.msg_size = CLIParser::MsgSizeKind::NONE; + } + else if (size == "SMALL") + { + config.pub_config.msg_size = CLIParser::MsgSizeKind::SMALL; + config.sub_config.msg_size = CLIParser::MsgSizeKind::SMALL; + } + else if (size == "MEDIUM") + { + config.pub_config.msg_size = CLIParser::MsgSizeKind::MEDIUM; + config.sub_config.msg_size = CLIParser::MsgSizeKind::MEDIUM; + } + else if (size == "BIG") + { + config.pub_config.msg_size = CLIParser::MsgSizeKind::BIG; + config.sub_config.msg_size = CLIParser::MsgSizeKind::BIG; + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid msg_size argument " + std::string( + argv[i]) + ": " + std::string("valid values are NONE, SMALL, MEDIUM, BIG")); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing msg_size argument"); + print_help(EXIT_FAILURE); + } + } + 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) + { + config.sub_config.samples = static_cast(input); + } + 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 == "-t" || arg == "--transport") + { + if (++i < argc) + { + std::string transport = argv[i]; + if (transport == "DEFAULT") + { + config.pub_config.transport = eprosima::fastdds::rtps::BuiltinTransports::DEFAULT; + config.sub_config.transport = eprosima::fastdds::rtps::BuiltinTransports::DEFAULT; + } + else if (transport == "SHM") + { + config.pub_config.transport = eprosima::fastdds::rtps::BuiltinTransports::SHM; + config.sub_config.transport = eprosima::fastdds::rtps::BuiltinTransports::SHM; + } + else if (transport == "UDPv4") + { + config.pub_config.transport = eprosima::fastdds::rtps::BuiltinTransports::UDPv4; + config.sub_config.transport = eprosima::fastdds::rtps::BuiltinTransports::UDPv4; + } + else if (transport == "LARGE_DATA") + { + config.pub_config.transport = eprosima::fastdds::rtps::BuiltinTransports::LARGE_DATA; + config.sub_config.transport = eprosima::fastdds::rtps::BuiltinTransports::LARGE_DATA; + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing transport argument"); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing transport argument"); + print_help(EXIT_FAILURE); + } + } + else if (arg == "--ttl") + { + if (++i < argc) + { + try + { + int input = std::stoi(argv[i]); + if (input < 0 || input > 255) + { + throw std::out_of_range("ttl argument " + std::string( + argv[i]) + " out of range [0, 255]."); + } + else + { + config.pub_config.ttl = static_cast(input); + config.sub_config.ttl = static_cast(input); + } + } + catch (const std::invalid_argument& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid ttl argument " + std::string( + argv[i]) + ": " + std::string(e.what())); + print_help(EXIT_FAILURE); + } + catch (const std::out_of_range& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, std::string(e.what())); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing ttl argument"); + print_help(EXIT_FAILURE); + } + } + else if (arg == "-i" || arg == "--interval") + { + if (config.entity == CLIParser::EntityKind::PUBLISHER) + { + if (++i < argc) + { + try + { + int input = std::stoi(argv[i]); + if (input < 1 || static_cast(input) > static_cast(max_duration)) + { + throw std::out_of_range("interval argument " + std::string( + argv[i]) + " out of range [1, " + std::to_string( + max_duration) + "]."); + } + else + { + config.pub_config.interval = static_cast(input); + } + } + catch (const std::invalid_argument& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid interval argument " + std::string( + argv[i]) + ": " + std::string(e.what())); + print_help(EXIT_FAILURE); + } + catch (const std::out_of_range& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, std::string(e.what())); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing interval argument"); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "interval argument is only valid for publisher entity"); + print_help(EXIT_FAILURE); + } + } + else if (arg == "-to" || arg == "--timeout") + { + if (config.entity == CLIParser::EntityKind::PUBLISHER) + { + if (++i < argc) + { + try + { + int input = std::stoi(argv[i]); + if (input < 1 || static_cast(input) > static_cast(max_duration)) + { + throw std::out_of_range("end argument " + std::string( + argv[i]) + " out of range [1, " + std::to_string( + max_duration) + "]."); + } + else + { + config.pub_config.timeout = static_cast(input); + } + } + catch (const std::invalid_argument& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid end argument " + std::string( + argv[i]) + ": " + std::string(e.what())); + print_help(EXIT_FAILURE); + } + catch (const std::out_of_range& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, std::string(e.what())); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing end argument"); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "end argument is only valid for publisher entity"); + print_help(EXIT_FAILURE); + } + } + else if (arg == "--transient-local") + { + config.pub_config.durability = DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS; + config.sub_config.durability = DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS; + + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing argument: " + 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 benchmark +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_EXAMPLES_CPP_BENCHMARK__CLIPARSER_HPP diff --git a/examples/cpp/benchmark/CMakeLists.txt b/examples/cpp/benchmark/CMakeLists.txt new file mode 100644 index 0000000000..912e2dcfca --- /dev/null +++ b/examples/cpp/benchmark/CMakeLists.txt @@ -0,0 +1,73 @@ +# 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. + +cmake_minimum_required(VERSION 3.20) + +project(fastdds_benchamrk_example VERSION 1 LANGUAGES CXX) + +# Find requirements +if(NOT fastcdr_FOUND) + find_package(fastcdr 2 REQUIRED) +endif() + +if(NOT fastdds_FOUND) + find_package(fastdds 3 REQUIRED) +endif() + +#Check C++11 +include(CheckCXXCompilerFlag) +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + check_cxx_compiler_flag(-std=c++11 SUPPORTS_CXX11) + if(NOT SUPPORTS_CXX11) + message(FATAL_ERROR "Compiler doesn't support C++11") + endif() +endif() + +# Set CMAKE_BUILD_TYPE to Release by default. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to 'Release' as none was specified.") + set(CMAKE_BUILD_TYPE Release CACHE STRING + "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." + FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif() + +message(STATUS "Configuring benchmark example...") +file(GLOB BENCHMARK_SOURCES_CXX "types/*.cxx") +file(GLOB BENCHMARK_SOURCES_CPP "*.cpp") + +add_executable(benchmark ${BENCHMARK_SOURCES_CXX} ${BENCHMARK_SOURCES_CPP}) +target_compile_definitions(benchmark PRIVATE + $<$>,$>:__DEBUG> + $<$:__INTERNALDEBUG> # Internal debug activated. + $<$:SHM_TRANSPORT_BUILTIN> # Enable SHM as built-in transport +) +target_link_libraries(benchmark fastdds fastcdr) +install(TARGETS benchmark + RUNTIME DESTINATION ${DATA_INSTALL_DIR}/fastdds/examples/cpp/benchmark/${BIN_INSTALL_DIR}) + +# Copy the XML files over to the build directory +file(GLOB_RECURSE XML_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.xml) +# for each xml file detected +foreach(XML_FILE_COMPLETE_PATH ${XML_FILES}) + # obtain the file name + get_filename_component(XML_FILE ${XML_FILE_COMPLETE_PATH} NAME_WE) + # copy the file from src to build folders + configure_file( + ${XML_FILE_COMPLETE_PATH} # from full src path + ${CMAKE_CURRENT_BINARY_DIR}/${XML_FILE}.xml # to relative build path + COPYONLY) + install(FILES ${XML_FILE_COMPLETE_PATH} + DESTINATION ${DATA_INSTALL_DIR}/fastdds/examples/cpp/benchmark/${BIN_INSTALL_DIR}) +endforeach() diff --git a/examples/cpp/benchmark/PublisherApp.cpp b/examples/cpp/benchmark/PublisherApp.cpp new file mode 100644 index 0000000000..092c18898d --- /dev/null +++ b/examples/cpp/benchmark/PublisherApp.cpp @@ -0,0 +1,527 @@ +// 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 +#include +#include +#include + +#include "types/BenchmarkPubSubTypes.hpp" +#include "types/Benchmark_smallPubSubTypes.hpp" +#include "types/Benchmark_mediumPubSubTypes.hpp" +#include "types/Benchmark_bigPubSubTypes.hpp" + +using namespace eprosima::fastdds::dds; +using namespace eprosima::fastdds::rtps; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace benchmark { + +PublisherApp::PublisherApp( + const CLIParser::publisher_config& config) + : participant_(nullptr) + , publisher_(nullptr) + , topic_pub_(nullptr) + , writer_(nullptr) + , subscriber_(nullptr) + , topic_sub_(nullptr) + , reader_(nullptr) + , type_(nullptr) + , matched_(0) + , samples_(config.samples) + , period_ms_(config.interval) + , timeout_(config.timeout) + , stop_(false) + , msg_size_(config.msg_size) + , count(0) + , vSamples(0) + , startTime(std::chrono::steady_clock::now()) +{ + + if (samples_ > 0) + { + timeout_ = 0; + } + // Create the participant + DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT; + pqos.name("Benchmark_pub_participant"); + auto factory = DomainParticipantFactory::get_instance(); + // Include Participant QoS + pqos.setup_transports(config.transport); + for (auto& transportDescriptor : pqos.transport().user_transports) + { + SocketTransportDescriptor* pT = dynamic_cast(transportDescriptor.get()); + if (pT) + { + pT->TTL = config.ttl; + } + } + participant_ = factory->create_participant(config.domain, pqos); + if (participant_ == nullptr) + { + throw std::runtime_error("Participant initialization failed"); + } + + // Register and set up the data type with initial values + if (msg_size_ == CLIParser::MsgSizeKind::NONE) + { + benchmark_.index(0); + type_ = TypeSupport(new BenchMarkPubSubType()); + } + else if (msg_size_ == CLIParser::MsgSizeKind::SMALL) + { + benchmark_small_.index(0); + type_ = TypeSupport(new BenchMarkSmallPubSubType()); + } + else if (msg_size_ == CLIParser::MsgSizeKind::MEDIUM) + { + benchmark_medium_.index(0); + type_ = TypeSupport(new BenchMarkMediumPubSubType()); + } + else if (msg_size_ == CLIParser::MsgSizeKind::BIG) + { + benchmark_big_.index(0); + type_ = TypeSupport(new BenchMarkBigPubSubType()); + } + else + { + throw std::runtime_error("Type initialization failed"); + } + type_.register_type(participant_); + + // Create the publisher + PublisherQos pub_qos = PUBLISHER_QOS_DEFAULT; + participant_->get_default_publisher_qos(pub_qos); + publisher_ = participant_->create_publisher(pub_qos, nullptr, StatusMask::none()); + if (publisher_ == nullptr) + { + throw std::runtime_error("Publisher initialization failed"); + } + + // Create the topics + TopicQos topic_qos = TOPIC_QOS_DEFAULT; + participant_->get_default_topic_qos(topic_qos); + topic_pub_ = participant_->create_topic(config.topic_name + "_1", type_.get_type_name(), topic_qos); + topic_sub_ = participant_->create_topic(config.topic_name + "_2", type_.get_type_name(), topic_qos); + if (topic_pub_ == nullptr) + { + throw std::runtime_error("Topic initialization failed"); + } + + // Create the data writer + DataWriterQos writer_qos = DATAWRITER_QOS_DEFAULT; + writer_qos.reliability().kind = config.reliability; + writer_qos.durability().kind = config.durability; + publisher_->get_default_datawriter_qos(writer_qos); + writer_ = publisher_->create_datawriter(topic_pub_, writer_qos, this, StatusMask::all()); + if (writer_ == nullptr) + { + throw std::runtime_error("DataWriter initialization failed"); + } + + // Create the subscriber + SubscriberQos sub_qos = SUBSCRIBER_QOS_DEFAULT; + participant_->get_default_subscriber_qos(sub_qos); + subscriber_ = participant_->create_subscriber(sub_qos, nullptr, StatusMask::none()); + if (subscriber_ == nullptr) + { + throw std::runtime_error("Subscriber initialization failed"); + } + + // Create the data reader + DataReaderQos reader_qos = DATAREADER_QOS_DEFAULT; + subscriber_->get_default_datareader_qos(reader_qos); + reader_qos.reliability().kind = config.reliability; + reader_qos.durability().kind = config.durability; + reader_ = subscriber_->create_datareader(topic_sub_, reader_qos, this, StatusMask::all()); + if (reader_ == nullptr) + { + throw std::runtime_error("DataReader initialization failed"); + } +} + +PublisherApp::~PublisherApp() +{ + if (nullptr != participant_) + { + // 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* /*writer*/, + const PublicationMatchedStatus& info) +{ + if (info.current_count_change == 1) + { + startTime = std::chrono::steady_clock::now(); + std::cout << "Publisher matched." << std::endl; + matched_++; + 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::on_subscription_matched( + DataReader* /*reader*/, + const SubscriptionMatchedStatus& info) +{ + if (info.current_count_change == 1) + { + std::cout << "Subscriber matched." << std::endl; + matched_++; + cv_.notify_one(); + } + else if (info.current_count_change == -1) + { + std::cout << "Subscriber unmatched." << std::endl; + } + else + { + std::cout << info.current_count_change + << " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl; + } +} + +void PublisherApp::on_data_available( + DataReader* reader) +{ + SampleInfo info; + + auto actualTime = std::chrono::steady_clock::now(); + auto elapsed = std::chrono::duration_cast(actualTime - startTime); + + switch (msg_size_) + { + case CLIParser::MsgSizeKind::NONE: + while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&benchmark_, &info))) + { + if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) + { + std::cout << "Sample with index: '" << + benchmark_.index() << "' (Array 0 Bytes) RECEIVED" << std::endl; + if ((elapsed.count() >= timeout_ && timeout_ != 0) || (count >= samples_ && samples_ != 0)) + { + cv_.notify_one(); + return; + } + + benchmark_.index(benchmark_.index() + 1); + count = benchmark_.index() + 1; + + if ((RETCODE_OK == writer_->write(&benchmark_)) == true) + { + std::cout << "Sample with index: '" << + benchmark_.index() << "' (Array 0 Bytes) SENT" << std::endl; + } + } + } + break; + + case CLIParser::MsgSizeKind::SMALL: + while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&benchmark_small_, &info))) + { + if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) + { + std::cout << "Sample with index: '" << + benchmark_small_.index() << "' (Array " << static_cast(benchmark_small_.array().size()) << + " Bytes) RECEIVED" << std::endl; + if ((elapsed.count() >= timeout_ && timeout_ != 0) || (count >= samples_ && samples_ != 0)) + { + cv_.notify_one(); + return; + } + + benchmark_small_.index(benchmark_small_.index() + 1); + count = benchmark_small_.index() + 1; + + if ((RETCODE_OK == writer_->write(&benchmark_small_)) == true) + { + std::cout << "Sample with index: '" << + benchmark_small_.index() << "' (Array " << + static_cast(benchmark_small_.array().size()) << + " Bytes) SENT" << std::endl; + } + } + } + break; + + case CLIParser::MsgSizeKind::MEDIUM: + while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&benchmark_medium_, &info))) + { + if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) + { + std::cout << "Sample with index: '" << + benchmark_medium_.index() << "' (Array " << + static_cast(benchmark_medium_.data().size()) << + " Bytes) RECEIVED" << std::endl; + if ((elapsed.count() >= timeout_ && timeout_ != 0) || (count >= samples_ && samples_ != 0)) + { + cv_.notify_one(); + return; + } + + benchmark_medium_.index(benchmark_medium_.index() + 1); + count = benchmark_medium_.index() + 1; + + if ((RETCODE_OK == writer_->write(&benchmark_medium_)) == true) + { + std::cout << "Sample with index: '" << + benchmark_medium_.index() << "' (Array " << + static_cast(benchmark_medium_.data().size()) << + " Bytes) SENT" << std::endl; + } + } + } + break; + + case CLIParser::MsgSizeKind::BIG: + while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&benchmark_big_, &info))) + { + if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) + { + std::cout << "Sample with index: '" << + benchmark_big_.index() << "' (Array " << static_cast(benchmark_big_.data().size()) << + " Bytes) RECEIVED" << std::endl; + if ((elapsed.count() >= timeout_ && timeout_ != 0) || (count >= samples_ && samples_ != 0)) + { + cv_.notify_one(); + return; + } + + benchmark_big_.index(benchmark_big_.index() + 1); + count = benchmark_big_.index() + 1; + + if ((RETCODE_OK == writer_->write(&benchmark_big_)) == true) + { + std::cout << "Sample with index: '" << + benchmark_big_.index() << "' (Array " << static_cast(benchmark_big_.data().size()) << + " Bytes) SENT" << std::endl; + } + } + } + break; + + default: + throw std::runtime_error("Type invalid"); + } +} + +void PublisherApp::run() +{ + { + // Wait for the data endpoints discovery + std::unique_lock matched_lock(mutex_); + cv_.wait(matched_lock, [&]() + { + // at least one has been discovered + return ((matched_ >= 2) || is_stopped()); + }); + } + publish(); + + uint16_t prevCount = 0; + + auto actualTime = std::chrono::steady_clock::now(); + auto elapsed = std::chrono::duration_cast(actualTime - startTime); + while (!is_stopped() && (elapsed.count() < timeout_ || timeout_ == 0) && (samples_ == 0 || count < samples_)) + { + // Wait for period or stop event + std::unique_lock periodic_lock(mutex_); + cv_.wait_for(periodic_lock, std::chrono::milliseconds(period_ms_), [&]() + { + return is_stopped(); + }); + vSamples.push_back(static_cast(count) - prevCount); + prevCount = static_cast(count); + actualTime = std::chrono::steady_clock::now(); + elapsed = std::chrono::duration_cast(actualTime - startTime); + } + std::cout << "RESULTS after " << elapsed.count() << " milliseconds:" << std::endl; + switch (msg_size_) + { + case CLIParser::MsgSizeKind::NONE: + std::cout << "COUNT: " << benchmark_.index() << std::endl; + break; + + case CLIParser::MsgSizeKind::SMALL: + std::cout << "COUNT: " << benchmark_small_.index() << std::endl; + break; + + case CLIParser::MsgSizeKind::MEDIUM: + std::cout << "COUNT: " << benchmark_medium_.index() << std::endl; + break; + + case CLIParser::MsgSizeKind::BIG: + std::cout << "COUNT: " << benchmark_big_.index() << std::endl; + break; + + default: + throw std::runtime_error("Type invalid"); + } + std::cout << "SAMPLES: "; + for (uint16_t i = 0; i < vSamples.size(); ++i) + { + std::cout << vSamples[i] << ","; + } + std::cout << std::endl; + std::cout << "THROUGHPUT BPS(Bytes per Second): "; + double mean_bps = static_cast(count) / (elapsed.count() / 1000.0); + switch (msg_size_) + { + case CLIParser::MsgSizeKind::NONE: + mean_bps = mean_bps * 4; + break; + + case CLIParser::MsgSizeKind::SMALL: + mean_bps = mean_bps * (4 + benchmark_small_.array().size()); + break; + + case CLIParser::MsgSizeKind::MEDIUM: + mean_bps = mean_bps * (4 + benchmark_medium_.data().size()); + break; + + case CLIParser::MsgSizeKind::BIG: + mean_bps = mean_bps * (4 + benchmark_big_.data().size()); + break; + + default: + throw std::runtime_error("Type invalid"); + } + if (mean_bps >= 1e9) + { + std::cout << mean_bps / 1e9 << " Gbps" << std::endl; + } + else if (mean_bps >= 1e6) + { + std::cout << mean_bps / 1e6 << " Mbps" << std::endl; + } + else if (mean_bps >= 1e3) + { + std::cout << mean_bps / 1e3 << " Kbps" << std::endl; + } + else + { + std::cout << mean_bps << " bps" << std::endl; + } +} + +bool PublisherApp::publish() +{ + bool ret = false; + if (!is_stopped()) + { + switch (msg_size_) + { + case CLIParser::MsgSizeKind::NONE: + benchmark_.index(0); + ret = (RETCODE_OK == writer_->write(&benchmark_)); + if (ret == true) + { + std::cout << "First Sample with index: '" + << benchmark_.index() << "'(Array 0 Bytes) SENT" << std::endl; + } + break; + + case CLIParser::MsgSizeKind::SMALL: + benchmark_small_.index(0); + ret = (RETCODE_OK == writer_->write(&benchmark_small_)); + if (ret == true) + { + std::cout << "First Sample with index: '" + << benchmark_small_.index() << "' (Array " << + static_cast(benchmark_small_.array().size()) + << " Bytes) SENT" << std::endl; + } + break; + + case CLIParser::MsgSizeKind::MEDIUM: + benchmark_medium_.index(0); + ret = (RETCODE_OK == writer_->write(&benchmark_medium_)); + if (ret == true) + { + std::cout << "First Sample with index: '" + << benchmark_medium_.index() << "' (Array " << + static_cast(benchmark_medium_.data().size()) + << " Bytes) SENT" << std::endl; + } + break; + + case CLIParser::MsgSizeKind::BIG: + benchmark_big_.index(0); + ret = (RETCODE_OK == writer_->write(&benchmark_big_)); + if (ret == true) + { + std::cout << "First Sample with index: '" + << benchmark_big_.index() << "' (Array " << + static_cast(benchmark_big_.data().size()) + << " Bytes) SENT" << std::endl; + } + break; + + default: + throw std::runtime_error("Type invalid"); + } + } + return ret; +} + +bool PublisherApp::is_stopped() +{ + return stop_.load(); +} + +void PublisherApp::stop() +{ + stop_.store(true); + cv_.notify_one(); +} + +} // namespace benchmark +} // namespace examples +} // namespace fastdds +} // namespace eprosima diff --git a/examples/cpp/benchmark/PublisherApp.hpp b/examples/cpp/benchmark/PublisherApp.hpp new file mode 100644 index 0000000000..1bdc6b8d6f --- /dev/null +++ b/examples/cpp/benchmark/PublisherApp.hpp @@ -0,0 +1,135 @@ +// 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_EXAMPLES_CPP_BENCHMARK__PUBLISHERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_BENCHMARK__PUBLISHERAPP_HPP + +#include +#include + +#include +#include +#include +#include +#include + +#include "Application.hpp" +#include "CLIParser.hpp" +#include "types/Benchmark.hpp" +#include "types/Benchmark_small.hpp" +#include "types/Benchmark_medium.hpp" +#include "types/Benchmark_big.hpp" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace benchmark { + +class PublisherApp : public Application, public DataWriterListener, public DataReaderListener +{ +public: + + PublisherApp( + const CLIParser::publisher_config& config); + + ~PublisherApp(); + + //! Publisher matched method + void on_publication_matched( + DataWriter* writer, + const PublicationMatchedStatus& info) override; + + //! Subscriber matched method + void on_subscription_matched( + DataReader* reader, + const SubscriptionMatchedStatus& info) override; + + //! Subscription callback + void on_data_available( + DataReader* reader) 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(); + + BenchMark benchmark_; + + BenchMarkSmall benchmark_small_; + + BenchMarkMedium benchmark_medium_; + + BenchMarkBig benchmark_big_; + + DomainParticipant* participant_; + + Publisher* publisher_; + + Topic* topic_pub_; + + DataWriter* writer_; + + Subscriber* subscriber_; + + Topic* topic_sub_; + + DataReader* reader_; + + TypeSupport type_; + + int16_t matched_; + + uint16_t samples_; + + std::mutex mutex_; + + uint16_t period_ms_; + + uint16_t timeout_; + + std::condition_variable cv_; + + std::atomic stop_; + + CLIParser::MsgSizeKind msg_size_; + + std::atomic_uint count; + + std::vector vSamples; + + std::chrono::time_point startTime; +}; + +} // namespace benchmark +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_EXAMPLES_CPP_BENCHMARK__PUBLISHERAPP_HPP diff --git a/examples/cpp/benchmark/README.md b/examples/cpp/benchmark/README.md new file mode 100644 index 0000000000..28afcbc642 --- /dev/null +++ b/examples/cpp/benchmark/README.md @@ -0,0 +1,296 @@ +# Benchmark example + +The *eProsima Fast DDS benchmark* example is a simple application intended to demonstrate a basic DDS deployment. + +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 *benchmark* example allows to select between different messages sizes and configurations to show how the DDS transport is carried and how many package are sent in each case. + +* [Description of the example](#description-of-the-example) +* [Run the example](#run-the-example) +* [Configuration](#configuration) +* [XML profile playground](#xml-profile-playground) + +## Description of the example + +Each example application (publisher and subscriber) creates the required DDS entities per case. +Both publisher and subscriber inherit from the corresponding listener class, overriding the listener's method associated to each event. +When an event occurs, the callback method is triggered. + +If the environment does not specify the expected configuration, they take the default configuration per entity. + +Moreover, this example extends the configuration options and message type size to showcase the results on the amount of messages transported during each sample time of the whole example duration for these conditions. + +## 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. + +### Benchmark publisher + +* Ubuntu ( / MacOS ) + + ```shell + user@machine:example_path$ ./benchmark publisher + Publisher running for 10000 milliseconds. Please press Ctrl+C to stop the Publisher at any time. + ``` + +* Windows + + ```powershell + example_path> benchmark.exe publisher + Publisher running for 10000 milliseconds. Please press Ctrl+C to stop the Publisher at any time. + ``` + +### Benchmark subscriber + +* Ubuntu ( / MacOS ) + + ```shell + user@machine:example_path$ ./benchmark subscriber + Subscriber running. Please press Ctrl+C to stop the Subscriber at any time. + ``` + +* Windows + + ```powershell + example_path> benchmark.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 sent and received data in each application, and finishing showing in the publisher the amount of data shared in each sample time during the running time with additional throughput data. + +### Benchmark publisher + +```shell +Publisher running for 500 samples. Please press Ctrl+C to stop the Publisher at any time. +Subscriber matched. +Publisher matched. +First Sample with index: '0' (Array 8388608 Bytes) SENT +Sample with index: '1' (Array 8388608 Bytes) RECEIVED +Sample with index: '2' (Array 8388608 Bytes) SENT +Sample with index: '3' (Array 8388608 Bytes) RECEIVED +Sample with index: '4' (Array 8388608 Bytes) SENT +Sample with index: '5' (Array 8388608 Bytes) RECEIVED +... +Sample with index: '499' (Array 8388608 Bytes) RECEIVED +Sample with index: '500' (Array 8388608 Bytes) SENT +Publisher unmatched. +Subscriber unmatched. +RESULTS after 1206 milliseconds: +COUNT: 500 +SAMPLES: 41,46,44,42,44,42,52,46,48,44,48,4, +THROUGHPUT BPS(Bytes per Second): 3.48482 Gbps + +... +``` + +### Benchmark subscriber + +```shell +Publisher matched. +Subscriber matched. +Subscriber running. Please press Ctrl+C to stop the Subscriber at any time. +Sample with index: '0' (Array 8388608 Bytes) RECEIVED +Sample with index: '1' (Array 8388608 Bytes) SENT +Sample with index: '2' (Array 8388608 Bytes) RECEIVED +Sample with index: '3' (Array 8388608 Bytes) SENT +Sample with index: '4' (Array 8388608 Bytes) RECEIVED +Sample with index: '5' (Array 8388608 Bytes) SENT +... +Sample with index: '499' (Array 8388608 Bytes) SENT +Sample with index: '500' (Array 8388608 Bytes) RECEIVED +... +``` + +When Ctrl+C is pressed to stop one of the applications, the other one will show the unmatched status, displaying an informative message, and it will stop sending / receiving messages. +The following is a possible output of the publisher application when stopping the subscriber app. + +```shell +... +Publisher running for 500 samples. Please press Ctrl+C to stop the Publisher at any time. +Subscriber matched. +Publisher matched. +First Sample with index: '0' (Array 8388608 Bytes) SENT +Sample with index: '1' (Array 8388608 Bytes) RECEIVED +Sample with index: '2' (Array 8388608 Bytes) SENT +Sample with index: '3' (Array 8388608 Bytes) RECEIVED +Sample with index: '4' (Array 8388608 Bytes) SENT +Publisher unmatched. +Subscriber unmatched. +``` + +## Configuration +Ahead are described the different configuration that can be selected by argument in the terminal. + +### Domain ID + +Using argument **`-d`** `` or **`--domain`** `` configures the Domain ID for the application. +The Domain ID ensures communication isolation between different groups of participants. + +- **Range**: `[0 <= <= 232]` +- **Default**: `0` + +### Topic Name + +Using argument **`-n`** `` or **`--name`** `` configures the custom name of the topic used by the publisher and subscriber. +This parameter allows flexibility in naming the topic, making it easier to identify or organize multiple test cases running simultaneously. + +- **Default**: `benchmark_topic` + + +### Reliability QoS + +Using argument **``-r``** or **``--reliable``** will configure the corresponding endpoint with **``RELIABLE``** reliability QoS. +If the argument is not provided, by default is configured as **``BEST_EFFORT``**. + +Whereas **``BEST_EFFORT``** do not retransmit missing samples, **``RELIABLE``** expects an arrival confirmation sample (acknowledge sample or ACK) per sample sent. + +**Note**: **``RELIABLE``** option may block the write operation if certain scenarios are met ([resource limits](#resource-limits-qos) reached for instance). + +Moreover, there is a compatibility rule between data readers and data writers, where the reliability QoS kind is checked to ensure the expected behavior. +The following table represents the compatibility matrix (compatible ✔️ vs incompatible ✖️): + + + + + + + + + + + + + + + + + + + + + +
Data writer reliability QoS kind
Best effortReliable
Data reader
reliability QoS kind
Best effort✔️✔️
Reliable✖️✔️
+ +### Durability QoS + +Using argument **`--transient-local`** will configure the corresponding endpoint with **`TRANSIENT_LOCAL`** durability QoS. +If the argument is not provided, by default it is configured as **`VOLATILE`**. + +Whereas **`VOLATILE`** does not store samples for late-joining subscribers, **`TRANSIENT_LOCAL`** ensures that samples are stored and delivered to any late-joining subscribers. + +**Note**: **`TRANSIENT_LOCAL`** option may require additional resources to store the samples until they are acknowledged by all subscribers. + +Moreover, there is a compatibility rule between data readers and data writers, where the durability QoS kind is checked to ensure the expected behavior. +The following table represents the compatibility matrix (compatible ✔️ vs incompatible ✖️): + + + + + + + + + + + + + + + + + + + + + +
Data writer durability QoS kind
VolatileTransient Local
Data reader
durability QoS kind
Volatile✔️✔️
Transient Local✖️✔️
+ +### Message Size + +Using argument **`-m`** `` or **`--msg-size`** `` configures the size of the message payload. + +- **Options**: + - `NONE`: Only an integer value is sent (smallest payload). + - `SMALL`: An integer value + an array of 16 KB. + - `MEDIUM`: An integer value + an array of 512 KB. + - `BIG`: An integer value + an array of 8 MB. +- **Default**: `NONE` + +### Number of Samples + +Using argument **`-s`** `` or **`--samples`** `` configures the number of samples to send or receive during the test. + +- **Range**: `[0 <= <= 65535]` +- **Default**: `0` (until timeout) + +If a value is given, the timeout parameter is ignored, and the application will run until the specified number of samples is sent or received. + +### Builtin transports + +Using argument **``-t``** ```` or **``--transport``** ```` will configure the internal DomainParticipant using the selected builtin transport: + +* **``SHM``** option instantiates a shared memory transport. +* **``UDPv4``** option instantiates a UDP for IPv4 transport. +* **``DEFAULT``** option instantiates both SHM and UDPv4 transports. + SHM transport has priority over the UDPv4 transport, meaning that SHM will always be used when possible. +* **``LARGE_DATA``** option instantiates UDPv4, TCPv4, and SHM transports. + However, UDPv4 will only be used for multicast announcements during the participant discovery phase (PDP), while the participant liveliness and the application data delivery occurs over TCPv4 or SHM. + +Argument **``--ttl``** ```` configures the number of multicast discovery Time To Live (TTL) hops. +It can be necessary to update this argument if the connection is deployed in different subnets. + +### Wait Time + +Using argument **`-w`** `` or **`--wait`** `` configures the time (in milliseconds) before the publisher starts sending samples. +This parameter allows controlled delays in the start of sample transmission, useful for synchronizing with other entities. + +- **Range**: `[0 <= <= 4294967]` +- **Default**: `1000` (1 second) + +### Interval Between Samples + +Using argument **`-i`** `` or **`--interval`** `` configures the time interval (in milliseconds) between each sample sent by the publisher. +This parameter determines the message frequency, influencing the throughput and network usage. + +- **Range**: `[1 <= <= 4294967]` +- **Default**: `100` (0.1 seconds) + +### Test Duration + +Using argument **`-e`** `` or **`--end`** `` configures the total runtime of the test in milliseconds. +This parameter controls how long the publisher or subscriber remains active. + +- **Range**: `[1 <= <= 4294967]` +- **Default**: `10000` (10 seconds) + +## XML profile playground + +The *eProsima Fast DDS* entities can be configured through an XML profile from the environment. +This is accomplished by setting the environment variable ``FASTDDS_DEFAULT_PROFILES_FILE`` to path to the XML profiles file: + +* Ubuntu ( / MacOS ) + + ```shell + user@machine:example_path$ export FASTDDS_DEFAULT_PROFILES_FILE=benchmark_profile.xml + ``` + +* Windows + + ```powershell + example_path> set FASTDDS_DEFAULT_PROFILES_FILE=benchmark_profile.xml + ``` + +The example provides with an XML profiles files with certain QoS: + +- Reliable reliability: avoid sample loss. +- Transient local durability: enable late-join subscriber applications to receive previous samples. +- Keep-last history with high depth: ensure certain amount of previous samples for late-joiners. + +Applying different configurations to the entities will change to a greater or lesser extent how the application behaves in relation to sample management. +Even when these settings affect the behavior of the sample management, the applications' output will be the similar. diff --git a/examples/cpp/benchmark/SubscriberApp.cpp b/examples/cpp/benchmark/SubscriberApp.cpp new file mode 100644 index 0000000000..264554847d --- /dev/null +++ b/examples/cpp/benchmark/SubscriberApp.cpp @@ -0,0 +1,353 @@ +// 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 +#include +#include +#include + +#include "types/BenchmarkPubSubTypes.hpp" +#include "types/Benchmark_smallPubSubTypes.hpp" +#include "types/Benchmark_mediumPubSubTypes.hpp" +#include "types/Benchmark_bigPubSubTypes.hpp" + +using namespace eprosima::fastdds::dds; +using namespace eprosima::fastdds::rtps; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace benchmark { + +SubscriberApp::SubscriberApp( + const CLIParser::subscriber_config& config) + : participant_(nullptr) + , publisher_(nullptr) + , topic_pub_(nullptr) + , writer_(nullptr) + , subscriber_(nullptr) + , topic_sub_(nullptr) + , reader_(nullptr) + , type_(nullptr) + , samples_(config.samples) + , matched_(0) + , stop_(false) + , msg_size_(config.msg_size) +{ + + // Create the participant + DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT; + pqos.name("Benchmark_sub_participant"); + auto factory = DomainParticipantFactory::get_instance(); + // Include Participant QoS + pqos.setup_transports(config.transport); + for (auto& transportDescriptor : pqos.transport().user_transports) + { + SocketTransportDescriptor* pT = dynamic_cast(transportDescriptor.get()); + if (pT) + { + pT->TTL = config.ttl; + } + } + participant_ = factory->create_participant(config.domain, pqos); + if (participant_ == nullptr) + { + throw std::runtime_error("Participant initialization failed"); + } + + // Register and set up the data type with initial values + if (msg_size_ == CLIParser::MsgSizeKind::NONE) + { + benchmark_.index(0); + type_ = TypeSupport(new BenchMarkPubSubType()); + } + else if (msg_size_ == CLIParser::MsgSizeKind::SMALL) + { + benchmark_small_.index(0); + type_ = TypeSupport(new BenchMarkSmallPubSubType()); + } + else if (msg_size_ == CLIParser::MsgSizeKind::MEDIUM) + { + benchmark_medium_.index(0); + type_ = TypeSupport(new BenchMarkMediumPubSubType()); + } + else if (msg_size_ == CLIParser::MsgSizeKind::BIG) + { + benchmark_big_.index(0); + type_ = TypeSupport(new BenchMarkBigPubSubType()); + } + else + { + throw std::runtime_error("Type initialization failed"); + } + type_.register_type(participant_); + + // Create the publisher + PublisherQos pub_qos = PUBLISHER_QOS_DEFAULT; + participant_->get_default_publisher_qos(pub_qos); + publisher_ = participant_->create_publisher(pub_qos, nullptr, StatusMask::none()); + if (publisher_ == nullptr) + { + throw std::runtime_error("Publisher initialization failed"); + } + + // Create the topics + TopicQos topic_qos = TOPIC_QOS_DEFAULT; + participant_->get_default_topic_qos(topic_qos); + topic_pub_ = participant_->create_topic(config.topic_name + "_2", type_.get_type_name(), topic_qos); + topic_sub_ = participant_->create_topic(config.topic_name + "_1", type_.get_type_name(), topic_qos); + if (topic_pub_ == nullptr) + { + throw std::runtime_error("Topic initialization failed"); + } + + // Create the data writer + DataWriterQos writer_qos = DATAWRITER_QOS_DEFAULT; + writer_qos.reliability().kind = config.reliability; + writer_qos.durability().kind = config.durability; + publisher_->get_default_datawriter_qos(writer_qos); + writer_ = publisher_->create_datawriter(topic_pub_, writer_qos, this, StatusMask::all()); + if (writer_ == nullptr) + { + throw std::runtime_error("DataWriter initialization failed"); + } + + // Create the subscriber + SubscriberQos sub_qos = SUBSCRIBER_QOS_DEFAULT; + participant_->get_default_subscriber_qos(sub_qos); + subscriber_ = participant_->create_subscriber(sub_qos, nullptr, StatusMask::none()); + if (subscriber_ == nullptr) + { + throw std::runtime_error("Subscriber initialization failed"); + } + + // Create the data reader + DataReaderQos reader_qos = DATAREADER_QOS_DEFAULT; + subscriber_->get_default_datareader_qos(reader_qos); + reader_qos.reliability().kind = config.reliability; + reader_qos.durability().kind = config.durability; + reader_ = subscriber_->create_datareader(topic_sub_, reader_qos, this, StatusMask::all()); + if (reader_ == nullptr) + { + throw std::runtime_error("DataReader initialization failed"); + } +} + +SubscriberApp::~SubscriberApp() +{ + if (nullptr != participant_) + { + // Delete DDS entities contained within the DomainParticipant + participant_->delete_contained_entities(); + + // Delete DomainParticipant + DomainParticipantFactory::get_instance()->delete_participant(participant_); + } +} + +void SubscriberApp::on_publication_matched( + DataWriter* /*writer*/, + const PublicationMatchedStatus& info) +{ + if (info.current_count_change == 1) + { + matched_++; + std::cout << "Publisher matched." << std::endl; + cv_.notify_one(); + } + else if (info.current_count_change == -1) + { + matched_--; + std::cout << "Publisher unmatched." << std::endl; + stop(); + } + else + { + std::cout << info.current_count_change + << " is not a valid value for PublicationMatchedStatus current count change" << std::endl; + } +} + +void SubscriberApp::on_subscription_matched( + DataReader* /*reader*/, + const SubscriptionMatchedStatus& info) +{ + if (info.current_count_change == 1) + { + matched_++; + std::cout << "Subscriber matched." << std::endl; + } + else if (info.current_count_change == -1) + { + matched_--; + std::cout << "Subscriber unmatched." << std::endl; + stop(); + } + 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; + switch (msg_size_) + { + case CLIParser::MsgSizeKind::NONE: + while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&benchmark_, &info))) + { + if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) + { + std::cout << "Sample with index: '" << + benchmark_.index() << "' (Array 0 Bytes) RECEIVED" << std::endl; + benchmark_.index(benchmark_.index() + 1); + if (samples_ != 0 && benchmark_.index() >= samples_) + { + stop(); + return; + } + if ((RETCODE_OK == writer_->write(&benchmark_)) == true) + { + std::cout << "Sample with index: '" << + benchmark_.index() << "' (Array 0 Bytes) SENT" << std::endl; + } + } + } + break; + + case CLIParser::MsgSizeKind::SMALL: + while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&benchmark_small_, &info))) + { + if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) + { + std::cout << "Sample with index: '" << + benchmark_small_.index() << "' (Array " << static_cast(benchmark_small_.array().size()) << + " Bytes) RECEIVED" << std::endl; + benchmark_small_.index(benchmark_small_.index() + 1); + if (samples_ != 0 && benchmark_small_.index() >= samples_) + { + stop(); + return; + } + if ((RETCODE_OK == writer_->write(&benchmark_small_)) == true) + { + std::cout << "Sample with index: '" << + benchmark_small_.index() << "' (Array " << + static_cast(benchmark_small_.array().size()) << + " Bytes) SENT" << std::endl; + } + } + } + break; + + case CLIParser::MsgSizeKind::MEDIUM: + while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&benchmark_medium_, &info))) + { + if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) + { + std::cout << "Sample with index: '" << + benchmark_medium_.index() << "' (Array " << + static_cast(benchmark_medium_.data().size()) << + " Bytes) RECEIVED" << std::endl; + benchmark_medium_.index(benchmark_medium_.index() + 1); + if (samples_ != 0 && benchmark_medium_.index() >= samples_) + { + stop(); + return; + } + if ((RETCODE_OK == writer_->write(&benchmark_medium_)) == true) + { + std::cout << "Sample with index: '" << + benchmark_medium_.index() << "' (Array " << + static_cast(benchmark_medium_.data().size()) << + " Bytes) SENT" << std::endl; + } + } + } + break; + + case CLIParser::MsgSizeKind::BIG: + while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&benchmark_big_, &info))) + { + if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) + { + std::cout << "Sample with index: '" << + benchmark_big_.index() << "' (Array " << static_cast(benchmark_big_.data().size()) << + " Bytes) RECEIVED" << std::endl; + benchmark_big_.index(benchmark_big_.index() + 1); + if (samples_ != 0 && benchmark_big_.index() >= samples_) + { + stop(); + return; + } + if ((RETCODE_OK == writer_->write(&benchmark_big_)) == true) + { + std::cout << "Sample with index: '" << + benchmark_big_.index() << "' (Array " << static_cast(benchmark_big_.data().size()) << + " Bytes) SENT" << std::endl; + } + } + } + break; + + default: + throw std::runtime_error("Type invalid"); + } +} + +void SubscriberApp::run() +{ + std::unique_lock lock_(mutex_); + cv_.wait(lock_, [&] + { + return is_stopped(); + }); +} + +bool SubscriberApp::is_stopped() +{ + return stop_.load(); +} + +void SubscriberApp::stop() +{ + stop_.store(true); + cv_.notify_one(); +} + +} // namespace benchmark +} // namespace examples +} // namespace fastdds +} // namespace eprosima diff --git a/examples/cpp/benchmark/SubscriberApp.hpp b/examples/cpp/benchmark/SubscriberApp.hpp new file mode 100644 index 0000000000..0e7872b4a6 --- /dev/null +++ b/examples/cpp/benchmark/SubscriberApp.hpp @@ -0,0 +1,121 @@ +// 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_EXAMPLES_CPP_BENCHMARK__SUBSCRIBERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_BENCHMARK__SUBSCRIBERAPP_HPP + +#include + +#include +#include +#include +#include +#include + +#include "Application.hpp" +#include "CLIParser.hpp" +#include "types/Benchmark.hpp" +#include "types/Benchmark_small.hpp" +#include "types/Benchmark_medium.hpp" +#include "types/Benchmark_big.hpp" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace benchmark { + +class SubscriberApp : public Application, public DataWriterListener, public DataReaderListener +{ +public: + + SubscriberApp( + const CLIParser::subscriber_config& config); + + ~SubscriberApp(); + + //! Publisher matched method + void on_publication_matched( + DataWriter* writer, + const PublicationMatchedStatus& info) override; + + //! Subscriber matched method + void on_subscription_matched( + DataReader* reader, + const SubscriptionMatchedStatus& info) override; + + //! Subscription callback + void on_data_available( + DataReader* reader) override; + + //! Run publisher + void run() override; + + //! Stop publisher + void stop() override; + +private: + + //! Return the current state of execution + bool is_stopped(); + + BenchMark benchmark_; + + BenchMarkSmall benchmark_small_; + + BenchMarkMedium benchmark_medium_; + + BenchMarkBig benchmark_big_; + + DomainParticipant* participant_; + + Publisher* publisher_; + + Topic* topic_pub_; + + DataWriter* writer_; + + Subscriber* subscriber_; + + Topic* topic_sub_; + + DataReader* reader_; + + TypeSupport type_; + + uint16_t samples_; + + int16_t matched_; + + std::mutex mutex_; + + std::condition_variable cv_; + + std::atomic stop_; + + CLIParser::MsgSizeKind msg_size_; +}; + +} // namespace benchmark +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_EXAMPLES_CPP_BENCHMARK__SUBSCRIBERAPP_HPP diff --git a/examples/cpp/benchmark/benchmark_profile.xml b/examples/cpp/benchmark/benchmark_profile.xml new file mode 100644 index 0000000000..566be19eec --- /dev/null +++ b/examples/cpp/benchmark/benchmark_profile.xml @@ -0,0 +1,52 @@ + + + + 0 + + benchmark_participant + + + + + + TRANSIENT_LOCAL + + + RELIABLE + + + + + KEEP_LAST + 100 + + + 100 + 1 + 100 + + + + + + + + TRANSIENT_LOCAL + + + RELIABLE + + + + + KEEP_LAST + 100 + + + 100 + 1 + 100 + + + + diff --git a/examples/cpp/benchmark/main.cpp b/examples/cpp/benchmark/main.cpp new file mode 100644 index 0000000000..8db54f654f --- /dev/null +++ b/examples/cpp/benchmark/main.cpp @@ -0,0 +1,116 @@ +// 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 eprosima::fastdds::dds::Log; + +using namespace eprosima::fastdds::examples::benchmark; + +std::function stop_app_handler; +void signal_handler( + int signum) +{ + stop_app_handler(signum); +} + +int main( + int argc, + char** argv) +{ + auto ret = EXIT_SUCCESS; + CLIParser::benchmark_config config = CLIParser::parse_cli_options(argc, argv); + uint32_t timeout = 1; + switch (config.entity) + { + case CLIParser::EntityKind::PUBLISHER: + timeout = config.pub_config.timeout; + break; + case CLIParser::EntityKind::SUBSCRIBER: + timeout = 0; + break; + default: + break; + } + + std::string app_name = CLIParser::parse_entity_kind(config.entity); + std::shared_ptr app; + + try + { + app = Application::make_app(config); + } + 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 (timeout == 0) + { + std::cout << app_name << " running. Please press Ctrl+C to stop the " + << app_name << " at any time." << std::endl; + } + else + { + if (config.pub_config.samples != 0) + { + std::cout << app_name << " running for " << config.pub_config.samples << + " samples. Please press Ctrl+C " + << "to stop the " << app_name << " at any time." << std::endl; + } + else + { + std::cout << app_name << " running for " << timeout << " milliseconds. 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(); + } + + Log::Reset(); + return ret; +} diff --git a/examples/cpp/benchmark/types/Benchmark.hpp b/examples/cpp/benchmark/types/Benchmark.hpp new file mode 100644 index 0000000000..3600c5947e --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark.hpp @@ -0,0 +1,176 @@ +// 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 Benchmark.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BENCHMARK_HPP +#define FAST_DDS_GENERATED__BENCHMARK_HPP + +#include +#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 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(BENCHMARK_SOURCE) +#define BENCHMARK_DllAPI __declspec( dllexport ) +#else +#define BENCHMARK_DllAPI __declspec( dllimport ) +#endif // BENCHMARK_SOURCE +#else +#define BENCHMARK_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define BENCHMARK_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the structure BenchMark defined by the user in the IDL file. + * @ingroup Benchmark + */ +class BenchMark +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport BenchMark() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~BenchMark() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object BenchMark that will be copied. + */ + eProsima_user_DllExport BenchMark( + const BenchMark& x) + { + m_index = x.m_index; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object BenchMark that will be copied. + */ + eProsima_user_DllExport BenchMark( + BenchMark&& x) noexcept + { + m_index = x.m_index; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object BenchMark that will be copied. + */ + eProsima_user_DllExport BenchMark& operator =( + const BenchMark& x) + { + + m_index = x.m_index; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object BenchMark that will be copied. + */ + eProsima_user_DllExport BenchMark& operator =( + BenchMark&& x) noexcept + { + + m_index = x.m_index; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x BenchMark object to compare. + */ + eProsima_user_DllExport bool operator ==( + const BenchMark& x) const + { + return (m_index == x.m_index); + } + + /*! + * @brief Comparison operator. + * @param x BenchMark object to compare. + */ + eProsima_user_DllExport bool operator !=( + const BenchMark& x) const + { + return !(*this == x); + } + + /*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ + eProsima_user_DllExport void index( + uint32_t _index) + { + m_index = _index; + } + + /*! + * @brief This function returns the value of member index + * @return Value of member index + */ + eProsima_user_DllExport uint32_t index() const + { + return m_index; + } + + /*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ + eProsima_user_DllExport uint32_t& index() + { + return m_index; + } + +private: + + uint32_t m_index{0}; + +}; + +#endif // _FAST_DDS_GENERATED_BENCHMARK_HPP_ + + diff --git a/examples/cpp/benchmark/types/Benchmark.idl b/examples/cpp/benchmark/types/Benchmark.idl new file mode 100644 index 0000000000..5bbc62d272 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark.idl @@ -0,0 +1,6 @@ +@extensibility(APPENDABLE) +struct BenchMark +{ + unsigned long index; +}; + diff --git a/examples/cpp/benchmark/types/BenchmarkCdrAux.hpp b/examples/cpp/benchmark/types/BenchmarkCdrAux.hpp new file mode 100644 index 0000000000..fb74fc3aee --- /dev/null +++ b/examples/cpp/benchmark/types/BenchmarkCdrAux.hpp @@ -0,0 +1,46 @@ +// 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 BenchmarkCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BENCHMARKCDRAUX_HPP +#define FAST_DDS_GENERATED__BENCHMARKCDRAUX_HPP + +#include "Benchmark.hpp" + +constexpr uint32_t BenchMark_max_cdr_typesize {8UL}; +constexpr uint32_t BenchMark_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const BenchMark& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__BENCHMARKCDRAUX_HPP + diff --git a/examples/cpp/benchmark/types/BenchmarkCdrAux.ipp b/examples/cpp/benchmark/types/BenchmarkCdrAux.ipp new file mode 100644 index 0000000000..8f0aae75f6 --- /dev/null +++ b/examples/cpp/benchmark/types/BenchmarkCdrAux.ipp @@ -0,0 +1,121 @@ +// 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 BenchmarkCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BENCHMARKCDRAUX_IPP +#define FAST_DDS_GENERATED__BENCHMARKCDRAUX_IPP + +#include "BenchmarkCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const BenchMark& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.index(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const BenchMark& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.index() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + BenchMark& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.index(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const BenchMark& data) +{ + + static_cast(scdr); + static_cast(data); + scdr << data.index(); + +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__BENCHMARKCDRAUX_IPP + diff --git a/examples/cpp/benchmark/types/BenchmarkPubSubTypes.cxx b/examples/cpp/benchmark/types/BenchmarkPubSubTypes.cxx new file mode 100644 index 0000000000..72035eb388 --- /dev/null +++ b/examples/cpp/benchmark/types/BenchmarkPubSubTypes.cxx @@ -0,0 +1,218 @@ +// 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 BenchmarkPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "BenchmarkPubSubTypes.hpp" + +#include +#include + +#include "BenchmarkCdrAux.hpp" +#include "BenchmarkTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +BenchMarkPubSubType::BenchMarkPubSubType() +{ + set_name("BenchMark"); + uint32_t type_size = BenchMark_max_cdr_typesize; + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = BenchMark_max_key_cdr_typesize > 16 ? BenchMark_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); +} + +BenchMarkPubSubType::~BenchMarkPubSubType() +{ + if (key_buffer_ != nullptr) + { + free(key_buffer_); + } +} + +bool BenchMarkPubSubType::serialize( + const void* const data, + SerializedPayload_t& payload, + DataRepresentationId_t data_representation) +{ + const BenchMark* 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; + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + ser.set_dds_cdr_options({0,0}); + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length + payload.length = static_cast(ser.get_serialized_data_length()); + return true; +} + +bool BenchMarkPubSubType::deserialize( + SerializedPayload_t& payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + BenchMark* 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); + + // 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; +} + +uint32_t BenchMarkPubSubType::calculate_serialized_size( + const void* const data, + DataRepresentationId_t data_representation) +{ + 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; + } +} + +void* BenchMarkPubSubType::create_data() +{ + return reinterpret_cast(new BenchMark()); +} + +void BenchMarkPubSubType::delete_data( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool BenchMarkPubSubType::compute_key( + SerializedPayload_t& payload, + InstanceHandle_t& handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + BenchMark data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool BenchMarkPubSubType::compute_key( + const void* const data, + InstanceHandle_t& handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + const BenchMark* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), + BenchMark_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2); + ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2); + eprosima::fastcdr::serialize_key(ser, *p_type); + if (force_md5 || BenchMark_max_key_cdr_typesize > 16) + { + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle.value[i] = md5_.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle.value[i] = key_buffer_[i]; + } + } + return true; +} + +void BenchMarkPubSubType::register_type_object_representation() +{ + register_BenchMark_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "BenchmarkCdrAux.ipp" diff --git a/examples/cpp/benchmark/types/BenchmarkPubSubTypes.hpp b/examples/cpp/benchmark/types/BenchmarkPubSubTypes.hpp new file mode 100644 index 0000000000..2b792f08c7 --- /dev/null +++ b/examples/cpp/benchmark/types/BenchmarkPubSubTypes.hpp @@ -0,0 +1,123 @@ +// 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 BenchmarkPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__BENCHMARK_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__BENCHMARK_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "Benchmark.hpp" + + +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) +#error \ + Generated Benchmark is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // FASTDDS_GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type BenchMark defined by the user in the IDL file. + * @ingroup Benchmark + */ +class BenchMarkPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef BenchMark type; + + eProsima_user_DllExport BenchMarkPubSubType(); + + eProsima_user_DllExport ~BenchMarkPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t& payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t& payload, + void* data) override; + + eProsima_user_DllExport uint32_t calculate_serialized_size( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t& payload, + eprosima::fastdds::rtps::InstanceHandle_t& ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t& ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* create_data() override; + + eProsima_user_DllExport void delete_data( + 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( + 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 + +private: + + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; + +}; + +#endif // FAST_DDS_GENERATED__BENCHMARK_PUBSUBTYPES_HPP + diff --git a/examples/cpp/benchmark/types/BenchmarkTypeObjectSupport.cxx b/examples/cpp/benchmark/types/BenchmarkTypeObjectSupport.cxx new file mode 100644 index 0000000000..3e76249d14 --- /dev/null +++ b/examples/cpp/benchmark/types/BenchmarkTypeObjectSupport.cxx @@ -0,0 +1,107 @@ +// 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 BenchmarkTypeObjectSupport.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 "BenchmarkTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Benchmark.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_BenchMark_type_identifier( + TypeIdentifierPair& type_ids_BenchMark) +{ + + ReturnCode_t return_code_BenchMark {eprosima::fastdds::dds::RETCODE_OK}; + return_code_BenchMark = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "BenchMark", type_ids_BenchMark); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_BenchMark) + { + StructTypeFlag struct_flags_BenchMark = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_BenchMark = "BenchMark"; + eprosima::fastcdr::optional type_ann_builtin_BenchMark; + eprosima::fastcdr::optional ann_custom_BenchMark; + AppliedAnnotationSeq tmp_ann_custom_BenchMark; + eprosima::fastcdr::optional verbatim_BenchMark; + if (!tmp_ann_custom_BenchMark.empty()) + { + ann_custom_BenchMark = tmp_ann_custom_BenchMark; + } + + CompleteTypeDetail detail_BenchMark = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_BenchMark, ann_custom_BenchMark, type_name_BenchMark.to_string()); + CompleteStructHeader header_BenchMark; + header_BenchMark = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_BenchMark); + CompleteStructMemberSeq member_seq_BenchMark; + { + 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_BenchMark.reset(); + CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_BenchMark); + CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); + TypeObjectUtils::add_complete_struct_member(member_seq_BenchMark, member_index); + } + CompleteStructType struct_type_BenchMark = TypeObjectUtils::build_complete_struct_type(struct_flags_BenchMark, header_BenchMark, member_seq_BenchMark); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_BenchMark, type_name_BenchMark.to_string(), type_ids_BenchMark)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "BenchMark already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/examples/cpp/benchmark/types/BenchmarkTypeObjectSupport.hpp b/examples/cpp/benchmark/types/BenchmarkTypeObjectSupport.hpp new file mode 100644 index 0000000000..cbebe002a8 --- /dev/null +++ b/examples/cpp/benchmark/types/BenchmarkTypeObjectSupport.hpp @@ -0,0 +1,56 @@ +// 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 BenchmarkTypeObjectSupport.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__BENCHMARK_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__BENCHMARK_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 BenchMark 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_BenchMark_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__BENCHMARK_TYPE_OBJECT_SUPPORT_HPP diff --git a/examples/cpp/benchmark/types/Benchmark_big.hpp b/examples/cpp/benchmark/types/Benchmark_big.hpp new file mode 100644 index 0000000000..f76f126878 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_big.hpp @@ -0,0 +1,223 @@ +// 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 Benchmark_big.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BENCHMARK_BIG_HPP +#define FAST_DDS_GENERATED__BENCHMARK_BIG_HPP + +#include +#include +#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 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(BENCHMARK_BIG_SOURCE) +#define BENCHMARK_BIG_DllAPI __declspec( dllexport ) +#else +#define BENCHMARK_BIG_DllAPI __declspec( dllimport ) +#endif // BENCHMARK_BIG_SOURCE +#else +#define BENCHMARK_BIG_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define BENCHMARK_BIG_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the structure BenchMarkBig defined by the user in the IDL file. + * @ingroup Benchmark_big + */ +class BenchMarkBig +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport BenchMarkBig() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~BenchMarkBig() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object BenchMarkBig that will be copied. + */ + eProsima_user_DllExport BenchMarkBig( + const BenchMarkBig& x) + { + m_data = x.m_data; + + m_index = x.m_index; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object BenchMarkBig that will be copied. + */ + eProsima_user_DllExport BenchMarkBig( + BenchMarkBig&& x) noexcept + { + m_data = std::move(x.m_data); + m_index = x.m_index; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object BenchMarkBig that will be copied. + */ + eProsima_user_DllExport BenchMarkBig& operator =( + const BenchMarkBig& x) + { + + m_data = x.m_data; + + m_index = x.m_index; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object BenchMarkBig that will be copied. + */ + eProsima_user_DllExport BenchMarkBig& operator =( + BenchMarkBig&& x) noexcept + { + + m_data = std::move(x.m_data); + m_index = x.m_index; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x BenchMarkBig object to compare. + */ + eProsima_user_DllExport bool operator ==( + const BenchMarkBig& x) const + { + return (m_data == x.m_data && + m_index == x.m_index); + } + + /*! + * @brief Comparison operator. + * @param x BenchMarkBig object to compare. + */ + eProsima_user_DllExport bool operator !=( + const BenchMarkBig& x) const + { + return !(*this == x); + } + + /*! + * @brief This function copies the value in member data + * @param _data New value to be copied in member data + */ + eProsima_user_DllExport void data( + const std::array& _data) + { + m_data = _data; + } + + /*! + * @brief This function moves the value in member data + * @param _data New value to be moved in member data + */ + eProsima_user_DllExport void data( + std::array&& _data) + { + m_data = std::move(_data); + } + + /*! + * @brief This function returns a constant reference to member data + * @return Constant reference to member data + */ + eProsima_user_DllExport const std::array& data() const + { + return m_data; + } + + /*! + * @brief This function returns a reference to member data + * @return Reference to member data + */ + eProsima_user_DllExport std::array& data() + { + return m_data; + } + + /*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ + eProsima_user_DllExport void index( + uint32_t _index) + { + m_index = _index; + } + + /*! + * @brief This function returns the value of member index + * @return Value of member index + */ + eProsima_user_DllExport uint32_t index() const + { + return m_index; + } + + /*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ + eProsima_user_DllExport uint32_t& index() + { + return m_index; + } + +private: + + std::array m_data{0}; + uint32_t m_index{0}; + +}; + +#endif // _FAST_DDS_GENERATED_BENCHMARK_BIG_HPP_ + + diff --git a/examples/cpp/benchmark/types/Benchmark_big.idl b/examples/cpp/benchmark/types/Benchmark_big.idl new file mode 100644 index 0000000000..1d25546ea8 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_big.idl @@ -0,0 +1,5 @@ +struct BenchMarkBig +{ + char data[8388608]; + unsigned long index; +}; diff --git a/examples/cpp/benchmark/types/Benchmark_bigCdrAux.hpp b/examples/cpp/benchmark/types/Benchmark_bigCdrAux.hpp new file mode 100644 index 0000000000..142b448f84 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_bigCdrAux.hpp @@ -0,0 +1,46 @@ +// 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 Benchmark_bigCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BENCHMARK_BIGCDRAUX_HPP +#define FAST_DDS_GENERATED__BENCHMARK_BIGCDRAUX_HPP + +#include "Benchmark_big.hpp" + +constexpr uint32_t BenchMarkBig_max_cdr_typesize {8388616UL}; +constexpr uint32_t BenchMarkBig_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const BenchMarkBig& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__BENCHMARK_BIGCDRAUX_HPP + diff --git a/examples/cpp/benchmark/types/Benchmark_bigCdrAux.ipp b/examples/cpp/benchmark/types/Benchmark_bigCdrAux.ipp new file mode 100644 index 0000000000..048fa8528a --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_bigCdrAux.ipp @@ -0,0 +1,131 @@ +// 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 Benchmark_bigCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BENCHMARK_BIGCDRAUX_IPP +#define FAST_DDS_GENERATED__BENCHMARK_BIGCDRAUX_IPP + +#include "Benchmark_bigCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const BenchMarkBig& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.data(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.index(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const BenchMarkBig& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.data() + << eprosima::fastcdr::MemberId(1) << data.index() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + BenchMarkBig& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.data(); + break; + + case 1: + dcdr >> data.index(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const BenchMarkBig& data) +{ + + static_cast(scdr); + static_cast(data); + scdr << data.data(); + + scdr << data.index(); + +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__BENCHMARK_BIGCDRAUX_IPP + diff --git a/examples/cpp/benchmark/types/Benchmark_bigPubSubTypes.cxx b/examples/cpp/benchmark/types/Benchmark_bigPubSubTypes.cxx new file mode 100644 index 0000000000..7c72a73b07 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_bigPubSubTypes.cxx @@ -0,0 +1,218 @@ +// 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 Benchmark_bigPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "Benchmark_bigPubSubTypes.hpp" + +#include +#include + +#include "Benchmark_bigCdrAux.hpp" +#include "Benchmark_bigTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +BenchMarkBigPubSubType::BenchMarkBigPubSubType() +{ + set_name("BenchMarkBig"); + uint32_t type_size = BenchMarkBig_max_cdr_typesize; + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = BenchMarkBig_max_key_cdr_typesize > 16 ? BenchMarkBig_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); +} + +BenchMarkBigPubSubType::~BenchMarkBigPubSubType() +{ + if (key_buffer_ != nullptr) + { + free(key_buffer_); + } +} + +bool BenchMarkBigPubSubType::serialize( + const void* const data, + SerializedPayload_t& payload, + DataRepresentationId_t data_representation) +{ + const BenchMarkBig* 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; + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + ser.set_dds_cdr_options({0,0}); + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length + payload.length = static_cast(ser.get_serialized_data_length()); + return true; +} + +bool BenchMarkBigPubSubType::deserialize( + SerializedPayload_t& payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + BenchMarkBig* 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); + + // 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; +} + +uint32_t BenchMarkBigPubSubType::calculate_serialized_size( + const void* const data, + DataRepresentationId_t data_representation) +{ + 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; + } +} + +void* BenchMarkBigPubSubType::create_data() +{ + return reinterpret_cast(new BenchMarkBig()); +} + +void BenchMarkBigPubSubType::delete_data( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool BenchMarkBigPubSubType::compute_key( + SerializedPayload_t& payload, + InstanceHandle_t& handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + BenchMarkBig data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool BenchMarkBigPubSubType::compute_key( + const void* const data, + InstanceHandle_t& handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + const BenchMarkBig* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), + BenchMarkBig_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2); + ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2); + eprosima::fastcdr::serialize_key(ser, *p_type); + if (force_md5 || BenchMarkBig_max_key_cdr_typesize > 16) + { + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle.value[i] = md5_.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle.value[i] = key_buffer_[i]; + } + } + return true; +} + +void BenchMarkBigPubSubType::register_type_object_representation() +{ + register_BenchMarkBig_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "Benchmark_bigCdrAux.ipp" diff --git a/examples/cpp/benchmark/types/Benchmark_bigPubSubTypes.hpp b/examples/cpp/benchmark/types/Benchmark_bigPubSubTypes.hpp new file mode 100644 index 0000000000..bc2a84338c --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_bigPubSubTypes.hpp @@ -0,0 +1,123 @@ +// 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 Benchmark_bigPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__BENCHMARK_BIG_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__BENCHMARK_BIG_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "Benchmark_big.hpp" + + +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) +#error \ + Generated Benchmark_big is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // FASTDDS_GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type BenchMarkBig defined by the user in the IDL file. + * @ingroup Benchmark_big + */ +class BenchMarkBigPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef BenchMarkBig type; + + eProsima_user_DllExport BenchMarkBigPubSubType(); + + eProsima_user_DllExport ~BenchMarkBigPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t& payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t& payload, + void* data) override; + + eProsima_user_DllExport uint32_t calculate_serialized_size( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t& payload, + eprosima::fastdds::rtps::InstanceHandle_t& ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t& ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* create_data() override; + + eProsima_user_DllExport void delete_data( + 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( + 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 + +private: + + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; + +}; + +#endif // FAST_DDS_GENERATED__BENCHMARK_BIG_PUBSUBTYPES_HPP + diff --git a/examples/cpp/benchmark/types/Benchmark_bigTypeObjectSupport.cxx b/examples/cpp/benchmark/types/Benchmark_bigTypeObjectSupport.cxx new file mode 100644 index 0000000000..41a4ad2863 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_bigTypeObjectSupport.cxx @@ -0,0 +1,164 @@ +// 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 Benchmark_bigTypeObjectSupport.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 "Benchmark_bigTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Benchmark_big.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_BenchMarkBig_type_identifier( + TypeIdentifierPair& type_ids_BenchMarkBig) +{ + + ReturnCode_t return_code_BenchMarkBig {eprosima::fastdds::dds::RETCODE_OK}; + return_code_BenchMarkBig = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "BenchMarkBig", type_ids_BenchMarkBig); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_BenchMarkBig) + { + StructTypeFlag struct_flags_BenchMarkBig = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_BenchMarkBig = "BenchMarkBig"; + eprosima::fastcdr::optional type_ann_builtin_BenchMarkBig; + eprosima::fastcdr::optional ann_custom_BenchMarkBig; + CompleteTypeDetail detail_BenchMarkBig = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_BenchMarkBig, ann_custom_BenchMarkBig, type_name_BenchMarkBig.to_string()); + CompleteStructHeader header_BenchMarkBig; + header_BenchMarkBig = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_BenchMarkBig); + CompleteStructMemberSeq member_seq_BenchMarkBig; + { + 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_array_char_8388608", 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( + "_char", type_ids_data); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_data) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Array element TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + bool element_identifier_anonymous_array_char_8388608_ec {false}; + TypeIdentifier* element_identifier_anonymous_array_char_8388608 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_data, element_identifier_anonymous_array_char_8388608_ec))}; + if (!element_identifier_anonymous_array_char_8388608_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Array element TypeIdentifier inconsistent."); + return; + } + EquivalenceKind equiv_kind_anonymous_array_char_8388608 = EK_COMPLETE; + if (TK_NONE == type_ids_data.type_identifier2()._d()) + { + equiv_kind_anonymous_array_char_8388608 = EK_BOTH; + } + CollectionElementFlag element_flags_anonymous_array_char_8388608 = 0; + PlainCollectionHeader header_anonymous_array_char_8388608 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_array_char_8388608, element_flags_anonymous_array_char_8388608); + { + LBoundSeq array_bound_seq; + TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast(8388608)); + + PlainArrayLElemDefn array_ldefn = TypeObjectUtils::build_plain_array_l_elem_defn(header_anonymous_array_char_8388608, array_bound_seq, + eprosima::fastcdr::external(element_identifier_anonymous_array_char_8388608)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_l_array_type_identifier(array_ldefn, "anonymous_array_char_8388608", type_ids_data)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_array_char_8388608 already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_data = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_data = 0x00000000; + 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_BenchMarkBig.reset(); + CompleteMemberDetail detail_data = TypeObjectUtils::build_complete_member_detail(name_data, member_ann_builtin_data, ann_custom_BenchMarkBig); + CompleteStructMember member_data = TypeObjectUtils::build_complete_struct_member(common_data, detail_data); + TypeObjectUtils::add_complete_struct_member(member_seq_BenchMarkBig, member_data); + } + { + 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 = 0x00000001; + 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_BenchMarkBig.reset(); + CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_BenchMarkBig); + CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); + TypeObjectUtils::add_complete_struct_member(member_seq_BenchMarkBig, member_index); + } + CompleteStructType struct_type_BenchMarkBig = TypeObjectUtils::build_complete_struct_type(struct_flags_BenchMarkBig, header_BenchMarkBig, member_seq_BenchMarkBig); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_BenchMarkBig, type_name_BenchMarkBig.to_string(), type_ids_BenchMarkBig)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "BenchMarkBig already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/examples/cpp/benchmark/types/Benchmark_bigTypeObjectSupport.hpp b/examples/cpp/benchmark/types/Benchmark_bigTypeObjectSupport.hpp new file mode 100644 index 0000000000..e36f101107 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_bigTypeObjectSupport.hpp @@ -0,0 +1,56 @@ +// 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 Benchmark_bigTypeObjectSupport.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__BENCHMARK_BIG_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__BENCHMARK_BIG_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 BenchMarkBig 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_BenchMarkBig_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__BENCHMARK_BIG_TYPE_OBJECT_SUPPORT_HPP diff --git a/examples/cpp/benchmark/types/Benchmark_medium.hpp b/examples/cpp/benchmark/types/Benchmark_medium.hpp new file mode 100644 index 0000000000..5721540209 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_medium.hpp @@ -0,0 +1,223 @@ +// 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 Benchmark_medium.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BENCHMARK_MEDIUM_HPP +#define FAST_DDS_GENERATED__BENCHMARK_MEDIUM_HPP + +#include +#include +#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 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(BENCHMARK_MEDIUM_SOURCE) +#define BENCHMARK_MEDIUM_DllAPI __declspec( dllexport ) +#else +#define BENCHMARK_MEDIUM_DllAPI __declspec( dllimport ) +#endif // BENCHMARK_MEDIUM_SOURCE +#else +#define BENCHMARK_MEDIUM_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define BENCHMARK_MEDIUM_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the structure BenchMarkMedium defined by the user in the IDL file. + * @ingroup Benchmark_medium + */ +class BenchMarkMedium +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport BenchMarkMedium() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~BenchMarkMedium() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object BenchMarkMedium that will be copied. + */ + eProsima_user_DllExport BenchMarkMedium( + const BenchMarkMedium& x) + { + m_data = x.m_data; + + m_index = x.m_index; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object BenchMarkMedium that will be copied. + */ + eProsima_user_DllExport BenchMarkMedium( + BenchMarkMedium&& x) noexcept + { + m_data = std::move(x.m_data); + m_index = x.m_index; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object BenchMarkMedium that will be copied. + */ + eProsima_user_DllExport BenchMarkMedium& operator =( + const BenchMarkMedium& x) + { + + m_data = x.m_data; + + m_index = x.m_index; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object BenchMarkMedium that will be copied. + */ + eProsima_user_DllExport BenchMarkMedium& operator =( + BenchMarkMedium&& x) noexcept + { + + m_data = std::move(x.m_data); + m_index = x.m_index; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x BenchMarkMedium object to compare. + */ + eProsima_user_DllExport bool operator ==( + const BenchMarkMedium& x) const + { + return (m_data == x.m_data && + m_index == x.m_index); + } + + /*! + * @brief Comparison operator. + * @param x BenchMarkMedium object to compare. + */ + eProsima_user_DllExport bool operator !=( + const BenchMarkMedium& x) const + { + return !(*this == x); + } + + /*! + * @brief This function copies the value in member data + * @param _data New value to be copied in member data + */ + eProsima_user_DllExport void data( + const std::array& _data) + { + m_data = _data; + } + + /*! + * @brief This function moves the value in member data + * @param _data New value to be moved in member data + */ + eProsima_user_DllExport void data( + std::array&& _data) + { + m_data = std::move(_data); + } + + /*! + * @brief This function returns a constant reference to member data + * @return Constant reference to member data + */ + eProsima_user_DllExport const std::array& data() const + { + return m_data; + } + + /*! + * @brief This function returns a reference to member data + * @return Reference to member data + */ + eProsima_user_DllExport std::array& data() + { + return m_data; + } + + /*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ + eProsima_user_DllExport void index( + uint32_t _index) + { + m_index = _index; + } + + /*! + * @brief This function returns the value of member index + * @return Value of member index + */ + eProsima_user_DllExport uint32_t index() const + { + return m_index; + } + + /*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ + eProsima_user_DllExport uint32_t& index() + { + return m_index; + } + +private: + + std::array m_data{0}; + uint32_t m_index{0}; + +}; + +#endif // _FAST_DDS_GENERATED_BENCHMARK_MEDIUM_HPP_ + + diff --git a/examples/cpp/benchmark/types/Benchmark_medium.idl b/examples/cpp/benchmark/types/Benchmark_medium.idl new file mode 100644 index 0000000000..bd557193fb --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_medium.idl @@ -0,0 +1,5 @@ +struct BenchMarkMedium +{ + char data[524288]; + unsigned long index; +}; diff --git a/examples/cpp/benchmark/types/Benchmark_mediumCdrAux.hpp b/examples/cpp/benchmark/types/Benchmark_mediumCdrAux.hpp new file mode 100644 index 0000000000..7d16b0af7d --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_mediumCdrAux.hpp @@ -0,0 +1,46 @@ +// 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 Benchmark_mediumCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BENCHMARK_MEDIUMCDRAUX_HPP +#define FAST_DDS_GENERATED__BENCHMARK_MEDIUMCDRAUX_HPP + +#include "Benchmark_medium.hpp" + +constexpr uint32_t BenchMarkMedium_max_cdr_typesize {524296UL}; +constexpr uint32_t BenchMarkMedium_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const BenchMarkMedium& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__BENCHMARK_MEDIUMCDRAUX_HPP + diff --git a/examples/cpp/benchmark/types/Benchmark_mediumCdrAux.ipp b/examples/cpp/benchmark/types/Benchmark_mediumCdrAux.ipp new file mode 100644 index 0000000000..3f147e78a5 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_mediumCdrAux.ipp @@ -0,0 +1,131 @@ +// 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 Benchmark_mediumCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BENCHMARK_MEDIUMCDRAUX_IPP +#define FAST_DDS_GENERATED__BENCHMARK_MEDIUMCDRAUX_IPP + +#include "Benchmark_mediumCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const BenchMarkMedium& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.data(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.index(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const BenchMarkMedium& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.data() + << eprosima::fastcdr::MemberId(1) << data.index() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + BenchMarkMedium& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.data(); + break; + + case 1: + dcdr >> data.index(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const BenchMarkMedium& data) +{ + + static_cast(scdr); + static_cast(data); + scdr << data.data(); + + scdr << data.index(); + +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__BENCHMARK_MEDIUMCDRAUX_IPP + diff --git a/examples/cpp/benchmark/types/Benchmark_mediumPubSubTypes.cxx b/examples/cpp/benchmark/types/Benchmark_mediumPubSubTypes.cxx new file mode 100644 index 0000000000..5f512aa12e --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_mediumPubSubTypes.cxx @@ -0,0 +1,218 @@ +// 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 Benchmark_mediumPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "Benchmark_mediumPubSubTypes.hpp" + +#include +#include + +#include "Benchmark_mediumCdrAux.hpp" +#include "Benchmark_mediumTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +BenchMarkMediumPubSubType::BenchMarkMediumPubSubType() +{ + set_name("BenchMarkMedium"); + uint32_t type_size = BenchMarkMedium_max_cdr_typesize; + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = BenchMarkMedium_max_key_cdr_typesize > 16 ? BenchMarkMedium_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); +} + +BenchMarkMediumPubSubType::~BenchMarkMediumPubSubType() +{ + if (key_buffer_ != nullptr) + { + free(key_buffer_); + } +} + +bool BenchMarkMediumPubSubType::serialize( + const void* const data, + SerializedPayload_t& payload, + DataRepresentationId_t data_representation) +{ + const BenchMarkMedium* 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; + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + ser.set_dds_cdr_options({0,0}); + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length + payload.length = static_cast(ser.get_serialized_data_length()); + return true; +} + +bool BenchMarkMediumPubSubType::deserialize( + SerializedPayload_t& payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + BenchMarkMedium* 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); + + // 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; +} + +uint32_t BenchMarkMediumPubSubType::calculate_serialized_size( + const void* const data, + DataRepresentationId_t data_representation) +{ + 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; + } +} + +void* BenchMarkMediumPubSubType::create_data() +{ + return reinterpret_cast(new BenchMarkMedium()); +} + +void BenchMarkMediumPubSubType::delete_data( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool BenchMarkMediumPubSubType::compute_key( + SerializedPayload_t& payload, + InstanceHandle_t& handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + BenchMarkMedium data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool BenchMarkMediumPubSubType::compute_key( + const void* const data, + InstanceHandle_t& handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + const BenchMarkMedium* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), + BenchMarkMedium_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2); + ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2); + eprosima::fastcdr::serialize_key(ser, *p_type); + if (force_md5 || BenchMarkMedium_max_key_cdr_typesize > 16) + { + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle.value[i] = md5_.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle.value[i] = key_buffer_[i]; + } + } + return true; +} + +void BenchMarkMediumPubSubType::register_type_object_representation() +{ + register_BenchMarkMedium_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "Benchmark_mediumCdrAux.ipp" diff --git a/examples/cpp/benchmark/types/Benchmark_mediumPubSubTypes.hpp b/examples/cpp/benchmark/types/Benchmark_mediumPubSubTypes.hpp new file mode 100644 index 0000000000..ad6964694a --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_mediumPubSubTypes.hpp @@ -0,0 +1,123 @@ +// 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 Benchmark_mediumPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__BENCHMARK_MEDIUM_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__BENCHMARK_MEDIUM_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "Benchmark_medium.hpp" + + +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) +#error \ + Generated Benchmark_medium is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // FASTDDS_GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type BenchMarkMedium defined by the user in the IDL file. + * @ingroup Benchmark_medium + */ +class BenchMarkMediumPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef BenchMarkMedium type; + + eProsima_user_DllExport BenchMarkMediumPubSubType(); + + eProsima_user_DllExport ~BenchMarkMediumPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t& payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t& payload, + void* data) override; + + eProsima_user_DllExport uint32_t calculate_serialized_size( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t& payload, + eprosima::fastdds::rtps::InstanceHandle_t& ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t& ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* create_data() override; + + eProsima_user_DllExport void delete_data( + 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( + 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 + +private: + + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; + +}; + +#endif // FAST_DDS_GENERATED__BENCHMARK_MEDIUM_PUBSUBTYPES_HPP + diff --git a/examples/cpp/benchmark/types/Benchmark_mediumTypeObjectSupport.cxx b/examples/cpp/benchmark/types/Benchmark_mediumTypeObjectSupport.cxx new file mode 100644 index 0000000000..1dc5205063 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_mediumTypeObjectSupport.cxx @@ -0,0 +1,164 @@ +// 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 Benchmark_mediumTypeObjectSupport.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 "Benchmark_mediumTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Benchmark_medium.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_BenchMarkMedium_type_identifier( + TypeIdentifierPair& type_ids_BenchMarkMedium) +{ + + ReturnCode_t return_code_BenchMarkMedium {eprosima::fastdds::dds::RETCODE_OK}; + return_code_BenchMarkMedium = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "BenchMarkMedium", type_ids_BenchMarkMedium); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_BenchMarkMedium) + { + StructTypeFlag struct_flags_BenchMarkMedium = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_BenchMarkMedium = "BenchMarkMedium"; + eprosima::fastcdr::optional type_ann_builtin_BenchMarkMedium; + eprosima::fastcdr::optional ann_custom_BenchMarkMedium; + CompleteTypeDetail detail_BenchMarkMedium = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_BenchMarkMedium, ann_custom_BenchMarkMedium, type_name_BenchMarkMedium.to_string()); + CompleteStructHeader header_BenchMarkMedium; + header_BenchMarkMedium = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_BenchMarkMedium); + CompleteStructMemberSeq member_seq_BenchMarkMedium; + { + 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_array_char_524288", 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( + "_char", type_ids_data); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_data) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Array element TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + bool element_identifier_anonymous_array_char_524288_ec {false}; + TypeIdentifier* element_identifier_anonymous_array_char_524288 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_data, element_identifier_anonymous_array_char_524288_ec))}; + if (!element_identifier_anonymous_array_char_524288_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Array element TypeIdentifier inconsistent."); + return; + } + EquivalenceKind equiv_kind_anonymous_array_char_524288 = EK_COMPLETE; + if (TK_NONE == type_ids_data.type_identifier2()._d()) + { + equiv_kind_anonymous_array_char_524288 = EK_BOTH; + } + CollectionElementFlag element_flags_anonymous_array_char_524288 = 0; + PlainCollectionHeader header_anonymous_array_char_524288 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_array_char_524288, element_flags_anonymous_array_char_524288); + { + LBoundSeq array_bound_seq; + TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast(524288)); + + PlainArrayLElemDefn array_ldefn = TypeObjectUtils::build_plain_array_l_elem_defn(header_anonymous_array_char_524288, array_bound_seq, + eprosima::fastcdr::external(element_identifier_anonymous_array_char_524288)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_l_array_type_identifier(array_ldefn, "anonymous_array_char_524288", type_ids_data)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_array_char_524288 already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_data = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_data = 0x00000000; + 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_BenchMarkMedium.reset(); + CompleteMemberDetail detail_data = TypeObjectUtils::build_complete_member_detail(name_data, member_ann_builtin_data, ann_custom_BenchMarkMedium); + CompleteStructMember member_data = TypeObjectUtils::build_complete_struct_member(common_data, detail_data); + TypeObjectUtils::add_complete_struct_member(member_seq_BenchMarkMedium, member_data); + } + { + 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 = 0x00000001; + 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_BenchMarkMedium.reset(); + CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_BenchMarkMedium); + CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); + TypeObjectUtils::add_complete_struct_member(member_seq_BenchMarkMedium, member_index); + } + CompleteStructType struct_type_BenchMarkMedium = TypeObjectUtils::build_complete_struct_type(struct_flags_BenchMarkMedium, header_BenchMarkMedium, member_seq_BenchMarkMedium); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_BenchMarkMedium, type_name_BenchMarkMedium.to_string(), type_ids_BenchMarkMedium)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "BenchMarkMedium already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/examples/cpp/benchmark/types/Benchmark_mediumTypeObjectSupport.hpp b/examples/cpp/benchmark/types/Benchmark_mediumTypeObjectSupport.hpp new file mode 100644 index 0000000000..31195a6430 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_mediumTypeObjectSupport.hpp @@ -0,0 +1,56 @@ +// 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 Benchmark_mediumTypeObjectSupport.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__BENCHMARK_MEDIUM_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__BENCHMARK_MEDIUM_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 BenchMarkMedium 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_BenchMarkMedium_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__BENCHMARK_MEDIUM_TYPE_OBJECT_SUPPORT_HPP diff --git a/examples/cpp/benchmark/types/Benchmark_small.hpp b/examples/cpp/benchmark/types/Benchmark_small.hpp new file mode 100644 index 0000000000..10e4860683 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_small.hpp @@ -0,0 +1,223 @@ +// 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 Benchmark_small.hpp + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BENCHMARK_SMALL_HPP +#define FAST_DDS_GENERATED__BENCHMARK_SMALL_HPP + +#include +#include +#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 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(BENCHMARK_SMALL_SOURCE) +#define BENCHMARK_SMALL_DllAPI __declspec( dllexport ) +#else +#define BENCHMARK_SMALL_DllAPI __declspec( dllimport ) +#endif // BENCHMARK_SMALL_SOURCE +#else +#define BENCHMARK_SMALL_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define BENCHMARK_SMALL_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the structure BenchMarkSmall defined by the user in the IDL file. + * @ingroup Benchmark_small + */ +class BenchMarkSmall +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport BenchMarkSmall() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~BenchMarkSmall() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object BenchMarkSmall that will be copied. + */ + eProsima_user_DllExport BenchMarkSmall( + const BenchMarkSmall& x) + { + m_array = x.m_array; + + m_index = x.m_index; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object BenchMarkSmall that will be copied. + */ + eProsima_user_DllExport BenchMarkSmall( + BenchMarkSmall&& x) noexcept + { + m_array = std::move(x.m_array); + m_index = x.m_index; + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object BenchMarkSmall that will be copied. + */ + eProsima_user_DllExport BenchMarkSmall& operator =( + const BenchMarkSmall& x) + { + + m_array = x.m_array; + + m_index = x.m_index; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object BenchMarkSmall that will be copied. + */ + eProsima_user_DllExport BenchMarkSmall& operator =( + BenchMarkSmall&& x) noexcept + { + + m_array = std::move(x.m_array); + m_index = x.m_index; + return *this; + } + + /*! + * @brief Comparison operator. + * @param x BenchMarkSmall object to compare. + */ + eProsima_user_DllExport bool operator ==( + const BenchMarkSmall& x) const + { + return (m_array == x.m_array && + m_index == x.m_index); + } + + /*! + * @brief Comparison operator. + * @param x BenchMarkSmall object to compare. + */ + eProsima_user_DllExport bool operator !=( + const BenchMarkSmall& x) const + { + return !(*this == x); + } + + /*! + * @brief This function copies the value in member array + * @param _array New value to be copied in member array + */ + eProsima_user_DllExport void array( + const std::array& _array) + { + m_array = _array; + } + + /*! + * @brief This function moves the value in member array + * @param _array New value to be moved in member array + */ + eProsima_user_DllExport void array( + std::array&& _array) + { + m_array = std::move(_array); + } + + /*! + * @brief This function returns a constant reference to member array + * @return Constant reference to member array + */ + eProsima_user_DllExport const std::array& array() const + { + return m_array; + } + + /*! + * @brief This function returns a reference to member array + * @return Reference to member array + */ + eProsima_user_DllExport std::array& array() + { + return m_array; + } + + /*! + * @brief This function sets a value in member index + * @param _index New value for member index + */ + eProsima_user_DllExport void index( + uint32_t _index) + { + m_index = _index; + } + + /*! + * @brief This function returns the value of member index + * @return Value of member index + */ + eProsima_user_DllExport uint32_t index() const + { + return m_index; + } + + /*! + * @brief This function returns a reference to member index + * @return Reference to member index + */ + eProsima_user_DllExport uint32_t& index() + { + return m_index; + } + +private: + + std::array m_array{0}; + uint32_t m_index{0}; + +}; + +#endif // _FAST_DDS_GENERATED_BENCHMARK_SMALL_HPP_ + + diff --git a/examples/cpp/benchmark/types/Benchmark_small.idl b/examples/cpp/benchmark/types/Benchmark_small.idl new file mode 100644 index 0000000000..a4fb883a96 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_small.idl @@ -0,0 +1,5 @@ +struct BenchMarkSmall +{ + char array[16384]; + unsigned long index; +}; diff --git a/examples/cpp/benchmark/types/Benchmark_smallCdrAux.hpp b/examples/cpp/benchmark/types/Benchmark_smallCdrAux.hpp new file mode 100644 index 0000000000..c3a7c2461e --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_smallCdrAux.hpp @@ -0,0 +1,46 @@ +// 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 Benchmark_smallCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BENCHMARK_SMALLCDRAUX_HPP +#define FAST_DDS_GENERATED__BENCHMARK_SMALLCDRAUX_HPP + +#include "Benchmark_small.hpp" + +constexpr uint32_t BenchMarkSmall_max_cdr_typesize {16392UL}; +constexpr uint32_t BenchMarkSmall_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const BenchMarkSmall& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__BENCHMARK_SMALLCDRAUX_HPP + diff --git a/examples/cpp/benchmark/types/Benchmark_smallCdrAux.ipp b/examples/cpp/benchmark/types/Benchmark_smallCdrAux.ipp new file mode 100644 index 0000000000..499a7f93c6 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_smallCdrAux.ipp @@ -0,0 +1,131 @@ +// 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 Benchmark_smallCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef FAST_DDS_GENERATED__BENCHMARK_SMALLCDRAUX_IPP +#define FAST_DDS_GENERATED__BENCHMARK_SMALLCDRAUX_IPP + +#include "Benchmark_smallCdrAux.hpp" + +#include +#include + + +#include +using namespace eprosima::fastcdr::exception; + +namespace eprosima { +namespace fastcdr { + +template<> +eProsima_user_DllExport size_t calculate_serialized_size( + eprosima::fastcdr::CdrSizeCalculator& calculator, + const BenchMarkSmall& data, + size_t& current_alignment) +{ + static_cast(data); + + eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding(); + size_t calculated_size {calculator.begin_calculate_type_serialized_size( + eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + current_alignment)}; + + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0), + data.array(), current_alignment); + + calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.index(), current_alignment); + + + calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment); + + return calculated_size; +} + +template<> +eProsima_user_DllExport void serialize( + eprosima::fastcdr::Cdr& scdr, + const BenchMarkSmall& data) +{ + eprosima::fastcdr::Cdr::state current_state(scdr); + scdr.begin_serialize_type(current_state, + eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR); + + scdr + << eprosima::fastcdr::MemberId(0) << data.array() + << eprosima::fastcdr::MemberId(1) << data.index() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + BenchMarkSmall& data) +{ + cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ? + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 : + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR, + [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool + { + bool ret_value = true; + switch (mid.id) + { + case 0: + dcdr >> data.array(); + break; + + case 1: + dcdr >> data.index(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const BenchMarkSmall& data) +{ + + static_cast(scdr); + static_cast(data); + scdr << data.array(); + + scdr << data.index(); + +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // FAST_DDS_GENERATED__BENCHMARK_SMALLCDRAUX_IPP + diff --git a/examples/cpp/benchmark/types/Benchmark_smallPubSubTypes.cxx b/examples/cpp/benchmark/types/Benchmark_smallPubSubTypes.cxx new file mode 100644 index 0000000000..62edd06476 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_smallPubSubTypes.cxx @@ -0,0 +1,218 @@ +// 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 Benchmark_smallPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "Benchmark_smallPubSubTypes.hpp" + +#include +#include + +#include "Benchmark_smallCdrAux.hpp" +#include "Benchmark_smallTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +BenchMarkSmallPubSubType::BenchMarkSmallPubSubType() +{ + set_name("BenchMarkSmall"); + uint32_t type_size = BenchMarkSmall_max_cdr_typesize; + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + max_serialized_type_size = type_size + 4; /*encapsulation*/ + is_compute_key_provided = false; + uint32_t key_length = BenchMarkSmall_max_key_cdr_typesize > 16 ? BenchMarkSmall_max_key_cdr_typesize : 16; + key_buffer_ = reinterpret_cast(malloc(key_length)); + memset(key_buffer_, 0, key_length); +} + +BenchMarkSmallPubSubType::~BenchMarkSmallPubSubType() +{ + if (key_buffer_ != nullptr) + { + free(key_buffer_); + } +} + +bool BenchMarkSmallPubSubType::serialize( + const void* const data, + SerializedPayload_t& payload, + DataRepresentationId_t data_representation) +{ + const BenchMarkSmall* 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; + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + ser.set_dds_cdr_options({0,0}); + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length + payload.length = static_cast(ser.get_serialized_data_length()); + return true; +} + +bool BenchMarkSmallPubSubType::deserialize( + SerializedPayload_t& payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + BenchMarkSmall* 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); + + // 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; +} + +uint32_t BenchMarkSmallPubSubType::calculate_serialized_size( + const void* const data, + DataRepresentationId_t data_representation) +{ + 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; + } +} + +void* BenchMarkSmallPubSubType::create_data() +{ + return reinterpret_cast(new BenchMarkSmall()); +} + +void BenchMarkSmallPubSubType::delete_data( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool BenchMarkSmallPubSubType::compute_key( + SerializedPayload_t& payload, + InstanceHandle_t& handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + BenchMarkSmall data; + if (deserialize(payload, static_cast(&data))) + { + return compute_key(static_cast(&data), handle, force_md5); + } + + return false; +} + +bool BenchMarkSmallPubSubType::compute_key( + const void* const data, + InstanceHandle_t& handle, + bool force_md5) +{ + if (!is_compute_key_provided) + { + return false; + } + + const BenchMarkSmall* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(key_buffer_), + BenchMarkSmall_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2); + ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2); + eprosima::fastcdr::serialize_key(ser, *p_type); + if (force_md5 || BenchMarkSmall_max_key_cdr_typesize > 16) + { + md5_.init(); + md5_.update(key_buffer_, static_cast(ser.get_serialized_data_length())); + md5_.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle.value[i] = md5_.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle.value[i] = key_buffer_[i]; + } + } + return true; +} + +void BenchMarkSmallPubSubType::register_type_object_representation() +{ + register_BenchMarkSmall_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "Benchmark_smallCdrAux.ipp" diff --git a/examples/cpp/benchmark/types/Benchmark_smallPubSubTypes.hpp b/examples/cpp/benchmark/types/Benchmark_smallPubSubTypes.hpp new file mode 100644 index 0000000000..07c4dc32dd --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_smallPubSubTypes.hpp @@ -0,0 +1,123 @@ +// 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 Benchmark_smallPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__BENCHMARK_SMALL_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__BENCHMARK_SMALL_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "Benchmark_small.hpp" + + +#if !defined(FASTDDS_GEN_API_VER) || (FASTDDS_GEN_API_VER != 3) +#error \ + Generated Benchmark_small is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // FASTDDS_GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type BenchMarkSmall defined by the user in the IDL file. + * @ingroup Benchmark_small + */ +class BenchMarkSmallPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef BenchMarkSmall type; + + eProsima_user_DllExport BenchMarkSmallPubSubType(); + + eProsima_user_DllExport ~BenchMarkSmallPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t& payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastdds::rtps::SerializedPayload_t& payload, + void* data) override; + + eProsima_user_DllExport uint32_t calculate_serialized_size( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool compute_key( + eprosima::fastdds::rtps::SerializedPayload_t& payload, + eprosima::fastdds::rtps::InstanceHandle_t& ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport bool compute_key( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t& ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* create_data() override; + + eProsima_user_DllExport void delete_data( + 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( + 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 + +private: + + eprosima::fastdds::MD5 md5_; + unsigned char* key_buffer_; + +}; + +#endif // FAST_DDS_GENERATED__BENCHMARK_SMALL_PUBSUBTYPES_HPP + diff --git a/examples/cpp/benchmark/types/Benchmark_smallTypeObjectSupport.cxx b/examples/cpp/benchmark/types/Benchmark_smallTypeObjectSupport.cxx new file mode 100644 index 0000000000..b766ec758a --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_smallTypeObjectSupport.cxx @@ -0,0 +1,164 @@ +// 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 Benchmark_smallTypeObjectSupport.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 "Benchmark_smallTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Benchmark_small.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_BenchMarkSmall_type_identifier( + TypeIdentifierPair& type_ids_BenchMarkSmall) +{ + + ReturnCode_t return_code_BenchMarkSmall {eprosima::fastdds::dds::RETCODE_OK}; + return_code_BenchMarkSmall = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "BenchMarkSmall", type_ids_BenchMarkSmall); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_BenchMarkSmall) + { + StructTypeFlag struct_flags_BenchMarkSmall = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_BenchMarkSmall = "BenchMarkSmall"; + eprosima::fastcdr::optional type_ann_builtin_BenchMarkSmall; + eprosima::fastcdr::optional ann_custom_BenchMarkSmall; + CompleteTypeDetail detail_BenchMarkSmall = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_BenchMarkSmall, ann_custom_BenchMarkSmall, type_name_BenchMarkSmall.to_string()); + CompleteStructHeader header_BenchMarkSmall; + header_BenchMarkSmall = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_BenchMarkSmall); + CompleteStructMemberSeq member_seq_BenchMarkSmall; + { + TypeIdentifierPair type_ids_array; + ReturnCode_t return_code_array {eprosima::fastdds::dds::RETCODE_OK}; + return_code_array = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_array_char_16384", type_ids_array); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_array) + { + return_code_array = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_char", type_ids_array); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_array) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "Array element TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + bool element_identifier_anonymous_array_char_16384_ec {false}; + TypeIdentifier* element_identifier_anonymous_array_char_16384 {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_array, element_identifier_anonymous_array_char_16384_ec))}; + if (!element_identifier_anonymous_array_char_16384_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Array element TypeIdentifier inconsistent."); + return; + } + EquivalenceKind equiv_kind_anonymous_array_char_16384 = EK_COMPLETE; + if (TK_NONE == type_ids_array.type_identifier2()._d()) + { + equiv_kind_anonymous_array_char_16384 = EK_BOTH; + } + CollectionElementFlag element_flags_anonymous_array_char_16384 = 0; + PlainCollectionHeader header_anonymous_array_char_16384 = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_array_char_16384, element_flags_anonymous_array_char_16384); + { + LBoundSeq array_bound_seq; + TypeObjectUtils::add_array_dimension(array_bound_seq, static_cast(16384)); + + PlainArrayLElemDefn array_ldefn = TypeObjectUtils::build_plain_array_l_elem_defn(header_anonymous_array_char_16384, array_bound_seq, + eprosima::fastcdr::external(element_identifier_anonymous_array_char_16384)); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_l_array_type_identifier(array_ldefn, "anonymous_array_char_16384", type_ids_array)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_array_char_16384 already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_array = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_array = 0x00000000; + bool common_array_ec {false}; + CommonStructMember common_array {TypeObjectUtils::build_common_struct_member(member_id_array, member_flags_array, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_array, common_array_ec))}; + if (!common_array_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure array member TypeIdentifier inconsistent."); + return; + } + MemberName name_array = "array"; + eprosima::fastcdr::optional member_ann_builtin_array; + ann_custom_BenchMarkSmall.reset(); + CompleteMemberDetail detail_array = TypeObjectUtils::build_complete_member_detail(name_array, member_ann_builtin_array, ann_custom_BenchMarkSmall); + CompleteStructMember member_array = TypeObjectUtils::build_complete_struct_member(common_array, detail_array); + TypeObjectUtils::add_complete_struct_member(member_seq_BenchMarkSmall, member_array); + } + { + 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 = 0x00000001; + 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_BenchMarkSmall.reset(); + CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_BenchMarkSmall); + CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); + TypeObjectUtils::add_complete_struct_member(member_seq_BenchMarkSmall, member_index); + } + CompleteStructType struct_type_BenchMarkSmall = TypeObjectUtils::build_complete_struct_type(struct_flags_BenchMarkSmall, header_BenchMarkSmall, member_seq_BenchMarkSmall); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_BenchMarkSmall, type_name_BenchMarkSmall.to_string(), type_ids_BenchMarkSmall)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "BenchMarkSmall already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/examples/cpp/benchmark/types/Benchmark_smallTypeObjectSupport.hpp b/examples/cpp/benchmark/types/Benchmark_smallTypeObjectSupport.hpp new file mode 100644 index 0000000000..407247c016 --- /dev/null +++ b/examples/cpp/benchmark/types/Benchmark_smallTypeObjectSupport.hpp @@ -0,0 +1,56 @@ +// 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 Benchmark_smallTypeObjectSupport.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__BENCHMARK_SMALL_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__BENCHMARK_SMALL_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 BenchMarkSmall 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_BenchMarkSmall_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // FAST_DDS_GENERATED__BENCHMARK_SMALL_TYPE_OBJECT_SUPPORT_HPP diff --git a/test/examples/benchmark.compose.yml b/test/examples/benchmark.compose.yml new file mode 100644 index 0000000000..843a0f222b --- /dev/null +++ b/test/examples/benchmark.compose.yml @@ -0,0 +1,46 @@ +# 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. + +services: + subscriber: + image: @DOCKER_IMAGE_NAME@ + network_mode: host + ipc: host + volumes: + - @PROJECT_BINARY_DIR_COMPOSE_VOLUME@ + - @fastcdr_LIB_DIR_COMPOSE_VOLUME@ + - @CMAKE_INSTALL_PREFIX_COMPOSE_VOLUME@ + @TINYXML2_LIB_DIR_COMPOSE_VOLUME@ + environment: + @PATH_ENVIRONMENT_VARIABLE_COMPOSE@ + EXAMPLE_DIR: @EXAMPLE_PREFIX_DIR_COMPOSE@/benchmark/@EXAMPLE_SUFFIX_DIR_COMPOSE@ + FASTDDS_DEFAULT_PROFILES_FILE: @FASTDDS_DEFAULT_PROFILES_FILE_PREFIX_COMPOSE@/benchmark/benchmark_profile.xml + SUBSCRIBER_ADDITIONAL_ARGUMENTS: ${SUB_ARGS} + command: @SHELL_EXECUTABLE@ -c "@COMMAND_EXAMPLE_DIR_PREFIX_COMPOSE@/benchmark@FILE_EXTENSION@ subscriber --reliable --transient-local --samples 1000 $${SUBSCRIBER_ADDITIONAL_ARGUMENTS}" + + publisher: + image: @DOCKER_IMAGE_NAME@ + network_mode: host + ipc: host + volumes: + - @PROJECT_BINARY_DIR_COMPOSE_VOLUME@ + - @fastcdr_LIB_DIR_COMPOSE_VOLUME@ + - @CMAKE_INSTALL_PREFIX_COMPOSE_VOLUME@ + @TINYXML2_LIB_DIR_COMPOSE_VOLUME@ + environment: + @PATH_ENVIRONMENT_VARIABLE_COMPOSE@ + EXAMPLE_DIR: @EXAMPLE_PREFIX_DIR_COMPOSE@/benchmark/@EXAMPLE_SUFFIX_DIR_COMPOSE@ + FASTDDS_DEFAULT_PROFILES_FILE: @FASTDDS_DEFAULT_PROFILES_FILE_PREFIX_COMPOSE@/benchmark/benchmark_profile.xml + PUBLISHER_ADDITIONAL_ARGUMENTS: ${PUB_ARGS} + command: @SHELL_EXECUTABLE@ -c "@COMMAND_EXAMPLE_DIR_PREFIX_COMPOSE@/benchmark@FILE_EXTENSION@ publisher --reliable --transient-local --samples 1000 $${PUBLISHER_ADDITIONAL_ARGUMENTS}" diff --git a/test/examples/test_benchmark.py b/test/examples/test_benchmark.py new file mode 100644 index 0000000000..54d227d9ab --- /dev/null +++ b/test/examples/test_benchmark.py @@ -0,0 +1,78 @@ +# 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 + +config_test_cases = [ + ('--transport DEFAULT --msg-size NONE', '--transport DEFAULT --msg-size NONE'), + ('--transport DEFAULT --msg-size SMALL', '--transport DEFAULT --msg-size SMALL'), + ('--transport DEFAULT --msg-size MEDIUM', '--transport DEFAULT --msg-size MEDIUM'), + ('--transport DEFAULT --msg-size BIG', '--transport DEFAULT --msg-size BIG'), + ('--transport DEFAULT --msg-size NONE', '--transport UDPv4 --msg-size NONE'), + ('--transport DEFAULT --msg-size SMALL', '--transport UDPv4 --msg-size SMALL'), + ('--transport DEFAULT --msg-size MEDIUM', '--transport UDPv4 --msg-size MEDIUM'), + ('--transport DEFAULT --msg-size BIG', '--transport UDPv4 --msg-size BIG'), + ('--transport SHM --msg-size NONE', '--transport SHM --msg-size NONE'), + ('--transport SHM --msg-size SMALL', '--transport SHM --msg-size SMALL'), + ('--transport SHM --msg-size MEDIUM', '--transport SHM --msg-size MEDIUM'), + ('--transport SHM --msg-size BIG', '--transport SHM --msg-size BIG'), + ('--transport UDPv4 --msg-size NONE', '--transport UDPv4 --msg-size NONE'), + ('--transport UDPv4 --msg-size SMALL', '--transport UDPv4 --msg-size SMALL'), + ('--transport UDPv4 --msg-size MEDIUM', '--transport UDPv4 --msg-size MEDIUM'), + ('--transport UDPv4 --msg-size BIG', '--transport UDPv4 --msg-size BIG'), + ('--transport LARGE_DATA --msg-size NONE', '--transport LARGE_DATA --msg-size NONE'), + ('--transport LARGE_DATA --msg-size SMALL', '--transport LARGE_DATA --msg-size SMALL'), + ('--transport LARGE_DATA --msg-size MEDIUM', '--transport LARGE_DATA --msg-size MEDIUM'), + ('--transport LARGE_DATA --msg-size BIG', '--transport LARGE_DATA --msg-size BIG'), +] + +@pytest.mark.parametrize("pub_args, sub_args", config_test_cases) +def test_benchmark(pub_args, sub_args): + """.""" + ret = False + out = '' + + command_prerequisites = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" ' + + try: + out = subprocess.check_output(command_prerequisites + '@DOCKER_EXECUTABLE@ compose -f benchmark.compose.yml up', + stderr=subprocess.STDOUT, + shell=True, + timeout=5 + ).decode().split('\n') + + sent = 0 + received = 0 + for line in out: + if 'SENT' in line: + sent += 1 + + if 'RECEIVED' in line: + received += 1 + + if sent != 0 and received != 0 and sent == received: + ret = True + else: + print ('ERROR: sent: ' + str(sent) + ', but received: ' + str(received) + ' (expected: ' + str(sent) + ')') + raise subprocess.CalledProcessError(1, out.decode()) + + except subprocess.CalledProcessError as e: + print (e.output) + except subprocess.TimeoutExpired: + print('TIMEOUT') + print(out) + + assert(ret) diff --git a/versions.md b/versions.md index c7751d51bc..d57e8ef4cb 100644 --- a/versions.md +++ b/versions.md @@ -10,6 +10,7 @@ Forthcoming * Machine UUID added to the Data(p) to check Participants in same host, instead of using GUIDs. * Windows ci example testing infrastructure and `hello world` example. * New property to configure the preferred key agreement algorithm. +* Refactor benchmark example. Version v3.1.0 --------------