Skip to content

Commit

Permalink
change
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google committed May 19, 2022
1 parent 4ba6d4f commit 5d49116
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/app/AttributePathParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ struct AttributePathParams
return true;
}

bool IsAttributePathOverlapped(const AttributePathParams & other) const
{
VerifyOrReturnError(HasWildcardEndpointId() || other.HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false);
VerifyOrReturnError(HasWildcardClusterId() || other.HasWildcardClusterId() || mClusterId == other.mClusterId, false);
VerifyOrReturnError(HasWildcardAttributeId() || other.HasWildcardAttributeId() || mAttributeId == other.mAttributeId, false);
return true;
}

bool IncludesAttributesInCluster(const DataVersionFilter & other) const
{
VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false);
Expand Down
26 changes: 26 additions & 0 deletions src/app/ClusterStateCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,32 @@ CHIP_ERROR ClusterStateCache::OnUpdateDataVersionFilterList(DataVersionFilterIBs
}
}

for (auto & attribute1 : aAttributePaths)
{
if (attribute1.HasWildcardAttributeId())
{
continue;
}

auto attribute2 = std::begin(mRequestPathSet);
while (attribute2 != std::end(mRequestPathSet))
{
if (attribute1.IsAttributePathOverlapped(*attribute2))
{
ChipLogError(InteractionModel, "overlapped");
attribute2 = mRequestPathSet.erase(attribute2);
}
else
{
ChipLogError(InteractionModel, "!overlapped");
++attribute2;
}
}
}

ChipLogError(InteractionModel, "debug how many %lu", mRequestPathSet.size());


std::vector<std::pair<DataVersionFilter, size_t>> filterVector;
GetSortedFilters(filterVector);

Expand Down
38 changes: 38 additions & 0 deletions src/controller/tests/data_model/TestRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,44 @@ void TestReadInteraction::TestReadSubscribeAttributeResponseWithCache(nlTestSuit
app::InteractionModelEngine::GetInstance()->RegisterReadHandlerAppCallback(&gTestReadInteraction);

int testId = 0;

// Read of E2C3A1, E*C3A1(1 supported attribute in E1C3A1), E2C3A* (3 supported attributes)
// Expect no versions would be cached.
{
testId++;
ChipLogProgress(DataManagement, "\t -- Running Read with ClusterStateCache Test ID %d", testId);
app::ReadClient readClient(chip::app::InteractionModelEngine::GetInstance(), &ctx.GetExchangeManager(),
cache.GetBufferedCallback(), chip::app::ReadClient::InteractionType::Read);
chip::app::AttributePathParams attributePathParams1[3];
attributePathParams1[0].mEndpointId = Test::kMockEndpoint2;
attributePathParams1[0].mClusterId = Test::MockClusterId(3);
attributePathParams1[0].mAttributeId = Test::MockAttributeId(1);

attributePathParams1[1].mEndpointId = kInvalidEndpointId;
attributePathParams1[1].mClusterId = Test::MockClusterId(3);
attributePathParams1[1].mAttributeId = Test::MockAttributeId(1);

attributePathParams1[2].mEndpointId = Test::kMockEndpoint2;
attributePathParams1[2].mClusterId = Test::MockClusterId(3);
attributePathParams1[2].mAttributeId = kInvalidAttributeId;

readPrepareParams.mpAttributePathParamsList = attributePathParams1;
readPrepareParams.mAttributePathParamsListSize = 3;
err = readClient.SendRequest(readPrepareParams);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

ctx.DrainAndServiceIO();
NL_TEST_ASSERT(apSuite, delegate.mNumAttributeResponse == 4);
NL_TEST_ASSERT(apSuite, !delegate.mReadError);
Optional<DataVersion> version1;
NL_TEST_ASSERT(apSuite, cache.GetVersion(Test::kMockEndpoint1, Test::MockClusterId(3), version1) == CHIP_NO_ERROR);
NL_TEST_ASSERT(apSuite, !version1.HasValue());
Optional<DataVersion> version2;
NL_TEST_ASSERT(apSuite, cache.GetVersion(Test::kMockEndpoint2, Test::MockClusterId(3), version2) == CHIP_NO_ERROR);
NL_TEST_ASSERT(apSuite, !version2.HasValue());
delegate.mNumAttributeResponse = 0;
}

// Read of E2C3A1, E2C3A2 and E3C2A2.
// Expect no versions would be cached.
{
Expand Down

0 comments on commit 5d49116

Please sign in to comment.