DataWriter Listener¶
DataWriterListener is an abstract class defining the callbacks that will be triggered in response to state changes on the DataWriter.
By default, all these callbacks are empty and do nothing.
The user should implement a specialization of this class overriding the callbacks that are needed on the application.
Callbacks that are not overridden will maintain their empty implementation.
DataWriterListener defines the following callbacks:
DataWriterListener::on_publication_matchedThe DataWriter has found a DataReader that matches the Topic and has a common partition and a compatible QoS, or has ceased to be matched with a DataReader that was previously considered to be matched. It is also triggered when a matched DataReader has changed its DataReaderQos.
DataWriterListener::on_offered_deadline_missedThe DataWriter failed to provide data within the deadline period configured on its DataWriterQos. It will be called for each deadline period and data instance for which the DataWriter failed to provide data.
DataWriterListener::on_offered_incompatible_qosThe DataWriter has found a DataReader that matches the Topic and has a common partition, but with a requested QoS that is incompatible with the one defined on the DataWriter.
DataWriterListener::on_liveliness_lostThe DataWriter did not respect the liveliness configuration on its DataWriterQos, and therefore, DataReader entities will consider the DataWriter as no longer active.
Example¶
class CustomDataWriterListener :
public DataWriterListener
{
void on_publication_matched(
DataWriter& /* writer */,
const PublicationMatchedStatus& /* info */) noexcept override
{
std::cout << "Publication matched" << std::endl;
}
void on_offered_deadline_missed(
DataWriter& /* writer */,
const OfferedDeadlineMissedStatus& /* status */) noexcept override
{
std::cout << "Offered deadline missed in datawriter" << std::endl;
}
void on_offered_incompatible_qos(
DataWriter& /* writer */,
const OfferedIncompatibleQosStatus& /* status */) noexcept override
{
std::cout << "Offered incompatible QoS in datawriter" << std::endl;
}
void on_liveliness_lost(
DataWriter& /* writer */,
const LivelinessLostStatus& /* status */) noexcept override
{
std::cout << "Liveliness lost in datawriter" << std::endl;
}
};