Skip to content

Commit

Permalink
Remove duplicate path in IM Read
Browse files Browse the repository at this point in the history
Summary of Changes:
--Remove duplicate attribute paths if there are multiple overlapped path in read
attribute path for IM Read
--Add unit test for multiple overlapped path
  • Loading branch information
yunhanw-google committed Sep 1, 2021
1 parent 3bbbc69 commit 6a43ddd
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
34 changes: 34 additions & 0 deletions src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,40 @@ void InteractionModelEngine::ReleaseClusterInfoList(ClusterInfo *& aClusterInfo)
aClusterInfo = nullptr;
}

void InteractionModelEngine::ReleaseClearClusterInfoList(ClusterInfo *& aClusterInfo)
{
ClusterInfo * updateList = nullptr;
ClusterInfo * runner = aClusterInfo;
if (aClusterInfo == nullptr)
{
return;
}
while (runner != nullptr)
{
ClusterInfo * next = runner->mpNext;
if (runner->IsDirty())
{
if (updateList != nullptr)
{
runner->mpNext = updateList;
updateList = runner;
}
else
{
updateList = runner;
}
}
else
{
runner->mpNext = mpNextAvailableClusterInfo;
mpNextAvailableClusterInfo = runner;
}
runner = next;
}

aClusterInfo = updateList;
}

CHIP_ERROR InteractionModelEngine::PushFront(ClusterInfo *& aClusterInfoList, ClusterInfo & aClusterInfo)
{
ClusterInfo * last = aClusterInfoList;
Expand Down
3 changes: 2 additions & 1 deletion src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ class InteractionModelEngine : public Messaging::ExchangeDelegate
reporting::Engine & GetReportingEngine() { return mReportingEngine; }

void ReleaseClusterInfoList(ClusterInfo *& aClusterInfo);
CHIP_ERROR PushFront(ClusterInfo *& aClusterInfoLisst, ClusterInfo & aClusterInfo);
CHIP_ERROR PushFront(ClusterInfo *& aClusterInfoList, ClusterInfo & aClusterInfo);
void ReleaseClearClusterInfoList(ClusterInfo *& aClusterInfo);

private:
friend class reporting::Engine;
Expand Down
28 changes: 28 additions & 0 deletions src/app/ReadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,39 @@ CHIP_ERROR ReadHandler::ProcessAttributePathList(AttributePathList::Parser & aAt
err = CHIP_NO_ERROR;
}

FilterOverlappedPath(mpAttributeClusterInfoList);

exit:
ChipLogFunctError(err);
return err;
}

void ReadHandler::FilterOverlappedPath(ClusterInfo *& aClusterInfoList)
{
ClusterInfo * runner1 = aClusterInfoList;
ClusterInfo * runner2 = aClusterInfoList;
while (runner1 != nullptr)
{
runner2 = aClusterInfoList;
while (runner2 != nullptr)
{
if (runner1 == runner2)
{
runner2 = runner2->mpNext;
continue;
}
if (runner2->IsAttributePathSupersetOf(*runner1))
{
runner1->ClearDirty();
break;
}
runner2 = runner2->mpNext;
}
runner1 = runner1->mpNext;
}
InteractionModelEngine::GetInstance()->ReleaseClearClusterInfoList(aClusterInfoList);
}

CHIP_ERROR ReadHandler::ProcessEventPathList(EventPathList::Parser & aEventPathListParser)
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down
1 change: 1 addition & 0 deletions src/app/ReadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class ReadHandler : public Messaging::ExchangeDelegate
void MoveToState(const HandlerState aTargetState);

const char * GetStateStr() const;
void FilterOverlappedPath(ClusterInfo *& aClusterInfoList);

Messaging::ExchangeContext * mpExchangeCtx = nullptr;

Expand Down
10 changes: 9 additions & 1 deletion src/app/tests/TestReadInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,20 @@ void TestReadInteraction::TestReadRoundtrip(nlTestSuite * apSuite, void * apCont
attributePathParams[0].mListIndex = 0;
attributePathParams[0].mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);

attributePathParams[1].mNodeId = chip::kTestDeviceNodeId;
attributePathParams[1].mEndpointId = kTestEndpointId;
attributePathParams[1].mClusterId = kTestClusterId;
attributePathParams[1].mFieldId = 1;
attributePathParams[1].mListIndex = 1;
attributePathParams[1].mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
attributePathParams[1].mFlags.Set(chip::app::AttributePathParams::Flags::kListIndexValid);

ReadPrepareParams readPrepareParams;
readPrepareParams.mSessionHandle = ctx.GetSessionLocalToPeer();
readPrepareParams.mpEventPathParamsList = eventPathParams;
readPrepareParams.mEventPathParamsListSize = 2;
readPrepareParams.mpAttributePathParamsList = attributePathParams;
readPrepareParams.mAttributePathParamsListSize = 1;
readPrepareParams.mAttributePathParamsListSize = 2;
err = chip::app::InteractionModelEngine::GetInstance()->SendReadRequest(readPrepareParams);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

Expand Down

0 comments on commit 6a43ddd

Please sign in to comment.