Skip to content

Commit

Permalink
Refs 12400. Using DDS SampleInfo.
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
MiguelCompany committed Sep 6, 2021
1 parent 1b1486a commit a6cac0b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 54 deletions.
38 changes: 1 addition & 37 deletions src/cpp/fastdds/subscriber/DataReaderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,40 +57,6 @@ namespace eprosima {
namespace fastdds {
namespace dds {

static void sample_info_to_dds (
const SampleInfo_t& rtps_info,
SampleInfo* dds_info)
{
dds_info->sample_state = NOT_READ_SAMPLE_STATE;
dds_info->view_state = NOT_NEW_VIEW_STATE;
dds_info->disposed_generation_count = 0;
dds_info->no_writers_generation_count = 1;
dds_info->sample_rank = 0;
dds_info->generation_rank = 0;
dds_info->absoulte_generation_rank = 0;
dds_info->source_timestamp = rtps_info.sourceTimestamp;
dds_info->reception_timestamp = rtps_info.receptionTimestamp;
dds_info->instance_handle = rtps_info.iHandle;
dds_info->publication_handle = fastrtps::rtps::InstanceHandle_t(rtps_info.sample_identity.writer_guid());
dds_info->sample_identity = rtps_info.sample_identity;
dds_info->related_sample_identity = rtps_info.related_sample_identity;
dds_info->valid_data = rtps_info.sampleKind == eprosima::fastrtps::rtps::ALIVE ? true : false;

switch (rtps_info.sampleKind)
{
case eprosima::fastrtps::rtps::ALIVE:
dds_info->instance_state = ALIVE_INSTANCE_STATE;
break;
case eprosima::fastrtps::rtps::NOT_ALIVE_DISPOSED:
dds_info->instance_state = NOT_ALIVE_DISPOSED_INSTANCE_STATE;
break;
default:
//TODO [ILG] change this if the other kinds ever get implemented
dds_info->instance_state = ALIVE_INSTANCE_STATE;
break;
}
}

static bool collections_have_same_properties(
const LoanableCollection& data_values,
const SampleInfoSeq& sample_infos)
Expand Down Expand Up @@ -677,10 +643,8 @@ ReturnCode_t DataReaderImpl::get_first_untaken_info(
return ReturnCode_t::RETCODE_NOT_ENABLED;
}

SampleInfo_t rtps_info;
if (history_.get_first_untaken_info(&rtps_info))
if (history_.get_first_untaken_info(*info))
{
sample_info_to_dds(rtps_info, info);
return ReturnCode_t::RETCODE_OK;
}
return ReturnCode_t::RETCODE_NO_DATA;
Expand Down
47 changes: 33 additions & 14 deletions src/cpp/fastdds/subscriber/history/DataReaderHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,40 @@ using namespace eprosima::fastrtps::rtps;

using eprosima::fastrtps::KeyedChanges;
using eprosima::fastrtps::RecursiveTimedMutex;
using eprosima::fastrtps::SampleInfo_t;

static void get_sample_info(
SampleInfo_t* info,
CacheChange_t* change,
uint32_t ownership_strength)
SampleInfo& info,
CacheChange_t* change)
{
info->sampleKind = change->kind;
info->sample_identity.writer_guid(change->writerGUID);
info->sample_identity.sequence_number(change->sequenceNumber);
info->sourceTimestamp = change->sourceTimestamp;
info->receptionTimestamp = change->reader_info.receptionTimestamp;
info->ownershipStrength = ownership_strength;
info->iHandle = change->instanceHandle;
info->related_sample_identity = change->write_params.sample_identity();
info.sample_state = NOT_READ_SAMPLE_STATE;
info.view_state = NOT_NEW_VIEW_STATE;
info.disposed_generation_count = 0;
info.no_writers_generation_count = 1;
info.sample_rank = 0;
info.generation_rank = 0;
info.absoulte_generation_rank = 0;
info.source_timestamp = change->sourceTimestamp;
info.reception_timestamp = change->reader_info.receptionTimestamp;
info.instance_handle = change->instanceHandle;
info.publication_handle = fastrtps::rtps::InstanceHandle_t(change->writerGUID);
info.sample_identity.writer_guid(change->writerGUID);
info.sample_identity.sequence_number(change->sequenceNumber);
info.related_sample_identity = change->write_params.sample_identity();
info.valid_data = change->kind == eprosima::fastrtps::rtps::ALIVE;

switch (change->kind)
{
case eprosima::fastrtps::rtps::ALIVE:
info.instance_state = ALIVE_INSTANCE_STATE;
break;
case eprosima::fastrtps::rtps::NOT_ALIVE_DISPOSED:
info.instance_state = NOT_ALIVE_DISPOSED_INSTANCE_STATE;
break;
default:
//TODO [ILG] change this if the other kinds ever get implemented
info.instance_state = ALIVE_INSTANCE_STATE;
break;
}
}

static HistoryAttributes to_history_attributes(
Expand Down Expand Up @@ -329,15 +348,15 @@ bool DataReaderHistory::find_key_for_change(
}

bool DataReaderHistory::get_first_untaken_info(
SampleInfo_t* info)
SampleInfo& info)
{
std::lock_guard<RecursiveTimedMutex> lock(*mp_mutex);

CacheChange_t* change = nullptr;
WriterProxy* wp = nullptr;
if (mp_reader->nextUntakenCache(&change, &wp))
{
get_sample_info(info, change, 0);
get_sample_info(info, change);
mp_reader->change_read_by_user(change, wp, false);
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/fastdds/subscriber/history/DataReaderHistory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <fastdds/dds/core/policy/QosPolicies.hpp>
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
#include <fastdds/dds/subscriber/SampleInfo.hpp>

#include <fastdds/dds/topic/TopicDataType.hpp>
#include <fastdds/dds/topic/TopicDescription.hpp>
Expand All @@ -38,7 +39,6 @@
#include <fastdds/rtps/resources/ResourceManagement.h>

#include <fastrtps/common/KeyedChanges.h>
#include <fastrtps/subscriber/SampleInfo.h>
#include <fastrtps/utils/fixed_size_string.hpp>

namespace eprosima {
Expand Down Expand Up @@ -98,11 +98,11 @@ class DataReaderHistory : public eprosima::fastrtps::rtps::ReaderHistory

/**
* @brief Returns information about the first untaken sample.
* @param [out] info Pointer to a SampleInfo_t structure to store first untaken sample information.
* @param [out] info SampleInfo structure to store first untaken sample information.
* @return true if sample info was returned. false if there is no sample to take.
*/
bool get_first_untaken_info(
fastrtps::SampleInfo_t* info);
SampleInfo& info);

/**
* This method is called to remove a change from the SubscriberHistory.
Expand Down

0 comments on commit a6cac0b

Please sign in to comment.