DataReader Listener

DataReaderListener is an abstract class defining the callbacks that will be triggered in response to state changes on the DataReader. 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.

DataReaderListener defines the following callbacks:

  • DataReaderListener::on_data_available

    There is new data available for the application on the DataReader. There is no queuing of invocations to this callback, meaning that if several new data changes are received at once, only one callback invocation may be issued for all of them, instead of one per change. If the application is retrieving the received data on this callback, it must keep reading data until no new changes are left.

  • DataReaderListener::on_subscription_matched

    The DataReader has found a DataWriter that matches the Topic and has a common partition and a compatible QoS, or has ceased to be matched with a DataWriter that was previously considered to be matched. It is also triggered when a matched DataWriter has changed its DataWriterQos.

  • DataReaderListener::on_requested_deadline_missed

    The DataReader did not receive data within the deadline period configured on its DataReaderQos. It will be called for each deadline period and data instance for which the DataReader missed data.

  • DataReaderListener::on_requested_incompatible_qos

    The DataReader has found a DataWriter that matches the Topic and has a common partition, but with a QoS that is incompatible with the one defined on the DataReader.

  • DataReaderListener::on_liveliness_changed

    The liveliness status of a matched DataWriter has changed. Either a DataWriter that was inactive has become active or the other way around.

  • DataReaderListener::on_sample_rejected

    A received data sample was rejected. See SampleRejectedStatus for further information.

  • DataReaderListener::on_sample_lost

    A data sample was lost and will never be received. See SampleLostStatus for further information.

Example

class CustomDataReaderListener : public DataReaderListener
{
    void on_data_available(
            DataReader& /* reader */) noexcept override
    {
        std::cout << "Data available on datareader" << std::endl;
    }

    void on_subscription_matched(
            DataReader& /* reader */,
            const SubscriptionMatchedStatus& /* info */) noexcept override
    {
        std::cout << "Subscription matched" << std::endl;
    }

    void on_requested_deadline_missed(
            DataReader& /* reader */,
            const RequestedDeadlineMissedStatus& /* status */) noexcept override
    {
        std::cout << "Requested deadline missed in datareader" << std::endl;
    }

    void on_liveliness_changed(
            DataReader& /* reader */,
            const LivelinessChangedStatus& /* status */) noexcept override
    {
        std::cout << "Liveliness changed in datareader" << std::endl;
    }

    void on_sample_rejected(
            DataReader& /* reader */,
            const SampleRejectedStatus& /* status */) noexcept override
    {
        std::cout << "Sample rejected in datareader" << std::endl;
    }

    void on_requested_incompatible_qos(
            DataReader& /* reader */,
            const RequestedIncompatibleQosStatus& /* status */) noexcept override
    {
        std::cout << "Requested incompatible QoS in datareader" << std::endl;
    }

    void on_sample_lost(
            DataReader& /* reader */,
            const SampleLostStatus& /* status */) noexcept override
    {
        std::cout << "Sample lost in datareader" << std::endl;
    }

};