.. _dds_layers_publication_publish_data: Publishing data =============== .. include:: ../../../safety_manual/rules/RULE_OPERATION_PHASE_ACTIONS.inc Data instances can be updated with the ``TypedDataWriter::write`` method. This change will be communicated to every :ref:`dds_layers_subscription_datareader` matched with the DataWriter. As a side effect, this operation asserts liveliness on the DataWriter itself, the :ref:`dds_layers_publication_publisher` and the :ref:`dds_layers_domain_participant`. .. _dds_layer_publisher_typedDataWriter: Using the TypedDataWriter ------------------------- .. note:: In order to provide a type safe API, Safe DDS provides a ``TypedDataWriter`` class. ``TypedDataWriter`` class is a specialization of the ``DataWriter`` class, and it is obtained by calling the ``TypedDataWriter::downcast`` method and its constructed using a :ref:`typesupport` class that must be previously :ref:`registered in the DomainParticipant ` with a :ref:`dds_layers_topic` name that matches the one used to create the ``DataWriter``. Once the ``TypedDataWriter`` reference is obtained, the ``write`` method can be used to publish data. The ``write`` function takes two arguments: * A reference to the data instance with the new values. * The handler to the instance. An empty (i.e., default constructed ``InstanceHandle`` or ``HANDLE_NIL``) instance handler can be used for the argument handle. This indicates that the identity of the instance should be automatically deduced from the key of the instance data. If the handle is not empty, then it must correspond to the value obtained with the ``TypedDataWriter::lookup_instance`` of the data. Otherwise the write function will fail with ``PRECONDITION_NOT_MET``. .. note:: If :ref:`Safe DDS Static API ` is used, there is no need to use the ``TypedDataWriter::downcast`` method, since the ``StaticDataWriter`` is already a ``TypedDataWriter``. Example """"""" .. literalinclude:: ../../../code/entity_creation/main.cpp :language: c++ :start-after: // DDS_WRITE_DATA :end-before: //! DDS_WRITE_DATA :dedent: 8