Skip to content

Latest commit

 

History

History
98 lines (68 loc) · 3.53 KB

createPublisher.rst

File metadata and controls

98 lines (68 loc) · 3.53 KB

Creating a Publisher

A :ref:`dds_layer_publisher_publisher` always belongs to a :ref:`dds_layer_domainParticipant`. Creation of a Publisher is done with the |DomainParticipant::create_publisher-api| member function on the DomainParticipant instance, that acts as a factory for the Publisher.

Mandatory arguments are:

Optional arguments are:

  • A Listener derived from :ref:`dds_layer_publisher_publisherListener`, implementing the callbacks that will be triggered in response to events and state changes on the Publisher. By default empty callbacks are used.
  • A |StatusMask-api| that activates or deactivates triggering of individual callbacks on the PublisherListener. By default all events are enabled.

|DomainParticipant::create_publisher-api| will return a null pointer if there was an error during the operation, e.g. if the provided QoS is not compatible or is not supported. It is advisable to check that the returned value is a valid pointer.

.. literalinclude:: /../code/DDSCodeTester.cpp
   :language: c++
   :start-after: //DDS_CREATE_PUBLISHER
   :end-before: //!
   :dedent: 8


Profile based creation of a Publisher

Instead of using a :ref:`dds_layer_publisher_publisherQos`, the name of a profile can be used to create a Publisher with the |DomainParticipant::create_publisher_with_profile-api| member function on the DomainParticipant instance.

Mandatory arguments are:

  • A string with the name that identifies the Publisher.

Optional arguments are:

  • A Listener derived from :ref:`dds_layer_publisher_publisherListener`, implementing the callbacks that will be triggered in response to events and state changes on the Publisher. By default empty callbacks are used.
  • A |StatusMask-api| that activates or deactivates triggering of individual callbacks on the PublisherListener. By default all events are enabled.

|DomainParticipant::create_publisher_with_profile-api| will return a null pointer if there was an error during the operation, e.g. if the provided QoS is not compatible or is not supported. It is advisable to check that the returned value is a valid pointer.

Note

XML profiles must have been loaded previously. See :ref:`dds_layer_domainParticipantFactory_load_profiles`.

.. literalinclude:: /../code/DDSCodeTester.cpp
   :language: c++
   :start-after: //DDS_CREATE_PROFILE_PUBLISHER
   :end-before: //!
   :dedent: 8


Deleting a Publisher

A Publisher can be deleted with the |DomainParticipant::delete_publisher-api| member function on the DomainParticipant instance where the Publisher was created.

Note

A Publisher can only be deleted if all Entities belonging to the Publisher (DataWriters) have already been deleted. Otherwise, the function will issue an error and the Publisher will not be deleted. This can be performed by using the |Publisher::delete_contained_entities-api| member function of the :ref:`dds_layer_publisher_publisher`.

.. literalinclude:: /../code/DDSCodeTester.cpp
   :language: c++
   :start-after: //DDS_DELETE_PUBLISHER
   :end-before: //!
   :dedent: 8