diff --git a/dds/DCPS/XTypes/DynamicDataXcdrReadImpl.cpp b/dds/DCPS/XTypes/DynamicDataXcdrReadImpl.cpp index 3f9053e185d..cda39176722 100644 --- a/dds/DCPS/XTypes/DynamicDataXcdrReadImpl.cpp +++ b/dds/DCPS/XTypes/DynamicDataXcdrReadImpl.cpp @@ -211,11 +211,7 @@ DDS::MemberId DynamicDataXcdrReadImpl::get_member_id_at_index(ACE_CDR::ULong ind return index; case TK_STRUCTURE: { - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return MEMBER_ID_INVALID; - } - const DDS::ExtensibilityKind ek = descriptor->extensibility_kind(); + const DDS::ExtensibilityKind ek = type_desc_->extensibility_kind(); if (ek == DDS::APPENDABLE || ek == DDS::MUTABLE) { if (!strm_.skip_delimiter()) { return MEMBER_ID_INVALID; @@ -371,7 +367,207 @@ DDS::MemberId DynamicDataXcdrReadImpl::get_member_id_at_index(ACE_CDR::ULong ind return MEMBER_ID_INVALID; } -ACE_CDR::ULong DynamicDataXcdrReadImpl::get_item_count() +bool DynamicDataXcdrReadImpl::get_struct_item_count() +{ + bool has_optional; + if (!has_optional_member(has_optional)) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count:" + " has_optional_member failed\n")); + } + return false; + } + + if (extent_ != DCPS::Sample::Full) { + const bool struct_has_explicit_keys = has_explicit_keys(type_); + if (struct_has_explicit_keys) { + ACE_CDR::ULong num_explicit_keys = 0; + for (ACE_CDR::ULong i = 0; i < type_->get_member_count(); ++i) { + DDS::DynamicTypeMember_var dtm; + DDS::ReturnCode_t rc = type_->get_member_by_index(dtm, i); + if (rc != DDS::RETCODE_OK) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count:" + " get_member_by_index %u failed: %C\n", i, retcode_to_string(rc))); + } + return false; + } + DDS::MemberDescriptor_var md; + rc = dtm->get_descriptor(md); + if (rc != DDS::RETCODE_OK) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count:" + " get_descriptor for member at index %u failed: %C\n", i, retcode_to_string(rc))); + } + return false; + } + if (md->is_key()) { + ++num_explicit_keys; + } + } + item_count_ = num_explicit_keys; + return true; + } else if (extent_ == DCPS::Sample::KeyOnly) { + item_count_ = 0; + return true; + } + } + + // Full sample or NestedKeyOnly sample with no explicit key. + if (!has_optional) { + item_count_ = type_->get_member_count(); + return true; + } + + // Optional members can be omitted, so we need to count members one by one. + ACE_CDR::ULong actual_count = 0; + const DDS::ExtensibilityKind ek = type_desc_->extensibility_kind(); + if (ek == DDS::FINAL || ek == DDS::APPENDABLE) { + if (ek == DDS::APPENDABLE) { + if (!strm_.skip_delimiter()) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count: Skip delimiter failed\n")); + } + return false; + } + } + for (ACE_CDR::ULong i = 0; i < type_->get_member_count(); ++i) { + ACE_CDR::ULong num_skipped; + if (!skip_struct_member_at_index(i, num_skipped)) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count:" + " Failed to skip struct member at index %u\n", i)); + } + return false; + } + actual_count += num_skipped; + } + } else { // Mutable + size_t dheader = 0; + if (!strm_.read_delimiter(dheader)) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count: Read delimiter failed\n")); + } + return false; + } + + const size_t end_of_struct = strm_.rpos() + dheader; + while (strm_.rpos() < end_of_struct) { + ACE_CDR::ULong member_id; + size_t member_size; + bool must_understand; + if (!strm_.read_parameter_id(member_id, member_size, must_understand)) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count: read_parameter_id failed\n")); + } + return false; + } + if (!strm_.skip(member_size)) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count:" + " Failed to skip %u bytes from the stream\n", member_size)); + } + return false; + } + ++actual_count; + } + } + item_count_ = actual_count; + return true; +} + +bool DynamicDataXcdrReadImpl::get_union_item_count() +{ + DDS::ReturnCode_t rc; + if (extent_ == DCPS::Sample::KeyOnly) { + DDS::DynamicTypeMember_var disc_dtm; + rc = type_->get_member(disc_dtm, DISCRIMINATOR_ID); + if (rc != DDS::RETCODE_OK) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count:" + " get_member for discriminator returned %C\n", retcode_to_string(rc))); + } + return false; + } + DDS::MemberDescriptor_var disc_md; + rc = disc_dtm->get_descriptor(disc_md); + if (rc != DDS::RETCODE_OK) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count:" + " get_descriptor for discriminator returned %C\n", retcode_to_string(rc))); + } + return false; + } + if (!disc_md->is_key()) { + item_count_ = 0; + return true; + } + } + if (extent_ != DCPS::Sample::Full) { + item_count_ = 1; + return true; + } + + const DDS::ExtensibilityKind ek = type_desc_->extensibility_kind(); + if (ek == DDS::APPENDABLE || ek == DDS::MUTABLE) { + if (!strm_.skip_delimiter()) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count: skip_delimiter failed\n")); + } + return false; + } + } + const DDS::DynamicType_var disc_type = get_base_type(type_desc_->discriminator_type()); + const DDS::ExtensibilityKind extend = type_desc_->extensibility_kind(); + ACE_CDR::Long label; + if (!read_discriminator(disc_type, extend, label)) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count: read_discriminator failed\n")); + } + return false; + } + + DDS::DynamicTypeMembersById_var members; + rc = type_->get_all_members(members); + if (rc != DDS::RETCODE_OK) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count:" + " get_all_members returned %C\n", retcode_to_string(rc))); + } + return false; + } + DynamicTypeMembersByIdImpl* members_impl = dynamic_cast(members.in()); + if (!members_impl) { + return false; + } + for (DynamicTypeMembersByIdImpl::const_iterator it = members_impl->begin(); it != members_impl->end(); ++it) { + DDS::MemberDescriptor_var md; + rc = it->second->get_descriptor(md); + if (rc != DDS::RETCODE_OK) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count:" + " get_descriptor returned %C\n", retcode_to_string(rc))); + } + return false; + } + if (md->is_default_label()) { + item_count_ = 2; + return true; + } + const DDS::UnionCaseLabelSeq& labels = md->label(); + for (ACE_CDR::ULong i = 0; i < labels.length(); ++i) { + if (label == labels[i]) { + item_count_ = 2; + return true; + } + } + } + + item_count_ = 1; + return true; +} + +DDS::UInt32 DynamicDataXcdrReadImpl::get_item_count() { if (item_count_ != ITEM_COUNT_INVALID) { return item_count_; @@ -379,11 +575,6 @@ ACE_CDR::ULong DynamicDataXcdrReadImpl::get_item_count() ScopedChainManager chain_manager(*this); - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return 0; - } - const TypeKind tk = type_->get_kind(); switch (tk) { case TK_BOOLEAN: @@ -402,204 +593,78 @@ ACE_CDR::ULong DynamicDataXcdrReadImpl::get_item_count() case TK_CHAR8: case TK_CHAR16: case TK_ENUM: - return 1; + item_count_ = 1; + break; case TK_STRING8: case TK_STRING16: { ACE_CDR::ULong bytes; if (!(strm_ >> bytes)) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count:" + " Failed to read %C\n", typekind_to_string(tk))); + } return 0; } - return (type_->get_kind() == TK_STRING8) ? bytes : bytes/2; + item_count_ = (tk == TK_STRING8) ? bytes : bytes/2; } + break; case TK_BITMASK: - return descriptor->bound()[0]; + item_count_ = type_desc_->bound()[0]; + break; case TK_STRUCTURE: - { - bool has_optional; - if (!has_optional_member(has_optional)) { - return 0; - } - - if (extent_ != DCPS::Sample::Full) { - const bool struct_has_explicit_keys = has_explicit_keys(type_); - if (struct_has_explicit_keys) { - ACE_CDR::ULong num_explicit_keys = 0; - for (ACE_CDR::ULong i = 0; i < type_->get_member_count(); ++i) { - DDS::DynamicTypeMember_var dtm; - if (type_->get_member_by_index(dtm, i) != DDS::RETCODE_OK) { - return 0; - } - DDS::MemberDescriptor_var md; - if (dtm->get_descriptor(md) != DDS::RETCODE_OK) { - return 0; - } - if (md->is_key()) { - ++num_explicit_keys; - } - } - return num_explicit_keys; - } else if (extent_ == DCPS::Sample::KeyOnly) { - return 0; - } - } - - // Full sample or NestedKeyOnly sample with no explicit key. - if (!has_optional) { - return type_->get_member_count(); - } - - // Optional members can be omitted, so we need to count members one by one. - ACE_CDR::ULong actual_count = 0; - const DDS::ExtensibilityKind ek = descriptor->extensibility_kind(); - if (ek == DDS::FINAL || ek == DDS::APPENDABLE) { - if (ek == DDS::APPENDABLE) { - if (!strm_.skip_delimiter()) { - return 0; - } - } - for (ACE_CDR::ULong i = 0; i < type_->get_member_count(); ++i) { - ACE_CDR::ULong num_skipped; - if (!skip_struct_member_at_index(i, num_skipped)) { - actual_count = 0; - break; - } - actual_count += num_skipped; - } - } else { // Mutable - size_t dheader = 0; - if (!strm_.read_delimiter(dheader)) { - return 0; - } - - const size_t end_of_struct = strm_.rpos() + dheader; - while (strm_.rpos() < end_of_struct) { - ACE_CDR::ULong member_id; - size_t member_size; - bool must_understand; - if (!strm_.read_parameter_id(member_id, member_size, must_understand)) { - actual_count = 0; - break; - } - - DDS::DynamicTypeMember_var dtm; - if (type_->get_member(dtm, member_id) != DDS::RETCODE_OK) { - actual_count = 0; - break; - } - DDS::MemberDescriptor_var descriptor; - if (dtm->get_descriptor(descriptor) != DDS::RETCODE_OK) { - actual_count = 0; - break; - } - const DDS::DynamicType_ptr mt = descriptor->type(); - if (!mt) { - actual_count = 0; - break; - } - const DDS::DynamicType_var member = get_base_type(mt); - if (member->get_kind() == TK_SEQUENCE) { - if (!skip_sequence_member(member)) { - actual_count = 0; - break; - } - } else if (!strm_.skip(member_size)) { - actual_count = 0; - break; - } - ++actual_count; - } - } - return actual_count; + if (!get_struct_item_count()) { + return 0; } + break; case TK_UNION: - { - if (extent_ == DCPS::Sample::KeyOnly) { - DDS::DynamicTypeMember_var disc_dtm; - if (type_->get_member(disc_dtm, DISCRIMINATOR_ID) != DDS::RETCODE_OK) { - return 0; - } - DDS::MemberDescriptor_var disc_md; - if (disc_dtm->get_descriptor(disc_md) != DDS::RETCODE_OK) { - return 0; - } - if (!disc_md->is_key()) { - return 0; - } - } - if (extent_ != DCPS::Sample::Full) { - return 1; - } - - const DDS::ExtensibilityKind ek = descriptor->extensibility_kind(); - if (ek == DDS::APPENDABLE || ek == DDS::MUTABLE) { - if (!strm_.skip_delimiter()) { - return 0; - } - } - const DDS::DynamicType_var disc_type = get_base_type(descriptor->discriminator_type()); - const DDS::ExtensibilityKind extend = descriptor->extensibility_kind(); - ACE_CDR::Long label; - if (!read_discriminator(disc_type, extend, label)) { - return 0; - } - - DDS::DynamicTypeMembersById_var members; - if (type_->get_all_members(members) != DDS::RETCODE_OK) { - return 0; - } - DynamicTypeMembersByIdImpl* members_impl = dynamic_cast(members.in()); - if (!members_impl) { - return 0; - } - for (DynamicTypeMembersByIdImpl::const_iterator it = members_impl->begin(); it != members_impl->end(); ++it) { - DDS::MemberDescriptor_var md; - if (it->second->get_descriptor(md) != DDS::RETCODE_OK) { - return 0; - } - if (md->is_default_label()) { - return 2; - } - const DDS::UnionCaseLabelSeq& labels = md->label(); - for (ACE_CDR::ULong i = 0; i < labels.length(); ++i) { - if (label == labels[i]) { - return 2; - } - } - } - return 1; + if (!get_union_item_count()) { + return 0; } + break; case TK_SEQUENCE: { - const DDS::DynamicType_var elem_type = get_base_type(descriptor->element_type()); - if (!is_primitive(elem_type->get_kind())) { - if (!strm_.skip_delimiter()) { - return 0; + const DDS::DynamicType_var elem_type = get_base_type(type_desc_->element_type()); + if (!is_primitive(elem_type->get_kind()) && !strm_.skip_delimiter()) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count: skip delimiter failed\n")); } + return 0; } ACE_CDR::ULong length; if (!(strm_ >> length)) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count: read sequence length failed\n")); + } return 0; } - return length; + item_count_ = length; } + break; case TK_ARRAY: - return bound_total(type_desc_); + item_count_ = bound_total(type_desc_); + break; case TK_MAP: { - const DDS::DynamicType_var key_type = get_base_type(descriptor->key_element_type()); - const DDS::DynamicType_var elem_type = get_base_type(descriptor->element_type()); - if (is_primitive(key_type->get_kind()) && - is_primitive(elem_type->get_kind())) { + const DDS::DynamicType_var key_type = get_base_type(type_desc_->key_element_type()); + const DDS::DynamicType_var elem_type = get_base_type(type_desc_->element_type()); + if (is_primitive(key_type->get_kind()) && is_primitive(elem_type->get_kind())) { ACE_CDR::ULong length; if (!(strm_ >> length)) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count: read map length failed\n")); + } return 0; } - return length; + item_count_ = length; + break; } size_t dheader; if (!strm_.read_delimiter(dheader)) { + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count: read delimiter failed\n")); + } return 0; } const size_t end_of_map = strm_.rpos() + dheader; @@ -607,20 +672,25 @@ ACE_CDR::ULong DynamicDataXcdrReadImpl::get_item_count() ACE_CDR::ULong length = 0; while (strm_.rpos() < end_of_map) { if (!skip_member(key_type) || !skip_member(elem_type)) { - length = 0; - break; + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count: skip map entry failed\n")); + } + return 0; } ++length; } - return length; + item_count_ = length; + } + break; + default: + if (log_level >= LogLevel::Warning) { + ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataXcdrReadImpl::get_item_count:" + " Calling on an unexpected type %C\n", typekind_to_string(tk))); } + return 0; } - if (DCPS::DCPS_debug_level >= 1) { - ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) DynamicDataXcdrReadImpl::get_item_count -") - ACE_TEXT(" Calling on an unexpected type %C\n"), typekind_to_string(tk))); - } - return 0; + return item_count_; } DDS::ReturnCode_t DynamicDataXcdrReadImpl::clear_all_values() @@ -768,19 +838,14 @@ DDS::ReturnCode_t DynamicDataXcdrReadImpl::get_value_from_struct(MemberType& val DDS::MemberDescriptor* DynamicDataXcdrReadImpl::get_union_selected_member() { - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return 0; - } - - const DDS::ExtensibilityKind ek = descriptor->extensibility_kind(); + const DDS::ExtensibilityKind ek = type_desc_->extensibility_kind(); if (ek == DDS::APPENDABLE || ek == DDS::MUTABLE) { if (!strm_.skip_delimiter()) { return 0; } } - const DDS::DynamicType_var disc_type = get_base_type(descriptor->discriminator_type()); + const DDS::DynamicType_var disc_type = get_base_type(type_desc_->discriminator_type()); ACE_CDR::Long label; if (!read_discriminator(disc_type, ek, label)) { return 0; @@ -900,21 +965,15 @@ DDS::ReturnCode_t DynamicDataXcdrReadImpl::get_value_from_union( return DDS::RETCODE_NO_DATA; } - DDS::TypeDescriptor_var descriptor; - DDS::ReturnCode_t rc = type_->get_descriptor(descriptor); - if (rc != DDS::RETCODE_OK) { - return rc; - } - + const DDS::ExtensibilityKind ek = type_desc_->extensibility_kind(); DDS::DynamicType_var member_type; if (id == DISCRIMINATOR_ID) { - const DDS::ExtensibilityKind ek = descriptor->extensibility_kind(); if (ek == DDS::APPENDABLE || ek == DDS::MUTABLE) { if (!strm_.skip_delimiter()) { return DDS::RETCODE_ERROR; } } - member_type = get_base_type(descriptor->discriminator_type()); + member_type = get_base_type(type_desc_->discriminator_type()); } else { DDS::MemberDescriptor_var md = get_from_union_common_checks(id, "get_value_from_union"); if (!md) { @@ -942,7 +1001,7 @@ DDS::ReturnCode_t DynamicDataXcdrReadImpl::get_value_from_union( return DDS::RETCODE_ERROR; } - if (descriptor->extensibility_kind() == DDS::MUTABLE) { + if (ek == DDS::MUTABLE) { unsigned member_id; size_t member_size; bool must_understand; @@ -967,15 +1026,10 @@ DDS::ReturnCode_t DynamicDataXcdrReadImpl::get_value_from_union( bool DynamicDataXcdrReadImpl::skip_to_sequence_element(MemberId id, DDS::DynamicType_ptr coll_type) { - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return false; - } - DDS::DynamicType_var elem_type; bool skip_all = false; if (!coll_type) { - elem_type = get_base_type(descriptor->element_type()); + elem_type = get_base_type(type_desc_->element_type()); } else { DDS::TypeDescriptor_var descriptor; if (coll_type->get_descriptor(descriptor) != DDS::RETCODE_OK) { @@ -1011,28 +1065,18 @@ bool DynamicDataXcdrReadImpl::skip_to_sequence_element(MemberId id, DDS::Dynamic bool DynamicDataXcdrReadImpl::skip_to_array_element(MemberId id, DDS::DynamicType_ptr coll_type) { - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return false; - } - - DDS::DynamicType_var elem_type; bool skip_all = false; DDS::TypeDescriptor_var coll_descriptor; if (!coll_type) { - elem_type = get_base_type(descriptor->element_type()); - coll_type = type_; - if (coll_type->get_descriptor(coll_descriptor) != DDS::RETCODE_OK) { - return false; - } + coll_descriptor = type_desc_; } else { if (coll_type->get_descriptor(coll_descriptor) != DDS::RETCODE_OK) { return false; } - elem_type = get_base_type(coll_descriptor->element_type()); skip_all = true; } + DDS::DynamicType_var elem_type = get_base_type(coll_descriptor->element_type()); const ACE_CDR::ULong length = bound_total(coll_descriptor); @@ -1061,13 +1105,8 @@ bool DynamicDataXcdrReadImpl::skip_to_array_element(MemberId id, DDS::DynamicTyp bool DynamicDataXcdrReadImpl::skip_to_map_element(MemberId id) { - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return false; - } - - const DDS::DynamicType_var key_type = get_base_type(descriptor->key_element_type()); - const DDS::DynamicType_var elem_type = get_base_type(descriptor->element_type()); + const DDS::DynamicType_var key_type = get_base_type(type_desc_->key_element_type()); + const DDS::DynamicType_var elem_type = get_base_type(type_desc_->element_type()); ACE_CDR::ULong key_size, elem_size; if (get_primitive_size(key_type, key_size) && @@ -1104,12 +1143,7 @@ template bool DynamicDataXcdrReadImpl::get_value_from_collection(ElementType& value, MemberId id, TypeKind collection_tk, TypeKind enum_or_bitmask, LBound lower, LBound upper) { - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return false; - } - - DDS::DynamicType_var elem_type = get_base_type(descriptor->element_type()); + DDS::DynamicType_var elem_type = get_base_type(type_desc_->element_type()); const TypeKind elem_tk = elem_type->get_kind(); if (elem_tk != ElementTypeKind && elem_tk != enum_or_bitmask) { @@ -1184,11 +1218,7 @@ DDS::ReturnCode_t DynamicDataXcdrReadImpl::get_single_value(ValueType& value, Me // accessed with MEMBER_ID_INVALID Id. However, there is only a single value in such // a DynamicData object, and checking for MEMBER_ID_INVALID from the input is perhaps // unnecessary. So, we read the value immediately here. - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return DDS::RETCODE_ERROR; - } - const LBound bit_bound = descriptor->bound()[0]; + const LBound bit_bound = type_desc_->bound()[0]; good = bit_bound >= lower && bit_bound <= upper && read_value(value, ValueTypeKind); } else { switch (tk) { @@ -1418,11 +1448,7 @@ DDS::ReturnCode_t DynamicDataXcdrReadImpl::get_boolean_value(ACE_CDR::Boolean& v break; case TK_BITMASK: { - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return DDS::RETCODE_ERROR; - } - const LBound bit_bound = descriptor->bound()[0]; + const LBound bit_bound = type_desc_->bound()[0]; ACE_CDR::ULong index; if (!get_index_from_id(id, index, bit_bound)) { if (DCPS::DCPS_debug_level >= 1) { @@ -1515,11 +1541,6 @@ DDS::ReturnCode_t DynamicDataXcdrReadImpl::get_complex_value(DDS::DynamicData_pt { ScopedChainManager chain_manager(*this); - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return DDS::RETCODE_ERROR; - } - const TypeKind tk = type_->get_kind(); bool good = true; @@ -1564,16 +1585,17 @@ DDS::ReturnCode_t DynamicDataXcdrReadImpl::get_complex_value(DDS::DynamicData_pt break; } + const DDS::ExtensibilityKind ek = type_desc_->extensibility_kind(); if (id == DISCRIMINATOR_ID) { - if (descriptor->extensibility_kind() == DDS::APPENDABLE || descriptor->extensibility_kind() == DDS::MUTABLE) { + if (ek == DDS::APPENDABLE || ek == DDS::MUTABLE) { if (!strm_.skip_delimiter()) { good = false; break; } } - const DDS::DynamicType_var disc_type = get_base_type(descriptor->discriminator_type()); - if (descriptor->extensibility_kind() == DDS::MUTABLE) { + const DDS::DynamicType_var disc_type = get_base_type(type_desc_->discriminator_type()); + if (ek == DDS::MUTABLE) { unsigned id; size_t size; bool must_understand; @@ -1593,7 +1615,7 @@ DDS::ReturnCode_t DynamicDataXcdrReadImpl::get_complex_value(DDS::DynamicData_pt break; } - if (descriptor->extensibility_kind() == DDS::MUTABLE) { + if (ek == DDS::MUTABLE) { unsigned id; size_t size; bool must_understand; @@ -1621,7 +1643,7 @@ DDS::ReturnCode_t DynamicDataXcdrReadImpl::get_complex_value(DDS::DynamicData_pt good = false; } else { CORBA::release(value); - value = new DynamicDataXcdrReadImpl(strm_, descriptor->element_type(), nested(extent_)); + value = new DynamicDataXcdrReadImpl(strm_, type_desc_->element_type(), nested(extent_)); } break; } @@ -1795,12 +1817,7 @@ bool DynamicDataXcdrReadImpl::get_values_from_union(SequenceType& value, MemberI return false; } - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return false; - } - - if (descriptor->extensibility_kind() == DDS::MUTABLE) { + if (type_desc_->extensibility_kind() == DDS::MUTABLE) { unsigned member_id; size_t member_size; bool must_understand; @@ -1813,8 +1830,6 @@ bool DynamicDataXcdrReadImpl::get_values_from_union(SequenceType& value, MemberI return read_values(value, ElementTypeKind); } - // Reset. - td = 0; if (elem_type->get_descriptor(td) != DDS::RETCODE_OK) { return false; } @@ -1826,12 +1841,7 @@ template bool DynamicDataXcdrReadImpl::get_values_from_sequence(SequenceType& value, MemberId id, TypeKind enum_or_bitmask, LBound lower, LBound upper) { - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return false; - } - - const DDS::DynamicType_var elem_type = get_base_type(descriptor->element_type()); + const DDS::DynamicType_var elem_type = get_base_type(type_desc_->element_type()); const TypeKind elem_tk = elem_type->get_kind(); if (elem_tk == ElementTypeKind) { @@ -1878,12 +1888,7 @@ template bool DynamicDataXcdrReadImpl::get_values_from_array(SequenceType& value, MemberId id, TypeKind enum_or_bitmask, LBound lower, LBound upper) { - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return false; - } - - const DDS::DynamicType_var elem_type = get_base_type(descriptor->element_type()); + const DDS::DynamicType_var elem_type = get_base_type(type_desc_->element_type()); if (elem_type->get_kind() != TK_SEQUENCE) { if (DCPS::DCPS_debug_level >= 1) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) DynamicDataXcdrReadImpl::get_values_from_array -") @@ -1923,12 +1928,7 @@ template bool DynamicDataXcdrReadImpl::get_values_from_map(SequenceType& value, MemberId id, TypeKind enum_or_bitmask, LBound lower, LBound upper) { - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return false; - } - - const DDS::DynamicType_var elem_type = get_base_type(descriptor->element_type()); + const DDS::DynamicType_var elem_type = get_base_type(type_desc_->element_type()); if (elem_type->get_kind() != TK_SEQUENCE) { if (DCPS::DCPS_debug_level >= 1) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) DynamicDataXcdrReadImpl::get_values_from_map -") @@ -2130,13 +2130,7 @@ CORBA::Boolean DynamicDataXcdrReadImpl::equals(DDS::DynamicData_ptr) DDS::ReturnCode_t DynamicDataXcdrReadImpl::skip_to_struct_member(DDS::MemberDescriptor* member_desc, MemberId id) { - DDS::TypeDescriptor_var descriptor; - DDS::ReturnCode_t rc = type_->get_descriptor(descriptor); - if (rc != DDS::RETCODE_OK) { - return rc; - } - - const DDS::ExtensibilityKind ek = descriptor->extensibility_kind(); + const DDS::ExtensibilityKind ek = type_desc_->extensibility_kind(); if (ek == DDS::FINAL || ek == DDS::APPENDABLE) { size_t dheader = 0; const bool xcdr2_appendable = encoding_.xcdr_version() == DCPS::Encoding::XCDR_VERSION_2 && @@ -2152,7 +2146,7 @@ DDS::ReturnCode_t DynamicDataXcdrReadImpl::skip_to_struct_member(DDS::MemberDesc for (ACE_CDR::ULong i = 0; i < member_desc->index(); ++i) { DDS::DynamicTypeMember_var dtm; - rc = type_->get_member_by_index(dtm, i); + DDS::ReturnCode_t rc = type_->get_member_by_index(dtm, i); if (rc != DDS::RETCODE_OK) { if (DCPS::log_level >= DCPS::LogLevel::Notice) { ACE_ERROR((LM_NOTICE, "(%P|%t) NOTICE: DynamicDataXcdrReadImpl::skip_to_struct_member:" @@ -2695,17 +2689,12 @@ bool DynamicDataXcdrReadImpl::read_discriminator(const DDS::DynamicType_ptr disc bool DynamicDataXcdrReadImpl::skip_all() { - DDS::TypeDescriptor_var descriptor; - if (type_->get_descriptor(descriptor) != DDS::RETCODE_OK) { - return false; - } - const TypeKind tk = type_->get_kind(); if (tk != TK_STRUCTURE && tk != TK_UNION) { return false; } - const DDS::ExtensibilityKind extensibility = descriptor->extensibility_kind(); + const DDS::ExtensibilityKind extensibility = type_desc_->extensibility_kind(); if (strm_.encoding().kind() == DCPS::Encoding::KIND_XCDR2 && (extensibility == DDS::APPENDABLE || extensibility == DDS::MUTABLE)) { size_t dheader; if (!strm_.read_delimiter(dheader)) { @@ -2729,7 +2718,7 @@ bool DynamicDataXcdrReadImpl::skip_all() } return good; } else { // Union - const DDS::DynamicType_var disc_type = get_base_type(descriptor->discriminator_type()); + const DDS::DynamicType_var disc_type = get_base_type(type_desc_->discriminator_type()); ACE_CDR::Long label; if (!read_discriminator(disc_type, extensibility, label)) { return false; diff --git a/dds/DCPS/XTypes/DynamicDataXcdrReadImpl.h b/dds/DCPS/XTypes/DynamicDataXcdrReadImpl.h index 922db7fcaca..6a20132eb41 100644 --- a/dds/DCPS/XTypes/DynamicDataXcdrReadImpl.h +++ b/dds/DCPS/XTypes/DynamicDataXcdrReadImpl.h @@ -26,6 +26,7 @@ class OpenDDS_Dcps_Export DynamicDataXcdrReadImpl : public DynamicDataBase { /// This creates a duplicated ACE_Message_Block chain from the provided chain. /// The duplicated chain is released when the object is destroyed. Caller is /// responsible for the release of the input message block chain. + /// The provided DynamicType must be the type for the data in the message block. DynamicDataXcdrReadImpl(ACE_Message_Block* chain, const DCPS::Encoding& encoding, DDS::DynamicType_ptr type, @@ -34,6 +35,7 @@ class OpenDDS_Dcps_Export DynamicDataXcdrReadImpl : public DynamicDataBase { /// Use this when you want to pass the alignment state of a given Serializer object over. /// A typical use case would be when a part of the data has already been consumed from /// @a ser and you want to give the remaining to DynamicData. + /// The provided DynamicType must be the type for the data in the message block. DynamicDataXcdrReadImpl(DCPS::Serializer& ser, DDS::DynamicType_ptr type, DCPS::Sample::Extent ext = DCPS::Sample::Full); @@ -377,6 +379,9 @@ class OpenDDS_Dcps_Export DynamicDataXcdrReadImpl : public DynamicDataBase { void copy(const DynamicDataXcdrReadImpl& other); + bool get_struct_item_count(); + bool get_union_item_count(); + /// Skip the whole data corresponding to this type if it is a struct or union. /// This is called by a containing type when it wants to skip a member which /// is an object of this type.