Skip to content

Commit

Permalink
Read from dynamic sample store
Browse files Browse the repository at this point in the history
  • Loading branch information
sonndinh committed Oct 16, 2024
1 parent b1a2036 commit f1cb07d
Show file tree
Hide file tree
Showing 2 changed files with 207 additions and 10 deletions.
203 changes: 196 additions & 7 deletions src/dds_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,13 @@ std::shared_ptr<TopicInfo> CommonData::getTopicInfo(const QString& topicName)
return topicInfo;
}

//------------------------------------------------------------------------------
QVariant CommonData::readValue(const QString& topicName,
const QString& memberName,
const unsigned int& index)
QVariant CommonData::readMember(const QString& topicName,
const QString& memberName,
unsigned int index)
{
QVariant value;
QMutexLocker locker(&m_sampleMutex);


// Make sure the index is valid
QList<std::shared_ptr<OpenDynamicData>>& sampleList = m_samples[topicName];
if ((int)index >= sampleList.count())
Expand All @@ -112,7 +110,6 @@ QVariant CommonData::readValue(const QString& topicName,
return value;
}


// Store the value into a QVariant
// The tmpValue may seem redundant, but it's very helpful for debug
CORBA::TCKind type = targetMember->getKind();
Expand Down Expand Up @@ -209,8 +206,200 @@ QVariant CommonData::readValue(const QString& topicName,
} // End targetMember type switch

return value;
}

QVariant CommonData::readDynamicMember(const QString& topicName,
const QString& memberName,
unsigned int index)
{
QVariant value;
QMutexLocker locker(&m_dynamicSamplesMutex);

if (!m_dynamicSamples.contains(topicName)) {
value = "NULL";
return value;
}

const QList<DDS::DynamicData_var>& sampleList = m_dynamicSamples[topicName];
if ((int)index >= sampleList.count()) {
value = "NULL";
return value;
}

DDS::DynamicData_var sample = sampleList.at(index);
DDS::DynamicType_var topic_type = sample->type();
DDS::DynamicTypeMember_var dtm;
DDS::ReturnCode_t rc = topic_type->get_member_by_name(dtm, memberName.toStdString().c_str());
if (rc != DDS::RETCODE_OK) {
value = "NULL";
return value;
}

DDS::MemberDescriptor_var md;
rc = dtm->get_descriptor(md);
if (rc != DDS::RETCODE_OK) {
value = "NULL";
return value;
}

const DDS::TypeKind member_tk = md->type()->get_kind();
const DDS::MemberId id = md->id();

bool failed = true;
switch (member_tk) {
case OpenDDS::XTypes::TK_BOOLEAN:
{
CORBA::Boolean tmp;
rc = sample->get_boolean_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
}
break;
}
case OpenDDS::XTypes::TK_BYTE:
{
CORBA::Octet tmp;
rc = sample->get_byte_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
}
break;
}
case OpenDDS::XTypes::TK_INT16:
{
CORBA::Short tmp;
rc = sample->get_int16_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
}
break;
}
case OpenDDS::XTypes::TK_UINT16:
{
CORBA::UShort tmp;
rc = sample->get_uint16_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
}
break;
}
case OpenDDS::XTypes::TK_INT32:
{
CORBA::Long tmp;
rc = sample->get_int32_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
}
break;
}
case OpenDDS::XTypes::TK_UINT32:
{
CORBA::UShort tmp;
rc = sample->get_uint16_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
}
break;
}
case OpenDDS::XTypes::TK_INT64:
{
CORBA::LongLong tmp;
rc = sample->get_int64_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;

Check failure on line 315 in src/dds_data.cpp

View workflow job for this annotation

GitHub Actions / build (master, ubuntu-22.04)

conversion from ‘CORBA::LongLong’ {aka ‘long int’} to ‘QVariant’ is ambiguous

Check failure on line 315 in src/dds_data.cpp

View workflow job for this annotation

GitHub Actions / build (master, ubuntu-20.04)

conversion from ‘CORBA::LongLong’ {aka ‘long int’} to ‘QVariant’ is ambiguous

Check failure on line 315 in src/dds_data.cpp

View workflow job for this annotation

GitHub Actions / build (latest-release, ubuntu-22.04)

conversion from ‘CORBA::LongLong’ {aka ‘long int’} to ‘QVariant’ is ambiguous

Check failure on line 315 in src/dds_data.cpp

View workflow job for this annotation

GitHub Actions / build (latest-release, ubuntu-20.04)

conversion from ‘CORBA::LongLong’ {aka ‘long int’} to ‘QVariant’ is ambiguous
failed = false;
}
break;
}
case OpenDDS::XTypes::TK_UINT64:
{
CORBA::ULongLong tmp;
rc = sample->get_uint64_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;

Check failure on line 325 in src/dds_data.cpp

View workflow job for this annotation

GitHub Actions / build (master, ubuntu-22.04)

conversion from ‘CORBA::ULongLong’ {aka ‘long unsigned int’} to ‘QVariant’ is ambiguous

Check failure on line 325 in src/dds_data.cpp

View workflow job for this annotation

GitHub Actions / build (master, ubuntu-20.04)

conversion from ‘CORBA::ULongLong’ {aka ‘long unsigned int’} to ‘QVariant’ is ambiguous

Check failure on line 325 in src/dds_data.cpp

View workflow job for this annotation

GitHub Actions / build (latest-release, ubuntu-22.04)

conversion from ‘CORBA::ULongLong’ {aka ‘long unsigned int’} to ‘QVariant’ is ambiguous

Check failure on line 325 in src/dds_data.cpp

View workflow job for this annotation

GitHub Actions / build (latest-release, ubuntu-20.04)

conversion from ‘CORBA::ULongLong’ {aka ‘long unsigned int’} to ‘QVariant’ is ambiguous
failed = false;
}
break;
}
case OpenDDS::XTypes::TK_FLOAT32:
{
CORBA::Float tmp;
rc = sample->get_float32_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
}
break;
}
case OpenDDS::XTypes::TK_FLOAT64:
{
CORBA::Double tmp;
rc = sample->get_float64_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
}
break;
}
case OpenDDS::XTypes::TK_CHAR8:
{
CORBA::Char tmp;
rc = sample->get_char8_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
}
break;
}
case OpenDDS::XTypes::TK_CHAR16:
{
CORBA::WChar tmp;
rc = sample->get_char16_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
}
break;
}
case OpenDDS::XTypes::TK_STRING8:
{
char* tmp;
rc = sample->get_string_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
}
break;
}
case OpenDDS::XTypes::TK_ENUM:
default:
break;
}

