Skip to content

Commit

Permalink
Adapt to RTPS WriterHistory refactor (#826)
Browse files Browse the repository at this point in the history
* Refs #21137. Adapt to RTPS WriterHistory refactor.

Signed-off-by: Miguel Company <[email protected]>

* Refs #21137. Spaces in comments.

Signed-off-by: Miguel Company <[email protected]>

---------

Signed-off-by: Miguel Company <[email protected]>
  • Loading branch information
MiguelCompany authored Jun 27, 2024
1 parent e2b24df commit fac26ea
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions code/CodeTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void rtps_api_example_create_entities()
//RTPS_API_CONF_PARTICIPANT
RTPSParticipantAttributes participant_attr;
participant_attr.setName("my_participant");
//etc.
// etc.
//!--
}

Expand All @@ -151,14 +151,11 @@ void rtps_api_example_create_entities()
}

//RTPS_API_WRITE_SAMPLE
//Request a change from the writer
CacheChange_t* change = writer->new_change([]() -> uint32_t
{
return 255;
}, ALIVE);
//Write serialized data into the change
// Request a change from the history
CacheChange_t* change = history->create_change(255, ALIVE);
// Write serialized data into the change
change->serializedPayload.length = sprintf((char*) change->serializedPayload.data, "My example string %d", 2) + 1;
//Insert change into the history. The Writer takes care of the rest.
// Insert change into the history. The Writer takes care of the rest.
history->add_change(change);
//!--
}
Expand Down Expand Up @@ -242,9 +239,9 @@ void rtps_api_example_create_entities_with_custom_pool()

// A writer using the custom payload pool
HistoryAttributes writer_history_attr;
WriterHistory* writer_history = new WriterHistory(writer_history_attr);
WriterHistory* writer_history = new WriterHistory(writer_history_attr, payload_pool);
WriterAttributes writer_attr;
RTPSWriter* writer = RTPSDomain::createRTPSWriter(participant, writer_attr, payload_pool, writer_history);
RTPSWriter* writer = RTPSDomain::createRTPSWriter(participant, writer_attr, writer_history);

// A reader using the same instance of the custom payload pool
HistoryAttributes reader_history_attr;
Expand All @@ -254,10 +251,7 @@ void rtps_api_example_create_entities_with_custom_pool()

// Write and Read operations work as usual, but take the Payloads from the pool.
// Requesting a change to the Writer will provide one with an empty Payload taken from the pool
CacheChange_t* change = writer->new_change([]() -> uint32_t
{
return 255;
}, ALIVE);
CacheChange_t* change = writer_history->create_change(255, ALIVE);

// Write serialized data into the change and add it to the history
change->serializedPayload.length = sprintf((char*) change->serializedPayload.data, "My example string %d", 2) + 1;
Expand All @@ -279,12 +273,12 @@ void rtps_api_example_conf()
//!--

//RTPS_API_HISTORY_CONF_PAYLOADMAXSIZE
history_attr.payloadMaxSize = 250;//Defaults to 500 bytes
history_attr.payloadMaxSize = 250; // Defaults to 500 bytes
//!--

//RTPS_API_HISTORY_CONF_RESOURCES
history_attr.initialReservedCaches = 250; //Defaults to 500
history_attr.maximumReservedCaches = 500; //Defaults to 0 = Unlimited Changes
history_attr.initialReservedCaches = 250; // Defaults to 500
history_attr.maximumReservedCaches = 500; // Defaults to 0 = Unlimited Changes
//!--
}

Expand Down

0 comments on commit fac26ea

Please sign in to comment.