The Quantum Physicist The Quantum Physicist - 4 years ago 102
C++ Question

OpenSplice DDS: Publish, until some timeout

I'm learning every day more about dds, so my question my sound weird. I hope it makes sense.

One of the requirements of some dds wrapper I'm writing, is that it times out after some timeout period if it fails to write. My question: How can I do that?

On Prism Tech's website's tutorial, there's explanation on how to use a

to block a read operation, but what about write?

Here's some code including the question:

dds::domain::DomainParticipant dp(0);
dds::topic::Topic<MyType> topic(dp, "MyTopic");
dds::pub::Publisher pub(dp);
dds::pub::DataWriter<MyType> dw(pub, topic);

MyType t;
dw.write(t); //how can I make this block for 5 seconds (tops), and then throw an error on failure?

I noticed there exists a function in the API
DataWriter::wait_for_acknowledgements(int timeout)
, but this seems to be bound to the
object, not to the specific call of writing. Can I bind it with the call above?

Answer Source

This is configured in QoS, cf RELIABILITY, field "max_blocking_time". How you set this value will depend on the vendor's implementation. Generally you get the current QoS, update the field, write the QoS back. Keep in mind that certain QoS policies must be set before something else happens. Reliability is "Before Enable" (at least in the implementation I'm most familiar with), which means you need to create the data-writer disabled, update the QoS, then enable the writer.

If QoS can be set outside the application (via XML for example), then you can set the policy easily. Otherwise, you need to do it in code.

From the spec:

The value of the max_blocking_time indicates the maximum time the operation DataWriter::write is allowed to block if the DataWriter does not have space to store the value written. The default max_blocking_time=100ms.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download