3.2.3. DomainParticipantFactory

The sole purpose of this class is to allow the creation and destruction of DomainParticipant objects. DomainParticipantFactory itself has no factory, it is a singleton object that can be accessed through the get_instance() static member function on the DomainParticipantFactory class.

The behavior of the DomainParticipantFactory can be modified with the QoS values specified on DomainParticipantFactoryQos. Since the DomainParticipantFactory is a singleton, its QoS can only be modified with the DomainParticipantFactory::set_qos() member function.

DomainParticipantFactory does not accept any Listener, since it is not an Entity.

3.2.3.1. DomainParticipantFactoryQos

DomainParticipantFactoryQos controls the behavior of the DomainParticipantFactory. Internally it contains the following QosPolicy objects:

QosPolicy class

Accessor/Mutator

Mutable

EntityFactoryQosPolicy

entity_factory()

Yes

ThreadSettings

shm_watchdog_thread()

No

ThreadSettings

file_watch_threads()

No

Since the DomainParticipantFactory is a singleton, its QoS can only be modified with the DomainParticipantFactory::set_qos() member function.

DomainParticipantFactoryQos qos;

// Setting autoenable_created_entities to true makes the created DomainParticipants
// to be enabled upon creation
qos.entity_factory().autoenable_created_entities = true;
if (DomainParticipantFactory::get_instance()->set_qos(qos) != ReturnCode_t::RETCODE_OK)
{
    // Error
    return;
}

// Create a DomainParticipant with the new DomainParticipantFactoryQos.
// The returned DomainParticipant is already enabled
DomainParticipant* enabled_participant =
        DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == enabled_participant)
{
    // Error
    return;
}

// Setting autoenable_created_entities to false makes the created DomainParticipants
// to be disabled upon creation
qos.entity_factory().autoenable_created_entities = false;
if (DomainParticipantFactory::get_instance()->set_qos(qos) != ReturnCode_t::RETCODE_OK)
{
    // Error
    return;
}

// Create a DomainParticipant with the new DomainParticipantFactoryQos.
// The returned DomainParticipant is disabled and will need to be enabled explicitly
DomainParticipant* disabled_participant =
        DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
if (nullptr == disabled_participant)
{
    // Error
    return;
}

3.2.3.2. Loading profiles from an XML file

To create Entities based on XML profiles, the file containing such profiles must be loaded first.

If the profile is described in one of the default loaded files, it will be automatically available on initialization. Otherwise, load_XML_profiles_file() member function can be used to load the profiles in the XML. See section XML profiles for more information regarding XML profile format and automatic loading.

Once loaded, the name of the profiles can be used to create Entities that will have QoS settings according to the profile specifications.

// Load the XML with the profiles
DomainParticipantFactory::get_instance()->load_XML_profiles_file("profiles.xml");

// Profiles can now be used to create Entities
DomainParticipant* participant_with_profile =
        DomainParticipantFactory::get_instance()->create_participant_with_profile(0, "participant_profile");
if (nullptr == participant_with_profile)
{
    // Error
    return;
}