RTI Connext Modern C++ API Version 7.3.0
Qos Provider Use Cases

How to use dds::core::QosProvider to access XML QoS profiles.

How to use dds::core::QosProvider to access XML QoS profiles.

Managing Qos Profiles

This section provides several examples on how to use a dds::core::QosProvider to load QoS profiles from XML. The class documentation provides general usage information.

These examples use the following file, ExampleQos.xml, which defines only the EntityName QoS policy for the DomainParticipant and DataWriter to illustrate how the profiles are loaded:

<?xml version="1.0"?>
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://community.rti.com/schema/current/rti_dds_profiles.xsd">
<qos_library name="MyLibrary">
<qos_profile name="MyProfile" is_default_qos="true">
<domain_participant_qos>
<participant_name>
<name>ExampleParticipantName</name>
</participant_name>
</domain_participant_qos>
<datawriter_qos>
<publication_name>
<name>ExamplePublicationName</name>
</publication_name>
</datawriter_qos>
</qos_profile>
</qos_library>
<qos_library name="MySecondLibrary">
<qos_profile name="MySecondProfile">
<domain_participant_qos>
<participant_name>
<name>SecondExampleParticipantName</name>
</participant_name>
</domain_participant_qos>
<datawriter_qos>
<publication_name>
<name>SecondExamplePublicationName</name>
</publication_name>
</datawriter_qos>
</qos_profile>
</qos_library>
</dds>

The example code shows how to create a QosProvider, load QoS profiles from the provider, and create entities with those QoS values:

// Load the contents of an XML file:
dds::core::QosProvider my_provider("ExampleQos.xml");
// Create a participant with the default profile:
auto participant_qos = my_provider.participant_qos();
dds::domain::DomainParticipant participant(0, participant_qos);
// This prints ExampleParticipantName because MyLibrary::MyProfile is marked
// with is_default_qos="true"
std::cout << participant.qos().policy<EntityName>().name().value()
<< std::endl;
// Load a specific profile. This time it prints SecondExampleParticipantName
participant_qos =
my_provider.participant_qos("MySecondLibrary::MySecondProfile");
std::cout << participant_qos.policy<EntityName>().name().value()
<< std::endl;
// Change the default profile:
my_provider.extensions().default_profile("MySecondLibrary::MySecondProfile");
// Now when the profile is not specified, participant_qos() looks at
// "MySecondLibrary::MySecondProfile", printing SecondExampleParticipantName
participant_qos = my_provider.participant_qos();
std::cout << participant_qos.policy<EntityName>().name().value()
<< std::endl;
// Create a topic, publisher and writer:
dds::topic::Topic<Foo> topic(participant, "Example Foo");
dds::pub::Publisher publisher(participant);
publisher,
topic,
my_provider.datawriter_qos());
// Prints SecondExamplePublicationName
std::cout << writer.qos().policy<EntityName>().name().value()
<< std::endl;
// If you don't want to specify the QoS argument for each writer you create
// you can set the default value:
my_provider.datawriter_qos("MyLibrary::MyProfile"));
dds::pub::DataWriter<Foo> other_writer(publisher, topic);
// Prints ExamplePublicationName
std::cout << writer.qos().policy<EntityName>().name().value() << std::endl;
// You can also load the QoS profiles from a string:
const char * my_xml_str =
"str://\"<dds>"
"<qos_library name=\"MyThirdLibrary\">"
"<qos_profile name=\"MyThirdProfile\">"
"<domain_participant_qos>"
"<participant_name>"
"<name>ThirdExampleParticipantName</name>"
"</participant_name>"
"</domain_participant_qos>"
"</qos_profile>"
"</qos_library>"
"</dds>\"";
// In this case we're also specifying which profile we want to load by
// default in the constructor
dds::core::QosProvider my_provider2(
my_xml_str,
"MyThirdLibrary::MyThirdProfile");
// This prints ThirdExampleParticipantName
participant_qos = my_provider2.participant_qos();
std::cout << participant_qos.policy<EntityName>().name().value()
<< std::endl;
// You can also examine which libraries and profiles that have been
// loaded:
auto libraries = my_provider.extensions().qos_profile_libraries();
for (const std::string& library : libraries) {
std::cout << library << std::endl;
auto profiles = my_provider.extensions().qos_profiles(library);
for (const std::string& profile : profiles) {
std::cout << " -" << profile << std::endl;
}
}
<<reference-type>> The QosProvider class provides a way for a user to control and access the XML QoS ...
Definition: TQosProvider.hpp:162
<<reference-type>> Container for all dds::core::Entity objects.
Definition: TDomainParticipant.hpp:63
const dds::domain::qos::DomainParticipantQos qos() const
Gets the current QoS policies of this DomainParticipant.
Definition: TDomainParticipant.hpp:253
const POLICY & policy() const
Gets a QoS policy by const reference.
<<reference-type>> Allows an application to publish data for a dds::topic::Topic
Definition: TDataWriter.hpp:58
<<reference-type>> A publisher is the object responsible for the actual dissemination of publications...
Definition: TPublisher.hpp:52
Publisher & default_datawriter_qos(const dds::pub::qos::DataWriterQos &dwqos)
Sets the default DataWriterQos.
Definition: TPublisher.hpp:183
std::string name() const
<<extension>> Gets the filter name
Definition: FilterImpl.hpp:133
<<reference-type>> Topic is the most basic description of the data to be published and subscribed.
Definition: TTopic.hpp:56
basic_string< char, rti::core::memory::OsapiAllocator< char > > string
A string convertible to std::string and with similar functionality.
Definition: String.hpp:266
See also
Create a DynamicType from an XML description
XML Application Creation

