Skip to content

Commit

Permalink
Create Participant with default profile (use environment XML configur…
Browse files Browse the repository at this point in the history
…ation) (#725)

Signed-off-by: JesusPoderoso <[email protected]>
Signed-off-by: eduponz <[email protected]>
  • Loading branch information
JesusPoderoso authored and EduPonz committed May 13, 2024
1 parent e846479 commit 88639cd
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
30 changes: 30 additions & 0 deletions code/DDSCodeTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -6498,6 +6523,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);
//!--
Expand Down
1 change: 1 addition & 0 deletions docs/03-exports/aliases-api.include
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
.. |DomainParticipant::disable-monitor-service-api| replace:: :cpp:func:`disable_monitor_service()<eprosima::fastdds::dds::DomainParticipant::disable_monitor_service>`

.. |DomainParticipantFactory-api| replace:: :cpp:class:`DomainParticipantFactory<eprosima::fastdds::dds::DomainParticipantFactory>`
.. |DomainParticipantFactory::create_participant_with_default_profile-api| replace:: :cpp:func:`create_participant_with_default_profile()<eprosima::fastdds::dds::DomainParticipantFactory::create_participant_with_default_profile>`
.. |DomainParticipantFactory::create_participant_with_profile-api| replace:: :cpp:func:`create_participant_with_profile()<eprosima::fastdds::dds::DomainParticipantFactory::create_participant_with_profile>`
.. |DomainParticipantFactory::create_participant-api| replace:: :cpp:func:`create_participant()<eprosima::fastdds::dds::DomainParticipantFactory::create_participant>`
.. |DomainParticipantFactory::delete_participant-api| replace:: :cpp:func:`delete_participant()<eprosima::fastdds::dds::DomainParticipantFactory::delete_participant>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,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
Expand Down
5 changes: 5 additions & 0 deletions docs/fastdds/xml_configuration/making_xml_profiles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 88639cd

Please sign in to comment.