Skip to content

Commit

Permalink
Read nested members
Browse files Browse the repository at this point in the history
  • Loading branch information
sonndinh committed Oct 22, 2024
1 parent 04d8a1d commit c1c5e2a
Showing 1 changed file with 42 additions and 32 deletions.
74 changes: 42 additions & 32 deletions src/dds_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,45 +213,56 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
const QString& memberName,
unsigned int index)
{
const char* error = "NULL";
QVariant value;
QMutexLocker locker(&m_dynamicSamplesMutex);

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

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

DDS::DynamicData_var sample = sampleList.at(index);
DDS::DynamicType_var topic_type = sample->type();
OpenDDS::XTypes::MemberPath member_path;
if (member_path.resolve_string_path(topic_type, memberName.toStdString().c_str()) != DDS::RETCODE_OK) {
return error;
}

// The direct parent dynamic data of this member
DDS::DynamicData_var parent_data;

// The Id of this member within the direct parent type
DDS::MemberId id;

if (member_path.get_member_from_data(sample, parent_data, id) != DDS::RETCODE_OK) {
return error;
}

DDS::DynamicType_var parent_type = parent_data->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;
if (parent_type->get_member(dtm, id) != DDS::RETCODE_OK) {
return error;
}

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

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

bool failed = true;
DDS::ReturnCode_t rc = DDS::RETCODE_OK;

switch (member_tk) {
case OpenDDS::XTypes::TK_BOOLEAN:
{
CORBA::Boolean tmp;
rc = sample->get_boolean_value(tmp, id);
rc = parent_data->get_boolean_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
Expand All @@ -261,7 +272,7 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
case OpenDDS::XTypes::TK_BYTE:
{
CORBA::Octet tmp;
rc = sample->get_byte_value(tmp, id);
rc = parent_data->get_byte_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
Expand All @@ -271,7 +282,7 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
case OpenDDS::XTypes::TK_INT16:
{
CORBA::Short tmp;
rc = sample->get_int16_value(tmp, id);
rc = parent_data->get_int16_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
Expand All @@ -281,7 +292,7 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
case OpenDDS::XTypes::TK_UINT16:
{
CORBA::UShort tmp;
rc = sample->get_uint16_value(tmp, id);
rc = parent_data->get_uint16_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
Expand All @@ -291,7 +302,7 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
case OpenDDS::XTypes::TK_INT32:
{
CORBA::Long tmp;
rc = sample->get_int32_value(tmp, id);
rc = parent_data->get_int32_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
Expand All @@ -300,8 +311,8 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
}
case OpenDDS::XTypes::TK_UINT32:
{
CORBA::UShort tmp;
rc = sample->get_uint16_value(tmp, id);
CORBA::ULong tmp;
rc = parent_data->get_uint32_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
Expand All @@ -311,7 +322,7 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
case OpenDDS::XTypes::TK_INT64:
{
CORBA::LongLong tmp;
rc = sample->get_int64_value(tmp, id);
rc = parent_data->get_int64_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = static_cast<qlonglong>(tmp);
failed = false;
Expand All @@ -321,7 +332,7 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
case OpenDDS::XTypes::TK_UINT64:
{
CORBA::ULongLong tmp;
rc = sample->get_uint64_value(tmp, id);
rc = parent_data->get_uint64_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = static_cast<qulonglong>(tmp);
failed = false;
Expand All @@ -331,7 +342,7 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
case OpenDDS::XTypes::TK_FLOAT32:
{
CORBA::Float tmp;
rc = sample->get_float32_value(tmp, id);
rc = parent_data->get_float32_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
Expand All @@ -341,7 +352,7 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
case OpenDDS::XTypes::TK_FLOAT64:
{
CORBA::Double tmp;
rc = sample->get_float64_value(tmp, id);
rc = parent_data->get_float64_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
Expand All @@ -351,7 +362,7 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
case OpenDDS::XTypes::TK_CHAR8:
{
CORBA::Char tmp;
rc = sample->get_char8_value(tmp, id);
rc = parent_data->get_char8_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
Expand All @@ -361,7 +372,7 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
case OpenDDS::XTypes::TK_CHAR16:
{
CORBA::WChar tmp;
rc = sample->get_char16_value(tmp, id);
rc = parent_data->get_char16_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp;
failed = false;
Expand All @@ -371,7 +382,7 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
case OpenDDS::XTypes::TK_STRING8:
{
CORBA::String_var tmp;
rc = sample->get_string_value(tmp, id);
rc = parent_data->get_string_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
value = tmp.in();
failed = false;
Expand All @@ -381,7 +392,7 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
case OpenDDS::XTypes::TK_ENUM:
{
CORBA::Long tmp;
rc = sample->get_int32_value(tmp, id);
rc = parent_data->get_int32_value(tmp, id);
if (rc == DDS::RETCODE_OK) {
DDS::String8_var name;
rc = OpenDDS::XTypes::get_enumerator_name(name, tmp, md->type());
Expand All @@ -397,7 +408,7 @@ QVariant CommonData::readDynamicMember(const QString& topicName,
}

if (failed) {
value = "NULL";
value = error;
}
return value;
}
Expand All @@ -411,7 +422,6 @@ QVariant CommonData::readValue(const QString& topicName,
if (value.toString() != "NULL") {
return value;
}

return readDynamicMember(topicName, memberName, index);
}

Expand Down

0 comments on commit c1c5e2a

Please sign in to comment.