From dfecea5b915f6a60d534a9883bca597d10536cee Mon Sep 17 00:00:00 2001 From: elianalf <62831776+elianalf@users.noreply.github.com> Date: Fri, 7 Jun 2024 09:49:53 +0200 Subject: [PATCH] Refs #21094: Apply suggestions Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com> --- .../cpp/custom_payload_pool/CLIParser.hpp | 50 ++++++++++++++++++- .../custom_payload_pool/CustomPayloadPool.hpp | 6 +-- .../cpp/custom_payload_pool/PublisherApp.cpp | 5 +- .../cpp/custom_payload_pool/PublisherApp.hpp | 6 +-- .../cpp/custom_payload_pool/SubscriberApp.cpp | 5 +- .../cpp/custom_payload_pool/SubscriberApp.hpp | 6 +-- test/examples/custom_payload_pool.compose.yml | 2 +- versions.md | 2 +- 8 files changed, 66 insertions(+), 16 deletions(-) diff --git a/examples/cpp/custom_payload_pool/CLIParser.hpp b/examples/cpp/custom_payload_pool/CLIParser.hpp index 5e041e51817..f40449c35bb 100644 --- a/examples/cpp/custom_payload_pool/CLIParser.hpp +++ b/examples/cpp/custom_payload_pool/CLIParser.hpp @@ -46,6 +46,7 @@ class CLIParser struct subscriber_config { uint16_t samples = 0; + uint16_t domain = 0; }; //! Publisher application configuration structure @@ -83,6 +84,8 @@ class CLIParser std::cout << " -s , --samples Number of samples to send or receive" << std::endl; std::cout << " [0 <= <= 65535]" << std::endl; std::cout << " (Default: 0 [unlimited])" << std::endl; + std::cout << " -d , --domain Domain ID number [0 <= <= 232]" << std::endl; + std::cout << " (Default: 0)" << std::endl; std::cout << "Publisher options:" << std::endl; std::cout << " -i, --interval Time between samples in milliseconds " << std::endl; std::cout << " (Default: 100)" << std::endl; @@ -183,6 +186,51 @@ class CLIParser EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg); print_help(EXIT_FAILURE); } + } + else if (arg == "-d" || arg == "--domain") + { + if (i + 1 < argc) + { + try + { + int input = std::stoi(argv[++i]); + if (input < 0 || input > 232) + { + throw std::out_of_range("domain argument out of range"); + } + else + { + if (config.entity == CLIParser::EntityKind::PUBLISHER) + { + config.pub_config.domain = static_cast(input); + } + else if (config.entity == CLIParser::EntityKind::SUBSCRIBER) + { + config.sub_config.domain = static_cast(input); + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "entity not specified for --domain argument"); + print_help(EXIT_FAILURE); + } + } + } + catch (const std::invalid_argument& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid domain argument for " + arg + ": " + e.what()); + print_help(EXIT_FAILURE); + } + catch (const std::out_of_range& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "domain argument out of range for " + arg + ": " + e.what()); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg); + print_help(EXIT_FAILURE); + } } else if (arg == "-i" || arg == "--interval") { @@ -192,7 +240,7 @@ class CLIParser { if (config.entity == CLIParser::EntityKind::PUBLISHER) { - config.pub_config.interval = std::stoi(argv[++i]); + config.pub_config.interval = static_cast(std::stoi(argv[++i])); } else { diff --git a/examples/cpp/custom_payload_pool/CustomPayloadPool.hpp b/examples/cpp/custom_payload_pool/CustomPayloadPool.hpp index 5f5c60f3d41..6365c48050f 100644 --- a/examples/cpp/custom_payload_pool/CustomPayloadPool.hpp +++ b/examples/cpp/custom_payload_pool/CustomPayloadPool.hpp @@ -16,8 +16,8 @@ * @file CustomPayloadPool.hpp */ -#ifndef DDS_CUSTOM_PAYLOAD_POOL_DATA_HPP -#define DDS_CUSTOM_PAYLOAD_POOL_DATA_HPP +#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_HPP_ +#define _FASTDDS_CUSTOM_PAYLOAD_POOL_HPP_ #include #include @@ -97,4 +97,4 @@ class CustomPayloadPool : public eprosima::fastrtps::rtps::IPayloadPool }; -#endif // DDS_CUSTOM_PAYLOAD_POOL_DATA_HPP +#endif // _FASTDDS_CUSTOM_PAYLOAD_POOL_HPP_ diff --git a/examples/cpp/custom_payload_pool/PublisherApp.cpp b/examples/cpp/custom_payload_pool/PublisherApp.cpp index 91315bb39b3..2400e64a9fb 100644 --- a/examples/cpp/custom_payload_pool/PublisherApp.cpp +++ b/examples/cpp/custom_payload_pool/PublisherApp.cpp @@ -56,8 +56,9 @@ PublisherApp::PublisherApp( payload_pool_ = std::make_shared(); // Create the participant + DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT; auto factory = DomainParticipantFactory::get_instance(); - participant_ = factory->create_participant_with_default_profile(nullptr, StatusMask::none()); + participant_ = factory->create_participant(config.domain, pqos); if (participant_ == nullptr) { throw std::runtime_error("Participant initialization failed"); @@ -176,4 +177,4 @@ void PublisherApp::stop() } // namespace custom_payload_pool } // namespace examples } // namespace fastdds -} // namespace eprosima \ No newline at end of file +} // namespace eprosima diff --git a/examples/cpp/custom_payload_pool/PublisherApp.hpp b/examples/cpp/custom_payload_pool/PublisherApp.hpp index 6f70da642d5..f65898d3485 100644 --- a/examples/cpp/custom_payload_pool/PublisherApp.hpp +++ b/examples/cpp/custom_payload_pool/PublisherApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_DATA_PUBLISHER_HPP_ -#define _FASTDDS_CUSTOM_PAYLOAD_POOL_DATA_PUBLISHER_HPP_ +#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_PUBLISHER_HPP_ +#define _FASTDDS_CUSTOM_PAYLOAD_POOL_PUBLISHER_HPP_ #include #include @@ -103,4 +103,4 @@ class PublisherApp : public Application, public DataWriterListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_CUSTOM_PAYLOAD_POOL_DATA_PUBLISHER_H_ */ +#endif /* _FASTDDS_CUSTOM_PAYLOAD_POOL_PUBLISHER_H_ */ diff --git a/examples/cpp/custom_payload_pool/SubscriberApp.cpp b/examples/cpp/custom_payload_pool/SubscriberApp.cpp index 90f2c6d00e3..9bd398cffc8 100644 --- a/examples/cpp/custom_payload_pool/SubscriberApp.cpp +++ b/examples/cpp/custom_payload_pool/SubscriberApp.cpp @@ -51,8 +51,9 @@ SubscriberApp::SubscriberApp( payload_pool_ = std::make_shared(); // Create the participant + DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT; auto factory = DomainParticipantFactory::get_instance(); - participant_ = factory->create_participant_with_default_profile(nullptr, StatusMask::none()); + participant_ = factory->create_participant(config.domain, pqos); if (participant_ == nullptr) { throw std::runtime_error("Participant initialization failed"); @@ -160,4 +161,4 @@ void SubscriberApp::stop() } // namespace custom_payload_pool } // namespace examples } // namespace fastdds -} // namespace eprosima \ No newline at end of file +} // namespace eprosima diff --git a/examples/cpp/custom_payload_pool/SubscriberApp.hpp b/examples/cpp/custom_payload_pool/SubscriberApp.hpp index 90c9a83126b..345c4c05821 100644 --- a/examples/cpp/custom_payload_pool/SubscriberApp.hpp +++ b/examples/cpp/custom_payload_pool/SubscriberApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_DATA_SUBSCRIBER_HPP_ -#define _FASTDDS_CUSTOM_PAYLOAD_POOL_DATA_SUBSCRIBER_HPP_ +#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_SUBSCRIBER_HPP_ +#define _FASTDDS_CUSTOM_PAYLOAD_POOL_SUBSCRIBER_HPP_ #include #include @@ -101,4 +101,4 @@ class SubscriberApp : public Application, public DataReaderListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_CUSTOM_PAYLOAD_POOL_DATA_SUBSCRIBER_HPP_ */ +#endif /* _FASTDDS_CUSTOM_PAYLOAD_POOL_SUBSCRIBER_HPP_ */ diff --git a/test/examples/custom_payload_pool.compose.yml b/test/examples/custom_payload_pool.compose.yml index bb3f0ac662d..51255be654d 100644 --- a/test/examples/custom_payload_pool.compose.yml +++ b/test/examples/custom_payload_pool.compose.yml @@ -26,4 +26,4 @@ services: EXAMPLE_DIR: @PROJECT_BINARY_DIR@/examples/cpp/custom_payload_pool command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/custom_payload_pool@FILE_EXTENSION@ publisher --samples 10" depends_on: - - subscriber \ No newline at end of file + - subscriber diff --git a/versions.md b/versions.md index 8fdc50efcbe..99be0d34260 100644 --- a/versions.md +++ b/versions.md @@ -41,7 +41,7 @@ Forthcoming * Refactor examples: * Hello world example with wait-sets and environment XML profiles. * Configuration example that condenses multiple QoS examples. Multiple configurations allowed through argument parsing. - * Custom payload pool example. + * Custom payload pool example that uses a user-defined payload pool instead of the default * Removed `TypeConsistencyQos` from DataReader, and included `TypeConsistencyEnforcementQosPolicy` and `DataRepresentationQosPolicy` * Added new `flow_controller_descriptor_list` XML configuration, remove `ThroughtputController`. * Migrate `#define`s within `BuiltinEndpoints.hpp` to namespaced `constexpr` variables.