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) (#4534)

* Refs #20543: Default Domain Id value

Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>

* Refs #20543: Rename method

Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>

* Refs #20543: Apply rev suggestions

Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>

* Refs #20543: Address missed suggestions

Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>

* Refs #20543: Apply last(?) revision suggestion

Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>

* Refs #20543: Apply Edu' suggestion

Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>

* Refs #20543: Apply Edu' suggestion (2)

Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>

* Refs #20543: Add missing test

Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>

* Refs #20543: Fix test

Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>

* Refs #20543: Apply rev suggestions

Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>

* Refs #20543: Instanciate test listener in stack

Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>

* Refs #20543: Include new feature in versions.md

Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>

---------

Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>
  • Loading branch information
JesusPoderoso committed Apr 12, 2024
1 parent 2bf9c26 commit e0658b6
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 7 deletions.
21 changes: 21 additions & 0 deletions include/fastdds/dds/domain/DomainParticipantFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ class DomainParticipantFactory
DomainParticipantListener* listener = nullptr,
const StatusMask& mask = StatusMask::all());

/**
* Create a Participant with default domain id and qos.
*
* @return DomainParticipant pointer. (nullptr if not created.)
*/
FASTDDS_EXPORTED_API DomainParticipant* create_participant_with_default_profile();


/**
* Create a Participant with default domain id and qos.
*
* @return DomainParticipant pointer. (nullptr if not created.)
* @param listener DomainParticipantListener Pointer
* @param mask StatusMask Reference
*/
FASTDDS_EXPORTED_API DomainParticipant* create_participant_with_default_profile(
DomainParticipantListener* listener,
const StatusMask& mask);

