File tree Expand file tree Collapse file tree
test/mock/rtps/DataSharingPayloadPool/rtps/DataSharing Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -369,20 +369,12 @@ ReturnCode_t DataWriterImpl::enable()
369369 w_att.endpoint .data_sharing_configuration ().kind () != DataSharingKind::OFF )
370370 {
371371 auto writer_pool = std::dynamic_pointer_cast<fastdds::rtps::WriterPool>(pool);
372- if (!writer_pool || !writer_pool->init_shared_memory (
373- writer, w_att.endpoint .data_sharing_configuration ().shm_directory ()))
372+ if (!writer_pool || !writer_pool->is_initialized ())
374373 {
375374 EPROSIMA_LOG_ERROR (DATA_WRITER , " Could not initialize DataSharing writer pool" );
376375 RTPSDomain::removeRTPSWriter (writer);
377376 writer = nullptr ;
378377 }
379- else
380- {
381- for (auto it = history_->changesBegin (); it != history_->changesEnd (); ++it)
382- {
383- writer_pool->add_to_shared_history (*it);
384- }
385- }
386378 }
387379
388380 if (writer == nullptr &&
Original file line number Diff line number Diff line change @@ -49,6 +49,17 @@ PersistentWriter::PersistentWriter(
4949 hist->m_isHistoryFull =
5050 hist->m_att .maximumReservedCaches > 0 &&
5151 static_cast <int32_t >(hist->m_changes .size ()) == hist->m_att .maximumReservedCaches ;
52+
53+ // Prepare the changes for datasharing if compatible
54+ if (att.endpoint .data_sharing_configuration ().kind () != dds::DataSharingKind::OFF )
55+ {
56+ auto pool = std::dynamic_pointer_cast<WriterPool>(hist->get_payload_pool ());
57+ assert (pool != nullptr );
58+ for (auto change : hist->m_changes )
59+ {
60+ pool->add_to_shared_history (change);
61+ }
62+ }
5263}
5364
5465PersistentWriter::~PersistentWriter ()
Original file line number Diff line number Diff line change 1919
2020#include < fastdds/rtps/writer/RTPSWriter.h>
2121
22+ #include < memory>
2223#include < mutex>
2324
2425#include < fastdds/dds/log/Log.hpp>
@@ -84,6 +85,15 @@ void RTPSWriter::init(
8485 fixed_payload_size_ = mp_history->m_att .payloadMaxSize ;
8586 }
8687
88+ if (att.endpoint .data_sharing_configuration ().kind () != dds::OFF )
89+ {
90+ std::shared_ptr<WriterPool> pool = std::dynamic_pointer_cast<WriterPool>(mp_history->get_payload_pool ());
91+ if (!pool || !pool->init_shared_memory (this , att.endpoint .data_sharing_configuration ().shm_directory ()))
92+ {
93+ EPROSIMA_LOG_ERROR (RTPS_WRITER , " Could not initialize DataSharing writer pool" );
94+ }
95+ }
96+
8797 mp_history->mp_writer = this ;
8898 mp_history->mp_mutex = &mp_mutex;
8999
Original file line number Diff line number Diff line change @@ -42,6 +42,11 @@ class WriterPool : public DataSharingPayloadPool
4242 return true ;
4343 }
4444
45+ bool is_initialized () const
46+ {
47+ return writer_guid_ != GUID_t::unknown ();
48+ }
49+
4550 void add_to_shared_history (
4651 const CacheChange_t* /* cache_change*/ )
4752 {
You can’t perform that action at this time.
0 commit comments