How to get all instance handles to the remote writer that changed liveliness?

2 posts / 0 new
Last post
Offline
Last seen: 2 years 12 months ago
Joined: 11/19/2016
Posts: 1
How to get all instance handles to the remote writer that changed liveliness?

Hi, 

I have a problem when using livelinessChangedStatus structure. In my project, I have one dataReader that listens to a topic which several dataWriters are publishing on. Every time when one or several dataWriters come offline/online due to network disconnect/reconnect, the function on_liveliness_changed(.....) is called, and I get a LivelinessChangedStatus struct. However, this struct only tells me the instance handle to the last remote writer that changed its liveliness, and this causes me a problem when several writers changed their liveliness at the same time.

How am I able to get all the instance handles to the remote writer that changed liveliness?

ajimenez's picture
Offline
Last seen: 1 year 1 month ago
Joined: 09/29/2017
Posts: 21

Hi Guanwen,

I was able to reproduce your issue. In the case of using waitset you will only get the last instance_handle if several DataWriters disconnect at the same time.

An alternative is to use a listener with the callback on_liveliness_changed(). This function will be called every time that the status is changed. Here you can see a snippet code about how to use it:

classtestListener: public DDSDataReaderListener {
    public:
        virtual void on_liveliness_changed(
                 DDSDataReader* reader,
                const DDS_LivelinessChangedStatus& status) {
             printf("\t alive_count: %d\n", status.alive_count);
             printf("\t last_publication_handle:");
             for(int i = 0; i < MIG_RTPS_KEY_HASH_MAX_LENGTH; i++)
                 printf("%02x",status.last_publication_handle.keyHash.value[i]);
         }
};
reader_listener = new testListener();
reader = subscriber-&gt;create_datareader(
topic, DDS_DATAREADER_QOS_DEFAULT, reader_listener,
DDS_LIVELINESS_CHANGED_STATUS);

Let me know if this approach suits your needs.

Best,

Antonio