DataWriter

A DataWriter is attached to exactly one Publisher that acts as a factory. Additionally, each DataWriter is bound to a single Topic since its creation. This Topic must exist prior to the creation of the DataWriter, and must be bound to the data type that the DataWriter wants to publish.

The effect of creating a new DataWriter in a Publisher for a specific Topic is to initiate a new publication with the name and data type described by the Topic.

Once the DataWriter is created, the application can inform of changes in the data value using the TypedDataWriter::write member function on the DataWriter. These changes will be transmitted to all subscriptions matched with this publication.

Safe DDS Usage

In Safe DDS, the DataWriter write operation shall be done through a TypedDatawriter::write method. Refer to Using the TypedDataWriter for more information.

DataWriterQos

DataWriterQos controls the behavior of the DataWriter. Internally it contains the following Policy objects:

Safe DDS Usage

In Safe DDS, DataWriterQos::reliability::max_blocking_time shall be always equal to execution::TIME_ZERO as far as Safe DDS shall not block in any write operation.

Safe DDS Usage

Check Memory management to understand how memory is managed in Safe DDS.

Example

// Construct DataWriterQos with default values
DataWriterQos datawriter_qos{};

// Set DurabilityQosPolicy
datawriter_qos.durability().kind = DurabilityQosPolicyKind::TRANSIENT_DURABILITY_QOS;

// Set DeadlineQosPolicy
datawriter_qos.deadline().period = {1, 0};

// Set LivelinessQosPolicy
datawriter_qos.liveliness().kind = LivelinessQosPolicyKind::AUTOMATIC_LIVELINESS_QOS;
datawriter_qos.liveliness().lease_duration = {1, 0};

// Set ReliabilityQosPolicy
datawriter_qos.reliability().kind = ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS;

// Set HistoryQosPolicy
datawriter_qos.history().kind = HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
datawriter_qos.history().depth = 10;

// Set ResourceLimitsQosPolicy
datawriter_qos.resource_limits().max_samples = 1000;
datawriter_qos.resource_limits().max_instances = 10;
datawriter_qos.resource_limits().max_samples_per_instance = 3;

// Set wire protocol configuration
datawriter_qos.wire_protocol_qos().output_integrity = protocol::OutputIntegrityCheck::ENABLED;

// Set DataWriterAllocationsQosPolicy memory configuration
datawriter_qos.allocations().preallocated_instances = 10;