You are here: Part 2: Core Concepts > Sending Data > Publishers > Creating Publishers

Creating Publishers

Before you can explicitly create a Publisher, you need a DomainParticipant (see DomainParticipants). To create a Publisher, use the DomainParticipant’s create_publisher() or create_publisher_with_profile() operations.

A QoS profile is way to use QoS settings from an XML file or string. With this approach, you can change QoS settings without recompiling the application. For details, see Configuring QoS with XML.

Note: The Modern C++ API Publishers provide constructors whose first and only required argument is the DomainParticipant.

DDSPublisher * create_publisher (
    const DDS_PublisherQos &qos, 
    DDSPublisherListener *listener, 
    DDS_StatusMask mask)
DDSPublisher * create_publisher_with_profile (
    const char *library_name, 
    const char *profile_name, 
    DDSPublisherListener *listener,
    DDS_StatusMask mask)

Where:

qos

If you want the default QoS settings (described in the API Reference HTML documentation), use DDS_PUBLISHER_QOS_DEFAULT for this parameter (see Figure 2).

If you want to customize any of the QosPolicies, supply a QoS structure (see Figure 3). The QoS structure for a Publisher is described in Publisher/Subscriber QosPolicies.

Note: If you use DDS_PUBLISHER_QOS_DEFAULT, it is not safe to create the Publisher while another thread may be simultaneously calling set_default_publisher_qos().

listener

Listeners are callback routines. Connext DDS uses them to notify your application when specific events (status changes) occur with respect to the Publisher or the DataWriters created by the Publisher.

The listener parameter may be set to NULL if you do not want to install a Listener. If you use NULL, the Listener of the DomainParticipant to which the Publisher belongs will be used instead (if it is set). For more information on PublisherListeners, see Setting Up PublisherListeners.

mask

This bit-mask indicates which status changes will cause the Publisher’s Listener to be invoked. The bits set in the mask must have corresponding callbacks implemented in the Listener.

If you use NULL for the Listener, use DDS_STATUS_MASK_NONE for this parameter. If the Listener implements all callbacks, use DDS_STATUS_MASK_ALL. For information on statuses, see Listeners.

library_name

A QoS Library is a named set of QoS profiles. See URL Groups. If NULL is used for library_name, the DomainParticipant’s default library is assumed (see Getting and Setting the Publisher’s Default QoS Profile and Library).

profile_name

A QoS profile groups a set of related QoS, usually one per entity. See URL Groups. If NULL is used for profile_name, the DomainParticipant’s default profile is assumed and library_name is ignored

Figure 2 Creating a Publisher with Default QosPolicies

// create the publisher
DDSPublisher* publisher =
    participant->create_publisher(
	DDS_PUBLISHER_QOS_DEFAULT,
	NULL, DDS_STATUS_MASK_NONE);
if (publisher == NULL) {
    // handle error
};

For more examples, see Configuring QoS Settings when the Publisher is Created.

After you create a Publisher, the next step is to use the Publisher to create a DataWriter for each Topic, see Creating DataWriters. For a list of operations you can perform with a Publisher, see Publisher Operations.

© 2017 RTI