Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to read a concrete attribute path from AttributePathIB::Parser #25293

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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