Skip to content

Commit b1f98a1

Browse files
committed
Refs #23923: Create const copy
Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com>
1 parent a56e8dd commit b1f98a1

38 files changed

Lines changed: 125 additions & 94 deletions

File tree

include/fastdds/rtps/participant/RTPSParticipant.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,23 @@ class FASTDDS_EXPORTED_API RTPSParticipant
238238
* instead to get a thread safe copy of the attributes.
239239
* @return RTPSParticipantAttributes reference.
240240
*/
241-
FASTDDS_TODO_BEFORE(4, 0, "Make this method return a copy and delete copy_attributes()");
241+
FASTDDS_TODO_BEFORE(4, 0, "Refactor to differentiate mutable and constant objects and make getters thread safe");
242242
const RTPSParticipantAttributes& get_attributes() const;
243243

244+
/**
245+
* @brief Get a const reference of the constant RTPSParticipantAttributes of this RTPSParticipantImpl.
246+
* This method is thread safe because it returns a const reference to the internal attributes.
247+
* @warning It must not be used to access mutable attributes as it could return outdated values.
248+
* @return A const reference to the RTPSParticipantAttributes of this RTPSParticipantImpl.
249+
*/
250+
FASTDDS_TODO_BEFORE(4, 0, "Refactor to differentiate mutable and constant objects and make getters thread safe");
251+
const RTPSParticipantAttributes& get_const_attributes() const;
252+
244253
/**
245254
* Get a copy of the current state of the RTPSParticipantParameters.
246255
* @return RTPSParticipantAttributes copy.
247256
*/
257+
FASTDDS_TODO_BEFORE(4, 0, "Refactor to differentiate mutable and constant objects and make getters thread safe");
248258
RTPSParticipantAttributes copy_attributes() const;
249259

