Skip to content

Latest commit

 

History

History
115 lines (79 loc) · 4.16 KB

createDataWriter.rst

File metadata and controls

115 lines (79 loc) · 4.16 KB

Creating a DataWriter

A :ref:`dds_layer_publisher_dataWriter` always belongs to a :ref:`dds_layer_publisher_publisher`. Creation of a DataWriter is done with the |Publisher::create_datawriter-api| member function on the Publisher instance, that acts as a factory for the DataWriter.

Mandatory arguments are:

Optional arguments are:

  • A Listener derived from :ref:`dds_layer_publisher_dataWriterListener`, implementing the callbacks that will be triggered in response to events and state changes on the DataWriter. By default empty callbacks are used.
  • A |StatusMask-api| that activates or deactivates triggering of individual callbacks on the DataWriterListener. By default all events are enabled.

|Publisher::create_datawriter-api| will return a null pointer if there was an error during the operation, e.g. if the provided QoS is not compatible or is not supported. It is advisable to check that the returned value is a valid pointer.

.. literalinclude:: /../code/DDSCodeTester.cpp
   :language: c++
   :start-after: //DDS_CREATE_DATAWRITER
   :end-before: //!
   :dedent: 8


Profile based creation of a DataWriter

Instead of using a DataWriterQos, the name of a profile can be used to create a DataWriter with the |Publisher::create_datawriter_with_profile-api| member function on the Publisher instance.

Mandatory arguments are:

  • A Topic bound to the data type that will be transmitted.
  • A string with the name that identifies the DataWriter.

Optional arguments are:

  • A Listener derived from DataWriterListener, implementing the callbacks that will be triggered in response to events and state changes on the DataWriter. By default empty callbacks are used.
  • A |StatusMask-api| that activates or deactivates triggering of individual callbacks on the DataWriterListener. By default all events are enabled.

|Publisher::create_datawriter_with_profile-api| will return a null pointer if there was an error during the operation, e.g. if the provided QoS is not compatible or is not supported. It is advisable to check that the returned value is a valid pointer.

Note

XML profiles must have been loaded previously. See :ref:`dds_layer_domainParticipantFactory_load_profiles`.

.. literalinclude:: /../code/DDSCodeTester.cpp
   :language: c++
   :start-after: //DDS_CREATE_PROFILE_DATAWRITER
   :end-before: //!
   :dedent: 8

Creating a DataWriter with a custom PayloadPool

A custom :ref:`PayloadPool<rtps_layer_custom_payload_pool>` can be passed as an argument during the creation of a :ref:`dds_layer_publisher_dataWriter`. This allows for customizing the management of the information exchanged between DataWriters and DataReaders. The same configuration can be set in the :ref:`opposite endpoint<dds_layer_subscriber_datareader_with_payload_pool_creation>`.

.. literalinclude:: /../code/DDSCodeTester.cpp
   :language: c++
   :start-after: //DDS_CREATE_PAYLOAD_POOL_DATAWRITER
   :end-before: //!
   :dedent: 8

This configuration can be performed also in the :ref:`RTPS layer<rtps_layer_custom_payload_pool>`. The :ref:`customization example<rtps_layer_payload_pool_example>` applies both layers.

Deleting a DataWriter

A DataWriter can be deleted with the |Publisher::delete_datawriter-api| member function on the :ref:`dds_layer_publisher_publisher` instance where the DataWriter was created.

.. literalinclude:: /../code/DDSCodeTester.cpp
   :language: c++
   :start-after: //DDS_DELETE_DATAWRITER
   :end-before: //!
   :dedent: 8