Cleanup IM (#12606)
--Move ConstructCommandPath function into CommandPathIB, update all usage across the codes.
--Use reference delcartion for usages on all Create* functions from IM MessageDef, update all usage across the code.
--Update the missing error-check for IM messageDef.
diff --git a/src/app/AttributeAccessInterface.h b/src/app/AttributeAccessInterface.h
index 9f7cca7..796f7b6 100644
--- a/src/app/AttributeAccessInterface.h
+++ b/src/app/AttributeAccessInterface.h
@@ -68,21 +68,17 @@
/**
* FinishAttribute encodes the "footer" part of an attribute report (it closes the containers opened in PrepareAttribute)
*/
- CHIP_ERROR FinishAttribute();
+ CHIP_ERROR FinishAttribute(AttributeReportIBs::Builder & aAttributeReportIBs);
/**
* EncodeValue encodes the value field of the report, it should be called exactly once.
*/
template <typename... Ts>
- CHIP_ERROR EncodeValue(Ts... aArgs)
+ CHIP_ERROR EncodeValue(AttributeReportIBs::Builder & aAttributeReportIBs, Ts... aArgs)
{
- return DataModel::Encode(*mAttributeDataIBBuilder.GetWriter(), TLV::ContextTag(to_underlying(AttributeDataIB::Tag::kData)),
- std::forward<Ts>(aArgs)...);
+ return DataModel::Encode(*(aAttributeReportIBs.GetAttributeReport().GetAttributeData().GetWriter()),
+ TLV::ContextTag(to_underlying(AttributeDataIB::Tag::kData)), std::forward<Ts>(aArgs)...);
}
-
-private:
- AttributeReportIB::Builder mAttributeReportIBBuilder;
- AttributeDataIB::Builder mAttributeDataIBBuilder;
};
/**
@@ -252,9 +248,9 @@
AttributeReportBuilder builder;
ReturnErrorOnFailure(builder.PrepareAttribute(mAttributeReportIBsBuilder, mPath, mDataVersion));
- ReturnErrorOnFailure(builder.EncodeValue(std::forward<Ts>(aArgs)...));
+ ReturnErrorOnFailure(builder.EncodeValue(mAttributeReportIBsBuilder, std::forward<Ts>(aArgs)...));
- return builder.FinishAttribute();
+ return builder.FinishAttribute(mAttributeReportIBsBuilder);
}
/**