Skip to content

Commit 4c6c26d

Browse files
authored
Refactor Configuration to data structs (#250)
* Refs #15188: Refactor Configuration to data structs Signed-off-by: jparisu <javierparis@eprosima.com> * Refs #15188: apply suggestions Signed-off-by: jparisu <javierparis@eprosima.com> * Refs #15188: change names of protected variables Signed-off-by: jparisu <javierparis@eprosima.com> * Refs #15188: retake method check_correct_configuration_object_ Signed-off-by: jparisu <javierparis@eprosima.com> * Refs #15188: uncrustify Signed-off-by: jparisu <javierparis@eprosima.com>
1 parent b0ec41e commit 4c6c26d

35 files changed

Lines changed: 429 additions & 638 deletions

File tree

.dev/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,16 @@ These are the log levels and when to use them
159159
| User | logUser | always | std::cout | showing message to the user |
160160
| Info | logInfo | only debug -d option | logInfo | showing important information about the execution |
161161
| Debug | logDebug | only debug -d option | logInfo | showing non important information |
162+
163+
### Configurations
164+
165+
Configurations are data structures with public access to their internal values.
166+
This makes it easier to work with them: to create, manage and copy them.
167+
The default values will be defined in the header, so every user could know which are them, and always
168+
have a default constructor.
169+
170+
From every internal object that requires a configuration to be created, the configuration argument
171+
must be created as an internal value and/or const to the object,
172+
or create some way that the configuration cannot be changed from outside without the internal object notice it.
173+
174+
Also, configurations must support an `is_valid` method to check that it is in a coherent state.

ddsrouter_core/include/ddsrouter_core/configuration/BaseConfiguration.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@
2121

2222
#include <ddsrouter_utils/Formatter.hpp>
2323

24+
#include <ddsrouter_core/library/library_dll.h>
25+
2426
namespace eprosima {
2527
namespace ddsrouter {
2628
namespace core {
2729
namespace configuration {
2830

2931
/**
30-
* This is an Interface class that force every configuration in ddsrouter to have a \c is_valid method.
32+
* Configurations in DDS Router are data structures with public access to its internal methods.
33+
* Thus, they are not forced to be correct in construction.
34+
* This is an Interface class that forces every configuration in ddsrouter to have an \c is_valid method.
3135
*/
32-
class BaseConfiguration
36+
struct BaseConfiguration
3337
{
34-
public:
35-
36-
virtual bool is_valid(
38+
DDSROUTER_CORE_DllAPI virtual bool is_valid(
3739
utils::Formatter& error_msg) const noexcept = 0;
3840
};
3941

ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterConfiguration.hpp

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,50 +39,45 @@ namespace configuration {
3939
* This class joins every DDSRouter feature configuration and includes methods
4040
* to interact with this configuration.
4141
*/
42-
class DDSRouterConfiguration : public DDSRouterReloadConfiguration
42+
struct DDSRouterConfiguration : public DDSRouterReloadConfiguration
4343
{
44-
public:
4544

46-
/**
47-
* TODO
48-
*/
45+
/////////////////////////
46+
// CONSTRUCTORS
47+
/////////////////////////
48+
49+
DDSROUTER_CORE_DllAPI DDSRouterConfiguration() = default;
50+
4951
DDSROUTER_CORE_DllAPI DDSRouterConfiguration(
5052
std::set<std::shared_ptr<types::FilterTopic>> allowlist,
5153
std::set<std::shared_ptr<types::FilterTopic>> blocklist,
5254
std::set<std::shared_ptr<types::RealTopic>> builtin_topics,
5355
std::set<std::shared_ptr<ParticipantConfiguration>> participants_configurations,
54-
unsigned int number_of_threads = default_number_of_threads());
55-
56-
/**
57-
* @brief Return a set with the different \c ParticipantConfigurations in the yaml
58-
*
59-
* Every participant configuration is an object of the specific class set in \c types::ParticipantKind .
60-
*
61-
* @return Set of \c ParticipantConfigurations
62-
*/
63-
DDSROUTER_CORE_DllAPI std::set<std::shared_ptr<ParticipantConfiguration>> participants_configurations() const
64-
noexcept;
56+
unsigned int number_of_threads);
6557

66-
DDSROUTER_CORE_DllAPI bool is_valid(
67-
utils::Formatter& error_msg) const noexcept override;
58+
/////////////////////////
59+
// METHODS
60+
/////////////////////////
6861

6962
DDSROUTER_CORE_DllAPI void reload(
7063
const DDSRouterReloadConfiguration& new_configuration);
7164

72-
DDSROUTER_CORE_DllAPI unsigned int number_of_threads() const noexcept;
65+
DDSROUTER_CORE_DllAPI bool is_valid(
66+
utils::Formatter& error_msg) const noexcept override;
67+
68+
/////////////////////////
69+
// VARIABLES
70+
/////////////////////////
71+
72+
std::set<std::shared_ptr<ParticipantConfiguration>> participants_configurations_ = {};
7373

74-
DDSROUTER_CORE_DllAPI static unsigned int default_number_of_threads() noexcept;
74+
unsigned int number_of_threads = 12;
7575

7676
protected:
7777

7878
static bool check_correct_configuration_object_(
7979
const std::shared_ptr<ParticipantConfiguration> configuration);
8080

81-
std::set<std::shared_ptr<ParticipantConfiguration>> participants_configurations_;
82-
83-
unsigned int number_of_threads_;
84-
85-
static const unsigned int DEFAULT_NUMBER_OF_THREADS_;
8681
};
8782

8883
} /* namespace configuration */

ddsrouter_core/include/ddsrouter_core/configuration/DDSRouterReloadConfiguration.hpp

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,45 +39,36 @@ namespace configuration {
3939
* This class joins every DDSRouter feature configuration and includes methods
4040
* to interact with this configuration.
4141
*/
42-
class DDSRouterReloadConfiguration : public BaseConfiguration
42+
struct DDSRouterReloadConfiguration : public BaseConfiguration
4343
{
44-
public:
4544

46-
/**
47-
* TODO
48-
*/
45+
/////////////////////////
46+
// CONSTRUCTORS
47+
/////////////////////////
48+
49+
DDSROUTER_CORE_DllAPI DDSRouterReloadConfiguration() = default;
50+
4951
DDSROUTER_CORE_DllAPI DDSRouterReloadConfiguration(
5052
std::set<std::shared_ptr<types::FilterTopic>> allowlist,
5153
std::set<std::shared_ptr<types::FilterTopic>> blocklist,
5254
std::set<std::shared_ptr<types::RealTopic>> builtin_topics);
5355

54-
/**
55-
* @brief Return a set with the topics allowed in the configuration
56-
*
57-
* @return Set of filters to get allowed topics
58-
*/
59-
DDSROUTER_CORE_DllAPI std::set<std::shared_ptr<types::FilterTopic>> allowlist() const noexcept;
60-
61-
/**
62-
* @brief Return a set with the topics blocked in the configuration
63-
*
64-
* @return Set of filters to get blocked topics
65-
*/
66-
DDSROUTER_CORE_DllAPI std::set<std::shared_ptr<types::FilterTopic>> blocklist() const noexcept;
67-
68-
/**
69-
* TODO
70-
*/
71-
DDSROUTER_CORE_DllAPI std::set<std::shared_ptr<types::RealTopic>> builtin_topics() const noexcept;
56+
/////////////////////////
57+
// METHODS
58+
/////////////////////////
7259

7360
DDSROUTER_CORE_DllAPI bool is_valid(
7461
utils::Formatter& error_msg) const noexcept override;
7562

76-
protected:
63+
/////////////////////////
64+
// VARIABLES
65+
/////////////////////////
66+
67+
std::set<std::shared_ptr<types::FilterTopic>> allowlist = {};
68+
69+
std::set<std::shared_ptr<types::FilterTopic>> blocklist = {};
7770

78-
std::set<std::shared_ptr<types::FilterTopic>> allowlist_;
79-
std::set<std::shared_ptr<types::FilterTopic>> blocklist_;
80-
std::set<std::shared_ptr<types::RealTopic>> builtin_topics_;
71+
std::set<std::shared_ptr<types::RealTopic>> builtin_topics = {};
8172
};
8273

8374
} /* namespace configuration */

ddsrouter_core/include/ddsrouter_core/configuration/participant/DiscoveryServerParticipantConfiguration.hpp

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,56 +36,45 @@ namespace configuration {
3636
/**
3737
* This class joins Discovery Server Participant Configuration features and gives methods to interact with it.
3838
*/
39-
class DiscoveryServerParticipantConfiguration : public SimpleParticipantConfiguration
39+
struct DiscoveryServerParticipantConfiguration : public SimpleParticipantConfiguration
4040
{
41-
public:
4241

43-
// TODO
44-
DDSROUTER_CORE_DllAPI DiscoveryServerParticipantConfiguration(
45-
const types::ParticipantId& id,
46-
const types::GuidPrefix& discovery_server_guid_prefix,
47-
const std::set<types::Address>& listening_addresses,
48-
const std::set<types::DiscoveryServerConnectionAddress>& connection_addresses,
49-
const types::ParticipantKind& kind = types::ParticipantKind::local_discovery_server,
50-
const types::security::TlsConfiguration tls_configuration = types::security::TlsConfiguration(),
51-
const types::DomainId& domain_id = DEFAULT_DS_DOMAIN_ID_);
42+
/////////////////////////
43+
// CONSTRUCTORS
44+
/////////////////////////
45+
46+
DDSROUTER_CORE_DllAPI DiscoveryServerParticipantConfiguration() = default;
5247

53-
// TODO
5448
DDSROUTER_CORE_DllAPI DiscoveryServerParticipantConfiguration(
5549
const types::ParticipantId& id,
50+
const types::ParticipantKind& kind,
51+
const types::DomainId& domain_id,
5652
const types::GuidPrefix& discovery_server_guid_prefix,
5753
const std::set<types::Address>& listening_addresses,
5854
const std::set<types::DiscoveryServerConnectionAddress>& connection_addresses,
59-
const types::DomainId& domain_id,
60-
const types::ParticipantKind& kind = types::ParticipantKind::local_discovery_server,
61-
const types::security::TlsConfiguration tls_configuration = types::security::TlsConfiguration());
62-
63-
DDSROUTER_CORE_DllAPI types::GuidPrefix discovery_server_guid_prefix() const noexcept;
64-
65-
DDSROUTER_CORE_DllAPI std::set<types::Address> listening_addresses() const noexcept;
55+
const types::security::TlsConfiguration tls_configuration);
6656

67-
DDSROUTER_CORE_DllAPI std::set<types::DiscoveryServerConnectionAddress> connection_addresses() const noexcept;
68-
69-
DDSROUTER_CORE_DllAPI bool tls_active() const noexcept;
70-
71-
DDSROUTER_CORE_DllAPI const types::security::TlsConfiguration& tls_configuration() const noexcept;
57+
/////////////////////////
58+
// METHODS
59+
/////////////////////////
7260

7361
DDSROUTER_CORE_DllAPI virtual bool is_valid(
7462
utils::Formatter& error_msg) const noexcept override;
7563

7664
DDSROUTER_CORE_DllAPI bool operator ==(
7765
const DiscoveryServerParticipantConfiguration& other) const noexcept;
7866

79-
DDSROUTER_CORE_DllAPI static types::DomainId default_domain_id() noexcept;
67+
/////////////////////////
68+
// VARIABLES
69+
/////////////////////////
70+
71+
types::GuidPrefix discovery_server_guid_prefix = types::GuidPrefix();
8072

81-
protected:
73+
std::set<types::Address> listening_addresses = {};
8274

83-
types::GuidPrefix discovery_server_guid_prefix_;
84-
std::set<types::Address> listening_addresses_;
85-
std::set<types::DiscoveryServerConnectionAddress> connection_addresses_;
86-
const types::security::TlsConfiguration tls_configuration_;
75+
std::set<types::DiscoveryServerConnectionAddress> connection_addresses = {};
8776

88-
DDSROUTER_CORE_DllAPI static const types::DomainId DEFAULT_DS_DOMAIN_ID_; // 66
77+
types::security::TlsConfiguration tls_configuration = types::security::TlsConfiguration();
8978
};
9079

9180
} /* namespace configuration */

ddsrouter_core/include/ddsrouter_core/configuration/participant/ParticipantConfiguration.hpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,26 @@ namespace ddsrouter {
2929
namespace core {
3030
namespace configuration {
3131

32-
/**
33-
* TODO
34-
*/
35-
class ParticipantConfiguration : public BaseConfiguration
32+
struct ParticipantConfiguration : public BaseConfiguration
3633
{
37-
public:
3834

39-
/**
40-
* TODO
41-
*/
35+
/////////////////////////
36+
// CONSTRUCTORS
37+
/////////////////////////
38+
39+
DDSROUTER_CORE_DllAPI ParticipantConfiguration() = default;
40+
4241
DDSROUTER_CORE_DllAPI ParticipantConfiguration(
4342
const types::ParticipantId& id,
4443
const types::ParticipantKind& kind) noexcept;
4544

46-
//! Participant Kind associated with this configuration
47-
DDSROUTER_CORE_DllAPI types::ParticipantKind kind() const noexcept;
48-
49-
//! Participant Id associated with this configuration
50-
DDSROUTER_CORE_DllAPI types::ParticipantId id() const noexcept;
45+
/////////////////////////
46+
// METHODS
47+
/////////////////////////
5148

5249
/**
5350
* @brief Equal comparator
5451
*
55-
* This comparator should check if the id is equal to the other Configuration and check the yaml equality.
56-
*
57-
* @todo: check equality yaml and not identity yaml.
58-
*
5952
* @param [in] other: ParticipantConfiguration to compare.
6053
* @return True if both configurations are the same, False otherwise.
6154
*/
@@ -65,13 +58,15 @@ class ParticipantConfiguration : public BaseConfiguration
6558
DDSROUTER_CORE_DllAPI virtual bool is_valid(
6659
utils::Formatter& error_msg) const noexcept override;
6760

68-
protected:
61+
/////////////////////////
62+
// VARIABLES
63+
/////////////////////////
6964

7065
//! Participant Id associated with this configuration
71-
const types::ParticipantId id_;
66+
types::ParticipantId id;
7267

7368
//! Participant Kind of the Participant that this configuration refers.
74-
const types::ParticipantKind kind_;
69+
types::ParticipantKind kind;
7570
};
7671

7772
} /* namespace configuration */

ddsrouter_core/include/ddsrouter_core/configuration/participant/SimpleParticipantConfiguration.hpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,43 @@ namespace core {
2929
namespace configuration {
3030

3131
/**
32-
* This class joins Simple Participant Configuration features and give methods to interact with it.
32+
* This data struct represents a configuration for a SimpleParticipant
3333
*/
34-
class SimpleParticipantConfiguration : public ParticipantConfiguration
34+
struct SimpleParticipantConfiguration : public ParticipantConfiguration
3535
{
3636
public:
3737

38-
//! TODO
38+
/////////////////////////
39+
// CONSTRUCTORS
40+
/////////////////////////
41+
DDSROUTER_CORE_DllAPI SimpleParticipantConfiguration() = default;
42+
3943
DDSROUTER_CORE_DllAPI SimpleParticipantConfiguration(
4044
const types::ParticipantId& id,
41-
const types::ParticipantKind& kind = types::ParticipantKind::simple_rtps,
42-
const types::DomainId& domain_id = DEFAULT_DOMAIN_ID_) noexcept;
45+
const types::ParticipantKind& kind,
46+
const types::DomainId& domain_id) noexcept;
47+
48+
/////////////////////////
49+
// METHODS
50+
/////////////////////////
51+
52+
DDSROUTER_CORE_DllAPI virtual bool is_valid(
53+
utils::Formatter& error_msg) const noexcept override;
4354

4455
/**
45-
* @brief Return domain set in the configuration
46-
*
47-
* In case domain is not set in Configuration, it returns the default DomainID = 0
56+
* @brief Equal comparator
4857
*
49-
* @return DomainId
58+
* @param [in] other: SimpleParticipantConfiguration to compare.
59+
* @return True if both configurations are the same, False otherwise.
5060
*/
51-
DDSROUTER_CORE_DllAPI types::DomainId domain() const noexcept;
52-
5361
DDSROUTER_CORE_DllAPI bool operator ==(
5462
const SimpleParticipantConfiguration& other) const noexcept;
5563

56-
DDSROUTER_CORE_DllAPI virtual bool is_valid(
57-
utils::Formatter& error_msg) const noexcept override;
58-
59-
protected:
60-
61-
types::DomainId domain_;
64+
/////////////////////////
65+
// VARIABLES
66+
/////////////////////////
6267

63-
DDSROUTER_CORE_DllAPI static const types::DomainId DEFAULT_DOMAIN_ID_; // 0
68+
types::DomainId domain = types::DomainId(0u);
6469
};
6570

6671
} /* namespace configuration */

0 commit comments

Comments
 (0)