3.4.2. SubscriberListenerΒΆ

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

SubscriberListener inherits from DataReaderListener. Therefore, it has the ability to react to all events that are reported to the DataReader. Since events are always notified to the most specific Entity Listener that can handle the event, callbacks that SubscriberListener inherits from DataReaderListener will only be called if the triggering DataReader has no Listener attached, or if the callback is disabled by the StatusMask on the DataReader.

Additionally, SubscriberListener adds the following callback:

  • on_data_on_readers(): New data is available on any DataReader belonging to this Subscriber. 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.


For more information about callbacks and its hierarchy, please refer to Listener.

class CustomSubscriberListener : public SubscriberListener


        : SubscriberListener()

    virtual ~CustomSubscriberListener()

    virtual void on_data_on_readers(
            Subscriber* sub)
        std::cout << "New data available" << std::endl;