if (failed) {
value = "NULL";
}
return value;
}

//------------------------------------------------------------------------------
QVariant CommonData::readValue(const QString& topicName,
const QString& memberName,
unsigned int index)
{
const QVariant value = readMember(topicName, memberName, index);
if (value.toString() != "NULL") {
return value;
}

} // End CommonData::readValue
return readDynamicMember(topicName, memberName, index);
}


//------------------------------------------------------------------------------
Expand Down
14 changes: 11 additions & 3 deletions src/dds_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class CommonData
*/
static QVariant readValue(const QString& topicName,
const QString& memberName,
const unsigned int& index = 0);
unsigned int index = 0);

/**
* @brief Delete all data samples for a specified topic.
Expand Down Expand Up @@ -293,12 +293,20 @@ class CommonData

private:

static QVariant readMember(const QString& topicName,
const QString& memberName,
unsigned int index = 0);

static QVariant readDynamicMember(const QString& topicName,
const QString& memberName,
unsigned int index = 0);

/**
* @brief Stores the data samples from DDS.
* @details The key is the topic name and the value is the data sample. The
* first sample is always the latest and the last sample is last.
*/
static QMap<QString, QList<std::shared_ptr<OpenDynamicData> > > m_samples;
static QMap<QString, QList<std::shared_ptr<OpenDynamicData>>> m_samples;

/**
* @brief Stores the data sample times.
Expand All @@ -316,7 +324,7 @@ class CommonData

/// Store list of DynamicData objects for each topic.
/// We are storing the timestamps for these samples also in m_sampleTimes.
static QMap<QString, QList<DDS::DynamicData_var> > m_dynamicSamples;
static QMap<QString, QList<DDS::DynamicData_var>> m_dynamicSamples;

/// Mutex for protecting access to m_samples.
static QMutex m_sampleMutex;
Expand Down

0 comments on commit f1cb07d

Please sign in to comment.