diff --git a/ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp index c139f79b..484fb23f 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/rtps/CommonParticipant.hpp @@ -194,8 +194,7 @@ class CommonParticipant const std::shared_ptr& participant_configuration, const std::shared_ptr& payload_pool, const std::shared_ptr& discovery_database, - const core::types::DomainId& domain_id, - const fastdds::rtps::RTPSParticipantAttributes& participant_attributes); + const core::types::DomainId& domain_id); /** * @brief Auxiliary method to create the internal RTPS participant. @@ -208,12 +207,19 @@ class CommonParticipant // RTPS specific methods /** - * @brief Static method that gives the std attributes for a Participant. + * @brief Virtual method that gives the common std attributes for a Participant. + * + * @note This method must be specialized from inherit classes. + */ + virtual fastdds::rtps::RTPSParticipantAttributes add_participant_att_properties_( + fastdds::rtps::RTPSParticipantAttributes& params) const; + + /** + * @brief Virtual method that gives the std attributes for a Participant. * * @note This method must be specialized from inherit classes. */ - static fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_( - const ParticipantConfiguration* participant_configuration); + virtual fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_() const; ///// // VARIABLES diff --git a/ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp index c33fe45d..e3640006 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/rtps/DiscoveryServerParticipant.hpp @@ -41,8 +41,7 @@ class DiscoveryServerParticipant protected: - static fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_( - const DiscoveryServerParticipantConfiguration* participant_configuration); + fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_() const override; }; diff --git a/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp index 0b11d86b..2eca30da 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/rtps/InitialPeersParticipant.hpp @@ -41,8 +41,7 @@ class InitialPeersParticipant protected: - static fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_( - const InitialPeersParticipantConfiguration* configuration); + fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_() const override; }; diff --git a/ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp index 46774a1c..71459bbc 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/rtps/SimpleParticipant.hpp @@ -52,8 +52,7 @@ class SimpleParticipant : public CommonParticipant /** * @brief Static method that gives the attributes for a Simple Participant. */ - static fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_( - const SimpleParticipantConfiguration* configuration); + fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_() const override; }; } /* namespace rtps */ diff --git a/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp index 914cdf9d..7d512abb 100644 --- a/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp @@ -54,13 +54,11 @@ CommonParticipant::CommonParticipant( const std::shared_ptr& participant_configuration, const std::shared_ptr& payload_pool, const std::shared_ptr& discovery_database, - const core::types::DomainId& domain_id, - const fastdds::rtps::RTPSParticipantAttributes& participant_attributes) + const core::types::DomainId& domain_id) : configuration_(participant_configuration) , payload_pool_(payload_pool) , discovery_database_(discovery_database) , domain_id_(domain_id) - , participant_attributes_(participant_attributes) { // Do nothing } @@ -75,6 +73,7 @@ CommonParticipant::~CommonParticipant() void CommonParticipant::init() { + participant_attributes_ = reckon_participant_attributes_(); create_participant_( domain_id_, participant_attributes_); @@ -487,14 +486,9 @@ std::shared_ptr CommonParticipant::create_reader( } fastdds::rtps::RTPSParticipantAttributes -CommonParticipant::reckon_participant_attributes_( - const ParticipantConfiguration* participant_configuration) +CommonParticipant::add_participant_att_properties_( + fastdds::rtps::RTPSParticipantAttributes& params) const { - fastdds::rtps::RTPSParticipantAttributes params; - - // Add Participant name - params.setName(participant_configuration->id.c_str()); - // Ignore the local endpoints so that the reader and writer of the same participant don't match. params.properties.properties().emplace_back( "fastdds.ignore_local_endpoints", @@ -503,16 +497,29 @@ CommonParticipant::reckon_participant_attributes_( // Set app properties params.properties.properties().emplace_back( "fastdds.application.id", - participant_configuration->app_id, + configuration_->app_id, "true"); params.properties.properties().emplace_back( "fastdds.application.metadata", - participant_configuration->app_metadata, + configuration_->app_metadata, "true"); return params; } +fastdds::rtps::RTPSParticipantAttributes +CommonParticipant::reckon_participant_attributes_() const +{ + fastdds::rtps::RTPSParticipantAttributes params; + + // Add Participant name + params.setName(configuration_->id.c_str()); + + add_participant_att_properties_(params); + + return params; +} + } /* namespace rtps */ } /* namespace participants */ } /* namespace ddspipe */ diff --git a/ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp index fb289f78..f5c6edff 100644 --- a/ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/rtps/DiscoveryServerParticipant.cpp @@ -38,21 +38,22 @@ DiscoveryServerParticipant::DiscoveryServerParticipant( participant_configuration, payload_pool, discovery_database, - participant_configuration->domain, - reckon_participant_attributes_(participant_configuration.get())) + participant_configuration->domain) { } fastdds::rtps::RTPSParticipantAttributes -DiscoveryServerParticipant::reckon_participant_attributes_( - const DiscoveryServerParticipantConfiguration* configuration) +DiscoveryServerParticipant::reckon_participant_attributes_() const { // Use default as base attributes - fastdds::rtps::RTPSParticipantAttributes params = CommonParticipant::reckon_participant_attributes_(configuration); + fastdds::rtps::RTPSParticipantAttributes params = CommonParticipant::reckon_participant_attributes_(); + + std::shared_ptr ds_configuration = + std::static_pointer_cast(configuration_); // Auxiliary variable to save characters and improve readability - const core::types::GuidPrefix& discovery_server_guid_prefix = configuration->discovery_server_guid_prefix; - const auto& tls_config = configuration->tls_configuration; + const core::types::GuidPrefix& discovery_server_guid_prefix = ds_configuration->discovery_server_guid_prefix; + const auto& tls_config = ds_configuration->tls_configuration; // Needed values to check at the end if descriptor must be set bool has_listening_addresses = false; @@ -68,14 +69,14 @@ DiscoveryServerParticipant::reckon_participant_attributes_( ///// // Set listening addresses - for (types::Address address : configuration->listening_addresses) + for (types::Address address : ds_configuration->listening_addresses) { if (!address.is_valid()) { // Invalid address, continue with next one EPROSIMA_LOG_WARNING(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, "Discard listening address: " << address << - " in Participant " << configuration->id << " initialization."); + " in Participant " << ds_configuration->id << " initialization."); continue; } @@ -121,7 +122,7 @@ DiscoveryServerParticipant::reckon_participant_attributes_( else { descriptor = create_descriptor( - configuration->whitelist); + ds_configuration->whitelist); descriptor->add_listener_port(address.port()); descriptor->set_WAN_address(address.ip()); @@ -140,7 +141,7 @@ DiscoveryServerParticipant::reckon_participant_attributes_( has_listening_tcp_ipv6 = true; std::shared_ptr descriptor = - create_descriptor(configuration->whitelist); + create_descriptor(ds_configuration->whitelist); descriptor->add_listener_port(address.port()); @@ -194,19 +195,19 @@ DiscoveryServerParticipant::reckon_participant_attributes_( params.defaultUnicastLocatorList.push_back(locator); logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, - "Add listening address " << address << " to Participant " << configuration->id << "."); + "Add listening address " << address << " to Participant " << ds_configuration->id << "."); } ///// // Set connection addresses - for (types::DiscoveryServerConnectionAddress connection_address : configuration->connection_addresses) + for (types::DiscoveryServerConnectionAddress connection_address : ds_configuration->connection_addresses) { if (!connection_address.is_valid()) { // Invalid connection address, continue with next one EPROSIMA_LOG_WARNING(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, "Discard connection address with remote server in Participant " << - configuration->id << " initialization."); + ds_configuration->id << " initialization."); continue; } @@ -217,7 +218,7 @@ DiscoveryServerParticipant::reckon_participant_attributes_( // Invalid ip address, continue with next one EPROSIMA_LOG_WARNING(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, "Discard connection address with remote server due to invalid ip address " << - address.ip() << " in Participant " << configuration->id << + address.ip() << " in Participant " << ds_configuration->id << " initialization."); continue; } @@ -260,7 +261,7 @@ DiscoveryServerParticipant::reckon_participant_attributes_( params.builtin.discovery_config.m_DiscoveryServers.push_back(locator); logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, - "Add connection address " << address << " to Server Participant " << configuration->id << "."); + "Add connection address " << address << " to Server Participant " << ds_configuration->id << "."); } } @@ -279,7 +280,7 @@ DiscoveryServerParticipant::reckon_participant_attributes_( if (!has_connection_addresses) { EPROSIMA_LOG_WARNING(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, - "Creating Participant " << configuration->id << " without listening or connection addresses. " << + "Creating Participant " << ds_configuration->id << " without listening or connection addresses. " << "It will not communicate with any other Participant."); } } @@ -295,7 +296,7 @@ DiscoveryServerParticipant::reckon_participant_attributes_( if (has_connection_tcp_ipv4 && !has_listening_tcp_ipv4) { std::shared_ptr descriptor = - create_descriptor(configuration->whitelist); + create_descriptor(ds_configuration->whitelist); // Enable TLS if (tls_config.is_active()) @@ -306,12 +307,12 @@ DiscoveryServerParticipant::reckon_participant_attributes_( params.userTransports.push_back(descriptor); logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, - "Adding TCPv4 Transport to Participant " << configuration->id << "."); + "Adding TCPv4 Transport to Participant " << ds_configuration->id << "."); } if (has_connection_tcp_ipv6 && !has_listening_tcp_ipv6) { std::shared_ptr descriptor = - create_descriptor(configuration->whitelist); + create_descriptor(ds_configuration->whitelist); // Enable TLS if (tls_config.is_active()) @@ -322,31 +323,31 @@ DiscoveryServerParticipant::reckon_participant_attributes_( params.userTransports.push_back(descriptor); logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, - "Adding TCPv6 Transport to Participant " << configuration->id << "."); + "Adding TCPv6 Transport to Participant " << ds_configuration->id << "."); } // If has UDP, create descriptor because it has not been created yet if (has_udp_ipv4) { std::shared_ptr descriptor = - create_descriptor(configuration->whitelist); + create_descriptor(ds_configuration->whitelist); params.userTransports.push_back(descriptor); logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, - "Adding UDPv4 Transport to Participant " << configuration->id << "."); + "Adding UDPv4 Transport to Participant " << ds_configuration->id << "."); } if (has_udp_ipv6) { std::shared_ptr descriptor_v6 = - create_descriptor(configuration->whitelist); + create_descriptor(ds_configuration->whitelist); params.userTransports.push_back(descriptor_v6); logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, - "Adding UDPv6 Transport to Participant " << configuration->id << "."); + "Adding UDPv6 Transport to Participant " << ds_configuration->id << "."); } logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT, - "Configured Participant " << configuration->id << " with server guid: " << + "Configured Participant " << ds_configuration->id << " with server guid: " << discovery_server_guid_prefix); return params; diff --git a/ddspipe_participants/src/cpp/participant/rtps/InitialPeersParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/InitialPeersParticipant.cpp index 5e3d521d..61c7770f 100644 --- a/ddspipe_participants/src/cpp/participant/rtps/InitialPeersParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/rtps/InitialPeersParticipant.cpp @@ -34,19 +34,20 @@ InitialPeersParticipant::InitialPeersParticipant( participant_configuration, payload_pool, discovery_database, - participant_configuration->domain, - reckon_participant_attributes_(participant_configuration.get())) + participant_configuration->domain) { } -fastdds::rtps::RTPSParticipantAttributes InitialPeersParticipant::reckon_participant_attributes_( - const InitialPeersParticipantConfiguration* configuration) +fastdds::rtps::RTPSParticipantAttributes InitialPeersParticipant::reckon_participant_attributes_() const { // Use default as base attributes - fastdds::rtps::RTPSParticipantAttributes params = CommonParticipant::reckon_participant_attributes_(configuration); + fastdds::rtps::RTPSParticipantAttributes params = CommonParticipant::reckon_participant_attributes_(); + + std::shared_ptr ip_configuration = + std::static_pointer_cast(configuration_); // Auxiliary variable to save characters and improve readability - const auto& tls_config = configuration->tls_configuration; + const auto& tls_config = ip_configuration->tls_configuration; // Needed values to check at the end if descriptor must be set bool has_listening_addresses = false; @@ -63,14 +64,14 @@ fastdds::rtps::RTPSParticipantAttributes InitialPeersParticipant::reckon_partici ///// // Set listening addresses - for (const types::Address& address : configuration->listening_addresses) + for (const types::Address& address : ip_configuration->listening_addresses) { if (!address.is_valid()) { // Invalid address, continue with next one EPROSIMA_LOG_WARNING(DDSPIPE_INITIALPEERS_PARTICIPANT, "Discard listening address: " << address << - " in Participant " << configuration->id << " initialization."); + " in Participant " << ip_configuration->id << " initialization."); continue; } @@ -116,7 +117,7 @@ fastdds::rtps::RTPSParticipantAttributes InitialPeersParticipant::reckon_partici else { descriptor = create_descriptor( - configuration->whitelist); + ip_configuration->whitelist); descriptor->add_listener_port(address.port()); descriptor->set_WAN_address(address.ip()); @@ -135,7 +136,7 @@ fastdds::rtps::RTPSParticipantAttributes InitialPeersParticipant::reckon_partici has_listening_tcp_ipv6 = true; std::shared_ptr descriptor = - create_descriptor(configuration->whitelist); + create_descriptor(ip_configuration->whitelist); descriptor->add_listener_port(address.port()); @@ -190,19 +191,19 @@ fastdds::rtps::RTPSParticipantAttributes InitialPeersParticipant::reckon_partici params.defaultUnicastLocatorList.push_back(locator); logDebug(DDSPIPE_INITIALPEERS_PARTICIPANT, - "Add listening address " << address << " to Participant " << configuration->id << "."); + "Add listening address " << address << " to Participant " << ip_configuration->id << "."); } ///// // Set connection addresses - for (const types::Address& connection_address : configuration->connection_addresses) + for (const types::Address& connection_address : ip_configuration->connection_addresses) { if (!connection_address.is_valid()) { // Invalid connection address, continue with next one EPROSIMA_LOG_WARNING(DDSPIPE_INITIALPEERS_PARTICIPANT, "Discard connection address: " << connection_address << - " in Participant " << configuration->id << " initialization."); + " in Participant " << ip_configuration->id << " initialization."); continue; } @@ -254,7 +255,7 @@ fastdds::rtps::RTPSParticipantAttributes InitialPeersParticipant::reckon_partici logDebug(DDSPIPE_INITIALPEERS_PARTICIPANT, "Add connection address " << connection_address << - " to Participant " << configuration->id << "."); + " to Participant " << ip_configuration->id << "."); } ///// @@ -264,7 +265,7 @@ fastdds::rtps::RTPSParticipantAttributes InitialPeersParticipant::reckon_partici if (has_connection_tcp_ipv4 && !has_listening_tcp_ipv4) { std::shared_ptr descriptor = - create_descriptor(configuration->whitelist); + create_descriptor(ip_configuration->whitelist); // Enable TLS if (tls_config.is_active()) @@ -275,13 +276,13 @@ fastdds::rtps::RTPSParticipantAttributes InitialPeersParticipant::reckon_partici params.userTransports.push_back(descriptor); logDebug(DDSPIPE_INITIALPEERS_PARTICIPANT, - "Adding TCPv4 Transport to Participant " << configuration->id << "."); + "Adding TCPv4 Transport to Participant " << ip_configuration->id << "."); } if (has_connection_tcp_ipv6 && !has_listening_tcp_ipv6) { std::shared_ptr descriptor = - create_descriptor(configuration->whitelist); + create_descriptor(ip_configuration->whitelist); // Enable TLS if (tls_config.is_active()) @@ -292,28 +293,28 @@ fastdds::rtps::RTPSParticipantAttributes InitialPeersParticipant::reckon_partici params.userTransports.push_back(descriptor); logDebug(DDSPIPE_INITIALPEERS_PARTICIPANT, - "Adding TCPv6 Transport to Participant " << configuration->id << "."); + "Adding TCPv6 Transport to Participant " << ip_configuration->id << "."); } // If has UDP, create descriptor because it has not been created yet if (has_udp_ipv4) { std::shared_ptr descriptor = - create_descriptor(configuration->whitelist); + create_descriptor(ip_configuration->whitelist); params.userTransports.push_back(descriptor); logDebug(DDSPIPE_INITIALPEERS_PARTICIPANT, - "Adding UDPv4 Transport to Participant " << configuration->id << "."); + "Adding UDPv4 Transport to Participant " << ip_configuration->id << "."); } if (has_udp_ipv6) { std::shared_ptr descriptor_v6 = - create_descriptor(configuration->whitelist); + create_descriptor(ip_configuration->whitelist); params.userTransports.push_back(descriptor_v6); logDebug(DDSPIPE_INITIALPEERS_PARTICIPANT, - "Adding UDPv6 Transport to Participant " << configuration->id << "."); + "Adding UDPv6 Transport to Participant " << ip_configuration->id << "."); } // To avoid creating a multicast transport in UDP when non listening addresses @@ -336,7 +337,7 @@ fastdds::rtps::RTPSParticipantAttributes InitialPeersParticipant::reckon_partici } logDebug(DDSPIPE_INITIALPEERS_PARTICIPANT, - "Configured Participant " << configuration->id); + "Configured Participant " << ip_configuration->id); return params; } diff --git a/ddspipe_participants/src/cpp/participant/rtps/SimpleParticipant.cpp b/ddspipe_participants/src/cpp/participant/rtps/SimpleParticipant.cpp index 30d21e64..2312821e 100644 --- a/ddspipe_participants/src/cpp/participant/rtps/SimpleParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/rtps/SimpleParticipant.cpp @@ -35,22 +35,23 @@ SimpleParticipant::SimpleParticipant( participant_configuration, payload_pool, discovery_database, - participant_configuration->domain, - reckon_participant_attributes_(participant_configuration.get())) + participant_configuration->domain) { } fastdds::rtps::RTPSParticipantAttributes -SimpleParticipant::reckon_participant_attributes_( - const SimpleParticipantConfiguration* configuration) +SimpleParticipant::reckon_participant_attributes_() const { // Use default as base attributes - fastdds::rtps::RTPSParticipantAttributes params = CommonParticipant::reckon_participant_attributes_(configuration); + fastdds::rtps::RTPSParticipantAttributes params = CommonParticipant::reckon_participant_attributes_(); + + std::shared_ptr simple_configuration = + std::static_pointer_cast(configuration_); // Configure Participant transports - if (configuration->transport == core::types::TransportDescriptors::builtin) + if (simple_configuration->transport == core::types::TransportDescriptors::builtin) { - if (!configuration->whitelist.empty()) + if (!simple_configuration->whitelist.empty()) { params.useBuiltinTransports = false; @@ -59,11 +60,11 @@ SimpleParticipant::reckon_participant_attributes_( params.userTransports.push_back(shm_transport); std::shared_ptr udp_transport = - create_descriptor(configuration->whitelist); + create_descriptor(simple_configuration->whitelist); params.userTransports.push_back(udp_transport); } } - else if (configuration->transport == core::types::TransportDescriptors::shm_only) + else if (simple_configuration->transport == core::types::TransportDescriptors::shm_only) { params.useBuiltinTransports = false; @@ -71,17 +72,17 @@ SimpleParticipant::reckon_participant_attributes_( std::make_shared(); params.userTransports.push_back(shm_transport); } - else if (configuration->transport == core::types::TransportDescriptors::udp_only) + else if (simple_configuration->transport == core::types::TransportDescriptors::udp_only) { params.useBuiltinTransports = false; std::shared_ptr udp_transport = - create_descriptor(configuration->whitelist); + create_descriptor(simple_configuration->whitelist); params.userTransports.push_back(udp_transport); } // Participant discovery filter configuration - switch (configuration->ignore_participant_flags) + switch (simple_configuration->ignore_participant_flags) { case core::types::IgnoreParticipantFlags::no_filter: params.builtin.discovery_config.ignoreParticipantFlags =