Skip to content

Commit

Permalink
Merge pull request OpenDDS#4278 from sonndinh/dynamicdata-backing-store
Browse files Browse the repository at this point in the history
Unified DynamicData implementation for both reader and writer
  • Loading branch information
jrw972 authored Dec 5, 2023
2 parents 5db6ef2 + a3dc62d commit d3ba55b
Show file tree
Hide file tree
Showing 12 changed files with 3,604 additions and 5,771 deletions.
81 changes: 3 additions & 78 deletions dds/DCPS/XTypes/DynamicDataBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,51 +301,6 @@ DDS::MemberId DynamicDataBase::get_union_default_member(DDS::DynamicType* type)
return default_branch;
}

DDS::ReturnCode_t DynamicDataBase::get_selected_union_branch(DDS::Int32 disc,
bool& found_selected_member, DDS::MemberDescriptor_var& selected_md) const
{
found_selected_member = false;
bool has_default = false;
DDS::ReturnCode_t rc = DDS::RETCODE_OK;
DDS::MemberDescriptor_var default_md;
for (DDS::UInt32 i = 0; i < type_->get_member_count(); ++i) {
DDS::DynamicTypeMember_var dtm;
rc = type_->get_member_by_index(dtm, i);
if (rc != DDS::RETCODE_OK) {
return rc;
}
if (dtm->get_id() == DISCRIMINATOR_ID) {
continue;
}
DDS::MemberDescriptor_var md;
rc = dtm->get_descriptor(md);
if (rc != DDS::RETCODE_OK) {
return rc;
}
bool found_matched_label = false;
const DDS::UnionCaseLabelSeq labels = md->label();
for (DDS::UInt32 j = 0; !found_matched_label && j < labels.length(); ++j) {
if (disc == labels[j]) {
found_matched_label = true;
}
}
if (found_matched_label) {
selected_md = md;
found_selected_member = true;
break;
}
if (md->is_default_label()) {
default_md = md;
has_default = true;
}
}
if (!found_selected_member && has_default) {
selected_md = default_md;
found_selected_member = true;
}
return rc;
}

DDS::ReturnCode_t DynamicDataBase::get_selected_union_branch(
bool& found_selected_member, DDS::MemberDescriptor_var& selected_md)
{
Expand All @@ -362,14 +317,15 @@ DDS::ReturnCode_t DynamicDataBase::get_selected_union_branch(
}
return DDS::RETCODE_ERROR;
}
return get_selected_union_branch(static_cast<DDS::Int32>(i64_disc), found_selected_member, selected_md);
return XTypes::get_selected_union_branch(type_, static_cast<DDS::Int32>(i64_disc),
found_selected_member, selected_md);
}

bool DynamicDataBase::discriminator_selects_no_member(DDS::Int32 disc) const
{
bool found_selected_member;
DDS::MemberDescriptor_var selected_md;
const DDS::ReturnCode_t rc = get_selected_union_branch(disc, found_selected_member, selected_md);
const DDS::ReturnCode_t rc = XTypes::get_selected_union_branch(type_, disc, found_selected_member, selected_md);
if (rc != DDS::RETCODE_OK) {
if (log_level >= LogLevel::Warning) {
ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: DynamicDataBase::discriminator_selects_no_member: "
Expand All @@ -380,37 +336,6 @@ bool DynamicDataBase::discriminator_selects_no_member(DDS::Int32 disc) const
return !found_selected_member;
}

bool DynamicDataBase::has_explicit_keys(DDS::DynamicType* dt)
{
// see dds_generator.h struct_has_explicit_keys() in opendds_idl
DDS::TypeDescriptor_var type_descriptor;
DDS::ReturnCode_t ret = dt->get_descriptor(type_descriptor);
if (ret != DDS::RETCODE_OK) {
return false;
}
DDS::DynamicType* const base = type_descriptor->base_type();
if (base && has_explicit_keys(base)) {
return true;
}

for (ACE_CDR::ULong i = 0; i < dt->get_member_count(); ++i) {
DDS::DynamicTypeMember_var member;
ret = dt->get_member_by_index(member, i);
if (ret != DDS::RETCODE_OK) {
return false;
}
DDS::MemberDescriptor_var descriptor;
ret = member->get_descriptor(descriptor);
if (ret != DDS::RETCODE_OK) {
return false;
}
if (descriptor->is_key()) {
return true;
}
}
return false;
}

DDS::ReturnCode_t DynamicDataBase::unsupported_method(const char* method_name, bool warning) const
{
if (log_level >= (warning ? LogLevel::Warning : LogLevel::Notice)) {
Expand Down
18 changes: 0 additions & 18 deletions dds/DCPS/XTypes/DynamicDataBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ class OpenDDS_Dcps_Export DynamicDataBase : public virtual DCPS::LocalObject<DDS
DDS::ReturnCode_t get_uint64_value(DDS::UInt64& value, DDS::MemberId id);
virtual DDS::ReturnCode_t get_uint64_value_impl(DDS::UInt64& value, DDS::MemberId id) = 0;

static bool has_explicit_keys(DDS::DynamicType* dt);
static bool exclude_member(DCPS::Sample::Extent ext, bool is_key, bool has_explicit_keys);
static DCPS::Sample::Extent nested(DCPS::Sample::Extent ext);

#ifndef OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE
virtual DDS::ReturnCode_t get_simple_value(DCPS::Value& value, DDS::MemberId id);
#endif
Expand Down Expand Up @@ -72,8 +68,6 @@ class OpenDDS_Dcps_Export DynamicDataBase : public virtual DCPS::LocalObject<DDS
}

static DDS::MemberId get_union_default_member(DDS::DynamicType* type);
DDS::ReturnCode_t get_selected_union_branch(
DDS::Int32 disc, bool& found_selected_member, DDS::MemberDescriptor_var& selected_md) const;
DDS::ReturnCode_t get_selected_union_branch(
bool& found_selected_member, DDS::MemberDescriptor_var& selected_md);
bool discriminator_selects_no_member(DDS::Int32 disc) const;
Expand All @@ -90,18 +84,6 @@ class OpenDDS_Dcps_Export DynamicDataBase : public virtual DCPS::LocalObject<DDS
DDS::TypeDescriptor_var type_desc_;
};

inline bool DynamicDataBase::exclude_member(DCPS::Sample::Extent ext, bool is_key, bool has_explicit_keys)
{
// see Fields::Iterator and explicit_keys_only() in opendds_idl's dds_generator.h
const bool explicit_keys_only = ext == DCPS::Sample::KeyOnly || (ext == DCPS::Sample::NestedKeyOnly && has_explicit_keys);
return explicit_keys_only && !is_key;
}

inline DCPS::Sample::Extent DynamicDataBase::nested(DCPS::Sample::Extent ext)
{
return ext == DCPS::Sample::KeyOnly ? DCPS::Sample::NestedKeyOnly : ext;
}

} // namespace XTypes
} // namespace OpenDDS

Expand Down
Loading

0 comments on commit d3ba55b

Please sign in to comment.