From 38f516832a37a7716848220a86aed106b8ef48d2 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Fri, 7 Jun 2024 11:14:49 +0200 Subject: [PATCH 01/18] Refs #21095: Remove old DiscoveryServerExample Signed-off-by: Mario Dominguez --- examples/cpp/dds/CMakeLists.txt | 1 - .../dds/DiscoveryServerExample/CMakeLists.txt | 49 --- .../DiscoveryServerPublisher.cpp | 311 ---------------- .../DiscoveryServerPublisher.h | 126 ------- .../DiscoveryServerServer.cpp | 292 --------------- .../DiscoveryServerServer.h | 105 ------ .../DiscoveryServerSubscriber.cpp | 331 ----------------- .../DiscoveryServerSubscriber.h | 140 ------- .../DiscoveryServer_main.cpp | 331 ----------------- .../cpp/dds/DiscoveryServerExample/README.md | 65 ---- .../arg_configuration.h | 345 ------------------ .../cpp/dds/DiscoveryServerExample/common.h | 80 ---- .../types/HelloWorld.hpp | 227 ------------ .../types/HelloWorld.idl | 5 - .../types/HelloWorldCdrAux.hpp | 46 --- .../types/HelloWorldCdrAux.ipp | 126 ------- .../types/HelloWorldPubSubTypes.cxx | 229 ------------ .../types/HelloWorldPubSubTypes.hpp | 133 ------- .../types/HelloWorldTypeObjectSupport.cxx | 138 ------- .../types/HelloWorldTypeObjectSupport.hpp | 56 --- 20 files changed, 3136 deletions(-) delete mode 100644 examples/cpp/dds/DiscoveryServerExample/CMakeLists.txt delete mode 100644 examples/cpp/dds/DiscoveryServerExample/DiscoveryServerPublisher.cpp delete mode 100644 examples/cpp/dds/DiscoveryServerExample/DiscoveryServerPublisher.h delete mode 100644 examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.cpp delete mode 100644 examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.h delete mode 100644 examples/cpp/dds/DiscoveryServerExample/DiscoveryServerSubscriber.cpp delete mode 100644 examples/cpp/dds/DiscoveryServerExample/DiscoveryServerSubscriber.h delete mode 100644 examples/cpp/dds/DiscoveryServerExample/DiscoveryServer_main.cpp delete mode 100644 examples/cpp/dds/DiscoveryServerExample/README.md delete mode 100644 examples/cpp/dds/DiscoveryServerExample/arg_configuration.h delete mode 100644 examples/cpp/dds/DiscoveryServerExample/common.h delete mode 100644 examples/cpp/dds/DiscoveryServerExample/types/HelloWorld.hpp delete mode 100644 examples/cpp/dds/DiscoveryServerExample/types/HelloWorld.idl delete mode 100644 examples/cpp/dds/DiscoveryServerExample/types/HelloWorldCdrAux.hpp delete mode 100644 examples/cpp/dds/DiscoveryServerExample/types/HelloWorldCdrAux.ipp delete mode 100644 examples/cpp/dds/DiscoveryServerExample/types/HelloWorldPubSubTypes.cxx delete mode 100644 examples/cpp/dds/DiscoveryServerExample/types/HelloWorldPubSubTypes.hpp delete mode 100644 examples/cpp/dds/DiscoveryServerExample/types/HelloWorldTypeObjectSupport.cxx delete mode 100644 examples/cpp/dds/DiscoveryServerExample/types/HelloWorldTypeObjectSupport.hpp diff --git a/examples/cpp/dds/CMakeLists.txt b/examples/cpp/dds/CMakeLists.txt index 8585624b003..32ea44c1f70 100644 --- a/examples/cpp/dds/CMakeLists.txt +++ b/examples/cpp/dds/CMakeLists.txt @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -add_subdirectory(DiscoveryServerExample) add_subdirectory(DynamicHelloWorldExample) add_subdirectory(FlowControlExample) add_subdirectory(HelloWorldExampleDataSharing) diff --git a/examples/cpp/dds/DiscoveryServerExample/CMakeLists.txt b/examples/cpp/dds/DiscoveryServerExample/CMakeLists.txt deleted file mode 100644 index 035ff741189..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -cmake_minimum_required(VERSION 3.20) - -project(DiscoveryServerExample 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) - check_cxx_compiler_flag(-std=c++11 SUPPORTS_CXX11) - if(NOT SUPPORTS_CXX11) - message(FATAL_ERROR "Compiler doesn't support C++11") - endif() -endif() - -message(STATUS "Configuring DiscoveryServerExample example...") -file(GLOB DISCOVERY_SERVER_EXAMPLE_SOURCES_CXX "types/*.cxx") -file(GLOB DISCOVERY_SERVER_EXAMPLE_SOURCES_CPP "*.cpp") - -add_executable(${PROJECT_NAME} ${DISCOVERY_SERVER_EXAMPLE_SOURCES_CXX} ${DISCOVERY_SERVER_EXAMPLE_SOURCES_CPP}) -target_compile_definitions(${PROJECT_NAME} PRIVATE - $<$>,$>:__DEBUG> - $<$:__INTERNALDEBUG> # Internal debug activated. -) -target_link_libraries(${PROJECT_NAME} fastdds fastcdr fastdds::optionparser) -install(TARGETS ${PROJECT_NAME} - RUNTIME DESTINATION examples/cpp/dds/${PROJECT_NAME}/${BIN_INSTALL_DIR}) diff --git a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerPublisher.cpp b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerPublisher.cpp deleted file mode 100644 index ae9e061e35b..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerPublisher.cpp +++ /dev/null @@ -1,311 +0,0 @@ -// Copyright 2021 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 DiscoveryServerPublisher.cpp - * - */ - -#include "DiscoveryServerPublisher.h" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace eprosima::fastdds::dds; -using namespace eprosima::fastdds::rtps; - -std::atomic HelloWorldPublisher::stop_(false); - -HelloWorldPublisher::HelloWorldPublisher() - : participant_(nullptr) - , publisher_(nullptr) - , topic_(nullptr) - , writer_(nullptr) - , type_(new HelloWorldPubSubType()) -{ -} - -bool HelloWorldPublisher::is_stopped() -{ - return stop_; -} - -void HelloWorldPublisher::stop() -{ - stop_ = true; -} - -bool HelloWorldPublisher::init( - const std::string& topic_name, - const std::string& server_address, - unsigned short server_port, - TransportKind transport) -{ - hello_.index(0); - hello_.message("HelloWorld"); - DomainParticipantQos pqos; - pqos.name("DS-Client_pub"); - pqos.transport().use_builtin_transports = false; - - std::string ip_server_address(server_address); - // Check if DNS is required - if (!is_ip(server_address)) - { - ip_server_address = get_ip_from_dns(server_address, transport); - } - - if (ip_server_address.empty()) - { - return false; - } - - // Create DS SERVER locator - eprosima::fastdds::rtps::Locator server_locator; - eprosima::fastdds::rtps::IPLocator::setPhysicalPort(server_locator, server_port); - - std::shared_ptr descriptor; - - switch (transport) - { - case TransportKind::SHM: - descriptor = std::make_shared(); - server_locator.kind = LOCATOR_KIND_SHM; - break; - - case TransportKind::UDPv4: - { - auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); - descriptor = descriptor_tmp; - - server_locator.kind = LOCATOR_KIND_UDPv4; - eprosima::fastdds::rtps::IPLocator::setIPv4(server_locator, ip_server_address); - break; - } - - case TransportKind::UDPv6: - { - auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); - descriptor = descriptor_tmp; - - server_locator.kind = LOCATOR_KIND_UDPv6; - eprosima::fastdds::rtps::IPLocator::setIPv6(server_locator, ip_server_address); - break; - } - - case TransportKind::TCPv4: - { - auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); - // One listening port must be added either in the pub or the sub - descriptor_tmp->add_listener_port(0); - descriptor = descriptor_tmp; - - server_locator.kind = LOCATOR_KIND_TCPv4; - eprosima::fastdds::rtps::IPLocator::setLogicalPort(server_locator, server_port); - eprosima::fastdds::rtps::IPLocator::setIPv4(server_locator, ip_server_address); - break; - } - - case TransportKind::TCPv6: - { - auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); - // One listening port must be added either in the pub or the sub - descriptor_tmp->add_listener_port(0); - descriptor = descriptor_tmp; - - server_locator.kind = LOCATOR_KIND_TCPv6; - eprosima::fastdds::rtps::IPLocator::setLogicalPort(server_locator, server_port); - if (eprosima::fastdds::rtps::IPLocator::isIPv6(ip_server_address)) - { - eprosima::fastdds::rtps::IPLocator::setIPv6(server_locator, ip_server_address); - } - else - { - eprosima::fastdds::rtps::IPLocator::setIPv6(server_locator, "::1"); - } - break; - } - - default: - break; - } - - // Set participant as DS CLIENT - pqos.wire_protocol().builtin.discovery_config.discoveryProtocol = - eprosima::fastdds::rtps::DiscoveryProtocol::CLIENT; - - // Add remote SERVER to CLIENT's list of SERVERs - pqos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(server_locator); - - // Add descriptor - pqos.transport().user_transports.push_back(descriptor); - - // CREATE THE PARTICIPANT - participant_ = DomainParticipantFactory::get_instance()->create_participant(0, pqos, &listener_); - - if (participant_ == nullptr) - { - return false; - } - - std::cout << - "Publisher Participant " << pqos.name() << - " created with GUID " << participant_->guid() << - " connecting to server <" << server_locator << "> " << - std::endl; - - // REGISTER THE TYPE - type_.register_type(participant_); - - // CREATE THE PUBLISHER - publisher_ = participant_->create_publisher(PUBLISHER_QOS_DEFAULT, nullptr); - - if (publisher_ == nullptr) - { - return false; - } - - // CREATE THE TOPIC - topic_ = participant_->create_topic(topic_name, "HelloWorld", TOPIC_QOS_DEFAULT); - - if (topic_ == nullptr) - { - return false; - } - - // CREATE THE WRITER - DataWriterQos wqos = DATAWRITER_QOS_DEFAULT; - writer_ = publisher_->create_datawriter(topic_, wqos, &listener_); - - if (writer_ == nullptr) - { - return false; - } - return true; -} - -HelloWorldPublisher::~HelloWorldPublisher() -{ - if (participant_ != nullptr) - { - if (publisher_ != nullptr) - { - if (writer_ != nullptr) - { - publisher_->delete_datawriter(writer_); - } - participant_->delete_publisher(publisher_); - } - if (topic_ != nullptr) - { - participant_->delete_topic(topic_); - } - DomainParticipantFactory::get_instance()->delete_participant(participant_); - } -} - -void HelloWorldPublisher::PubListener::on_publication_matched( - eprosima::fastdds::dds::DataWriter*, - const eprosima::fastdds::dds::PublicationMatchedStatus& info) -{ - if (info.current_count_change == 1) - { - matched_ = info.current_count; - std::cout << "Publisher matched." << std::endl; - } - else if (info.current_count_change == -1) - { - matched_ = 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 HelloWorldPublisher::PubListener::on_participant_discovery( - eprosima::fastdds::dds::DomainParticipant* /*participant*/, - eprosima::fastdds::rtps::ParticipantDiscoveryInfo&& info, - bool& should_be_ignored) -{ - static_cast(should_be_ignored); - if (info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT) - { - std::cout << "Discovered Participant with GUID " << info.info.m_guid << std::endl; - } - else if (info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT || - info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT) - { - std::cout << "Dropped Participant with GUID " << info.info.m_guid << std::endl; - } -} - -void HelloWorldPublisher::runThread( - uint32_t samples, - uint32_t sleep) -{ - while (!is_stopped() && (samples == 0 || hello_.index() < samples)) - { - publish(); - std::cout << "Message: " << hello_.message() << " with index: " << hello_.index() - << " SENT" << std::endl; - std::this_thread::sleep_for(std::chrono::milliseconds(sleep)); - } -} - -void HelloWorldPublisher::run( - uint32_t samples, - uint32_t sleep) -{ - stop_ = false; - std::thread thread(&HelloWorldPublisher::runThread, this, samples, sleep); - if (samples == 0) - { - std::cout << "Publisher running. Please press CTRL+C to stop the Publisher at any time." << std::endl; - } - else - { - std::cout << "Publisher running " << samples << - " samples. Please press CTRL+C to stop the Publisher at any time." << std::endl; - } - signal(SIGINT, [](int signum) - { - std::cout << "SIGINT received, stopping Publisher execution." << std::endl; - static_cast(signum); HelloWorldPublisher::stop(); - }); - thread.join(); -} - -void HelloWorldPublisher::publish() -{ - hello_.index(hello_.index() + 1); - writer_->write(&hello_); -} diff --git a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerPublisher.h b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerPublisher.h deleted file mode 100644 index 8397dd5472b..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerPublisher.h +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2021 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 DiscoveryServerPublisher.h - * - */ - -#ifndef _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERPUBLISHER_H_ -#define _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERPUBLISHER_H_ - -#include - -#include -#include -#include - -#include "types/HelloWorldPubSubTypes.hpp" -#include "common.h" - -/** - * Class used to group into a single working unit a Publisher with a DataWriter, its listener, and a TypeSupport member - * corresponding to the HelloWorld datatype - */ -class HelloWorldPublisher -{ -public: - - HelloWorldPublisher(); - - virtual ~HelloWorldPublisher(); - - //! Initialize the publisher - bool init( - const std::string& topic_name, - const std::string& server_address, - unsigned short server_port, - TransportKind transport); - - //! Publish a sample - void publish(); - - //! Run for number samples, publish every sleep seconds - void run( - uint32_t number, - uint32_t sleep); - - //! Return the current state of execution - static bool is_stopped(); - - //! Trigger the end of execution - static void stop(); - -private: - - HelloWorld hello_; - - eprosima::fastdds::dds::DomainParticipant* participant_; - - eprosima::fastdds::dds::Publisher* publisher_; - - eprosima::fastdds::dds::Topic* topic_; - - eprosima::fastdds::dds::DataWriter* writer_; - - eprosima::fastdds::dds::TypeSupport type_; - - /** - * Class handling discovery events - */ - class PubListener : public eprosima::fastdds::dds::DomainParticipantListener - { - public: - - PubListener() - : matched_(0) - { - } - - ~PubListener() override - { - } - - //! Callback executed when a DataReader is matched or unmatched - void on_publication_matched( - eprosima::fastdds::dds::DataWriter* writer, - const eprosima::fastdds::dds::PublicationMatchedStatus& info) override; - - //! Callback executed when a DomainParticipant is discovered, dropped or removed - void on_participant_discovery( - eprosima::fastdds::dds::DomainParticipant* /*participant*/, - eprosima::fastdds::rtps::ParticipantDiscoveryInfo&& info, - bool& should_be_ignored) override; - - private: - - using eprosima::fastdds::dds::DomainParticipantListener::on_participant_discovery; - - //! Number of DataReaders matched to the associated DataWriter - std::atomic matched_; - } - listener_; - - //! Run thread for number samples, publish every sleep seconds - void runThread( - uint32_t number, - uint32_t sleep); - - //! Member used for control flow purposes - static std::atomic stop_; -}; - - - -#endif /* _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERPUBLISHER_H_ */ diff --git a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.cpp b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.cpp deleted file mode 100644 index e659bd8ad39..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.cpp +++ /dev/null @@ -1,292 +0,0 @@ -// Copyright 2021 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 DiscoveryServerServer.cpp - * - */ - -#include "DiscoveryServerServer.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -using namespace eprosima::fastdds::dds; -using namespace eprosima::fastdds::rtps; - -std::atomic DiscoveryServer::stop_(false); -std::mutex DiscoveryServer::terminate_cv_mtx_; -std::condition_variable DiscoveryServer::terminate_cv_; - -DiscoveryServer::DiscoveryServer() - : participant_(nullptr) -{ -} - -bool DiscoveryServer::is_stopped() -{ - return stop_; -} - -void DiscoveryServer::stop() -{ - stop_ = true; - terminate_cv_.notify_all(); -} - -bool DiscoveryServer::init( - const std::string& server_address, - unsigned short server_port, - TransportKind transport, - bool has_connection_server, - const std::string& connection_server_address, - unsigned short connection_server_port) -{ - DomainParticipantQos pqos; - pqos.name("DS-Server"); - pqos.transport().use_builtin_transports = false; - - std::string ip_listening_address(server_address); - std::string ip_connection_address(connection_server_address); - // Check if DNS is required - if (!is_ip(server_address)) - { - ip_listening_address = get_ip_from_dns(server_address, transport); - } - - if (ip_listening_address.empty()) - { - return false; - } - - // Do the same for connection - if (has_connection_server && !is_ip(connection_server_address)) - { - ip_connection_address = get_ip_from_dns(connection_server_address, transport); - } - - if (has_connection_server && ip_connection_address.empty()) - { - return false; - } - - /////////////////////////////// - // Configure Listening address - /////////////////////////////// - - // Create DS SERVER locator - eprosima::fastdds::rtps::Locator listening_locator; - eprosima::fastdds::rtps::Locator connection_locator; - eprosima::fastdds::rtps::IPLocator::setPhysicalPort(listening_locator, server_port); - eprosima::fastdds::rtps::IPLocator::setPhysicalPort(connection_locator, connection_server_port); - - std::shared_ptr descriptor; - - switch (transport) - { - case TransportKind::SHM: - descriptor = std::make_shared(); - listening_locator.kind = LOCATOR_KIND_SHM; - connection_locator.kind = LOCATOR_KIND_SHM; - break; - - case TransportKind::UDPv4: - { - auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_listening_address); - descriptor = descriptor_tmp; - - listening_locator.kind = LOCATOR_KIND_UDPv4; - eprosima::fastdds::rtps::IPLocator::setIPv4(listening_locator, ip_listening_address); - connection_locator.kind = LOCATOR_KIND_UDPv4; - eprosima::fastdds::rtps::IPLocator::setIPv4(connection_locator, ip_connection_address); - break; - } - - case TransportKind::UDPv6: - { - auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_listening_address); - descriptor = descriptor_tmp; - - listening_locator.kind = LOCATOR_KIND_UDPv6; - eprosima::fastdds::rtps::IPLocator::setIPv6(listening_locator, ip_listening_address); - connection_locator.kind = LOCATOR_KIND_UDPv6; - eprosima::fastdds::rtps::IPLocator::setIPv6(connection_locator, ip_connection_address); - break; - } - - case TransportKind::TCPv4: - { - auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_listening_address); - descriptor_tmp->add_listener_port(server_port); - descriptor = descriptor_tmp; - - listening_locator.kind = LOCATOR_KIND_TCPv4; - eprosima::fastdds::rtps::IPLocator::setLogicalPort(listening_locator, server_port); - eprosima::fastdds::rtps::IPLocator::setIPv4(listening_locator, ip_listening_address); - connection_locator.kind = LOCATOR_KIND_TCPv4; - eprosima::fastdds::rtps::IPLocator::setIPv4(connection_locator, ip_connection_address); - eprosima::fastdds::rtps::IPLocator::setLogicalPort(connection_locator, connection_server_port); - break; - } - - case TransportKind::TCPv6: - { - auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_listening_address); - descriptor_tmp->add_listener_port(server_port); - descriptor = descriptor_tmp; - - listening_locator.kind = LOCATOR_KIND_TCPv6; - eprosima::fastdds::rtps::IPLocator::setLogicalPort(listening_locator, server_port); - if (eprosima::fastdds::rtps::IPLocator::isIPv6(ip_listening_address)) - { - eprosima::fastdds::rtps::IPLocator::setIPv6(listening_locator, ip_listening_address); - } - else - { - eprosima::fastdds::rtps::IPLocator::setIPv6(listening_locator, "::1"); - } - connection_locator.kind = LOCATOR_KIND_TCPv6; - eprosima::fastdds::rtps::IPLocator::setIPv6(connection_locator, ip_connection_address); - eprosima::fastdds::rtps::IPLocator::setLogicalPort(connection_locator, connection_server_port); - break; - } - - default: - break; - } - - // Add descriptor - pqos.transport().user_transports.push_back(descriptor); - - // Set participant as SERVER - pqos.wire_protocol().builtin.discovery_config.discoveryProtocol = - eprosima::fastdds::rtps::DiscoveryProtocol::SERVER; - - // Set SERVER's listening locator for PDP - pqos.wire_protocol().builtin.metatrafficUnicastLocatorList.push_back(listening_locator); - - /////////////////////////////// - // Configure Connection address - /////////////////////////////// - - if (has_connection_server) - { - // Add remote SERVER to CLIENT's list of SERVERs - pqos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(connection_locator); - } - - - /////////////////////////////// - // Create Participant - /////////////////////////////// - - // CREATE THE PARTICIPANT - participant_ = DomainParticipantFactory::get_instance()->create_participant(0, pqos, &listener_); - - if (participant_ == nullptr) - { - return false; - } - - - if (has_connection_server) - { - std::cout << - "Server Participant " << pqos.name() << - " created with GUID " << participant_->guid() << - " listening in address <" << listening_locator << "> " << - " connecting with Discovery Server <" << connection_locator << "> " << - std::endl; - } - else - { - std::cout << - "Server Participant " << pqos.name() << - " created with GUID " << participant_->guid() << - " listening in address <" << listening_locator << "> " << - std::endl; - } - - return true; -} - -DiscoveryServer::~DiscoveryServer() -{ - if (participant_ != nullptr) - { - DomainParticipantFactory::get_instance()->delete_participant(participant_); - } -} - -void DiscoveryServer::ServerListener::on_participant_discovery( - eprosima::fastdds::dds::DomainParticipant* /*participant*/, - eprosima::fastdds::rtps::ParticipantDiscoveryInfo&& info, - bool& should_be_ignored) -{ - static_cast(should_be_ignored); - if (info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT) - { - std::cout << "Discovered Participant with GUID " << info.info.m_guid << std::endl; - } - else if (info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT || - info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT) - { - std::cout << "Dropped Participant with GUID " << info.info.m_guid << std::endl; - } -} - -void DiscoveryServer::run( - unsigned int timeout) -{ - stop_ = false; - std::cout << "Server running. Please press CTRL+C to stop the Server." << std::endl; - signal(SIGINT, [](int signum) - { - std::cout << "SIGINT received, stopping Server execution." << std::endl; - static_cast(signum); DiscoveryServer::stop(); - }); - - if (timeout > 0) - { - // Create a thread that will stop this process after timeout - std::thread t( - [=] - () - { - std::this_thread::sleep_for(std::chrono::seconds(timeout)); - std::cout << "Stopping Server execution due to timeout." << std::endl; - DiscoveryServer::stop(); - }); - t.detach(); - } - - std::unique_lock lck(terminate_cv_mtx_); - terminate_cv_.wait(lck, [] - { - return is_stopped(); - }); -} diff --git a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.h b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.h deleted file mode 100644 index 0520eb2dc00..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerServer.h +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2021 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 DiscoveryServerServer.h - * - */ - -#ifndef _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSERVER_H_ -#define _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSERVER_H_ - -#include -#include -#include - -#include -#include - -#include "common.h" - -/** - * Class with a partipant configured to function as server in the Discovery Server mechanism - */ -class DiscoveryServer -{ -public: - - DiscoveryServer(); - - virtual ~DiscoveryServer(); - - //! Initialize the server - bool init( - const std::string& server_address, - unsigned short server_port, - TransportKind transport, - bool has_connection_server, - const std::string& connection_server_address, - unsigned short connection_server_port); - - //! Run - void run( - unsigned int timeout); - - //! Return the current state of execution - static bool is_stopped(); - - //! Trigger the end of execution - static void stop(); - -private: - - eprosima::fastdds::dds::DomainParticipant* participant_; - - /** - * Class handling discovery events - */ - class ServerListener : public eprosima::fastdds::dds::DomainParticipantListener - { - public: - - ServerListener() - { - } - - ~ServerListener() override - { - } - - //! Callback executed when a DomainParticipant is discovered, dropped or removed - void on_participant_discovery( - eprosima::fastdds::dds::DomainParticipant* /*participant*/, - eprosima::fastdds::rtps::ParticipantDiscoveryInfo&& info, - bool& should_be_ignored) override; - - private: - - using eprosima::fastdds::dds::DomainParticipantListener::on_participant_discovery; - } - listener_; - - //! Member used for control flow purposes - static std::atomic stop_; - - //! Protects terminate condition variable - static std::mutex terminate_cv_mtx_; - - //! Waits during execution until SIGINT or max_messages_ samples are received - static std::condition_variable terminate_cv_; -}; - - - -#endif /* _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSERVER_H_ */ diff --git a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerSubscriber.cpp b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerSubscriber.cpp deleted file mode 100644 index 8cfb7f3d194..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerSubscriber.cpp +++ /dev/null @@ -1,331 +0,0 @@ -// Copyright 2021 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 DiscoveryServerSubscriber.cpp - * - */ - -#include "DiscoveryServerSubscriber.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace eprosima::fastdds::dds; -using namespace eprosima::fastdds::rtps; - -std::atomic HelloWorldSubscriber::stop_(false); -std::mutex HelloWorldSubscriber::terminate_cv_mtx_; -std::condition_variable HelloWorldSubscriber::terminate_cv_; - -HelloWorldSubscriber::HelloWorldSubscriber() - : participant_(nullptr) - , subscriber_(nullptr) - , topic_(nullptr) - , reader_(nullptr) - , type_(new HelloWorldPubSubType()) -{ -} - -bool HelloWorldSubscriber::is_stopped() -{ - return stop_; -} - -void HelloWorldSubscriber::stop() -{ - stop_ = true; - terminate_cv_.notify_all(); -} - -bool HelloWorldSubscriber::init( - const std::string& topic_name, - uint32_t max_messages, - const std::string& server_address, - unsigned short server_port, - TransportKind transport) -{ - DomainParticipantQos pqos; - pqos.name("DS-Client_sub"); - pqos.transport().use_builtin_transports = false; - - std::string ip_server_address(server_address); - // Check if DNS is required - if (!is_ip(server_address)) - { - ip_server_address = get_ip_from_dns(server_address, transport); - } - - if (ip_server_address.empty()) - { - return false; - } - - // Create DS SERVER locator - eprosima::fastdds::rtps::Locator server_locator; - eprosima::fastdds::rtps::IPLocator::setPhysicalPort(server_locator, server_port); - - std::shared_ptr descriptor; - - switch (transport) - { - case TransportKind::SHM: - descriptor = std::make_shared(); - server_locator.kind = LOCATOR_KIND_SHM; - break; - - case TransportKind::UDPv4: - { - auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); - descriptor = descriptor_tmp; - - server_locator.kind = LOCATOR_KIND_UDPv4; - eprosima::fastdds::rtps::IPLocator::setIPv4(server_locator, ip_server_address); - break; - } - - case TransportKind::UDPv6: - { - auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); - descriptor = descriptor_tmp; - - server_locator.kind = LOCATOR_KIND_UDPv6; - eprosima::fastdds::rtps::IPLocator::setIPv6(server_locator, ip_server_address); - break; - } - - case TransportKind::TCPv4: - { - auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); - // One listening port must be added either in the pub or the sub - descriptor_tmp->add_listener_port(0); - descriptor = descriptor_tmp; - - server_locator.kind = LOCATOR_KIND_TCPv4; - eprosima::fastdds::rtps::IPLocator::setLogicalPort(server_locator, server_port); - eprosima::fastdds::rtps::IPLocator::setIPv4(server_locator, ip_server_address); - break; - } - - case TransportKind::TCPv6: - { - auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); - // One listening port must be added either in the pub or the sub - descriptor_tmp->add_listener_port(0); - descriptor = descriptor_tmp; - - server_locator.kind = LOCATOR_KIND_TCPv6; - eprosima::fastdds::rtps::IPLocator::setLogicalPort(server_locator, server_port); - if (eprosima::fastdds::rtps::IPLocator::isIPv6(ip_server_address)) - { - eprosima::fastdds::rtps::IPLocator::setIPv6(server_locator, ip_server_address); - } - else - { - eprosima::fastdds::rtps::IPLocator::setIPv6(server_locator, "::1"); - } - break; - } - - default: - break; - } - - // Set participant as DS CLIENT - pqos.wire_protocol().builtin.discovery_config.discoveryProtocol = - eprosima::fastdds::rtps::DiscoveryProtocol::CLIENT; - - // Add remote SERVER to CLIENT's list of SERVERs - pqos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(server_locator); - - // Add descriptor - pqos.transport().user_transports.push_back(descriptor); - - // CREATE THE PARTICIPANT - participant_ = DomainParticipantFactory::get_instance()->create_participant(0, pqos, &listener_, - StatusMask::all() >> StatusMask::data_on_readers()); - - if (participant_ == nullptr) - { - return false; - } - - std::cout << - "Subscriber Participant " << pqos.name() << - " created with GUID " << participant_->guid() << - " connecting to server <" << server_locator << "> " << - std::endl; - - // REGISTER THE TYPE - type_.register_type(participant_); - - // CREATE THE SUBSCRIBER - subscriber_ = participant_->create_subscriber(SUBSCRIBER_QOS_DEFAULT, nullptr); - - if (subscriber_ == nullptr) - { - return false; - } - - // CREATE THE TOPIC - topic_ = participant_->create_topic( - topic_name, - "HelloWorld", - TOPIC_QOS_DEFAULT); - - if (topic_ == nullptr) - { - return false; - } - - // CREATE THE READER - if (max_messages > 0) - { - listener_.set_max_messages(max_messages); - } - DataReaderQos rqos = DATAREADER_QOS_DEFAULT; - reader_ = subscriber_->create_datareader(topic_, rqos, &listener_); - - if (reader_ == nullptr) - { - return false; - } - - return true; -} - -HelloWorldSubscriber::~HelloWorldSubscriber() -{ - if (participant_ != nullptr) - { - if (topic_ != nullptr) - { - participant_->delete_topic(topic_); - } - if (subscriber_ != nullptr) - { - if (reader_ != nullptr) - { - subscriber_->delete_datareader(reader_); - } - participant_->delete_subscriber(subscriber_); - } - DomainParticipantFactory::get_instance()->delete_participant(participant_); - } -} - -void HelloWorldSubscriber::SubListener::set_max_messages( - uint32_t max_messages) -{ - max_messages_ = max_messages; -} - -void HelloWorldSubscriber::SubListener::on_subscription_matched( - DataReader*, - const SubscriptionMatchedStatus& info) -{ - if (info.current_count_change == 1) - { - matched_ = info.current_count; - std::cout << "Subscriber matched." << std::endl; - } - else if (info.current_count_change == -1) - { - matched_ = info.current_count; - 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 HelloWorldSubscriber::SubListener::on_data_available( - DataReader* reader) -{ - SampleInfo info; - while ((reader->take_next_sample(&hello_, &info) == RETCODE_OK) && !is_stopped()) - { - if (info.instance_state == ALIVE_INSTANCE_STATE) - { - samples_++; - // Print your structure data here. - std::cout << "Message " << hello_.message() << " " << hello_.index() << " RECEIVED" << std::endl; - if (max_messages_ > 0 && (samples_ >= max_messages_)) - { - stop(); - } - } - } -} - -void HelloWorldSubscriber::SubListener::on_participant_discovery( - eprosima::fastdds::dds::DomainParticipant* /*participant*/, - eprosima::fastdds::rtps::ParticipantDiscoveryInfo&& info, - bool& should_be_ignored) -{ - static_cast(should_be_ignored); - if (info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT) - { - std::cout << "Discovered Participant with GUID " << info.info.m_guid << std::endl; - } - else if (info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT || - info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT) - { - std::cout << "Dropped Participant with GUID " << info.info.m_guid << std::endl; - } -} - -void HelloWorldSubscriber::run( - uint32_t samples) -{ - stop_ = false; - if (samples > 0) - { - std::cout << "Subscriber running until " << samples << - " samples have been received. Please press CTRL+C to stop the Subscriber at any time." << std::endl; - } - else - { - std::cout << "Subscriber running. Please press CTRL+C to stop the Subscriber." << std::endl; - } - signal(SIGINT, [](int signum) - { - std::cout << "SIGINT received, stopping Subscriber execution." << std::endl; - static_cast(signum); HelloWorldSubscriber::stop(); - }); - std::unique_lock lck(terminate_cv_mtx_); - terminate_cv_.wait(lck, [] - { - return is_stopped(); - }); -} diff --git a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerSubscriber.h b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerSubscriber.h deleted file mode 100644 index cc81aad5f6a..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServerSubscriber.h +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2021 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 DiscoveryServerSubscriber.h - * - */ - -#ifndef _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSUBSCRIBER_H_ -#define _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSUBSCRIBER_H_ - -#include -#include -#include - -#include -#include -#include - -#include "types/HelloWorldPubSubTypes.hpp" -#include "common.h" - -/** - * Class used to group into a single working unit a Subscriber with a DataReader, its listener, and a TypeSupport member - * corresponding to the HelloWorld datatype - */ -class HelloWorldSubscriber -{ -public: - - HelloWorldSubscriber(); - - virtual ~HelloWorldSubscriber(); - - //! Initialize the subscriber - bool init( - const std::string& topic_name, - uint32_t max_messages, - const std::string& server_address, - unsigned short server_port, - TransportKind transport); - - //! RUN the subscriber until number samples are received - void run( - uint32_t number); - - //! Return the current state of execution - static bool is_stopped(); - - //! Trigger the end of execution - static void stop(); - -private: - - eprosima::fastdds::dds::DomainParticipant* participant_; - - eprosima::fastdds::dds::Subscriber* subscriber_; - - eprosima::fastdds::dds::Topic* topic_; - - eprosima::fastdds::dds::DataReader* reader_; - - eprosima::fastdds::dds::TypeSupport type_; - - /** - * Class handling discovery and dataflow events - */ - class SubListener : public eprosima::fastdds::dds::DomainParticipantListener - { - public: - - SubListener() - : matched_(0) - , samples_(0) - , max_messages_(0) - { - } - - ~SubListener() override - { - } - - //! Set the maximum number of messages to receive before exiting - void set_max_messages( - uint32_t max_messages); - - //! Callback executed when a new sample is received - void on_data_available( - eprosima::fastdds::dds::DataReader* reader) override; - - //! Callback executed when a DataWriter is matched or unmatched - void on_subscription_matched( - eprosima::fastdds::dds::DataReader* reader, - const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) override; - - //! Callback executed when a DomainParticipant is discovered, dropped or removed - void on_participant_discovery( - eprosima::fastdds::dds::DomainParticipant* /*participant*/, - eprosima::fastdds::rtps::ParticipantDiscoveryInfo&& info, - bool& should_be_ignored) override; - - private: - - using eprosima::fastdds::dds::DomainParticipantListener::on_participant_discovery; - - HelloWorld hello_; - - //! Number of DataWriters matched to the associated DataReader - int matched_; - - //! Number of samples received - uint32_t samples_; - - //! Number of messages to be received before triggering termination of execution - uint32_t max_messages_; - } - listener_; - - //! Member used for control flow purposes - static std::atomic stop_; - - //! Protects terminate condition variable - static std::mutex terminate_cv_mtx_; - - //! Waits during execution until SIGINT or max_messages_ samples are received - static std::condition_variable terminate_cv_; -}; - -#endif /* _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_DISCOVERYSERVERSUBSCRIBER_H_ */ diff --git a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServer_main.cpp b/examples/cpp/dds/DiscoveryServerExample/DiscoveryServer_main.cpp deleted file mode 100644 index e71d6b04fe0..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/DiscoveryServer_main.cpp +++ /dev/null @@ -1,331 +0,0 @@ -// Copyright 2021 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 DiscoveryServer_main.cpp - * - */ - -#include - -#include "arg_configuration.h" -#include "DiscoveryServerPublisher.h" -#include "DiscoveryServerServer.h" -#include "DiscoveryServerSubscriber.h" - -enum class EntityKind -{ - PUBLISHER, - SUBSCRIBER, - SERVER, -}; - -int main( - int argc, - char** argv) -{ - int columns; - -#if defined(_WIN32) - char* buf = nullptr; - size_t sz = 0; - if (_dupenv_s(&buf, &sz, "COLUMNS") == 0 && buf != nullptr) - { - columns = strtol(buf, nullptr, 10); - free(buf); - } - else - { - columns = 80; - } -#else - columns = getenv("COLUMNS") ? atoi(getenv("COLUMNS")) : 80; -#endif // if defined(_WIN32) - - EntityKind type = EntityKind::PUBLISHER; - std::string topic_name = "HelloWorldTopic"; - int count = 0; - long sleep = 100; - - // Transport - TransportKind transport = TransportKind::UDPv4; - - // Discovery Server connection - std::string connection_address = "127.0.0.1"; // default ip address - uint16_t connection_port = 16166; // default physical port - bool id_ds_set = false; - - // Discovery Server listening - std::string listening_address = "127.0.0.1"; // default ip address - uint16_t listening_port = 16166; // default physical port - uint32_t timeout = 0; // default DS id - - if (argc > 1) - { - if (!strcmp(argv[1], "publisher")) - { - type = EntityKind::PUBLISHER; - } - else if (!strcmp(argv[1], "subscriber")) - { - type = EntityKind::SUBSCRIBER; - } - else if (!strcmp(argv[1], "server")) - { - type = EntityKind::SERVER; - } - // check if first argument is help, needed because we skip it when parsing - else if (!(strcmp(argv[1], "-h") && strcmp(argv[1], "--help"))) - { - option::printUsage(fwrite, stdout, usage, columns); - return 0; - } - else - { - std::cerr << "ERROR: first argument can only be " << std::endl; - option::printUsage(fwrite, stdout, usage, columns); - return 1; - } - - argc -= (argc > 0); - argv += (argc > 0); // skip program name argv[0] if present - --argc; ++argv; // skip pub/sub argument - option::Stats stats(usage, argc, argv); - std::vector options(stats.options_max); - std::vector buffer(stats.buffer_max); - option::Parser parse(usage, argc, argv, &options[0], &buffer[0]); - - if (parse.error()) - { - option::printUsage(fwrite, stdout, usage, columns); - return 1; - } - - if (options[HELP]) - { - option::printUsage(fwrite, stdout, usage, columns); - return 0; - } - - for (int i = 0; i < parse.optionsCount(); ++i) - { - option::Option& opt = buffer[i]; - switch (opt.index()) - { - case optionIndex::HELP: - // not possible, because handled further above and exits the program - break; - - case optionIndex::TOPIC: - if (type == EntityKind::SERVER) - { - print_warning("publisher|subscriber", opt.name); - } - else - { - topic_name = std::string(opt.arg); - } - break; - - case optionIndex::SAMPLES: - if (type == EntityKind::SERVER) - { - print_warning("publisher|subscriber", opt.name); - } - else - { - count = strtol(opt.arg, nullptr, 10); - } - break; - - case optionIndex::INTERVAL: - if (type == EntityKind::PUBLISHER) - { - sleep = strtol(opt.arg, nullptr, 10); - } - else - { - print_warning("publisher", opt.name); - } - break; - - case optionIndex::TRANSPORT: - { - std::string transport_str(opt.arg); - if (transport_str == "udpv4") - { - transport = TransportKind::UDPv4; - } - else if (transport_str == "udpv6") - { - transport = TransportKind::UDPv6; - } - else if (transport_str == "tcpv4") - { - transport = TransportKind::TCPv4; - } - else if (transport_str == "tcpv6") - { - transport = TransportKind::TCPv6; - } - else - { - print_warning("udpv4|udpv6|tcpv4|tcpv6", opt.name); - } - - break; - } - - case optionIndex::CONNECTION_PORT: - id_ds_set = true; - connection_port = static_cast(strtol(opt.arg, nullptr, 10)); - break; - - case optionIndex::CONNECTION_ADDRESS: - id_ds_set = true; - connection_address = opt.arg; - break; - - case optionIndex::LISTENING_PORT: - if (type != EntityKind::SERVER) - { - print_warning("server", opt.name); - break; - } - listening_port = static_cast(strtol(opt.arg, nullptr, 10)); - break; - - case optionIndex::LISTENING_ADDRESS: - if (type != EntityKind::SERVER) - { - print_warning("server", opt.name); - break; - } - listening_address = opt.arg; - - break; - - case optionIndex::TIMEOUT: - if (type != EntityKind::SERVER) - { - print_warning("server", opt.name); - break; - } - timeout = strtol(opt.arg, nullptr, 10); - break; - - case optionIndex::UNKNOWN_OPT: - std::cerr << "ERROR: " << opt.name << " is not a valid argument." << std::endl; - option::printUsage(fwrite, stdout, usage, columns); - return 1; - break; - } - } - } - else - { - std::cerr << "ERROR: argument is required." << std::endl; - option::printUsage(fwrite, stdout, usage, columns); - return 1; - } - - // Check that ip matches transport - // if (transport == TransportKind::UDPv4 && !eprosima::fastdds::rtps::IPLocator::isIPv4(listening_address)) - // { - // std::cerr << "ERROR: IPv4 is needed to use UDPv4. Wrong IP address: " << listening_address << std::endl; - // option::printUsage(fwrite, stdout, usage, columns); - // return 1; - // } - // else if (transport == TransportKind::UDPv6 && !eprosima::fastdds::rtps::IPLocator::isIPv6(listening_address)) - // { - // std::cerr << "ERROR: IPv6 is needed to use UDPv6. Wrong IP address: " << listening_address << std::endl; - // option::printUsage(fwrite, stdout, usage, columns); - // return 1; - // } - - // Check that a DS has not same ip and port in listening and connection - if (id_ds_set && - type == EntityKind::SERVER && - listening_address == connection_address && - listening_port == connection_port) - { - std::cerr << "ERROR: Discovery Servers ports must be different, " - << " cannot connect to a server with same listening address " - << listening_address << "(" << listening_port << ")" << std::endl; - option::printUsage(fwrite, stdout, usage, columns); - return 1; - } - - switch (type) - { - case EntityKind::PUBLISHER: - { - HelloWorldPublisher mypub; - if (mypub.init( - topic_name, - connection_address, - connection_port, - transport)) - { - mypub.run(static_cast(count), static_cast(sleep)); - } - else - { - std::cerr << "ERROR: when initializing Publisher." << std::endl; - return 1; - } - break; - } - case EntityKind::SUBSCRIBER: - { - HelloWorldSubscriber mysub; - if (mysub.init( - topic_name, - static_cast(count), - connection_address, - connection_port, - transport)) - { - mysub.run(static_cast(count)); - } - else - { - std::cerr << "ERROR: when initializing Subscriber." << std::endl; - return 1; - } - break; - } - case EntityKind::SERVER: - { - DiscoveryServer myserver; - if (myserver.init( - listening_address, - listening_port, - transport, - id_ds_set, - connection_address, - connection_port)) - { - myserver.run(timeout); - } - else - { - std::cerr << "ERROR: when initializing Server." << std::endl; - return 1; - } - break; - } - } - return 0; -} diff --git a/examples/cpp/dds/DiscoveryServerExample/README.md b/examples/cpp/dds/DiscoveryServerExample/README.md deleted file mode 100644 index ef236617f4e..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/README.md +++ /dev/null @@ -1,65 +0,0 @@ -# Discovery Server Example - -This example demonstrates how communication between a publisher and subscriber can be established through the Discovery -Server mechanism. - -## Execution instructions - -To launch this test open three different consoles: - -In the first one launch: ./DiscoveryServerExample publisher (or DiscoveryServerExample.exe publisher on windows). -In the second one: ./DiscoveryServerExample subscriber (or DiscoveryServerExample.exe subscriber on windows). -In the third one: ./DiscoveryServerExample server (or DiscoveryServerExample.exe server on windows). - -## Arguments - -First argument is `publisher`, `subscriber` or `server` and then the rest of arguments are read unordered - -```sh -Usage: DiscoveryServerExample - -General options: - -h --help - Produce help message. - -Publisher options: - -t --topic= - Topic name (Default: HelloWorldTopic). - -s --samples= - Number of samples to send (Default: 0 => infinite samples). - -i --interval= - Time between samples in milliseconds (Default: 100). - -c --connection-address= - Server address (Default address: 127.0.0.1). - -p --connection-port= - Server listening port (Default port: 16166). - --transport= - Use Transport Protocol [udpv4|udpv6|tcpv4|tcpv6] (Default: udpv4). - -Subscriber options: - -t --topic= - Topic name (Default: HelloWorldTopic). - -s --samples= - Number of samples to wait for (Default: 0 => infinite - samples). - -c --connection-address= - Server address (Default address: 127.0.0.1). - -p --connection-port= - Server listening port (Default port: 16166). - --transport= - Use Transport Protocol [udpv4|udpv6|tcpv4|tcpv6] (Default: udpv4). - -DiscoveryServer options: - --listening-address= - Server address (Default address: 127.0.0.1). - --listening-port= - Server listening port (Default port: 16166). - --transport= - Use Transport Protocol [udpv4|udpv6|tcpv4|tcpv6] (Default: udpv4). - -c --connection-address= - Server address (Default address: 127.0.0.1). - -p --connection-port= - Server listening port (Default port: 16166). - -z --timeout - Number of seconds before finish the process (Default: 0 = till ^C). -``` diff --git a/examples/cpp/dds/DiscoveryServerExample/arg_configuration.h b/examples/cpp/dds/DiscoveryServerExample/arg_configuration.h deleted file mode 100644 index d7a888df0af..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/arg_configuration.h +++ /dev/null @@ -1,345 +0,0 @@ -// Copyright 2021 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 arg_configuration.h - * - */ - -#ifndef _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_ARG_CONFIGURATION_H_ -#define _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_ARG_CONFIGURATION_H_ - -#include -#include -#include - -#include -#include - -#include "common.h" - -namespace option = eprosima::option; - -const std::regex IPv4_REGEX(R"(^((?:[0-9]{1,3}\.){3}[0-9]{1,3})?:?(?:(\d+))?$)"); - -struct Arg : public option::Arg -{ - static void print_error( - const char* msg1, - const option::Option& opt, - const char* msg2) - { - fprintf(stderr, "%s", msg1); - fwrite(opt.name, opt.namelen, 1, stderr); - fprintf(stderr, "%s", msg2); - } - - static option::ArgStatus Unknown( - const option::Option& option, - bool msg) - { - if (msg) - { - print_error("Unknown option '", option, "'\n"); - } - return option::ARG_ILLEGAL; - } - - static option::ArgStatus Required( - const option::Option& option, - bool msg) - { - if (option.arg != 0 && option.arg[0] != 0) - { - return option::ARG_OK; - } - - if (msg) - { - print_error("Option '", option, "' requires an argument\n"); - } - return option::ARG_ILLEGAL; - } - - static option::ArgStatus Numeric( - const option::Option& option, - bool msg) - { - char* endptr = 0; - if (option.arg != 0 && strtol(option.arg, &endptr, 10)) - { - } - if (endptr != option.arg && *endptr == 0) - { - return option::ARG_OK; - } - - if (msg) - { - print_error("Option '", option, "' requires a numeric argument\n"); - } - return option::ARG_ILLEGAL; - } - - static option::ArgStatus String( - const option::Option& option, - bool msg) - { - if (option.arg != 0) - { - return option::ARG_OK; - } - if (msg) - { - print_error("Option '", option, "' requires a string argument\n"); - } - return option::ARG_ILLEGAL; - } - - static option::ArgStatus Locator( - const option::Option& option, - bool msg) - { - if (option.arg != 0) - { - // we must check if it is a correct ip address plus port number - std::string ip_str(option.arg); - if ( - eprosima::fastdds::rtps::IPLocator::isIPv4(ip_str) || - eprosima::fastdds::rtps::IPLocator::isIPv6(ip_str)) - { - return option::ARG_OK; - } - } - if (msg) - { - print_error("Option '", option, "' requires an v4 or v6 argument\n"); - } - return option::ARG_ILLEGAL; - } - - static option::ArgStatus Transport( - const option::Option& option, - bool msg) - { - if (option.arg != 0) - { - // we must check if it is a correct ip address plus port number - std::string transport = std::string(option.arg); - if ( - // transport == "shm" || - transport == "udpv4" || - transport == "udpv6" || - transport == "tcpv4" || - transport == "tcpv6" - ) - { - return option::ARG_OK; - } - } - if (msg) - { - print_error("Option '", option, "' requires a string argument\n"); - } - return option::ARG_ILLEGAL; - } - -}; - -enum optionIndex -{ - UNKNOWN_OPT, - HELP, - - TOPIC, - SAMPLES, - INTERVAL, - TRANSPORT, - - CONNECTION_ADDRESS, - CONNECTION_PORT, - - LISTENING_ADDRESS, - LISTENING_PORT, - TIMEOUT, -}; - -const option::Descriptor usage[] = { - {UNKNOWN_OPT, 0, "", "", Arg::None, - "Usage: DiscoveryServerExample \n\nGeneral options:" }, - { - HELP, - 0, - "h", - "help", - Arg::None, - " -h \t--help \tProduce help message." - }, - - /// PUBLISHER OPTIONS - {UNKNOWN_OPT, 0, "", "", Arg::None, "\nPublisher options:"}, - { - TOPIC, - 0, - "t", - "topic", - Arg::String, - " -t \t--topic= \tTopic name (Default: HelloWorldTopic)." - }, - { - SAMPLES, - 0, - "s", - "samples", - Arg::Numeric, - " -s \t--samples= \tNumber of samples to send (Default: 0 => infinite samples)." - }, - { - INTERVAL, - 0, - "i", - "interval", - Arg::Numeric, - " -i \t--interval= \tTime between samples in milliseconds (Default: 100)." - }, - { - CONNECTION_ADDRESS, - 0, - "c", - "connection-address", - Arg::String, - " -c \t--connection-address= \tServer address (Default address: 127.0.0.1)." - }, - { - CONNECTION_PORT, - 0, - "p", - "connection-port", - Arg::Numeric, - " -p \t--connection-port= \tServer listening port (Default port: 16166)." - }, - { - TRANSPORT, - 0, - "", - "transport", - Arg::Transport, - " \t--transport \tUse Transport Protocol [udpv4|udpv6|tcpv4|tcpv6] (UDPv4 by default)." - }, - - /// SUBSCRIBER OPTIONS - {UNKNOWN_OPT, 0, "", "", Arg::None, "\nSubscriber options:"}, - { - TOPIC, - 0, - "t", - "topic", - Arg::String, - " -t \t--topic= \tTopic name (Default: HelloWorldTopic)." - }, - { - SAMPLES, - 0, - "s", - "samples", - Arg::Numeric, - " -s \t--samples= \tNumber of samples to send (Default: 0 => infinite samples)." - }, - { - CONNECTION_ADDRESS, - 0, - "c", - "connection-address", - Arg::String, - " -c \t--connection-address= \tServer address (Default address: 127.0.0.1)." - }, - { - CONNECTION_PORT, - 0, - "p", - "connection-port", - Arg::Numeric, - " -p \t--connection-port= \tServer listening port (Default port: 16166)." - }, - { - TRANSPORT, - 0, - "", - "transport", - Arg::Transport, - " \t--transport \tUse Transport Protocol [udpv4|udpv6|tcpv4|tcpv6] (UDPv4 by default)." - }, - - /// SERVER OPTIONS - {UNKNOWN_OPT, 0, "", "", Arg::None, "\nDiscovery Server options:"}, - { - LISTENING_ADDRESS, - 0, - "", - "listening-address", - Arg::String, - " \t--listening-address= \tServer address (Default address: 127.0.0.1)." - }, - { - LISTENING_PORT, - 0, - "", - "listening-port", - Arg::Numeric, - " \t--listening-port= \tServer listening port (Default port: 16166)." - }, - { - TRANSPORT, - 0, - "", - "transport", - Arg::Transport, - " \t--transport \tUse Transport Protocol [udpv4|udpv6|tcpv4|tcpv6] (UDPv4 by default)." - }, - { - CONNECTION_PORT, - 0, - "p", - "connection-port", - Arg::Numeric, - " -p \t--connection-port= \tServer listening port (Default port: 16166)." - }, - { - CONNECTION_ADDRESS, - 0, - "c", - "connection-address", - Arg::String, - " -c \t--connection-address= \tServer address (Default address: 127.0.0.1)." - }, - { - TIMEOUT, - 0, - "z", - "timeout", - Arg::Numeric, - " -z \t--timeout \tNumber of seconds before finish the process (Default: 0 = till ^C). " - }, - - { 0, 0, 0, 0, 0, 0 } -}; - -void print_warning( - std::string type, - const char* opt) -{ - std::cerr << "WARNING: " << opt << " is a " << type << " option, ignoring argument." << std::endl; -} - -#endif /* _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_ARG_CONFIGURATION_H_ */ diff --git a/examples/cpp/dds/DiscoveryServerExample/common.h b/examples/cpp/dds/DiscoveryServerExample/common.h deleted file mode 100644 index 2012555902d..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/common.h +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2021 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 common.h - * - */ - -#ifndef _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_COMMON_H_ -#define _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_COMMON_H_ - -#include -#include - -enum class TransportKind -{ - UDPv4, - UDPv6, - TCPv4, - TCPv6, - SHM, -}; - -inline bool is_ip( - const std::string ip_str) -{ - return eprosima::fastdds::rtps::IPLocator::isIPv4(ip_str) || eprosima::fastdds::rtps::IPLocator::isIPv6(ip_str); -} - -inline std::string get_ip_from_dns( - const std::string& domain_name, - TransportKind kind) -{ - std::pair, std::set> dns_response = - eprosima::fastdds::rtps::IPLocator::resolveNameDNS(domain_name); - - if (kind == TransportKind::UDPv4 || kind == TransportKind::TCPv4) - { - if (dns_response.first.empty()) - { - std::cout << "Not DNS found for IPv4 for " << domain_name << std::endl; - return ""; - } - else - { - std::string solution(*dns_response.first.begin()); - std::cout << "DNS found for " << domain_name << " => " << solution << std::endl; - return solution; - } - } - else if (kind == TransportKind::UDPv6 || kind == TransportKind::TCPv6) - { - if (dns_response.second.empty()) - { - std::cout << "Not DNS found for IPv6 for " << domain_name << std::endl; - return ""; - } - else - { - std::string solution(*dns_response.second.begin()); - std::cout << "DNS found for " << domain_name << " => " << solution << std::endl; - return solution; - } - } - - return domain_name; -} - -#endif /* _EPROSIMA_FASTDDS_EXAMPLES_CPP_DDS_DISCOVERYSERVEREXAMPLE_COMMON_H_ */ diff --git a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorld.hpp b/examples/cpp/dds/DiscoveryServerExample/types/HelloWorld.hpp deleted file mode 100644 index 46d0d7b5814..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorld.hpp +++ /dev/null @@ -1,227 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/*! - * @file HelloWorld.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__HELLOWORLD_HPP -#define FAST_DDS_GENERATED__HELLOWORLD_HPP - -#include -#include -#include -#include - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#if defined(HELLOWORLD_SOURCE) -#define HELLOWORLD_DllAPI __declspec( dllexport ) -#else -#define HELLOWORLD_DllAPI __declspec( dllimport ) -#endif // HELLOWORLD_SOURCE -#else -#define HELLOWORLD_DllAPI -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define HELLOWORLD_DllAPI -#endif // _WIN32 - -/*! - * @brief This class represents the structure HelloWorld defined by the user in the IDL file. - * @ingroup HelloWorld - */ -class HelloWorld -{ -public: - - /*! - * @brief Default constructor. - */ - eProsima_user_DllExport HelloWorld() - { - } - - /*! - * @brief Default destructor. - */ - eProsima_user_DllExport ~HelloWorld() - { - } - - /*! - * @brief Copy constructor. - * @param x Reference to the object HelloWorld that will be copied. - */ - eProsima_user_DllExport HelloWorld( - const HelloWorld& x) - { - m_index = x.m_index; - - m_message = x.m_message; - - } - - /*! - * @brief Move constructor. - * @param x Reference to the object HelloWorld that will be copied. - */ - eProsima_user_DllExport HelloWorld( - HelloWorld&& x) noexcept - { - m_index = x.m_index; - m_message = std::move(x.m_message); - } - - /*! - * @brief Copy assignment. - * @param x Reference to the object HelloWorld that will be copied. - */ - eProsima_user_DllExport HelloWorld& operator =( - const HelloWorld& x) - { - - m_index = x.m_index; - - m_message = x.m_message; - - return *this; - } - - /*! - * @brief Move assignment. - * @param x Reference to the object HelloWorld that will be copied. - */ - eProsima_user_DllExport HelloWorld& operator =( - HelloWorld&& x) noexcept - { - - m_index = x.m_index; - m_message = std::move(x.m_message); - return *this; - } - - /*! - * @brief Comparison operator. - * @param x HelloWorld object to compare. - */ - eProsima_user_DllExport bool operator ==( - const HelloWorld& x) const - { - return (m_index == x.m_index && - m_message == x.m_message); - } - - /*! - * @brief Comparison operator. - * @param x HelloWorld object to compare. - */ - eProsima_user_DllExport bool operator !=( - const HelloWorld& 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; - } - - - /*! - * @brief This function copies the value in member message - * @param _message New value to be copied in member message - */ - eProsima_user_DllExport void message( - const std::string& _message) - { - m_message = _message; - } - - /*! - * @brief This function moves the value in member message - * @param _message New value to be moved in member message - */ - eProsima_user_DllExport void message( - std::string&& _message) - { - m_message = std::move(_message); - } - - /*! - * @brief This function returns a constant reference to member message - * @return Constant reference to member message - */ - eProsima_user_DllExport const std::string& message() const - { - return m_message; - } - - /*! - * @brief This function returns a reference to member message - * @return Reference to member message - */ - eProsima_user_DllExport std::string& message() - { - return m_message; - } - - - -private: - - uint32_t m_index{0}; - std::string m_message; - -}; - -#endif // _FAST_DDS_GENERATED_HELLOWORLD_HPP_ - - diff --git a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorld.idl b/examples/cpp/dds/DiscoveryServerExample/types/HelloWorld.idl deleted file mode 100644 index 0fd2c355aee..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorld.idl +++ /dev/null @@ -1,5 +0,0 @@ -struct HelloWorld -{ - unsigned long index; - string message; -}; diff --git a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldCdrAux.hpp b/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldCdrAux.hpp deleted file mode 100644 index 1164cd5cce1..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldCdrAux.hpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/*! - * @file HelloWorldCdrAux.hpp - * This source file contains some definitions of CDR related functions. - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef FAST_DDS_GENERATED__HELLOWORLDCDRAUX_HPP -#define FAST_DDS_GENERATED__HELLOWORLDCDRAUX_HPP - -#include "HelloWorld.hpp" - -constexpr uint32_t HelloWorld_max_cdr_typesize {268UL}; -constexpr uint32_t HelloWorld_max_key_cdr_typesize {0UL}; - - -namespace eprosima { -namespace fastcdr { - -class Cdr; -class CdrSizeCalculator; - -eProsima_user_DllExport void serialize_key( - eprosima::fastcdr::Cdr& scdr, - const HelloWorld& data); - - -} // namespace fastcdr -} // namespace eprosima - -#endif // FAST_DDS_GENERATED__HELLOWORLDCDRAUX_HPP - diff --git a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldCdrAux.ipp b/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldCdrAux.ipp deleted file mode 100644 index 19316df7d3c..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldCdrAux.ipp +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/*! - * @file HelloWorldCdrAux.ipp - * This source file contains some declarations of CDR related functions. - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef FAST_DDS_GENERATED__HELLOWORLDCDRAUX_IPP -#define FAST_DDS_GENERATED__HELLOWORLDCDRAUX_IPP - -#include "HelloWorldCdrAux.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 HelloWorld& 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.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), - data.message(), 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 HelloWorld& 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() - << eprosima::fastcdr::MemberId(1) << data.message() -; - scdr.end_serialize_type(current_state); -} - -template<> -eProsima_user_DllExport void deserialize( - eprosima::fastcdr::Cdr& cdr, - HelloWorld& 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; - - case 1: - dcdr >> data.message(); - break; - - default: - ret_value = false; - break; - } - return ret_value; - }); -} - -void serialize_key( - eprosima::fastcdr::Cdr& scdr, - const HelloWorld& data) -{ - static_cast(scdr); - static_cast(data); -} - - - -} // namespace fastcdr -} // namespace eprosima - -#endif // FAST_DDS_GENERATED__HELLOWORLDCDRAUX_IPP - diff --git a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldPubSubTypes.cxx b/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldPubSubTypes.cxx deleted file mode 100644 index 38393dbf8c9..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldPubSubTypes.cxx +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/*! - * @file HelloWorldPubSubTypes.cpp - * This header file contains the implementation of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - -#include "HelloWorldPubSubTypes.hpp" - -#include -#include - -#include "HelloWorldCdrAux.hpp" -#include "HelloWorldTypeObjectSupport.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; - -HelloWorldPubSubType::HelloWorldPubSubType() -{ - setName("HelloWorld"); - uint32_t type_size = -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(HelloWorld::getMaxCdrSerializedSize()); -#else - HelloWorld_max_cdr_typesize; -#endif - type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ - m_typeSize = type_size + 4; /*encapsulation*/ - m_isGetKeyDefined = false; - uint32_t keyLength = HelloWorld_max_key_cdr_typesize > 16 ? HelloWorld_max_key_cdr_typesize : 16; - m_keyBuffer = reinterpret_cast(malloc(keyLength)); - memset(m_keyBuffer, 0, keyLength); -} - -HelloWorldPubSubType::~HelloWorldPubSubType() -{ - if (m_keyBuffer != nullptr) - { - free(m_keyBuffer); - } -} - -bool HelloWorldPubSubType::serialize( - const void* const data, - SerializedPayload_t* payload, - DataRepresentationId_t data_representation) -{ - const HelloWorld* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); - payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; -#if FASTCDR_VERSION_MAJOR > 1 - ser.set_encoding_flag( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : - eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); -#endif // FASTCDR_VERSION_MAJOR > 1 - - try - { - // Serialize encapsulation - ser.serialize_encapsulation(); - // Serialize the object. - ser << *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - // Get the serialized length -#if FASTCDR_VERSION_MAJOR == 1 - payload->length = static_cast(ser.getSerializedDataLength()); -#else - payload->length = static_cast(ser.get_serialized_data_length()); -#endif // FASTCDR_VERSION_MAJOR == 1 - return true; -} - -bool HelloWorldPubSubType::deserialize( - SerializedPayload_t* payload, - void* data) -{ - try - { - // Convert DATA to pointer of your type - HelloWorld* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); - - // Object that deserializes the data. - eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN -#if FASTCDR_VERSION_MAJOR == 1 - , eprosima::fastcdr::Cdr::CdrType::DDS_CDR -#endif // FASTCDR_VERSION_MAJOR == 1 - ); - - // Deserialize encapsulation. - deser.read_encapsulation(); - payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; - - // Deserialize the object. - deser >> *p_type; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return false; - } - - return true; -} - -std::function HelloWorldPubSubType::getSerializedSizeProvider( - const void* const data, - DataRepresentationId_t data_representation) -{ - return [data, data_representation]() -> uint32_t - { -#if FASTCDR_VERSION_MAJOR == 1 - static_cast(data_representation); - return static_cast(type::getCdrSerializedSize(*static_cast(data))) + - 4u /*encapsulation*/; -#else - try - { - eprosima::fastcdr::CdrSizeCalculator calculator( - data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? - eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); - size_t current_alignment {0}; - return static_cast(calculator.calculate_serialized_size( - *static_cast(data), current_alignment)) + - 4u /*encapsulation*/; - } - catch (eprosima::fastcdr::exception::Exception& /*exception*/) - { - return 0; - } -#endif // FASTCDR_VERSION_MAJOR == 1 - }; -} - -void* HelloWorldPubSubType::createData() -{ - return reinterpret_cast(new HelloWorld()); -} - -void HelloWorldPubSubType::deleteData( - void* data) -{ - delete(reinterpret_cast(data)); -} - -bool HelloWorldPubSubType::getKey( - const void* const data, - InstanceHandle_t* handle, - bool force_md5) -{ - if (!m_isGetKeyDefined) - { - return false; - } - - const HelloWorld* p_type = static_cast(data); - - // Object that manages the raw buffer. - eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), - HelloWorld_max_key_cdr_typesize); - - // Object that serializes the data. - eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); -#if FASTCDR_VERSION_MAJOR == 1 - p_type->serializeKey(ser); -#else - eprosima::fastcdr::serialize_key(ser, *p_type); -#endif // FASTCDR_VERSION_MAJOR == 1 - if (force_md5 || HelloWorld_max_key_cdr_typesize > 16) - { - m_md5.init(); -#if FASTCDR_VERSION_MAJOR == 1 - m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); -#else - m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); -#endif // FASTCDR_VERSION_MAJOR == 1 - m_md5.finalize(); - for (uint8_t i = 0; i < 16; ++i) - { - handle->value[i] = m_md5.digest[i]; - } - } - else - { - for (uint8_t i = 0; i < 16; ++i) - { - handle->value[i] = m_keyBuffer[i]; - } - } - return true; -} - -void HelloWorldPubSubType::register_type_object_representation() -{ - register_HelloWorld_type_identifier(type_identifiers_); -} - - -// Include auxiliary functions like for serializing/deserializing. -#include "HelloWorldCdrAux.ipp" diff --git a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldPubSubTypes.hpp b/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldPubSubTypes.hpp deleted file mode 100644 index 556d4c05ecf..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldPubSubTypes.hpp +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/*! - * @file HelloWorldPubSubTypes.hpp - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef FAST_DDS_GENERATED__HELLOWORLD_PUBSUBTYPES_HPP -#define FAST_DDS_GENERATED__HELLOWORLD_PUBSUBTYPES_HPP - -#include -#include -#include -#include -#include - -#include "HelloWorld.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated HelloWorld is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type HelloWorld defined by the user in the IDL file. - * @ingroup HelloWorld - */ -class HelloWorldPubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef HelloWorld type; - - eProsima_user_DllExport HelloWorldPubSubType(); - - eProsima_user_DllExport ~HelloWorldPubSubType() override; - - eProsima_user_DllExport bool serialize( - const void* const data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - 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 std::function getSerializedSizeProvider( - const void* const data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - const void* const data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - const void* const data, - eprosima::fastdds::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - eprosima::fastdds::MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // FAST_DDS_GENERATED__HELLOWORLD_PUBSUBTYPES_HPP - diff --git a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldTypeObjectSupport.cxx b/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldTypeObjectSupport.cxx deleted file mode 100644 index 58928b6f057..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldTypeObjectSupport.cxx +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/*! - * @file HelloWorldTypeObjectSupport.cxx - * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#include "HelloWorldTypeObjectSupport.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "HelloWorld.hpp" - - -using namespace eprosima::fastdds::dds::xtypes; - -// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method -void register_HelloWorld_type_identifier( - TypeIdentifierPair& type_ids_HelloWorld) -{ - - ReturnCode_t return_code_HelloWorld {eprosima::fastdds::dds::RETCODE_OK}; - return_code_HelloWorld = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "HelloWorld", type_ids_HelloWorld); - if (eprosima::fastdds::dds::RETCODE_OK != return_code_HelloWorld) - { - StructTypeFlag struct_flags_HelloWorld = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, - false, false); - QualifiedTypeName type_name_HelloWorld = "HelloWorld"; - eprosima::fastcdr::optional type_ann_builtin_HelloWorld; - eprosima::fastcdr::optional ann_custom_HelloWorld; - CompleteTypeDetail detail_HelloWorld = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_HelloWorld, ann_custom_HelloWorld, type_name_HelloWorld.to_string()); - CompleteStructHeader header_HelloWorld; - header_HelloWorld = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_HelloWorld); - CompleteStructMemberSeq member_seq_HelloWorld; - { - TypeIdentifierPair type_ids_index; - ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; - return_code_index = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "_uint32_t", type_ids_index); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); - return; - } - StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::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_HelloWorld.reset(); - CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_HelloWorld); - CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); - TypeObjectUtils::add_complete_struct_member(member_seq_HelloWorld, member_index); - } - { - TypeIdentifierPair type_ids_message; - ReturnCode_t return_code_message {eprosima::fastdds::dds::RETCODE_OK}; - return_code_message = - eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( - "anonymous_string_unbounded", type_ids_message); - - if (eprosima::fastdds::dds::RETCODE_OK != return_code_message) - { - { - SBound bound = 0; - StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, - "anonymous_string_unbounded", type_ids_message)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); - } - } - } - StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, - false, false, false, false); - MemberId member_id_message = 0x00000001; - bool common_message_ec {false}; - CommonStructMember common_message {TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, common_message_ec))}; - if (!common_message_ec) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure message member TypeIdentifier inconsistent."); - return; - } - MemberName name_message = "message"; - eprosima::fastcdr::optional member_ann_builtin_message; - ann_custom_HelloWorld.reset(); - CompleteMemberDetail detail_message = TypeObjectUtils::build_complete_member_detail(name_message, member_ann_builtin_message, ann_custom_HelloWorld); - CompleteStructMember member_message = TypeObjectUtils::build_complete_struct_member(common_message, detail_message); - TypeObjectUtils::add_complete_struct_member(member_seq_HelloWorld, member_message); - } - CompleteStructType struct_type_HelloWorld = TypeObjectUtils::build_complete_struct_type(struct_flags_HelloWorld, header_HelloWorld, member_seq_HelloWorld); - if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == - TypeObjectUtils::build_and_register_struct_type_object(struct_type_HelloWorld, type_name_HelloWorld.to_string(), type_ids_HelloWorld)) - { - EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, - "HelloWorld already registered in TypeObjectRegistry for a different type."); - } - } -} - diff --git a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldTypeObjectSupport.hpp b/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldTypeObjectSupport.hpp deleted file mode 100644 index ec922163d11..00000000000 --- a/examples/cpp/dds/DiscoveryServerExample/types/HelloWorldTypeObjectSupport.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/*! - * @file HelloWorldTypeObjectSupport.hpp - * Header file containing the API required to register the TypeObject representation of the described types in the IDL file - * - * This file was generated by the tool fastddsgen. - */ - -#ifndef FAST_DDS_GENERATED__HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP -#define FAST_DDS_GENERATED__HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP - -#include - - -#if defined(_WIN32) -#if defined(EPROSIMA_USER_DLL_EXPORT) -#define eProsima_user_DllExport __declspec( dllexport ) -#else -#define eProsima_user_DllExport -#endif // EPROSIMA_USER_DLL_EXPORT -#else -#define eProsima_user_DllExport -#endif // _WIN32 - -#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -/** - * @brief Register HelloWorld related TypeIdentifier. - * Fully-descriptive TypeIdentifiers are directly registered. - * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is - * indirectly registered as well. - * - * @param[out] TypeIdentifier of the registered type. - * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. - * Invalid TypeIdentifier is returned in case of error. - */ -eProsima_user_DllExport void register_HelloWorld_type_identifier( - eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); - - -#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC - -#endif // FAST_DDS_GENERATED__HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP From beb785d2d19b1c708a2465dfb08f30edeb69fa84 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Fri, 7 Jun 2024 11:15:31 +0200 Subject: [PATCH 02/18] Refs #21095: Add new discovery_server example Signed-off-by: Mario Dominguez --- examples/CMakeLists.txt | 1 + examples/cpp/discovery_server/Application.cpp | 61 ++ examples/cpp/discovery_server/Application.hpp | 55 ++ examples/cpp/discovery_server/CLIParser.hpp | 714 ++++++++++++++++++ examples/cpp/discovery_server/CMakeLists.txt | 50 ++ .../discovery_server/ClientPublisherApp.cpp | 308 ++++++++ .../discovery_server/ClientPublisherApp.hpp | 98 +++ .../discovery_server/ClientSubscriberApp.cpp | 295 ++++++++ .../discovery_server/ClientSubscriberApp.hpp | 97 +++ examples/cpp/discovery_server/HelloWorld.hpp | 227 ++++++ examples/cpp/discovery_server/HelloWorld.idl | 6 + .../cpp/discovery_server/HelloWorldCdrAux.hpp | 46 ++ .../cpp/discovery_server/HelloWorldCdrAux.ipp | 126 ++++ .../HelloWorldPubSubTypes.cxx | 229 ++++++ .../discovery_server/HelloWorldPubSubTypes.h | 133 ++++ .../HelloWorldTypeObjectSupport.cxx | 145 ++++ .../HelloWorldTypeObjectSupport.hpp | 56 ++ examples/cpp/discovery_server/Helpers.hpp | 94 +++ examples/cpp/discovery_server/README.md | 115 +++ examples/cpp/discovery_server/ServerApp.cpp | 286 +++++++ examples/cpp/discovery_server/ServerApp.hpp | 86 +++ examples/cpp/discovery_server/main.cpp | 110 +++ 22 files changed, 3338 insertions(+) create mode 100644 examples/cpp/discovery_server/Application.cpp create mode 100644 examples/cpp/discovery_server/Application.hpp create mode 100644 examples/cpp/discovery_server/CLIParser.hpp create mode 100644 examples/cpp/discovery_server/CMakeLists.txt create mode 100644 examples/cpp/discovery_server/ClientPublisherApp.cpp create mode 100644 examples/cpp/discovery_server/ClientPublisherApp.hpp create mode 100644 examples/cpp/discovery_server/ClientSubscriberApp.cpp create mode 100644 examples/cpp/discovery_server/ClientSubscriberApp.hpp create mode 100644 examples/cpp/discovery_server/HelloWorld.hpp create mode 100644 examples/cpp/discovery_server/HelloWorld.idl create mode 100644 examples/cpp/discovery_server/HelloWorldCdrAux.hpp create mode 100644 examples/cpp/discovery_server/HelloWorldCdrAux.ipp create mode 100644 examples/cpp/discovery_server/HelloWorldPubSubTypes.cxx create mode 100644 examples/cpp/discovery_server/HelloWorldPubSubTypes.h create mode 100644 examples/cpp/discovery_server/HelloWorldTypeObjectSupport.cxx create mode 100644 examples/cpp/discovery_server/HelloWorldTypeObjectSupport.hpp create mode 100644 examples/cpp/discovery_server/Helpers.hpp create mode 100644 examples/cpp/discovery_server/README.md create mode 100644 examples/cpp/discovery_server/ServerApp.cpp create mode 100644 examples/cpp/discovery_server/ServerApp.hpp create mode 100644 examples/cpp/discovery_server/main.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 03b1517abf4..07eb00f15be 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -19,6 +19,7 @@ add_subdirectory(cpp/content_filter) add_subdirectory(cpp/custom_payload_pool) add_subdirectory(cpp/dds) add_subdirectory(cpp/delivery_mechanisms) +add_subdirectory(cpp/discovery_server) add_subdirectory(cpp/hello_world) add_subdirectory(cpp/rtps) add_subdirectory(cpp/xtypes) diff --git a/examples/cpp/discovery_server/Application.cpp b/examples/cpp/discovery_server/Application.cpp new file mode 100644 index 00000000000..00fb74a6863 --- /dev/null +++ b/examples/cpp/discovery_server/Application.cpp @@ -0,0 +1,61 @@ +// 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 "ClientPublisherApp.hpp" +#include "ClientSubscriberApp.hpp" +#include "CLIParser.hpp" +#include "ServerApp.hpp" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace discovery_server { + +//! Factory method to create a publisher or subscriber +std::shared_ptr Application::make_app( + const CLIParser::ds_example_config& config) +{ + std::shared_ptr entity; + switch (config.entity) + { + case CLIParser::EntityKind::CLIENT_PUBLISHER: + entity = std::make_shared(config.pub_config); + break; + case CLIParser::EntityKind::CLIENT_SUBSCRIBER: + entity = std::make_shared(config.sub_config); + break; + case CLIParser::EntityKind::SERVER: + entity = std::make_shared(config.srv_config); + break; + case CLIParser::EntityKind::UNDEFINED: + default: + throw std::runtime_error("Entity initialization failed"); + break; + } + return entity; +} + +} // namespace discovery_server +} // namespace examples +} // namespace fastdds +} // namespace eprosima diff --git a/examples/cpp/discovery_server/Application.hpp b/examples/cpp/discovery_server/Application.hpp new file mode 100644 index 00000000000..94470a1d794 --- /dev/null +++ b/examples/cpp/discovery_server/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_DISCOVERY_SERVER_APPLICATION_HPP_ +#define _FASTDDS_DISCOVERY_SERVER_APPLICATION_HPP_ + +#include + +#include "CLIParser.hpp" + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace discovery_server { + +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::ds_example_config& config); +}; + +} // namespace discovery_server +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif /* _FASTDDS_DISCOVERY_SERVER_APPLICATION_HPP_ */ diff --git a/examples/cpp/discovery_server/CLIParser.hpp b/examples/cpp/discovery_server/CLIParser.hpp new file mode 100644 index 00000000000..e8b938fe236 --- /dev/null +++ b/examples/cpp/discovery_server/CLIParser.hpp @@ -0,0 +1,714 @@ +// 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 CLIParser.hpp + * + */ + +#include +#include +#include + +#include + +#include "Helpers.hpp" + +#ifndef _FASTDDS_DISCOVERY_SERVER_CLI_PARSER_HPP_ +#define _FASTDDS_DISCOVERY_SERVER_CLI_PARSER_HPP_ + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace discovery_server { + +using dds::Log; + +class CLIParser +{ +public: + + CLIParser() = delete; + + //! Entity kind enumeration + enum class EntityKind : uint8_t + { + CLIENT_PUBLISHER, + CLIENT_SUBSCRIBER, + SERVER, + UNDEFINED + }; + + //! Common configuration for all the entities + struct common_config + { + TransportKind transport_kind{TransportKind::UDPv4}; + }; + + //! Clients common configuration + struct client_config + { + uint16_t connection_port{16166}; + uint16_t connection_ds_id{0}; + std::string connection_address{"127.0.0.1"}; + }; + + //! Configuration options for both publisher and subscriber clients + struct pubsub_config : public client_config + { + bool reliable{false}; + bool transient_local{false}; + uint16_t samples{0}; + std::string topic_name{"discovery_server_topic"}; + }; + + //! Publisher client configuration structure + struct client_publisher_config : public common_config, + public pubsub_config + { + uint16_t interval{100}; + }; + + //! Subscriber client configuration structure + struct client_subscriber_config : public common_config, + public pubsub_config + { + }; + + //! Server configuration structure + //! A server can, in turn, act as a client + struct server_config : public common_config, + public client_config + { + bool is_also_client{false}; + uint16_t listening_port{16166}; + uint16_t id{0}; + uint16_t timeout{0}; + std::string listening_address{"127.0.0.1"}; + }; + + //! Configuration structure for the example + struct ds_example_config + { + CLIParser::EntityKind entity = CLIParser::EntityKind::UNDEFINED; + client_publisher_config pub_config; + client_subscriber_config sub_config; + server_config srv_config; + + friend std::ostream& operator<< ( + std::ostream& os, + const ds_example_config& config) + { + os << "Entity: " << parse_entity_kind(config.entity) << std::endl; + os << "Common options:" << std::endl; + os << " Transport: " << static_cast(config.pub_config.transport_kind) << std::endl; + + if (config.entity != CLIParser::EntityKind::SERVER || + (config.entity == CLIParser::EntityKind::SERVER && config.srv_config.is_also_client)) + { + os << "Client options:" << std::endl; + os << " Connection address: " << config.pub_config.connection_address << std::endl; + os << " Connection port: " << config.pub_config.connection_port << std::endl; + os << " Connection DS id: " << config.pub_config.connection_ds_id << std::endl; + } + + if (config.entity == CLIParser::EntityKind::CLIENT_PUBLISHER) + { + os << "Publisher options:" << std::endl; + os << " Topic name: " << config.pub_config.topic_name << std::endl; + os << " Samples: " << config.pub_config.samples << std::endl; + os << " Interval: " << config.pub_config.interval << std::endl; + } + else if (config.entity == CLIParser::EntityKind::CLIENT_SUBSCRIBER) + { + os << "Subscriber options:" << std::endl; + os << " Topic name: " << config.sub_config.topic_name << std::endl; + os << " Samples: " << config.sub_config.samples << std::endl; + } + else if (config.entity == CLIParser::EntityKind::SERVER) + { + os << "Server options:" << std::endl; + os << " Listening address: " << config.srv_config.listening_address << std::endl; + os << " Listening port: " << config.srv_config.listening_port << std::endl; + os << " Id: " << config.srv_config.id << std::endl; + os << " Timeout: " << config.srv_config.timeout << std::endl; + } + + return os; + } + }; + + /** + * @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: discovery_server [options]" << std::endl; + std::cout << "" << std::endl; + std::cout << "Entities:" << std::endl; + std::cout << " publisher Run a client publisher entity." << std::endl; + std::cout << " subscriber Run a client subscriber entity." << std::endl; + std::cout << " server Run a server 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 << " -c , --connection-address Server address" << std::endl; + std::cout << " (Default address: 127.0.0.1)." << std::endl; + std::cout << " -p , --connection-port Server listening port" << std::endl; + std::cout << " (Default port: 16166)." << std::endl; + std::cout << " -d --connection-ds-id Id of the Discovery Server to connect to" << std::endl; + std::cout << " (0 by default)." << std::endl; + std::cout << " --transport [udpv4|udpv6|tcpv4|tcpv6|shm] " << std::endl; + std::cout << " (udpv4 by default)." << std::endl; + std::cout << "" << std::endl; + std::cout << "Publisher options:" << std::endl; + std::cout << " -t , --topic Topic name" << std::endl; + std::cout << " (Default: discovery_server_topic)." << std::endl; + std::cout << " -r, --reliable Set Reliability QoS as reliable" << std::endl; + std::cout << " (Default: reliable)" << std::endl; + std::cout << " --transient-local Set Durability QoS as transient local" << std::endl; + std::cout << " (Default: volatile)" << std::endl; + std::cout << " -s , --samples Number of samples to send " << std::endl; + std::cout << " (Default: 0 => infinite samples)." << std::endl; + std::cout << " -i , --interval Time between samples in milliseconds" << std::endl; + std::cout << " (Default: 100)." << std::endl; + std::cout << "" << std::endl; + std::cout << "Subscriber options:" << std::endl; + std::cout << " -t , --topic Topic name" << std::endl; + std::cout << " -s , --samples Number of samples to receive" << std::endl; + std::cout << " (Default: 0 => infinite samples)." << 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 << "" << std::endl; + std::cout << "Server options:" << std::endl; + std::cout << " --listening-address Server listening address" << std::endl; + std::cout << " (Default address: 127.0.0.1)" << std::endl; + std::cout << " --listening-port Server listening port" << std::endl; + std::cout << " (Default port: 16166)" << std::endl; + std::cout << " --id Id of the Discovery Server (Default: 0)." << std::endl; + std::cout << " --timeout Number of seconds before finish" << std::endl; + std::cout << " --id the process (Default: 0 = till ^C)." << std::endl; + std::exit(return_code); + } + + /** + * @brief Parse the command line options and return the configuration_config object + * + * @param argc number of arguments + * @param argv array of arguments + * @return configuration_config object with the parsed options + * + * @warning This method finishes the execution of the program if the input arguments are invalid + */ + static ds_example_config parse_cli_options( + int argc, + char* argv[]) + { + ds_example_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::CLIENT_PUBLISHER; + } + else if (first_argument == "subscriber") + { + config.entity = CLIParser::EntityKind::CLIENT_SUBSCRIBER; + } + else if (first_argument == "server") + { + config.entity = CLIParser::EntityKind::SERVER; + } + else if (first_argument == "-h" || first_argument == "--help") + { + print_help(EXIT_SUCCESS); + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing entity argument " + first_argument); + print_help(EXIT_FAILURE); + } + + for (int i = 2; i < argc; ++i) + { + std::string arg = argv[i]; + + if (arg == "-h" || arg == "--help") + { + print_help(EXIT_SUCCESS); + } + // Common options + else if (arg == "--transport") + { + if (++i < argc) + { + std::string input = argv[i]; + + if (input == "udpv4") + { + config.pub_config.transport_kind = TransportKind::UDPv4; + config.sub_config.transport_kind = TransportKind::UDPv4; + config.srv_config.transport_kind = TransportKind::UDPv4; + } + else if (input == "udpv6") + { + config.pub_config.transport_kind = TransportKind::UDPv6; + config.sub_config.transport_kind = TransportKind::UDPv6; + config.srv_config.transport_kind = TransportKind::UDPv6; + } + else if (input == "tcpv4") + { + config.pub_config.transport_kind = TransportKind::TCPv4; + config.sub_config.transport_kind = TransportKind::TCPv4; + config.srv_config.transport_kind = TransportKind::TCPv4; + } + else if (input == "tcpv6") + { + config.pub_config.transport_kind = TransportKind::TCPv6; + config.sub_config.transport_kind = TransportKind::TCPv6; + config.srv_config.transport_kind = TransportKind::TCPv6; + } + else if (input == "shm") + { + config.pub_config.transport_kind = TransportKind::SHM; + config.sub_config.transport_kind = TransportKind::SHM; + config.srv_config.transport_kind = TransportKind::SHM; + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "Unkown transport argument: " + input); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing transport argument"); + print_help(EXIT_FAILURE); + } + } + // Client options + else if (arg == "-c" || arg == "--connection-address") + { + if (++i < argc) + { + config.pub_config.connection_address = argv[i]; + config.sub_config.connection_address = argv[i]; + config.srv_config.connection_address = argv[i]; + if (config.entity == CLIParser::EntityKind::SERVER) + { + config.srv_config.is_also_client = true; + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing connection-address argument"); + print_help(EXIT_FAILURE); + } + } + else if (arg == "-p" || arg == "--connection-port") + { + if (++i < argc) + { + try + { + int input = std::stoi(argv[i]); + if (input < std::numeric_limits::min() || + input > std::numeric_limits::max()) + { + throw std::out_of_range("port argument " + std::string( + argv[i]) + " out of range [0, 65535]."); + } + else + { + config.pub_config.connection_port = static_cast(input); + config.sub_config.connection_port = static_cast(input); + config.srv_config.connection_port = static_cast(input); + if (config.entity == CLIParser::EntityKind::SERVER) + { + config.srv_config.is_also_client = true; + } + } + } + catch (const std::invalid_argument& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid port 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 port argument"); + print_help(EXIT_FAILURE); + } + } + else if (arg == "-d" || arg == "--connection-ds-id") + { + if (++i < argc) + { + try + { + int input = std::stoi(argv[i]); + if (input < 0 || input > 255) + { + throw std::out_of_range("connection-ds-id argument " + std::string( + argv[i]) + " out of range [0, 255]."); + } + else + { + config.pub_config.connection_ds_id = static_cast(input); + config.sub_config.connection_ds_id = static_cast(input); + config.srv_config.connection_ds_id = static_cast(input); + if (config.entity == CLIParser::EntityKind::SERVER) + { + config.srv_config.is_also_client = true; + } + } + } + catch (const std::invalid_argument& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid connection-ds-id 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 connection-ds-id argument"); + print_help(EXIT_FAILURE); + } + } + // PubSub options + else if (arg == "-t" || arg == "--topic-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 topic name 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("samples argument out of range"); + } + else + { + if (config.entity == CLIParser::EntityKind::CLIENT_PUBLISHER || + config.entity == CLIParser::EntityKind::CLIENT_SUBSCRIBER) + { + config.pub_config.samples = static_cast(input); + config.sub_config.samples = static_cast(input); + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "entity error or not specified for --samples 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, "samples 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 == "--reliable") + { + config.pub_config.reliable = true; + config.sub_config.reliable = true; + } + else if (arg == "--transient-local") + { + config.pub_config.transient_local = true; + config.sub_config.transient_local = true; + } + // Publisher options + else if (arg == "-i" || arg == "--interval") + { + if (config.entity == CLIParser::EntityKind::CLIENT_PUBLISHER) + { + if (++i < argc) + { + try + { + int input = std::stoi(argv[i]); + if (input < std::numeric_limits::min() || + input > std::numeric_limits::max()) + { + throw std::out_of_range("interval argument out of range"); + } + 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 client publisher entity"); + print_help(EXIT_FAILURE); + } + } + // Server options + else if (arg == "--listening-address") + { + if (++i < argc) + { + config.srv_config.listening_address = argv[i]; + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing connection-address argument"); + print_help(EXIT_FAILURE); + } + } + else if (arg == "--listening-port") + { + if (++i < argc) + { + try + { + int input = std::stoi(argv[i]); + if (input < std::numeric_limits::min() || + input > std::numeric_limits::max()) + { + throw std::out_of_range("listening-port argument " + std::string( + argv[i]) + " out of range [0, 65535]."); + } + else + { + config.srv_config.listening_port = static_cast(input); + } + } + catch (const std::invalid_argument& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid listening-port 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 port argument"); + print_help(EXIT_FAILURE); + } + } + else if (arg == "--id") + { + if (++i < argc) + { + try + { + int input = std::stoi(argv[i]); + if (input < 0 || input > 255) + { + throw std::out_of_range("id argument " + std::string( + argv[i]) + " out of range [0, 255]."); + } + else + { + config.srv_config.id = static_cast(input); + } + } + catch (const std::invalid_argument& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid id 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 id argument"); + print_help(EXIT_FAILURE); + } + } + else if (arg == "--timeout") + { + if (++i < argc) + { + try + { + int input = std::stoi(argv[i]); + if (input < std::numeric_limits::min() || + input > std::numeric_limits::max()) + { + throw std::out_of_range("timeout argument " + std::string( + argv[i]) + " out of range [0, 65535]."); + } + else + { + config.srv_config.timeout = static_cast(input); + } + } + catch (const std::invalid_argument& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid timeout 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 port argument"); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "unknown option " + arg); + print_help(EXIT_FAILURE); + } + } + + return config; + } + + /** + * @brief Parse the signal number into the signal name + * + * @param signum signal number + * @return std::string signal name + */ + static std::string parse_signal( + const int& signum) + { + switch (signum) + { + case SIGINT: + return "SIGINT"; + case SIGTERM: + return "SIGTERM"; +#ifndef _WIN32 + case SIGQUIT: + return "SIGQUIT"; + case SIGHUP: + return "SIGHUP"; +#endif // _WIN32 + default: + return "UNKNOWN SIGNAL"; + } + } + + /** + * @brief Parse the entity kind into std::string + * + * @param entity entity kind + * @return std::string entity kind + */ + static std::string parse_entity_kind( + const EntityKind& entity) + { + switch (entity) + { + case EntityKind::CLIENT_PUBLISHER: + return "Client Publisher"; + case EntityKind::CLIENT_SUBSCRIBER: + return "Client Subscriber"; + case EntityKind::SERVER: + return "Discovery Server"; + case EntityKind::UNDEFINED: + default: + return "Undefined entity"; + } + } + +}; + +} // namespace discovery_server +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif // _FASTDDS_DISCOVERY_SERVER_CLI_PARSER_HPP_ diff --git a/examples/cpp/discovery_server/CMakeLists.txt b/examples/cpp/discovery_server/CMakeLists.txt new file mode 100644 index 00000000000..44d985226ac --- /dev/null +++ b/examples/cpp/discovery_server/CMakeLists.txt @@ -0,0 +1,50 @@ +# 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_discovery_server_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() + +message(STATUS "Configuring discovery server example...") +file(GLOB DISCOVERY_SERVER_SOURCES_CXX "*.cxx") +file(GLOB DISCOVERY_SERVER_SOURCES_CPP "*.cpp") + +add_executable(discovery_server ${DISCOVERY_SERVER_SOURCES_CXX} ${DISCOVERY_SERVER_SOURCES_CPP}) +target_compile_definitions(discovery_server PRIVATE + $<$>,$>:__DEBUG> + $<$:__INTERNALDEBUG> # Internal debug activated. + $<$:SHM_TRANSPORT_BUILTIN> # Enable SHM as built-in transport +) +target_link_libraries(discovery_server fastdds fastcdr) +install(TARGETS discovery_server + RUNTIME DESTINATION ${DATA_INSTALL_DIR}/fastdds/examples/cpp/discovery_server/${BIN_INSTALL_DIR}) + diff --git a/examples/cpp/discovery_server/ClientPublisherApp.cpp b/examples/cpp/discovery_server/ClientPublisherApp.cpp new file mode 100644 index 00000000000..60a65494a94 --- /dev/null +++ b/examples/cpp/discovery_server/ClientPublisherApp.cpp @@ -0,0 +1,308 @@ +// 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 ClientPublisherApp.cpp + * + */ + +#include "ClientPublisherApp.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace discovery_server { + +ClientPublisherApp::ClientPublisherApp( + const CLIParser::client_publisher_config& config) + : participant_(nullptr) + , publisher_(nullptr) + , topic_(nullptr) + , writer_(nullptr) + , type_(new HelloWorldPubSubType()) + , matched_(0) + , samples_(config.samples) + , stop_(false) + , period_ms_(config.interval) +{ + // Set up the data type with initial values + hello_.index(0); + hello_.message("Hello world"); + + // Configure Participant QoS + DomainParticipantQos pqos; + + pqos.name("DS-Client_pub"); + pqos.transport().use_builtin_transports = false; + + uint16_t server_port = config.connection_port; + + std::string ip_server_address(config.connection_address); + + // Check if DNS is required + if (!is_ip(config.connection_address)) + { + ip_server_address = get_ip_from_dns(config.connection_address, config.transport_kind); + } + + if (ip_server_address.empty()) + { + throw std::runtime_error("Invalid connection address"); + } + + // Create DS locator + eprosima::fastdds::rtps::Locator server_locator; + eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(server_locator, server_port); + + std::shared_ptr descriptor; + + switch (config.transport_kind) + { + case TransportKind::SHM: + descriptor = std::make_shared(); + server_locator.kind = LOCATOR_KIND_SHM; + break; + + case TransportKind::UDPv4: + { + auto descriptor_tmp = std::make_shared(); + // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); + descriptor = descriptor_tmp; + + server_locator.kind = LOCATOR_KIND_UDPv4; + eprosima::fastrtps::rtps::IPLocator::setIPv4(server_locator, ip_server_address); + break; + } + + case TransportKind::UDPv6: + { + auto descriptor_tmp = std::make_shared(); + // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); + descriptor = descriptor_tmp; + + server_locator.kind = LOCATOR_KIND_UDPv6; + eprosima::fastrtps::rtps::IPLocator::setIPv6(server_locator, ip_server_address); + break; + } + + case TransportKind::TCPv4: + { + auto descriptor_tmp = std::make_shared(); + // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); + // One listening port must be added either in the pub or the sub + descriptor_tmp->add_listener_port(0); + descriptor = descriptor_tmp; + + server_locator.kind = LOCATOR_KIND_TCPv4; + eprosima::fastrtps::rtps::IPLocator::setLogicalPort(server_locator, server_port); + eprosima::fastrtps::rtps::IPLocator::setIPv4(server_locator, ip_server_address); + break; + } + + case TransportKind::TCPv6: + { + auto descriptor_tmp = std::make_shared(); + // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); + // One listening port must be added either in the pub or the sub + descriptor_tmp->add_listener_port(0); + descriptor = descriptor_tmp; + + server_locator.kind = LOCATOR_KIND_TCPv6; + eprosima::fastrtps::rtps::IPLocator::setLogicalPort(server_locator, server_port); + eprosima::fastrtps::rtps::IPLocator::setIPv6(server_locator, ip_server_address); + break; + } + + default: + break; + } + + // Set participant as DS CLIENT + pqos.wire_protocol().builtin.discovery_config.discoveryProtocol = + eprosima::fastrtps::rtps::DiscoveryProtocol_t::CLIENT; + + // Set SERVER's GUID prefix + rtps::RemoteServerAttributes remote_server_att; + remote_server_att.guidPrefix = get_discovery_server_guid_from_id(config.connection_ds_id); + + // Set SERVER's listening locator for PDP + remote_server_att.metatrafficUnicastLocatorList.push_back(server_locator); + + // Add remote SERVER to CLIENT's list of SERVERs + pqos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(remote_server_att); + + // Add descriptor + pqos.transport().user_transports.push_back(descriptor); + + // Create Domainparticipant + participant_ = DomainParticipantFactory::get_instance()->create_participant(0, pqos, nullptr); + + if (participant_ == nullptr) + { + throw std::runtime_error("Participant initialization failed"); + } + + std::cout << + "Publisher Participant " << pqos.name() << + " created with GUID " << participant_->guid() << + " connecting to server <" << server_locator << "> " << + " with Guid: <" << remote_server_att.guidPrefix << "> " << + std::endl; + + // Regsiter type + type_.register_type(participant_); + + // Create the publisher + publisher_ = participant_->create_publisher(PUBLISHER_QOS_DEFAULT, nullptr); + + if (publisher_ == nullptr) + { + throw std::runtime_error("Publisher initialization failed"); + } + + // Create the topic + topic_ = participant_->create_topic(config.topic_name, "HelloWorld", TOPIC_QOS_DEFAULT); + + if (topic_ == nullptr) + { + throw std::runtime_error("Topic initialization failed"); + } + + // Create de data writer + DataWriterQos wqos = DATAWRITER_QOS_DEFAULT; + + if (config.reliable) + { + wqos.reliability().kind = RELIABLE_RELIABILITY_QOS; + } + else + { + wqos.reliability().kind = BEST_EFFORT_RELIABILITY_QOS; + } + + if (config.transient_local) + { + wqos.durability().kind = TRANSIENT_LOCAL_DURABILITY_QOS; + } + + writer_ = publisher_->create_datawriter(topic_, wqos, this); + + if (writer_ == nullptr) + { + throw std::runtime_error("DataWriter initialization failed"); + } +} + +ClientPublisherApp::~ClientPublisherApp() +{ + if (nullptr != participant_) + { + // Delete DDS entities contained within the DomainParticipant + participant_->delete_contained_entities(); + + // Delete DomainParticipant + DomainParticipantFactory::get_instance()->delete_participant(participant_); + } +} + +void ClientPublisherApp::on_publication_matched( + DataWriter* /*writer*/, + const PublicationMatchedStatus& info) +{ + if (info.current_count_change == 1) + { + matched_ = static_cast(info.current_count); + std::cout << "Publisher matched." << std::endl; + cv_.notify_one(); + } + else if (info.current_count_change == -1) + { + matched_ = static_cast(info.current_count); + std::cout << "Publisher unmatched." << std::endl; + } + else + { + std::cout << info.current_count_change + << " is not a valid value for PublicationMatchedStatus current count change" << std::endl; + } +} + +void ClientPublisherApp::run() +{ + while (!is_stopped() && ((samples_ == 0) || (hello_.index() < samples_))) + { + if (publish()) + { + std::cout << "Message: '" << hello_.message() << "' with index: '" << hello_.index() + << "' SENT" << std::endl; + } + // Wait for period or stop event + std::unique_lock period_lock(mutex_); + cv_.wait_for(period_lock, std::chrono::milliseconds(period_ms_), [&]() + { + return is_stopped(); + }); + } +} + +bool ClientPublisherApp::publish() +{ + bool ret = false; + // Wait for the data endpoints discovery + std::unique_lock matched_lock(mutex_); + cv_.wait(matched_lock, [&]() + { + // at least one has been discovered + return ((matched_ > 0) || is_stopped()); + }); + + if (!is_stopped()) + { + hello_.index(hello_.index() + 1); + ret = writer_->write(&hello_); + } + return ret; +} + +bool ClientPublisherApp::is_stopped() +{ + return stop_.load(); +} + +void ClientPublisherApp::stop() +{ + stop_.store(true); + cv_.notify_one(); +} + +} // namespace discovery_server +} // namespace examples +} // namespace fastdds +} // namespace eprosima diff --git a/examples/cpp/discovery_server/ClientPublisherApp.hpp b/examples/cpp/discovery_server/ClientPublisherApp.hpp new file mode 100644 index 00000000000..ddb5d8a5a6f --- /dev/null +++ b/examples/cpp/discovery_server/ClientPublisherApp.hpp @@ -0,0 +1,98 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @file ClientPublisherApp.hpp + * + */ + +#ifndef _FASTDDS_DISCOVERY_SERVER_CLIENT_PUBLISHER_APP_HPP_ +#define _FASTDDS_DISCOVERY_SERVER_CLIENT_PUBLISHER_APP_HPP_ + +#include + +#include +#include +#include + +#include "Application.hpp" +#include "CLIParser.hpp" +#include "HelloWorldPubSubTypes.h" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace discovery_server { + +class ClientPublisherApp : public Application, public DataWriterListener +{ +public: + + ClientPublisherApp( + const CLIParser::client_publisher_config& config); + + ~ClientPublisherApp(); + + //! Publisher matched method + void on_publication_matched( + DataWriter* writer, + const PublicationMatchedStatus& info) override; + + //! Run publisher + void run() override; + + //! Stop publisher + void stop() override; + +private: + + //! Return the current state of execution + bool is_stopped(); + + //! Publish a sample + bool publish(); + + HelloWorld hello_; + + DomainParticipant* participant_; + + Publisher* publisher_; + + Topic* topic_; + + DataWriter* writer_; + + TypeSupport type_; + + int16_t matched_; + + uint16_t samples_; + + std::mutex mutex_; + + std::condition_variable cv_; + + std::atomic stop_; + + const uint16_t period_ms_{100}; // in ms +}; + +} // namespace discovery_server +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif /* _FASTDDS_DISCOVERY_SERVER_CLIENT_PUBLISHER_APP_HPP_ */ diff --git a/examples/cpp/discovery_server/ClientSubscriberApp.cpp b/examples/cpp/discovery_server/ClientSubscriberApp.cpp new file mode 100644 index 00000000000..334fc99b47a --- /dev/null +++ b/examples/cpp/discovery_server/ClientSubscriberApp.cpp @@ -0,0 +1,295 @@ +// 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 ClientSubscriberApp.cpp + * + */ + +#include "ClientSubscriberApp.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "CLIParser.hpp" +#include "HelloWorldPubSubTypes.h" +#include "Application.hpp" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace discovery_server { + +ClientSubscriberApp::ClientSubscriberApp( + const CLIParser::client_subscriber_config& config) + : participant_(nullptr) + , subscriber_(nullptr) + , topic_(nullptr) + , reader_(nullptr) + , type_(new HelloWorldPubSubType()) + , samples_(config.samples) + , received_samples_(0) + , stop_(false) +{ + DomainParticipantQos pqos; + pqos.name("DS-Client_sub"); + pqos.transport().use_builtin_transports = false; + + uint16_t server_port = config.connection_port; + + std::string ip_server_address(config.connection_address); + // Check if DNS is required + if (!is_ip(config.connection_address)) + { + ip_server_address = get_ip_from_dns(config.connection_address, config.transport_kind); + } + + if (ip_server_address.empty()) + { + throw std::runtime_error("Invalid connection address"); + } + + // Create DS SERVER locator + eprosima::fastdds::rtps::Locator server_locator; + eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(server_locator, server_port); + + std::shared_ptr descriptor; + + switch (config.transport_kind) + { + case TransportKind::SHM: + descriptor = std::make_shared(); + server_locator.kind = LOCATOR_KIND_SHM; + break; + + case TransportKind::UDPv4: + { + auto descriptor_tmp = std::make_shared(); + // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); + descriptor = descriptor_tmp; + + server_locator.kind = LOCATOR_KIND_UDPv4; + eprosima::fastrtps::rtps::IPLocator::setIPv4(server_locator, ip_server_address); + break; + } + + case TransportKind::UDPv6: + { + auto descriptor_tmp = std::make_shared(); + // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); + descriptor = descriptor_tmp; + + server_locator.kind = LOCATOR_KIND_UDPv6; + eprosima::fastrtps::rtps::IPLocator::setIPv6(server_locator, ip_server_address); + break; + } + + case TransportKind::TCPv4: + { + auto descriptor_tmp = std::make_shared(); + // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); + // One listening port must be added either in the pub or the sub + descriptor_tmp->add_listener_port(0); + descriptor = descriptor_tmp; + + server_locator.kind = LOCATOR_KIND_TCPv4; + eprosima::fastrtps::rtps::IPLocator::setLogicalPort(server_locator, server_port); + eprosima::fastrtps::rtps::IPLocator::setIPv4(server_locator, ip_server_address); + break; + } + + case TransportKind::TCPv6: + { + auto descriptor_tmp = std::make_shared(); + // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); + // One listening port must be added either in the pub or the sub + descriptor_tmp->add_listener_port(0); + descriptor = descriptor_tmp; + + server_locator.kind = LOCATOR_KIND_TCPv6; + eprosima::fastrtps::rtps::IPLocator::setLogicalPort(server_locator, server_port); + eprosima::fastrtps::rtps::IPLocator::setIPv4(server_locator, ip_server_address); + break; + } + + default: + break; + } + + // Set participant as DS CLIENT + pqos.wire_protocol().builtin.discovery_config.discoveryProtocol = + eprosima::fastrtps::rtps::DiscoveryProtocol_t::CLIENT; + + // Set SERVER's GUID prefix + rtps::RemoteServerAttributes remote_server_att; + remote_server_att.guidPrefix = get_discovery_server_guid_from_id(config.connection_ds_id); + + // Set SERVER's listening locator for PDP + remote_server_att.metatrafficUnicastLocatorList.push_back(server_locator); + + // Add remote SERVER to CLIENT's list of SERVERs + pqos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(remote_server_att); + + // Add descriptor + pqos.transport().user_transports.push_back(descriptor); + + // Create the Domainparticipant + participant_ = DomainParticipantFactory::get_instance()->create_participant(0, pqos, nullptr, + StatusMask::all() >> StatusMask::data_on_readers()); + + if (participant_ == nullptr) + { + throw std::runtime_error("Participant initialization failed"); + } + + std::cout << + "Subscriber Participant " << pqos.name() << + " created with GUID " << participant_->guid() << + " connecting to server <" << server_locator << "> " << + " with Guid: <" << remote_server_att.guidPrefix << "> " << + std::endl; + + // Register the type + type_.register_type(participant_); + + // Create the subscriber + subscriber_ = participant_->create_subscriber(SUBSCRIBER_QOS_DEFAULT, nullptr); + + if (subscriber_ == nullptr) + { + throw std::runtime_error("Subscriber initialization failed"); + } + + // Create the topic + topic_ = participant_->create_topic( + config.topic_name, + "HelloWorld", + TOPIC_QOS_DEFAULT); + + if (topic_ == nullptr) + { + throw std::runtime_error("Topic initialization failed"); + } + + // Create the data reader + DataReaderQos rqos = DATAREADER_QOS_DEFAULT; + + if (config.reliable) + { + rqos.reliability().kind = RELIABLE_RELIABILITY_QOS; + } + + if (config.transient_local) + { + rqos.durability().kind = TRANSIENT_LOCAL_DURABILITY_QOS; + } + + reader_ = subscriber_->create_datareader(topic_, rqos, this); + + if (reader_ == nullptr) + { + throw std::runtime_error("DataWriter initialization failed"); + } +} + +ClientSubscriberApp::~ClientSubscriberApp() +{ + if (nullptr != participant_) + { + // Delete DDS entities contained within the DomainParticipant + participant_->delete_contained_entities(); + + // Delete DomainParticipant + DomainParticipantFactory::get_instance()->delete_participant(participant_); + } +} + +void ClientSubscriberApp::on_subscription_matched( + DataReader* /*reader*/, + const SubscriptionMatchedStatus& info) +{ + if (info.current_count_change == 1) + { + std::cout << "Subscriber matched." << std::endl; + } + 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 ClientSubscriberApp::on_data_available( + DataReader* reader) +{ + SampleInfo info; + while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&hello_, &info))) + { + if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) + { + received_samples_++; + // Print Hello world message data + std::cout << "Message: '" << hello_.message() << "' with index: '" << hello_.index() + << "' RECEIVED" << std::endl; + if (samples_ > 0 && (received_samples_ >= samples_)) + { + stop(); + } + } + } +} + +void ClientSubscriberApp::run() +{ + std::unique_lock lck(terminate_cv_mtx_); + terminate_cv_.wait(lck, [&] + { + return is_stopped(); + }); +} + +bool ClientSubscriberApp::is_stopped() +{ + return stop_.load(); +} + +void ClientSubscriberApp::stop() +{ + stop_.store(true); + terminate_cv_.notify_all(); +} + +} // namespace discovery_server +} // namespace examples +} // namespace fastdds +} // namespace eprosima diff --git a/examples/cpp/discovery_server/ClientSubscriberApp.hpp b/examples/cpp/discovery_server/ClientSubscriberApp.hpp new file mode 100644 index 00000000000..d006f2ce2ae --- /dev/null +++ b/examples/cpp/discovery_server/ClientSubscriberApp.hpp @@ -0,0 +1,97 @@ +// 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 ClientSubscriberApp.hpp + * + */ + +#ifndef _FASTDDS_DISCOVERY_SERVER_CLIENT_SUBSCRIBER_APP_HPP_ +#define _FASTDDS_DISCOVERY_SERVER_CLIENT_SUBSCRIBER_APP_HPP_ + +#include + +#include +#include +#include + +#include "CLIParser.hpp" +#include "HelloWorldPubSubTypes.h" +#include "Application.hpp" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace discovery_server { + +class ClientSubscriberApp : public Application, public DataReaderListener +{ +public: + + ClientSubscriberApp( + const CLIParser::client_subscriber_config& config); + + ~ClientSubscriberApp(); + + //! Subscription callback + void on_data_available( + DataReader* reader) override; + + //! Subscriber matched method + void on_subscription_matched( + DataReader* reader, + const SubscriptionMatchedStatus& info) override; + + //! Run subscriber + void run() override; + + //! Trigger the end of execution + void stop() override; + +private: + + //! Return the current state of execution + bool is_stopped(); + + HelloWorld hello_; + + DomainParticipant* participant_; + + Subscriber* subscriber_; + + Topic* topic_; + + DataReader* reader_; + + TypeSupport type_; + + uint16_t samples_; + + uint16_t received_samples_; + + std::atomic stop_; + + mutable std::mutex terminate_cv_mtx_; + + std::condition_variable terminate_cv_; +}; + +} // namespace discovery_server +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif /* _FASTDDS_DISCOVERY_SERVER_CLIENT_SUBSCRIBER_APP_HPP_ */ diff --git a/examples/cpp/discovery_server/HelloWorld.hpp b/examples/cpp/discovery_server/HelloWorld.hpp new file mode 100644 index 00000000000..971fea8d920 --- /dev/null +++ b/examples/cpp/discovery_server/HelloWorld.hpp @@ -0,0 +1,227 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file HelloWorld.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_HELLOWORLD_HPP_ +#define _FAST_DDS_GENERATED_HELLOWORLD_HPP_ + +#include +#include +#include +#include + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#if defined(HELLOWORLD_SOURCE) +#define HELLOWORLD_DllAPI __declspec( dllexport ) +#else +#define HELLOWORLD_DllAPI __declspec( dllimport ) +#endif // HELLOWORLD_SOURCE +#else +#define HELLOWORLD_DllAPI +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define HELLOWORLD_DllAPI +#endif // _WIN32 + +/*! + * @brief This class represents the structure HelloWorld defined by the user in the IDL file. + * @ingroup HelloWorld + */ +class HelloWorld +{ +public: + + /*! + * @brief Default constructor. + */ + eProsima_user_DllExport HelloWorld() + { + } + + /*! + * @brief Default destructor. + */ + eProsima_user_DllExport ~HelloWorld() + { + } + + /*! + * @brief Copy constructor. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld( + const HelloWorld& x) + { + m_index = x.m_index; + + m_message = x.m_message; + + } + + /*! + * @brief Move constructor. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld( + HelloWorld&& x) noexcept + { + m_index = x.m_index; + m_message = std::move(x.m_message); + } + + /*! + * @brief Copy assignment. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld& operator =( + const HelloWorld& x) + { + + m_index = x.m_index; + + m_message = x.m_message; + + return *this; + } + + /*! + * @brief Move assignment. + * @param x Reference to the object HelloWorld that will be copied. + */ + eProsima_user_DllExport HelloWorld& operator =( + HelloWorld&& x) noexcept + { + + m_index = x.m_index; + m_message = std::move(x.m_message); + return *this; + } + + /*! + * @brief Comparison operator. + * @param x HelloWorld object to compare. + */ + eProsima_user_DllExport bool operator ==( + const HelloWorld& x) const + { + return (m_index == x.m_index && + m_message == x.m_message); + } + + /*! + * @brief Comparison operator. + * @param x HelloWorld object to compare. + */ + eProsima_user_DllExport bool operator !=( + const HelloWorld& 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; + } + + + /*! + * @brief This function copies the value in member message + * @param _message New value to be copied in member message + */ + eProsima_user_DllExport void message( + const std::string& _message) + { + m_message = _message; + } + + /*! + * @brief This function moves the value in member message + * @param _message New value to be moved in member message + */ + eProsima_user_DllExport void message( + std::string&& _message) + { + m_message = std::move(_message); + } + + /*! + * @brief This function returns a constant reference to member message + * @return Constant reference to member message + */ + eProsima_user_DllExport const std::string& message() const + { + return m_message; + } + + /*! + * @brief This function returns a reference to member message + * @return Reference to member message + */ + eProsima_user_DllExport std::string& message() + { + return m_message; + } + + + +private: + + uint32_t m_index{0}; + std::string m_message; + +}; + +#endif // _FAST_DDS_GENERATED_HELLOWORLD_HPP_ + + diff --git a/examples/cpp/discovery_server/HelloWorld.idl b/examples/cpp/discovery_server/HelloWorld.idl new file mode 100644 index 00000000000..192f8f9d487 --- /dev/null +++ b/examples/cpp/discovery_server/HelloWorld.idl @@ -0,0 +1,6 @@ +@extensibility(APPENDABLE) +struct HelloWorld +{ + unsigned long index; + string message; +}; diff --git a/examples/cpp/discovery_server/HelloWorldCdrAux.hpp b/examples/cpp/discovery_server/HelloWorldCdrAux.hpp new file mode 100644 index 00000000000..6feb8a9da15 --- /dev/null +++ b/examples/cpp/discovery_server/HelloWorldCdrAux.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 HelloWorldCdrAux.hpp + * This source file contains some definitions of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_HPP_ +#define _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_HPP_ + +#include "HelloWorld.hpp" + +constexpr uint32_t HelloWorld_max_cdr_typesize {268UL}; +constexpr uint32_t HelloWorld_max_key_cdr_typesize {0UL}; + + +namespace eprosima { +namespace fastcdr { + +class Cdr; +class CdrSizeCalculator; + +eProsima_user_DllExport void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const HelloWorld& data); + + +} // namespace fastcdr +} // namespace eprosima + +#endif // _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_HPP_ + diff --git a/examples/cpp/discovery_server/HelloWorldCdrAux.ipp b/examples/cpp/discovery_server/HelloWorldCdrAux.ipp new file mode 100644 index 00000000000..97df3fe9d9e --- /dev/null +++ b/examples/cpp/discovery_server/HelloWorldCdrAux.ipp @@ -0,0 +1,126 @@ +// 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 HelloWorldCdrAux.ipp + * This source file contains some declarations of CDR related functions. + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_IPP_ +#define _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_IPP_ + +#include "HelloWorldCdrAux.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 HelloWorld& 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.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1), + data.message(), 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 HelloWorld& 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() + << eprosima::fastcdr::MemberId(1) << data.message() +; + scdr.end_serialize_type(current_state); +} + +template<> +eProsima_user_DllExport void deserialize( + eprosima::fastcdr::Cdr& cdr, + HelloWorld& 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; + + case 1: + dcdr >> data.message(); + break; + + default: + ret_value = false; + break; + } + return ret_value; + }); +} + +void serialize_key( + eprosima::fastcdr::Cdr& scdr, + const HelloWorld& data) +{ + static_cast(scdr); + static_cast(data); +} + + + +} // namespace fastcdr +} // namespace eprosima + +#endif // _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_IPP_ + diff --git a/examples/cpp/discovery_server/HelloWorldPubSubTypes.cxx b/examples/cpp/discovery_server/HelloWorldPubSubTypes.cxx new file mode 100644 index 00000000000..aa161b2e163 --- /dev/null +++ b/examples/cpp/discovery_server/HelloWorldPubSubTypes.cxx @@ -0,0 +1,229 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file HelloWorldPubSubTypes.cpp + * This header file contains the implementation of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + +#include "HelloWorldPubSubTypes.h" + +#include +#include + +#include "HelloWorldCdrAux.hpp" +#include "HelloWorldTypeObjectSupport.hpp" + +using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; +using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; + +HelloWorldPubSubType::HelloWorldPubSubType() +{ + setName("HelloWorld"); + uint32_t type_size = +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(HelloWorld::getMaxCdrSerializedSize()); +#else + HelloWorld_max_cdr_typesize; +#endif + type_size += static_cast(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */ + m_typeSize = type_size + 4; /*encapsulation*/ + m_isGetKeyDefined = false; + uint32_t keyLength = HelloWorld_max_key_cdr_typesize > 16 ? HelloWorld_max_key_cdr_typesize : 16; + m_keyBuffer = reinterpret_cast(malloc(keyLength)); + memset(m_keyBuffer, 0, keyLength); +} + +HelloWorldPubSubType::~HelloWorldPubSubType() +{ + if (m_keyBuffer != nullptr) + { + free(m_keyBuffer); + } +} + +bool HelloWorldPubSubType::serialize( + void* data, + SerializedPayload_t* payload, + DataRepresentationId_t data_representation) +{ + HelloWorld* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2); + payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; +#if FASTCDR_VERSION_MAJOR > 1 + ser.set_encoding_flag( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR : + eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2); +#endif // FASTCDR_VERSION_MAJOR > 1 + + try + { + // Serialize encapsulation + ser.serialize_encapsulation(); + // Serialize the object. + ser << *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + // Get the serialized length +#if FASTCDR_VERSION_MAJOR == 1 + payload->length = static_cast(ser.getSerializedDataLength()); +#else + payload->length = static_cast(ser.get_serialized_data_length()); +#endif // FASTCDR_VERSION_MAJOR == 1 + return true; +} + +bool HelloWorldPubSubType::deserialize( + SerializedPayload_t* payload, + void* data) +{ + try + { + // Convert DATA to pointer of your type + HelloWorld* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->length); + + // Object that deserializes the data. + eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN +#if FASTCDR_VERSION_MAJOR == 1 + , eprosima::fastcdr::Cdr::CdrType::DDS_CDR +#endif // FASTCDR_VERSION_MAJOR == 1 + ); + + // Deserialize encapsulation. + deser.read_encapsulation(); + payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE; + + // Deserialize the object. + deser >> *p_type; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return false; + } + + return true; +} + +std::function HelloWorldPubSubType::getSerializedSizeProvider( + void* data, + DataRepresentationId_t data_representation) +{ + return [data, data_representation]() -> uint32_t + { +#if FASTCDR_VERSION_MAJOR == 1 + static_cast(data_representation); + return static_cast(type::getCdrSerializedSize(*static_cast(data))) + + 4u /*encapsulation*/; +#else + try + { + eprosima::fastcdr::CdrSizeCalculator calculator( + data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ? + eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2); + size_t current_alignment {0}; + return static_cast(calculator.calculate_serialized_size( + *static_cast(data), current_alignment)) + + 4u /*encapsulation*/; + } + catch (eprosima::fastcdr::exception::Exception& /*exception*/) + { + return 0; + } +#endif // FASTCDR_VERSION_MAJOR == 1 + }; +} + +void* HelloWorldPubSubType::createData() +{ + return reinterpret_cast(new HelloWorld()); +} + +void HelloWorldPubSubType::deleteData( + void* data) +{ + delete(reinterpret_cast(data)); +} + +bool HelloWorldPubSubType::getKey( + void* data, + InstanceHandle_t* handle, + bool force_md5) +{ + if (!m_isGetKeyDefined) + { + return false; + } + + HelloWorld* p_type = static_cast(data); + + // Object that manages the raw buffer. + eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), + HelloWorld_max_key_cdr_typesize); + + // Object that serializes the data. + eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv1); +#if FASTCDR_VERSION_MAJOR == 1 + p_type->serializeKey(ser); +#else + eprosima::fastcdr::serialize_key(ser, *p_type); +#endif // FASTCDR_VERSION_MAJOR == 1 + if (force_md5 || HelloWorld_max_key_cdr_typesize > 16) + { + m_md5.init(); +#if FASTCDR_VERSION_MAJOR == 1 + m_md5.update(m_keyBuffer, static_cast(ser.getSerializedDataLength())); +#else + m_md5.update(m_keyBuffer, static_cast(ser.get_serialized_data_length())); +#endif // FASTCDR_VERSION_MAJOR == 1 + m_md5.finalize(); + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_md5.digest[i]; + } + } + else + { + for (uint8_t i = 0; i < 16; ++i) + { + handle->value[i] = m_keyBuffer[i]; + } + } + return true; +} + +void HelloWorldPubSubType::register_type_object_representation() +{ + register_HelloWorld_type_identifier(type_identifiers_); +} + + +// Include auxiliary functions like for serializing/deserializing. +#include "HelloWorldCdrAux.ipp" diff --git a/examples/cpp/discovery_server/HelloWorldPubSubTypes.h b/examples/cpp/discovery_server/HelloWorldPubSubTypes.h new file mode 100644 index 00000000000..7c83d2b300b --- /dev/null +++ b/examples/cpp/discovery_server/HelloWorldPubSubTypes.h @@ -0,0 +1,133 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file HelloWorldPubSubTypes.h + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef _FAST_DDS_GENERATED_HELLOWORLD_PUBSUBTYPES_H_ +#define _FAST_DDS_GENERATED_HELLOWORLD_PUBSUBTYPES_H_ + +#include +#include +#include +#include +#include + +#include "HelloWorld.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated HelloWorld is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type HelloWorld defined by the user in the IDL file. + * @ingroup HelloWorld + */ +class HelloWorldPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef HelloWorld type; + + eProsima_user_DllExport HelloWorldPubSubType(); + + eProsima_user_DllExport ~HelloWorldPubSubType() override; + + eProsima_user_DllExport bool serialize( + void* data, + eprosima::fastrtps::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport bool serialize( + void* data, + eprosima::fastrtps::rtps::SerializedPayload_t* payload, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool deserialize( + eprosima::fastrtps::rtps::SerializedPayload_t* payload, + void* data) override; + + eProsima_user_DllExport std::function getSerializedSizeProvider( + void* data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + void* data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + void* data, + eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // _FAST_DDS_GENERATED_HELLOWORLD_PUBSUBTYPES_H_ + diff --git a/examples/cpp/discovery_server/HelloWorldTypeObjectSupport.cxx b/examples/cpp/discovery_server/HelloWorldTypeObjectSupport.cxx new file mode 100644 index 00000000000..aaf391eeed3 --- /dev/null +++ b/examples/cpp/discovery_server/HelloWorldTypeObjectSupport.cxx @@ -0,0 +1,145 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file HelloWorldTypeObjectSupport.cxx + * Source file containing the implementation to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#include "HelloWorldTypeObjectSupport.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "HelloWorld.hpp" + + +using namespace eprosima::fastdds::dds::xtypes; + +// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method +void register_HelloWorld_type_identifier( + TypeIdentifierPair& type_ids_HelloWorld) +{ + + ReturnCode_t return_code_HelloWorld {eprosima::fastdds::dds::RETCODE_OK}; + return_code_HelloWorld = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "HelloWorld", type_ids_HelloWorld); + if (eprosima::fastdds::dds::RETCODE_OK != return_code_HelloWorld) + { + StructTypeFlag struct_flags_HelloWorld = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE, + false, false); + QualifiedTypeName type_name_HelloWorld = "HelloWorld"; + eprosima::fastcdr::optional type_ann_builtin_HelloWorld; + eprosima::fastcdr::optional ann_custom_HelloWorld; + AppliedAnnotationSeq tmp_ann_custom_HelloWorld; + eprosima::fastcdr::optional verbatim_HelloWorld; + if (!tmp_ann_custom_HelloWorld.empty()) + { + ann_custom_HelloWorld = tmp_ann_custom_HelloWorld; + } + + CompleteTypeDetail detail_HelloWorld = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_HelloWorld, ann_custom_HelloWorld, type_name_HelloWorld.to_string()); + CompleteStructHeader header_HelloWorld; + header_HelloWorld = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_HelloWorld); + CompleteStructMemberSeq member_seq_HelloWorld; + { + TypeIdentifierPair type_ids_index; + ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK}; + return_code_index = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "_uint32_t", type_ids_index); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_index) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "index Structure member TypeIdentifier unknown to TypeObjectRegistry."); + return; + } + StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::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_HelloWorld.reset(); + CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_HelloWorld); + CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index); + TypeObjectUtils::add_complete_struct_member(member_seq_HelloWorld, member_index); + } + { + TypeIdentifierPair type_ids_message; + ReturnCode_t return_code_message {eprosima::fastdds::dds::RETCODE_OK}; + return_code_message = + eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers( + "anonymous_string_unbounded", type_ids_message); + + if (eprosima::fastdds::dds::RETCODE_OK != return_code_message) + { + { + SBound bound = 0; + StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn, + "anonymous_string_unbounded", type_ids_message)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "anonymous_string_unbounded already registered in TypeObjectRegistry for a different type."); + } + } + } + StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD, + false, false, false, false); + MemberId member_id_message = 0x00000001; + bool common_message_ec {false}; + CommonStructMember common_message {TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, common_message_ec))}; + if (!common_message_ec) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure message member TypeIdentifier inconsistent."); + return; + } + MemberName name_message = "message"; + eprosima::fastcdr::optional member_ann_builtin_message; + ann_custom_HelloWorld.reset(); + CompleteMemberDetail detail_message = TypeObjectUtils::build_complete_member_detail(name_message, member_ann_builtin_message, ann_custom_HelloWorld); + CompleteStructMember member_message = TypeObjectUtils::build_complete_struct_member(common_message, detail_message); + TypeObjectUtils::add_complete_struct_member(member_seq_HelloWorld, member_message); + } + CompleteStructType struct_type_HelloWorld = TypeObjectUtils::build_complete_struct_type(struct_flags_HelloWorld, header_HelloWorld, member_seq_HelloWorld); + if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER == + TypeObjectUtils::build_and_register_struct_type_object(struct_type_HelloWorld, type_name_HelloWorld.to_string(), type_ids_HelloWorld)) + { + EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, + "HelloWorld already registered in TypeObjectRegistry for a different type."); + } + } +} + diff --git a/examples/cpp/discovery_server/HelloWorldTypeObjectSupport.hpp b/examples/cpp/discovery_server/HelloWorldTypeObjectSupport.hpp new file mode 100644 index 00000000000..2eba797b07f --- /dev/null +++ b/examples/cpp/discovery_server/HelloWorldTypeObjectSupport.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 HelloWorldTypeObjectSupport.hpp + * Header file containing the API required to register the TypeObject representation of the described types in the IDL file + * + * This file was generated by the tool fastddsgen. + */ + +#ifndef _FAST_DDS_GENERATED_HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP_ +#define _FAST_DDS_GENERATED_HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP_ + +#include + + +#if defined(_WIN32) +#if defined(EPROSIMA_USER_DLL_EXPORT) +#define eProsima_user_DllExport __declspec( dllexport ) +#else +#define eProsima_user_DllExport +#endif // EPROSIMA_USER_DLL_EXPORT +#else +#define eProsima_user_DllExport +#endif // _WIN32 + +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +/** + * @brief Register HelloWorld related TypeIdentifier. + * Fully-descriptive TypeIdentifiers are directly registered. + * Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is + * indirectly registered as well. + * + * @param[out] TypeIdentifier of the registered type. + * The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers. + * Invalid TypeIdentifier is returned in case of error. + */ +eProsima_user_DllExport void register_HelloWorld_type_identifier( + eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); + + +#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#endif // _FAST_DDS_GENERATED_HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP_ diff --git a/examples/cpp/discovery_server/Helpers.hpp b/examples/cpp/discovery_server/Helpers.hpp new file mode 100644 index 00000000000..3b602e640f1 --- /dev/null +++ b/examples/cpp/discovery_server/Helpers.hpp @@ -0,0 +1,94 @@ +// Copyright 2021 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 Helpers.hpp + * + */ + +#ifndef _FASTDDS_DISCOVERY_SERVER_EXAMPLE_HELPERS_HPP_ +#define _FASTDDS_DISCOVERY_SERVER_EXAMPLE_HELPERS_HPP_ + +#include +#include + +//! Transport kind enumeration +enum class TransportKind : uint8_t +{ + UDPv4, + UDPv6, + TCPv4, + TCPv6, + SHM, +}; + +inline eprosima::fastrtps::rtps::GuidPrefix_t get_discovery_server_guid_from_id( + unsigned short id) +{ + eprosima::fastrtps::rtps::GuidPrefix_t result; + + // Get default DS guid and modify the one value expected to be changed + std::istringstream(eprosima::fastdds::rtps::DEFAULT_ROS2_SERVER_GUIDPREFIX) >> result; + result.value[2] = + static_cast(id); // This is done like this in Fast + + return result; +} + +inline bool is_ip( + const std::string ip_str) +{ + return eprosima::fastrtps::rtps::IPLocator::isIPv4(ip_str) || eprosima::fastrtps::rtps::IPLocator::isIPv6(ip_str); +} + +inline std::string get_ip_from_dns( + const std::string& domain_name, + TransportKind kind) +{ + std::pair, std::set> dns_response = + eprosima::fastrtps::rtps::IPLocator::resolveNameDNS(domain_name); + + if (kind == TransportKind::UDPv4 || kind == TransportKind::TCPv4) + { + if (dns_response.first.empty()) + { + std::cout << "Not DNS found for IPv4 for " << domain_name << std::endl; + return ""; + } + else + { + std::string solution(*dns_response.first.begin()); + std::cout << "DNS found for " << domain_name << " => " << solution << std::endl; + return solution; + } + } + else if (kind == TransportKind::UDPv6 || kind == TransportKind::TCPv6) + { + if (dns_response.second.empty()) + { + std::cout << "Not DNS found for IPv6 for " << domain_name << std::endl; + return ""; + } + else + { + std::string solution(*dns_response.second.begin()); + std::cout << "DNS found for " << domain_name << " => " << solution << std::endl; + return solution; + } + } + + return domain_name; +} + +#endif /* _FASTDDS_DISCOVERY_SERVER_EXAMPLE_HELPERS_HPP_ */ diff --git a/examples/cpp/discovery_server/README.md b/examples/cpp/discovery_server/README.md new file mode 100644 index 00000000000..15071fc7cde --- /dev/null +++ b/examples/cpp/discovery_server/README.md @@ -0,0 +1,115 @@ +# Discovery Server example + +The *eProsima Fast DDS discovery server* example is an application intended to demonstrate the use of *Discovery Server*. + +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 *discovery server* example describes the use of *Discovery Server* as a discovery hub among different publishers and subscribers. + +* [Description of the example](#description-of-the-example) +* [Run the example](#run-the-example) +* [Wait-set subscriber](#wait-set-subscriber) +* [XML profile playground](#xml-profile-playground) + +## Description of the example + +Within the example, user can create three different entities: a publisher, a subscriber, or a discovery server. +The publisher and subscriber entities are discovery server clients designed to send and receive messages, respectively, while the server is intended to act as the centralized discovery entity among them. + +A server can also act as a client of another server, allowing the creation of a network of servers that can be used to distribute the discovery information among them. +For further information about discovery server, please refer to the [Discovery Server documentation](https://fast-dds.docs.eprosima.com/en/latest/fastdds/discovery/discovery_server.html). + +## Run the example + +To launch this example, three different terminals are required. +One of them will run the publisher example application, another one will run the subscriber application and the third one will run the discovery server application. + +### Discovery Server publisher client + +* Ubuntu ( / MacOS ) + + ```shell + user@machine:example_path$ ./discovery_server publisher + Publisher running. Please press Ctrl+C to stop the Publisher at any time. + ``` + +* Windows + + ```powershell + example_path> discovery_server.exe publisher + Publisher running. Please press Ctrl+C to stop the Publisher at any time. + ``` + +### Discovery Server subscriber client + +* Ubuntu ( / MacOS ) + + ```shell + user@machine:example_path$ ./discovery_server subscriber + Subscriber running. Please press Ctrl+C to stop the Subscriber at any time. + ``` + +* Windows + + ```powershell + example_path> discovery_server.exe subscriber + Subscriber running. Please press Ctrl+C to stop the Subscriber at any time. + ``` + +### Discovery Server server + +* Ubuntu ( / MacOS ) + + ```shell + user@machine:example_path$ ./discovery_server server + Subscriber running. Please press Ctrl+C to stop the Server at any time. + ``` + +* Windows + + ```powershell + example_path> discovery_server.exe server + Subscriber running. Please press Ctrl+C to stop the Server 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, the publisher will not start sending data until the server is up and the subscriber is discovered. +The expected output both for publisher and subscriber is a first displayed message acknowledging the match, followed by the amount of samples sent or received until Ctrl+C is pressed. + +### Discovery Server publisher client + +```shell +Publisher running. Please press Ctrl+C to stop the Publisher at any time. +Publisher matched. +Message: 'Hello world' with index: '1' SENT +Message: 'Hello world' with index: '2' SENT +Message: 'Hello world' with index: '3' SENT +... +``` + +### Discovery Server subscriber client + +```shell +Subscriber running. Please press Ctrl+C to stop the Subscriber at any time. +Subscriber matched. +Message: 'Hello world' with index: '1' RECEIVED +Message: 'Hello world' with index: '2' RECEIVED +Message: 'Hello world' with index: '3' RECEIVED +... +``` + +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 +... +Message: 'Hello world' with index: '8' SENT +Message: 'Hello world' with index: '9' SENT +Message: 'Hello world' with index: '10' SENT +Message: 'Hello world' with index: '11' SENT +Publisher unmatched. +``` + diff --git a/examples/cpp/discovery_server/ServerApp.cpp b/examples/cpp/discovery_server/ServerApp.cpp new file mode 100644 index 00000000000..a4090b53291 --- /dev/null +++ b/examples/cpp/discovery_server/ServerApp.cpp @@ -0,0 +1,286 @@ +// 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 ServerApp.cpp + * + */ + +#include "ServerApp.hpp" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace discovery_server { + +ServerApp::ServerApp( + const CLIParser::server_config& config) + : participant_(nullptr) + , matched_(0) + , timeout_(config.timeout) + , start_time_(std::chrono::steady_clock::now()) + , stop_(false) +{ + DomainParticipantQos pqos; + pqos.name("DS-Server"); + pqos.transport().use_builtin_transports = false; + + std::string ip_listening_address(config.listening_address); + std::string ip_connection_address(config.connection_address); + // Check if DNS is required + if (!is_ip(config.listening_address)) + { + ip_listening_address = get_ip_from_dns(config.listening_address, config.transport_kind); + } + + if (ip_listening_address.empty()) + { + throw std::runtime_error("Invalid listening address"); + } + + // Do the same for connection + if (config.is_also_client && !is_ip(config.connection_address)) + { + ip_connection_address = get_ip_from_dns(config.connection_address, config.transport_kind); + } + + if (config.is_also_client && ip_connection_address.empty()) + { + throw std::runtime_error("Invalid connection address"); + } + + // Configure Listening address + // Create DS SERVER locator + eprosima::fastdds::rtps::Locator listening_locator; + eprosima::fastdds::rtps::Locator connection_locator; + eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(listening_locator, config.listening_port); + eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(connection_locator, config.connection_port); + + std::shared_ptr descriptor; + + switch (config.transport_kind) + { + case TransportKind::SHM: + descriptor = std::make_shared(); + listening_locator.kind = LOCATOR_KIND_SHM; + connection_locator.kind = LOCATOR_KIND_SHM; + break; + + case TransportKind::UDPv4: + { + auto descriptor_tmp = std::make_shared(); + descriptor = descriptor_tmp; + + listening_locator.kind = LOCATOR_KIND_UDPv4; + eprosima::fastrtps::rtps::IPLocator::setIPv4(listening_locator, ip_listening_address); + connection_locator.kind = LOCATOR_KIND_UDPv4; + eprosima::fastrtps::rtps::IPLocator::setIPv4(connection_locator, ip_connection_address); + break; + } + + case TransportKind::UDPv6: + { + auto descriptor_tmp = std::make_shared(); + descriptor = descriptor_tmp; + + listening_locator.kind = LOCATOR_KIND_UDPv6; + eprosima::fastrtps::rtps::IPLocator::setIPv6(listening_locator, ip_listening_address); + connection_locator.kind = LOCATOR_KIND_UDPv6; + eprosima::fastrtps::rtps::IPLocator::setIPv6(connection_locator, ip_connection_address); + break; + } + + case TransportKind::TCPv4: + { + auto descriptor_tmp = std::make_shared(); + descriptor_tmp->add_listener_port(config.listening_port); + descriptor = descriptor_tmp; + + listening_locator.kind = LOCATOR_KIND_TCPv4; + eprosima::fastrtps::rtps::IPLocator::setLogicalPort(listening_locator, config.listening_port); + eprosima::fastrtps::rtps::IPLocator::setIPv4(listening_locator, ip_listening_address); + connection_locator.kind = LOCATOR_KIND_TCPv4; + eprosima::fastrtps::rtps::IPLocator::setIPv4(connection_locator, ip_connection_address); + eprosima::fastrtps::rtps::IPLocator::setLogicalPort(connection_locator, config.connection_port); + break; + } + + case TransportKind::TCPv6: + { + auto descriptor_tmp = std::make_shared(); + descriptor_tmp->add_listener_port(config.listening_port); + descriptor = descriptor_tmp; + + listening_locator.kind = LOCATOR_KIND_TCPv6; + eprosima::fastrtps::rtps::IPLocator::setLogicalPort(listening_locator, config.listening_port); + eprosima::fastrtps::rtps::IPLocator::setIPv6(listening_locator, ip_listening_address); + connection_locator.kind = LOCATOR_KIND_TCPv6; + eprosima::fastrtps::rtps::IPLocator::setIPv6(connection_locator, ip_connection_address); + eprosima::fastrtps::rtps::IPLocator::setLogicalPort(connection_locator, config.connection_port); + break; + } + + default: + break; + } + + // Add descriptor + pqos.transport().user_transports.push_back(descriptor); + + // Set participant as SERVER + pqos.wire_protocol().builtin.discovery_config.discoveryProtocol = + eprosima::fastrtps::rtps::DiscoveryProtocol_t::SERVER; + + // Set SERVER's GUID prefix + pqos.wire_protocol().prefix = get_discovery_server_guid_from_id(config.id); + + // Set SERVER's listening locator for PDP + pqos.wire_protocol().builtin.metatrafficUnicastLocatorList.push_back(listening_locator); + + // Configure Connection address + rtps::RemoteServerAttributes remote_server_att; + if (config.is_also_client) + { + // Set SERVER's GUID prefix + remote_server_att.guidPrefix = get_discovery_server_guid_from_id(config.connection_ds_id); + + // Set SERVER's listening locator for PDP + remote_server_att.metatrafficUnicastLocatorList.push_back(connection_locator); + + // Add remote SERVER to CLIENT's list of SERVERs + pqos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(remote_server_att); + } + + + // Create Participant + participant_ = DomainParticipantFactory::get_instance()->create_participant(0, pqos, this); + + if (participant_ == nullptr) + { + throw std::runtime_error("Participant initialization failed"); + } + + if (config.is_also_client) + { + std::cout << + "Server Participant " << pqos.name() << + " created with GUID " << participant_->guid() << + " listening in address <" << listening_locator << "> " << + " connecting with Discovery Server <" << remote_server_att.guidPrefix << "> " + " with address <" << connection_locator << "> " << + std::endl; + } + else + { + std::cout << + "Server Participant " << pqos.name() << + " created with GUID " << participant_->guid() << + " listening in address <" << listening_locator << "> " << + std::endl; + } +} + +ServerApp::~ServerApp() +{ + if (nullptr != participant_) + { + // Delete DDS entities contained within the DomainParticipant + participant_->delete_contained_entities(); + + // Delete DomainParticipant + DomainParticipantFactory::get_instance()->delete_participant(participant_); + } +} + +void ServerApp::on_participant_discovery( + DomainParticipant*, + fastrtps::rtps::ParticipantDiscoveryInfo&& info, + bool& should_be_ignored) +{ + static_cast(should_be_ignored); + if (info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT) + { + std::cout << "Discovered Participant with GUID " << info.info.m_guid << std::endl; + ++matched_; + } + else if (info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT || + info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT) + { + std::cout << "Dropped Participant with GUID " << info.info.m_guid << std::endl; + --matched_; + } +} + +void ServerApp::run() +{ + while (!is_stopped()) + { + // Wait for period or stop event + std::unique_lock period_lock(mutex_); + + if (timeout_ != 0) + { + bool timeout = false; + cv_.wait_for(period_lock, std::chrono::seconds(timeout_), [&]() + { + timeout = ((std::chrono::steady_clock::now() - start_time_) >= std::chrono::milliseconds(timeout_ * 1000)); + return is_stopped() || timeout; + }); + + if (timeout) + { + stop(); + } + } + else + { + cv_.wait(period_lock, [&]() + { + return is_stopped(); + }); + } + } +} + +bool ServerApp::is_stopped() +{ + return stop_.load(); +} + +void ServerApp::stop() +{ + stop_.store(true); + cv_.notify_one(); +} + +} // namespace discovery_server +} // namespace examples +} // namespace fastdds +} // namespace eprosima diff --git a/examples/cpp/discovery_server/ServerApp.hpp b/examples/cpp/discovery_server/ServerApp.hpp new file mode 100644 index 00000000000..54d7b52438f --- /dev/null +++ b/examples/cpp/discovery_server/ServerApp.hpp @@ -0,0 +1,86 @@ +// 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 ServerApp.hpp + * + */ + +#ifndef _FASTDDS_DISCOVERY_SERVER_SERVER_APP_HPP_ +#define _FASTDDS_DISCOVERY_SERVER_SERVER_APP_HPP_ + +#include + +#include +#include +#include + +#include "Application.hpp" +#include "CLIParser.hpp" +#include "HelloWorldPubSubTypes.h" + +using namespace eprosima::fastdds::dds; + +namespace eprosima { +namespace fastdds { +namespace examples { +namespace discovery_server { + +class ServerApp : public Application, public DomainParticipantListener +{ +public: + + ServerApp( + const CLIParser::server_config& config); + + ~ServerApp(); + + //! Publisher matched method + void on_participant_discovery( + DomainParticipant* participant, + fastrtps::rtps::ParticipantDiscoveryInfo&& info, + bool& should_be_ignored) override; + + //! Run publisher + void run() override; + + //! Stop publisher + void stop() override; + +private: + + //! Return the current state of execution + bool is_stopped(); + + DomainParticipant* participant_; + + int16_t matched_; + + std::mutex mutex_; + + uint16_t timeout_; + + std::chrono::steady_clock::time_point start_time_; + + std::condition_variable cv_; + + std::atomic stop_; +}; + +} // namespace discovery_server +} // namespace examples +} // namespace fastdds +} // namespace eprosima + +#endif /* _FASTDDS_DISCOVERY_SERVER_SERVER_APP_HPP_ */ diff --git a/examples/cpp/discovery_server/main.cpp b/examples/cpp/discovery_server/main.cpp new file mode 100644 index 00000000000..e35a7f105d9 --- /dev/null +++ b/examples/cpp/discovery_server/main.cpp @@ -0,0 +1,110 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @file main.cpp + * + */ + +#include +#include +#include + +#include +#include + +#include "Application.hpp" +#include "CLIParser.hpp" + +using eprosima::fastdds::dds::Log; + +using namespace eprosima::fastdds::examples::discovery_server; + +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::ds_example_config config = CLIParser::parse_cli_options(argc, argv); + uint16_t samples = 0; + switch (config.entity) + { + case CLIParser::EntityKind::CLIENT_PUBLISHER: + samples = config.pub_config.samples; + break; + case CLIParser::EntityKind::CLIENT_SUBSCRIBER: + samples = config.sub_config.samples; + break; + case CLIParser::EntityKind::SERVER: + samples = config.sub_config.samples; + break; + default: + break; + } + + std::string app_name = CLIParser::parse_entity_kind(config.entity); + std::shared_ptr app; + + try + { + app = Application::make_app(config); + } + catch (const std::runtime_error& e) + { + EPROSIMA_LOG_ERROR(app_name, e.what()); + ret = EXIT_FAILURE; + } + + if (EXIT_FAILURE != ret) + { + std::thread thread(&Application::run, app); + + if (samples == 0) + { + std::cout << app_name << " running. Please press Ctrl+C to stop the " + << app_name << " at any time." << std::endl; + } + else + { + std::cout << app_name << " running for " << samples << " samples. Please press Ctrl+C to stop the " + << app_name << " at any time." << std::endl; + } + + stop_app_handler = [&](int signum) + { + std::cout << "\n" << CLIParser::parse_signal(signum) << " received, stopping " << app_name + << " execution." << std::endl; + app->stop(); + }; + + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); + #ifndef _WIN32 + signal(SIGQUIT, signal_handler); + signal(SIGHUP, signal_handler); + #endif // _WIN32 + + thread.join(); + } + + Log::Reset(); + return ret; +} From b96578bacc37824175c3208058ea558398028bec Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Fri, 7 Jun 2024 11:15:50 +0200 Subject: [PATCH 03/18] Refs #21095: Add discovery_sever example tests Signed-off-by: Mario Dominguez --- test/examples/discovery_server.compose.yml | 66 ++++++++++++++++++++++ test/examples/test_configuration.py | 52 +++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 test/examples/discovery_server.compose.yml diff --git a/test/examples/discovery_server.compose.yml b/test/examples/discovery_server.compose.yml new file mode 100644 index 00000000000..bdba0e291d1 --- /dev/null +++ b/test/examples/discovery_server.compose.yml @@ -0,0 +1,66 @@ +version: "3" + +services: + subscriber: + image: @DOCKER_IMAGE_NAME@ + volumes: + - @PROJECT_BINARY_DIR@:@PROJECT_BINARY_DIR@ + - @fastcdr_LIB_DIR@:@fastcdr_LIB_DIR@ + @TINYXML2_LIB_DIR_COMPOSE_VOLUME@ + environment: + # TODO(eduponz): LD_LIBRARY_PATH is not the correct variable for Windows + LD_LIBRARY_PATH: @PROJECT_BINARY_DIR@/src/cpp:@fastcdr_LIB_DIR@@TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH@ + EXAMPLE_DIR: @PROJECT_BINARY_DIR@/examples/cpp/discovery_server@FILE_EXTENSION@ + SUBSCRIBER_ADDITIONAL_ARGUMENTS: ${SUB_ARGS} + command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/discovery_server@FILE_EXTENSION@ subscriber --reliable --transient-local $${SUBSCRIBER_ADDITIONAL_ARGUMENTS}" + network_mode: host + ipc: host + depends_on: + - server_1 + + publisher: + image: @DOCKER_IMAGE_NAME@ + volumes: + - @PROJECT_BINARY_DIR@:@PROJECT_BINARY_DIR@ + - @fastcdr_LIB_DIR@:@fastcdr_LIB_DIR@ + @TINYXML2_LIB_DIR_COMPOSE_VOLUME@ + environment: + # TODO(eduponz): LD_LIBRARY_PATH is not the correct variable for Windows + LD_LIBRARY_PATH: @PROJECT_BINARY_DIR@/src/cpp:@fastcdr_LIB_DIR@@TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH@ + EXAMPLE_DIR: @PROJECT_BINARY_DIR@/examples/cpp/discovery_server@FILE_EXTENSION@ + PUBLISHER_ADDITIONAL_ARGUMENTS: ${PUB_ARGS} + command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/discovery_server@FILE_EXTENSION@ publisher --reliable --transient-local $${PUBLISHER_ADDITIONAL_ARGUMENTS}" + network_mode: host + ipc: host + depends_on: + - server_1 + + server_1: + image: @DOCKER_IMAGE_NAME@ + volumes: + - @PROJECT_BINARY_DIR@:@PROJECT_BINARY_DIR@ + - @fastcdr_LIB_DIR@:@fastcdr_LIB_DIR@ + @TINYXML2_LIB_DIR_COMPOSE_VOLUME@ + environment: + # TODO(eduponz): LD_LIBRARY_PATH is not the correct variable for Windows + LD_LIBRARY_PATH: @PROJECT_BINARY_DIR@/src/cpp:@fastcdr_LIB_DIR@@TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH@ + EXAMPLE_DIR: @PROJECT_BINARY_DIR@/examples/cpp/discovery_server@FILE_EXTENSION@ + SERVER1_ADDITIONAL_ARGUMENTS: ${SERVER1_ARGS} + network_mode: host + ipc: host + command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/discovery_server@FILE_EXTENSION@ server $${SERVER1_ADDITIONAL_ARGUMENTS}" + + server_2: + image: @DOCKER_IMAGE_NAME@ + volumes: + - @PROJECT_BINARY_DIR@:@PROJECT_BINARY_DIR@ + - @fastcdr_LIB_DIR@:@fastcdr_LIB_DIR@ + @TINYXML2_LIB_DIR_COMPOSE_VOLUME@ + environment: + # TODO(eduponz): LD_LIBRARY_PATH is not the correct variable for Windows + LD_LIBRARY_PATH: @PROJECT_BINARY_DIR@/src/cpp:@fastcdr_LIB_DIR@@TINYXML2_LIB_DIR_COMPOSE_LD_LIBRARY_PATH@ + EXAMPLE_DIR: @PROJECT_BINARY_DIR@/examples/cpp/discovery_server@FILE_EXTENSION@ + SERVER2_ADDITIONAL_ARGUMENTS: ${SERVER2_ARGS} + network_mode: host + ipc: host + command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/discovery_server@FILE_EXTENSION@ server $${SERVER2_ADDITIONAL_ARGUMENTS}" diff --git a/test/examples/test_configuration.py b/test/examples/test_configuration.py index 79fede9278b..26181851a03 100644 --- a/test/examples/test_configuration.py +++ b/test/examples/test_configuration.py @@ -16,6 +16,58 @@ import pytest import re +""" + Expected output test cases for Discovery Server example. + Each element is a ternary (pub_args, sub_args, server_args) +""" +discovery_server_test_cases = [ + ('--samples 10', '--samples 10', '--timeout 5', '--id 2 --listening-port 11400 --timeout 1'), + ('--connection-port 11500 --samples 10', '--connection-port 11500 --samples 10', '--listening-port 11500 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), + ('--transport tcpv4 --samples 10', '--transport tcpv4 --samples 10', '--transport tcpv4 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), + ('--connection-ds-id 1 --samples 10', '--connection-ds-id 1 --samples 10', '--id 1 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), + ('--connection-ds-id 1 --samples 10', '--connection-ds-id 2 --connection-port 11400 --samples 10', '--id 1 --timeout 5 --connection-ds-id 2 --connection-port 11400', '--id 2 --listening-port 11400 --timeout 5') +] + +@pytest.mark.parametrize("pub_args, sub_args, server1_args, server2_args", discovery_server_test_cases) +def test_discovery_server(pub_args, sub_args, server1_args, server2_args): + """.""" + ret = False + out = '' + command_args = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" SERVER1_ARGS="' + server1_args + '" SERVER2_ARGS="' + server2_args + '" ' + try: + out = subprocess.check_output( + command_args + '@DOCKER_EXECUTABLE@ compose -f discovery_server.compose.yml up', + stderr=subprocess.STDOUT, + shell=True, + timeout=30 + ).decode().split('\n') + + sent = 0 + received = 0 + for line in out: + if 'SENT' in line: + sent += 1 + continue + + if 'RECEIVED' in line: + received += 1 + continue + + if sent != 0 and received != 0 and sent == received: + ret = True + else: + print('ERROR: sent: ' + str(sent) + ', but received: ' + str(received)) + raise subprocess.CalledProcessError(1, '') + + except subprocess.CalledProcessError: + for l in out: + print(l) + except subprocess.TimeoutExpired: + print('TIMEOUT') + print(out) + + assert(ret) + config_test_cases = [ ('--keep-last 10 --transport DEFAULT', '--keep-last 10 --transport DEFAULT'), # Builtin transports ('--keep-last 10 --transport DEFAULT', '--keep-last 10 --transport UDPv4'), From 4f9ddfd95feecf2b8bcebdbd31b73289428234d4 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Fri, 7 Jun 2024 11:24:31 +0200 Subject: [PATCH 04/18] Refs #21095: versions.md Signed-off-by: Mario Dominguez --- versions.md | 1 + 1 file changed, 1 insertion(+) diff --git a/versions.md b/versions.md index 9e749ca7a2e..2d2d0d1cb35 100644 --- a/versions.md +++ b/versions.md @@ -50,6 +50,7 @@ Forthcoming * X-Types example with dynamic type discovery and Hello world example compatibility. * Custom Content filter example * Delivery mechanisms example with SHM, UDP, TCP, data-sharing and intra-process mechanisms. + * Discovery server example. * Removed `TypeConsistencyQos` from DataReader, and included `TypeConsistencyEnforcementQosPolicy` and `DataRepresentationQosPolicy` * Added new `flow_controller_descriptor_list` XML configuration, remove `ThroughtputController`. * Migrate `#define`s within `BuiltinEndpoints.hpp` to namespaced `constexpr` variables. From d80b5b670b8efa6b17535b97849bb22b81a7ffd8 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Fri, 7 Jun 2024 11:54:46 +0200 Subject: [PATCH 05/18] Refs #21095: Linter all except from types Signed-off-by: Mario Dominguez --- examples/cpp/discovery_server/CLIParser.hpp | 19 ++++++++++--------- examples/cpp/discovery_server/ServerApp.cpp | 16 +++++++++------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/examples/cpp/discovery_server/CLIParser.hpp b/examples/cpp/discovery_server/CLIParser.hpp index e8b938fe236..ce7eff6c45d 100644 --- a/examples/cpp/discovery_server/CLIParser.hpp +++ b/examples/cpp/discovery_server/CLIParser.hpp @@ -75,21 +75,21 @@ class CLIParser //! Publisher client configuration structure struct client_publisher_config : public common_config, - public pubsub_config + public pubsub_config { uint16_t interval{100}; }; //! Subscriber client configuration structure struct client_subscriber_config : public common_config, - public pubsub_config + public pubsub_config { }; //! Server configuration structure //! A server can, in turn, act as a client struct server_config : public common_config, - public client_config + public client_config { bool is_also_client{false}; uint16_t listening_port{16166}; @@ -106,16 +106,16 @@ class CLIParser client_subscriber_config sub_config; server_config srv_config; - friend std::ostream& operator<< ( - std::ostream& os, - const ds_example_config& config) + friend std::ostream& operator << ( + std::ostream& os, + const ds_example_config& config) { os << "Entity: " << parse_entity_kind(config.entity) << std::endl; os << "Common options:" << std::endl; os << " Transport: " << static_cast(config.pub_config.transport_kind) << std::endl; if (config.entity != CLIParser::EntityKind::SERVER || - (config.entity == CLIParser::EntityKind::SERVER && config.srv_config.is_also_client)) + (config.entity == CLIParser::EntityKind::SERVER && config.srv_config.is_also_client)) { os << "Client options:" << std::endl; os << " Connection address: " << config.pub_config.connection_address << std::endl; @@ -147,6 +147,7 @@ class CLIParser return os; } + }; /** @@ -442,7 +443,7 @@ class CLIParser else { if (config.entity == CLIParser::EntityKind::CLIENT_PUBLISHER || - config.entity == CLIParser::EntityKind::CLIENT_SUBSCRIBER) + config.entity == CLIParser::EntityKind::CLIENT_SUBSCRIBER) { config.pub_config.samples = static_cast(input); config.sub_config.samples = static_cast(input); @@ -492,7 +493,7 @@ class CLIParser { int input = std::stoi(argv[i]); if (input < std::numeric_limits::min() || - input > std::numeric_limits::max()) + input > std::numeric_limits::max()) { throw std::out_of_range("interval argument out of range"); } diff --git a/examples/cpp/discovery_server/ServerApp.cpp b/examples/cpp/discovery_server/ServerApp.cpp index a4090b53291..e76c6f88260 100644 --- a/examples/cpp/discovery_server/ServerApp.cpp +++ b/examples/cpp/discovery_server/ServerApp.cpp @@ -249,10 +249,12 @@ void ServerApp::run() { bool timeout = false; cv_.wait_for(period_lock, std::chrono::seconds(timeout_), [&]() - { - timeout = ((std::chrono::steady_clock::now() - start_time_) >= std::chrono::milliseconds(timeout_ * 1000)); - return is_stopped() || timeout; - }); + { + timeout = + ((std::chrono::steady_clock::now() - start_time_) >= + std::chrono::milliseconds(timeout_ * 1000)); + return is_stopped() || timeout; + }); if (timeout) { @@ -262,9 +264,9 @@ void ServerApp::run() else { cv_.wait(period_lock, [&]() - { - return is_stopped(); - }); + { + return is_stopped(); + }); } } } From f9595c0d0e54f905d6128eee7de93a2d3040a7c7 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Mon, 10 Jun 2024 15:14:17 +0200 Subject: [PATCH 06/18] Refs #21095: split discovery server example Signed-off-by: Mario Dominguez --- test/examples/test_configuration.py | 52 ------------------------- test/examples/test_discovery_server.py | 54 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 52 deletions(-) create mode 100644 test/examples/test_discovery_server.py diff --git a/test/examples/test_configuration.py b/test/examples/test_configuration.py index 26181851a03..79fede9278b 100644 --- a/test/examples/test_configuration.py +++ b/test/examples/test_configuration.py @@ -16,58 +16,6 @@ import pytest import re -""" - Expected output test cases for Discovery Server example. - Each element is a ternary (pub_args, sub_args, server_args) -""" -discovery_server_test_cases = [ - ('--samples 10', '--samples 10', '--timeout 5', '--id 2 --listening-port 11400 --timeout 1'), - ('--connection-port 11500 --samples 10', '--connection-port 11500 --samples 10', '--listening-port 11500 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), - ('--transport tcpv4 --samples 10', '--transport tcpv4 --samples 10', '--transport tcpv4 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), - ('--connection-ds-id 1 --samples 10', '--connection-ds-id 1 --samples 10', '--id 1 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), - ('--connection-ds-id 1 --samples 10', '--connection-ds-id 2 --connection-port 11400 --samples 10', '--id 1 --timeout 5 --connection-ds-id 2 --connection-port 11400', '--id 2 --listening-port 11400 --timeout 5') -] - -@pytest.mark.parametrize("pub_args, sub_args, server1_args, server2_args", discovery_server_test_cases) -def test_discovery_server(pub_args, sub_args, server1_args, server2_args): - """.""" - ret = False - out = '' - command_args = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" SERVER1_ARGS="' + server1_args + '" SERVER2_ARGS="' + server2_args + '" ' - try: - out = subprocess.check_output( - command_args + '@DOCKER_EXECUTABLE@ compose -f discovery_server.compose.yml up', - stderr=subprocess.STDOUT, - shell=True, - timeout=30 - ).decode().split('\n') - - sent = 0 - received = 0 - for line in out: - if 'SENT' in line: - sent += 1 - continue - - if 'RECEIVED' in line: - received += 1 - continue - - if sent != 0 and received != 0 and sent == received: - ret = True - else: - print('ERROR: sent: ' + str(sent) + ', but received: ' + str(received)) - raise subprocess.CalledProcessError(1, '') - - except subprocess.CalledProcessError: - for l in out: - print(l) - except subprocess.TimeoutExpired: - print('TIMEOUT') - print(out) - - assert(ret) - config_test_cases = [ ('--keep-last 10 --transport DEFAULT', '--keep-last 10 --transport DEFAULT'), # Builtin transports ('--keep-last 10 --transport DEFAULT', '--keep-last 10 --transport UDPv4'), diff --git a/test/examples/test_discovery_server.py b/test/examples/test_discovery_server.py new file mode 100644 index 00000000000..2614aa1739a --- /dev/null +++ b/test/examples/test_discovery_server.py @@ -0,0 +1,54 @@ +import subprocess +import pytest + +""" + Expected output test cases for Discovery Server example. + Each element is a ternary (pub_args, sub_args, server_args) +""" +discovery_server_test_cases = [ + ('--samples 10', '--samples 10', '--timeout 5', '--id 2 --listening-port 11400 --timeout 1'), + ('--connection-port 11500 --samples 10', '--connection-port 11500 --samples 10', '--listening-port 11500 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), + ('--transport tcpv4 --samples 10', '--transport tcpv4 --samples 10', '--transport tcpv4 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), + ('--connection-ds-id 1 --samples 10', '--connection-ds-id 1 --samples 10', '--id 1 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), + ('--connection-ds-id 1 --samples 10', '--connection-ds-id 2 --connection-port 11400 --samples 10', '--id 1 --timeout 5 --connection-ds-id 2 --connection-port 11400', '--id 2 --listening-port 11400 --timeout 5') +] + +@pytest.mark.parametrize("pub_args, sub_args, server1_args, server2_args", discovery_server_test_cases) +def test_discovery_server(pub_args, sub_args, server1_args, server2_args): + """.""" + ret = False + out = '' + command_args = 'PUB_ARGS="' + pub_args + '" SUB_ARGS="' + sub_args + '" SERVER1_ARGS="' + server1_args + '" SERVER2_ARGS="' + server2_args + '" ' + try: + out = subprocess.check_output( + command_args + '@DOCKER_EXECUTABLE@ compose -f discovery_server.compose.yml up', + stderr=subprocess.STDOUT, + shell=True, + timeout=30 + ).decode().split('\n') + + sent = 0 + received = 0 + for line in out: + if 'SENT' in line: + sent += 1 + continue + + if 'RECEIVED' in line: + received += 1 + continue + + if sent != 0 and received != 0 and sent == received: + ret = True + else: + print('ERROR: sent: ' + str(sent) + ', but received: ' + str(received)) + raise subprocess.CalledProcessError(1, '') + + except subprocess.CalledProcessError: + for l in out: + print(l) + except subprocess.TimeoutExpired: + print('TIMEOUT') + print(out) + + assert(ret) From 00ee139435e6ea1da3d11fad9afbdafa1d19cf8c Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 11 Jun 2024 11:30:02 +0200 Subject: [PATCH 07/18] Refs #21095: Address Elianas review Signed-off-by: Mario Dominguez --- examples/cpp/discovery_server/CLIParser.hpp | 178 +++++++++++------- .../discovery_server/ClientPublisherApp.cpp | 6 +- .../discovery_server/ClientSubscriberApp.cpp | 4 +- examples/cpp/discovery_server/main.cpp | 3 - 4 files changed, 114 insertions(+), 77 deletions(-) diff --git a/examples/cpp/discovery_server/CLIParser.hpp b/examples/cpp/discovery_server/CLIParser.hpp index ce7eff6c45d..6ccdf5066fe 100644 --- a/examples/cpp/discovery_server/CLIParser.hpp +++ b/examples/cpp/discovery_server/CLIParser.hpp @@ -50,12 +50,6 @@ class CLIParser UNDEFINED }; - //! Common configuration for all the entities - struct common_config - { - TransportKind transport_kind{TransportKind::UDPv4}; - }; - //! Clients common configuration struct client_config { @@ -74,24 +68,24 @@ class CLIParser }; //! Publisher client configuration structure - struct client_publisher_config : public common_config, - public pubsub_config + struct client_publisher_config : public pubsub_config { + TransportKind transport_kind{TransportKind::UDPv4}; uint16_t interval{100}; }; //! Subscriber client configuration structure - struct client_subscriber_config : public common_config, - public pubsub_config + struct client_subscriber_config : public pubsub_config { + TransportKind transport_kind{TransportKind::UDPv4}; }; //! Server configuration structure //! A server can, in turn, act as a client - struct server_config : public common_config, - public client_config + struct server_config : public client_config { bool is_also_client{false}; + TransportKind transport_kind{TransportKind::UDPv4}; uint16_t listening_port{16166}; uint16_t id{0}; uint16_t timeout{0}; @@ -167,13 +161,13 @@ class CLIParser std::cout << " subscriber Run a client subscriber entity." << std::endl; std::cout << " server Run a server 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 << " -c , --connection-address Server address" << std::endl; + std::cout << "Client options (common to Publisher, Subscriber and Server acting as Client):" << std::endl; + std::cout << " -c , --connection-address Address of the Server to connect to" << std::endl; std::cout << " (Default address: 127.0.0.1)." << std::endl; - std::cout << " -p , --connection-port Server listening port" << std::endl; + std::cout << " -p , --connection-port Port of the Server to connect to" << std::endl; std::cout << " (Default port: 16166)." << std::endl; - std::cout << " -d --connection-ds-id Id of the Discovery Server to connect to" << std::endl; + std::cout << " --connection-ds-id Id of the Discovery Server to connect to" << std::endl; std::cout << " (0 by default)." << std::endl; std::cout << " --transport [udpv4|udpv6|tcpv4|tcpv6|shm] " << std::endl; std::cout << " (udpv4 by default)." << std::endl; @@ -192,6 +186,7 @@ class CLIParser std::cout << "" << std::endl; std::cout << "Subscriber options:" << std::endl; std::cout << " -t , --topic Topic name" << std::endl; + std::cout << " (Default: discovery_server_topic)." << std::endl; std::cout << " -s , --samples Number of samples to receive" << std::endl; std::cout << " (Default: 0 => infinite samples)." << std::endl; std::cout << " -r, --reliable Set Reliability QoS as reliable" << std::endl; @@ -206,7 +201,7 @@ class CLIParser std::cout << " (Default port: 16166)" << std::endl; std::cout << " --id Id of the Discovery Server (Default: 0)." << std::endl; std::cout << " --timeout Number of seconds before finish" << std::endl; - std::cout << " --id the process (Default: 0 = till ^C)." << std::endl; + std::cout << " the process (Default: 0 = till ^C)." << std::endl; std::exit(return_code); } @@ -255,6 +250,8 @@ class CLIParser print_help(EXIT_FAILURE); } + bool uses_ipv6 = false; + bool listening_address_was_set = false; for (int i = 2; i < argc; ++i) { std::string arg = argv[i]; @@ -281,6 +278,7 @@ class CLIParser config.pub_config.transport_kind = TransportKind::UDPv6; config.sub_config.transport_kind = TransportKind::UDPv6; config.srv_config.transport_kind = TransportKind::UDPv6; + uses_ipv6 = true; } else if (input == "tcpv4") { @@ -293,6 +291,7 @@ class CLIParser config.pub_config.transport_kind = TransportKind::TCPv6; config.sub_config.transport_kind = TransportKind::TCPv6; config.srv_config.transport_kind = TransportKind::TCPv6; + uses_ipv6 = true; } else if (input == "shm") { @@ -373,7 +372,7 @@ class CLIParser print_help(EXIT_FAILURE); } } - else if (arg == "-d" || arg == "--connection-ds-id") + else if (arg == "--connection-ds-id") { if (++i < argc) { @@ -415,16 +414,17 @@ class CLIParser } } // PubSub options - else if (arg == "-t" || arg == "--topic-name") + else if (arg == "-t" || arg == "--topic") { - if (++i < argc) + if (config.entity == CLIParser::EntityKind::CLIENT_PUBLISHER || + config.entity == CLIParser::EntityKind::CLIENT_SUBSCRIBER) { config.pub_config.topic_name = argv[i]; config.sub_config.topic_name = argv[i]; } else { - EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing topic name argument"); + EPROSIMA_LOG_ERROR(CLI_PARSER, "wrong or missing entity for --topic argument: only available for publisher and subscriber"); print_help(EXIT_FAILURE); } } @@ -531,7 +531,16 @@ class CLIParser { if (++i < argc) { - config.srv_config.listening_address = argv[i]; + if (config.entity == CLIParser::EntityKind::SERVER ) + { + config.srv_config.listening_address = argv[i]; + listening_address_was_set = true; + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "listening address argument is only valid for server entity"); + print_help(EXIT_FAILURE); + } } else { @@ -543,29 +552,37 @@ class CLIParser { if (++i < argc) { - try + if (config.entity == CLIParser::EntityKind::SERVER) { - int input = std::stoi(argv[i]); - if (input < std::numeric_limits::min() || - input > std::numeric_limits::max()) + try { - throw std::out_of_range("listening-port argument " + std::string( - argv[i]) + " out of range [0, 65535]."); + int input = std::stoi(argv[i]); + if (input < std::numeric_limits::min() || + input > std::numeric_limits::max()) + { + throw std::out_of_range("listening-port argument " + std::string( + argv[i]) + " out of range [0, 65535]."); + } + else + { + config.srv_config.listening_port = static_cast(input); + } } - else + catch (const std::invalid_argument& e) { - config.srv_config.listening_port = static_cast(input); + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid listening-port 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); } } - catch (const std::invalid_argument& e) - { - EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid listening-port argument " + std::string( - argv[i]) + ": " + std::string(e.what())); - print_help(EXIT_FAILURE); - } - catch (const std::out_of_range& e) + else { - EPROSIMA_LOG_ERROR(CLI_PARSER, std::string(e.what())); + EPROSIMA_LOG_ERROR(CLI_PARSER, "--listening-port argument is only valid for server entity"); print_help(EXIT_FAILURE); } } @@ -579,28 +596,36 @@ class CLIParser { if (++i < argc) { - try + if (config.entity == CLIParser::EntityKind::SERVER) { - int input = std::stoi(argv[i]); - if (input < 0 || input > 255) + try { - throw std::out_of_range("id argument " + std::string( - argv[i]) + " out of range [0, 255]."); + int input = std::stoi(argv[i]); + if (input < 0 || input > 255) + { + throw std::out_of_range("id argument " + std::string( + argv[i]) + " out of range [0, 255]."); + } + else + { + config.srv_config.id = static_cast(input); + } } - else + catch (const std::invalid_argument& e) { - config.srv_config.id = static_cast(input); + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid id 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); } } - catch (const std::invalid_argument& e) - { - EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid id argument " + std::string( - argv[i]) + ": " + std::string(e.what())); - print_help(EXIT_FAILURE); - } - catch (const std::out_of_range& e) + else { - EPROSIMA_LOG_ERROR(CLI_PARSER, std::string(e.what())); + EPROSIMA_LOG_ERROR(CLI_PARSER, "--listening-port argument is only valid for server entity"); print_help(EXIT_FAILURE); } } @@ -614,29 +639,37 @@ class CLIParser { if (++i < argc) { - try + if (config.entity == CLIParser::EntityKind::SERVER) { - int input = std::stoi(argv[i]); - if (input < std::numeric_limits::min() || - input > std::numeric_limits::max()) + try { - throw std::out_of_range("timeout argument " + std::string( - argv[i]) + " out of range [0, 65535]."); + int input = std::stoi(argv[i]); + if (input < std::numeric_limits::min() || + input > std::numeric_limits::max()) + { + throw std::out_of_range("timeout argument " + std::string( + argv[i]) + " out of range [0, 65535]."); + } + else + { + config.srv_config.timeout = static_cast(input); + } } - else + catch (const std::invalid_argument& e) { - config.srv_config.timeout = static_cast(input); + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid timeout 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); } } - catch (const std::invalid_argument& e) - { - EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid timeout argument " + std::string( - argv[i]) + ": " + std::string(e.what())); - print_help(EXIT_FAILURE); - } - catch (const std::out_of_range& e) + else { - EPROSIMA_LOG_ERROR(CLI_PARSER, std::string(e.what())); + EPROSIMA_LOG_ERROR(CLI_PARSER, "--listening-port argument is only valid for server entity"); print_help(EXIT_FAILURE); } } @@ -653,6 +686,13 @@ class CLIParser } } + if (uses_ipv6 + && !listening_address_was_set + && config.entity == CLIParser::EntityKind::SERVER) + { + config.srv_config.listening_address = "::1"; + } + return config; } diff --git a/examples/cpp/discovery_server/ClientPublisherApp.cpp b/examples/cpp/discovery_server/ClientPublisherApp.cpp index 60a65494a94..1643aab8d4d 100644 --- a/examples/cpp/discovery_server/ClientPublisherApp.cpp +++ b/examples/cpp/discovery_server/ClientPublisherApp.cpp @@ -188,7 +188,7 @@ ClientPublisherApp::ClientPublisherApp( } // Create the topic - topic_ = participant_->create_topic(config.topic_name, "HelloWorld", TOPIC_QOS_DEFAULT); + topic_ = participant_->create_topic(config.topic_name, type_.get_type_name(), TOPIC_QOS_DEFAULT); if (topic_ == nullptr) { @@ -207,9 +207,9 @@ ClientPublisherApp::ClientPublisherApp( wqos.reliability().kind = BEST_EFFORT_RELIABILITY_QOS; } - if (config.transient_local) + if (!config.transient_local) { - wqos.durability().kind = TRANSIENT_LOCAL_DURABILITY_QOS; + wqos.durability().kind = VOLATILE_DURABILITY_QOS; } writer_ = publisher_->create_datawriter(topic_, wqos, this); diff --git a/examples/cpp/discovery_server/ClientSubscriberApp.cpp b/examples/cpp/discovery_server/ClientSubscriberApp.cpp index 334fc99b47a..61bbad11ea9 100644 --- a/examples/cpp/discovery_server/ClientSubscriberApp.cpp +++ b/examples/cpp/discovery_server/ClientSubscriberApp.cpp @@ -134,7 +134,7 @@ ClientSubscriberApp::ClientSubscriberApp( server_locator.kind = LOCATOR_KIND_TCPv6; eprosima::fastrtps::rtps::IPLocator::setLogicalPort(server_locator, server_port); - eprosima::fastrtps::rtps::IPLocator::setIPv4(server_locator, ip_server_address); + eprosima::fastrtps::rtps::IPLocator::setIPv6(server_locator, ip_server_address); break; } @@ -189,7 +189,7 @@ ClientSubscriberApp::ClientSubscriberApp( // Create the topic topic_ = participant_->create_topic( config.topic_name, - "HelloWorld", + type_.get_type_name(), TOPIC_QOS_DEFAULT); if (topic_ == nullptr) diff --git a/examples/cpp/discovery_server/main.cpp b/examples/cpp/discovery_server/main.cpp index e35a7f105d9..d6cd7bfb050 100644 --- a/examples/cpp/discovery_server/main.cpp +++ b/examples/cpp/discovery_server/main.cpp @@ -53,9 +53,6 @@ int main( case CLIParser::EntityKind::CLIENT_SUBSCRIBER: samples = config.sub_config.samples; break; - case CLIParser::EntityKind::SERVER: - samples = config.sub_config.samples; - break; default: break; } From 8da131aee819e63001bfef16376c3265eb688a19 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 11 Jun 2024 11:45:33 +0200 Subject: [PATCH 08/18] Refs #21095: Linter Signed-off-by: Mario Dominguez --- examples/cpp/discovery_server/CLIParser.hpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/cpp/discovery_server/CLIParser.hpp b/examples/cpp/discovery_server/CLIParser.hpp index 6ccdf5066fe..c00bcccc312 100644 --- a/examples/cpp/discovery_server/CLIParser.hpp +++ b/examples/cpp/discovery_server/CLIParser.hpp @@ -417,14 +417,15 @@ class CLIParser else if (arg == "-t" || arg == "--topic") { if (config.entity == CLIParser::EntityKind::CLIENT_PUBLISHER || - config.entity == CLIParser::EntityKind::CLIENT_SUBSCRIBER) + config.entity == CLIParser::EntityKind::CLIENT_SUBSCRIBER) { config.pub_config.topic_name = argv[i]; config.sub_config.topic_name = argv[i]; } else { - EPROSIMA_LOG_ERROR(CLI_PARSER, "wrong or missing entity for --topic argument: only available for publisher and subscriber"); + EPROSIMA_LOG_ERROR(CLI_PARSER, + "wrong or missing entity for --topic argument: only available for publisher and subscriber"); print_help(EXIT_FAILURE); } } @@ -561,7 +562,7 @@ class CLIParser input > std::numeric_limits::max()) { throw std::out_of_range("listening-port argument " + std::string( - argv[i]) + " out of range [0, 65535]."); + argv[i]) + " out of range [0, 65535]."); } else { @@ -604,7 +605,7 @@ class CLIParser if (input < 0 || input > 255) { throw std::out_of_range("id argument " + std::string( - argv[i]) + " out of range [0, 255]."); + argv[i]) + " out of range [0, 255]."); } else { @@ -648,7 +649,7 @@ class CLIParser input > std::numeric_limits::max()) { throw std::out_of_range("timeout argument " + std::string( - argv[i]) + " out of range [0, 65535]."); + argv[i]) + " out of range [0, 65535]."); } else { @@ -687,8 +688,8 @@ class CLIParser } if (uses_ipv6 - && !listening_address_was_set - && config.entity == CLIParser::EntityKind::SERVER) + && !listening_address_was_set + && config.entity == CLIParser::EntityKind::SERVER) { config.srv_config.listening_address = "::1"; } From 614eadc55f68a53d9bdd7e0a8271ea698affb03b Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 11 Jun 2024 12:57:39 +0200 Subject: [PATCH 09/18] Refs #21095: Fix casting for windows compilation Signed-off-by: Mario Dominguez --- examples/cpp/discovery_server/CLIParser.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/cpp/discovery_server/CLIParser.hpp b/examples/cpp/discovery_server/CLIParser.hpp index c00bcccc312..3bd233147c5 100644 --- a/examples/cpp/discovery_server/CLIParser.hpp +++ b/examples/cpp/discovery_server/CLIParser.hpp @@ -500,7 +500,7 @@ class CLIParser } else { - config.pub_config.interval = static_cast(input); + config.pub_config.interval = static_cast(input); } } catch (const std::invalid_argument& e) From 8e2b38c89813b1e8afe61570e474b81682095e97 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Wed, 12 Jun 2024 11:42:58 +0200 Subject: [PATCH 10/18] Refs #21095: Create a test for each transport and intialize to ::1 when ipv6 is used Signed-off-by: Mario Dominguez --- examples/cpp/discovery_server/CLIParser.hpp | 25 ++++++++++++++++--- .../discovery_server/ClientPublisherApp.cpp | 4 --- test/examples/test_discovery_server.py | 5 +++- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/examples/cpp/discovery_server/CLIParser.hpp b/examples/cpp/discovery_server/CLIParser.hpp index 3bd233147c5..e18393117ab 100644 --- a/examples/cpp/discovery_server/CLIParser.hpp +++ b/examples/cpp/discovery_server/CLIParser.hpp @@ -252,6 +252,8 @@ class CLIParser bool uses_ipv6 = false; bool listening_address_was_set = false; + bool connection_address_was_set = false; + for (int i = 2; i < argc; ++i) { std::string arg = argv[i]; @@ -323,6 +325,7 @@ class CLIParser { config.srv_config.is_also_client = true; } + connection_address_was_set = true; } else { @@ -687,11 +690,25 @@ class CLIParser } } - if (uses_ipv6 - && !listening_address_was_set - && config.entity == CLIParser::EntityKind::SERVER) + // change default values if IPv6 is used + // and user did not specified ones + if (uses_ipv6) { - config.srv_config.listening_address = "::1"; + if (config.entity == CLIParser::EntityKind::SERVER && + !listening_address_was_set) + { + config.srv_config.listening_address = "::1"; + } + + if (!connection_address_was_set) + { + config.pub_config.connection_address = "::1"; + config.sub_config.connection_address = "::1"; + if (config.srv_config.is_also_client) + { + config.srv_config.connection_address = "::1"; + } + } } return config; diff --git a/examples/cpp/discovery_server/ClientPublisherApp.cpp b/examples/cpp/discovery_server/ClientPublisherApp.cpp index 1643aab8d4d..2d917fe0ece 100644 --- a/examples/cpp/discovery_server/ClientPublisherApp.cpp +++ b/examples/cpp/discovery_server/ClientPublisherApp.cpp @@ -115,8 +115,6 @@ ClientPublisherApp::ClientPublisherApp( case TransportKind::TCPv4: { auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); - // One listening port must be added either in the pub or the sub descriptor_tmp->add_listener_port(0); descriptor = descriptor_tmp; @@ -129,8 +127,6 @@ ClientPublisherApp::ClientPublisherApp( case TransportKind::TCPv6: { auto descriptor_tmp = std::make_shared(); - // descriptor_tmp->interfaceWhiteList.push_back(ip_server_address); - // One listening port must be added either in the pub or the sub descriptor_tmp->add_listener_port(0); descriptor = descriptor_tmp; diff --git a/test/examples/test_discovery_server.py b/test/examples/test_discovery_server.py index 2614aa1739a..278190d86fa 100644 --- a/test/examples/test_discovery_server.py +++ b/test/examples/test_discovery_server.py @@ -10,7 +10,10 @@ ('--connection-port 11500 --samples 10', '--connection-port 11500 --samples 10', '--listening-port 11500 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), ('--transport tcpv4 --samples 10', '--transport tcpv4 --samples 10', '--transport tcpv4 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), ('--connection-ds-id 1 --samples 10', '--connection-ds-id 1 --samples 10', '--id 1 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), - ('--connection-ds-id 1 --samples 10', '--connection-ds-id 2 --connection-port 11400 --samples 10', '--id 1 --timeout 5 --connection-ds-id 2 --connection-port 11400', '--id 2 --listening-port 11400 --timeout 5') + ('--connection-ds-id 1 --samples 10', '--connection-ds-id 2 --connection-port 11400 --samples 10', '--id 1 --timeout 5 --connection-ds-id 2 --connection-port 11400', '--id 2 --listening-port 11400 --timeout 5'), + ('--transport udpv6 --connection-ds-id 1 --samples 10', '--transport udpv6 --connection-ds-id 2 --connection-port 18000 --samples 10', '--transport udpv6 --id 1 --timeout 5 --connection-ds-id 2 --connection-port 18000', '--transport udpv6 --id 2 --listening-port 18000 --timeout 5'), + ('--transport tcpv4 --connection-ds-id 1 --samples 10', '--transport tcpv4 --connection-ds-id 2 --connection-port 18000 --samples 10', '--transport tcpv4 --id 1 --timeout 5 --connection-ds-id 2 --connection-port 18000', '--transport tcpv4 --id 2 --listening-port 18000 --timeout 5'), + ('--transport tcpv6 --connection-ds-id 1 --samples 10', '--transport tcpv6 --connection-ds-id 2 --connection-port 18000 --samples 10', '--transport tcpv6 --id 1 --timeout 5 --connection-ds-id 2 --connection-port 18000', '--transport tcpv6 --id 2 --listening-port 18000 --timeout 5') ] @pytest.mark.parametrize("pub_args, sub_args, server1_args, server2_args", discovery_server_test_cases) From e6b32004adae9dbe05d1640cbd8d934e74910a4f Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Wed, 12 Jun 2024 16:03:30 +0200 Subject: [PATCH 11/18] Refs #21095: Only change datawriter reliability when reliable is false Signed-off-by: Mario Dominguez --- examples/cpp/discovery_server/CLIParser.hpp | 2 +- examples/cpp/discovery_server/ClientPublisherApp.cpp | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/examples/cpp/discovery_server/CLIParser.hpp b/examples/cpp/discovery_server/CLIParser.hpp index e18393117ab..3c3345769e3 100644 --- a/examples/cpp/discovery_server/CLIParser.hpp +++ b/examples/cpp/discovery_server/CLIParser.hpp @@ -176,7 +176,7 @@ class CLIParser std::cout << " -t , --topic Topic name" << std::endl; std::cout << " (Default: discovery_server_topic)." << std::endl; std::cout << " -r, --reliable Set Reliability QoS as reliable" << std::endl; - std::cout << " (Default: 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 << " -s , --samples Number of samples to send " << std::endl; diff --git a/examples/cpp/discovery_server/ClientPublisherApp.cpp b/examples/cpp/discovery_server/ClientPublisherApp.cpp index 2d917fe0ece..75742960c85 100644 --- a/examples/cpp/discovery_server/ClientPublisherApp.cpp +++ b/examples/cpp/discovery_server/ClientPublisherApp.cpp @@ -194,11 +194,7 @@ ClientPublisherApp::ClientPublisherApp( // Create de data writer DataWriterQos wqos = DATAWRITER_QOS_DEFAULT; - if (config.reliable) - { - wqos.reliability().kind = RELIABLE_RELIABILITY_QOS; - } - else + if (!config.reliable) { wqos.reliability().kind = BEST_EFFORT_RELIABILITY_QOS; } From 3ed3a269f7af4a8e027049eca2d9faa2b05e59b3 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 18 Jun 2024 09:56:04 +0200 Subject: [PATCH 12/18] Refs #21095: Avoid using connection_ds option for the example. Although it is left for configurability Signed-off-by: Mario Dominguez --- .../cpp/discovery_server/ClientPublisherApp.cpp | 10 +--------- .../cpp/discovery_server/ClientSubscriberApp.cpp | 10 +--------- examples/cpp/discovery_server/ServerApp.cpp | 10 +--------- test/examples/test_discovery_server.py | 16 ++++++++-------- 4 files changed, 11 insertions(+), 35 deletions(-) diff --git a/examples/cpp/discovery_server/ClientPublisherApp.cpp b/examples/cpp/discovery_server/ClientPublisherApp.cpp index 75742960c85..466e0fdd190 100644 --- a/examples/cpp/discovery_server/ClientPublisherApp.cpp +++ b/examples/cpp/discovery_server/ClientPublisherApp.cpp @@ -144,15 +144,8 @@ ClientPublisherApp::ClientPublisherApp( pqos.wire_protocol().builtin.discovery_config.discoveryProtocol = eprosima::fastrtps::rtps::DiscoveryProtocol_t::CLIENT; - // Set SERVER's GUID prefix - rtps::RemoteServerAttributes remote_server_att; - remote_server_att.guidPrefix = get_discovery_server_guid_from_id(config.connection_ds_id); - - // Set SERVER's listening locator for PDP - remote_server_att.metatrafficUnicastLocatorList.push_back(server_locator); - // Add remote SERVER to CLIENT's list of SERVERs - pqos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(remote_server_att); + pqos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(server_locator); // Add descriptor pqos.transport().user_transports.push_back(descriptor); @@ -169,7 +162,6 @@ ClientPublisherApp::ClientPublisherApp( "Publisher Participant " << pqos.name() << " created with GUID " << participant_->guid() << " connecting to server <" << server_locator << "> " << - " with Guid: <" << remote_server_att.guidPrefix << "> " << std::endl; // Regsiter type diff --git a/examples/cpp/discovery_server/ClientSubscriberApp.cpp b/examples/cpp/discovery_server/ClientSubscriberApp.cpp index 61bbad11ea9..f75ab6d79ba 100644 --- a/examples/cpp/discovery_server/ClientSubscriberApp.cpp +++ b/examples/cpp/discovery_server/ClientSubscriberApp.cpp @@ -146,15 +146,8 @@ ClientSubscriberApp::ClientSubscriberApp( pqos.wire_protocol().builtin.discovery_config.discoveryProtocol = eprosima::fastrtps::rtps::DiscoveryProtocol_t::CLIENT; - // Set SERVER's GUID prefix - rtps::RemoteServerAttributes remote_server_att; - remote_server_att.guidPrefix = get_discovery_server_guid_from_id(config.connection_ds_id); - - // Set SERVER's listening locator for PDP - remote_server_att.metatrafficUnicastLocatorList.push_back(server_locator); - // Add remote SERVER to CLIENT's list of SERVERs - pqos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(remote_server_att); + pqos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(server_locator); // Add descriptor pqos.transport().user_transports.push_back(descriptor); @@ -172,7 +165,6 @@ ClientSubscriberApp::ClientSubscriberApp( "Subscriber Participant " << pqos.name() << " created with GUID " << participant_->guid() << " connecting to server <" << server_locator << "> " << - " with Guid: <" << remote_server_att.guidPrefix << "> " << std::endl; // Register the type diff --git a/examples/cpp/discovery_server/ServerApp.cpp b/examples/cpp/discovery_server/ServerApp.cpp index e76c6f88260..ec70ba1b7ca 100644 --- a/examples/cpp/discovery_server/ServerApp.cpp +++ b/examples/cpp/discovery_server/ServerApp.cpp @@ -165,17 +165,10 @@ ServerApp::ServerApp( pqos.wire_protocol().builtin.metatrafficUnicastLocatorList.push_back(listening_locator); // Configure Connection address - rtps::RemoteServerAttributes remote_server_att; if (config.is_also_client) { - // Set SERVER's GUID prefix - remote_server_att.guidPrefix = get_discovery_server_guid_from_id(config.connection_ds_id); - - // Set SERVER's listening locator for PDP - remote_server_att.metatrafficUnicastLocatorList.push_back(connection_locator); - // Add remote SERVER to CLIENT's list of SERVERs - pqos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(remote_server_att); + pqos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(connection_locator); } @@ -193,7 +186,6 @@ ServerApp::ServerApp( "Server Participant " << pqos.name() << " created with GUID " << participant_->guid() << " listening in address <" << listening_locator << "> " << - " connecting with Discovery Server <" << remote_server_att.guidPrefix << "> " " with address <" << connection_locator << "> " << std::endl; } diff --git a/test/examples/test_discovery_server.py b/test/examples/test_discovery_server.py index 278190d86fa..7fad43811ed 100644 --- a/test/examples/test_discovery_server.py +++ b/test/examples/test_discovery_server.py @@ -6,14 +6,14 @@ Each element is a ternary (pub_args, sub_args, server_args) """ discovery_server_test_cases = [ - ('--samples 10', '--samples 10', '--timeout 5', '--id 2 --listening-port 11400 --timeout 1'), - ('--connection-port 11500 --samples 10', '--connection-port 11500 --samples 10', '--listening-port 11500 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), - ('--transport tcpv4 --samples 10', '--transport tcpv4 --samples 10', '--transport tcpv4 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), - ('--connection-ds-id 1 --samples 10', '--connection-ds-id 1 --samples 10', '--id 1 --timeout 5', '--id 2 --listening-port 11400 --timeout 1'), - ('--connection-ds-id 1 --samples 10', '--connection-ds-id 2 --connection-port 11400 --samples 10', '--id 1 --timeout 5 --connection-ds-id 2 --connection-port 11400', '--id 2 --listening-port 11400 --timeout 5'), - ('--transport udpv6 --connection-ds-id 1 --samples 10', '--transport udpv6 --connection-ds-id 2 --connection-port 18000 --samples 10', '--transport udpv6 --id 1 --timeout 5 --connection-ds-id 2 --connection-port 18000', '--transport udpv6 --id 2 --listening-port 18000 --timeout 5'), - ('--transport tcpv4 --connection-ds-id 1 --samples 10', '--transport tcpv4 --connection-ds-id 2 --connection-port 18000 --samples 10', '--transport tcpv4 --id 1 --timeout 5 --connection-ds-id 2 --connection-port 18000', '--transport tcpv4 --id 2 --listening-port 18000 --timeout 5'), - ('--transport tcpv6 --connection-ds-id 1 --samples 10', '--transport tcpv6 --connection-ds-id 2 --connection-port 18000 --samples 10', '--transport tcpv6 --id 1 --timeout 5 --connection-ds-id 2 --connection-port 18000', '--transport tcpv6 --id 2 --listening-port 18000 --timeout 5') + ('--samples 10', '--samples 10', '--timeout 5', '--listening-port 11400 --timeout 1'), + ('--connection-port 11500 --samples 10', '--connection-port 11500 --samples 10', '--listening-port 11500 --timeout 5', '--listening-port 11400 --timeout 1'), + ('--transport tcpv4 --samples 10', '--transport tcpv4 --samples 10', '--transport tcpv4 --timeout 5', '--listening-port 11400 --timeout 1'), + ('--samples 10', '--samples 10', '--timeout 5', '--listening-port 11400 --timeout 1'), + ('--samples 10', '--connection-port 11400 --samples 10', '--timeout 5 --connection-port 11400', '--listening-port 11400 --timeout 5'), + ('--transport udpv6 --samples 10', '--transport udpv6 --connection-port 18000 --samples 10', '--transport udpv6 --timeout 5 --connection-port 18000', '--transport udpv6 --listening-port 18000 --timeout 5'), + ('--transport tcpv4 --samples 10', '--transport tcpv4 --connection-port 18000 --samples 10', '--transport tcpv4 --timeout 5 --connection-port 18000', '--transport tcpv4 --listening-port 18000 --timeout 5'), + ('--transport tcpv6 --samples 10', '--transport tcpv6 --connection-port 18000 --samples 10', '--transport tcpv6 --timeout 5 --connection-port 18000', '--transport tcpv6 --listening-port 18000 --timeout 5') ] @pytest.mark.parametrize("pub_args, sub_args, server1_args, server2_args", discovery_server_test_cases) From 55ae6aba8d06592d9164947b59a0a58fa2bb7501 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 18 Jun 2024 09:57:30 +0200 Subject: [PATCH 13/18] Refs #21095: Add license Signed-off-by: Mario Dominguez --- test/examples/discovery_server.compose.yml | 14 ++++++++++++++ test/examples/test_discovery_server.py | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/test/examples/discovery_server.compose.yml b/test/examples/discovery_server.compose.yml index bdba0e291d1..127e034b336 100644 --- a/test/examples/discovery_server.compose.yml +++ b/test/examples/discovery_server.compose.yml @@ -1,3 +1,17 @@ +# Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + version: "3" services: diff --git a/test/examples/test_discovery_server.py b/test/examples/test_discovery_server.py index 7fad43811ed..2a1167f4d1c 100644 --- a/test/examples/test_discovery_server.py +++ b/test/examples/test_discovery_server.py @@ -1,3 +1,17 @@ +# Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import subprocess import pytest From 273b82110d6f576b389d90eeca7a847f6c7dfd2a Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 18 Jun 2024 16:06:36 +0200 Subject: [PATCH 14/18] Refs #21095: Remove -id- since it is no longer needed Signed-off-by: Mario Dominguez --- examples/cpp/discovery_server/CLIParser.hpp | 90 --------------------- examples/cpp/discovery_server/ServerApp.cpp | 5 +- 2 files changed, 1 insertion(+), 94 deletions(-) diff --git a/examples/cpp/discovery_server/CLIParser.hpp b/examples/cpp/discovery_server/CLIParser.hpp index 3c3345769e3..d24c048b21c 100644 --- a/examples/cpp/discovery_server/CLIParser.hpp +++ b/examples/cpp/discovery_server/CLIParser.hpp @@ -54,7 +54,6 @@ class CLIParser struct client_config { uint16_t connection_port{16166}; - uint16_t connection_ds_id{0}; std::string connection_address{"127.0.0.1"}; }; @@ -87,7 +86,6 @@ class CLIParser bool is_also_client{false}; TransportKind transport_kind{TransportKind::UDPv4}; uint16_t listening_port{16166}; - uint16_t id{0}; uint16_t timeout{0}; std::string listening_address{"127.0.0.1"}; }; @@ -114,7 +112,6 @@ class CLIParser os << "Client options:" << std::endl; os << " Connection address: " << config.pub_config.connection_address << std::endl; os << " Connection port: " << config.pub_config.connection_port << std::endl; - os << " Connection DS id: " << config.pub_config.connection_ds_id << std::endl; } if (config.entity == CLIParser::EntityKind::CLIENT_PUBLISHER) @@ -135,7 +132,6 @@ class CLIParser os << "Server options:" << std::endl; os << " Listening address: " << config.srv_config.listening_address << std::endl; os << " Listening port: " << config.srv_config.listening_port << std::endl; - os << " Id: " << config.srv_config.id << std::endl; os << " Timeout: " << config.srv_config.timeout << std::endl; } @@ -167,7 +163,6 @@ class CLIParser std::cout << " (Default address: 127.0.0.1)." << std::endl; std::cout << " -p , --connection-port Port of the Server to connect to" << std::endl; std::cout << " (Default port: 16166)." << std::endl; - std::cout << " --connection-ds-id Id of the Discovery Server to connect to" << std::endl; std::cout << " (0 by default)." << std::endl; std::cout << " --transport [udpv4|udpv6|tcpv4|tcpv6|shm] " << std::endl; std::cout << " (udpv4 by default)." << std::endl; @@ -199,7 +194,6 @@ class CLIParser std::cout << " (Default address: 127.0.0.1)" << std::endl; std::cout << " --listening-port Server listening port" << std::endl; std::cout << " (Default port: 16166)" << std::endl; - std::cout << " --id Id of the Discovery Server (Default: 0)." << std::endl; std::cout << " --timeout Number of seconds before finish" << std::endl; std::cout << " the process (Default: 0 = till ^C)." << std::endl; std::exit(return_code); @@ -375,47 +369,6 @@ class CLIParser print_help(EXIT_FAILURE); } } - else if (arg == "--connection-ds-id") - { - if (++i < argc) - { - try - { - int input = std::stoi(argv[i]); - if (input < 0 || input > 255) - { - throw std::out_of_range("connection-ds-id argument " + std::string( - argv[i]) + " out of range [0, 255]."); - } - else - { - config.pub_config.connection_ds_id = static_cast(input); - config.sub_config.connection_ds_id = static_cast(input); - config.srv_config.connection_ds_id = static_cast(input); - if (config.entity == CLIParser::EntityKind::SERVER) - { - config.srv_config.is_also_client = true; - } - } - } - catch (const std::invalid_argument& e) - { - EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid connection-ds-id 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 connection-ds-id argument"); - print_help(EXIT_FAILURE); - } - } // PubSub options else if (arg == "-t" || arg == "--topic") { @@ -596,49 +549,6 @@ class CLIParser print_help(EXIT_FAILURE); } } - else if (arg == "--id") - { - if (++i < argc) - { - if (config.entity == CLIParser::EntityKind::SERVER) - { - try - { - int input = std::stoi(argv[i]); - if (input < 0 || input > 255) - { - throw std::out_of_range("id argument " + std::string( - argv[i]) + " out of range [0, 255]."); - } - else - { - config.srv_config.id = static_cast(input); - } - } - catch (const std::invalid_argument& e) - { - EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid id 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, "--listening-port argument is only valid for server entity"); - print_help(EXIT_FAILURE); - } - } - else - { - EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing id argument"); - print_help(EXIT_FAILURE); - } - } else if (arg == "--timeout") { if (++i < argc) diff --git a/examples/cpp/discovery_server/ServerApp.cpp b/examples/cpp/discovery_server/ServerApp.cpp index ec70ba1b7ca..53c8eedbad2 100644 --- a/examples/cpp/discovery_server/ServerApp.cpp +++ b/examples/cpp/discovery_server/ServerApp.cpp @@ -158,9 +158,6 @@ ServerApp::ServerApp( pqos.wire_protocol().builtin.discovery_config.discoveryProtocol = eprosima::fastrtps::rtps::DiscoveryProtocol_t::SERVER; - // Set SERVER's GUID prefix - pqos.wire_protocol().prefix = get_discovery_server_guid_from_id(config.id); - // Set SERVER's listening locator for PDP pqos.wire_protocol().builtin.metatrafficUnicastLocatorList.push_back(listening_locator); @@ -186,7 +183,7 @@ ServerApp::ServerApp( "Server Participant " << pqos.name() << " created with GUID " << participant_->guid() << " listening in address <" << listening_locator << "> " << - " with address <" << connection_locator << "> " << + " connected to address <" << connection_locator << "> " << std::endl; } else From 709ac36970b64bd8512f881c8a7b70024fecaedb Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Thu, 20 Jun 2024 09:46:07 +0200 Subject: [PATCH 15/18] Refs #21095: Move namespace to fastdds Signed-off-by: Mario Dominguez --- .../discovery_server/ClientPublisherApp.cpp | 16 ++++---- .../discovery_server/ClientSubscriberApp.cpp | 16 ++++---- .../HelloWorldPubSubTypes.cxx | 4 +- .../discovery_server/HelloWorldPubSubTypes.h | 8 ++-- examples/cpp/discovery_server/Helpers.hpp | 10 ++--- examples/cpp/discovery_server/ServerApp.cpp | 38 +++++++++---------- examples/cpp/discovery_server/ServerApp.hpp | 2 +- 7 files changed, 47 insertions(+), 47 deletions(-) diff --git a/examples/cpp/discovery_server/ClientPublisherApp.cpp b/examples/cpp/discovery_server/ClientPublisherApp.cpp index 466e0fdd190..4a125771cf5 100644 --- a/examples/cpp/discovery_server/ClientPublisherApp.cpp +++ b/examples/cpp/discovery_server/ClientPublisherApp.cpp @@ -79,7 +79,7 @@ ClientPublisherApp::ClientPublisherApp( // Create DS locator eprosima::fastdds::rtps::Locator server_locator; - eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(server_locator, server_port); + eprosima::fastdds::rtps::IPLocator::setPhysicalPort(server_locator, server_port); std::shared_ptr descriptor; @@ -97,7 +97,7 @@ ClientPublisherApp::ClientPublisherApp( descriptor = descriptor_tmp; server_locator.kind = LOCATOR_KIND_UDPv4; - eprosima::fastrtps::rtps::IPLocator::setIPv4(server_locator, ip_server_address); + eprosima::fastdds::rtps::IPLocator::setIPv4(server_locator, ip_server_address); break; } @@ -108,7 +108,7 @@ ClientPublisherApp::ClientPublisherApp( descriptor = descriptor_tmp; server_locator.kind = LOCATOR_KIND_UDPv6; - eprosima::fastrtps::rtps::IPLocator::setIPv6(server_locator, ip_server_address); + eprosima::fastdds::rtps::IPLocator::setIPv6(server_locator, ip_server_address); break; } @@ -119,8 +119,8 @@ ClientPublisherApp::ClientPublisherApp( descriptor = descriptor_tmp; server_locator.kind = LOCATOR_KIND_TCPv4; - eprosima::fastrtps::rtps::IPLocator::setLogicalPort(server_locator, server_port); - eprosima::fastrtps::rtps::IPLocator::setIPv4(server_locator, ip_server_address); + eprosima::fastdds::rtps::IPLocator::setLogicalPort(server_locator, server_port); + eprosima::fastdds::rtps::IPLocator::setIPv4(server_locator, ip_server_address); break; } @@ -131,8 +131,8 @@ ClientPublisherApp::ClientPublisherApp( descriptor = descriptor_tmp; server_locator.kind = LOCATOR_KIND_TCPv6; - eprosima::fastrtps::rtps::IPLocator::setLogicalPort(server_locator, server_port); - eprosima::fastrtps::rtps::IPLocator::setIPv6(server_locator, ip_server_address); + eprosima::fastdds::rtps::IPLocator::setLogicalPort(server_locator, server_port); + eprosima::fastdds::rtps::IPLocator::setIPv6(server_locator, ip_server_address); break; } @@ -142,7 +142,7 @@ ClientPublisherApp::ClientPublisherApp( // Set participant as DS CLIENT pqos.wire_protocol().builtin.discovery_config.discoveryProtocol = - eprosima::fastrtps::rtps::DiscoveryProtocol_t::CLIENT; + eprosima::fastdds::rtps::DiscoveryProtocol::CLIENT; // Add remote SERVER to CLIENT's list of SERVERs pqos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(server_locator); diff --git a/examples/cpp/discovery_server/ClientSubscriberApp.cpp b/examples/cpp/discovery_server/ClientSubscriberApp.cpp index f75ab6d79ba..8f50af191a1 100644 --- a/examples/cpp/discovery_server/ClientSubscriberApp.cpp +++ b/examples/cpp/discovery_server/ClientSubscriberApp.cpp @@ -77,7 +77,7 @@ ClientSubscriberApp::ClientSubscriberApp( // Create DS SERVER locator eprosima::fastdds::rtps::Locator server_locator; - eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(server_locator, server_port); + eprosima::fastdds::rtps::IPLocator::setPhysicalPort(server_locator, server_port); std::shared_ptr descriptor; @@ -95,7 +95,7 @@ ClientSubscriberApp::ClientSubscriberApp( descriptor = descriptor_tmp; server_locator.kind = LOCATOR_KIND_UDPv4; - eprosima::fastrtps::rtps::IPLocator::setIPv4(server_locator, ip_server_address); + eprosima::fastdds::rtps::IPLocator::setIPv4(server_locator, ip_server_address); break; } @@ -106,7 +106,7 @@ ClientSubscriberApp::ClientSubscriberApp( descriptor = descriptor_tmp; server_locator.kind = LOCATOR_KIND_UDPv6; - eprosima::fastrtps::rtps::IPLocator::setIPv6(server_locator, ip_server_address); + eprosima::fastdds::rtps::IPLocator::setIPv6(server_locator, ip_server_address); break; } @@ -119,8 +119,8 @@ ClientSubscriberApp::ClientSubscriberApp( descriptor = descriptor_tmp; server_locator.kind = LOCATOR_KIND_TCPv4; - eprosima::fastrtps::rtps::IPLocator::setLogicalPort(server_locator, server_port); - eprosima::fastrtps::rtps::IPLocator::setIPv4(server_locator, ip_server_address); + eprosima::fastdds::rtps::IPLocator::setLogicalPort(server_locator, server_port); + eprosima::fastdds::rtps::IPLocator::setIPv4(server_locator, ip_server_address); break; } @@ -133,8 +133,8 @@ ClientSubscriberApp::ClientSubscriberApp( descriptor = descriptor_tmp; server_locator.kind = LOCATOR_KIND_TCPv6; - eprosima::fastrtps::rtps::IPLocator::setLogicalPort(server_locator, server_port); - eprosima::fastrtps::rtps::IPLocator::setIPv6(server_locator, ip_server_address); + eprosima::fastdds::rtps::IPLocator::setLogicalPort(server_locator, server_port); + eprosima::fastdds::rtps::IPLocator::setIPv6(server_locator, ip_server_address); break; } @@ -144,7 +144,7 @@ ClientSubscriberApp::ClientSubscriberApp( // Set participant as DS CLIENT pqos.wire_protocol().builtin.discovery_config.discoveryProtocol = - eprosima::fastrtps::rtps::DiscoveryProtocol_t::CLIENT; + eprosima::fastdds::rtps::DiscoveryProtocol::CLIENT; // Add remote SERVER to CLIENT's list of SERVERs pqos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(server_locator); diff --git a/examples/cpp/discovery_server/HelloWorldPubSubTypes.cxx b/examples/cpp/discovery_server/HelloWorldPubSubTypes.cxx index aa161b2e163..a73cf0ffa55 100644 --- a/examples/cpp/discovery_server/HelloWorldPubSubTypes.cxx +++ b/examples/cpp/discovery_server/HelloWorldPubSubTypes.cxx @@ -27,8 +27,8 @@ #include "HelloWorldCdrAux.hpp" #include "HelloWorldTypeObjectSupport.hpp" -using SerializedPayload_t = eprosima::fastrtps::rtps::SerializedPayload_t; -using InstanceHandle_t = eprosima::fastrtps::rtps::InstanceHandle_t; +using SerializedPayload_t = eprosima::fastdds::rtps::SerializedPayload_t; +using InstanceHandle_t = eprosima::fastdds::rtps::InstanceHandle_t; using DataRepresentationId_t = eprosima::fastdds::dds::DataRepresentationId_t; HelloWorldPubSubType::HelloWorldPubSubType() diff --git a/examples/cpp/discovery_server/HelloWorldPubSubTypes.h b/examples/cpp/discovery_server/HelloWorldPubSubTypes.h index 7c83d2b300b..f048c9be28e 100644 --- a/examples/cpp/discovery_server/HelloWorldPubSubTypes.h +++ b/examples/cpp/discovery_server/HelloWorldPubSubTypes.h @@ -54,18 +54,18 @@ class HelloWorldPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport bool serialize( void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload) override + eprosima::fastdds::rtps::SerializedPayload_t* payload) override { return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); } eProsima_user_DllExport bool serialize( void* data, - eprosima::fastrtps::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::SerializedPayload_t* payload, eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; eProsima_user_DllExport bool deserialize( - eprosima::fastrtps::rtps::SerializedPayload_t* payload, + eprosima::fastdds::rtps::SerializedPayload_t* payload, void* data) override; eProsima_user_DllExport std::function getSerializedSizeProvider( @@ -80,7 +80,7 @@ class HelloWorldPubSubType : public eprosima::fastdds::dds::TopicDataType eProsima_user_DllExport bool getKey( void* data, - eprosima::fastrtps::rtps::InstanceHandle_t* ihandle, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; eProsima_user_DllExport void* createData() override; diff --git a/examples/cpp/discovery_server/Helpers.hpp b/examples/cpp/discovery_server/Helpers.hpp index 3b602e640f1..fdbe4328192 100644 --- a/examples/cpp/discovery_server/Helpers.hpp +++ b/examples/cpp/discovery_server/Helpers.hpp @@ -33,15 +33,15 @@ enum class TransportKind : uint8_t SHM, }; -inline eprosima::fastrtps::rtps::GuidPrefix_t get_discovery_server_guid_from_id( +inline eprosima::fastdds::rtps::GuidPrefix_t get_discovery_server_guid_from_id( unsigned short id) { - eprosima::fastrtps::rtps::GuidPrefix_t result; + eprosima::fastdds::rtps::GuidPrefix_t result; // Get default DS guid and modify the one value expected to be changed std::istringstream(eprosima::fastdds::rtps::DEFAULT_ROS2_SERVER_GUIDPREFIX) >> result; result.value[2] = - static_cast(id); // This is done like this in Fast + static_cast(id); // This is done like this in Fast return result; } @@ -49,7 +49,7 @@ inline eprosima::fastrtps::rtps::GuidPrefix_t get_discovery_server_guid_from_id( inline bool is_ip( const std::string ip_str) { - return eprosima::fastrtps::rtps::IPLocator::isIPv4(ip_str) || eprosima::fastrtps::rtps::IPLocator::isIPv6(ip_str); + return eprosima::fastdds::rtps::IPLocator::isIPv4(ip_str) || eprosima::fastdds::rtps::IPLocator::isIPv6(ip_str); } inline std::string get_ip_from_dns( @@ -57,7 +57,7 @@ inline std::string get_ip_from_dns( TransportKind kind) { std::pair, std::set> dns_response = - eprosima::fastrtps::rtps::IPLocator::resolveNameDNS(domain_name); + eprosima::fastdds::rtps::IPLocator::resolveNameDNS(domain_name); if (kind == TransportKind::UDPv4 || kind == TransportKind::TCPv4) { diff --git a/examples/cpp/discovery_server/ServerApp.cpp b/examples/cpp/discovery_server/ServerApp.cpp index 53c8eedbad2..e6fced2ce83 100644 --- a/examples/cpp/discovery_server/ServerApp.cpp +++ b/examples/cpp/discovery_server/ServerApp.cpp @@ -80,8 +80,8 @@ ServerApp::ServerApp( // Create DS SERVER locator eprosima::fastdds::rtps::Locator listening_locator; eprosima::fastdds::rtps::Locator connection_locator; - eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(listening_locator, config.listening_port); - eprosima::fastrtps::rtps::IPLocator::setPhysicalPort(connection_locator, config.connection_port); + eprosima::fastdds::rtps::IPLocator::setPhysicalPort(listening_locator, config.listening_port); + eprosima::fastdds::rtps::IPLocator::setPhysicalPort(connection_locator, config.connection_port); std::shared_ptr descriptor; @@ -99,9 +99,9 @@ ServerApp::ServerApp( descriptor = descriptor_tmp; listening_locator.kind = LOCATOR_KIND_UDPv4; - eprosima::fastrtps::rtps::IPLocator::setIPv4(listening_locator, ip_listening_address); + eprosima::fastdds::rtps::IPLocator::setIPv4(listening_locator, ip_listening_address); connection_locator.kind = LOCATOR_KIND_UDPv4; - eprosima::fastrtps::rtps::IPLocator::setIPv4(connection_locator, ip_connection_address); + eprosima::fastdds::rtps::IPLocator::setIPv4(connection_locator, ip_connection_address); break; } @@ -111,9 +111,9 @@ ServerApp::ServerApp( descriptor = descriptor_tmp; listening_locator.kind = LOCATOR_KIND_UDPv6; - eprosima::fastrtps::rtps::IPLocator::setIPv6(listening_locator, ip_listening_address); + eprosima::fastdds::rtps::IPLocator::setIPv6(listening_locator, ip_listening_address); connection_locator.kind = LOCATOR_KIND_UDPv6; - eprosima::fastrtps::rtps::IPLocator::setIPv6(connection_locator, ip_connection_address); + eprosima::fastdds::rtps::IPLocator::setIPv6(connection_locator, ip_connection_address); break; } @@ -124,11 +124,11 @@ ServerApp::ServerApp( descriptor = descriptor_tmp; listening_locator.kind = LOCATOR_KIND_TCPv4; - eprosima::fastrtps::rtps::IPLocator::setLogicalPort(listening_locator, config.listening_port); - eprosima::fastrtps::rtps::IPLocator::setIPv4(listening_locator, ip_listening_address); + eprosima::fastdds::rtps::IPLocator::setLogicalPort(listening_locator, config.listening_port); + eprosima::fastdds::rtps::IPLocator::setIPv4(listening_locator, ip_listening_address); connection_locator.kind = LOCATOR_KIND_TCPv4; - eprosima::fastrtps::rtps::IPLocator::setIPv4(connection_locator, ip_connection_address); - eprosima::fastrtps::rtps::IPLocator::setLogicalPort(connection_locator, config.connection_port); + eprosima::fastdds::rtps::IPLocator::setIPv4(connection_locator, ip_connection_address); + eprosima::fastdds::rtps::IPLocator::setLogicalPort(connection_locator, config.connection_port); break; } @@ -139,11 +139,11 @@ ServerApp::ServerApp( descriptor = descriptor_tmp; listening_locator.kind = LOCATOR_KIND_TCPv6; - eprosima::fastrtps::rtps::IPLocator::setLogicalPort(listening_locator, config.listening_port); - eprosima::fastrtps::rtps::IPLocator::setIPv6(listening_locator, ip_listening_address); + eprosima::fastdds::rtps::IPLocator::setLogicalPort(listening_locator, config.listening_port); + eprosima::fastdds::rtps::IPLocator::setIPv6(listening_locator, ip_listening_address); connection_locator.kind = LOCATOR_KIND_TCPv6; - eprosima::fastrtps::rtps::IPLocator::setIPv6(connection_locator, ip_connection_address); - eprosima::fastrtps::rtps::IPLocator::setLogicalPort(connection_locator, config.connection_port); + eprosima::fastdds::rtps::IPLocator::setIPv6(connection_locator, ip_connection_address); + eprosima::fastdds::rtps::IPLocator::setLogicalPort(connection_locator, config.connection_port); break; } @@ -156,7 +156,7 @@ ServerApp::ServerApp( // Set participant as SERVER pqos.wire_protocol().builtin.discovery_config.discoveryProtocol = - eprosima::fastrtps::rtps::DiscoveryProtocol_t::SERVER; + eprosima::fastdds::rtps::DiscoveryProtocol::SERVER; // Set SERVER's listening locator for PDP pqos.wire_protocol().builtin.metatrafficUnicastLocatorList.push_back(listening_locator); @@ -210,17 +210,17 @@ ServerApp::~ServerApp() void ServerApp::on_participant_discovery( DomainParticipant*, - fastrtps::rtps::ParticipantDiscoveryInfo&& info, + fastdds::rtps::ParticipantDiscoveryInfo&& info, bool& should_be_ignored) { static_cast(should_be_ignored); - if (info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT) + if (info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT) { std::cout << "Discovered Participant with GUID " << info.info.m_guid << std::endl; ++matched_; } - else if (info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT || - info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT) + else if (info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT || + info.status == eprosima::fastdds::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT) { std::cout << "Dropped Participant with GUID " << info.info.m_guid << std::endl; --matched_; diff --git a/examples/cpp/discovery_server/ServerApp.hpp b/examples/cpp/discovery_server/ServerApp.hpp index 54d7b52438f..d0d1be4280c 100644 --- a/examples/cpp/discovery_server/ServerApp.hpp +++ b/examples/cpp/discovery_server/ServerApp.hpp @@ -49,7 +49,7 @@ class ServerApp : public Application, public DomainParticipantListener //! Publisher matched method void on_participant_discovery( DomainParticipant* participant, - fastrtps::rtps::ParticipantDiscoveryInfo&& info, + fastdds::rtps::ParticipantDiscoveryInfo&& info, bool& should_be_ignored) override; //! Run publisher From b87274d3897c53e5c2295599b6037e1065d78cdb Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Wed, 3 Jul 2024 08:55:46 +0200 Subject: [PATCH 16/18] Refs #21095: regenerate types Signed-off-by: Mario Dominguez --- examples/cpp/discovery_server/HelloWorld.hpp | 4 +- .../cpp/discovery_server/HelloWorldCdrAux.hpp | 6 +- .../cpp/discovery_server/HelloWorldCdrAux.ipp | 6 +- .../HelloWorldPubSubTypes.cxx | 14 +- .../HelloWorldPubSubTypes.hpp | 133 ++++++++++++++++++ .../HelloWorldTypeObjectSupport.hpp | 6 +- 6 files changed, 151 insertions(+), 18 deletions(-) create mode 100644 examples/cpp/discovery_server/HelloWorldPubSubTypes.hpp diff --git a/examples/cpp/discovery_server/HelloWorld.hpp b/examples/cpp/discovery_server/HelloWorld.hpp index 971fea8d920..46d0d7b5814 100644 --- a/examples/cpp/discovery_server/HelloWorld.hpp +++ b/examples/cpp/discovery_server/HelloWorld.hpp @@ -19,8 +19,8 @@ * This file was generated by the tool fastddsgen. */ -#ifndef _FAST_DDS_GENERATED_HELLOWORLD_HPP_ -#define _FAST_DDS_GENERATED_HELLOWORLD_HPP_ +#ifndef FAST_DDS_GENERATED__HELLOWORLD_HPP +#define FAST_DDS_GENERATED__HELLOWORLD_HPP #include #include diff --git a/examples/cpp/discovery_server/HelloWorldCdrAux.hpp b/examples/cpp/discovery_server/HelloWorldCdrAux.hpp index 6feb8a9da15..1164cd5cce1 100644 --- a/examples/cpp/discovery_server/HelloWorldCdrAux.hpp +++ b/examples/cpp/discovery_server/HelloWorldCdrAux.hpp @@ -19,8 +19,8 @@ * This file was generated by the tool fastddsgen. */ -#ifndef _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_HPP_ -#define _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_HPP_ +#ifndef FAST_DDS_GENERATED__HELLOWORLDCDRAUX_HPP +#define FAST_DDS_GENERATED__HELLOWORLDCDRAUX_HPP #include "HelloWorld.hpp" @@ -42,5 +42,5 @@ eProsima_user_DllExport void serialize_key( } // namespace fastcdr } // namespace eprosima -#endif // _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_HPP_ +#endif // FAST_DDS_GENERATED__HELLOWORLDCDRAUX_HPP diff --git a/examples/cpp/discovery_server/HelloWorldCdrAux.ipp b/examples/cpp/discovery_server/HelloWorldCdrAux.ipp index 97df3fe9d9e..19316df7d3c 100644 --- a/examples/cpp/discovery_server/HelloWorldCdrAux.ipp +++ b/examples/cpp/discovery_server/HelloWorldCdrAux.ipp @@ -19,8 +19,8 @@ * This file was generated by the tool fastddsgen. */ -#ifndef _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_IPP_ -#define _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_IPP_ +#ifndef FAST_DDS_GENERATED__HELLOWORLDCDRAUX_IPP +#define FAST_DDS_GENERATED__HELLOWORLDCDRAUX_IPP #include "HelloWorldCdrAux.hpp" @@ -122,5 +122,5 @@ void serialize_key( } // namespace fastcdr } // namespace eprosima -#endif // _FAST_DDS_GENERATED_HELLOWORLDCDRAUX_IPP_ +#endif // FAST_DDS_GENERATED__HELLOWORLDCDRAUX_IPP diff --git a/examples/cpp/discovery_server/HelloWorldPubSubTypes.cxx b/examples/cpp/discovery_server/HelloWorldPubSubTypes.cxx index a73cf0ffa55..38393dbf8c9 100644 --- a/examples/cpp/discovery_server/HelloWorldPubSubTypes.cxx +++ b/examples/cpp/discovery_server/HelloWorldPubSubTypes.cxx @@ -19,7 +19,7 @@ * This file was generated by the tool fastddsgen. */ -#include "HelloWorldPubSubTypes.h" +#include "HelloWorldPubSubTypes.hpp" #include #include @@ -57,11 +57,11 @@ HelloWorldPubSubType::~HelloWorldPubSubType() } bool HelloWorldPubSubType::serialize( - void* data, + const void* const data, SerializedPayload_t* payload, DataRepresentationId_t data_representation) { - HelloWorld* p_type = static_cast(data); + const HelloWorld* p_type = static_cast(data); // Object that manages the raw buffer. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(payload->data), payload->max_size); @@ -133,7 +133,7 @@ bool HelloWorldPubSubType::deserialize( } std::function HelloWorldPubSubType::getSerializedSizeProvider( - void* data, + const void* const data, DataRepresentationId_t data_representation) { return [data, data_representation]() -> uint32_t @@ -150,7 +150,7 @@ std::function HelloWorldPubSubType::getSerializedSizeProvider( 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)) + + *static_cast(data), current_alignment)) + 4u /*encapsulation*/; } catch (eprosima::fastcdr::exception::Exception& /*exception*/) @@ -173,7 +173,7 @@ void HelloWorldPubSubType::deleteData( } bool HelloWorldPubSubType::getKey( - void* data, + const void* const data, InstanceHandle_t* handle, bool force_md5) { @@ -182,7 +182,7 @@ bool HelloWorldPubSubType::getKey( return false; } - HelloWorld* p_type = static_cast(data); + const HelloWorld* p_type = static_cast(data); // Object that manages the raw buffer. eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast(m_keyBuffer), diff --git a/examples/cpp/discovery_server/HelloWorldPubSubTypes.hpp b/examples/cpp/discovery_server/HelloWorldPubSubTypes.hpp new file mode 100644 index 00000000000..556d4c05ecf --- /dev/null +++ b/examples/cpp/discovery_server/HelloWorldPubSubTypes.hpp @@ -0,0 +1,133 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file HelloWorldPubSubTypes.hpp + * This header file contains the declaration of the serialization functions. + * + * This file was generated by the tool fastddsgen. + */ + + +#ifndef FAST_DDS_GENERATED__HELLOWORLD_PUBSUBTYPES_HPP +#define FAST_DDS_GENERATED__HELLOWORLD_PUBSUBTYPES_HPP + +#include +#include +#include +#include +#include + +#include "HelloWorld.hpp" + + +#if !defined(GEN_API_VER) || (GEN_API_VER != 2) +#error \ + Generated HelloWorld is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. +#endif // GEN_API_VER + + +/*! + * @brief This class represents the TopicDataType of the type HelloWorld defined by the user in the IDL file. + * @ingroup HelloWorld + */ +class HelloWorldPubSubType : public eprosima::fastdds::dds::TopicDataType +{ +public: + + typedef HelloWorld type; + + eProsima_user_DllExport HelloWorldPubSubType(); + + eProsima_user_DllExport ~HelloWorldPubSubType() override; + + eProsima_user_DllExport bool serialize( + const void* const data, + eprosima::fastdds::rtps::SerializedPayload_t* payload) override + { + return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + 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 std::function getSerializedSizeProvider( + const void* const data) override + { + return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); + } + + eProsima_user_DllExport std::function getSerializedSizeProvider( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + eProsima_user_DllExport bool getKey( + const void* const data, + eprosima::fastdds::rtps::InstanceHandle_t* ihandle, + bool force_md5 = false) override; + + eProsima_user_DllExport void* createData() override; + + eProsima_user_DllExport void deleteData( + void* data) override; + + //Register TypeObject representation in Fast DDS TypeObjectRegistry + eProsima_user_DllExport void register_type_object_representation() override; + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + eProsima_user_DllExport inline bool is_bounded() const override + { + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED + +#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + eProsima_user_DllExport inline bool is_plain() const override + { + return false; + } + + eProsima_user_DllExport inline bool is_plain( + eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override + { + static_cast(data_representation); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN + +#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + eProsima_user_DllExport inline bool construct_sample( + void* memory) const override + { + static_cast(memory); + return false; + } + +#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE + + eprosima::fastdds::MD5 m_md5; + unsigned char* m_keyBuffer; + +}; + +#endif // FAST_DDS_GENERATED__HELLOWORLD_PUBSUBTYPES_HPP + diff --git a/examples/cpp/discovery_server/HelloWorldTypeObjectSupport.hpp b/examples/cpp/discovery_server/HelloWorldTypeObjectSupport.hpp index 2eba797b07f..ec922163d11 100644 --- a/examples/cpp/discovery_server/HelloWorldTypeObjectSupport.hpp +++ b/examples/cpp/discovery_server/HelloWorldTypeObjectSupport.hpp @@ -19,8 +19,8 @@ * This file was generated by the tool fastddsgen. */ -#ifndef _FAST_DDS_GENERATED_HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP_ -#define _FAST_DDS_GENERATED_HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP_ +#ifndef FAST_DDS_GENERATED__HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP +#define FAST_DDS_GENERATED__HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP #include @@ -53,4 +53,4 @@ eProsima_user_DllExport void register_HelloWorld_type_identifier( #endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC -#endif // _FAST_DDS_GENERATED_HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP_ +#endif // FAST_DDS_GENERATED__HELLOWORLD_TYPE_OBJECT_SUPPORT_HPP From 1c390797d64eb8fcb4dca4fc5861153b2082f2cb Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Wed, 3 Jul 2024 09:16:19 +0200 Subject: [PATCH 17/18] Refs #21095: update headers Signed-off-by: Mario Dominguez --- .../discovery_server/ClientPublisherApp.cpp | 10 +- .../discovery_server/ClientPublisherApp.hpp | 2 +- .../discovery_server/ClientSubscriberApp.cpp | 11 +- .../discovery_server/ClientSubscriberApp.hpp | 2 +- .../discovery_server/HelloWorldPubSubTypes.h | 133 ------------------ examples/cpp/discovery_server/Helpers.hpp | 17 +-- examples/cpp/discovery_server/ServerApp.cpp | 10 +- examples/cpp/discovery_server/ServerApp.hpp | 2 +- 8 files changed, 20 insertions(+), 167 deletions(-) delete mode 100644 examples/cpp/discovery_server/HelloWorldPubSubTypes.h diff --git a/examples/cpp/discovery_server/ClientPublisherApp.cpp b/examples/cpp/discovery_server/ClientPublisherApp.cpp index 4a125771cf5..d705aeb21cd 100644 --- a/examples/cpp/discovery_server/ClientPublisherApp.cpp +++ b/examples/cpp/discovery_server/ClientPublisherApp.cpp @@ -27,11 +27,11 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include using namespace eprosima::fastdds::dds; diff --git a/examples/cpp/discovery_server/ClientPublisherApp.hpp b/examples/cpp/discovery_server/ClientPublisherApp.hpp index ddb5d8a5a6f..11a51518e53 100644 --- a/examples/cpp/discovery_server/ClientPublisherApp.hpp +++ b/examples/cpp/discovery_server/ClientPublisherApp.hpp @@ -28,7 +28,7 @@ #include "Application.hpp" #include "CLIParser.hpp" -#include "HelloWorldPubSubTypes.h" +#include "HelloWorldPubSubTypes.hpp" using namespace eprosima::fastdds::dds; diff --git a/examples/cpp/discovery_server/ClientSubscriberApp.cpp b/examples/cpp/discovery_server/ClientSubscriberApp.cpp index 8f50af191a1..8918f708df7 100644 --- a/examples/cpp/discovery_server/ClientSubscriberApp.cpp +++ b/examples/cpp/discovery_server/ClientSubscriberApp.cpp @@ -29,14 +29,13 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "CLIParser.hpp" -#include "HelloWorldPubSubTypes.h" #include "Application.hpp" using namespace eprosima::fastdds::dds; diff --git a/examples/cpp/discovery_server/ClientSubscriberApp.hpp b/examples/cpp/discovery_server/ClientSubscriberApp.hpp index d006f2ce2ae..877a076c585 100644 --- a/examples/cpp/discovery_server/ClientSubscriberApp.hpp +++ b/examples/cpp/discovery_server/ClientSubscriberApp.hpp @@ -27,7 +27,7 @@ #include #include "CLIParser.hpp" -#include "HelloWorldPubSubTypes.h" +#include "HelloWorldPubSubTypes.hpp" #include "Application.hpp" using namespace eprosima::fastdds::dds; diff --git a/examples/cpp/discovery_server/HelloWorldPubSubTypes.h b/examples/cpp/discovery_server/HelloWorldPubSubTypes.h deleted file mode 100644 index f048c9be28e..00000000000 --- a/examples/cpp/discovery_server/HelloWorldPubSubTypes.h +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/*! - * @file HelloWorldPubSubTypes.h - * This header file contains the declaration of the serialization functions. - * - * This file was generated by the tool fastddsgen. - */ - - -#ifndef _FAST_DDS_GENERATED_HELLOWORLD_PUBSUBTYPES_H_ -#define _FAST_DDS_GENERATED_HELLOWORLD_PUBSUBTYPES_H_ - -#include -#include -#include -#include -#include - -#include "HelloWorld.hpp" - - -#if !defined(GEN_API_VER) || (GEN_API_VER != 2) -#error \ - Generated HelloWorld is not compatible with current installed Fast DDS. Please, regenerate it with fastddsgen. -#endif // GEN_API_VER - - -/*! - * @brief This class represents the TopicDataType of the type HelloWorld defined by the user in the IDL file. - * @ingroup HelloWorld - */ -class HelloWorldPubSubType : public eprosima::fastdds::dds::TopicDataType -{ -public: - - typedef HelloWorld type; - - eProsima_user_DllExport HelloWorldPubSubType(); - - eProsima_user_DllExport ~HelloWorldPubSubType() override; - - eProsima_user_DllExport bool serialize( - void* data, - eprosima::fastdds::rtps::SerializedPayload_t* payload) override - { - return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport bool serialize( - void* 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 std::function getSerializedSizeProvider( - void* data) override - { - return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION); - } - - eProsima_user_DllExport std::function getSerializedSizeProvider( - void* data, - eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; - - eProsima_user_DllExport bool getKey( - void* data, - eprosima::fastdds::rtps::InstanceHandle_t* ihandle, - bool force_md5 = false) override; - - eProsima_user_DllExport void* createData() override; - - eProsima_user_DllExport void deleteData( - void* data) override; - - //Register TypeObject representation in Fast DDS TypeObjectRegistry - eProsima_user_DllExport void register_type_object_representation() override; - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - eProsima_user_DllExport inline bool is_bounded() const override - { - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED - -#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - eProsima_user_DllExport inline bool is_plain() const override - { - return false; - } - - eProsima_user_DllExport inline bool is_plain( - eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override - { - static_cast(data_representation); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN - -#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - eProsima_user_DllExport inline bool construct_sample( - void* memory) const override - { - static_cast(memory); - return false; - } - -#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE - - MD5 m_md5; - unsigned char* m_keyBuffer; - -}; - -#endif // _FAST_DDS_GENERATED_HELLOWORLD_PUBSUBTYPES_H_ - diff --git a/examples/cpp/discovery_server/Helpers.hpp b/examples/cpp/discovery_server/Helpers.hpp index fdbe4328192..98dc986d095 100644 --- a/examples/cpp/discovery_server/Helpers.hpp +++ b/examples/cpp/discovery_server/Helpers.hpp @@ -20,8 +20,8 @@ #ifndef _FASTDDS_DISCOVERY_SERVER_EXAMPLE_HELPERS_HPP_ #define _FASTDDS_DISCOVERY_SERVER_EXAMPLE_HELPERS_HPP_ -#include -#include +#include +#include //! Transport kind enumeration enum class TransportKind : uint8_t @@ -33,19 +33,6 @@ enum class TransportKind : uint8_t SHM, }; -inline eprosima::fastdds::rtps::GuidPrefix_t get_discovery_server_guid_from_id( - unsigned short id) -{ - eprosima::fastdds::rtps::GuidPrefix_t result; - - // Get default DS guid and modify the one value expected to be changed - std::istringstream(eprosima::fastdds::rtps::DEFAULT_ROS2_SERVER_GUIDPREFIX) >> result; - result.value[2] = - static_cast(id); // This is done like this in Fast - - return result; -} - inline bool is_ip( const std::string ip_str) { diff --git a/examples/cpp/discovery_server/ServerApp.cpp b/examples/cpp/discovery_server/ServerApp.cpp index e6fced2ce83..3df45a1ba5c 100644 --- a/examples/cpp/discovery_server/ServerApp.cpp +++ b/examples/cpp/discovery_server/ServerApp.cpp @@ -27,11 +27,11 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include using namespace eprosima::fastdds::dds; diff --git a/examples/cpp/discovery_server/ServerApp.hpp b/examples/cpp/discovery_server/ServerApp.hpp index d0d1be4280c..bde507da287 100644 --- a/examples/cpp/discovery_server/ServerApp.hpp +++ b/examples/cpp/discovery_server/ServerApp.hpp @@ -28,7 +28,7 @@ #include "Application.hpp" #include "CLIParser.hpp" -#include "HelloWorldPubSubTypes.h" +#include "HelloWorldPubSubTypes.hpp" using namespace eprosima::fastdds::dds; From 6e4f64b5cef3b3f19a798225629cafbcdeaa6e9c Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Wed, 3 Jul 2024 14:54:09 +0200 Subject: [PATCH 18/18] Refs #21095: Reword header marks Signed-off-by: Mario Dominguez --- examples/cpp/discovery_server/Application.hpp | 6 +++--- examples/cpp/discovery_server/CLIParser.hpp | 6 +++--- examples/cpp/discovery_server/ClientPublisherApp.hpp | 6 +++--- examples/cpp/discovery_server/ClientSubscriberApp.hpp | 6 +++--- examples/cpp/discovery_server/Helpers.hpp | 6 +++--- examples/cpp/discovery_server/ServerApp.hpp | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/cpp/discovery_server/Application.hpp b/examples/cpp/discovery_server/Application.hpp index 94470a1d794..14df294260e 100644 --- a/examples/cpp/discovery_server/Application.hpp +++ b/examples/cpp/discovery_server/Application.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_DISCOVERY_SERVER_APPLICATION_HPP_ -#define _FASTDDS_DISCOVERY_SERVER_APPLICATION_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__APPLICATION_HPP +#define FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__APPLICATION_HPP #include @@ -52,4 +52,4 @@ class Application } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_DISCOVERY_SERVER_APPLICATION_HPP_ */ +#endif /* FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__APPLICATION_HPP */ diff --git a/examples/cpp/discovery_server/CLIParser.hpp b/examples/cpp/discovery_server/CLIParser.hpp index d24c048b21c..89a9ffb5073 100644 --- a/examples/cpp/discovery_server/CLIParser.hpp +++ b/examples/cpp/discovery_server/CLIParser.hpp @@ -25,8 +25,8 @@ #include "Helpers.hpp" -#ifndef _FASTDDS_DISCOVERY_SERVER_CLI_PARSER_HPP_ -#define _FASTDDS_DISCOVERY_SERVER_CLI_PARSER_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__CLIPARSER_HPP +#define FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__CLIPARSER_HPP namespace eprosima { namespace fastdds { @@ -680,4 +680,4 @@ class CLIParser } // namespace fastdds } // namespace eprosima -#endif // _FASTDDS_DISCOVERY_SERVER_CLI_PARSER_HPP_ +#endif // FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__CLIPARSER_HPP diff --git a/examples/cpp/discovery_server/ClientPublisherApp.hpp b/examples/cpp/discovery_server/ClientPublisherApp.hpp index 11a51518e53..bfdd291e2b4 100644 --- a/examples/cpp/discovery_server/ClientPublisherApp.hpp +++ b/examples/cpp/discovery_server/ClientPublisherApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_DISCOVERY_SERVER_CLIENT_PUBLISHER_APP_HPP_ -#define _FASTDDS_DISCOVERY_SERVER_CLIENT_PUBLISHER_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__CLIENTPUBLISHERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__CLIENTPUBLISHERAPP_HPP #include @@ -95,4 +95,4 @@ class ClientPublisherApp : public Application, public DataWriterListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_DISCOVERY_SERVER_CLIENT_PUBLISHER_APP_HPP_ */ +#endif /* FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__CLIENTPUBLISHERAPP_HPP */ diff --git a/examples/cpp/discovery_server/ClientSubscriberApp.hpp b/examples/cpp/discovery_server/ClientSubscriberApp.hpp index 877a076c585..2d1ddae1fca 100644 --- a/examples/cpp/discovery_server/ClientSubscriberApp.hpp +++ b/examples/cpp/discovery_server/ClientSubscriberApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_DISCOVERY_SERVER_CLIENT_SUBSCRIBER_APP_HPP_ -#define _FASTDDS_DISCOVERY_SERVER_CLIENT_SUBSCRIBER_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__CLIENTSUBSCRIBERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__CLIENTSUBSCRIBERAPP_HPP #include @@ -94,4 +94,4 @@ class ClientSubscriberApp : public Application, public DataReaderListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_DISCOVERY_SERVER_CLIENT_SUBSCRIBER_APP_HPP_ */ +#endif /* FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__CLIENTSUBSCRIBERAPP_HPP */ diff --git a/examples/cpp/discovery_server/Helpers.hpp b/examples/cpp/discovery_server/Helpers.hpp index 98dc986d095..c4603c69a9a 100644 --- a/examples/cpp/discovery_server/Helpers.hpp +++ b/examples/cpp/discovery_server/Helpers.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_DISCOVERY_SERVER_EXAMPLE_HELPERS_HPP_ -#define _FASTDDS_DISCOVERY_SERVER_EXAMPLE_HELPERS_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__HELPERS_HPP +#define FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__HELPERS_HPP #include #include @@ -78,4 +78,4 @@ inline std::string get_ip_from_dns( return domain_name; } -#endif /* _FASTDDS_DISCOVERY_SERVER_EXAMPLE_HELPERS_HPP_ */ +#endif /* FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__HELPERS_HPP */ diff --git a/examples/cpp/discovery_server/ServerApp.hpp b/examples/cpp/discovery_server/ServerApp.hpp index bde507da287..f9eca825559 100644 --- a/examples/cpp/discovery_server/ServerApp.hpp +++ b/examples/cpp/discovery_server/ServerApp.hpp @@ -17,8 +17,8 @@ * */ -#ifndef _FASTDDS_DISCOVERY_SERVER_SERVER_APP_HPP_ -#define _FASTDDS_DISCOVERY_SERVER_SERVER_APP_HPP_ +#ifndef FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__SERVERAPP_HPP +#define FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__SERVERAPP_HPP #include @@ -83,4 +83,4 @@ class ServerApp : public Application, public DomainParticipantListener } // namespace fastdds } // namespace eprosima -#endif /* _FASTDDS_DISCOVERY_SERVER_SERVER_APP_HPP_ */ +#endif /* FASTDDS_EXAMPLES_CPP_DISCOVERY_SERVER__SERVERAPP_HPP */