Skip to content

Commit 56115e7

Browse files
JesusPoderosoEduPonz
authored andcommitted
Create Participant with default profile (use environment XML configuration) (#725)
Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com> Signed-off-by: eduponz <eduardoponz@eprosima.com>
1 parent aef53bb commit 56115e7

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

code/DDSCodeTester.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,31 @@ void dds_domain_examples()
392392
//!--
393393
}
394394

395+
{
396+
//DDS_CREATE_DOMAINPARTICIPANT_DEFAULT_PROFILE
397+
// Create a DomainParticipant using the environment profile and no Listener
398+
DomainParticipant* participant =
399+
DomainParticipantFactory::get_instance()->create_participant_with_default_profile();
400+
if (nullptr == participant)
401+
{
402+
// Error
403+
return;
404+
}
405+
406+
// Create a DomainParticipant using the environment profile and a custom Listener.
407+
// CustomDomainParticipantListener inherits from DomainParticipantListener.
408+
CustomDomainParticipantListener custom_listener;
409+
DomainParticipant* participant_with_custom_listener =
410+
DomainParticipantFactory::get_instance()->create_participant_with_default_profile(
411+
&custom_listener, StatusMask::none());
412+
if (nullptr == participant_with_custom_listener)
413+
{
414+
// Error
415+
return;
416+
}
417+
//!--
418+
}
419+
395420
{
396421
//DDS_CHANGE_DOMAINPARTICIPANTQOS
397422
// Create a DomainParticipant with default DomainParticipantQos
@@ -6498,6 +6523,11 @@ void pubsub_api_example_create_entities()
64986523
DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
64996524
//!--
65006525

6526+
//PUBSUB_API_CREATE_DEFAULT_PARTICIPANT
6527+
DomainParticipant* default_participant =
6528+
DomainParticipantFactory::get_instance()->create_participant_with_default_profile();
6529+
//!--
6530+
65016531
//PUBSUB_API_CREATE_PUBLISHER
65026532
Publisher* publisher = participant->create_publisher(PUBLISHER_QOS_DEFAULT);
65036533
//!--

docs/03-exports/aliases-api.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
.. |DomainParticipant::disable-monitor-service-api| replace:: :cpp:func:`disable_monitor_service()<eprosima::fastdds::dds::DomainParticipant::disable_monitor_service>`
151151

152152
.. |DomainParticipantFactory-api| replace:: :cpp:class:`DomainParticipantFactory<eprosima::fastdds::dds::DomainParticipantFactory>`
153+
.. |DomainParticipantFactory::create_participant_with_default_profile-api| replace:: :cpp:func:`create_participant_with_default_profile()<eprosima::fastdds::dds::DomainParticipantFactory::create_participant_with_default_profile>`
153154
.. |DomainParticipantFactory::create_participant_with_profile-api| replace:: :cpp:func:`create_participant_with_profile()<eprosima::fastdds::dds::DomainParticipantFactory::create_participant_with_profile>`
154155
.. |DomainParticipantFactory::create_participant-api| replace:: :cpp:func:`create_participant()<eprosima::fastdds::dds::DomainParticipantFactory::create_participant>`
155156
.. |DomainParticipantFactory::delete_participant-api| replace:: :cpp:func:`delete_participant()<eprosima::fastdds::dds::DomainParticipantFactory::delete_participant>`

docs/fastdds/dds_layer/domain/domainParticipant/createDomainParticipant.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,42 @@ It is advisable to check that the returned value is a valid pointer.
9191
:end-before: //!
9292
:dedent: 8
9393

94+
.. _dds_layer_domainParticipant_creation_default_profile:
95+
96+
Default profile DomainParticipant creation
97+
------------------------------------------
98+
99+
If there is a profile already exported in the environment (please refer to :ref:`xml_profiles` for related
100+
information), creating a DomainParticipant with the
101+
|DomainParticipantFactory::create_participant_with_default_profile-api| member function on the
102+
:ref:`dds_layer_domainParticipantFactory` singleton would use that settings to configure the participant.
103+
If the profile has not been exported, the DomainParticipant will be created with the default values per
104+
:ref:`dds_layer_domainParticipantQos`, and ``0`` as |DomainId-api|.
105+
106+
Optional arguments are:
107+
108+
* A Listener derived from :ref:`dds_layer_domainParticipantListener`, implementing the callbacks
109+
that will be triggered in response to events and state changes on the DomainParticipant.
110+
By default empty callbacks are used.
111+
112+
* A |StatusMask-api| that activates or deactivates triggering of individual callbacks on the
113+
:ref:`dds_layer_domainParticipantListener`.
114+
By default all events are enabled.
115+
116+
|DomainParticipantFactory::create_participant_with_default_profile-api| will return a null pointer if there was an
117+
error during the operation.
118+
It is advisable to check that the returned value is a valid pointer.
119+
120+
.. note::
121+
122+
XML profiles must have been loaded previously. See :ref:`xml_profiles`.
123+
124+
.. literalinclude:: /../code/DDSCodeTester.cpp
125+
:language: c++
126+
:start-after: //DDS_CREATE_DOMAINPARTICIPANT_DEFAULT_PROFILE
127+
:end-before: //!
128+
:dedent: 8
129+
94130
.. _dds_layer_domainParticipant_deletion:
95131

96132
Deleting a DomainParticipant

docs/fastdds/xml_configuration/making_xml_profiles.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ if founded.
6464
:end-before: //!--
6565
:dedent: 8
6666

67+
For simplicity, the |DomainParticipantFactory::create_participant_with_default_profile-api| method takes the default
68+
profile set in the environment to create a participant.
69+
It requires the XML profile to have been already loaded.
70+
Please, refer to :ref:`xml_profiles` for further information regarding loading profiles.
71+
6772
.. warning::
6873

6974
It is worth mentioning that if the same XML profile file is loaded multiple times, the second loading of

0 commit comments

Comments
 (0)