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.
QosPolicy |
Description |
Configures the mechanism that sends user data in an external middleware thread. |
|
Controls whether or not child Entities are created in the enabled state. |
|
Assigns a name and role_name to a Publisher. |
|
Configures multi-thread concurrency and deadlock prevention capabilities. |
|
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. |
|
Adds string identifiers that are used for matching DataReaders and DataWriters for the same Topic. |
|
Controls how Connext DDS presents data received by an application to the DataReaders of the data. |
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 }
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.
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 }
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.
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().
This method is provided as a convenience for setting the values in a DataWriterQos structure before using that structure to create a DataWriter. As explained in Setting Topic QosPolicies, most of the policies in a TopicQos structure do not apply directly to the Topic itself, but to the associated DataWriters and DataReaders of that Topic. The TopicQos serves as a single container where the values of QosPolicies that must be set compatibly across matching DataWriters and DataReaders can be stored.
Thus instead of setting the values of the individual QosPolicies that make up a DataWriterQos structure every time you need to create a DataWriter for a Topic, you can use the Publisher’s copy_from_topic_qos() operation to “import” the Topic’s QosPolicies into a DataWriterQos structure. This operation copies the relevant policies in the TopicQos to the corresponding policies in the DataWriterQos.
This copy operation will often be used in combination with the Publisher’s get_default_datawriter_qos() and the Topic’s get_qos() operations. The Topic’s QoS values are merged on top of the Publisher’s default DataWriter QosPolicies with the result used to create a new DataWriter, or to set the QoS of an existing one (see Setting DataWriter QosPolicies).
C API users should use the DDS_PublisherQos_copy() operation rather than using structure assignment when copying between two QoS structures. The copy() operation will perform a deep copy so that policies that allocate heap memory such as sequences are copied correctly. In C++, C++/CLI, C# and Java, a copy constructor is provided to take care of sequences automatically.
Some QosPolicies contain sequences that allocate memory dynamically as they grow or shrink. The C API’s DDS_PublisherQos_finalize() operation frees the memory used by sequences but otherwise leaves the QoS unchanged. C API users should call finalize() on all DDS_PublisherQos objects before they are freed, or for QoS structures allocated on the stack, before they go out of scope. In C++, C++/CLI, C# and Java, the memory used by sequences is freed in the destructor.
© 2017 RTI