You are here: Part 2: Core Concepts > Sending Data > Publishers > Setting Publisher QosPolicies

Setting Publisher QosPolicies

A Publisher’s QosPolicies control its behavior. Think of the policies as the configuration and behavior ‘properties’ of the Publisher. The DDS_PublisherQos structure has the following format:

DDS_PublisherQos struct  {
    DDS_PresentationQosPolicy  presentation; 
    DDS_PartitionQosPolicy  partition; 
    DDS_GroupDataQosPolicy  group_data; 
    DDS_EntityFactoryQosPolicy  entity_factory;
    DDS_AsynchronousPublisherQosPolicy  asynchronous_publisher;
    DDS_ExclusiveAreaQosPolicy  exclusive_area; 
    DDS_EntityNameQosPolicy  publisher_name;
} DDS_PublisherQos;

Note: set_qos() cannot always be used in a listener callback; see Restricted Operations in Listener Callbacks.

Publisher QosPolicies summarizes the meaning of each policy. (They appear alphabetically in the table.) For information on why you would want to change a particular QosPolicy, see the referenced section. For defaults and valid ranges, please refer to the API Reference HTML documentation for each policy.

Publisher QosPolicies

QosPolicy

Description

ASYNCHRONOUS_PUBLISHER QosPolicy (DDS Extension)

Configures the mechanism that sends user data in an external middleware thread.

ENTITYFACTORY QosPolicy

Controls whether or not child Entities are created in the enabled state.

ENTITY_NAME QosPolicy (DDS Extension)

Assigns a name and role_name to a Publisher.

EXCLUSIVE_AREA QosPolicy (DDS Extension)

Configures multi-thread concurrency and deadlock prevention capabilities.

GROUP_DATA QosPolicy

Along with TOPIC_DATA QosPolicy and USER_DATA QosPolicy, this QosPolicy is used to attach a buffer of bytes to Connext DDS's discovery meta-data.

PARTITION QosPolicy

Adds string identifiers that are used for matching DataReaders and DataWriters for the same Topic.

PRESENTATION QosPolicy

Controls how Connext DDS presents data received by an application to the DataReaders of the data.

Configuring QoS Settings when the Publisher is Created

As described in Creating Publishers, there are different ways to create a Publisher, depending on how you want to specify its QoS (with or without a QoS Profile).

For more information, see Creating Publishers and Configuring QoS with XML.

Figure 3 Creating a Publisher with Non-Default QosPolicies (not from a profile)

DDS_PublisherQos publisher_qos;1For the C API, you need to use DDS_PublisherQos_INITIALIZER or DDS_PublisherQos_initialize(). See
Special QosPolicy Handling Considerations for C (Section on page 1)
// get defaults
if (participant->get_default_publisher_qos(publisher_qos) != DDS_RETCODE_OK){
    // handle error
}
// make QoS changes here
// for example, this changes the ENTITY_FACTORY QoS
publisher_qos.entity_factory.autoenable_created_entities = DDS_BOOLEAN_FALSE;
    // create the publisher
    DDSPublisher* publisher = participant->create_publisher(publisher_qos,
        NULL, DDS_STATUS_MASK_NONE);
if (publisher == NULL) {
    // handle error
}

Figure 4 Creating a Publisher with a QoS Profile

// create the publisher with QoS profile
DDSPublisher* publisher = participant->create_publisher_with_profile(
    “MyPublisherLibary”, “MyPublisherProfile”,
    NULL, DDS_STATUS_MASK_NONE);
if (publisher == NULL) {
    // handle error
}

Figure 5 Getting QoS Values from a Profile, Changing QoS Values, Creating a Publisher with Modified QoS Values

DDS_PublisherQos publisher_qos;2For the C API, you need to use DDS_PublisherQos_INITIALIZER or DDS_PublisherQos_initialize(). See
Special QosPolicy Handling Considerations for C (Section on page 1)
// Get publisher QoS from profile
retcode = factory->get_publisher_qos_from_profile(publisher_qos,
    “PublisherLibrary”, “PublisherProfile”);
if (retcode != DDS_RETCODE_OK) {
    // handle error
}
// Makes QoS changes here
// New entity_factory autoenable_created_entities will be true
publisher_qos.entity_factory.autoenable_created_entities = DDS_BOOLEAN_TRUE;
// create the publisher with modified QoS
DDSPublisher* publisher = participant->create_publisher(
    “Example Foo”, type_name, publisher_qos,
    NULL, DDS_STATUS_MASK_NONE);
