.. _dds_layers_create_domain_participant: Create a DomainParticipant ========================== .. include:: ../../../safety_manual/rules/RULE_CREATION_ORDER.inc .. include:: ../../../safety_manual/rules/RULE_ENABLING_ORDER.inc Creation of a :ref:`dds_layers_domain_participant` can be done with the ``DomainParticipantFactory::create_participant`` member function on the :ref:`dds_layers_domain_participant_factory`, that acts as a factory for the DomainParticipant. Mandatory arguments are: * The ``DomainId`` that identifies the domain where the DomainParticipant will be created. * The :ref:`dds_layers_domain_participant_qos` describing the behavior of the DomainParticipant. Optional arguments are: * A Listener derived from :ref:`dds_layers_domain_participant_listener`, implementing the callbacks that will be triggered in response to events and state changes on the DomainParticipant. * A ``StatusMask`` that activates or deactivates triggering of individual callbacks on the :ref:`dds_layers_domain_participant_listener`. ``DomainParticipantFactory::create_participant`` 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_domain_participant_classic: Example """"""" .. literalinclude:: ../../../code/entity_creation/main.cpp :language: c++ :start-after: // DDS_DOMAINPARTICIPANT_CREATION :end-before: //! DDS_DOMAINPARTICIPANT_CREATION :dedent: 4 .. _dds_layers_create_domain_participant_static: Static memory example """"""""""""""""""""" In order to create a :ref:`dds_layers_domain_participant` that does not use any :ref:`platform allocation ` a ``StaticDomainParticipant`` 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_domain_participant_qos` will be ignored. .. literalinclude:: ../../../code/entity_creation/main.cpp :language: c++ :start-after: // DDS_STATIC_DOMAINPARTICIPANT_CREATION :end-before: //! DDS_STATIC_DOMAINPARTICIPANT_CREATION :dedent: 4 .. only :: SafetyManual .. _dds_layers_create_safe_domain_participant_listeners: Create safe DomainParticipant with listener """"""""""""""""""""""""""""""""""""""""""" .. include:: ../../../safety_manual/rules/RULE_HANDLING_STATUS.inc When leveraging listeners to handle DDS Entity Statuses, the ``DomainParticipants`` shall be created as follows: .. literalinclude:: ../../../code/entity_creation/main.cpp :language: c++ :start-after: // DDS_SAFE_DOMAINPARTICIPANT_CREATION_LISTENER :end-before: //! DDS_SAFE_DOMAINPARTICIPANT_CREATION_LISTENER :dedent: 8 .. _dds_layers_create_safe_domain_participant_status: Create safe DomainParticipant without listener """""""""""""""""""""""""""""""""""""""""""""" .. include:: ../../../safety_manual/rules/RULE_HANDLING_STATUS.inc When leveraging query APIs to handle DDS Entity Statuses, the ``DomainParticipants`` shall be created as follows: .. literalinclude:: ../../../code/entity_creation/main.cpp :language: c++ :start-after: // DDS_SAFE_DOMAINPARTICIPANT_CREATION_STATUS :end-before: //! DDS_SAFE_DOMAINPARTICIPANT_CREATION_STATUS :dedent: 8