The following #includes are needed for the examples on this page
#include <dds/domain/ddsdomain.hpp>
Changing the QoS for an entity
The QoS for an entity can be specified at entity creation time. Once an entity has been created, its QoS can be manipulated as the following examples illustrate. A DataWriter is used in these examples, but the same can be applied to DomainParticipants, Subscribers, Publishers, DataReaders, and Topics.
- See QosProvider for examples on how to manage user-defined QoS profiles.
- See Qos Use Cases for examples on how to work with the Qos policy classes.
- Get an entity's QoS settings
- Change the desired qos policy fields
- Set the qos
Changing the listener and enabling/disabling statuses associated with it
The listener for an entity can be specified at the entity creation time. By default the listener is enabled for all the statuses supported by the entity.
Once an entity has been created, its listener and/or the statuses for which it is enabled can be manipulated as follows.
The following examples use a DomainParticipant but the same examples can be applied to all other entities (Subscribers, Publishers, DataReaders, DataWriters, and Topics)
- User defines entity listener methods
class ExampleDomainParticipantListener : public dds::domain::NoOpDomainParticipantListener
{
public:
ExampleDomainParticipantListener() {}
public:
void on_liveliness_lost(
const::dds::core::status::LivelinessLostStatus&)
{
std::cout << "on_liveliness_lost" << std::endl;
}
void on_liveliness_changed(
{
std::cout << "on_liveliness_changed" << std::endl;
}
void on_inconsistent_topic(
{
std::cout << "on_inconsistent_topic" << std::endl;
}
void on_data_on_readers(
{
std::cout << "on_data_on_readers" << std::endl;
}
void on_offered_deadline_missed(
const::dds::core::status::OfferedDeadlineMissedStatus&)
{
std::cout << "on_offered_deadline_missed" << std::endl;
}
void on_offered_incompatible_qos(
const::dds::core::status::OfferedIncompatibleQosStatus&)
{
std::cout << "on_offered_incompatible_qos" << std::endl;
}
void on_publication_matched(
const::dds::core::status::PublicationMatchedStatus&)
{
std::cout << "on_publication_matched" << std::endl;
}
void on_requested_deadline_missed(
{
std::cout << "on_requested_deadline_missed" << std::endl;
}
void on_requested_incompatible_qos(
{
std::cout << "on_requested_incompatible_qos" << std::endl;
}
void on_sample_lost(
{
std::cout << "on_sample_lost" << std::endl;
}
void on_sample_rejected(
{
std::cout << "on_sample_rejected" << std::endl;
}
void on_subscription_matched(
{
std::cout << "on_subscription_matched" << std::endl;
}
void on_data_available(
{
std::cout << "on_data_available" << std::endl;
}
};
- Get an entity's listener
ExampleDomainParticipantListener *listener = new ExampleDomainParticipantListener;
- Enable statuses for the
listener
- Disable a status for the
listener
enabled_status_list &= ~dds::core::status::StatusMask::offered_incompatible_qos();
- Set an entity's listener and only enable the listener for the statuses specified by the
enabled_status_list
. participant.
listener(listener, enabled_status_list);
Enabling/Disabling statuses associated with a status condition
Upon entity creation, by default, all the statuses are enabled for the DDS_StatusCondition associated with the entity.
Once an entity has been created, the list of statuses for which the DDS_StatusCondition is triggered can be manipulated as follows.
- Given an
entity
and the associated status_condition
ExampleDomainParticipantListener *listener = new ExampleDomainParticipantListener;
- Get the list of statuses enabled for the
status_condition
- Check if a given status is enabled for the
status_condition
- Enable statuses for the
status_condition
status_condition.enabled_statuses(
- Disable statuses for the
status_condition
status_condition.enabled_statuses(
Ignoring Entities
A Topic is used in this example, but each of the other entities (DomainParticipants, Publishers, Subscribers, and DataWriters) also have an ignore() method which takes the DomainParticipant and InstanceHandle(s) of the entities that are to be ignored
- Ignore Topics
handles.push_back(topic2.instance_handle());
handles.push_back(topic3.instance_handle());
Tearing Down An Entity
The following examples use a DomainParticipant to show the various patterns which exist to tear down an entity, but the same examples can also be applied when shutting down Subscribers, Publishers, DataReaders, DataWriters, and Topics
- Let all references to a given entity go out-of-scope and let the destructor take care of entity clean up
- Explicitly call close() on one of the existing references to an Entity
same_participant.
close();
try {
}
std::cout <<
"Expected AlreadyClosedError: " << ex.
what() << std::endl;
}
- Assign dds::core::null to the last reference to an Entity
participant1 = participant2;
- Retaining and then destroying an Entity
void howto_teardown_retain()
{
const uint32_t domain_id_0 = 0;
const uint32_t domain_id_1 = 1;
create_and_retain_participant(domain_id_0, false);
create_and_retain_participant(domain_id_1, true);
try {
}
std::cout <<
"Expected AlreadyClosedError: " << ex.
what() << std::endl;
}
}
void create_and_retain_participant(
const uint32_t
domain_id,
bool retain)
{
if (retain) {
}
}