From 15a33db3ddd4026f674613d98177f89795fcfff9 Mon Sep 17 00:00:00 2001 From: jparisu Date: Tue, 19 Jul 2022 09:00:01 +0200 Subject: [PATCH 1/5] Refs #15188: Refactor Configuration to data structs Signed-off-by: jparisu --- .dev/README.md | 13 + .../configuration/BaseConfiguration.hpp | 12 +- .../configuration/DDSRouterConfiguration.hpp | 47 +-- .../DDSRouterReloadConfiguration.hpp | 45 +-- ...iscoveryServerParticipantConfiguration.hpp | 51 ++- .../participant/ParticipantConfiguration.hpp | 35 +- .../SimpleParticipantConfiguration.hpp | 37 +- .../configuration/DDSRouterConfiguration.cpp | 58 +--- .../DDSRouterReloadConfiguration.cpp | 15 - ...iscoveryServerParticipantConfiguration.cpp | 112 +----- .../participant/ParticipantConfiguration.cpp | 12 +- .../SimpleParticipantConfiguration.cpp | 7 - ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp | 18 +- .../src/cpp/core/ParticipantFactory.cpp | 20 +- .../auxiliar/impl/BaseParticipant.ipp | 8 +- .../rtps/impl/CommonRTPSRouterParticipant.ipp | 4 +- .../rtps/impl/DiscoveryServerParticipant.ipp | 8 +- ddsrouter_core/test/TestUtils/test_utils.cpp | 4 +- .../ddsrouter_core/dds/WAN/DDSTestWAN.cpp | 12 +- .../ddsrouter_core/dds/local/DDSTestLocal.cpp | 3 +- .../ddsrouter_core/trivial/TrivialTest.cpp | 44 +-- .../implementations/ImplementationsTest.cpp | 25 +- .../include/ddsrouter_yaml/YamlReader.hpp | 24 ++ .../ddsrouter_yaml/impl/YamlReader.ipp | 30 +- ddsrouter_yaml/src/cpp/YamlReader.cpp | 323 +++++------------- ddsrouter_yaml/test/TestUtils/test_utils.cpp | 4 +- .../YamlReaderConfigurationTest.cpp | 2 +- .../YamlGetConfigurationDDSRouterTest.cpp | 58 ++-- ...lGetCommonParticipantConfigurationTest.cpp | 4 +- ...lGetSimpleParticipantConfigurationTest.cpp | 6 +- ...t_get_participant_connection_addresses.ipp | 20 +- ...nfigurationTest_get_participant_domain.ipp | 2 +- ...st_get_participant_listening_addresses.ipp | 8 +- ...figurationTest_get_participant_minimum.ipp | 16 +- ...tConfigurationTest_get_participant_tls.ipp | 20 +- 35 files changed, 405 insertions(+), 702 deletions(-) diff --git a/.dev/README.md b/.dev/README.md index 665a8ddb3..fb2ee5a66 100644 --- a/.dev/README.md +++ b/.dev/README.md @@ -159,3 +159,16 @@ These are the log levels and when to use them | User | logUser | always | std::cout | showing message to the user | | Info | logInfo | only debug -d option | logInfo | showing important information about the execution | | Debug | logDebug | only debug -d option | logInfo | showing non important information | + +### Configurations + +Configurations are data structures with public access to their internal values. +This makes it easier to work with them: to create, manage and copy them. +The default values will be defined in the header, so every used could know which are them, and always +have a default constructor. + +From every internal object that requires a configuration to be created, the configuration argument +must be created as an internal value and/or const to the object, +or create some way that the configuration cannot be changed from outside without the internal object notice it. + +Also, configurations must support an `is_valid` method to check that it is in a coherent state. diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/BaseConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/BaseConfiguration.hpp index d968498b4..016c5fca7 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/BaseConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/BaseConfiguration.hpp @@ -21,19 +21,21 @@ #include +#include + namespace eprosima { namespace ddsrouter { namespace core { namespace configuration { /** - * This is an Interface class that force every configuration in ddsrouter to have a \c is_valid method. + * Configurations in DDS Router are data structures with public access to its internal methods. + * Thus, they are not forced to be correct in construction. + * This is an Interface class that forces every configuration in ddsrouter to have a \c is_valid method. */ -class BaseConfiguration +struct BaseConfiguration { -public: - - virtual bool is_valid( + DDSROUTER_CORE_DllAPI virtual bool is_valid( utils::Formatter& error_msg) const noexcept = 0; }; diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp index 5ccdbaf1a..97470adad 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp @@ -39,50 +39,39 @@ namespace configuration { * This class joins every DDSRouter feature configuration and includes methods * to interact with this configuration. */ -class DDSRouterConfiguration : public DDSRouterReloadConfiguration +struct DDSRouterConfiguration : public DDSRouterReloadConfiguration { -public: - /** - * TODO - */ + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + + DDSROUTER_CORE_DllAPI DDSRouterConfiguration() = default; + DDSROUTER_CORE_DllAPI DDSRouterConfiguration( std::set> allowlist, std::set> blocklist, std::set> builtin_topics, std::set> participants_configurations, - unsigned int number_of_threads = default_number_of_threads()); - - /** - * @brief Return a set with the different \c ParticipantConfigurations in the yaml - * - * Every participant configuration is an object of the specific class set in \c types::ParticipantKind . - * - * @return Set of \c ParticipantConfigurations - */ - DDSROUTER_CORE_DllAPI std::set> participants_configurations() const - noexcept; + unsigned int number_of_threads); - DDSROUTER_CORE_DllAPI bool is_valid( - utils::Formatter& error_msg) const noexcept override; + ///////////////////////// + // METHODS + ///////////////////////// DDSROUTER_CORE_DllAPI void reload( const DDSRouterReloadConfiguration& new_configuration); - DDSROUTER_CORE_DllAPI unsigned int number_of_threads() const noexcept; - - DDSROUTER_CORE_DllAPI static unsigned int default_number_of_threads() noexcept; - -protected: - - static bool check_correct_configuration_object_( - const std::shared_ptr configuration); + DDSROUTER_CORE_DllAPI bool is_valid( + utils::Formatter& error_msg) const noexcept override; - std::set> participants_configurations_; + ///////////////////////// + // VARIABLES + ///////////////////////// - unsigned int number_of_threads_; + std::set> participants_configurations_ = {}; - static const unsigned int DEFAULT_NUMBER_OF_THREADS_; + unsigned int number_of_threads_ = 10; }; } /* namespace configuration */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp index fa2900528..1d32996b2 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp @@ -39,45 +39,36 @@ namespace configuration { * This class joins every DDSRouter feature configuration and includes methods * to interact with this configuration. */ -class DDSRouterReloadConfiguration : public BaseConfiguration +struct DDSRouterReloadConfiguration : public BaseConfiguration { -public: - /** - * TODO - */ + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + + DDSROUTER_CORE_DllAPI DDSRouterReloadConfiguration() = default; + DDSROUTER_CORE_DllAPI DDSRouterReloadConfiguration( std::set> allowlist, std::set> blocklist, std::set> builtin_topics); - /** - * @brief Return a set with the topics allowed in the configuration - * - * @return Set of filters to get allowed topics - */ - DDSROUTER_CORE_DllAPI std::set> allowlist() const noexcept; - - /** - * @brief Return a set with the topics blocked in the configuration - * - * @return Set of filters to get blocked topics - */ - DDSROUTER_CORE_DllAPI std::set> blocklist() const noexcept; - - /** - * TODO - */ - DDSROUTER_CORE_DllAPI std::set> builtin_topics() const noexcept; + ///////////////////////// + // METHODS + ///////////////////////// DDSROUTER_CORE_DllAPI bool is_valid( utils::Formatter& error_msg) const noexcept override; -protected: + ///////////////////////// + // VARIABLES + ///////////////////////// + + std::set> allowlist_ = {}; + + std::set> blocklist_ = {}; - std::set> allowlist_; - std::set> blocklist_; - std::set> builtin_topics_; + std::set> builtin_topics_ = {}; }; } /* namespace configuration */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/participant/DiscoveryServerParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/participant/DiscoveryServerParticipantConfiguration.hpp index 9098f3382..9bf231516 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/participant/DiscoveryServerParticipantConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/participant/DiscoveryServerParticipantConfiguration.hpp @@ -36,39 +36,27 @@ namespace configuration { /** * This class joins Discovery Server Participant Configuration features and gives methods to interact with it. */ -class DiscoveryServerParticipantConfiguration : public SimpleParticipantConfiguration +struct DiscoveryServerParticipantConfiguration : public SimpleParticipantConfiguration { -public: - // TODO - DDSROUTER_CORE_DllAPI DiscoveryServerParticipantConfiguration( - const types::ParticipantId& id, - const types::GuidPrefix& discovery_server_guid_prefix, - const std::set& listening_addresses, - const std::set& connection_addresses, - const types::ParticipantKind& kind = types::ParticipantKind::local_discovery_server, - const types::security::TlsConfiguration tls_configuration = types::security::TlsConfiguration(), - const types::DomainId& domain_id = DEFAULT_DS_DOMAIN_ID_); + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + + DDSROUTER_CORE_DllAPI DiscoveryServerParticipantConfiguration() = default; - // TODO DDSROUTER_CORE_DllAPI DiscoveryServerParticipantConfiguration( const types::ParticipantId& id, + const types::ParticipantKind& kind, + const types::DomainId& domain_id, const types::GuidPrefix& discovery_server_guid_prefix, const std::set& listening_addresses, const std::set& connection_addresses, - const types::DomainId& domain_id, - const types::ParticipantKind& kind = types::ParticipantKind::local_discovery_server, - const types::security::TlsConfiguration tls_configuration = types::security::TlsConfiguration()); - - DDSROUTER_CORE_DllAPI types::GuidPrefix discovery_server_guid_prefix() const noexcept; - - DDSROUTER_CORE_DllAPI std::set listening_addresses() const noexcept; + const types::security::TlsConfiguration tls_configuration); - DDSROUTER_CORE_DllAPI std::set connection_addresses() const noexcept; - - DDSROUTER_CORE_DllAPI bool tls_active() const noexcept; - - DDSROUTER_CORE_DllAPI const types::security::TlsConfiguration& tls_configuration() const noexcept; + ///////////////////////// + // METHODS + ///////////////////////// DDSROUTER_CORE_DllAPI virtual bool is_valid( utils::Formatter& error_msg) const noexcept override; @@ -76,16 +64,17 @@ class DiscoveryServerParticipantConfiguration : public SimpleParticipantConfigur DDSROUTER_CORE_DllAPI bool operator ==( const DiscoveryServerParticipantConfiguration& other) const noexcept; - DDSROUTER_CORE_DllAPI static types::DomainId default_domain_id() noexcept; + ///////////////////////// + // VARIABLES + ///////////////////////// + + types::GuidPrefix discovery_server_guid_prefix_ = types::GuidPrefix(); -protected: + std::set listening_addresses_ = {}; - types::GuidPrefix discovery_server_guid_prefix_; - std::set listening_addresses_; - std::set connection_addresses_; - const types::security::TlsConfiguration tls_configuration_; + std::set connection_addresses_ = {}; - DDSROUTER_CORE_DllAPI static const types::DomainId DEFAULT_DS_DOMAIN_ID_; // 66 + types::security::TlsConfiguration tls_configuration_ = types::security::TlsConfiguration(); }; } /* namespace configuration */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/participant/ParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/participant/ParticipantConfiguration.hpp index f0a879085..e5a4aa12a 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/participant/ParticipantConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/participant/ParticipantConfiguration.hpp @@ -29,33 +29,26 @@ namespace ddsrouter { namespace core { namespace configuration { -/** - * TODO - */ -class ParticipantConfiguration : public BaseConfiguration +struct ParticipantConfiguration : public BaseConfiguration { -public: - /** - * TODO - */ + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + + DDSROUTER_CORE_DllAPI ParticipantConfiguration() = default; + DDSROUTER_CORE_DllAPI ParticipantConfiguration( const types::ParticipantId& id, const types::ParticipantKind& kind) noexcept; - //! Participant Kind associated with this configuration - DDSROUTER_CORE_DllAPI types::ParticipantKind kind() const noexcept; - - //! Participant Id associated with this configuration - DDSROUTER_CORE_DllAPI types::ParticipantId id() const noexcept; + ///////////////////////// + // METHODS + ///////////////////////// /** * @brief Equal comparator * - * This comparator should check if the id is equal to the other Configuration and check the yaml equality. - * - * @todo: check equality yaml and not identity yaml. - * * @param [in] other: ParticipantConfiguration to compare. * @return True if both configurations are the same, False otherwise. */ @@ -65,13 +58,15 @@ class ParticipantConfiguration : public BaseConfiguration DDSROUTER_CORE_DllAPI virtual bool is_valid( utils::Formatter& error_msg) const noexcept override; -protected: + ///////////////////////// + // VARIABLES + ///////////////////////// //! Participant Id associated with this configuration - const types::ParticipantId id_; + types::ParticipantId id_; //! Participant Kind of the Participant that this configuration refers. - const types::ParticipantKind kind_; + types::ParticipantKind kind_; }; } /* namespace configuration */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp index dcb71ac7b..24886302f 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp @@ -35,32 +35,37 @@ class SimpleParticipantConfiguration : public ParticipantConfiguration { public: - //! TODO + ///////////////////////// + // CONSTRUCTORS + ///////////////////////// + DDSROUTER_CORE_DllAPI SimpleParticipantConfiguration() = default; + DDSROUTER_CORE_DllAPI SimpleParticipantConfiguration( const types::ParticipantId& id, - const types::ParticipantKind& kind = types::ParticipantKind::simple_rtps, - const types::DomainId& domain_id = DEFAULT_DOMAIN_ID_) noexcept; + const types::ParticipantKind& kind, + const types::DomainId& domain_id) noexcept; + + ///////////////////////// + // METHODS + ///////////////////////// + + DDSROUTER_CORE_DllAPI virtual bool is_valid( + utils::Formatter& error_msg) const noexcept override; /** - * @brief Return domain set in the configuration - * - * In case domain is not set in Configuration, it returns the default DomainID = 0 + * @brief Equal comparator * - * @return DomainId + * @param [in] other: SimpleParticipantConfiguration to compare. + * @return True if both configurations are the same, False otherwise. */ - DDSROUTER_CORE_DllAPI types::DomainId domain() const noexcept; - DDSROUTER_CORE_DllAPI bool operator ==( const SimpleParticipantConfiguration& other) const noexcept; - DDSROUTER_CORE_DllAPI virtual bool is_valid( - utils::Formatter& error_msg) const noexcept override; - -protected: - - types::DomainId domain_; + ///////////////////////// + // VARIABLES + ///////////////////////// - DDSROUTER_CORE_DllAPI static const types::DomainId DEFAULT_DOMAIN_ID_; // 0 + types::DomainId domain_ = types::DomainId(0u); }; } /* namespace configuration */ diff --git a/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp index 4c88d1834..0573aa95e 100644 --- a/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp @@ -33,8 +33,6 @@ namespace configuration { using namespace eprosima::ddsrouter::core::types; -const unsigned int DDSRouterConfiguration::DEFAULT_NUMBER_OF_THREADS_ = 12; - DDSRouterConfiguration::DDSRouterConfiguration( std::set> allowlist, std::set> blocklist, @@ -47,11 +45,6 @@ DDSRouterConfiguration::DDSRouterConfiguration( { } -std::set> DDSRouterConfiguration::participants_configurations() const noexcept -{ - return participants_configurations_; -} - bool DDSRouterConfiguration::is_valid( utils::Formatter& error_msg) const noexcept { @@ -84,19 +77,12 @@ bool DDSRouterConfiguration::is_valid( // Check configuration is valid if (!configuration->is_valid(error_msg)) { - error_msg << "Error in Participant " << configuration->id() << ". "; - return false; - } - - // Check that the configuration is of type required - if (!check_correct_configuration_object_(configuration)) - { - error_msg << "Participant " << configuration->id() << " is not of correct Configuration class. "; + error_msg << "Error in Participant " << configuration->id_ << ". "; return false; } // Store every id in a set to see if there are repetitions - ids.insert(configuration->id()); + ids.insert(configuration->id_); } // If the number of ids are not equal the number of configurations, is because they are repeated @@ -112,43 +98,9 @@ bool DDSRouterConfiguration::is_valid( void DDSRouterConfiguration::reload( const DDSRouterReloadConfiguration& new_configuration) { - this->allowlist_ = new_configuration.allowlist(); - this->blocklist_ = new_configuration.blocklist(); - this->builtin_topics_ = new_configuration.builtin_topics(); -} - -template -bool check_correct_configuration_object_by_type_( - const std::shared_ptr configuration) -{ - return nullptr != std::dynamic_pointer_cast(configuration); -} - -bool DDSRouterConfiguration::check_correct_configuration_object_( - const std::shared_ptr configuration) -{ - switch (configuration->kind()) - { - case ParticipantKind::simple_rtps: - return check_correct_configuration_object_by_type_(configuration); - - case ParticipantKind::local_discovery_server: - case ParticipantKind::wan: - return check_correct_configuration_object_by_type_(configuration); - - default: - return check_correct_configuration_object_by_type_(configuration); - } -} - -unsigned int DDSRouterConfiguration::number_of_threads() const noexcept -{ - return number_of_threads_; -} - -unsigned int DDSRouterConfiguration::default_number_of_threads() noexcept -{ - return DEFAULT_NUMBER_OF_THREADS_; + this->allowlist_ = new_configuration.allowlist_; + this->blocklist_ = new_configuration.blocklist_; + this->builtin_topics_ = new_configuration.builtin_topics_; } } /* namespace configuration */ diff --git a/ddsrouter_core/src/cpp/configuration/DDSRouterReloadConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/DDSRouterReloadConfiguration.cpp index 0cc3177f6..ba3a39066 100644 --- a/ddsrouter_core/src/cpp/configuration/DDSRouterReloadConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/DDSRouterReloadConfiguration.cpp @@ -39,21 +39,6 @@ DDSRouterReloadConfiguration::DDSRouterReloadConfiguration( { } -std::set> DDSRouterReloadConfiguration::allowlist() const noexcept -{ - return allowlist_; -} - -std::set> DDSRouterReloadConfiguration::blocklist() const noexcept -{ - return blocklist_; -} - -std::set> DDSRouterReloadConfiguration::builtin_topics() const noexcept -{ - return builtin_topics_; -} - bool DDSRouterReloadConfiguration::is_valid( utils::Formatter& error_msg) const noexcept { diff --git a/ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp index 07b88c5be..e1fb30dfd 100644 --- a/ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp @@ -28,61 +28,21 @@ namespace configuration { using namespace eprosima::ddsrouter::core::types; -const DomainId DiscoveryServerParticipantConfiguration::DEFAULT_DS_DOMAIN_ID_(66u); - DiscoveryServerParticipantConfiguration::DiscoveryServerParticipantConfiguration( - const ParticipantId& id, - const GuidPrefix& discovery_server_guid_prefix, - const std::set
& listening_addresses, - const std::set& connection_addresses, - const ParticipantKind& kind /* = ParticipantKind::local_discovery_server */, - const types::security::TlsConfiguration tls_configuration /* = types::security::TlsConfiguration() */, - const DomainId& domain_id /* = DEFAULT_DS_DOMAIN_ID_ */) + const types::ParticipantId& id, + const types::ParticipantKind& kind, + const types::DomainId& domain_id, + const types::GuidPrefix& discovery_server_guid_prefix, + const std::set& listening_addresses, + const std::set& connection_addresses, + const types::security::TlsConfiguration tls_configuration) : SimpleParticipantConfiguration(id, kind, domain_id) , discovery_server_guid_prefix_(discovery_server_guid_prefix) , listening_addresses_(listening_addresses) , connection_addresses_(connection_addresses) , tls_configuration_(tls_configuration) { -} - -DiscoveryServerParticipantConfiguration::DiscoveryServerParticipantConfiguration( - const ParticipantId& id, - const GuidPrefix& discovery_server_guid_prefix, - const std::set
& listening_addresses, - const std::set& connection_addresses, - const DomainId& domain_id, - const ParticipantKind& kind /* = ParticipantKind::local_discovery_server */, - const types::security::TlsConfiguration tls_configuration /* = types::security::TlsConfiguration() */) - : DiscoveryServerParticipantConfiguration( - id, discovery_server_guid_prefix, listening_addresses, connection_addresses, kind, tls_configuration, domain_id) -{ -} - -GuidPrefix DiscoveryServerParticipantConfiguration::discovery_server_guid_prefix() const noexcept -{ - return discovery_server_guid_prefix_; -} - -std::set
DiscoveryServerParticipantConfiguration::listening_addresses() const noexcept -{ - return listening_addresses_; -} - -std::set -DiscoveryServerParticipantConfiguration::connection_addresses() const noexcept -{ - return connection_addresses_; -} - -bool DiscoveryServerParticipantConfiguration::tls_active() const noexcept -{ - return tls_configuration_.is_active(); -} - -const types::security::TlsConfiguration& DiscoveryServerParticipantConfiguration::tls_configuration() const noexcept -{ - return tls_configuration_; + // Do nothing } bool DiscoveryServerParticipantConfiguration::is_valid( @@ -94,57 +54,6 @@ bool DiscoveryServerParticipantConfiguration::is_valid( return false; } - // Check listening addresses - for (Address address : listening_addresses_) - { - if (!address.is_valid()) - { - error_msg << "Incorrect address " << address << " in listening addresses. "; - return false; - } - } - - // Check connection addresses - for (DiscoveryServerConnectionAddress address : connection_addresses_) - { - if (!address.is_valid()) - { - error_msg << "Incorrect address " << address << " in connection addresses. "; - return false; - } - } - - // Check exist at least one address - if (listening_addresses_.empty() && connection_addresses_.empty()) - { - error_msg << "No listening or connection address specified. "; - return false; - } - - // If active, check it is valid - if (tls_configuration_.is_active()) - { - // If has listening addresses, it should be able to provide TLS server configuration - if (!listening_addresses_.empty()) - { - if (!tls_configuration_.compatible()) - { - error_msg << "TLS requires to support Server Configuration if listening addresses set. "; - return false; - } - } - - // If has connection addresses, it should be able to provide TLS client configuration - if (!connection_addresses_.empty()) - { - if (!tls_configuration_.compatible()) - { - error_msg << "TLS requires to support Client Configuration if connection addresses set. "; - return false; - } - } - } - // Check DS Guid Prefix if (!discovery_server_guid_prefix_.is_valid()) { @@ -162,11 +71,6 @@ bool DiscoveryServerParticipantConfiguration::operator ==( return false; } -DomainId DiscoveryServerParticipantConfiguration::default_domain_id() noexcept -{ - return DEFAULT_DS_DOMAIN_ID_; -} - } /* namespace configuration */ } /* namespace core */ } /* namespace ddsrouter */ diff --git a/ddsrouter_core/src/cpp/configuration/participant/ParticipantConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/participant/ParticipantConfiguration.cpp index a47bb9f2d..cd490f6ea 100644 --- a/ddsrouter_core/src/cpp/configuration/participant/ParticipantConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/participant/ParticipantConfiguration.cpp @@ -36,16 +36,6 @@ ParticipantConfiguration::ParticipantConfiguration( { } -ParticipantKind ParticipantConfiguration::kind() const noexcept -{ - return kind_; -} - -ParticipantId ParticipantConfiguration::id() const noexcept -{ - return id_; -} - bool ParticipantConfiguration::is_valid( utils::Formatter& error_msg) const noexcept { @@ -67,7 +57,7 @@ bool ParticipantConfiguration::is_valid( bool ParticipantConfiguration::operator ==( const ParticipantConfiguration& other) const noexcept { - return this->id() == other.id() && this->kind() == other.kind(); + return this->id_ == other.id_ && this->kind_ == other.kind_; } } /* namespace configuration */ diff --git a/ddsrouter_core/src/cpp/configuration/participant/SimpleParticipantConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/participant/SimpleParticipantConfiguration.cpp index 8e7289880..62c7b8285 100644 --- a/ddsrouter_core/src/cpp/configuration/participant/SimpleParticipantConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/participant/SimpleParticipantConfiguration.cpp @@ -26,8 +26,6 @@ namespace configuration { using namespace eprosima::ddsrouter::core::types; -const DomainId SimpleParticipantConfiguration::DEFAULT_DOMAIN_ID_(0u); - SimpleParticipantConfiguration::SimpleParticipantConfiguration( const ParticipantId& id, const ParticipantKind& kind /* = ParticipantKind::simple_rtps */, @@ -54,11 +52,6 @@ bool SimpleParticipantConfiguration::is_valid( return true; } -DomainId SimpleParticipantConfiguration::domain() const noexcept -{ - return domain_; -} - bool SimpleParticipantConfiguration::operator ==( const SimpleParticipantConfiguration& other) const noexcept { diff --git a/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp b/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp index 0e119b423..b9d179f06 100644 --- a/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp +++ b/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp @@ -45,7 +45,7 @@ DDSRouterImpl::DDSRouterImpl( , discovery_database_(new DiscoveryDatabase()) , configuration_(configuration) , enabled_(false) - , thread_pool_(std::make_shared(configuration_.number_of_threads())) + , thread_pool_(std::make_shared(configuration_.number_of_threads_)) { logDebug(DDSROUTER, "Creating DDS Router."); @@ -128,12 +128,12 @@ utils::ReturnCode DDSRouterImpl::reload_configuration( // Load new configuration and check it is okey AllowedTopicList new_allowed_topic_list( - new_configuration.allowlist(), - new_configuration.blocklist()); + new_configuration.allowlist_, + new_configuration.blocklist_); // Check if there are any new builtin topics std::set new_builtin_topics; - for (auto builtin_topic : new_configuration.builtin_topics()) + for (auto builtin_topic : new_configuration.builtin_topics_) { if (current_topics_.find(*builtin_topic) == current_topics_.end()) { @@ -269,8 +269,8 @@ utils::ReturnCode DDSRouterImpl::stop_() noexcept void DDSRouterImpl::init_allowed_topics_() { allowed_topics_ = AllowedTopicList( - configuration_.allowlist(), - configuration_.blocklist()); + configuration_.allowlist_, + configuration_.blocklist_); logInfo(DDSROUTER, "DDS Router configured with allowed topics: " << allowed_topics_); } @@ -278,7 +278,7 @@ void DDSRouterImpl::init_allowed_topics_() void DDSRouterImpl::init_participants_() { for (std::shared_ptr participant_config : - configuration_.participants_configurations()) + configuration_.participants_configurations_) { std::shared_ptr new_participant; @@ -296,7 +296,7 @@ void DDSRouterImpl::init_participants_() { // Failed to create participant throw utils::InitializationException(utils::Formatter() - << "Failed to create creating Participant " << participant_config->id()); + << "Failed to create creating Participant " << participant_config->id_); } logInfo(DDSROUTER, "Participant created with id: " << new_participant->id() @@ -327,7 +327,7 @@ void DDSRouterImpl::init_participants_() void DDSRouterImpl::init_bridges_() { - for (std::shared_ptr topic : configuration_.builtin_topics()) + for (std::shared_ptr topic : configuration_.builtin_topics_) { discovered_topic_(*topic); } diff --git a/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp b/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp index c438ec494..d7188b96b 100644 --- a/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp +++ b/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp @@ -39,19 +39,17 @@ namespace core { using namespace eprosima::ddsrouter::core::types; using namespace eprosima::ddsrouter::core::configuration; -// TODO: Add logs - std::shared_ptr ParticipantFactory::create_participant( std::shared_ptr participant_configuration, std::shared_ptr payload_pool, std::shared_ptr discovery_database) { // Create a new Participant depending on the ParticipantKind specified by the configuration - switch (participant_configuration->kind()) + switch (participant_configuration->kind_) { case ParticipantKind::blank: // BlankParticipant - return std::make_shared(participant_configuration->id()); + return std::make_shared(participant_configuration->id_); case ParticipantKind::echo: // EchoParticipant @@ -70,8 +68,8 @@ std::shared_ptr ParticipantFactory::create_participant( if (!conf_) { throw utils::ConfigurationException( - utils::Formatter() << "Configuration from Participant: " << participant_configuration->id() << " is not for Participant Kind: " << - participant_configuration->kind()); + utils::Formatter() << "Configuration from Participant: " << participant_configuration->id_ << + " is not for Participant Kind: " << participant_configuration->kind_); } return std::make_shared ( @@ -89,8 +87,8 @@ std::shared_ptr ParticipantFactory::create_participant( if (!conf_) { throw utils::ConfigurationException( - utils::Formatter() << "Configuration from Participant: " << participant_configuration->id() << " is not for Participant Kind: " << - participant_configuration->kind()); + utils::Formatter() << "Configuration from Participant: " << participant_configuration->id_ << " is not for Participant Kind: " << + participant_configuration->kind_); } return std::make_shared ( @@ -108,8 +106,8 @@ std::shared_ptr ParticipantFactory::create_participant( if (!conf_) { throw utils::ConfigurationException( - utils::Formatter() << "Configuration from Participant: " << participant_configuration->id() << " is not for Participant Kind: " << - participant_configuration->kind()); + utils::Formatter() << "Configuration from Participant: " << participant_configuration->id_ << " is not for Participant Kind: " << + participant_configuration->kind_); } return std::make_shared ( @@ -119,7 +117,7 @@ std::shared_ptr ParticipantFactory::create_participant( } case ParticipantKind::invalid: - throw utils::ConfigurationException(utils::Formatter() << "Kind: " << participant_configuration->kind() + throw utils::ConfigurationException(utils::Formatter() << "Kind: " << participant_configuration->kind_ << " is not a valid participant kind name."); default: diff --git a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/impl/BaseParticipant.ipp b/ddsrouter_core/src/cpp/participant/implementations/auxiliar/impl/BaseParticipant.ipp index ae63919a2..1c4d6a4ad 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/impl/BaseParticipant.ipp +++ b/ddsrouter_core/src/cpp/participant/implementations/auxiliar/impl/BaseParticipant.ipp @@ -68,7 +68,7 @@ types::ParticipantId BaseParticipant::id() const noexcept { std::lock_guard lock(mutex_); - return configuration_.id(); + return configuration_.id_; } template @@ -76,7 +76,7 @@ types::ParticipantKind BaseParticipant::kind() const noexcept { std::lock_guard lock(mutex_); - return configuration_.kind(); + return configuration_.kind_; } template @@ -178,7 +178,7 @@ void BaseParticipant::delete_reader_( template types::ParticipantId BaseParticipant::id_nts_() const noexcept { - return configuration_.id(); + return configuration_.id_; } template @@ -186,7 +186,7 @@ std::ostream& operator <<( std::ostream& os, const BaseParticipant& participant) { - os << "{" << participant.id() << ";" << participant.configuration_.kind() << "}"; + os << "{" << participant.id() << ";" << participant.configuration_.kind_ << "}"; return os; } diff --git a/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/CommonRTPSRouterParticipant.ipp b/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/CommonRTPSRouterParticipant.ipp index 90a5c4e87..c420f8c79 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/CommonRTPSRouterParticipant.ipp +++ b/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/CommonRTPSRouterParticipant.ipp @@ -213,7 +213,7 @@ void CommonRTPSRouterParticipant::onWriterDiscovery( template void CommonRTPSRouterParticipant::create_participant_() { - types::DomainId domain = this->configuration_.domain(); + types::DomainId domain = this->configuration_.domain_; fastrtps::rtps::RTPSParticipantAttributes params = participant_attributes_(); logInfo(DDSROUTER_RTPS_PARTICIPANT, @@ -232,7 +232,7 @@ void CommonRTPSRouterParticipant::create_participant_() } logInfo(DDSROUTER_RTPS_PARTICIPANT, - "New Participant " << this->configuration_.kind() << + "New Participant " << this->configuration_.kind_ << " created with id " << this->id() << " in domain " << domain << " with guid " << rtps_participant_->getGuid()); } diff --git a/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/DiscoveryServerParticipant.ipp b/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/DiscoveryServerParticipant.ipp index 7dcb22f07..34b84474f 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/DiscoveryServerParticipant.ipp +++ b/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/DiscoveryServerParticipant.ipp @@ -52,11 +52,11 @@ fastrtps::rtps::RTPSParticipantAttributes DiscoveryServerParticipant::participant_attributes_() const { // Get Configuration information - std::set listening_addresses = this->configuration_.listening_addresses(); + std::set listening_addresses = this->configuration_.listening_addresses_; std::set connection_addresses = - this->configuration_.connection_addresses(); - types::GuidPrefix discovery_server_guid_prefix = this->configuration_.discovery_server_guid_prefix(); - const auto& tls_config = this->configuration_.tls_configuration(); + this->configuration_.connection_addresses_; + types::GuidPrefix discovery_server_guid_prefix = this->configuration_.discovery_server_guid_prefix_; + const auto& tls_config = this->configuration_.tls_configuration_; // Set attributes fastrtps::rtps::RTPSParticipantAttributes params; diff --git a/ddsrouter_core/test/TestUtils/test_utils.cpp b/ddsrouter_core/test/TestUtils/test_utils.cpp index 7327b08c5..a92506694 100644 --- a/ddsrouter_core/test/TestUtils/test_utils.cpp +++ b/ddsrouter_core/test/TestUtils/test_utils.cpp @@ -234,10 +234,12 @@ std::shared_ptr random_participan return std::make_shared( id, + kind, + random_domain(seed), random_guid_prefix(seed), std::set
(), std::set({connection_address}), - kind); + security::TlsConfiguration()); } // Add cases where Participants need specific arguments diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp index e8bf61774..e9717709c 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/DDSTestWAN.cpp @@ -120,10 +120,11 @@ std::shared_ptr wan_participant_configu { return std::make_shared( types::ParticipantId("WanParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), + types::ParticipantKind::wan, + types::DomainId(0u), types::GuidPrefix((this_server_id_is_1 ? 1u : 0u)), listening_addresses, connection_addresses, - types::ParticipantKind(types::ParticipantKind::wan), tls_configuration(wan_kind)); } @@ -131,11 +132,12 @@ std::shared_ptr wan_participant_configu { return std::make_shared( types::ParticipantId("WanParticipant_" + std::to_string((this_server_id_is_1 ? 1 : 0))), + types::ParticipantKind::wan, + types::DomainId(0u), types::GuidPrefix((this_server_id_is_1 ? 1u : 0u)), listening_addresses, connection_addresses, - types::ParticipantKind(types::ParticipantKind::wan) - ); + types::security::TlsConfiguration()); } } @@ -181,8 +183,8 @@ configuration::DDSRouterConfiguration router_configuration( allowlist, blocklist, builtin_topics, - participants_configurations - ); + participants_configurations, + 1); } /** diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp index 7828ab97f..790ae1486 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp @@ -83,7 +83,8 @@ configuration::DDSRouterConfiguration dds_test_simple_configuration( allowlist, blocklist, builtin_topics, - participants_configurations + participants_configurations, + 1 ); } diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp index 92552f6f4..bb9203620 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp @@ -50,17 +50,17 @@ configuration::DDSRouterConfiguration void_configuration() std::set>(), std::set>(), std::set>( - { - std::make_shared( - ParticipantId("ParticipantVoid1"), - ParticipantKind::blank - ), - std::make_shared( - ParticipantId("ParticipantVoid2"), - ParticipantKind::blank - ) - } - )); + { + std::make_shared( + ParticipantId("ParticipantVoid1"), + ParticipantKind::blank + ), + std::make_shared( + ParticipantId("ParticipantVoid2"), + ParticipantKind::blank + ) + }), + 1); } /** @@ -79,17 +79,17 @@ configuration::DDSRouterConfiguration simple_configuration( std::set>(), std::set>({std::make_shared(topic_name, topic_type)}), std::set>( - { - std::make_shared( - ParticipantId(participant_1_name), - ParticipantKind::dummy - ), - std::make_shared( - ParticipantId(participant_2_name), - ParticipantKind::dummy - ) - } - )); + { + std::make_shared( + ParticipantId(participant_1_name), + ParticipantKind::dummy + ), + std::make_shared( + ParticipantId(participant_2_name), + ParticipantKind::dummy + ) + }), + 1); } /** diff --git a/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp b/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp index e51e37848..f9fdbd097 100644 --- a/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp +++ b/ddsrouter_core/test/blackbox/implementations/ImplementationsTest.cpp @@ -35,6 +35,16 @@ #include #include +namespace eprosima { +namespace ddsrouter { +namespace test { + +constexpr const unsigned int DEFAULT_THREAD_POOL_SIZE = 2; + +} /* namespace test */ +} /* namespace ddsrouter */ +} /* namespace eprosima */ + using namespace eprosima::ddsrouter; using namespace eprosima::ddsrouter::core; using namespace eprosima::ddsrouter::core::types; @@ -57,7 +67,8 @@ TEST(ImplementationsTest, solo_participant_implementation) std::set>(), std::set>(), std::set>(), - participant_configurations); + participant_configurations, + test::DEFAULT_THREAD_POOL_SIZE); // Create DDSRouter entity ASSERT_THROW(DDSRouter router(configuration), utils::ConfigurationException) << kind; @@ -90,7 +101,8 @@ TEST(ImplementationsTest, pair_implementation) std::set>(), std::set>(), std::set>(), - participant_configurations); + participant_configurations, + test::DEFAULT_THREAD_POOL_SIZE); // Create DDSRouter entity DDSRouter router(configuration); @@ -134,7 +146,8 @@ TEST(ImplementationsTest, pair_implementation_with_topic) std::set>(), std::set>(), builtin_topics, - participant_configurations); + participant_configurations, + test::DEFAULT_THREAD_POOL_SIZE); // Create DDSRouter entity DDSRouter router(configuration); @@ -185,7 +198,8 @@ TEST(ImplementationsTest, all_implementations) std::set>(), std::set>(), std::set>(), - participant_configurations); + participant_configurations, + test::DEFAULT_THREAD_POOL_SIZE); // Create DDSRouter entity DDSRouter router(configuration); @@ -220,7 +234,8 @@ TEST(ImplementationsTest, duplicated_ids) std::set>(), std::set>(), std::set>(), - participant_configurations); + participant_configurations, + test::DEFAULT_THREAD_POOL_SIZE); // Create DDSRouter entity ASSERT_THROW(DDSRouter router(configuration), eprosima::ddsrouter::utils::ConfigurationException) << kind; diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp b/ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp index 11a483950..4357ccf98 100644 --- a/ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp +++ b/ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp @@ -137,6 +137,30 @@ class DDSROUTER_YAML_DllAPI YamlReader const TagType& tag, const YamlReaderVersion version); + /** + * @brief Fill an element given by parameter with the values inside \c yml + * + * This method simplifies the process of retrieving an object which parent has its own \c fill method, + * as the code is reused from one another calling parent \c fill in child. + * It is also very helpful to handle default creation values. Without this, every different default value + * must have its own it-else clause, forcing to create the respective constructor. With this method, + * the default values are initialized in with the default constructor, and then are overwritten by the yaml. + * [this problem arises because C++ does not allow different order of parameters in method call] + */ + template + static void fill( + T& object, + const Yaml& yml, + const YamlReaderVersion version); + + //! Fill an element given by parameter with the values inside \c tag in \c yml + template + static void fill( + T& object, + const Yaml& yml, + const TagType& tag, + const YamlReaderVersion version); + //! TODO comment template static std::list get_list( diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp b/ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp index 73c3f495c..fb8fa60fc 100644 --- a/ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp +++ b/ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp @@ -32,7 +32,7 @@ template T YamlReader::get( const Yaml& yml, const TagType& tag, - const YamlReaderVersion version /* = LATEST */) + const YamlReaderVersion version) { // ATTENTION: This try catch can be avoided, it is only used to add verbose information try @@ -46,9 +46,27 @@ T YamlReader::get( "Error getting required value of type <" << TYPE_NAME(T) << "> in tag <" << tag << "> :\n " << e.what()); } +} - utils::tsnh(utils::Formatter() << "Impossible to arrive to this point."); - return get(yml, version); // Unreachable code +template +void YamlReader::fill( + T& object, + const Yaml& yml, + const TagType& tag, + const YamlReaderVersion version) +{ + // ATTENTION: This try catch can be avoided, it is only used to add verbose information + try + { + return fill(get_value_in_tag(yml, tag), object, version); + } + catch (const std::exception& e) + { + throw utils::ConfigurationException( + utils::Formatter() << + "Error filing object of type <" << TYPE_NAME(T) << + "> in tag <" << tag << "> :\n " << e.what()); + } } template @@ -94,7 +112,7 @@ template std::list YamlReader::get_list( const Yaml& yml, const TagType& tag, - const YamlReaderVersion version /* = LATEST */) + const YamlReaderVersion version) { try { @@ -110,7 +128,7 @@ std::list YamlReader::get_list( template std::list YamlReader::get_list( const Yaml& yml, - const YamlReaderVersion version /* = LATEST */) + const YamlReaderVersion version) { if (!yml.IsSequence()) { @@ -141,7 +159,7 @@ template std::set YamlReader::get_set( const Yaml& yml, const TagType& tag, - const YamlReaderVersion version /* = LATEST */) + const YamlReaderVersion version) { std::list elements_list = get_list(yml, tag, version); return std::set(elements_list.begin(), elements_list.end()); diff --git a/ddsrouter_yaml/src/cpp/YamlReader.cpp b/ddsrouter_yaml/src/cpp/YamlReader.cpp index 9a1c85f81..30f958b7e 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader.cpp @@ -543,249 +543,114 @@ security::TlsConfiguration YamlReader::get( * PARTICIPANTS * ************************/ +////////////////////////////////// +// ParticipantConfiguration template <> -configuration::ParticipantConfiguration YamlReader::get( +void YamlReader::fill( + configuration::ParticipantConfiguration& object, const Yaml& yml, const YamlReaderVersion version) { // Id required - types::ParticipantId id = get(yml, PARTICIPANT_NAME_TAG, version); + object.id_ = get(yml, PARTICIPANT_NAME_TAG, version); // Kind required - types::ParticipantKind kind = get(yml, PARTICIPANT_KIND_TAG, version); - - return configuration::ParticipantConfiguration(id, kind); + object.kind_ = get(yml, PARTICIPANT_KIND_TAG, version); } template <> -configuration::SimpleParticipantConfiguration YamlReader::get( +configuration::ParticipantConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { - // Id required - types::ParticipantId id = get(yml, PARTICIPANT_NAME_TAG, version); + configuration::ParticipantConfiguration object; + fill(object, yml, version); + return object; +} - // Kind required - types::ParticipantKind kind = get(yml, PARTICIPANT_KIND_TAG, version); +////////////////////////////////// +// SimpleParticipantConfiguration +template <> +void YamlReader::fill( + configuration::SimpleParticipantConfiguration& object, + const Yaml& yml, + const YamlReaderVersion version) +{ + // Parent class fill + fill(object, yml, version); // Domain optional - types::DomainId domain; - bool has_domain = is_tag_present(yml, DOMAIN_ID_TAG); - if (has_domain) - { - domain = get(yml, DOMAIN_ID_TAG, version); - } - - if (has_domain) - { - return configuration::SimpleParticipantConfiguration(id, kind, domain); - } - else + if (is_tag_present(yml, DOMAIN_ID_TAG)) { - return configuration::SimpleParticipantConfiguration(id, kind); + object.domain_ = get(yml, DOMAIN_ID_TAG, version); } } -configuration::DiscoveryServerParticipantConfiguration _get_discovery_server_participant_configuration_v1( +template <> +configuration::SimpleParticipantConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { - // Id required - types::ParticipantId id = YamlReader::get(yml, PARTICIPANT_NAME_TAG, version); - - // Kind required - types::ParticipantKind kind = YamlReader::get(yml, PARTICIPANT_KIND_TAG, version); - - // Guid Prefix required - types::GuidPrefix guid = YamlReader::get(yml, version); - - // Domain option - types::DomainId domain; - bool has_domain = YamlReader::is_tag_present(yml, DOMAIN_ID_TAG); - if (has_domain) - { - domain = YamlReader::get(yml, DOMAIN_ID_TAG, version); - } - - // Optional listening addresses - std::set listening_addresses; - if (YamlReader::is_tag_present(yml, LISTENING_ADDRESSES_TAG)) - { - listening_addresses = YamlReader::get_set(yml, LISTENING_ADDRESSES_TAG, version); - } - - // Optional connection addresses - std::set connection_addresses; - if (YamlReader::is_tag_present(yml, CONNECTION_ADDRESSES_TAG)) - { - connection_addresses = YamlReader::get_set( - yml, - CONNECTION_ADDRESSES_TAG, - version); - } - - // Optional TLS - types::security::TlsConfiguration tls; - bool has_tls = YamlReader::is_tag_present(yml, TLS_TAG); - if (has_tls) - { - tls = YamlReader::get(yml, TLS_TAG, version); - } - - if (has_domain) - { - if (has_tls) - { - return configuration::DiscoveryServerParticipantConfiguration( - id, - guid, - listening_addresses, - connection_addresses, - kind, - tls, - domain); - } - else - { - return configuration::DiscoveryServerParticipantConfiguration( - id, - guid, - listening_addresses, - connection_addresses, - domain, - kind); - } - } - else - { - if (has_tls) - { - return configuration::DiscoveryServerParticipantConfiguration( - id, - guid, - listening_addresses, - connection_addresses, - kind, - tls); - } - else - { - return configuration::DiscoveryServerParticipantConfiguration( - id, - guid, - listening_addresses, - connection_addresses, - kind); - } - } + configuration::SimpleParticipantConfiguration object; + fill(object, yml, version); + return object; } -configuration::DiscoveryServerParticipantConfiguration _get_discovery_server_participant_configuration_latest( +////////////////////////////////// +// DiscoveryServerParticipantConfiguration +template <> +void YamlReader::fill( + configuration::DiscoveryServerParticipantConfiguration& object, const Yaml& yml, const YamlReaderVersion version) { - // Id required - types::ParticipantId id = YamlReader::get(yml, PARTICIPANT_NAME_TAG, version); - - // Kind required - types::ParticipantKind kind = YamlReader::get(yml, PARTICIPANT_KIND_TAG, version); - - // Guid Prefix required - types::GuidPrefix guid = YamlReader::get(yml, DISCOVERY_SERVER_GUID_PREFIX_TAG, version); - - // Domain option - types::DomainId domain; - bool has_domain = YamlReader::is_tag_present(yml, DOMAIN_ID_TAG); - if (has_domain) - { - domain = YamlReader::get(yml, DOMAIN_ID_TAG, version); - } + // Parent class fill + fill(object, yml, version); // Optional listening addresses - std::set listening_addresses; if (YamlReader::is_tag_present(yml, LISTENING_ADDRESSES_TAG)) { - listening_addresses = YamlReader::get_set(yml, LISTENING_ADDRESSES_TAG, version); + object.listening_addresses_ = YamlReader::get_set(yml, LISTENING_ADDRESSES_TAG, version); } // Optional connection addresses - std::set connection_addresses; if (YamlReader::is_tag_present(yml, CONNECTION_ADDRESSES_TAG)) { - connection_addresses = YamlReader::get_set(yml, - CONNECTION_ADDRESSES_TAG, - version); + object.connection_addresses_ = YamlReader::get_set( + yml, + CONNECTION_ADDRESSES_TAG, + version); } // Optional TLS - types::security::TlsConfiguration tls; - bool has_tls = YamlReader::is_tag_present(yml, TLS_TAG); - if (has_tls) + if (YamlReader::is_tag_present(yml, TLS_TAG)) { - tls = YamlReader::get(yml, TLS_TAG, version); + object.tls_configuration_ = YamlReader::get(yml, TLS_TAG, version); } - if (has_domain) - { - if (has_tls) - { - return configuration::DiscoveryServerParticipantConfiguration( - id, - guid, - listening_addresses, - connection_addresses, - kind, - tls, - domain); - } - else - { - return configuration::DiscoveryServerParticipantConfiguration( - id, - guid, - listening_addresses, - connection_addresses, - domain, - kind); - } - } - else + // NOTE: The only field that change regarding the version is the GuidPrefix. + switch (version) { - if (has_tls) - { - return configuration::DiscoveryServerParticipantConfiguration( - id, - guid, - listening_addresses, - connection_addresses, - kind, - tls); - } - else - { - return configuration::DiscoveryServerParticipantConfiguration( - id, - guid, - listening_addresses, - connection_addresses, - kind); - } + case V_1_0: + object.discovery_server_guid_prefix_ = + YamlReader::get(yml, version); + break; + + default: + object.discovery_server_guid_prefix_ = + YamlReader::get(yml, DISCOVERY_SERVER_GUID_PREFIX_TAG, version); + break; } } template <> -configuration::DiscoveryServerParticipantConfiguration YamlReader::get( +configuration::DiscoveryServerParticipantConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { - switch (version) - { - case V_1_0: - return _get_discovery_server_participant_configuration_v1(yml, version); - - default: - return _get_discovery_server_participant_configuration_latest(yml, version); - } + configuration::DiscoveryServerParticipantConfiguration object; + fill(object, yml, version); + return object; } /*************************** @@ -827,36 +692,34 @@ YamlReader::get>( } } -core::configuration::DDSRouterConfiguration _get_ddsrouter_configuration_v1( +void _fill_ddsrouter_configuration_v1( + core::configuration::DDSRouterConfiguration& object, const Yaml& yml, const YamlReaderVersion version) { ///// // Get optional allowlist - std::set> allowlist; if (YamlReader::is_tag_present(yml, ALLOWLIST_TAG)) { - allowlist = utils::convert_set_to_shared( + object.allowlist_ = utils::convert_set_to_shared( YamlReader::get_set(yml, ALLOWLIST_TAG, version)); } ///// // Get optional blocklist - std::set> blocklist; if (YamlReader::is_tag_present(yml, BLOCKLIST_TAG)) { - blocklist = utils::convert_set_to_shared( + object.blocklist_ = utils::convert_set_to_shared( YamlReader::get_set(yml, BLOCKLIST_TAG, version)); } ///// // Get builtin topics from allowlist - std::set> builtin_topics; - for (const std::shared_ptr& topic : allowlist) + for (const std::shared_ptr& topic : object.allowlist_) { if (RealTopic::is_real_topic(topic->topic_name(), topic->topic_type())) { - builtin_topics.emplace( + object.builtin_topics_.emplace( std::make_shared( topic->topic_name(), topic->topic_type(), @@ -866,8 +729,6 @@ core::configuration::DDSRouterConfiguration _get_ddsrouter_configuration_v1( ///// // Get participants configurations from this yaml level - std::set> participants_configurations; - for (Yaml::const_iterator participant_it = yml.begin(); participant_it != yml.end(); ++participant_it) @@ -906,55 +767,44 @@ core::configuration::DDSRouterConfiguration _get_ddsrouter_configuration_v1( participant_yml[PARTICIPANT_KIND_TAG] = participant_yml[PARTICIPANT_KIND_TAG_V1]; // Add new Participant with its configuration - participants_configurations.insert( + object.participants_configurations_.insert( YamlReader::get>( participant_yml, version)); } - - ///// - // Construct object - return core::configuration::DDSRouterConfiguration( - allowlist, - blocklist, - builtin_topics, - participants_configurations); } -core::configuration::DDSRouterConfiguration _get_ddsrouter_configuration_latest( +void _fill_ddsrouter_configuration_latest( + core::configuration::DDSRouterConfiguration& object, const Yaml& yml, const YamlReaderVersion version) { ///// // Get optional allowlist - std::set> allowlist; if (YamlReader::is_tag_present(yml, ALLOWLIST_TAG)) { - allowlist = utils::convert_set_to_shared( + object.allowlist_ = utils::convert_set_to_shared( YamlReader::get_set(yml, ALLOWLIST_TAG, version)); } ///// // Get optional blocklist - std::set> blocklist; if (YamlReader::is_tag_present(yml, BLOCKLIST_TAG)) { - blocklist = utils::convert_set_to_shared( + object.blocklist_ = utils::convert_set_to_shared( YamlReader::get_set(yml, BLOCKLIST_TAG, version)); } ///// // Get optional builtin topics - std::set> builtin_topics; if (YamlReader::is_tag_present(yml, BUILTIN_TAG)) { - builtin_topics = utils::convert_set_to_shared( + object.builtin_topics_ = utils::convert_set_to_shared( YamlReader::get_set(yml, BUILTIN_TAG, version)); } ///// // Get participants configurations. Required field, if get_value_in_tag fail propagate exception. - std::set> participants_configurations; auto participants_configurations_yml = YamlReader::get_value_in_tag(yml, COLLECTION_PARTICIPANTS_TAG); // TODO do it in a single instruction @@ -969,38 +819,17 @@ core::configuration::DDSRouterConfiguration _get_ddsrouter_configuration_latest( for (auto conf : participants_configurations_yml) { - participants_configurations.insert( + object.participants_configurations_.insert( YamlReader::get>(conf, version)); } ///// // Get optional number of threads - int number_of_threads; - bool has_number_of_threads = YamlReader::is_tag_present(yml, NUMBER_THREADS_TAG); - if (has_number_of_threads) + if (YamlReader::is_tag_present(yml, NUMBER_THREADS_TAG)) { - number_of_threads = YamlReader::get(yml, NUMBER_THREADS_TAG, version); + object.number_of_threads_ = YamlReader::get(yml, NUMBER_THREADS_TAG, version); } - ///// - // Construct object - if (has_number_of_threads) - { - return core::configuration::DDSRouterConfiguration( - allowlist, - blocklist, - builtin_topics, - participants_configurations, - number_of_threads); - } - else - { - return core::configuration::DDSRouterConfiguration( - allowlist, - blocklist, - builtin_topics, - participants_configurations); - } } template <> @@ -1008,14 +837,18 @@ core::configuration::DDSRouterConfiguration YamlReader::get random_participan return std::make_shared( id, + kind, + random_domain(seed), random_guid_prefix(seed), std::set
(), std::set({connection_address}), - kind); + security::TlsConfiguration()); } // Add cases where Participants need specific arguments diff --git a/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp index e007c05b5..b44563128 100644 --- a/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp @@ -274,7 +274,7 @@ TEST(YamlReaderConfigurationTest, number_of_threads) YamlReaderConfiguration::load_ddsrouter_configuration(yml); // Check threads are correct - ASSERT_EQ(test_case, configuration_result.number_of_threads()); + ASSERT_EQ(test_case, configuration_result.number_of_threads_); } } diff --git a/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp b/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp index e1d705451..fad69f6d9 100644 --- a/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp +++ b/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp @@ -53,19 +53,19 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_trivial) ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check Topics are empty - ASSERT_EQ(configuration_result.allowlist(), std::set>()); - ASSERT_EQ(configuration_result.blocklist(), std::set>()); - ASSERT_EQ(configuration_result.builtin_topics(), std::set>()); + ASSERT_EQ(configuration_result.allowlist_, std::set>()); + ASSERT_EQ(configuration_result.blocklist_, std::set>()); + ASSERT_EQ(configuration_result.builtin_topics_, std::set>()); // Check Participant configurations std::set> - participant_configurations = configuration_result.participants_configurations(); + participant_configurations = configuration_result.participants_configurations_; ASSERT_EQ(participant_configurations.size(), 2); for (auto participant : participant_configurations) { - ASSERT_EQ(participant->kind(), core::types::ParticipantKind::echo); + ASSERT_EQ(participant->kind_, core::types::ParticipantKind::echo); } } @@ -104,11 +104,11 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_ros_case) ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check Topic lists are empty - ASSERT_EQ(configuration_result.allowlist(), std::set>()); - ASSERT_EQ(configuration_result.blocklist(), std::set>()); + ASSERT_EQ(configuration_result.allowlist_, std::set>()); + ASSERT_EQ(configuration_result.blocklist_, std::set>()); // Check Builtin Topics has one correct topic - std::set> builtin_result = configuration_result.builtin_topics(); + std::set> builtin_result = configuration_result.builtin_topics_; ASSERT_EQ(builtin_result.size(), 1); std::shared_ptr topic_result = (*builtin_result.begin()); ASSERT_EQ(topic_result->topic_name(), "rt/chatter"); @@ -118,13 +118,13 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_ros_case) // Check Participant configurations std::set> - participant_configurations = configuration_result.participants_configurations(); + participant_configurations = configuration_result.participants_configurations_; ASSERT_EQ(participant_configurations.size(), 3); for (auto participant : participant_configurations) { - ASSERT_EQ(participant->kind(), core::types::ParticipantKind::simple_rtps); + ASSERT_EQ(participant->kind_, core::types::ParticipantKind::simple_rtps); } } @@ -154,19 +154,19 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_trivial_v1) ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check Topics are empty - ASSERT_EQ(configuration_result.allowlist(), std::set>()); - ASSERT_EQ(configuration_result.blocklist(), std::set>()); - ASSERT_EQ(configuration_result.builtin_topics(), std::set>()); + ASSERT_EQ(configuration_result.allowlist_, std::set>()); + ASSERT_EQ(configuration_result.blocklist_, std::set>()); + ASSERT_EQ(configuration_result.builtin_topics_, std::set>()); // Check Participant configurations std::set> - participant_configurations = configuration_result.participants_configurations(); + participant_configurations = configuration_result.participants_configurations_; ASSERT_EQ(participant_configurations.size(), 2); for (auto participant : participant_configurations) { - ASSERT_EQ(participant->kind(), core::types::ParticipantKind::echo); + ASSERT_EQ(participant->kind_, core::types::ParticipantKind::echo); } } @@ -201,14 +201,14 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_builtin_v1) ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check block Topics are empty - ASSERT_EQ(configuration_result.blocklist(), std::set>()); + ASSERT_EQ(configuration_result.blocklist_, std::set>()); // Check allowlist has 2 topics - std::set> allowlist_result = configuration_result.allowlist(); + std::set> allowlist_result = configuration_result.allowlist_; ASSERT_EQ(allowlist_result.size(), 2); // Check Builtin Topics has one correct topic - std::set> builtin_result = configuration_result.builtin_topics(); + std::set> builtin_result = configuration_result.builtin_topics_; ASSERT_EQ(builtin_result.size(), 1); std::shared_ptr topic_result = (*builtin_result.begin()); ASSERT_EQ(topic_result->topic_name(), "topic1"); @@ -217,13 +217,13 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_builtin_v1) // Check Participant configurations std::set> - participant_configurations = configuration_result.participants_configurations(); + participant_configurations = configuration_result.participants_configurations_; ASSERT_EQ(participant_configurations.size(), 2); for (auto participant : participant_configurations) { - ASSERT_EQ(participant->kind(), core::types::ParticipantKind::echo); + ASSERT_EQ(participant->kind_, core::types::ParticipantKind::echo); } } @@ -260,20 +260,20 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_discovery_se ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check Topics are empty - ASSERT_EQ(configuration_result.allowlist(), std::set>()); - ASSERT_EQ(configuration_result.blocklist(), std::set>()); - ASSERT_EQ(configuration_result.builtin_topics(), std::set>()); + ASSERT_EQ(configuration_result.allowlist_, std::set>()); + ASSERT_EQ(configuration_result.blocklist_, std::set>()); + ASSERT_EQ(configuration_result.builtin_topics_, std::set>()); // Check Participant configurations std::set> - participant_configurations = configuration_result.participants_configurations(); + participant_configurations = configuration_result.participants_configurations_; ASSERT_EQ(participant_configurations.size(), 2); for (std::shared_ptr participant : participant_configurations) { // If it is not the discovery server participant, continue - if (!(participant->kind() == core::types::ParticipantKind::local_discovery_server)) + if (!(participant->kind_ == core::types::ParticipantKind::local_discovery_server)) { continue; } @@ -284,18 +284,18 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_discovery_se std::dynamic_pointer_cast(participant); // Check Name - ASSERT_EQ(ds_participant->id(), core::types::ParticipantId("participant2")); + ASSERT_EQ(ds_participant->id_, core::types::ParticipantId("participant2")); // Check GuidPrefix ASSERT_EQ( - ds_participant->discovery_server_guid_prefix(), + ds_participant->discovery_server_guid_prefix_, core::types::GuidPrefix(true, 3)); // Check Connection addresses ASSERT_EQ( - ds_participant->connection_addresses().size(), + ds_participant->connection_addresses_.size(), 1); - core::types::DiscoveryServerConnectionAddress address = *ds_participant->connection_addresses().begin(); + core::types::DiscoveryServerConnectionAddress address = *ds_participant->connection_addresses_.begin(); ASSERT_EQ( address, (core::types::DiscoveryServerConnectionAddress( diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp index a50939d61..a595a2066 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp @@ -54,8 +54,8 @@ TEST(YamlGetCommonParticipantConfigurationTest, get_participant) YamlReader::get(yml, "participant", LATEST); // Check result - ASSERT_EQ(id, result.id()); - ASSERT_EQ(kind, result.kind()); + ASSERT_EQ(id, result.id_); + ASSERT_EQ(kind, result.kind_); } } } diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp index 664675a78..70ab74ed6 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp @@ -60,9 +60,9 @@ TEST(YamlGetSimpleParticipantConfigurationTest, get_participant) LATEST); // Check result - ASSERT_EQ(id, result.id()); - ASSERT_EQ(kind, result.kind()); - ASSERT_EQ(domain, result.domain()); + ASSERT_EQ(id, result.id_); + ASSERT_EQ(kind, result.kind_); + ASSERT_EQ(domain, result.domain_); } } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp index e48534afd..d263a6319 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp @@ -81,10 +81,10 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect LATEST); // Check result - ASSERT_EQ(1, result.connection_addresses().size()); - ASSERT_EQ(1, result.connection_addresses().begin()->addresses().size()); - ASSERT_EQ(connection_guid, result.connection_addresses().begin()->discovery_server_guid_prefix()); - ASSERT_EQ(address, *result.connection_addresses().begin()->addresses().begin()); + ASSERT_EQ(1, result.connection_addresses_.size()); + ASSERT_EQ(1, result.connection_addresses_.begin()->addresses().size()); + ASSERT_EQ(connection_guid, result.connection_addresses_.begin()->discovery_server_guid_prefix()); + ASSERT_EQ(address, *result.connection_addresses_.begin()->addresses().begin()); } // 1 connection N addresses @@ -130,15 +130,15 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect LATEST); // Check result - ASSERT_EQ(1, result.connection_addresses().size()); - ASSERT_EQ(addresses.size(), result.connection_addresses().begin()->addresses().size()); - ASSERT_EQ(connection_guid, result.connection_addresses().begin()->discovery_server_guid_prefix()); + ASSERT_EQ(1, result.connection_addresses_.size()); + ASSERT_EQ(addresses.size(), result.connection_addresses_.begin()->addresses().size()); + ASSERT_EQ(connection_guid, result.connection_addresses_.begin()->discovery_server_guid_prefix()); // Check every address is inside connection addresses of the configuration for (core::types::Address address : addresses) { // ATTENTION: this previous declaration is needed as listening_addresses() does not return a reference std::set addresses_result = - result.connection_addresses().begin()->addresses(); + result.connection_addresses_.begin()->addresses(); ASSERT_NE( addresses_result.find(address), addresses_result.end()); @@ -191,9 +191,9 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect LATEST); // Check result - ASSERT_EQ(connection_guids.size(), result.connection_addresses().size()); + ASSERT_EQ(connection_guids.size(), result.connection_addresses_.size()); // Check that every connection has a correct number of addresses and a guid given - for (core::types::DiscoveryServerConnectionAddress connection : result.connection_addresses()) + for (core::types::DiscoveryServerConnectionAddress connection : result.connection_addresses_) { ASSERT_NE( std::find(connection_guids.begin(), connection_guids.end(), connection.discovery_server_guid_prefix()) diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp index f08a7c26f..d4284cff6 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp @@ -63,7 +63,7 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_domain) LATEST); // Check result - ASSERT_EQ(domain, result.domain()); + ASSERT_EQ(domain, result.domain_); } // incorrect domain format diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp index fb9fda568..620a2d955 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp @@ -69,8 +69,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni LATEST); // Check result - ASSERT_EQ(1, result.listening_addresses().size()); - ASSERT_EQ(address, *result.listening_addresses().begin()); + ASSERT_EQ(1, result.listening_addresses_.size()); + ASSERT_EQ(address, *result.listening_addresses_.begin()); } // N addresses @@ -107,12 +107,12 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni LATEST); // Check result - ASSERT_EQ(addresses.size(), result.listening_addresses().size()) << yml; + ASSERT_EQ(addresses.size(), result.listening_addresses_.size()) << yml; // Check every address is inside listening addresses of the configuration for (core::types::Address address : addresses) { // ATTENTION: this previous declaration is needed as listening_addresses() does not return a reference - std::set addresses_result = result.listening_addresses(); + std::set addresses_result = result.listening_addresses_; ASSERT_NE( addresses_result.find(address), addresses_result.end()); diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp index 083edda84..4aabb5f32 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp @@ -61,17 +61,17 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_minimum LATEST); // Check result - ASSERT_EQ(id, result.id()); - ASSERT_EQ(kind, result.kind()); - ASSERT_EQ(guid, result.discovery_server_guid_prefix()); + ASSERT_EQ(id, result.id_); + ASSERT_EQ(kind, result.kind_); + ASSERT_EQ(guid, result.discovery_server_guid_prefix_); // Check default values - ASSERT_EQ(0, result.connection_addresses().size()); - ASSERT_EQ(0, result.listening_addresses().size()); - ASSERT_FALSE(result.tls_active()); + ASSERT_EQ(0, result.connection_addresses_.size()); + ASSERT_EQ(0, result.listening_addresses_.size()); + ASSERT_FALSE(result.tls_configuration_.is_active()); ASSERT_EQ( - core::configuration::DiscoveryServerParticipantConfiguration::default_domain_id(), - result.domain()); + core::configuration::DiscoveryServerParticipantConfiguration().domain_, + result.domain_); } } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp index 9691aaae0..3a6642939 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp @@ -156,16 +156,16 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, tls_configuration_inact LATEST); // Check tls_configuration - ASSERT_FALSE(ds_participant_cfg.tls_configuration().compatible()); - ASSERT_FALSE(ds_participant_cfg.tls_configuration().compatible()); - ASSERT_FALSE(ds_participant_cfg.tls_configuration().compatible()); - ASSERT_FALSE(ds_participant_cfg.tls_configuration().is_active()); - - ASSERT_THROW(ds_participant_cfg.tls_configuration().certificate_authority_file(), utils::InconsistencyException); - ASSERT_THROW(ds_participant_cfg.tls_configuration().private_key_file_password(), utils::InconsistencyException); - ASSERT_THROW(ds_participant_cfg.tls_configuration().private_key_file(), utils::InconsistencyException); - ASSERT_THROW(ds_participant_cfg.tls_configuration().certificate_chain_file(), utils::InconsistencyException); - ASSERT_THROW(ds_participant_cfg.tls_configuration().dh_params_file(), utils::InconsistencyException); + ASSERT_FALSE(ds_participant_cfg.tls_configuration_.compatible()); + ASSERT_FALSE(ds_participant_cfg.tls_configuration_.compatible()); + ASSERT_FALSE(ds_participant_cfg.tls_configuration_.compatible()); + ASSERT_FALSE(ds_participant_cfg.tls_configuration_.is_active()); + + ASSERT_THROW(ds_participant_cfg.tls_configuration_.certificate_authority_file(), utils::InconsistencyException); + ASSERT_THROW(ds_participant_cfg.tls_configuration_.private_key_file_password(), utils::InconsistencyException); + ASSERT_THROW(ds_participant_cfg.tls_configuration_.private_key_file(), utils::InconsistencyException); + ASSERT_THROW(ds_participant_cfg.tls_configuration_.certificate_chain_file(), utils::InconsistencyException); + ASSERT_THROW(ds_participant_cfg.tls_configuration_.dh_params_file(), utils::InconsistencyException); } TEST(YamlGetDiscoveryServerParticipantConfigurationTest, tls_configuration_incorrect_empty) From 34d59b88dba10f7cc08505784c70f3ddf6ccc6f3 Mon Sep 17 00:00:00 2001 From: jparisu Date: Wed, 27 Jul 2022 15:14:14 +0200 Subject: [PATCH 2/5] Refs #15188: apply suggestions Signed-off-by: jparisu --- .dev/README.md | 2 +- .../configuration/BaseConfiguration.hpp | 2 +- .../configuration/DDSRouterConfiguration.hpp | 2 +- .../SimpleParticipantConfiguration.hpp | 4 +- ...iscoveryServerParticipantConfiguration.cpp | 51 +++++++++++++++++++ .../include/ddsrouter_yaml/YamlReader.hpp | 6 +-- .../ddsrouter_yaml/impl/YamlReader.ipp | 2 +- 7 files changed, 60 insertions(+), 9 deletions(-) diff --git a/.dev/README.md b/.dev/README.md index fb2ee5a66..d2a8f88d3 100644 --- a/.dev/README.md +++ b/.dev/README.md @@ -164,7 +164,7 @@ These are the log levels and when to use them Configurations are data structures with public access to their internal values. This makes it easier to work with them: to create, manage and copy them. -The default values will be defined in the header, so every used could know which are them, and always +The default values will be defined in the header, so every user could know which are them, and always have a default constructor. From every internal object that requires a configuration to be created, the configuration argument diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/BaseConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/BaseConfiguration.hpp index 016c5fca7..d342e9277 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/BaseConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/BaseConfiguration.hpp @@ -31,7 +31,7 @@ namespace configuration { /** * Configurations in DDS Router are data structures with public access to its internal methods. * Thus, they are not forced to be correct in construction. - * This is an Interface class that forces every configuration in ddsrouter to have a \c is_valid method. + * This is an Interface class that forces every configuration in ddsrouter to have an \c is_valid method. */ struct BaseConfiguration { diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp index 97470adad..56d87448a 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp @@ -71,7 +71,7 @@ struct DDSRouterConfiguration : public DDSRouterReloadConfiguration std::set> participants_configurations_ = {}; - unsigned int number_of_threads_ = 10; + unsigned int number_of_threads_ = 12; }; } /* namespace configuration */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp index 24886302f..1b2f0af27 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp @@ -29,9 +29,9 @@ namespace core { namespace configuration { /** - * This class joins Simple Participant Configuration features and give methods to interact with it. + * This dat struct represents a configuration for a SimpleParticipant */ -class SimpleParticipantConfiguration : public ParticipantConfiguration +struct SimpleParticipantConfiguration : public ParticipantConfiguration { public: diff --git a/ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp index e1fb30dfd..c62e0b516 100644 --- a/ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp @@ -61,6 +61,57 @@ bool DiscoveryServerParticipantConfiguration::is_valid( return false; } + // Check listening addresses + for (Address address : listening_addresses_) + { + if (!address.is_valid()) + { + error_msg << "Incorrect address " << address << " in listening addresses. "; + return false; + } + } + + // Check connection addresses + for (DiscoveryServerConnectionAddress address : connection_addresses_) + { + if (!address.is_valid()) + { + error_msg << "Incorrect address " << address << " in connection addresses. "; + return false; + } + } + + // Check exist at least one address + if (listening_addresses_.empty() && connection_addresses_.empty()) + { + error_msg << "No listening or connection address specified. "; + return false; + } + + // If active, check it is valid + if (tls_configuration_.is_active()) + { + // If has listening addresses, it should be able to provide TLS server configuration + if (!listening_addresses_.empty()) + { + if (!tls_configuration_.compatible()) + { + error_msg << "TLS requires to support Server Configuration if listening addresses set. "; + return false; + } + } + + // If has connection addresses, it should be able to provide TLS client configuration + if (!connection_addresses_.empty()) + { + if (!tls_configuration_.compatible()) + { + error_msg << "TLS requires to support Client Configuration if connection addresses set. "; + return false; + } + } + } + return true; } diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp b/ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp index 4357ccf98..537d576e6 100644 --- a/ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp +++ b/ddsrouter_yaml/include/ddsrouter_yaml/YamlReader.hpp @@ -140,11 +140,11 @@ class DDSROUTER_YAML_DllAPI YamlReader /** * @brief Fill an element given by parameter with the values inside \c yml * - * This method simplifies the process of retrieving an object which parent has its own \c fill method, + * This method simplifies the process of retrieving an object whose parent has its own \c fill method, * as the code is reused from one another calling parent \c fill in child. * It is also very helpful to handle default creation values. Without this, every different default value - * must have its own it-else clause, forcing to create the respective constructor. With this method, - * the default values are initialized in with the default constructor, and then are overwritten by the yaml. + * must have its own if-else clause, forcing to create the respective constructor. With this method, + * the default values are initialized with the default constructor, and then are overwritten by the yaml. * [this problem arises because C++ does not allow different order of parameters in method call] */ template diff --git a/ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp b/ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp index fb8fa60fc..046fc95a2 100644 --- a/ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp +++ b/ddsrouter_yaml/include/ddsrouter_yaml/impl/YamlReader.ipp @@ -64,7 +64,7 @@ void YamlReader::fill( { throw utils::ConfigurationException( utils::Formatter() << - "Error filing object of type <" << TYPE_NAME(T) << + "Error filling object of type <" << TYPE_NAME(T) << "> in tag <" << tag << "> :\n " << e.what()); } } From a1a0aaf3fd09eb0c75c0e0cac87f40d7dfef0f06 Mon Sep 17 00:00:00 2001 From: jparisu Date: Wed, 27 Jul 2022 20:18:12 +0200 Subject: [PATCH 3/5] Refs #15188: change names of protected variables Signed-off-by: jparisu --- ...iscoveryServerParticipantConfiguration.hpp | 8 +++--- .../participant/ParticipantConfiguration.hpp | 4 +-- .../SimpleParticipantConfiguration.hpp | 2 +- .../configuration/DDSRouterConfiguration.cpp | 4 +-- ...iscoveryServerParticipantConfiguration.cpp | 28 +++++++++---------- .../participant/ParticipantConfiguration.cpp | 14 +++++----- .../SimpleParticipantConfiguration.cpp | 8 +++--- ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp | 2 +- .../src/cpp/core/ParticipantFactory.cpp | 18 ++++++------ .../auxiliar/impl/BaseParticipant.ipp | 8 +++--- .../rtps/impl/CommonRTPSRouterParticipant.ipp | 4 +-- .../rtps/impl/DiscoveryServerParticipant.ipp | 8 +++--- ddsrouter_yaml/src/cpp/YamlReader.cpp | 16 +++++------ .../YamlGetConfigurationDDSRouterTest.cpp | 18 ++++++------ ...lGetCommonParticipantConfigurationTest.cpp | 4 +-- ...lGetSimpleParticipantConfigurationTest.cpp | 6 ++-- ...t_get_participant_connection_addresses.ipp | 20 ++++++------- ...nfigurationTest_get_participant_domain.ipp | 2 +- ...st_get_participant_listening_addresses.ipp | 8 +++--- ...figurationTest_get_participant_minimum.ipp | 16 +++++------ ...tConfigurationTest_get_participant_tls.ipp | 20 ++++++------- 21 files changed, 109 insertions(+), 109 deletions(-) diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/participant/DiscoveryServerParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/participant/DiscoveryServerParticipantConfiguration.hpp index 9bf231516..22b7936dc 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/participant/DiscoveryServerParticipantConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/participant/DiscoveryServerParticipantConfiguration.hpp @@ -68,13 +68,13 @@ struct DiscoveryServerParticipantConfiguration : public SimpleParticipantConfigu // VARIABLES ///////////////////////// - types::GuidPrefix discovery_server_guid_prefix_ = types::GuidPrefix(); + types::GuidPrefix discovery_server_guid_prefix = types::GuidPrefix(); - std::set listening_addresses_ = {}; + std::set listening_addresses = {}; - std::set connection_addresses_ = {}; + std::set connection_addresses = {}; - types::security::TlsConfiguration tls_configuration_ = types::security::TlsConfiguration(); + types::security::TlsConfiguration tls_configuration = types::security::TlsConfiguration(); }; } /* namespace configuration */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/participant/ParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/participant/ParticipantConfiguration.hpp index e5a4aa12a..f8ff1cbf9 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/participant/ParticipantConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/participant/ParticipantConfiguration.hpp @@ -63,10 +63,10 @@ struct ParticipantConfiguration : public BaseConfiguration ///////////////////////// //! Participant Id associated with this configuration - types::ParticipantId id_; + types::ParticipantId id; //! Participant Kind of the Participant that this configuration refers. - types::ParticipantKind kind_; + types::ParticipantKind kind; }; } /* namespace configuration */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp index 1b2f0af27..fd75fb0c1 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp @@ -65,7 +65,7 @@ struct SimpleParticipantConfiguration : public ParticipantConfiguration // VARIABLES ///////////////////////// - types::DomainId domain_ = types::DomainId(0u); + types::DomainId domain = types::DomainId(0u); }; } /* namespace configuration */ diff --git a/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp index 0573aa95e..5767ca2fe 100644 --- a/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp @@ -77,12 +77,12 @@ bool DDSRouterConfiguration::is_valid( // Check configuration is valid if (!configuration->is_valid(error_msg)) { - error_msg << "Error in Participant " << configuration->id_ << ". "; + error_msg << "Error in Participant " << configuration->id << ". "; return false; } // Store every id in a set to see if there are repetitions - ids.insert(configuration->id_); + ids.insert(configuration->id); } // If the number of ids are not equal the number of configurations, is because they are repeated diff --git a/ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp index c62e0b516..d5506489c 100644 --- a/ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/participant/DiscoveryServerParticipantConfiguration.cpp @@ -37,10 +37,10 @@ DiscoveryServerParticipantConfiguration::DiscoveryServerParticipantConfiguration const std::set& connection_addresses, const types::security::TlsConfiguration tls_configuration) : SimpleParticipantConfiguration(id, kind, domain_id) - , discovery_server_guid_prefix_(discovery_server_guid_prefix) - , listening_addresses_(listening_addresses) - , connection_addresses_(connection_addresses) - , tls_configuration_(tls_configuration) + , discovery_server_guid_prefix(discovery_server_guid_prefix) + , listening_addresses(listening_addresses) + , connection_addresses(connection_addresses) + , tls_configuration(tls_configuration) { // Do nothing } @@ -55,14 +55,14 @@ bool DiscoveryServerParticipantConfiguration::is_valid( } // Check DS Guid Prefix - if (!discovery_server_guid_prefix_.is_valid()) + if (!discovery_server_guid_prefix.is_valid()) { - error_msg << "Non valid Participant Guid Prefix " << discovery_server_guid_prefix_ << ". "; + error_msg << "Non valid Participant Guid Prefix " << discovery_server_guid_prefix << ". "; return false; } // Check listening addresses - for (Address address : listening_addresses_) + for (Address address : listening_addresses) { if (!address.is_valid()) { @@ -72,7 +72,7 @@ bool DiscoveryServerParticipantConfiguration::is_valid( } // Check connection addresses - for (DiscoveryServerConnectionAddress address : connection_addresses_) + for (DiscoveryServerConnectionAddress address : connection_addresses) { if (!address.is_valid()) { @@ -82,19 +82,19 @@ bool DiscoveryServerParticipantConfiguration::is_valid( } // Check exist at least one address - if (listening_addresses_.empty() && connection_addresses_.empty()) + if (listening_addresses.empty() && connection_addresses.empty()) { error_msg << "No listening or connection address specified. "; return false; } // If active, check it is valid - if (tls_configuration_.is_active()) + if (tls_configuration.is_active()) { // If has listening addresses, it should be able to provide TLS server configuration - if (!listening_addresses_.empty()) + if (!listening_addresses.empty()) { - if (!tls_configuration_.compatible()) + if (!tls_configuration.compatible()) { error_msg << "TLS requires to support Server Configuration if listening addresses set. "; return false; @@ -102,9 +102,9 @@ bool DiscoveryServerParticipantConfiguration::is_valid( } // If has connection addresses, it should be able to provide TLS client configuration - if (!connection_addresses_.empty()) + if (!connection_addresses.empty()) { - if (!tls_configuration_.compatible()) + if (!tls_configuration.compatible()) { error_msg << "TLS requires to support Client Configuration if connection addresses set. "; return false; diff --git a/ddsrouter_core/src/cpp/configuration/participant/ParticipantConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/participant/ParticipantConfiguration.cpp index cd490f6ea..c3a4bbb1b 100644 --- a/ddsrouter_core/src/cpp/configuration/participant/ParticipantConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/participant/ParticipantConfiguration.cpp @@ -31,23 +31,23 @@ using namespace eprosima::ddsrouter::core::types; ParticipantConfiguration::ParticipantConfiguration( const ParticipantId& id, const ParticipantKind& kind) noexcept - : id_(id) - , kind_(kind) + : id(id) + , kind(kind) { } bool ParticipantConfiguration::is_valid( utils::Formatter& error_msg) const noexcept { - if (!id_.is_valid()) + if (!id.is_valid()) { - error_msg << "Non valid Participant Id " << id_ << ". "; + error_msg << "Non valid Participant Id " << id << ". "; return false; } - if (kind_ == ParticipantKind::invalid) + if (kind == ParticipantKind::invalid) { - error_msg << "Non valid Participant kind " << kind_ << ". "; + error_msg << "Non valid Participant kind " << kind << ". "; return false; } @@ -57,7 +57,7 @@ bool ParticipantConfiguration::is_valid( bool ParticipantConfiguration::operator ==( const ParticipantConfiguration& other) const noexcept { - return this->id_ == other.id_ && this->kind_ == other.kind_; + return this->id == other.id && this->kind == other.kind; } } /* namespace configuration */ diff --git a/ddsrouter_core/src/cpp/configuration/participant/SimpleParticipantConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/participant/SimpleParticipantConfiguration.cpp index 62c7b8285..742bba4c6 100644 --- a/ddsrouter_core/src/cpp/configuration/participant/SimpleParticipantConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/participant/SimpleParticipantConfiguration.cpp @@ -31,7 +31,7 @@ SimpleParticipantConfiguration::SimpleParticipantConfiguration( const ParticipantKind& kind /* = ParticipantKind::simple_rtps */, const DomainId& domain_id /* = DEFAULT_DOMAIN_ID_ */) noexcept : ParticipantConfiguration(id, kind) - , domain_(domain_id) + , domain(domain_id) { } @@ -43,9 +43,9 @@ bool SimpleParticipantConfiguration::is_valid( return false; } - if (!domain_.is_valid()) + if (!domain.is_valid()) { - error_msg << "Incorrect domain " << domain_ << ". "; + error_msg << "Incorrect domain " << domain << ". "; return false; } @@ -57,7 +57,7 @@ bool SimpleParticipantConfiguration::operator ==( { return ParticipantConfiguration::operator ==( other) && - this->domain_ == other.domain_; + this->domain == other.domain; } } /* namespace configuration */ diff --git a/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp b/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp index b9d179f06..98e1e645c 100644 --- a/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp +++ b/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp @@ -296,7 +296,7 @@ void DDSRouterImpl::init_participants_() { // Failed to create participant throw utils::InitializationException(utils::Formatter() - << "Failed to create creating Participant " << participant_config->id_); + << "Failed to create creating Participant " << participant_config->id); } logInfo(DDSROUTER, "Participant created with id: " << new_participant->id() diff --git a/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp b/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp index d7188b96b..8d2086375 100644 --- a/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp +++ b/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp @@ -45,11 +45,11 @@ std::shared_ptr ParticipantFactory::create_participant( std::shared_ptr discovery_database) { // Create a new Participant depending on the ParticipantKind specified by the configuration - switch (participant_configuration->kind_) + switch (participant_configuration->kind) { case ParticipantKind::blank: // BlankParticipant - return std::make_shared(participant_configuration->id_); + return std::make_shared(participant_configuration->id); case ParticipantKind::echo: // EchoParticipant @@ -68,8 +68,8 @@ std::shared_ptr ParticipantFactory::create_participant( if (!conf_) { throw utils::ConfigurationException( - utils::Formatter() << "Configuration from Participant: " << participant_configuration->id_ << - " is not for Participant Kind: " << participant_configuration->kind_); + utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << + " is not for Participant Kind: " << participant_configuration->kind); } return std::make_shared ( @@ -87,8 +87,8 @@ std::shared_ptr ParticipantFactory::create_participant( if (!conf_) { throw utils::ConfigurationException( - utils::Formatter() << "Configuration from Participant: " << participant_configuration->id_ << " is not for Participant Kind: " << - participant_configuration->kind_); + utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << " is not for Participant Kind: " << + participant_configuration->kind); } return std::make_shared ( @@ -106,8 +106,8 @@ std::shared_ptr ParticipantFactory::create_participant( if (!conf_) { throw utils::ConfigurationException( - utils::Formatter() << "Configuration from Participant: " << participant_configuration->id_ << " is not for Participant Kind: " << - participant_configuration->kind_); + utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << " is not for Participant Kind: " << + participant_configuration->kind); } return std::make_shared ( @@ -117,7 +117,7 @@ std::shared_ptr ParticipantFactory::create_participant( } case ParticipantKind::invalid: - throw utils::ConfigurationException(utils::Formatter() << "Kind: " << participant_configuration->kind_ + throw utils::ConfigurationException(utils::Formatter() << "Kind: " << participant_configuration->kind << " is not a valid participant kind name."); default: diff --git a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/impl/BaseParticipant.ipp b/ddsrouter_core/src/cpp/participant/implementations/auxiliar/impl/BaseParticipant.ipp index 1c4d6a4ad..58c2e740e 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/auxiliar/impl/BaseParticipant.ipp +++ b/ddsrouter_core/src/cpp/participant/implementations/auxiliar/impl/BaseParticipant.ipp @@ -68,7 +68,7 @@ types::ParticipantId BaseParticipant::id() const noexcept { std::lock_guard lock(mutex_); - return configuration_.id_; + return configuration_.id; } template @@ -76,7 +76,7 @@ types::ParticipantKind BaseParticipant::kind() const noexcept { std::lock_guard lock(mutex_); - return configuration_.kind_; + return configuration_.kind; } template @@ -178,7 +178,7 @@ void BaseParticipant::delete_reader_( template types::ParticipantId BaseParticipant::id_nts_() const noexcept { - return configuration_.id_; + return configuration_.id; } template @@ -186,7 +186,7 @@ std::ostream& operator <<( std::ostream& os, const BaseParticipant& participant) { - os << "{" << participant.id() << ";" << participant.configuration_.kind_ << "}"; + os << "{" << participant.id() << ";" << participant.configuration_.kind << "}"; return os; } diff --git a/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/CommonRTPSRouterParticipant.ipp b/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/CommonRTPSRouterParticipant.ipp index c420f8c79..bcf74a9f7 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/CommonRTPSRouterParticipant.ipp +++ b/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/CommonRTPSRouterParticipant.ipp @@ -213,7 +213,7 @@ void CommonRTPSRouterParticipant::onWriterDiscovery( template void CommonRTPSRouterParticipant::create_participant_() { - types::DomainId domain = this->configuration_.domain_; + types::DomainId domain = this->configuration_.domain; fastrtps::rtps::RTPSParticipantAttributes params = participant_attributes_(); logInfo(DDSROUTER_RTPS_PARTICIPANT, @@ -232,7 +232,7 @@ void CommonRTPSRouterParticipant::create_participant_() } logInfo(DDSROUTER_RTPS_PARTICIPANT, - "New Participant " << this->configuration_.kind_ << + "New Participant " << this->configuration_.kind << " created with id " << this->id() << " in domain " << domain << " with guid " << rtps_participant_->getGuid()); } diff --git a/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/DiscoveryServerParticipant.ipp b/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/DiscoveryServerParticipant.ipp index 34b84474f..69ef53886 100644 --- a/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/DiscoveryServerParticipant.ipp +++ b/ddsrouter_core/src/cpp/participant/implementations/rtps/impl/DiscoveryServerParticipant.ipp @@ -52,11 +52,11 @@ fastrtps::rtps::RTPSParticipantAttributes DiscoveryServerParticipant::participant_attributes_() const { // Get Configuration information - std::set listening_addresses = this->configuration_.listening_addresses_; + std::set listening_addresses = this->configuration_.listening_addresses; std::set connection_addresses = - this->configuration_.connection_addresses_; - types::GuidPrefix discovery_server_guid_prefix = this->configuration_.discovery_server_guid_prefix_; - const auto& tls_config = this->configuration_.tls_configuration_; + this->configuration_.connection_addresses; + types::GuidPrefix discovery_server_guid_prefix = this->configuration_.discovery_server_guid_prefix; + const auto& tls_config = this->configuration_.tls_configuration; // Set attributes fastrtps::rtps::RTPSParticipantAttributes params; diff --git a/ddsrouter_yaml/src/cpp/YamlReader.cpp b/ddsrouter_yaml/src/cpp/YamlReader.cpp index 30f958b7e..b9055a886 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader.cpp @@ -552,10 +552,10 @@ void YamlReader::fill( const YamlReaderVersion version) { // Id required - object.id_ = get(yml, PARTICIPANT_NAME_TAG, version); + object.id = get(yml, PARTICIPANT_NAME_TAG, version); // Kind required - object.kind_ = get(yml, PARTICIPANT_KIND_TAG, version); + object.kind = get(yml, PARTICIPANT_KIND_TAG, version); } template <> @@ -582,7 +582,7 @@ void YamlReader::fill( // Domain optional if (is_tag_present(yml, DOMAIN_ID_TAG)) { - object.domain_ = get(yml, DOMAIN_ID_TAG, version); + object.domain = get(yml, DOMAIN_ID_TAG, version); } } @@ -610,13 +610,13 @@ void YamlReader::fill( // Optional listening addresses if (YamlReader::is_tag_present(yml, LISTENING_ADDRESSES_TAG)) { - object.listening_addresses_ = YamlReader::get_set(yml, LISTENING_ADDRESSES_TAG, version); + object.listening_addresses = YamlReader::get_set(yml, LISTENING_ADDRESSES_TAG, version); } // Optional connection addresses if (YamlReader::is_tag_present(yml, CONNECTION_ADDRESSES_TAG)) { - object.connection_addresses_ = YamlReader::get_set( + object.connection_addresses = YamlReader::get_set( yml, CONNECTION_ADDRESSES_TAG, version); @@ -625,19 +625,19 @@ void YamlReader::fill( // Optional TLS if (YamlReader::is_tag_present(yml, TLS_TAG)) { - object.tls_configuration_ = YamlReader::get(yml, TLS_TAG, version); + object.tls_configuration = YamlReader::get(yml, TLS_TAG, version); } // NOTE: The only field that change regarding the version is the GuidPrefix. switch (version) { case V_1_0: - object.discovery_server_guid_prefix_ = + object.discovery_server_guid_prefix = YamlReader::get(yml, version); break; default: - object.discovery_server_guid_prefix_ = + object.discovery_server_guid_prefix = YamlReader::get(yml, DISCOVERY_SERVER_GUID_PREFIX_TAG, version); break; } diff --git a/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp b/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp index fad69f6d9..96b689f9a 100644 --- a/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp +++ b/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp @@ -65,7 +65,7 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_trivial) for (auto participant : participant_configurations) { - ASSERT_EQ(participant->kind_, core::types::ParticipantKind::echo); + ASSERT_EQ(participant->kind, core::types::ParticipantKind::echo); } } @@ -124,7 +124,7 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_ros_case) for (auto participant : participant_configurations) { - ASSERT_EQ(participant->kind_, core::types::ParticipantKind::simple_rtps); + ASSERT_EQ(participant->kind, core::types::ParticipantKind::simple_rtps); } } @@ -166,7 +166,7 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_trivial_v1) for (auto participant : participant_configurations) { - ASSERT_EQ(participant->kind_, core::types::ParticipantKind::echo); + ASSERT_EQ(participant->kind, core::types::ParticipantKind::echo); } } @@ -223,7 +223,7 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_builtin_v1) for (auto participant : participant_configurations) { - ASSERT_EQ(participant->kind_, core::types::ParticipantKind::echo); + ASSERT_EQ(participant->kind, core::types::ParticipantKind::echo); } } @@ -273,7 +273,7 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_discovery_se for (std::shared_ptr participant : participant_configurations) { // If it is not the discovery server participant, continue - if (!(participant->kind_ == core::types::ParticipantKind::local_discovery_server)) + if (!(participant->kind == core::types::ParticipantKind::local_discovery_server)) { continue; } @@ -284,18 +284,18 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_discovery_se std::dynamic_pointer_cast(participant); // Check Name - ASSERT_EQ(ds_participant->id_, core::types::ParticipantId("participant2")); + ASSERT_EQ(ds_participant->id, core::types::ParticipantId("participant2")); // Check GuidPrefix ASSERT_EQ( - ds_participant->discovery_server_guid_prefix_, + ds_participant->discovery_server_guid_prefix, core::types::GuidPrefix(true, 3)); // Check Connection addresses ASSERT_EQ( - ds_participant->connection_addresses_.size(), + ds_participant->connection_addresses.size(), 1); - core::types::DiscoveryServerConnectionAddress address = *ds_participant->connection_addresses_.begin(); + core::types::DiscoveryServerConnectionAddress address = *ds_participant->connection_addresses.begin(); ASSERT_EQ( address, (core::types::DiscoveryServerConnectionAddress( diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp index a595a2066..b31a262ef 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetCommonParticipantConfigurationTest.cpp @@ -54,8 +54,8 @@ TEST(YamlGetCommonParticipantConfigurationTest, get_participant) YamlReader::get(yml, "participant", LATEST); // Check result - ASSERT_EQ(id, result.id_); - ASSERT_EQ(kind, result.kind_); + ASSERT_EQ(id, result.id); + ASSERT_EQ(kind, result.kind); } } } diff --git a/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp index 70ab74ed6..f6c4a0793 100644 --- a/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/participants/YamlGetSimpleParticipantConfigurationTest.cpp @@ -60,9 +60,9 @@ TEST(YamlGetSimpleParticipantConfigurationTest, get_participant) LATEST); // Check result - ASSERT_EQ(id, result.id_); - ASSERT_EQ(kind, result.kind_); - ASSERT_EQ(domain, result.domain_); + ASSERT_EQ(id, result.id); + ASSERT_EQ(kind, result.kind); + ASSERT_EQ(domain, result.domain); } } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp index d263a6319..431a92d3e 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_connection_addresses.ipp @@ -81,10 +81,10 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect LATEST); // Check result - ASSERT_EQ(1, result.connection_addresses_.size()); - ASSERT_EQ(1, result.connection_addresses_.begin()->addresses().size()); - ASSERT_EQ(connection_guid, result.connection_addresses_.begin()->discovery_server_guid_prefix()); - ASSERT_EQ(address, *result.connection_addresses_.begin()->addresses().begin()); + ASSERT_EQ(1, result.connection_addresses.size()); + ASSERT_EQ(1, result.connection_addresses.begin()->addresses().size()); + ASSERT_EQ(connection_guid, result.connection_addresses.begin()->discovery_server_guid_prefix()); + ASSERT_EQ(address, *result.connection_addresses.begin()->addresses().begin()); } // 1 connection N addresses @@ -130,15 +130,15 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect LATEST); // Check result - ASSERT_EQ(1, result.connection_addresses_.size()); - ASSERT_EQ(addresses.size(), result.connection_addresses_.begin()->addresses().size()); - ASSERT_EQ(connection_guid, result.connection_addresses_.begin()->discovery_server_guid_prefix()); + ASSERT_EQ(1, result.connection_addresses.size()); + ASSERT_EQ(addresses.size(), result.connection_addresses.begin()->addresses().size()); + ASSERT_EQ(connection_guid, result.connection_addresses.begin()->discovery_server_guid_prefix()); // Check every address is inside connection addresses of the configuration for (core::types::Address address : addresses) { // ATTENTION: this previous declaration is needed as listening_addresses() does not return a reference std::set addresses_result = - result.connection_addresses_.begin()->addresses(); + result.connection_addresses.begin()->addresses(); ASSERT_NE( addresses_result.find(address), addresses_result.end()); @@ -191,9 +191,9 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_connect LATEST); // Check result - ASSERT_EQ(connection_guids.size(), result.connection_addresses_.size()); + ASSERT_EQ(connection_guids.size(), result.connection_addresses.size()); // Check that every connection has a correct number of addresses and a guid given - for (core::types::DiscoveryServerConnectionAddress connection : result.connection_addresses_) + for (core::types::DiscoveryServerConnectionAddress connection : result.connection_addresses) { ASSERT_NE( std::find(connection_guids.begin(), connection_guids.end(), connection.discovery_server_guid_prefix()) diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp index d4284cff6..ce14b192f 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_domain.ipp @@ -63,7 +63,7 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_domain) LATEST); // Check result - ASSERT_EQ(domain, result.domain_); + ASSERT_EQ(domain, result.domain); } // incorrect domain format diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp index 620a2d955..e0409d1a2 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_listening_addresses.ipp @@ -69,8 +69,8 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni LATEST); // Check result - ASSERT_EQ(1, result.listening_addresses_.size()); - ASSERT_EQ(address, *result.listening_addresses_.begin()); + ASSERT_EQ(1, result.listening_addresses.size()); + ASSERT_EQ(address, *result.listening_addresses.begin()); } // N addresses @@ -107,12 +107,12 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_listeni LATEST); // Check result - ASSERT_EQ(addresses.size(), result.listening_addresses_.size()) << yml; + ASSERT_EQ(addresses.size(), result.listening_addresses.size()) << yml; // Check every address is inside listening addresses of the configuration for (core::types::Address address : addresses) { // ATTENTION: this previous declaration is needed as listening_addresses() does not return a reference - std::set addresses_result = result.listening_addresses_; + std::set addresses_result = result.listening_addresses; ASSERT_NE( addresses_result.find(address), addresses_result.end()); diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp index 4aabb5f32..d21b1cf64 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_minimum.ipp @@ -61,17 +61,17 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, get_participant_minimum LATEST); // Check result - ASSERT_EQ(id, result.id_); - ASSERT_EQ(kind, result.kind_); - ASSERT_EQ(guid, result.discovery_server_guid_prefix_); + ASSERT_EQ(id, result.id); + ASSERT_EQ(kind, result.kind); + ASSERT_EQ(guid, result.discovery_server_guid_prefix); // Check default values - ASSERT_EQ(0, result.connection_addresses_.size()); - ASSERT_EQ(0, result.listening_addresses_.size()); - ASSERT_FALSE(result.tls_configuration_.is_active()); + ASSERT_EQ(0, result.connection_addresses.size()); + ASSERT_EQ(0, result.listening_addresses.size()); + ASSERT_FALSE(result.tls_configuration.is_active()); ASSERT_EQ( - core::configuration::DiscoveryServerParticipantConfiguration().domain_, - result.domain_); + core::configuration::DiscoveryServerParticipantConfiguration().domain, + result.domain); } } } diff --git a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp index 3a6642939..9c3330ab9 100644 --- a/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp +++ b/ddsrouter_yaml/test/unittest/participants/test_units/YamlGetDiscoveryServerParticipantConfigurationTest_get_participant_tls.ipp @@ -156,16 +156,16 @@ TEST(YamlGetDiscoveryServerParticipantConfigurationTest, tls_configuration_inact LATEST); // Check tls_configuration - ASSERT_FALSE(ds_participant_cfg.tls_configuration_.compatible()); - ASSERT_FALSE(ds_participant_cfg.tls_configuration_.compatible()); - ASSERT_FALSE(ds_participant_cfg.tls_configuration_.compatible()); - ASSERT_FALSE(ds_participant_cfg.tls_configuration_.is_active()); - - ASSERT_THROW(ds_participant_cfg.tls_configuration_.certificate_authority_file(), utils::InconsistencyException); - ASSERT_THROW(ds_participant_cfg.tls_configuration_.private_key_file_password(), utils::InconsistencyException); - ASSERT_THROW(ds_participant_cfg.tls_configuration_.private_key_file(), utils::InconsistencyException); - ASSERT_THROW(ds_participant_cfg.tls_configuration_.certificate_chain_file(), utils::InconsistencyException); - ASSERT_THROW(ds_participant_cfg.tls_configuration_.dh_params_file(), utils::InconsistencyException); + ASSERT_FALSE(ds_participant_cfg.tls_configuration.compatible()); + ASSERT_FALSE(ds_participant_cfg.tls_configuration.compatible()); + ASSERT_FALSE(ds_participant_cfg.tls_configuration.compatible()); + ASSERT_FALSE(ds_participant_cfg.tls_configuration.is_active()); + + ASSERT_THROW(ds_participant_cfg.tls_configuration.certificate_authority_file(), utils::InconsistencyException); + ASSERT_THROW(ds_participant_cfg.tls_configuration.private_key_file_password(), utils::InconsistencyException); + ASSERT_THROW(ds_participant_cfg.tls_configuration.private_key_file(), utils::InconsistencyException); + ASSERT_THROW(ds_participant_cfg.tls_configuration.certificate_chain_file(), utils::InconsistencyException); + ASSERT_THROW(ds_participant_cfg.tls_configuration.dh_params_file(), utils::InconsistencyException); } TEST(YamlGetDiscoveryServerParticipantConfigurationTest, tls_configuration_incorrect_empty) From 70a77e4ecc97c977cc9fde74e22d0701c3870c2e Mon Sep 17 00:00:00 2001 From: jparisu Date: Wed, 27 Jul 2022 20:26:04 +0200 Subject: [PATCH 4/5] Refs #15188: retake method check_correct_configuration_object_ Signed-off-by: jparisu --- .../configuration/DDSRouterConfiguration.hpp | 8 +++- .../DDSRouterReloadConfiguration.hpp | 6 +-- .../SimpleParticipantConfiguration.hpp | 2 +- .../configuration/DDSRouterConfiguration.cpp | 39 +++++++++++++++++-- .../DDSRouterReloadConfiguration.cpp | 12 +++--- ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp | 14 +++---- ddsrouter_yaml/src/cpp/YamlReader.cpp | 16 ++++---- .../YamlReaderConfigurationTest.cpp | 2 +- .../YamlGetConfigurationDDSRouterTest.cpp | 30 +++++++------- 9 files changed, 83 insertions(+), 46 deletions(-) diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp index 56d87448a..707ac7d2c 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp @@ -71,7 +71,13 @@ struct DDSRouterConfiguration : public DDSRouterReloadConfiguration std::set> participants_configurations_ = {}; - unsigned int number_of_threads_ = 12; + unsigned int number_of_threads = 12; + +protected: + + static bool check_correct_configuration_object_( + const std::shared_ptr configuration); + }; } /* namespace configuration */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp index 1d32996b2..273dc1bb2 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp @@ -64,11 +64,11 @@ struct DDSRouterReloadConfiguration : public BaseConfiguration // VARIABLES ///////////////////////// - std::set> allowlist_ = {}; + std::set> allowlist = {}; - std::set> blocklist_ = {}; + std::set> blocklist = {}; - std::set> builtin_topics_ = {}; + std::set> builtin_topics = {}; }; } /* namespace configuration */ diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp index fd75fb0c1..3cf96f419 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp @@ -29,7 +29,7 @@ namespace core { namespace configuration { /** - * This dat struct represents a configuration for a SimpleParticipant + * This data struct represents a configuration for a SimpleParticipant */ struct SimpleParticipantConfiguration : public ParticipantConfiguration { diff --git a/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp index 5767ca2fe..dafb7814f 100644 --- a/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/DDSRouterConfiguration.cpp @@ -41,7 +41,7 @@ DDSRouterConfiguration::DDSRouterConfiguration( unsigned int number_of_threads /* = default_number_of_threads() */) : DDSRouterReloadConfiguration (allowlist, blocklist, builtin_topics) , participants_configurations_(participants_configurations) - , number_of_threads_(number_of_threads) + , number_of_threads(number_of_threads) { } @@ -81,6 +81,13 @@ bool DDSRouterConfiguration::is_valid( return false; } + // Check that the configuration is of type required + if (!check_correct_configuration_object_(configuration)) + { + error_msg << "Participant " << configuration->id << " is not of correct Configuration class. "; + return false; + } + // Store every id in a set to see if there are repetitions ids.insert(configuration->id); } @@ -98,9 +105,33 @@ bool DDSRouterConfiguration::is_valid( void DDSRouterConfiguration::reload( const DDSRouterReloadConfiguration& new_configuration) { - this->allowlist_ = new_configuration.allowlist_; - this->blocklist_ = new_configuration.blocklist_; - this->builtin_topics_ = new_configuration.builtin_topics_; + this->allowlist = new_configuration.allowlist; + this->blocklist = new_configuration.blocklist; + this->builtin_topics = new_configuration.builtin_topics; +} + +template +bool check_correct_configuration_object_by_type_( + const std::shared_ptr configuration) +{ + return nullptr != std::dynamic_pointer_cast(configuration); +} + +bool DDSRouterConfiguration::check_correct_configuration_object_( + const std::shared_ptr configuration) +{ + switch (configuration->kind) + { + case ParticipantKind::simple_rtps: + return check_correct_configuration_object_by_type_(configuration); + + case ParticipantKind::local_discovery_server: + case ParticipantKind::wan: + return check_correct_configuration_object_by_type_(configuration); + + default: + return check_correct_configuration_object_by_type_(configuration); + } } } /* namespace configuration */ diff --git a/ddsrouter_core/src/cpp/configuration/DDSRouterReloadConfiguration.cpp b/ddsrouter_core/src/cpp/configuration/DDSRouterReloadConfiguration.cpp index ba3a39066..40dae329f 100644 --- a/ddsrouter_core/src/cpp/configuration/DDSRouterReloadConfiguration.cpp +++ b/ddsrouter_core/src/cpp/configuration/DDSRouterReloadConfiguration.cpp @@ -33,9 +33,9 @@ DDSRouterReloadConfiguration::DDSRouterReloadConfiguration( std::set> allowlist, std::set> blocklist, std::set> builtin_topics) - : allowlist_(allowlist) - , blocklist_(blocklist) - , builtin_topics_(builtin_topics) + : allowlist(allowlist) + , blocklist(blocklist) + , builtin_topics(builtin_topics) { } @@ -43,7 +43,7 @@ bool DDSRouterReloadConfiguration::is_valid( utils::Formatter& error_msg) const noexcept { // Check Allow list topics - for (std::shared_ptr topic : allowlist_) + for (std::shared_ptr topic : allowlist) { if (!topic) { @@ -60,7 +60,7 @@ bool DDSRouterReloadConfiguration::is_valid( } // Check Block list topics - for (std::shared_ptr topic : blocklist_) + for (std::shared_ptr topic : blocklist) { if (!topic) { @@ -77,7 +77,7 @@ bool DDSRouterReloadConfiguration::is_valid( } // Check Builtin list topics - for (std::shared_ptr topic : builtin_topics_) + for (std::shared_ptr topic : builtin_topics) { if (!topic) { diff --git a/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp b/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp index 98e1e645c..0c011475d 100644 --- a/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp +++ b/ddsrouter_core/src/cpp/core/DDSRouterImpl.cpp @@ -45,7 +45,7 @@ DDSRouterImpl::DDSRouterImpl( , discovery_database_(new DiscoveryDatabase()) , configuration_(configuration) , enabled_(false) - , thread_pool_(std::make_shared(configuration_.number_of_threads_)) + , thread_pool_(std::make_shared(configuration_.number_of_threads)) { logDebug(DDSROUTER, "Creating DDS Router."); @@ -128,12 +128,12 @@ utils::ReturnCode DDSRouterImpl::reload_configuration( // Load new configuration and check it is okey AllowedTopicList new_allowed_topic_list( - new_configuration.allowlist_, - new_configuration.blocklist_); + new_configuration.allowlist, + new_configuration.blocklist); // Check if there are any new builtin topics std::set new_builtin_topics; - for (auto builtin_topic : new_configuration.builtin_topics_) + for (auto builtin_topic : new_configuration.builtin_topics) { if (current_topics_.find(*builtin_topic) == current_topics_.end()) { @@ -269,8 +269,8 @@ utils::ReturnCode DDSRouterImpl::stop_() noexcept void DDSRouterImpl::init_allowed_topics_() { allowed_topics_ = AllowedTopicList( - configuration_.allowlist_, - configuration_.blocklist_); + configuration_.allowlist, + configuration_.blocklist); logInfo(DDSROUTER, "DDS Router configured with allowed topics: " << allowed_topics_); } @@ -327,7 +327,7 @@ void DDSRouterImpl::init_participants_() void DDSRouterImpl::init_bridges_() { - for (std::shared_ptr topic : configuration_.builtin_topics_) + for (std::shared_ptr topic : configuration_.builtin_topics) { discovered_topic_(*topic); } diff --git a/ddsrouter_yaml/src/cpp/YamlReader.cpp b/ddsrouter_yaml/src/cpp/YamlReader.cpp index b9055a886..06eaf8089 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader.cpp @@ -701,7 +701,7 @@ void _fill_ddsrouter_configuration_v1( // Get optional allowlist if (YamlReader::is_tag_present(yml, ALLOWLIST_TAG)) { - object.allowlist_ = utils::convert_set_to_shared( + object.allowlist = utils::convert_set_to_shared( YamlReader::get_set(yml, ALLOWLIST_TAG, version)); } @@ -709,17 +709,17 @@ void _fill_ddsrouter_configuration_v1( // Get optional blocklist if (YamlReader::is_tag_present(yml, BLOCKLIST_TAG)) { - object.blocklist_ = utils::convert_set_to_shared( + object.blocklist = utils::convert_set_to_shared( YamlReader::get_set(yml, BLOCKLIST_TAG, version)); } ///// // Get builtin topics from allowlist - for (const std::shared_ptr& topic : object.allowlist_) + for (const std::shared_ptr& topic : object.allowlist) { if (RealTopic::is_real_topic(topic->topic_name(), topic->topic_type())) { - object.builtin_topics_.emplace( + object.builtin_topics.emplace( std::make_shared( topic->topic_name(), topic->topic_type(), @@ -783,7 +783,7 @@ void _fill_ddsrouter_configuration_latest( // Get optional allowlist if (YamlReader::is_tag_present(yml, ALLOWLIST_TAG)) { - object.allowlist_ = utils::convert_set_to_shared( + object.allowlist = utils::convert_set_to_shared( YamlReader::get_set(yml, ALLOWLIST_TAG, version)); } @@ -791,7 +791,7 @@ void _fill_ddsrouter_configuration_latest( // Get optional blocklist if (YamlReader::is_tag_present(yml, BLOCKLIST_TAG)) { - object.blocklist_ = utils::convert_set_to_shared( + object.blocklist = utils::convert_set_to_shared( YamlReader::get_set(yml, BLOCKLIST_TAG, version)); } @@ -799,7 +799,7 @@ void _fill_ddsrouter_configuration_latest( // Get optional builtin topics if (YamlReader::is_tag_present(yml, BUILTIN_TAG)) { - object.builtin_topics_ = utils::convert_set_to_shared( + object.builtin_topics = utils::convert_set_to_shared( YamlReader::get_set(yml, BUILTIN_TAG, version)); } @@ -827,7 +827,7 @@ void _fill_ddsrouter_configuration_latest( // Get optional number of threads if (YamlReader::is_tag_present(yml, NUMBER_THREADS_TAG)) { - object.number_of_threads_ = YamlReader::get(yml, NUMBER_THREADS_TAG, version); + object.number_of_threads = YamlReader::get(yml, NUMBER_THREADS_TAG, version); } } diff --git a/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp b/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp index b44563128..1cf57cef8 100644 --- a/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp +++ b/ddsrouter_yaml/test/unittest/configuration/YamlReaderConfigurationTest.cpp @@ -274,7 +274,7 @@ TEST(YamlReaderConfigurationTest, number_of_threads) YamlReaderConfiguration::load_ddsrouter_configuration(yml); // Check threads are correct - ASSERT_EQ(test_case, configuration_result.number_of_threads_); + ASSERT_EQ(test_case, configuration_result.number_of_threads); } } diff --git a/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp b/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp index 96b689f9a..7825c868e 100644 --- a/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp +++ b/ddsrouter_yaml/test/unittest/entities/ddsrouter/YamlGetConfigurationDDSRouterTest.cpp @@ -53,9 +53,9 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_trivial) ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check Topics are empty - ASSERT_EQ(configuration_result.allowlist_, std::set>()); - ASSERT_EQ(configuration_result.blocklist_, std::set>()); - ASSERT_EQ(configuration_result.builtin_topics_, std::set>()); + ASSERT_EQ(configuration_result.allowlist, std::set>()); + ASSERT_EQ(configuration_result.blocklist, std::set>()); + ASSERT_EQ(configuration_result.builtin_topics, std::set>()); // Check Participant configurations std::set> @@ -104,11 +104,11 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_ros_case) ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check Topic lists are empty - ASSERT_EQ(configuration_result.allowlist_, std::set>()); - ASSERT_EQ(configuration_result.blocklist_, std::set>()); + ASSERT_EQ(configuration_result.allowlist, std::set>()); + ASSERT_EQ(configuration_result.blocklist, std::set>()); // Check Builtin Topics has one correct topic - std::set> builtin_result = configuration_result.builtin_topics_; + std::set> builtin_result = configuration_result.builtin_topics; ASSERT_EQ(builtin_result.size(), 1); std::shared_ptr topic_result = (*builtin_result.begin()); ASSERT_EQ(topic_result->topic_name(), "rt/chatter"); @@ -154,9 +154,9 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_trivial_v1) ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check Topics are empty - ASSERT_EQ(configuration_result.allowlist_, std::set>()); - ASSERT_EQ(configuration_result.blocklist_, std::set>()); - ASSERT_EQ(configuration_result.builtin_topics_, std::set>()); + ASSERT_EQ(configuration_result.allowlist, std::set>()); + ASSERT_EQ(configuration_result.blocklist, std::set>()); + ASSERT_EQ(configuration_result.builtin_topics, std::set>()); // Check Participant configurations std::set> @@ -201,14 +201,14 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_builtin_v1) ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check block Topics are empty - ASSERT_EQ(configuration_result.blocklist_, std::set>()); + ASSERT_EQ(configuration_result.blocklist, std::set>()); // Check allowlist has 2 topics - std::set> allowlist_result = configuration_result.allowlist_; + std::set> allowlist_result = configuration_result.allowlist; ASSERT_EQ(allowlist_result.size(), 2); // Check Builtin Topics has one correct topic - std::set> builtin_result = configuration_result.builtin_topics_; + std::set> builtin_result = configuration_result.builtin_topics; ASSERT_EQ(builtin_result.size(), 1); std::shared_ptr topic_result = (*builtin_result.begin()); ASSERT_EQ(topic_result->topic_name(), "topic1"); @@ -260,9 +260,9 @@ TEST(YamlGetConfigurationDDSRouterTest, get_ddsrouter_configuration_discovery_se ASSERT_TRUE(configuration_result.is_valid(error_msg)); // Check Topics are empty - ASSERT_EQ(configuration_result.allowlist_, std::set>()); - ASSERT_EQ(configuration_result.blocklist_, std::set>()); - ASSERT_EQ(configuration_result.builtin_topics_, std::set>()); + ASSERT_EQ(configuration_result.allowlist, std::set>()); + ASSERT_EQ(configuration_result.blocklist, std::set>()); + ASSERT_EQ(configuration_result.builtin_topics, std::set>()); // Check Participant configurations std::set> From 723419f32c99f2f99e0ae71ccff3463cacea4488 Mon Sep 17 00:00:00 2001 From: jparisu Date: Thu, 28 Jul 2022 09:13:31 +0200 Subject: [PATCH 5/5] Refs #15188: uncrustify Signed-off-by: jparisu --- .../src/cpp/core/ParticipantFactory.cpp | 2 +- .../ddsrouter_core/trivial/TrivialTest.cpp | 40 +++++++++---------- ddsrouter_yaml/src/cpp/YamlReader.cpp | 4 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp b/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp index 8d2086375..a0e857f3b 100644 --- a/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp +++ b/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp @@ -69,7 +69,7 @@ std::shared_ptr ParticipantFactory::create_participant( { throw utils::ConfigurationException( utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << - " is not for Participant Kind: " << participant_configuration->kind); + " is not for Participant Kind: " << participant_configuration->kind); } return std::make_shared ( diff --git a/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp b/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp index bb9203620..dea53d3dd 100644 --- a/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp +++ b/ddsrouter_core/test/blackbox/ddsrouter_core/trivial/TrivialTest.cpp @@ -50,16 +50,16 @@ configuration::DDSRouterConfiguration void_configuration() std::set>(), std::set>(), std::set>( - { - std::make_shared( - ParticipantId("ParticipantVoid1"), - ParticipantKind::blank - ), - std::make_shared( - ParticipantId("ParticipantVoid2"), - ParticipantKind::blank - ) - }), + { + std::make_shared( + ParticipantId("ParticipantVoid1"), + ParticipantKind::blank + ), + std::make_shared( + ParticipantId("ParticipantVoid2"), + ParticipantKind::blank + ) + }), 1); } @@ -79,16 +79,16 @@ configuration::DDSRouterConfiguration simple_configuration( std::set>(), std::set>({std::make_shared(topic_name, topic_type)}), std::set>( - { - std::make_shared( - ParticipantId(participant_1_name), - ParticipantKind::dummy - ), - std::make_shared( - ParticipantId(participant_2_name), - ParticipantKind::dummy - ) - }), + { + std::make_shared( + ParticipantId(participant_1_name), + ParticipantKind::dummy + ), + std::make_shared( + ParticipantId(participant_2_name), + ParticipantKind::dummy + ) + }), 1); } diff --git a/ddsrouter_yaml/src/cpp/YamlReader.cpp b/ddsrouter_yaml/src/cpp/YamlReader.cpp index 06eaf8089..3ea7534fd 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader.cpp @@ -633,12 +633,12 @@ void YamlReader::fill( { case V_1_0: object.discovery_server_guid_prefix = - YamlReader::get(yml, version); + YamlReader::get(yml, version); break; default: object.discovery_server_guid_prefix = - YamlReader::get(yml, DISCOVERY_SERVER_GUID_PREFIX_TAG, version); + YamlReader::get(yml, DISCOVERY_SERVER_GUID_PREFIX_TAG, version); break; } }