Skip to content

Commit

Permalink
Fix for lifetime of entities not matching the attached callback funct…
Browse files Browse the repository at this point in the history
…ions

Listeners on DataReader/DataWriter classes causing the
org::eclipse::cyclonedds::core::EntityDelegate::prevent_callbacks()
function to assert(false) when all references to it have expired
but there are still callbacks referencing it.
This is fixed by first acquiring a strong reference to the entity
assuring its lifetime for the callback function

Signed-off-by: Martijn Reicher <[email protected]>
  • Loading branch information
reicheratwork authored and eboasson committed Mar 22, 2023
1 parent a3c9606 commit a49b3f0
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 87 deletions.
50 changes: 33 additions & 17 deletions src/ddscxx/include/dds/pub/detail/DataWriterImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,11 +930,15 @@ void dds::pub::detail::DataWriter<T>::on_offered_deadline_missed(dds_entity_t,
dds::core::status::OfferedDeadlineMissedStatus s;
s.delegate() = sd;

dds::pub::DataWriter<T, dds::pub::detail::DataWriter> dw = wrapper();

dds::pub::DataWriterListener<T> *l =
reinterpret_cast<dds::pub::DataWriterListener<T> *>(this->listener_get());
l->on_offered_deadline_missed(dw, s);
auto sr = this->get_strong_ref();
if (sr) {
dds::pub::DataWriter<T, dds::pub::detail::DataWriter> dw = wrapper();

dds::pub::DataWriterListener<T> *l =
reinterpret_cast<dds::pub::DataWriterListener<T> *>(this->listener_get());
if (l)
l->on_offered_deadline_missed(dw, s);
}
}

template <typename T>
Expand All @@ -944,11 +948,15 @@ void dds::pub::detail::DataWriter<T>::on_offered_incompatible_qos(dds_entity_t,
dds::core::status::OfferedIncompatibleQosStatus s;
s.delegate() = sd;

dds::pub::DataWriter<T, dds::pub::detail::DataWriter> dw = wrapper();
auto sr = this->get_strong_ref();
if (sr) {
dds::pub::DataWriter<T, dds::pub::detail::DataWriter> dw = wrapper();

dds::pub::DataWriterListener<T> *l =
reinterpret_cast<dds::pub::DataWriterListener<T> *>(this->listener_get());
l->on_offered_incompatible_qos(dw, s);
dds::pub::DataWriterListener<T> *l =
reinterpret_cast<dds::pub::DataWriterListener<T> *>(this->listener_get());
if (l)
l->on_offered_incompatible_qos(dw, s);
}
}

template <typename T>
Expand All @@ -958,11 +966,15 @@ void dds::pub::detail::DataWriter<T>::on_liveliness_lost(dds_entity_t,
dds::core::status::LivelinessLostStatus s;
s.delegate() = sd;

dds::pub::DataWriter<T, dds::pub::detail::DataWriter> dw = wrapper();
auto sr = this->get_strong_ref();
if (sr) {
dds::pub::DataWriter<T, dds::pub::detail::DataWriter> dw = wrapper();

dds::pub::DataWriterListener<T> *l =
reinterpret_cast<dds::pub::DataWriterListener<T> *>(this->listener_get());
l->on_liveliness_lost(dw, s);
dds::pub::DataWriterListener<T> *l =
reinterpret_cast<dds::pub::DataWriterListener<T> *>(this->listener_get());
if (l)
l->on_liveliness_lost(dw, s);
}
}

template <typename T>
Expand All @@ -972,11 +984,15 @@ void dds::pub::detail::DataWriter<T>::on_publication_matched(dds_entity_t,
dds::core::status::PublicationMatchedStatus s;
s.delegate() = sd;

dds::pub::DataWriter<T, dds::pub::detail::DataWriter> dw = wrapper();
auto sr = this->get_strong_ref();
if (sr) {
dds::pub::DataWriter<T, dds::pub::detail::DataWriter> dw = wrapper();

dds::pub::DataWriterListener<T> *l =
reinterpret_cast<dds::pub::DataWriterListener<T> *>(this->listener_get());
l->on_publication_matched(dw, s);
dds::pub::DataWriterListener<T> *l =
reinterpret_cast<dds::pub::DataWriterListener<T> *>(this->listener_get());
if (l)
l->on_publication_matched(dw, s);
}
}

#endif /* OMG_DDS_PUB_DATA_WRITER_IMPL_HPP_ */
80 changes: 54 additions & 26 deletions src/ddscxx/include/dds/sub/detail/TDataReaderImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,11 +1351,15 @@ void dds::sub::detail::DataReader<T>::on_requested_deadline_missed(dds_entity_t,
dds::core::status::RequestedDeadlineMissedStatus s;
s.delegate() = sd;

dds::sub::DataReader<T, dds::sub::detail::DataReader> dr = wrapper();
auto sr = this->get_strong_ref();
if (sr) {
dds::sub::DataReader<T, dds::sub::detail::DataReader> dr = wrapper();

dds::sub::DataReaderListener<T> *l =
reinterpret_cast<dds::sub::DataReaderListener<T> *>(this->listener_get());
l->on_requested_deadline_missed(dr, s);
dds::sub::DataReaderListener<T> *l =
reinterpret_cast<dds::sub::DataReaderListener<T> *>(this->listener_get());
if (l)
l->on_requested_deadline_missed(dr, s);
}
}

