Skip to content

Commit 5fc790c

Browse files
Separate initialization and enabling of BuiltinProtocols (#2171)
* Refs #12355. Separate initialization and enable of BuiltinProtocols Signed-off-by: Ricardo González Moreno <[email protected]> Signed-off-by: Ricardo González <[email protected]> * Refs #12355. Fix segmentation fault Signed-off-by: Ricardo González Moreno <[email protected]> Signed-off-by: Ricardo González <[email protected]> * Refs #12378. Change order of calling user callback Ensure good behaviour with static discovery, calling first for participant and later for endpoints. Signed-off-by: Ricardo González Moreno <[email protected]> Signed-off-by: Ricardo González <[email protected]> * Refs #12378. Fix error not enabling correctly PDP Signed-off-by: Ricardo González Moreno <[email protected]> Signed-off-by: Ricardo González <[email protected]> * Refs #12257. Create statistics endpoints before enable participant Signed-off-by: Ricardo González <[email protected]> * Apply suggestions from code review Co-authored-by: Miguel Company <[email protected]> Signed-off-by: Ricardo González <[email protected]> * Refs #12388. Apply suggestions Signed-off-by: Ricardo González Moreno <[email protected]> Signed-off-by: Ricardo González <[email protected]> * Apply suggestion Co-authored-by: Miguel Company <[email protected]> Signed-off-by: Ricardo González <[email protected]> Co-authored-by: Miguel Company <[email protected]>
1 parent 04abfba commit 5fc790c

File tree

11 files changed

+380
-340
lines changed

11 files changed

+380
-340
lines changed

include/fastdds/rtps/builtin/BuiltinProtocols.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ class BuiltinProtocols
7878
RTPSParticipantImpl* p_part,
7979
BuiltinAttributes& attributes);
8080

