Skip to content

Commit 6802780

Browse files
IPayloadPool refactor (#800)
* Refs #21121: Update API Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Refs #21121: Revision - remove getters/setter Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Refs #21121: Make get_payload's first arg const Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> * Refs #21121: Revision Signed-off-by: cferreiragonz <carlosferreira@eprosima.com> --------- Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>
1 parent ac2911b commit 6802780

3 files changed

Lines changed: 28 additions & 30 deletions

File tree

code/CodeTester.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -175,64 +175,63 @@ void rtps_api_example_create_entities_with_custom_pool()
175175
{
176176
bool get_payload(
177177
uint32_t size,
178-
CacheChange_t& cache_change) override
178+
SerializedPayload_t& payload) override
179179
{
180180
// Reserve new memory for the payload buffer
181-
octet* payload = new octet[size];
181+
octet* payload_buff = new octet[size];
182182

183183
// Assign the payload buffer to the CacheChange and update sizes
184-
cache_change.serializedPayload.data = payload;
185-
cache_change.serializedPayload.length = size;
186-
cache_change.serializedPayload.max_size = size;
184+
payload.data = payload_buff;
185+
payload.length = size;
186+
payload.max_size = size;
187187

188188
// Tell the CacheChange who needs to release its payload
189-
cache_change.payload_owner(this);
189+
payload.payload_owner = this;
190190

191191
return true;
192192
}
193193

194194
bool get_payload(
195-
SerializedPayload_t& data,
196-
IPayloadPool*& /*data_owner*/,
197-
CacheChange_t& cache_change)
195+
const SerializedPayload_t& data,
196+
SerializedPayload_t& payload)
198197
{
199198
// Reserve new memory for the payload buffer
200-
octet* payload = new octet[data.length];
199+
octet* payload_buff = new octet[data.length];
201200

202201
// Copy the data
203-
memcpy(payload, data.data, data.length);
202+
memcpy(payload_buff, data.data, data.length);
204203

205204
// Tell the CacheChange who needs to release its payload
206-
cache_change.payload_owner(this);
205+
payload.payload_owner = this;
207206

208207
// Assign the payload buffer to the CacheChange and update sizes
209-
cache_change.serializedPayload.data = payload;
210-
cache_change.serializedPayload.length = data.length;
211-
cache_change.serializedPayload.max_size = data.length;
208+
payload.data = payload_buff;
209+
payload.length = data.length;
210+
payload.max_size = data.length;
212211

213212
return true;
214213
}
215214

216215
bool release_payload(
217-
CacheChange_t& cache_change) override
216+
SerializedPayload_t& payload) override
218217
{
219218
// Ensure precondition
220-
if (this != cache_change.payload_owner())
219+
if (this != payload.payload_owner)
221220
{
222221
std::cerr << "Trying to release a payload buffer allocated by a different PayloadPool." << std::endl;
223222
return false;
224223
}
225224

226225
// Dealloc the buffer of the payload
227-
delete[] cache_change.serializedPayload.data;
226+
delete[] payload.data;
228227

229228
// Reset sizes and pointers
230-
cache_change.serializedPayload.data = nullptr;
231-
cache_change.serializedPayload.length = 0;
232-
cache_change.serializedPayload.max_size = 0;
229+
payload.data = nullptr;
230+
payload.length = 0;
231+
payload.max_size = 0;
233232

234233
// Reset the owner of the payload
235-
cache_change.payload_owner(nullptr);
234+
payload.payload_owner = nullptr;
236235

237236
return true;
238237
}

code/DDSCodeTester.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,21 +260,20 @@ class CustomPayloadPool : public eprosima::fastrtps::rtps::IPayloadPool
260260
~CustomPayloadPool() = default;
261261
bool get_payload(
262262
unsigned int size,
263-
eprosima::fastrtps::rtps::CacheChange_t& cache_change)
263+
eprosima::fastrtps::rtps::SerializedPayload_t& payload)
264264
{
265265
return true;
266266
}
267267

268268
bool get_payload(
269-
eprosima::fastrtps::rtps::SerializedPayload_t& data,
270-
eprosima::fastrtps::rtps::IPayloadPool*& data_owner,
271-
eprosima::fastrtps::rtps::CacheChange_t& cache_change)
269+
const eprosima::fastrtps::rtps::SerializedPayload_t& data,
270+
eprosima::fastrtps::rtps::SerializedPayload_t& payload)
272271
{
273272
return true;
274273
}
275274

276275
bool release_payload(
277-
eprosima::fastrtps::rtps::CacheChange_t& cache_change)
276+
eprosima::fastrtps::rtps::SerializedPayload_t& payload)
278277
{
279278
return true;
280279
}

docs/fastdds/rtps_layer/rtps_layer.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ IPayloadPool interface
304304

305305
* |IPayloadPool::get_payload-api| overload with SerializadPayload parameter:
306306

307-
Copies the given Payload data to a new Payload from the pool and ties it to the :class:`CacheChange_t` instance.
308-
This overload also takes a pointer to the pool that owns the original Payload.
309-
This allows certain optimizations, like sharing the Payload if the original one comes form this same pool,
307+
Copies the given Payload data to a new Payload from the pool.
308+
Each :cpp:member:`SerializedPayload_t` contains a pointer to the pool that allocated its data.
309+
This allows certain certain optimizations, like sharing the Payload if the original one comes from this same pool,
310310
therefore avoiding the copy operation.
311311

312312
* |IPayloadPool::release_payload-api|:

0 commit comments

Comments
 (0)