.. _dds_layers_publication_create_publisher: Create a Publisher ================== .. include:: ../../../safety_manual/rules/RULE_CREATION_ORDER.inc .. include:: ../../../safety_manual/rules/RULE_ENABLING_ORDER.inc A :ref:`dds_layers_publication_publisher` always belongs to a :ref:`dds_layers_domain_participant`. Creation of a Publisher is done with the ``DomainParticipant::create_publisher`` member function on the DomainParticipant instance, that acts as a factory for the Publisher. Mandatory arguments are: * The :ref:`dds_layers_publication_publisherqos` describing the behavior of the Publisher. Optional arguments are: * A Listener derived from :ref:`dds_layers_publication_publisherlistener`, implementing the callbacks that will be triggered in response to events and state changes on the Publisher. * A ``StatusMask`` that activates or deactivates triggering of individual callbacks on the PublisherListener. ``DomainParticipant::create_publisher`` 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_publisher_classic: Example """"""" .. literalinclude:: ../../../code/entity_creation/main.cpp :language: c++ :start-after: // DDS_PUBLISHER_CREATION :end-before: //! DDS_PUBLISHER_CREATION :dedent: 4 .. _dds_layers_create_publisher_static: Static memory example """"""""""""""""""""" In order to create a :ref:`dds_layers_publication_publisher` that does not use any :ref:`platform allocation ` a ``StaticPublisher`` 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_publication_publisherqos` will be ignored. .. literalinclude:: ../../../code/entity_creation/main.cpp :language: c++ :start-after: // DDS_STATIC_PUBLISHER_CREATION :end-before: //! DDS_STATIC_PUBLISHER_CREATION :dedent: 4