Skip to content

Commit 87fe006

Browse files
authored
Refactor Participants so are not templatized by configuration (#263)
* Refactor Participants so are not templatized by configuration Signed-off-by: jparisu <javierparis@eprosima.com> * apply suggestions Signed-off-by: jparisu <javierparis@eprosima.com> * uncrustify Signed-off-by: jparisu <javierparis@eprosima.com>
1 parent 2c49682 commit 87fe006

21 files changed

Lines changed: 177 additions & 405 deletions

ddsrouter_core/include/ddsrouter_core/types/dds/DomainId.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class DomainId
6464
DDSROUTER_CORE_DllAPI bool operator ==(
6565
const DomainId& other) const noexcept;
6666

67+
DDSROUTER_CORE_DllAPI operator DomainIdType() const noexcept;
68+
6769
protected:
6870

6971
//! Value of Fast DDS Domain ID

ddsrouter_core/src/cpp/core/ParticipantFactory.cpp

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@
2929
#include <participant/implementations/auxiliar/EchoParticipant.hpp>
3030
#include <participant/implementations/auxiliar/BlankParticipant.hpp>
3131
#include <participant/implementations/rtps/SimpleParticipant.hpp>
32-
#include <participant/implementations/rtps/LocalDiscoveryServerParticipant.hpp>
33-
#include <participant/implementations/rtps/WanDiscoveryServerParticipant.hpp>
34-
#include <participant/implementations/rtps/WanInitialPeersParticipant.hpp>
32+
#include <participant/implementations/rtps/InitialPeersParticipant.hpp>
33+
#include <participant/implementations/rtps/DiscoveryServerParticipant.hpp>
3534

3635
namespace eprosima {
3736
namespace ddsrouter {
@@ -54,11 +53,11 @@ std::shared_ptr<IParticipant> ParticipantFactory::create_participant(
5453

5554
case ParticipantKind::echo:
5655
// EchoParticipant
57-
return std::make_shared<EchoParticipant>((*participant_configuration), payload_pool, discovery_database);
56+
return std::make_shared<EchoParticipant>(participant_configuration, payload_pool, discovery_database);
5857

5958
case ParticipantKind::dummy:
6059
// DummyParticipant
61-
return std::make_shared<DummyParticipant>((*participant_configuration), payload_pool, discovery_database);
60+
return std::make_shared<DummyParticipant>(participant_configuration, payload_pool, discovery_database);
6261

6362
case ParticipantKind::simple_rtps:
6463
// Simple RTPS Participant
@@ -74,30 +73,12 @@ std::shared_ptr<IParticipant> ParticipantFactory::create_participant(
7473
}
7574

7675
return std::make_shared<rtps::SimpleParticipant> (
77-
(*conf_),
76+
conf_,
7877
payload_pool,
7978
discovery_database);
8079
}
8180

8281
case ParticipantKind::local_discovery_server:
83-
// Discovery Server RTPS Participant
84-
{
85-
std::shared_ptr<configuration::DiscoveryServerParticipantConfiguration> conf_ =
86-
std::dynamic_pointer_cast<configuration::DiscoveryServerParticipantConfiguration>(
87-
participant_configuration);
88-
if (!conf_)
89-
{
90-
throw utils::ConfigurationException(
91-
utils::Formatter() << "Configuration from Participant: " << participant_configuration->id << " is not for Participant Kind: " <<
92-
participant_configuration->kind);
93-
}
94-
95-
return std::make_shared<rtps::LocalDiscoveryServerParticipant> (
96-
(*conf_),
97-
payload_pool,
98-
discovery_database);
99-
}
100-
10182
case ParticipantKind::wan_discovery_server:
10283
// Discovery Server RTPS Participant
10384
{
@@ -111,8 +92,8 @@ std::shared_ptr<IParticipant> ParticipantFactory::create_participant(
11192
participant_configuration->kind);
11293
}
11394

114-
return std::make_shared<rtps::WanDiscoveryServerParticipant> (
115-
(*conf_),
95+
return std::make_shared<rtps::DiscoveryServerParticipant> (
96+
conf_,
11697
payload_pool,
11798
discovery_database);
11899
}
@@ -130,8 +111,8 @@ std::shared_ptr<IParticipant> ParticipantFactory::create_participant(
130111
participant_configuration->kind);
131112
}
132113

133-
return std::make_shared<rtps::WanInitialPeersParticipant> (
134-
(*conf_),
114+
return std::make_shared<rtps::InitialPeersParticipant> (
115+
conf_,
135116
payload_pool,
136117
discovery_database);
137118
}

ddsrouter_core/src/cpp/participant/implementations/auxiliar/impl/BaseParticipant.ipp renamed to ddsrouter_core/src/cpp/participant/implementations/auxiliar/BaseParticipant.cpp

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,24 @@
1313
// limitations under the License.
1414

1515
/**
16-
* @file BaseParticipant.ipp
16+
* @file BaseParticipant.cpp
1717
*/
1818

19-
#ifndef __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BASEPARTICIPANT_IMPL_IPP_
20-
#define __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BASEPARTICIPANT_IMPL_IPP_
21-
2219
#include <memory>
2320

21+
#include <ddsrouter_core/types/participant/ParticipantKind.hpp>
2422
#include <ddsrouter_utils/exception/InitializationException.hpp>
25-
#include <reader/implementations/auxiliar/BaseReader.hpp>
2623
#include <ddsrouter_utils/Log.hpp>
27-
#include <ddsrouter_core/types/participant/ParticipantKind.hpp>
24+
#include <participant/implementations/auxiliar/BaseParticipant.hpp>
25+
#include <reader/implementations/auxiliar/BaseReader.hpp>
2826
#include <writer/implementations/auxiliar/BaseWriter.hpp>
2927

3028
namespace eprosima {
3129
namespace ddsrouter {
3230
namespace core {
3331

34-
template <class ConfigurationType>
35-
BaseParticipant<ConfigurationType>::BaseParticipant(
36-
const ConfigurationType participant_configuration,
32+
BaseParticipant::BaseParticipant(
33+
std::shared_ptr<configuration::ParticipantConfiguration> participant_configuration,
3734
std::shared_ptr <PayloadPool> payload_pool,
3835
std::shared_ptr <DiscoveryDatabase> discovery_database)
3936
: configuration_(participant_configuration)
@@ -43,8 +40,7 @@ BaseParticipant<ConfigurationType>::BaseParticipant(
4340
logDebug(DDSROUTER_TRACK, "Creating Participant " << *this << ".");
4441
}
4542

46-
template <class ConfigurationType>
47-
BaseParticipant<ConfigurationType>::~BaseParticipant()
43+
BaseParticipant::~BaseParticipant()
4844
{
4945
logDebug(DDSROUTER_TRACK, "Destroying Participant " << *this << ".");
5046

@@ -63,32 +59,28 @@ BaseParticipant<ConfigurationType>::~BaseParticipant()
6359
logDebug(DDSROUTER_TRACK, "Participant " << *this << " destroyed.");
6460
}
6561

66-
template <class ConfigurationType>
67-
types::ParticipantId BaseParticipant<ConfigurationType>::id() const noexcept
62+
types::ParticipantId BaseParticipant::id() const noexcept
6863
{
6964
std::lock_guard <std::recursive_mutex> lock(mutex_);
7065

71-
return configuration_.id;
66+
return configuration_->id;
7267
}
7368

74-
template <class ConfigurationType>
75-
types::ParticipantKind BaseParticipant<ConfigurationType>::kind() const noexcept
69+
types::ParticipantKind BaseParticipant::kind() const noexcept
7670
{
7771
std::lock_guard <std::recursive_mutex> lock(mutex_);
7872

79-
return configuration_.kind;
73+
return configuration_->kind;
8074
}
8175

82-
template <class ConfigurationType>
83-
bool BaseParticipant<ConfigurationType>::is_repeater() const noexcept
76+
bool BaseParticipant::is_repeater() const noexcept
8477
{
8578
std::lock_guard <std::recursive_mutex> lock(mutex_);
8679

87-
return configuration_.is_repeater;
80+
return configuration_->is_repeater;
8881
}
8982

90-
template <class ConfigurationType>
91-
std::shared_ptr<IWriter> BaseParticipant<ConfigurationType>::create_writer(
83+
std::shared_ptr<IWriter> BaseParticipant::create_writer(
9284
types::RealTopic topic)
9385
{
9486
std::lock_guard <std::recursive_mutex> lock(mutex_);
@@ -111,8 +103,7 @@ std::shared_ptr<IWriter> BaseParticipant<ConfigurationType>::create_writer(
111103
return new_writer;
112104
}
113105

114-
template <class ConfigurationType>
115-
std::shared_ptr<IReader> BaseParticipant<ConfigurationType>::create_reader(
106+
std::shared_ptr<IReader> BaseParticipant::create_reader(
116107
types::RealTopic topic)
117108
{
118109
std::lock_guard <std::recursive_mutex> lock(mutex_);
@@ -135,8 +126,7 @@ std::shared_ptr<IReader> BaseParticipant<ConfigurationType>::create_reader(
135126
return new_reader;
136127
}
137128

138-
template <class ConfigurationType>
139-
void BaseParticipant<ConfigurationType>::delete_writer(
129+
void BaseParticipant::delete_writer(
140130
std::shared_ptr <IWriter> writer) noexcept
141131
{
142132
std::lock_guard <std::recursive_mutex> lock(mutex_);
@@ -152,8 +142,7 @@ void BaseParticipant<ConfigurationType>::delete_writer(
152142
}
153143
}
154144

155-
template <class ConfigurationType>
156-
void BaseParticipant<ConfigurationType>::delete_reader(
145+
void BaseParticipant::delete_reader(
157146
std::shared_ptr <IReader> reader) noexcept
158147
{
159148
std::lock_guard <std::recursive_mutex> lock(mutex_);
@@ -169,37 +158,31 @@ void BaseParticipant<ConfigurationType>::delete_reader(
169158
}
170159
}
171160

172-
template <class ConfigurationType>
173-
void BaseParticipant<ConfigurationType>::delete_writer_(
161+
void BaseParticipant::delete_writer_(
174162
std::shared_ptr <IWriter>) noexcept
175163
{
176164
// It does nothing. Override this method so it has functionality.
177165
}
178166

179-
template <class ConfigurationType>
180-
void BaseParticipant<ConfigurationType>::delete_reader_(
167+
void BaseParticipant::delete_reader_(
181168
std::shared_ptr <IReader>) noexcept
182169
{
183170
// It does nothing. Override this method so it has functionality.
184171
}
185172

186-
template <class ConfigurationType>
187-
types::ParticipantId BaseParticipant<ConfigurationType>::id_nts_() const noexcept
173+
types::ParticipantId BaseParticipant::id_nts_() const noexcept
188174
{
189-
return configuration_.id;
175+
return configuration_->id;
190176
}
191177

192-
template <class ConfigurationType>
193178
std::ostream& operator <<(
194179
std::ostream& os,
195-
const BaseParticipant<ConfigurationType>& participant)
180+
const BaseParticipant& participant)
196181
{
197-
os << "{" << participant.id() << ";" << participant.configuration_.kind << "}";
182+
os << "{" << participant.id() << ";" << participant.configuration_->kind << "}";
198183
return os;
199184
}
200185

201186
} /* namespace core */
202187
} /* namespace ddsrouter */
203188
} /* namespace eprosima */
204-
205-
#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BASEPARTICIPANT_IMPL_IPP_ */

ddsrouter_core/src/cpp/participant/implementations/auxiliar/BaseParticipant.hpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,9 @@ namespace core {
3838
*
3939
* This class stores every Endpoint created by this Participant.
4040
*/
41-
template <class ConfigurationType>
4241
class BaseParticipant : public IParticipant
4342
{
4443

45-
// Force ConfigurationType to be subclass of ParticipantConfiguration
46-
FORCE_TEMPLATE_SUBCLASS(configuration::ParticipantConfiguration, ConfigurationType);
47-
4844
public:
4945

5046
/**
@@ -57,7 +53,7 @@ class BaseParticipant : public IParticipant
5753
* @param discovery_database DDS Router shared Discovery Database
5854
*/
5955
BaseParticipant(
60-
const ConfigurationType participant_configuration,
56+
std::shared_ptr<configuration::ParticipantConfiguration> participant_configuration,
6157
std::shared_ptr<PayloadPool> payload_pool,
6258
std::shared_ptr<DiscoveryDatabase> discovery_database);
6359

@@ -194,7 +190,7 @@ class BaseParticipant : public IParticipant
194190
types::ParticipantId id_nts_() const noexcept;
195191

196192
//! Participant configuration
197-
ConfigurationType configuration_;
193+
std::shared_ptr<configuration::ParticipantConfiguration> configuration_;
198194

199195
//! DDS Router shared Payload Pool
200196
std::shared_ptr<PayloadPool> payload_pool_;
@@ -212,10 +208,9 @@ class BaseParticipant : public IParticipant
212208
mutable std::recursive_mutex mutex_;
213209

214210
// Allow operator << to use private variables
215-
template <class C>
216211
friend std::ostream& operator <<(
217212
std::ostream&,
218-
const BaseParticipant<C>&);
213+
const BaseParticipant&);
219214
};
220215

221216
/**
@@ -224,16 +219,12 @@ class BaseParticipant : public IParticipant
224219
* This method is merely a to_string of a BaseParticipant definition.
225220
* It serialize the Id and kind
226221
*/
227-
template <class ConfigurationType>
228222
std::ostream& operator <<(
229223
std::ostream& os,
230-
const BaseParticipant<ConfigurationType>& track);
224+
const BaseParticipant& part);
231225

232226
} /* namespace core */
233227
} /* namespace ddsrouter */
234228
} /* namespace eprosima */
235229

236-
// Include implementation template file
237-
#include <participant/implementations/auxiliar/impl/BaseParticipant.ipp>
238-
239230
#endif /* __SRC_DDSROUTERCORE_PARTICIPANT_IMPLEMENTATIONS_AUXILIAR_BASEPARTICIPANT_HPP_ */

ddsrouter_core/src/cpp/participant/implementations/auxiliar/DummyParticipant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ std::mutex DummyParticipant::static_mutex_;
3232
std::map<ParticipantId, DummyParticipant*> DummyParticipant::participants_;
3333

3434
DummyParticipant::DummyParticipant(
35-
const configuration::ParticipantConfiguration participant_configuration,
35+
std::shared_ptr<configuration::ParticipantConfiguration> participant_configuration,
3636
std::shared_ptr<PayloadPool> payload_pool,
3737
std::shared_ptr<DiscoveryDatabase> discovery_database)
3838
: BaseParticipant(participant_configuration, payload_pool, discovery_database)

ddsrouter_core/src/cpp/participant/implementations/auxiliar/DummyParticipant.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace core {
3838
*
3939
* This Participant is used for Testing, as it could mock a DDS real network.
4040
*/
41-
class DummyParticipant : public BaseParticipant<configuration::ParticipantConfiguration>
41+
class DummyParticipant : public BaseParticipant
4242
{
4343
public:
4444

@@ -50,7 +50,7 @@ class DummyParticipant : public BaseParticipant<configuration::ParticipantConfig
5050
* the DDSRouter.
5151
*/
5252
DummyParticipant(
53-
const configuration::ParticipantConfiguration participant_configuration,
53+
std::shared_ptr<configuration::ParticipantConfiguration> participant_configuration,
5454
std::shared_ptr<PayloadPool> payload_pool,
5555
std::shared_ptr<DiscoveryDatabase> discovery_database);
5656

ddsrouter_core/src/cpp/participant/implementations/auxiliar/EchoParticipant.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace core {
2828
/**
2929
* Concrete Participant that prints in stdout each message that arrives.
3030
*/
31-
class EchoParticipant : public BaseParticipant<configuration::ParticipantConfiguration>
31+
class EchoParticipant : public BaseParticipant
3232
{
3333
public:
3434

0 commit comments

Comments
 (0)