Skip to content

Commit

Permalink
Fix resetting of LivelinessLostStatus::total_changes (#2782)
Browse files Browse the repository at this point in the history
* Refs #14982. Fix `DataWriter::get_liveliness_lost_status()`

* Apply suggestions from code review

Co-authored-by: Eduardo Ponz Segrelles <eduardoponz@eprosima.com>

Co-authored-by: Eduardo Ponz Segrelles <eduardoponz@eprosima.com>
(cherry picked from commit b5f87dd)
  • Loading branch information
richiware authored and mergify[bot] committed Jul 13, 2022
1 parent d1f11e2 commit 9569823
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/cpp/fastdds/publisher/DataWriterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,12 +1107,16 @@ void DataWriterImpl::InnerDataWriterListener::on_liveliness_lost(
fastrtps::rtps::RTPSWriter* /*writer*/,
const fastrtps::LivelinessLostStatus& status)
{
data_writer_->update_liveliness_lost_status(status);
StatusMask notify_status = StatusMask::liveliness_lost();
DataWriterListener* listener = data_writer_->get_listener_for(notify_status);
if (listener != nullptr)
{
listener->on_liveliness_lost(
data_writer_->user_datawriter_, status);
LivelinessLostStatus callback_status;
if (ReturnCode_t::RETCODE_OK == data_writer_->get_liveliness_lost_status(callback_status))
{
listener->on_liveliness_lost(data_writer_->user_datawriter_, callback_status);
}
}
data_writer_->user_datawriter_->get_statuscondition().get_impl()->set_status(notify_status, true);
}
Expand Down Expand Up @@ -1406,10 +1410,8 @@ ReturnCode_t DataWriterImpl::get_liveliness_lost_status(
{
std::unique_lock<RecursiveTimedMutex> lock(writer_->getMutex());

status.total_count = writer_->liveliness_lost_status_.total_count;
status.total_count_change = writer_->liveliness_lost_status_.total_count_change;

writer_->liveliness_lost_status_.total_count_change = 0u;
status = liveliness_lost_status_;
liveliness_lost_status_.total_count_change = 0u;
}

user_datawriter_->get_statuscondition().get_impl()->set_status(StatusMask::liveliness_lost(), false);
Expand Down Expand Up @@ -1491,6 +1493,14 @@ OfferedIncompatibleQosStatus& DataWriterImpl::update_offered_incompatible_qos(
return offered_incompatible_qos_status_;
}

LivelinessLostStatus& DataWriterImpl::update_liveliness_lost_status(
const fastrtps::LivelinessLostStatus& liveliness_lost_status)
{
liveliness_lost_status_.total_count = liveliness_lost_status.total_count;
liveliness_lost_status_.total_count_change += liveliness_lost_status.total_count_change;
return liveliness_lost_status_;
}

void DataWriterImpl::set_qos(
DataWriterQos& to,
const DataWriterQos& from,
Expand Down
14 changes: 13 additions & 1 deletion src/cpp/fastdds/publisher/DataWriterImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,10 @@ class DataWriterImpl : protected rtps::IReaderDataFilter
PublicationMatchedStatus publication_matched_status_;

//! The offered deadline missed status
fastrtps::OfferedDeadlineMissedStatus deadline_missed_status_;
OfferedDeadlineMissedStatus deadline_missed_status_;

//! The liveliness lost status
LivelinessLostStatus liveliness_lost_status_;

//! The offered incompatible qos status
OfferedIncompatibleQosStatus offered_incompatible_qos_status_;
Expand Down Expand Up @@ -511,6 +514,15 @@ class DataWriterImpl : protected rtps::IReaderDataFilter
OfferedIncompatibleQosStatus& update_offered_incompatible_qos(
PolicyMask incompatible_policies);

/*!
* @brief Updates liveliness lost status.
*
* @param[in] liveliness_lost_status Liveliness lost status coming from RTPS layer.
* @return Current liveliness lost status.
*/
LivelinessLostStatus& update_liveliness_lost_status(
const fastrtps::LivelinessLostStatus& liveliness_lost_status);

/**
* Returns the most appropriate listener to handle the callback for the given status,
* or nullptr if there is no appropriate listener.
Expand Down

0 comments on commit 9569823

Please sign in to comment.