Skip to content

Commit 44687c5

Browse files
author
jparisu
committed
Refs #15831: Remove acyclic shared_ptrs
Signed-off-by: jparisu <[email protected]>
1 parent a07fbcf commit 44687c5

File tree

5 files changed

+323
-45
lines changed

5 files changed

+323
-45
lines changed

include/fastdds_statistics_backend/exception/Exception.hpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,35 @@ class CorruptedFile : public Exception
292292
const CorruptedFile& other) = default;
293293
};
294294

295+
/**
296+
* @brief Exception to signal that there has been found an inconsistency inside the database.
297+
*/
298+
class Inconsistency : public Exception
299+
{
300+
301+
public:
302+
303+
using Exception::Exception;
304+
305+
/**
306+
* @brief Copies the statistics_backend::Inconsistency exception into a new one
307+
*
308+
* @param other The original exception object to copy
309+
*/
310+
FASTDDS_STATISTICS_BACKEND_DllAPI Inconsistency(
311+
const Inconsistency& other) = default;
312+
313+
/**
314+
* @brief Copies the statistics_backend::Inconsistency exception into the current one
315+
*
316+
* @param other The original statistics_backend::Inconsistency exception to copy
317+
* @return the current statistics_backend::Inconsistency exception after the copy
318+
*/
319+
FASTDDS_STATISTICS_BACKEND_DllAPI Inconsistency& operator =(
320+
const Inconsistency& other) = default;
321+
};
322+
295323
} // namespace statistics_backend
296324
} // namespace eprosima
297325

298-
299326
#endif // _EPROSIMA_FASTDDS_STATISTICS_BACKEND_EXCEPTION_EXCEPTION_HPP_
300-

src/cpp/database/database.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ class Database
469469
throw BadParameter("Endpoint locators cannot be empty");
470470
}
471471

472-
/* Check that participant exits */
472+
/* Check that participant exists */
473473
bool participant_exists = false;
474474
auto domain_participants = participants_.find(endpoint->participant->domain->id);
475475
if (domain_participants != participants_.end())
@@ -589,11 +589,11 @@ class Database
589589
}
590590
}
591591

592-
// Change the curent locators map for the new updated one
593-
endpoint->locators = actual_locators_map;
592+
// Remove the current locator map as it will be filled in following loop
593+
endpoint->locators.clear();
594594

595595
/* Add to x_by_y_ collections and to locators_ */
596-
for (auto& locator_it : endpoint->locators)
596+
for (auto& locator_it : actual_locators_map)
597597
{
598598
/* Check that locator exists */
599599
if (locators_.find(locator_it.first) == locators_.end())
@@ -608,6 +608,9 @@ class Database
608608
participants_by_locator_[locator_it.first][endpoint->participant->id] = endpoint->participant;
609609
// Add endpoint to locator's collection
610610
insert_ddsendpoint_to_locator(endpoint, locator_it.second);
611+
612+
// Add this locator to the locators map
613+
endpoint->locators[locator_it.first] = locator_it.second;
611614
}
612615

613616
/* Add endpoint to topics's collection */

src/cpp/database/entities.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ DDSEndpoint::DDSEndpoint(
5858
std::string endpoint_name, /* "INVALID" */
5959
Qos endpoint_qos, /* {} */
6060
std::string endpoint_guid, /* "|GUID UNKNOWN|" */
61-
std::shared_ptr<DomainParticipant> endpoint_participant, /* nullptr */
62-
std::shared_ptr<Topic> endpoint_topic /* nullptr */) noexcept
61+
details::fragile_ptr<DomainParticipant> endpoint_participant, /* nullptr */
62+
details::fragile_ptr<Topic> endpoint_topic /* nullptr */) noexcept
6363
: DDSEntity(entity_kind, endpoint_name, endpoint_qos, endpoint_guid)
6464
, participant(endpoint_participant)
6565
, topic(endpoint_topic)
@@ -121,25 +121,25 @@ void Locator::clear()
121121
}
122122

