Get sample count in reader... with unusual caveat

1 post / 0 new
Offline
Last seen: 7 years 7 months ago
Joined: 08/25/2016
Posts: 1
Get sample count in reader... with unusual caveat

I'm in a situation where I have to detect whether a message on a topic has arrived - without caring (or even being able to know) what's in the message. In other words I have a topic string, a string representing a datatype that I know nothing else about (and isn't created by my IDL), and no intention of ever using read or take  - because I have no knowledge of what sort of sequence I'd have to pass in to receive the messages.

My first thought was to just override on_data_available, and immediately do the action I need to do from within there, without ever reading samples. It's acceptable if the sample isn't ever read; I'm going to close down the data reader at that point anyway.

But this won't work. My on_data_available gets called when the publisher goes away. I don't want to trigger any behaviour in that case. Unfortunately, the only way I can see to detect whether I got called for that case is to take() the data and example the info sequences's valid flag. But take() isn't an option, etc..

For various reasons, dynamic type discovery isn't a reasonable option. Even if it was, the sample Hello Topic code doesn't show how to tell whether on_data_available is being called with a valid sample.

So now I need to know if I can use tricks. I see DDS_DataReaderCacheStatus offers a sample count. Does it strictly count actual samples (so I could test whether it's nonzero?) Or does that count include the "bogus" invalid sample used to denote a disconnect? Ditto DDS_DataReaderProtocolStatus's received_sample_bytes_change. Is that guaranteed to be 0 if only a disconnect happened, and strictly nonzero on the arrival of a sample?

I realise this is a somewhat bizarre set of restrictions; the "thou shalt not know the structure of the message" rule make little sense but is outside my control. TIA.