diff --git a/code/DDSCodeTester.cpp b/code/DDSCodeTester.cpp index 7149ceb74..900567bb0 100644 --- a/code/DDSCodeTester.cpp +++ b/code/DDSCodeTester.cpp @@ -392,6 +392,31 @@ void dds_domain_examples() //!-- } + { + //DDS_CREATE_DOMAINPARTICIPANT_DEFAULT_PROFILE + // Create a DomainParticipant using the environment profile and no Listener + DomainParticipant* participant = + DomainParticipantFactory::get_instance()->create_participant_with_default_profile(); + if (nullptr == participant) + { + // Error + return; + } + + // Create a DomainParticipant using the environment profile and a custom Listener. + // CustomDomainParticipantListener inherits from DomainParticipantListener. + CustomDomainParticipantListener custom_listener; + DomainParticipant* participant_with_custom_listener = + DomainParticipantFactory::get_instance()->create_participant_with_default_profile( + &custom_listener, StatusMask::none()); + if (nullptr == participant_with_custom_listener) + { + // Error + return; + } + //!-- + } + { //DDS_CHANGE_DOMAINPARTICIPANTQOS // Create a DomainParticipant with default DomainParticipantQos @@ -6460,6 +6485,11 @@ void pubsub_api_example_create_entities() DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT); //!-- + //PUBSUB_API_CREATE_DEFAULT_PARTICIPANT + DomainParticipant* default_participant = + DomainParticipantFactory::get_instance()->create_participant_with_default_profile(); + //!-- + //PUBSUB_API_CREATE_PUBLISHER Publisher* publisher = participant->create_publisher(PUBLISHER_QOS_DEFAULT); //!-- diff --git a/docs/03-exports/aliases-api.include b/docs/03-exports/aliases-api.include index 6999c6d18..1990d7f0a 100644 --- a/docs/03-exports/aliases-api.include +++ b/docs/03-exports/aliases-api.include @@ -150,6 +150,7 @@ .. |DomainParticipant::disable-monitor-service-api| replace:: :cpp:func:`disable_monitor_service()` .. |DomainParticipantFactory-api| replace:: :cpp:class:`DomainParticipantFactory` +.. |DomainParticipantFactory::create_participant_with_default_profile-api| replace:: :cpp:func:`create_participant_with_default_profile()` .. |DomainParticipantFactory::create_participant_with_profile-api| replace:: :cpp:func:`create_participant_with_profile()` .. |DomainParticipantFactory::create_participant-api| replace:: :cpp:func:`create_participant()` .. |DomainParticipantFactory::delete_participant-api| replace:: :cpp:func:`delete_participant()` diff --git a/docs/fastdds/dds_layer/domain/domainParticipant/createDomainParticipant.rst b/docs/fastdds/dds_layer/domain/domainParticipant/createDomainParticipant.rst index eed896915..29cf00f83 100644 --- a/docs/fastdds/dds_layer/domain/domainParticipant/createDomainParticipant.rst +++ b/docs/fastdds/dds_layer/domain/domainParticipant/createDomainParticipant.rst @@ -88,6 +88,42 @@ It is advisable to check that the returned value is a valid pointer. :end-before: //! :dedent: 8 +.. _dds_layer_domainParticipant_creation_default_profile: + +Default profile DomainParticipant creation +------------------------------------------ + +If there is a profile already exported in the environment (please refer to :ref:`xml_profiles` for related +information), creating a DomainParticipant with the +|DomainParticipantFactory::create_participant_with_default_profile-api| member function on the +:ref:`dds_layer_domainParticipantFactory` singleton would use that settings to configure the participant. +If the profile has not been exported, the DomainParticipant will be created with the default values per +:ref:`dds_layer_domainParticipantQos`, and ``0`` as |DomainId-api|. + +Optional arguments are: + + * A Listener derived from :ref:`dds_layer_domainParticipantListener`, implementing the callbacks + that will be triggered in response to events and state changes on the DomainParticipant. + By default empty callbacks are used. + + * A |StatusMask-api| that activates or deactivates triggering of individual callbacks on the + :ref:`dds_layer_domainParticipantListener`. + By default all events are enabled. + +|DomainParticipantFactory::create_participant_with_default_profile-api| will return a null pointer if there was an +error during the operation. +It is advisable to check that the returned value is a valid pointer. + +.. note:: + + XML profiles must have been loaded previously. See :ref:`xml_profiles`. + +.. literalinclude:: /../code/DDSCodeTester.cpp + :language: c++ + :start-after: //DDS_CREATE_DOMAINPARTICIPANT_DEFAULT_PROFILE + :end-before: //! + :dedent: 8 + .. _dds_layer_domainParticipant_deletion: Deleting a DomainParticipant diff --git a/docs/fastdds/xml_configuration/making_xml_profiles.rst b/docs/fastdds/xml_configuration/making_xml_profiles.rst index 408332d42..d0f27cae2 100644 --- a/docs/fastdds/xml_configuration/making_xml_profiles.rst +++ b/docs/fastdds/xml_configuration/making_xml_profiles.rst @@ -64,6 +64,11 @@ if founded. :end-before: //!-- :dedent: 8 +For simplicity, the |DomainParticipantFactory::create_participant_with_default_profile-api| method takes the default +profile set in the environment to create a participant. +It requires the XML profile to have been already loaded. +Please, refer to :ref:`xml_profiles` for further information regarding loading profiles. + .. warning:: It is worth mentioning that if the same XML profile file is loaded multiple times, the second loading of