Skip to content

Commit

Permalink
Expose PayloadPool in DDSDataWriter and DDSDataReader (#514)
Browse files Browse the repository at this point in the history
* Refs #18913: Expose PayloadPool in DDSDataWriter and DDSDataReader

Signed-off-by: JesusPoderoso <[email protected]>

* Refs #18913: apply rev suggestions

Signed-off-by: JesusPoderoso <[email protected]>

* Refs #18913: Update code to build and pass CI

Signed-off-by: JesusPoderoso <[email protected]>

* Refs #18913: Apply rev suggestions

Signed-off-by: JesusPoderoso <[email protected]>

* Refs #19024: Update method calls

Signed-off-by: JesusPoderoso <[email protected]>

---------

Signed-off-by: JesusPoderoso <[email protected]>
  • Loading branch information
JesusPoderoso authored Aug 3, 2023
1 parent 3484b2d commit 3355a19
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
63 changes: 63 additions & 0 deletions code/DDSCodeTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <fastcdr/Cdr.h>

#include <sstream>
#include <memory>

using namespace eprosima::fastdds::dds;

Expand Down Expand Up @@ -254,6 +255,33 @@ class CustomDomainParticipantListener : public DomainParticipantListener
};
//!--

// Custom Payload pool example for documentation
class CustomPayloadPool : public eprosima::fastrtps::rtps::IPayloadPool
{
public:
CustomPayloadPool() = default;
~CustomPayloadPool() = default;
bool get_payload(
unsigned int size,
eprosima::fastrtps::rtps::CacheChange_t& cache_change)
{
return true;
}
bool get_payload(
eprosima::fastrtps::rtps::SerializedPayload_t& data,
eprosima::fastrtps::rtps::IPayloadPool*& data_owner,
eprosima::fastrtps::rtps::CacheChange_t& cache_change)
{
return true;
}
bool release_payload(
eprosima::fastrtps::rtps::CacheChange_t& cache_change)
{
return true;
}
};
//!--

void dds_domain_examples()
{
{
Expand Down Expand Up @@ -2517,6 +2545,24 @@ void dds_dataWriter_examples()
//!--
}

{
//DDS_CREATE_PAYLOAD_POOL_DATAWRITER
// A DataWriterQos must be provided to the creation method
DataWriterQos qos;

// Create PayloadPool
std::shared_ptr<eprosima::fastrtps::rtps::IPayloadPool> payload_pool =
std::dynamic_pointer_cast<eprosima::fastrtps::rtps::IPayloadPool>(std::make_shared<CustomPayloadPool>());

DataWriter* data_writer = publisher->create_datawriter(topic, qos, nullptr, StatusMask::all(), payload_pool);
if (nullptr == data_writer)
{
// Error
return;
}
//!--
}

{
//DDS_CHANGE_DATAWRITERQOS
// Create a DataWriter with default DataWriterQos
Expand Down Expand Up @@ -3292,6 +3338,23 @@ void dds_dataReader_examples()
//!--
}

{
//DDS_CREATE_PAYLOAD_POOL_DATAREADER
// A DataReaderQos must be provided to the creation method
DataReaderQos qos;

// Create PayloadPool
std::shared_ptr<CustomPayloadPool> payload_pool = std::make_shared<CustomPayloadPool>();

DataReader* data_reader = subscriber->create_datareader(topic, qos, nullptr, StatusMask::all(), payload_pool);
if (nullptr == data_reader)
{
// Error
return;
}
//!--
}

{
//DDS_CHANGE_DATAREADERQOS
// Create a DataReader with default DataReaderQos
Expand Down
19 changes: 19 additions & 0 deletions docs/fastdds/dds_layer/publisher/dataWriter/createDataWriter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ It is advisable to check that the returned value is a valid pointer.
:end-before: //!
:dedent: 8

.. _dds_layer_publisher_datawriter_with_payload_pool_creation:

Creating a DataWriter with a custom PayloadPool
-----------------------------------------------

A custom :ref:`PayloadPool<rtps_layer_custom_payload_pool>` can be passed as an argument during the creation of a
:ref:`dds_layer_publisher_dataWriter`.
This allows for customizing the management of the information exchanged between DataWriters and DataReaders.
The same configuration can be set in the
:ref:`opposite endpoint<dds_layer_subscriber_datareader_with_payload_pool_creation>`.

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

This configuration can be performed also in the :ref:`RTPS layer<rtps_layer_custom_payload_pool>`.
The :ref:`customization example<rtps_layer_payload_pool_example>` applies both layers.

.. _dds_layer_publisher_datawriter_deletion:

Expand Down
20 changes: 20 additions & 0 deletions docs/fastdds/dds_layer/subscriber/dataReader/createDataReader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ It is advisable to check that the returned value is a valid pointer.
:dedent: 8


.. _dds_layer_subscriber_datareader_with_payload_pool_creation:

Creating a DataWriter with a custom PayloadPool
-----------------------------------------------

A custom :ref:`PayloadPool<rtps_layer_custom_payload_pool>` can be passed as an argument during the creation of a
:ref:`dds_layer_subscriber_dataReader`.
This allows for customizing the management of the information exchanged between DataWriters and DataReaders.
The same configuration can be set in the
:ref:`opposite endpoint<dds_layer_publisher_datawriter_with_payload_pool_creation>`.

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

This configuration can be performed also in the :ref:`RTPS layer<rtps_layer_custom_payload_pool>`.
The :ref:`customization example<rtps_layer_payload_pool_example>` applies both layers.

.. _dds_layer_subscriber_datareader_deletion:

Deleting a DataReader
Expand Down
5 changes: 4 additions & 1 deletion docs/fastdds/rtps_layer/rtps_layer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ You can specify a maximum amount of changes for the History to hold and an initi
When the initial amount of reserved changes is lower than the maximum, the History will allocate more changes as they
are needed until it reaches the maximum size.

.. _rtps_layer_custom_payload_pool:

Using a custom Payload Pool
---------------------------

Expand Down Expand Up @@ -256,7 +258,6 @@ IPayloadPool interface

Note that the size requested to |IPayloadPool::get_payload-api| already considers this 4 octet header.


Default Payload pool implementation
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -303,6 +304,8 @@ Released Payloads can be reused for another :class:`CacheChange_t`.
If there is at least one free Payload with a buffer size equal or larger to the requested one,
no memory allocation is done.

.. _rtps_layer_payload_pool_example:

Example using a custom Payload pool
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down

0 comments on commit 3355a19

Please sign in to comment.