Before you can create a DataWriter, you need a DomainParticipant, a Topic, and optionally, a Publisher.
DataWriters are created by calling create_datawriter() or create_datawriter_with_profile()—these operations exist for DomainParticipants and Publishers. If you use the DomainParticipant to create a DataWriter, it will belong to the implicit Publisher described in Creating Publishers Explicitly vs. Implicitly. If you use a Publisher’s operations to create a DataWriter, it will belong to that Publisher.
A QoS profile is way to use QoS settings from an XML file or string. With this approach, you can change QoS settings without recompiling the application. For details, see Configuring QoS with XML.
Note: In the Modern C++ API DataWriters provide constructors whose first argument is a Publisher. The only required arguments are the publisher and the topic.
DDSDataWriter* create_datawriter ( DDSTopic *topic, const DDS_DataWriterQos &qos,
DDSDataWriterListener *listener,
DDS_StatusMask mask) DDSDataWriter * create_datawriter_with_profile( DDSTopic * topic, const char * library_name, const char * profile_name, DDSDataWriterListener * listener, DDS_StatusMask mask)
Where:
topic |
The Topic that the DataWriter will publish. This must have been previously created by the same DomainParticipant. |
qos |
If you want the default QoS settings (described in the API Reference HTML documentation), use the constant DDS_DATAWRITER_QOS_DEFAULT for this parameter (see Figure 9). If you want to customize any of the QosPolicies, supply a QoS structure (see Setting DataWriter QosPolicies). Note: If you use DDS_DATAWRITER_QOS_DEFAULT for the qos parameter, it is not safe to create the DataWriter while another thread may be simultaneously calling the Publisher’sset_default_datawriter_qos() operation. |
listener |
Listeners are callback routines. Connext DDS uses them to notify your application of specific events (status changes) that may occur with respect to the DataWriter. The listener parameter may be set to NULL; in this case, the PublisherListener (or if that is NULL, the DomainParticipantListener) will be used instead. For more information, see Setting Up DataWriterListeners |
mask |
This bit-mask indicates which status changes will cause the Listener to be invoked. The bits set in the mask must have corresponding callbacks implemented in the Listener. If you use NULL for the Listener, use DDS_STATUS_MASK_NONE for this parameter. If the Listener implements all callbacks, use DDS_STATUS_MASK_ALL. For information on statuses, see Listeners. |
library_name |
A QoS Library is a named set of QoS profiles. See URL Groups. |
profile_name |
A QoS profile groups a set of related QoS, usually one per entity. See URL Groups |
For more examples on how to create a DataWriter, see Configuring QoS Settings when the DataWriter is Created
After you create a DataWriter, you can use it to write data. See Writing Data.
Note: When a DataWriter is created, only those transports already registered are available to the DataWriter. The built-in transports are implicitly registered when (a) the DomainParticipant is enabled, (b) the first DataWriter is created, or (c) you look up a built-in data reader, whichever happens first.
Figure 9 Creating a DataWriter with Default QosPolicies and a Listener
// MyWriterListener is user defined, extends DDSDataWriterListener DDSDataWriterListener* writer_listener = new MyWriterListener(); DDSDataWriter* writer = publisher->create_datawriter( topic, DDS_DATAWRITER_QOS_DEFAULT, writer_listener, DDS_STATUS_MASK_ALL); if (writer == NULL) { // ... error }; // narrow it for your specific data type FooDataWriter* foo_writer = FooDataWriter::narrow(writer);
© 2017 RTI