250260
/**

src/cpp/fastdds/builtin/type_lookup_service/TypeLookupManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ bool TypeLookupManager::init(
127127
{
128128
participant_ = protocols->mp_participantImpl;
129129
builtin_protocols_ = protocols;
130-
auto locators_allocations = participant_->copy_attributes().allocation.locators;
130+
const auto& locators_allocations = participant_->get_const_attributes().allocation.locators;
131131

132132
local_instance_name_ = get_instance_name(participant_->getGuid());
133133

src/cpp/fastdds/builtin/type_lookup_service/TypeLookupReplyListener.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void TypeLookupReplyListener::start_reply_processor_thread()
5959
};
6060
// Create and start the processing thread
6161
replies_processor_thread = eprosima::create_thread(thread_func,
62-
typelookup_manager_->participant_->copy_attributes().typelookup_service_thread,
62+
typelookup_manager_->participant_->get_const_attributes().typelookup_service_thread,
6363
"dds.tls.replies.%u");
6464
}
6565
}

src/cpp/fastdds/builtin/type_lookup_service/TypeLookupRequestListener.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void TypeLookupRequestListener::start_request_processor_thread()
112112
};
113113
// Create and start the processing thread
114114
request_processor_thread = eprosima::create_thread(thread_func,
115-
typelookup_manager_->participant_->copy_attributes().typelookup_service_thread,
115+
typelookup_manager_->participant_->get_const_attributes().typelookup_service_thread,
116116
"dds.tls.requests.%u");
117117
}
118118
}

src/cpp/rtps/builtin/BuiltinProtocols.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ bool BuiltinProtocols::initBuiltinProtocols(
8686

8787
filter_server_remote_locators(p_part->network_factory());
8888

89-
RTPSParticipantAllocationAttributes allocation = p_part->copy_attributes().allocation;
89+
const RTPSParticipantAllocationAttributes& allocation = p_part->get_const_attributes().allocation;
9090

9191
// PDP
9292
switch (m_att.discovery_config.discoveryProtocol)

src/cpp/rtps/builtin/discovery/endpoint/EDPSimple.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ void EDPSimple::assignRemoteEndpoints(
755755
const NetworkFactory& network = mp_RTPSParticipant->network_factory();
756756
uint32_t endp = pdata.m_available_builtin_endpoints;
757757
uint32_t auxendp;
758-
bool use_multicast_locators = !mp_PDP->getRTPSParticipant()->copy_attributes().builtin.avoid_builtin_multicast ||
758+
bool use_multicast_locators = !mp_PDP->getRTPSParticipant()->get_const_attributes().builtin.avoid_builtin_multicast ||
759759
pdata.metatraffic_locators.unicast.empty();
760760

761761
auto temp_reader_proxy_data = get_temporary_reader_proxies_pool().get();

src/cpp/rtps/builtin/discovery/endpoint/EDPStatic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ bool EDPStatic::initEDP(
137137
}
138138

139139
// Check there is a Participant's property changing the exchange format.
140-
auto properties = mp_RTPSParticipant->copy_attributes().properties.properties();
141-
for (auto& property : properties)
140+
const auto& properties = mp_RTPSParticipant->get_const_attributes().properties.properties();
141+
for (const auto& property : properties)
142142
{
143143
if (0 == property.name().compare(exchange_format_property_name))
144144
{

src/cpp/rtps/builtin/discovery/participant/PDP.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ ParticipantProxyData* PDP::add_participant_proxy_data(
179179
{
180180
// Pool is empty but limit has not been reached, so we create a new entry.
181181
++participant_proxies_number_;
182-
ret_val = new ParticipantProxyData(mp_RTPSParticipant->copy_attributes().allocation);
182+
ret_val = new ParticipantProxyData(mp_RTPSParticipant->get_const_attributes().allocation);
183183
if (participant_guid != mp_RTPSParticipant->getGuid())
184184
{
185185
ret_val->lease_duration_event = new TimedEvent(mp_RTPSParticipant->getEventResource(),
@@ -487,8 +487,7 @@ bool PDP::initPDP(
487487
{
488488
EPROSIMA_LOG_INFO(RTPS_PDP, "Beginning");
489489
mp_RTPSParticipant = part;
490-
m_discovery = mp_RTPSParticipant->copy_attributes().builtin;
491-
initial_announcements_ = m_discovery.discovery_config.initial_announcements;
490+
initial_announcements_ = mp_RTPSParticipant->get_const_attributes().builtin.discovery_config.initial_announcements;
492491
//CREATE ENDPOINTS
493492
if (!createPDPEndpoints())
494493
{
@@ -967,7 +966,7 @@ ReaderProxyData* PDP::addReaderProxyData(
967966
// Pool is empty but limit has not been reached, so we create a new entry.
968967
++reader_proxies_number_;
969968

970-
auto allocations = mp_RTPSParticipant->copy_attributes().allocation;
969+
const auto& allocations = mp_RTPSParticipant->get_const_attributes().allocation;
971970

972971
ret_val = new ReaderProxyData(
973972
allocations.locators.max_unicast_locators,
@@ -1055,7 +1054,7 @@ WriterProxyData* PDP::addWriterProxyData(
10551054
// Pool is empty but limit has not been reached, so we create a new entry.
10561055
++writer_proxies_number_;
10571056

1058-
auto allocations = mp_RTPSParticipant->copy_attributes().allocation;
1057+
const auto& allocations = mp_RTPSParticipant->get_const_attributes().allocation;
10591058

10601059
ret_val = new WriterProxyData(
10611060
allocations.locators.max_unicast_locators,
@@ -1518,7 +1517,7 @@ void PDP::resend_ininitial_announcements()
15181517
void PDP::set_external_participant_properties_(
15191518
ParticipantProxyData* participant_data)
15201519
{
1521-
auto part_attributes = mp_RTPSParticipant->copy_attributes();
1520+
const RTPSParticipantAttributes& part_attributes = mp_RTPSParticipant->get_const_attributes();
15221521

15231522
// For each property add it if it should be sent (it is propagated)
15241523
for (auto const& property : part_attributes.properties.properties())
@@ -1588,8 +1587,6 @@ static void set_builtin_endpoint_locators(
15881587
const PDP* pdp,
15891588
const BuiltinProtocols* builtin)
15901589
{
1591-
RTPSParticipantAttributes pattr = pdp->getRTPSParticipant()->copy_attributes();
1592-
15931590
auto part_data = pdp->getLocalParticipantProxyData();
15941591
if (nullptr == part_data)
15951592
{
@@ -1615,14 +1612,14 @@ static void set_builtin_endpoint_locators(
16151612

16161613
// External locators are always taken from the same place
16171614
endpoint.external_unicast_locators = pdp->builtin_attributes().metatraffic_external_unicast_locators;
1618-
endpoint.ignore_non_matching_locators = pattr.ignore_non_matching_locators;
1615+
endpoint.ignore_non_matching_locators = pdp->getRTPSParticipant()->get_const_attributes().ignore_non_matching_locators;
16191616
}
16201617

16211618
ReaderAttributes PDP::create_builtin_reader_attributes()
16221619
{
16231620
ReaderAttributes attributes;
16241621

1625-
RTPSParticipantAttributes pattr = getRTPSParticipant()->copy_attributes();
1622+
const RTPSParticipantAttributes& pattr = getRTPSParticipant()->get_const_attributes();
16261623
set_builtin_matched_allocation(attributes.matched_writers_allocation, pattr);
16271624

16281625
// Builtin endpoints are always reliable, transient local, keyed topics
@@ -1646,7 +1643,7 @@ WriterAttributes PDP::create_builtin_writer_attributes()
16461643
{
16471644
WriterAttributes attributes;
16481645

1649-
RTPSParticipantAttributes pattr = getRTPSParticipant()->copy_attributes();
1646+
const RTPSParticipantAttributes& pattr = getRTPSParticipant()->get_const_attributes();
16501647
set_builtin_matched_allocation(attributes.matched_readers_allocation, pattr);
16511648

16521649
// Builtin endpoints are always reliable, transient local, keyed topics

src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void PDPClient::initializeParticipantProxyData(
104104
{
105105
PDP::initializeParticipantProxyData(participant_data); // TODO: Remember that the PDP version USES security
106106

107-
auto discovery_config = getRTPSParticipant()->copy_attributes().builtin.discovery_config;
107+
const auto& discovery_config = getRTPSParticipant()->get_const_attributes().builtin.discovery_config;
108108

109109
if ((DiscoveryProtocol::CLIENT != discovery_config.discoveryProtocol) &&
110110
(DiscoveryProtocol::SUPER_CLIENT != discovery_config.discoveryProtocol))

src/cpp/rtps/builtin/discovery/participant/PDPListener.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace rtps {
4949
PDPListener::PDPListener(
5050
PDP* parent)
5151
: parent_pdp_(parent)
52-
, temp_participant_data_(parent->getRTPSParticipant()->copy_attributes().allocation)
52+
, temp_participant_data_(parent->getRTPSParticipant()->get_const_attributes().allocation)
5353
{
5454
}
5555

0 commit comments

Comments
 (0)