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?
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->create_datareader(
topic, DDS_DATAREADER_QOS_DEFAULT, reader_listener,
DDS_LIVELINESS_CHANGED_STATUS);
Let me know if this approach suits your needs.
Best,
Antonio