123123
template<>
124-
std::map<EntityId, std::shared_ptr<DataReader>>& DomainParticipant::ddsendpoints<DataReader>()
124+
std::map<EntityId, details::fragile_ptr<DataReader>>& DomainParticipant::ddsendpoints<DataReader>()
125125
{
126126
return data_readers;
127127
}
128128

129129
template<>
130-
std::map<EntityId, std::shared_ptr<DataWriter>>& DomainParticipant::ddsendpoints<DataWriter>()
130+
std::map<EntityId, details::fragile_ptr<DataWriter>>& DomainParticipant::ddsendpoints<DataWriter>()
131131
{
132132
return data_writers;
133133
}
134134

135135
template<>
136-
std::map<EntityId, std::shared_ptr<DataReader>>& Topic::ddsendpoints<DataReader>()
136+
std::map<EntityId, details::fragile_ptr<DataReader>>& Topic::ddsendpoints<DataReader>()
137137
{
138138
return data_readers;
139139
}
140140

141141
template<>
142-
std::map<EntityId, std::shared_ptr<DataWriter>>& Topic::ddsendpoints<DataWriter>()
142+
std::map<EntityId, details::fragile_ptr<DataWriter>>& Topic::ddsendpoints<DataWriter>()
143143
{
144144
return data_writers;
145145
}

src/cpp/database/entities.hpp

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <fastdds_statistics_backend/types/types.hpp>
2626
#include <fastdds_statistics_backend/types/EntityId.hpp>
2727

28+
#include <types/fragile_ptr.hpp>
29+
2830
#include "data.hpp"
2931

3032
namespace eprosima {
@@ -118,7 +120,7 @@ struct Host : Entity
118120
* Collection of users within the host which are involved in the communication.
119121
* The collection is ordered by the EntityId of the user nodes.
120122
*/
121-
std::map<EntityId, std::shared_ptr<User>> users;
123+
std::map<EntityId, details::fragile_ptr<User>> users;
122124
};
123125

124126
/*
@@ -128,7 +130,7 @@ struct User : Entity
128130
{
129131
User(
130132
std::string user_name,
131-
std::shared_ptr<Host> user_host) noexcept
133+
details::fragile_ptr<Host> user_host) noexcept
132134
: Entity(EntityKind::USER, user_name, false, false)
133135
, host(user_host)
134136
{
@@ -140,13 +142,13 @@ struct User : Entity
140142
void clear() final;
141143

142144
//! Reference to the Host in which this user runs
143-
std::shared_ptr<Host> host;
145+
details::fragile_ptr<Host> host;
144146

145147
/*
146148
* Collection of processes within the host which are involved in the communication.
147149
* The collection is ordered by the EntityId of the process nodes.
148150
*/
149-
std::map<EntityId, std::shared_ptr<Process>> processes;
151+
std::map<EntityId, details::fragile_ptr<Process>> processes;
150152
};
151153

152154
/*
@@ -157,7 +159,7 @@ struct Process : Entity
157159
Process(
158160
std::string process_name,
159161
std::string process_id,
160-
std::shared_ptr<User> process_user) noexcept
162+
details::fragile_ptr<User> process_user) noexcept
161163
: Entity(EntityKind::PROCESS, process_name, false, false)
162164
, pid(process_id)
163165
, user(process_user)
@@ -173,13 +175,13 @@ struct Process : Entity
173175
std::string pid;
174176

175177
//! Reference to the User in which this process runs.
176-
std::shared_ptr<User> user;
178+
details::fragile_ptr<User> user;
177179

178180
/*
179181
* Collection of DomainParticipant within the process which are involved in the communication.
180182
* The collection is ordered by the EntityId of the DomainParticipant nodes.
181183
*/
182-
std::map<EntityId, std::shared_ptr<DomainParticipant>> participants;
184+
std::map<EntityId, details::fragile_ptr<DomainParticipant>> participants;
183185
};
184186

185187
/*
@@ -203,13 +205,13 @@ struct Domain : Entity
203205
* Collection of Topics within the Domain which are either published, subscribed, or both.
204206
* The collection is ordered by the EntityId of the Topic nodes.
205207
*/
206-
std::map<EntityId, std::shared_ptr<Topic>> topics;
208+
std::map<EntityId, details::fragile_ptr<Topic>> topics;
207209

