31.10 Writing Coherent Sets of DDS Data Samples
A publishing application can request that a set of DDS data-sample changes be propagated in such a way that they are interpreted at the receivers' side as a cohesive set of modifications. In this case, the receiver will only be able to access the data after all the modifications in the set are available at the subscribing end.
This is useful in cases where the values are inter-related. For example, suppose you have two data-instances representing the ‘altitude’ and ‘velocity vector’ of the same aircraft. If both are changed, it may be important to ensure that reader see both together (otherwise, it may erroneously interpret that the aircraft is on a collision course).
To use this mechanism in C, Traditional C++, Java and .NET:
- Call the Publisher’s begin_coherent_changes() operation to indicate the start a coherent set.
- For each DDS sample in the coherent set: call the FooDataWriter’s write() operation.
- Call the Publisher’s end_coherent_changes() operation to terminate the set.
In the Modern C++ API:
- Instantiate a dds::pub::CoherentSet passing a publisher to the constructor
- For each DDS sample in the coherent set call dds::pub::DataWriter<Foo>::write().
- Let the dds::pub::CoherentSet destructor terminate the set or explicitly call dds::pub::CoherentSet::end()
Calls to begin_coherent_changes() and end_coherent_changes() can be nested. Publisher’s samples (samples published by any of the DataWriters within the Publisher) that are not published within a begin_coherent_changes/end_coherent_changes block will not be provided to the DataReaders as a set.
See also: the coherent_access field in the 46.6 PRESENTATION QosPolicy and the coherent_set_info field in 41.6 The SampleInfo Structure.