if (publisher == NULL) {
    // handle error
}

Comparing QoS Values

The equals() operation compares two Publisher’s DDS_PublisherQoS structures for equality. It takes two parameters for the two Publisher’s QoS structures to be compared, then returns TRUE is they are equal (all values are the same) or FALSE if they are not equal.

Changing QoS Settings After the Publisher Has Been Created

There are 2 ways to change an existing Publisher’s QoS after it is has been created—again depending on whether or not you are using a QoS Profile.

Figure 6 Changing the QoS of an Existing Publisher

DDS_PublisherQos publisher_qos;3For the C API, you need to use DDS_PublisherQos_INITIALIZER or DDS_PublisherQos_initialize(). See
Special QosPolicy Handling Considerations for C (Section on page 1)
// Get current QoS. publisher points to an existing DDSPublisher.
if (publisher->get_qos(publisher_qos) != DDS_RETCODE_OK) {
    // handle error
}
// make changes
// New entity_factory autoenable_created_entities will be true
publisher_qos.entity_factory.autoenable_created_entities =DDS_BOOLEAN_TRUE;
// Set the new QoS
if (publisher->set_qos(publisher_qos) != DDS_RETCODE_OK ) {
    // handle error
}

Figure 7 Changing the QoS of an Existing Publisher with a QoS Profile

retcode = publisher->set_qos_with_profile(
    “PublisherProfileLibrary”,”PublisherProfile”);
if (retcode != DDS_RETCODE_OK) {
    // handle error
}

Getting and Setting the Publisher’s Default QoS Profile and Library

You can retrieve the default QoS profile used to create Publishers with the get_default_profile() operation.

You can also get the default library for Publishers, as well as the library that contains the Publisher’s default profile (these are not necessarily the same library); these operations are called get_default_library() and get_default_library_profile(), respectively. These operations are for informational purposes only (that is, you do not need to use them as a precursor to setting a library or profile.) For more information, see Configuring QoS with XML.

virtual const char *  get_default_library ()
const char *  get_default_profile ()
const char *  get_default_profile_library ()

There are also operations for setting the Publisher’s default library and profile:

DDS_ReturnCode_t set_default_library (const char *  library_name) 
DDS_ReturnCode_t set_default_profile (const char *  library_name, 
    const char *  profile_name) 

These operations only affect which library/profile will be used as the default the next time a default Publisher library/profile is needed during a call to one of this Publisher’s operations.

When calling a Publisher operation that requires a profile_name parameter, you can use NULL to refer to the default profile. (This same information applies to setting a default library.) If the default library/profile is not set, the Publisher inherits the default from the DomainParticipant.

set_default_profile() does not set the default QoS for DataWriters created by the Publisher; for this functionality, use the Publisher’s set_default_datawriter_qos_with_profile(), see Getting and Setting Default QoS for DataWriters (you may pass in NULL aftercalling the Publisher’s set_default_profile()).

set_default_profile() does not set the default QoS for newly created Publishers; for this functionality, use the DomainParticipant’s set_default_publisher_qos_with_profile() operation, see Getting and Setting Default QoS for Child Entities.

Getting and Setting Default QoS for DataWriters

These operations set the default QoS that will be used for new DataWriters if create_datawriter() is called with DDS_DATAWRITER_QOS_DEFAULT as the qos parameter:

DDS_ReturnCode_t set_default_datawriter_qos (const DDS_DataWriterQos &qos)
DDS_ReturnCode_t set_default_datawriter_qos_with_profile (
   const char *library_name, 
   const char *profile_name)

The above operations may potentially allocate memory, depending on the sequences contained in some QoS policies.

To get the default QoS that will be used for creating DataWriters if create_datawriter() is called with DDS_PARTICIPANT_QOS_DEFAULT as the qos parameter:

DDS_ReturnCode_t get_default_datawriter_qos (DDS_DataWriterQos & qos)   

This operation gets the QoS settings that were specified on the last successful call to set_default_datawriter_qos() or set_default_datawriter_qos_with_profile(), or if the call was never made, the default values listed in DDS_DataWriterQos.

Note: It is not safe to set the default DataWriter QoS values while another thread may be simultaneously calling get_default_datawriter_qos(), set_default_datawriter_qos(), or create_datawriter() with DDS_DATAWRITER_QOS_DEFAULT as the qos parameter. It is also not safe to get the default DataWriter QoS values while another thread may be simultaneously calling set_default_datawriter_qos().

Other Publisher QoS-Related Operations

© 2017 RTI