Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: LifespanQoSExample Using the api incorrectly #4912

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions examples/cpp/dds/LifespanQoSExample/LifespanSubscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,32 @@ void LifespanSubscriber::run(
std::cout << std::endl << "Subscriber waiting for " << sleep_ms << " milliseconds" << std::endl << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_ms));

LifespanPubSubType::type data;
SampleInfo info;
LoanableSequence<Lifespan> data_values;
SampleInfoSeq sample_infos;

int32_t max_samples = listener.n_samples;
ReturnCode_t result = reader_->take(
data_values,
sample_infos,
max_samples,
ANY_SAMPLE_STATE);

for ( uint32_t i = 0; i < listener.n_samples; i++ )
if (result == ReturnCode_t::RETCODE_OK)
{
if (reader_->take_next_sample((void*) &data, &info) == ReturnCode_t::RETCODE_OK)
size_t samples_taken = sample_infos.length();
for (size_t i = 0; i < samples_taken; ++i)
{
std::cout << "Message " << data.message() << " " << data.index() << " read from history" << std::endl;
}
else
{
std::cout << "Could not read message " << i << " from history" << std::endl;
Lifespan& sample = data_values[i];
SampleInfo& sample_info = sample_infos[i];

std::cout << "Message " << sample.message() << " with index " << sample.index()
<< " read from history." << std::endl;
}
}
else
{
std::cout << "Could not read message from history" << std::endl;
}

reader_->return_loan(data_values, sample_infos);
}