81+
/**
82+
* Enable the builtin protocols
83+
*/
84+
void enable();
85+
8186
/**
8287
* Update the metatraffic locatorlist after it was created. Because when you create
8388
* the EDP readers you are not sure the selected endpoints can be used.

include/fastdds/rtps/builtin/discovery/participant/PDP.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ class PDP
401401
std::recursive_mutex* mp_mutex;
402402
//!To protect callbacks (ParticipantProxyData&)
403403
std::mutex callback_mtx_;
404+
//!Tell if object is enabled
405+
bool enable_ = false;
404406

405407
/**
406408
* Adds an entry to the collection of participant proxy information.

src/cpp/fastdds/domain/DomainParticipantImpl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ ReturnCode_t DomainParticipantImpl::enable()
284284

285285
guid_ = part->getGuid();
286286
rtps_participant_ = part;
287-
rtps_participant_->enable();
288287

289288
rtps_participant_->set_check_type_function(
290289
[this](const std::string& type_name) -> bool
@@ -326,6 +325,8 @@ ReturnCode_t DomainParticipantImpl::enable()
326325
}
327326
}
328327

328+
rtps_participant_->enable();
329+
329330
return ReturnCode_t::RETCODE_OK;
330331
}
331332

src/cpp/rtps/builtin/BuiltinProtocols.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,19 @@ bool BuiltinProtocols::initBuiltinProtocols(
146146
tlm_->init_typelookup_service(mp_participantImpl);
147147
}
148148

149-
mp_PDP->announceParticipantState(true);
150-
mp_PDP->resetParticipantAnnouncement();
151-
mp_PDP->enable();
152-
153149
return true;
154150
}
155151

152+
void BuiltinProtocols::enable()
153+
{
154+
if (nullptr != mp_PDP)
155+
{
156+
mp_PDP->enable();
157+
mp_PDP->announceParticipantState(true);
158+
mp_PDP->resetParticipantAnnouncement();
159+
}
160+
}
161+
156162
bool BuiltinProtocols::updateMetatrafficLocators(
157163
LocatorList_t& loclist)
158164
{

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

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ bool PDP::initPDP(
373373
mp_builtin->updateMetatrafficLocators(this->mp_PDPReader->getAttributes().unicastLocatorList);
374374

375375
mp_mutex->lock();
376-
ParticipantProxyData* pdata = add_participant_proxy_data(part->getGuid(), false);
376+
ParticipantProxyData* pdata = add_participant_proxy_data(mp_RTPSParticipant->getGuid(), false);
377377
mp_mutex->unlock();
378378

379379
if (pdata == nullptr)
@@ -382,6 +382,11 @@ bool PDP::initPDP(
382382
}
383383
initializeParticipantProxyData(pdata);
384384

385+
return true;
386+
}
387+
388+
bool PDP::enable()
389+
{
385390
// Create lease events on already created proxy data objects
386391
for (ParticipantProxyData* pool_item : participant_proxies_pool_)
387392
{
@@ -404,11 +409,8 @@ bool PDP::initPDP(
404409

405410
set_initial_announcement_interval();
406411

407-
return true;
408-
}
412+
enable_ = true;
409413

410-
bool PDP::enable()
411-
{
412414
return mp_RTPSParticipant->enableReader(mp_PDPReader);
413415
}
414416

@@ -417,30 +419,75 @@ void PDP::announceParticipantState(
417419
bool dispose,
418420
WriteParams& wparams)
419421
{
420-
// logInfo(RTPS_PDP, "Announcing RTPSParticipant State (new change: " << new_change << ")");
421-
CacheChange_t* change = nullptr;
422-
423-
if (!dispose)
422+
if (enable_)
424423
{
425-
if (m_hasChangedLocalPDP.exchange(false) || new_change)
424+
// logInfo(RTPS_PDP, "Announcing RTPSParticipant State (new change: " << new_change << ")");
425+
CacheChange_t* change = nullptr;
426+
427+
if (!dispose)
428+
{
429+
if (m_hasChangedLocalPDP.exchange(false) || new_change)
430+
{
431+
this->mp_mutex->lock();
432+
ParticipantProxyData* local_participant_data = getLocalParticipantProxyData();
433+
InstanceHandle_t key = local_participant_data->m_key;
434+
ParticipantProxyData proxy_data_copy(*local_participant_data);
435+
this->mp_mutex->unlock();
436+
437+
if (mp_PDPWriterHistory->getHistorySize() > 0)
438+
{
439+
mp_PDPWriterHistory->remove_min_change();
440+
}
441+
uint32_t cdr_size = proxy_data_copy.get_serialized_size(true);
442+
change = mp_PDPWriter->new_change(
443+
[cdr_size]() -> uint32_t
444+
{
445+
return cdr_size;
446+
},
447+
ALIVE, key);
448+
449+
if (change != nullptr)
450+
{
451+
CDRMessage_t aux_msg(change->serializedPayload);
452+
453+
#if __BIG_ENDIAN__
454+
change->serializedPayload.encapsulation = (uint16_t)PL_CDR_BE;
455+
aux_msg.msg_endian = BIGEND;
456+
#else
457+
change->serializedPayload.encapsulation = (uint16_t)PL_CDR_LE;
458+
aux_msg.msg_endian = LITTLEEND;
459+
#endif // if __BIG_ENDIAN__
460+
461+
if (proxy_data_copy.writeToCDRMessage(&aux_msg, true))
462+
{
463+
change->serializedPayload.length = (uint16_t)aux_msg.length;
464+
465+
mp_PDPWriterHistory->add_change(change, wparams);
466+
}
467+
else
468+
{
469+
logError(RTPS_PDP, "Cannot serialize ParticipantProxyData.");
470+
}
471+
}
472+
}
473+
474+
}
475+
else
426476
{
427477
this->mp_mutex->lock();
428-
ParticipantProxyData* local_participant_data = getLocalParticipantProxyData();
429-
InstanceHandle_t key = local_participant_data->m_key;
430-
ParticipantProxyData proxy_data_copy(*local_participant_data);
478+
ParticipantProxyData proxy_data_copy(*getLocalParticipantProxyData());
431479
this->mp_mutex->unlock();
432480

433481
if (mp_PDPWriterHistory->getHistorySize() > 0)
434482
{
435483
mp_PDPWriterHistory->remove_min_change();
436484
}
437485
uint32_t cdr_size = proxy_data_copy.get_serialized_size(true);
438-
change = mp_PDPWriter->new_change(
439-
[cdr_size]() -> uint32_t
440-
{
441-
return cdr_size;
442-
},
443-
ALIVE, key);
486+
change = mp_PDPWriter->new_change([cdr_size]() -> uint32_t
487+
{
488+
return cdr_size;
489+
},
490+
NOT_ALIVE_DISPOSED_UNREGISTERED, getLocalParticipantProxyData()->m_key);
444491

445492
if (change != nullptr)
446493
{
@@ -466,48 +513,6 @@ void PDP::announceParticipantState(
466513
}
467514
}
468515
}
469-
470-
}
471-
else
472-
{
473-
this->mp_mutex->lock();
474-
ParticipantProxyData proxy_data_copy(*getLocalParticipantProxyData());
475-
this->mp_mutex->unlock();
476-
477-
if (mp_PDPWriterHistory->getHistorySize() > 0)
478-
{
479-
mp_PDPWriterHistory->remove_min_change();
480-
}
481-
uint32_t cdr_size = proxy_data_copy.get_serialized_size(true);
482-
change = mp_PDPWriter->new_change([cdr_size]() -> uint32_t
483-
{
484-
return cdr_size;
485-
},
486-
NOT_ALIVE_DISPOSED_UNREGISTERED, getLocalParticipantProxyData()->m_key);
487-
488-
if (change != nullptr)
489-
{
490-
CDRMessage_t aux_msg(change->serializedPayload);
491-
492-
#if __BIG_ENDIAN__
493-
change->serializedPayload.encapsulation = (uint16_t)PL_CDR_BE;
494-
aux_msg.msg_endian = BIGEND;
495-
#else
496-
change->serializedPayload.encapsulation = (uint16_t)PL_CDR_LE;
497-
aux_msg.msg_endian = LITTLEEND;
498-
#endif // if __BIG_ENDIAN__
499-
500-
if (proxy_data_copy.writeToCDRMessage(&aux_msg, true))
501-
{
502-
change->serializedPayload.length = (uint16_t)aux_msg.length;
503-
504-
mp_PDPWriterHistory->add_change(change, wparams);
505-
}
506-
else
507-
{
508-
logError(RTPS_PDP, "Cannot serialize ParticipantProxyData.");
509-
}
510-
}
511516
}
512517

513518
}

0 commit comments

Comments
 (0)