Create a DomainParticipant¶
Creation of a DomainParticipant can be done with the DomainParticipantFactory::create_participant
member function on the DomainParticipantFactory, that acts as a factory for the DomainParticipant.
Mandatory arguments are:
The
DomainIdthat identifies the domain where the DomainParticipant will be created.The DomainParticipantQos describing the behavior of the DomainParticipant.
Optional arguments are:
A Listener derived from DomainParticipant Listener, implementing the callbacks that will be triggered in response to events and state changes on the DomainParticipant.
A
StatusMaskthat activates or deactivates triggering of individual callbacks on the DomainParticipant Listener.
DomainParticipantFactory::create_participant will return a null pointer if there was an error during the operation, e.g. if the provided QoS is not compatible or is not supported.
It is advisable to check that the returned value is a valid pointer.
Example¶
// Instantiation of the application's DomainParticipantFactory
DomainParticipantFactory factory{};
// Domain ID to be used
DomainId domain_id = 0;
// Definition of a DomainParticipant QoS
DomainParticipantQos qos{};
memory::container::StaticString256 participant_name("safedds_participant");
qos.participant_name() = participant_name;
// Instantiation of a custom DomainParticipantListener
CustomDomainParticipantListener listener{};
// Creation of a StatusMask
StatusMask mask = ANY_STATUS_MASK;
// Remove a unwanted status
status_mask_unset(mask, INCONSISTENT_TOPIC_STATUS);
// Creation of a DomainParticipant
DomainParticipant* participant = factory.create_participant(
domain_id,
qos,
&listener,
mask);
// Check if the DomainParticipant was created
if (nullptr == participant)
{
std::cout << "Error creating DomainParticipant" << std::endl;
}
Static memory example¶
In order to create a DomainParticipant that does not use any platform allocation a StaticDomainParticipant can be instantiated:
Note
When using Safe DDS Static memory API, any Policy related with PreallocMemoryConfig in DomainParticipantQos will be ignored.
constexpr uint32_t STATIC_PARTICIPANT_MAX_REMOTE_PARTICIPANTS = 1;
constexpr uint32_t STATIC_PARTICIPANT_MAX_LOCAL_READERS = 1;
constexpr uint32_t STATIC_PARTICIPANT_MAX_REMOTE_READERS = 1;
constexpr uint32_t STATIC_PARTICIPANT_MAX_LOCAL_WRITERS = 1;
constexpr uint32_t STATIC_PARTICIPANT_MAX_REMOTE_WRITERS = 1;
constexpr uint32_t STATIC_PARTICIPANT_MAX_LOCAL_TOPICS = 1;
StaticDomainParticipant<
STATIC_PARTICIPANT_MAX_REMOTE_PARTICIPANTS,
STATIC_PARTICIPANT_MAX_LOCAL_READERS,
STATIC_PARTICIPANT_MAX_REMOTE_READERS,
STATIC_PARTICIPANT_MAX_LOCAL_WRITERS,
STATIC_PARTICIPANT_MAX_REMOTE_WRITERS,
STATIC_PARTICIPANT_MAX_LOCAL_TOPICS>
static_participant(
domain_id,
qos,
&listener,
mask,
transport,
transport);