diff --git a/src/app/MessageDef/AttributePathIB.cpp b/src/app/MessageDef/AttributePathIB.cpp index bc79aa1c170789..90d6ea5a6225b2 100644 --- a/src/app/MessageDef/AttributePathIB.cpp +++ b/src/app/MessageDef/AttributePathIB.cpp @@ -171,8 +171,11 @@ CHIP_ERROR AttributePathIB::Parser::GetListIndex(DataModel::Nullable 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; err = GetListIndex(&(listIndex)); @@ -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; diff --git a/src/app/MessageDef/AttributePathIB.h b/src/app/MessageDef/AttributePathIB.h index 0f7fb623ae44ea..906fd319a4113f 100644 --- a/src/app/MessageDef/AttributePathIB.h +++ b/src/app/MessageDef/AttributePathIB.h @@ -131,14 +131,27 @@ class Parser : public ListParser CHIP_ERROR GetListIndex(DataModel::Nullable * 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. diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index 5a24bbbefb1d4f..cbd131f288c3b0 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -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; } diff --git a/src/app/WriteClient.cpp b/src/app/WriteClient.cpp index c29242d7a146fa..42992f42e8ee50 100644 --- a/src/app/WriteClient.cpp +++ b/src/app/WriteClient.cpp @@ -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)); diff --git a/src/app/WriteHandler.cpp b/src/app/WriteHandler.cpp index 1e5343432a3709..b4dca470a33219 100644 --- a/src/app/WriteHandler.cpp +++ b/src/app/WriteHandler.cpp @@ -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); @@ -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);