/**
* Create a Participant.
*
Expand Down Expand Up @@ -342,6 +361,8 @@ class DomainParticipantFactory

mutable bool default_xml_profiles_loaded;

DomainId_t default_domain_id_;

DomainParticipantFactoryQos factory_qos_;

DomainParticipantQos default_participant_qos_;
Expand Down
32 changes: 25 additions & 7 deletions src/cpp/fastdds/domain/DomainParticipantFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace dds {

DomainParticipantFactory::DomainParticipantFactory()
: default_xml_profiles_loaded(false)
, default_domain_id_(0)
, default_participant_qos_(PARTICIPANT_QOS_DEFAULT)
, topic_pool_(fastrtps::rtps::TopicPayloadPoolRegistry::instance())
, rtps_domain_(fastrtps::rtps::RTPSDomainImpl::get_instance())
Expand Down Expand Up @@ -155,7 +156,7 @@ ReturnCode_t DomainParticipantFactory::delete_participant(
DomainParticipant* DomainParticipantFactory::create_participant(
DomainId_t did,
const DomainParticipantQos& qos,
DomainParticipantListener* listen,
DomainParticipantListener* listener,
const StatusMask& mask)
{
load_profiles();
Expand All @@ -164,10 +165,10 @@ DomainParticipant* DomainParticipantFactory::create_participant(

DomainParticipant* dom_part = new DomainParticipant(mask);
#ifndef FASTDDS_STATISTICS
DomainParticipantImpl* dom_part_impl = new DomainParticipantImpl(dom_part, did, pqos, listen);
DomainParticipantImpl* dom_part_impl = new DomainParticipantImpl(dom_part, did, pqos, listener);
#else
eprosima::fastdds::statistics::dds::DomainParticipantImpl* dom_part_impl =
new eprosima::fastdds::statistics::dds::DomainParticipantImpl(dom_part, did, pqos, listen);
new eprosima::fastdds::statistics::dds::DomainParticipantImpl(dom_part, did, pqos, listener);
#endif // FASTDDS_STATISTICS

if (fastrtps::rtps::GUID_t::unknown() != dom_part_impl->guid())
Expand Down Expand Up @@ -206,10 +207,23 @@ DomainParticipant* DomainParticipantFactory::create_participant(
return dom_part;
}

DomainParticipant* DomainParticipantFactory::create_participant_with_default_profile()
{
return create_participant_with_default_profile(nullptr, StatusMask::none());
}

DomainParticipant* DomainParticipantFactory::create_participant_with_default_profile(
DomainParticipantListener* listener,
const StatusMask& mask)
{
load_profiles();
return create_participant(default_domain_id_, default_participant_qos_, listener, mask);
}

DomainParticipant* DomainParticipantFactory::create_participant_with_profile(
DomainId_t did,
const std::string& profile_name,
DomainParticipantListener* listen,
DomainParticipantListener* listener,
const StatusMask& mask)
{
load_profiles();
Expand All @@ -220,15 +234,15 @@ DomainParticipant* DomainParticipantFactory::create_participant_with_profile(
{
DomainParticipantQos qos = default_participant_qos_;
utils::set_qos_from_attributes(qos, attr.rtps);
return create_participant(did, qos, listen, mask);
return create_participant(did, qos, listener, mask);
}

return nullptr;
}

DomainParticipant* DomainParticipantFactory::create_participant_with_profile(
const std::string& profile_name,
DomainParticipantListener* listen,
DomainParticipantListener* listener,
const StatusMask& mask)
{
load_profiles();
Expand All @@ -239,7 +253,7 @@ DomainParticipant* DomainParticipantFactory::create_participant_with_profile(
{
DomainParticipantQos qos = default_participant_qos_;
utils::set_qos_from_attributes(qos, attr.rtps);
return create_participant(attr.domainId, qos, listen, mask);
return create_participant(attr.domainId, qos, listener, mask);
}

return nullptr;
Expand Down Expand Up @@ -349,6 +363,10 @@ ReturnCode_t DomainParticipantFactory::load_profiles()
{
reset_default_participant_qos();
}
// Take the default domain id from the default participant profile
eprosima::fastdds::ParticipantAttributes attr;
XMLProfileManager::getDefaultParticipantAttributes(attr);
default_domain_id_ = attr.domainId;

RTPSDomain::set_filewatch_thread_config(factory_qos_.file_watch_threads(), factory_qos_.file_watch_threads());
}
Expand Down
78 changes: 78 additions & 0 deletions test/unittest/dds/participant/ParticipantTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <chrono>
#include <cstdlib>
#include <fstream>
#include <future>
#include <memory>
Expand Down Expand Up @@ -64,6 +65,7 @@
#include <xmlparser/attributes/PublisherAttributes.hpp>
#include <xmlparser/attributes/SubscriberAttributes.hpp>

#include "../../common/env_var_utils.hpp"
#include "../../logging/mock/MockConsumer.h"

#if defined(__cplusplus_winrt)
Expand Down Expand Up @@ -568,6 +570,82 @@ TEST(ParticipantTests, CreateDomainParticipantWithProfile)
ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant(participant) == ReturnCode_t::RETCODE_OK);
}

TEST(ParticipantTests, CreateDomainParticipantWithDefaultProfile)
{
uint32_t domain_id = 123u; // This is the domain ID set in the default profile above

// set XML profile as environment variable: "export FASTDDS_DEFAULT_PROFILES_FILE=test_xml_profile.xml"
eprosima::testing::set_environment_variable("FASTDDS_DEFAULT_PROFILES_FILE", "test_xml_profile.xml");

//participant using the given profile
DomainParticipant* default_env_participant =
DomainParticipantFactory::get_instance()->create_participant_with_default_profile();

// unset XML profile environment variable
eprosima::testing::clear_environment_variable("FASTDDS_DEFAULT_PROFILES_FILE");

ASSERT_NE(default_env_participant, nullptr);
ASSERT_EQ(default_env_participant->get_domain_id(), domain_id);
ASSERT_EQ(default_env_participant->get_listener(), nullptr);
ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant(
default_env_participant) == ReturnCode_t::RETCODE_OK);
}

TEST(ParticipantTests, CreateDomainParticipantWithDefaultProfileListener)
{
uint32_t domain_id = 123u; // This is the domain ID set in the default profile above

// set XML profile as environment variable: "export FASTDDS_DEFAULT_PROFILES_FILE=test_xml_profile.xml"
eprosima::testing::set_environment_variable("FASTDDS_DEFAULT_PROFILES_FILE", "test_xml_profile.xml");

DomainParticipantListener listener;

//participant using the given profile
DomainParticipant* default_env_participant =
DomainParticipantFactory::get_instance()->create_participant_with_default_profile(&listener,
StatusMask::none());

// unset XML profile environment variable
eprosima::testing::clear_environment_variable("FASTDDS_DEFAULT_PROFILES_FILE");

ASSERT_NE(default_env_participant, nullptr);
ASSERT_EQ(default_env_participant->get_domain_id(), domain_id);
ASSERT_EQ(default_env_participant->get_listener(), &listener);
ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant(
default_env_participant) == ReturnCode_t::RETCODE_OK);
}

TEST(ParticipantTests, CreateDomainParticipantWithoutDefaultProfile)
{
uint32_t default_domain_id = 0u; // This is the default domain ID

//participant using default values
DomainParticipant* default_participant =
DomainParticipantFactory::get_instance()->create_participant_with_default_profile();
ASSERT_NE(default_participant, nullptr);
ASSERT_EQ(default_participant->get_domain_id(), default_domain_id);
ASSERT_EQ(default_participant->get_listener(), nullptr);
ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant(
default_participant) == ReturnCode_t::RETCODE_OK);
}

TEST(ParticipantTests, CreateDomainParticipantWithoutDefaultProfileListener)
{
uint32_t default_domain_id = 0u; // This is the default domain ID

DomainParticipantListener listener;

//participant using default values
DomainParticipant* default_participant =
DomainParticipantFactory::get_instance()->create_participant_with_default_profile(&listener,
StatusMask::none());
ASSERT_NE(default_participant, nullptr);
ASSERT_EQ(default_participant->get_domain_id(), default_domain_id);
ASSERT_EQ(default_participant->get_listener(), &listener);
ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant(
default_participant) == ReturnCode_t::RETCODE_OK);
}

TEST(ParticipantTests, GetParticipantProfileQos)
{
DomainParticipantFactory::get_instance()->load_XML_profiles_file("test_xml_profile.xml");
Expand Down
1 change: 1 addition & 0 deletions versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Forthcoming
* StringMatching
* TimeConversion
* DBQueue
* Added create participant methods that use environment XML profile for participant configuration.

Version 2.14.0
--------------
Expand Down

0 comments on commit e0658b6

Please sign in to comment.