208210
/*
209211
* Collection of DomainParticipant within the Domain which are involved in the communication.
210212
* The collection is ordered by the EntityId of the DomainParticipant nodes.
211213
*/
212-
std::map<EntityId, std::shared_ptr<DomainParticipant>> participants;
214+
std::map<EntityId, details::fragile_ptr<DomainParticipant>> participants;
213215
};
214216

215217
/*
@@ -245,14 +247,14 @@ struct DDSEndpoint : DDSEntity
245247
std::string endpoint_name = "INVALID",
246248
Qos endpoint_qos = {},
247249
std::string endpoint_guid = "|GUID UNKNOWN|",
248-
std::shared_ptr<DomainParticipant> endpoint_participant = nullptr,
249-
std::shared_ptr<Topic> endpoint_topic = nullptr) noexcept;
250+
details::fragile_ptr<DomainParticipant> endpoint_participant = nullptr,
251+
details::fragile_ptr<Topic> endpoint_topic = nullptr) noexcept;
250252

251253
//! Reference to the DomainParticipant in which this Endpoint runs.
252-
std::shared_ptr<DomainParticipant> participant;
254+
details::fragile_ptr<DomainParticipant> participant;
253255

254256
//! Reference to the Domain in which this endpoint publishes/subscribes.
255-
std::shared_ptr<Topic> topic;
257+
details::fragile_ptr<Topic> topic;
256258

257259
//! Flag to signal that this is a virtual endpoint used to collect meta traffic data.
258260
bool is_virtual_metatraffic = false;
@@ -261,7 +263,7 @@ struct DDSEndpoint : DDSEntity
261263
* Collection of Locators related to this endpoint.
262264
* The collection is ordered by the EntityId of the Locator nodes.
263265
*/
264-
std::map<EntityId, std::shared_ptr<Locator>> locators;
266+
std::map<EntityId, details::fragile_ptr<Locator>> locators;
265267
};
266268

267269
/*
@@ -273,8 +275,8 @@ struct DomainParticipant : DDSEntity
273275
std::string participant_name,
274276
Qos participant_qos,
275277
std::string participant_guid,
276-
std::shared_ptr<Process> participant_process,
277-
std::shared_ptr<Domain> participant_domain) noexcept
278+
details::fragile_ptr<Process> participant_process,
279+
details::fragile_ptr<Domain> participant_domain) noexcept
278280
: DDSEntity(EntityKind::PARTICIPANT, participant_name, participant_qos, participant_guid)
279281
, process(participant_process)
280282
, domain(participant_domain)
@@ -287,28 +289,28 @@ struct DomainParticipant : DDSEntity
287289
void clear() final;
288290

289291
template<typename T>
290-
std::map<EntityId, std::shared_ptr<T>>& ddsendpoints();
292+
std::map<EntityId, details::fragile_ptr<T>>& ddsendpoints();
291293

292294
//! Reference to the Process in which this DomainParticipant runs.
293-
std::shared_ptr<Process> process;
295+
details::fragile_ptr<Process> process;
294296

295297
//! Reference to the Domain in which this DomainParticipant runs.
296-
std::shared_ptr<Domain> domain;
298+
details::fragile_ptr<Domain> domain;
297299

298300
//! Reference to the meta traffic endpoint of this DomainParticipant.
299-
std::shared_ptr<DDSEndpoint> meta_traffic_endpoint;
301+
details::fragile_ptr<DDSEndpoint> meta_traffic_endpoint;
300302

301303
/*
302304
* Collection of DataReaders within the DomainParticipant which are involved in the communication.
303305
* The collection is ordered by the EntityId of the DataReader nodes.
304306
*/
305-
std::map<EntityId, std::shared_ptr<DataReader>> data_readers;
307+
std::map<EntityId, details::fragile_ptr<DataReader>> data_readers;
306308

307309
/*
308310
* Collection of DataWriters within the DomainParticipant which are involved in the communication.
309311
* The collection is ordered by the EntityId of the DataWriter nodes.
310312
*/
311-
std::map<EntityId, std::shared_ptr<DataWriter>> data_writers;
313+
std::map<EntityId, details::fragile_ptr<DataWriter>> data_writers;
312314