template <typename T>
Expand All @@ -1365,11 +1369,15 @@ void dds::sub::detail::DataReader<T>::on_requested_incompatible_qos(dds_entity_t
dds::core::status::RequestedIncompatibleQosStatus s;
s.delegate() = sd;

dds::sub::DataReader<T, dds::sub::detail::DataReader> dr = wrapper();
auto sr = this->get_strong_ref();
if (sr) {
dds::sub::DataReader<T, dds::sub::detail::DataReader> dr = wrapper();

dds::sub::DataReaderListener<T> *l =
reinterpret_cast<dds::sub::DataReaderListener<T> *>(this->listener_get());
l->on_requested_incompatible_qos(dr, s);
dds::sub::DataReaderListener<T> *l =
reinterpret_cast<dds::sub::DataReaderListener<T> *>(this->listener_get());
if (l)
l->on_requested_incompatible_qos(dr, s);
}
}

template <typename T>
Expand All @@ -1379,11 +1387,15 @@ void dds::sub::detail::DataReader<T>::on_sample_rejected(dds_entity_t,
dds::core::status::SampleRejectedStatus s;
s.delegate() = sd;

dds::sub::DataReader<T, dds::sub::detail::DataReader> dr = wrapper();
auto sr = this->get_strong_ref();
if (sr) {
dds::sub::DataReader<T, dds::sub::detail::DataReader> dr = wrapper();

dds::sub::DataReaderListener<T> *l =
dds::sub::DataReaderListener<T>* l =
reinterpret_cast<dds::sub::DataReaderListener<T> *>(this->listener_get());
l->on_sample_rejected(dr, s);
if (l)
l->on_sample_rejected(dr, s);
}
}


Expand All @@ -1394,21 +1406,29 @@ void dds::sub::detail::DataReader<T>::on_liveliness_changed(dds_entity_t,
dds::core::status::LivelinessChangedStatus s;
s.delegate() = sd;

dds::sub::DataReader<T, dds::sub::detail::DataReader> dr = wrapper();
auto sr = this->get_strong_ref();
if (sr) {
dds::sub::DataReader<T, dds::sub::detail::DataReader> dr = wrapper();

dds::sub::DataReaderListener<T> *l =
dds::sub::DataReaderListener<T>* l =
reinterpret_cast<dds::sub::DataReaderListener<T> *>(this->listener_get());
l->on_liveliness_changed(dr, s);
if (l)
l->on_liveliness_changed(dr, s);
}
}

template <typename T>
void dds::sub::detail::DataReader<T>::on_data_available(dds_entity_t)
{
dds::sub::DataReader<T, dds::sub::detail::DataReader> dr = wrapper();
auto sr = this->get_strong_ref();
if (sr) {
dds::sub::DataReader<T, dds::sub::detail::DataReader> dr = wrapper();

dds::sub::DataReaderListener<T> *l =
reinterpret_cast<dds::sub::DataReaderListener<T> *>(this->listener_get());
l->on_data_available(dr);
dds::sub::DataReaderListener<T>* l =
reinterpret_cast<dds::sub::DataReaderListener<T> *>(this->listener_get());
if (l)
l->on_data_available(dr);
}
}

template <typename T>
Expand All @@ -1418,11 +1438,15 @@ void dds::sub::detail::DataReader<T>::on_subscription_matched(dds_entity_t,
dds::core::status::SubscriptionMatchedStatus s;
s.delegate() = sd;

dds::sub::DataReader<T, dds::sub::detail::DataReader> dr = wrapper();
auto sr = this->get_strong_ref();
if (sr) {
dds::sub::DataReader<T, dds::sub::detail::DataReader> dr = wrapper();

dds::sub::DataReaderListener<T> *l =
reinterpret_cast<dds::sub::DataReaderListener<T> *>(this->listener_get());
l->on_subscription_matched(dr, s);
dds::sub::DataReaderListener<T>* l =
reinterpret_cast<dds::sub::DataReaderListener<T> *>(this->listener_get());
if (l)
l->on_subscription_matched(dr, s);
}
}

template <typename T>
Expand All @@ -1432,11 +1456,15 @@ void dds::sub::detail::DataReader<T>::on_sample_lost(dds_entity_t,
dds::core::status::SampleLostStatus s;
s.delegate() = sd;

dds::sub::DataReader<T, dds::sub::detail::DataReader> dr = wrapper();
auto sr = this->get_strong_ref();
if (sr) {
dds::sub::DataReader<T, dds::sub::detail::DataReader> dr = wrapper();

dds::sub::DataReaderListener<T> *l =
reinterpret_cast<dds::sub::DataReaderListener<T> *>(this->listener_get());
l->on_sample_lost(dr, s);
dds::sub::DataReaderListener<T> *l =
reinterpret_cast<dds::sub::DataReaderListener<T> *>(this->listener_get());
if (l)
l->on_sample_lost(dr, s);
}
}

// End of implementation
Expand Down
Loading

0 comments on commit a49b3f0

Please sign in to comment.