Skip to content

Commit

Permalink
Add a way to read a concrete attribute path from AttributePathIB::Par…
Browse files Browse the repository at this point in the history
…ser.

Fixes #14934
  • Loading branch information
bzbarsky-apple committed Feb 23, 2023
1 parent 7775bec commit 280d4d1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 36 deletions.
13 changes: 12 additions & 1 deletion src/app/MessageDef/AttributePathIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@ CHIP_ERROR AttributePathIB::Parser::GetListIndex(DataModel::Nullable<ListIndex>
return GetNullableUnsignedInteger(to_underlying(Tag::kListIndex), apListIndex);
}

CHIP_ERROR AttributePathIB::Parser::GetListIndex(ConcreteDataAttributePath & aAttributePath) const
CHIP_ERROR AttributePathIB::Parser::GetGroupAttributePath(ConcreteDataAttributePath & aAttributePath) const
{
ReturnErrorOnFailure(GetCluster(&aAttributePath.mClusterId));
ReturnErrorOnFailure(GetAttribute(&aAttributePath.mAttributeId));

CHIP_ERROR err = CHIP_NO_ERROR;
DataModel::Nullable<ListIndex> listIndex;
err = GetListIndex(&(listIndex));
Expand All @@ -198,6 +201,14 @@ CHIP_ERROR AttributePathIB::Parser::GetListIndex(ConcreteDataAttributePath & aAt
return err;
}

CHIP_ERROR AttributePathIB::Parser::GetConcreteAttributePath(ConcreteDataAttributePath & aAttributePath) const
{
ReturnErrorOnFailure(GetGroupAttributePath(aAttributePath));

// And now read our endpoint.
return GetEndpoint(&aAttributePath.mEndpointId);
}

CHIP_ERROR AttributePathIB::Parser::ParsePath(AttributePathParams & aAttribute) const
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down
21 changes: 17 additions & 4 deletions src/app/MessageDef/AttributePathIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,27 @@ class Parser : public ListParser
CHIP_ERROR GetListIndex(DataModel::Nullable<ListIndex> * const apListIndex) const;

/**
* @brief Get the ListIndex, and set the mListIndex and mListOp fields in the ConcreteDataAttributePath accordingly. It will set
* ListOp to NotList when the list index is missing, users should interpret it as ReplaceAll according to the context.
* @brief Get the concrete attribute path. This will set the ListOp to
* NotList when there is no ListIndex. Consumers should interpret NotList
* as ReplaceAll if that's appropriate to their context.
*
* @param [in] aAttributePath The attribute path object for setting list index and list op.
* @param [in] aAttributePath The attribute path object to write to.
*
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR GetListIndex(ConcreteDataAttributePath & aAttributePath) const;
CHIP_ERROR GetConcreteAttributePath(ConcreteDataAttributePath & aAttributePath) const;

/**
* @brief Get a group attribute path. This will set the ListOp to
* NotList when there is no ListIndex. Consumers should interpret NotList
* as ReplaceAll if that's appropriate to their context. The
* endpoint id of the resulting path might have any value.
*
* @param [in] aAttributePath The attribute path object to write to.
*
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR GetGroupAttributePath(ConcreteDataAttributePath & aAttributePath) const;

// TODO(#14934) Add a function to get ConcreteDataAttributePath from AttributePathIB::Parser directly.

Expand Down
8 changes: 1 addition & 7 deletions src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,7 @@ CHIP_ERROR ReadClient::ProcessAttributePath(AttributePathIB::Parser & aAttribute
{
CHIP_ERROR err = CHIP_NO_ERROR;
// The ReportData must contain a concrete attribute path
err = aAttributePathParser.GetEndpoint(&(aAttributePath.mEndpointId));
VerifyOrReturnError(err == CHIP_NO_ERROR, CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB);
err = aAttributePathParser.GetCluster(&(aAttributePath.mClusterId));
VerifyOrReturnError(err == CHIP_NO_ERROR, CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB);
err = aAttributePathParser.GetAttribute(&(aAttributePath.mAttributeId));
VerifyOrReturnError(err == CHIP_NO_ERROR, CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB);
err = aAttributePathParser.GetListIndex(aAttributePath);
err = aAttributePathParser.GetConcreteAttributePath(aAttributePath);
VerifyOrReturnError(err == CHIP_NO_ERROR, CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB);
return CHIP_NO_ERROR;
}
Expand Down
8 changes: 1 addition & 7 deletions src/app/WriteClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,7 @@ CHIP_ERROR WriteClient::ProcessAttributeStatusIB(AttributeStatusIB::Parser & aAt
err = aAttributeStatusIB.GetPath(&attributePathParser);
SuccessOrExit(err);

err = attributePathParser.GetCluster(&(attributePath.mClusterId));
SuccessOrExit(err);
err = attributePathParser.GetEndpoint(&(attributePath.mEndpointId));
SuccessOrExit(err);
err = attributePathParser.GetAttribute(&(attributePath.mAttributeId));
SuccessOrExit(err);
err = attributePathParser.GetListIndex(attributePath);
err = attributePathParser.GetConcreteAttributePath(attributePath);
SuccessOrExit(err);

err = aAttributeStatusIB.GetErrorStatus(&(StatusIBParser));
Expand Down
19 changes: 2 additions & 17 deletions src/app/WriteHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,7 @@ CHIP_ERROR WriteHandler::ProcessAttributeDataIBs(TLV::TLVReader & aAttributeData
err = element.GetPath(&attributePath);
SuccessOrExit(err);

err = attributePath.GetEndpoint(&(dataAttributePath.mEndpointId));
SuccessOrExit(err);

err = attributePath.GetCluster(&(dataAttributePath.mClusterId));
SuccessOrExit(err);

err = attributePath.GetAttribute(&(dataAttributePath.mAttributeId));
SuccessOrExit(err);

err = attributePath.GetListIndex(dataAttributePath);
err = attributePath.GetConcreteAttributePath(dataAttributePath);
SuccessOrExit(err);

err = element.GetData(&dataReader);
Expand Down Expand Up @@ -407,13 +398,7 @@ CHIP_ERROR WriteHandler::ProcessGroupAttributeDataIBs(TLV::TLVReader & aAttribut
err = element.GetPath(&attributePath);
SuccessOrExit(err);

err = attributePath.GetCluster(&(dataAttributePath.mClusterId));
SuccessOrExit(err);

err = attributePath.GetAttribute(&(dataAttributePath.mAttributeId));
SuccessOrExit(err);

err = attributePath.GetListIndex(dataAttributePath);
err = attributePath.GetGroupAttributePath(dataAttributePath);
SuccessOrExit(err);

err = element.GetData(&dataReader);
Expand Down

0 comments on commit 280d4d1

Please sign in to comment.