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.
Note
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:
durabilityas DurabilityQosPolicyDefines the durability of the DataWriter.
deadlineas DeadlineQosPolicyDefines the deadline for the DataWriter.
livelinessas LivelinessQosPolicyDefines the liveliness of the DataWriter.
reliabilityas ReliabilityQosPolicyDefines the reliability of the DataWriter.
historyas HistoryQosPolicyDefines the history of the DataWriter.
resource_limitsas ResourceLimitsQosPolicyDefines the resource limits of the DataWriter.
wire_protocol_qosas DataWriterWireProtocolQosPolicyThe configuration of the wire protocol.
allocationsas DataWriterAllocationsQosPolicyDefines the memory configuration of the DataWriter.
Note
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::OUTPUT_INTEGRITY_CHECK_ENABLED;
// Set DataWriterAllocationsQosPolicy memory configuration
datawriter_qos.allocations().preallocated_instances = 10;