DataWriter callback when writer queue is available for writing

3 posts / 0 new
Last post
Offline
Last seen: 7 years 4 months ago
Joined: 03/03/2015
Posts: 19
DataWriter callback when writer queue is available for writing

Hey,

I'm have a DDS_DataWriter configured to keep history with a depth of 128. After 128 written samples, the DDS_DataWriter returns a "DDS_RETCODE_TIMEOUT" error, which is expected because the buffer is full and no DDS_DataReader has read anything from it.

However, is there a DDS_DataWriter callbacks which triggers when a DDS_DataReader has read a sample, so the DDS_DataWriter buffer now has available space in the queue for writing? I'm simulating a blocking write, but I cannot use the blocking write that DDS offers, as the blocking behavior is implemented at the top application level, which calls into DDS. The application waits for a DataWriter callback telling it that there's space to write in the data writer buffer.

I would be very grateful for help. I investigated DDS_DataWriter listener "on_reliable_writer_cache_changed" callbacks, but it triggers unnexpectedly, even when writing but the data writer buffer is not full.

 

Thank you!

Best regards,

Andrei

Organization:
Gerardo Pardo's picture
Offline
Last seen: 3 weeks 3 hours ago
Joined: 06/02/2010
Posts: 602

Hi Andrei,

I think the on_reliable_writer_cache_changed callbacks are the right ones to use. But when you get called back you need to look at the DDS_ReliableWriterCacheChangedStatus to determine the state of the DataWriter cache. There are several reasons that trigger this call (basically any changes to the DDS_ReliableWriterCacheChangedStatus) so you need to look at the contents to determine if the reason why the callback was triggered and whether it matches what you are looking for.

For example to detect if the "queue is full" you need to look at the full_reliable_writer_cache field and specifically at full_reliable_writer_cache.total_count_change.

Another interesting fields to detect the queue is getting full before it actially happens are high_watermark_reliable_writer_cache and unacknowledged_sample_count

Note that the  on_reliable_writer_cache_changed is not triggered each time a sample is ackowledged by the DataReaders because doing so would potentially be too much. But there are some "watermarks" you can set wo that you are notified whenevers the number of unacknowledged samples crosses them. These are the low_watermark and the high_watermark. By configuring these using the DataWriterQos and then observing the high_watermark_reliable_writer_cache you can be notified when the unacknwledged samples cross these thresholds.

Gerardo

 

Offline
Last seen: 7 years 4 months ago
Joined: 03/03/2015
Posts: 19

Thank you very much for the answer. The problem got fixed after I used it :)