The Default Qos Provider

This example shows how to configure the default QosProvider:

// We're going to configure the default QoS Provider to load ExampleQos.xml
// and to ignore the NDDS_QOS_PROFILES environment variable and the file
// USER_QOS_PROFILES.xml
params.url_profile({ "ExampleQos.xml" });
params.ignore_user_profile(true);
// To ensure that the new configuration takes effect before any other
// profiles are loaded, set the new parameters before accessing
// QosProvider::Default().
dds::domain::DomainParticipant participant1(0, default_provider.participant_qos());
// Prints "ExampleParticipantName"
std::cout << participant1.qos().policy<EntityName>().name().value()
<< std::endl;
// Change the default profile
default_provider.extensions().default_profile("MySecondLibrary::MySecondProfile");
dds::domain::DomainParticipant participant2(1, default_provider.participant_qos());
// Prints "SecondExampleParticipantName"
std::cout << participant2.qos().policy<EntityName>().name().value()
<< std::endl;
// Reset the QosProviderParams for the default QosProvider
// This participant will not have a participant name (the default
// RTI Connext value) because we reset the default QosProviderParams,
// meaning that the value for string_profile is empty and the above example
// XML Qos profile is not loaded.
dds::domain::DomainParticipant participant3(2, default_provider.participant_qos());
// Prints false
std::cout << std::boolalpha
<< participant2.qos().policy<EntityName>().name().has_value()
<< std::endl;
const dds::domain::qos::DomainParticipantQos participant_qos()
Get the dds::domain::qos::DomainParticipantQos in the default profile.
Definition: TQosProvider.hpp:234
static QosProvider Default()
Get the default QosProvider.
Definition: TQosProvider.hpp:412
void default_profile(const std::string &profile_name)
<<extension>> Set the default profile for this QosProvider.
static void reset_default()
Reset the default settings of the default QosProvider.
Definition: TQosProvider.hpp:424
<<extension>> <<value-type>> Configure options that control the way that XML documents containing QoS...
Definition: QosProviderParams.hpp:80
bool ignore_user_profile() const
Get the value that is currently set for ignore_user_profile.
const dds::core::StringSeq url_profile() const
Get the current list of URL groups stored by this QosProviderParams.
bool ignore_environment_profile() const
Get the value that is currently set for ignore_environment_profile.
QosProviderParams default_qos_provider_params()
<<extension>> Get the rti::core::QosProviderParams for the default QosProvider