Skip to content

Commit

Permalink
clearer logic that we handle all cases
Browse files Browse the repository at this point in the history
  • Loading branch information
andy31415 committed Jan 17, 2025
1 parent f38661b commit 1c19e1b
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/app/clusters/descriptor/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu

auto & endpointInfo = endpoints[idx];

if (endpointInfo.compositionPattern == DataModel::EndpointCompositionPattern::kFullFamily)
switch (endpointInfo.compositionPattern)
{
case DataModel::EndpointCompositionPattern::kFullFamily:
// encodes ALL endpoints that have the specified endpoint as a descendant
return aEncoder.EncodeList([&endpoints, endpoint](const auto & encoder) -> CHIP_ERROR {
for (auto & ep : endpoints.GetSpanValidForLifetime())
Expand All @@ -158,21 +159,24 @@ CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, Attribu
}
return CHIP_NO_ERROR;
});
}

// ASSERT we know all composition types and this should be tree:
// assert(endpointInfo.compositionPattern == DataModel::EndpointCompositionPattern::kTree)
return aEncoder.EncodeList([&endpoints, endpoint](const auto & encoder) -> CHIP_ERROR {
for (auto & ep : endpoints.GetSpanValidForLifetime())
{
if (ep.parentId != endpoint)
case DataModel::EndpointCompositionPattern::kTree:
return aEncoder.EncodeList([&endpoints, endpoint](const auto & encoder) -> CHIP_ERROR {
for (auto & ep : endpoints.GetSpanValidForLifetime())
{
continue;
if (ep.parentId != endpoint)
{
continue;
}
ReturnErrorOnFailure(encoder.Encode(ep.id));
}
ReturnErrorOnFailure(encoder.Encode(ep.id));
}
return CHIP_NO_ERROR;
});
return CHIP_NO_ERROR;
});
// NOTE: no default to enforce that we handle all possible composition patterns.
default:
// unreachable: all variants should be handled above
chipDie();
}
}

CHIP_ERROR DescriptorAttrAccess::ReadDeviceAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder)
Expand Down

0 comments on commit 1c19e1b

Please sign in to comment.