.. _dds_layers_publication_create_datawriter: Create a DataWriter =================== .. include:: ../../../safety_manual/rules/RULE_CREATION_ORDER.inc .. include:: ../../../safety_manual/rules/RULE_ENABLING_ORDER.inc A :ref:`dds_layers_publication_datawriter` always belongs to a :ref:`dds_layers_publication_publisher`. Creation of a DataWriter is done with the ``Publisher::create_datawriter`` member function on the Publisher instance, that acts as a factory for the DataWriter. Mandatory arguments are: * A :ref:`dds_layers_topic` bound to the data type that will be transmitted. * The :ref:`dds_layers_datawriter_qos` describing the behavior of the DataWriter. Optional arguments are: * A Listener derived from :ref:`dds_layers_publication_datawriterlistener`, implementing the callbacks that will be triggered in response to events and state changes on the DataWriter. * A ``StatusMask`` that activates or deactivates triggering of individual callbacks on the DataWriterListener. ``Publisher::create_datawriter`` 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. .. _dds_layers_create_datawriter_classic: Example """"""" .. literalinclude:: ../../../code/entity_creation/main.cpp :language: c++ :start-after: // DDS_DATAWRITER_CREATION :end-before: //! DDS_DATAWRITER_CREATION :dedent: 4 .. _dds_layers_create_datawriter_static: Static memory example """"""""""""""""""""" In order to create a :ref:`dds_layers_publication_datawriter` that does not use any :ref:`platform allocation ` a ``StaticDataWriter`` can be instantiated: .. note:: When using Safe DDS Static memory API, any :ref:`dds_layers_infrastructure_policies` related with :ref:`dds_layers_infrastructure_safedds_preallocmemoryconfig` in :ref:`dds_layers_datawriter_qos` will be ignored. .. literalinclude:: ../../../code/entity_creation/main.cpp :language: c++ :start-after: // DDS_STATIC_DATAWRITER_CREATION :end-before: //! DDS_STATIC_DATAWRITER_CREATION :dedent: 4