313315
//! Actual statistical data reported by Fast DDS Statistics Module regarding this DomainParticipant.
314316
DomainParticipantData data;
@@ -323,7 +325,7 @@ struct Topic : Entity
323325
Topic(
324326
std::string topic_name,
325327
std::string topic_type,
326-
std::shared_ptr<Domain> topic_domain) noexcept
328+
details::fragile_ptr<Domain> topic_domain) noexcept
327329
: Entity(EntityKind::TOPIC, topic_name, is_metatraffic_topic(topic_name))
328330
, data_type(topic_type)
329331
, domain(topic_domain)
@@ -336,25 +338,25 @@ struct Topic : Entity
336338
void clear() final;
337339

338340
template<typename T>
339-
std::map<EntityId, std::shared_ptr<T>>& ddsendpoints();
341+
std::map<EntityId, details::fragile_ptr<T>>& ddsendpoints();
340342

341343
//! The data type name of the topic
342344
std::string data_type;
343345

344346
//! Reference to the Domain in which this topic is published/subscribed.
345-
std::shared_ptr<Domain> domain;
347+
details::fragile_ptr<Domain> domain;
346348

347349
/*
348350
* Collection of Datareaders subscribing to this topic.
349351
* The collection is ordered by the EntityId of the Datareader nodes.
350352
*/
351-
std::map<EntityId, std::shared_ptr<DataReader>> data_readers;
353+
std::map<EntityId, details::fragile_ptr<DataReader>> data_readers;
352354

353355
/*
354356
* Collection of DataWriters publishind in this topic.
355357
* The collection is ordered by the EntityId of the DataWriter nodes.
356358
*/
357-
std::map<EntityId, std::shared_ptr<DataWriter>> data_writers;
359+
std::map<EntityId, details::fragile_ptr<DataWriter>> data_writers;
358360
};
359361

360362
/*
@@ -366,8 +368,8 @@ struct DataReader : DDSEndpoint
366368
std::string datareader_name,
367369
Qos datareader_qos,
368370
std::string datareader_guid,
369-
std::shared_ptr<DomainParticipant> datareader_participant,
370-
std::shared_ptr<Topic> datareader_topic) noexcept
371+
details::fragile_ptr<DomainParticipant> datareader_participant,
372+
details::fragile_ptr<Topic> datareader_topic) noexcept
371373
: DDSEndpoint(EntityKind::DATAREADER, datareader_name, datareader_qos, datareader_guid, datareader_participant,
372374
datareader_topic)
373375
{
@@ -392,8 +394,8 @@ struct DataWriter : DDSEndpoint
392394
std::string datawriter_name,
393395
Qos datawriter_qos,
394396
std::string datawriter_guid,
395-
std::shared_ptr<DomainParticipant> datawriter_participant,
396-
std::shared_ptr<Topic> datawriter_topic) noexcept
397+
details::fragile_ptr<DomainParticipant> datawriter_participant,
398+
details::fragile_ptr<Topic> datawriter_topic) noexcept
397399
: DDSEndpoint(EntityKind::DATAWRITER, datawriter_name, datawriter_qos, datawriter_guid, datawriter_participant,
398400
datawriter_topic)
399401
{
@@ -430,13 +432,13 @@ struct Locator : Entity
430432
* Collection of DataReaders using this locator.
431433
* The collection is ordered by the EntityId of the DataReader nodes.
432434
*/
433-
std::map<EntityId, std::shared_ptr<DataReader>> data_readers;
435+
std::map<EntityId, details::fragile_ptr<DataReader>> data_readers;
434436

435437
/*
436438
* Collection of DataWriters using this locator.
437439
* The collection is ordered by the EntityId of the DataWriter nodes.
438440
*/
439-
std::map<EntityId, std::shared_ptr<DataWriter>> data_writers;
441+
std::map<EntityId, details::fragile_ptr<DataWriter>> data_writers;
440442
};
441443

442444
} //namespace database

0 commit comments

Comments
 (0)