Skip to content

Commit

Permalink
Fixed missing callbacks for pending events
Browse files Browse the repository at this point in the history
When creating an Entity with a Listener, any instantaneous events that occurred during creation would miss their callback.
This was caused by the C++ API not being able to wrap the underlying C API with a C++ object prior to C already trying to invoking the callback.
That is now resolved by not setting the Listener at creation time, but by setting it after successfully putting a C++ wrapper around the underlying C Entity.
This should fix issue eclipse-cyclonedds#410
A prerequisite for applying this fix is to make sure pull request #eclipse-cyclonedds/cyclonedds#1717 is applied to the cyclonedds repository.

Signed-off-by: Erik Hendriks <[email protected]>
  • Loading branch information
e-hndrks committed Jun 16, 2023
1 parent 02abba3 commit b24275b
Showing 1 changed file with 1 addition and 33 deletions.
34 changes: 1 addition & 33 deletions src/ddscxx/include/dds/pub/detail/DataWriterImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ dds::pub::detail::DataWriter<T>::DataWriter(
std::string name = topic.name() + "_datawriter";

this->listener(listener, mask);
dds_entity_t ddsc_writer = dds_create_writer (ddsc_pub, ddsc_topic, ddsc_qos, this->listener_callbacks);
dds_entity_t ddsc_writer = dds_create_writer (ddsc_pub, ddsc_topic, ddsc_qos, NULL);
dds_delete_qos(ddsc_qos);
ISOCPP_DDSC_RESULT_CHECK_AND_THROW(ddsc_writer, "Could not create DataWriter.");
topic_.delegate()->incrNrDependents();
Expand Down Expand Up @@ -417,38 +417,6 @@ dds::pub::detail::DataWriter<T>::init(ObjectDelegate::weak_ref_type weak_ref)
/* Register writer at publisher. */
this->pub_.delegate()->add_datawriter(*this);

// Because listeners are added after writer is created (which is in enabled state, because
// disabled state is not yet supported), events could have occured before listeners were
// registered. Therefore the event handlers for those events are called here.
if (this->listener_get()) {
dds::core::status::StatusMask writerStatus = status_changes();

if (listener_mask.to_ulong() & dds::core::status::StatusMask::liveliness_lost().to_ulong()
&& writerStatus.test(DDS_LIVELINESS_LOST_STATUS_ID))
{
dds::core::status::LivelinessLostStatus status = liveliness_lost_status();
on_liveliness_lost(this->ddsc_entity, status);
}
if (listener_mask.to_ulong() & dds::core::status::StatusMask::offered_deadline_missed().to_ulong()
&& writerStatus.test(DDS_OFFERED_DEADLINE_MISSED_STATUS_ID))
{
dds::core::status::OfferedDeadlineMissedStatus status = offered_deadline_missed_status();
on_offered_deadline_missed(this->ddsc_entity, status);
}
if (listener_mask.to_ulong() & dds::core::status::StatusMask::offered_incompatible_qos().to_ulong()
&& writerStatus.test(DDS_OFFERED_INCOMPATIBLE_QOS_STATUS_ID))
{
dds::core::status::OfferedIncompatibleQosStatus status = offered_incompatible_qos_status();
on_offered_incompatible_qos(this->ddsc_entity, status);
}
if (listener_mask.to_ulong() & dds::core::status::StatusMask::publication_matched().to_ulong()
&& writerStatus.test(DDS_PUBLICATION_MATCHED_STATUS_ID))
{
dds::core::status::PublicationMatchedStatus status = publication_matched_status();
on_publication_matched(this->ddsc_entity, status);
}
}

/* Enable when needed. */
if (this->pub_.delegate()->is_auto_enable()) {
this->enable();
Expand Down

0 comments on commit b24275b

Please sign in to comment.