From cc616d4d91b7caafb0e2dfc467e674b4b1660658 Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Tue, 16 Nov 2021 05:03:34 -0800 Subject: [PATCH] Cleanup IM messagedef (#11811) Replace buidler/parser base with structBuilder/Parser for rest struct message. Replace ReturnLogErroronFailure and VerifyLogErrorOnFailure without log since CHIP_ERROR has recorded the initial error location. --- src/app/MessageDef/ArrayParser.cpp | 2 +- src/app/MessageDef/Builder.cpp | 18 +---- src/app/MessageDef/EventFilterIB.cpp | 4 +- src/app/MessageDef/InvokeRequestMessage.cpp | 8 -- src/app/MessageDef/InvokeRequestMessage.h | 9 --- src/app/MessageDef/ListParser.cpp | 2 +- src/app/MessageDef/ReadRequestMessage.cpp | 21 ----- src/app/MessageDef/ReadRequestMessage.h | 21 +---- src/app/MessageDef/StatusIB.cpp | 9 --- src/app/MessageDef/StatusIB.h | 9 --- src/app/MessageDef/StatusResponseMessage.cpp | 26 ++---- src/app/MessageDef/StatusResponseMessage.h | 13 +-- src/app/MessageDef/StructParser.cpp | 2 +- .../MessageDef/SubscribeRequestMessage.cpp | 81 ++++++++----------- src/app/MessageDef/SubscribeRequestMessage.h | 14 +--- .../MessageDef/SubscribeResponseMessage.cpp | 40 +++------ src/app/MessageDef/SubscribeResponseMessage.h | 14 +--- src/app/MessageDef/TimedRequestMessage.cpp | 16 +--- src/app/MessageDef/TimedRequestMessage.h | 14 +--- src/app/MessageDef/WriteRequestMessage.cpp | 20 ----- src/app/MessageDef/WriteRequestMessage.h | 26 +----- 21 files changed, 81 insertions(+), 288 deletions(-) diff --git a/src/app/MessageDef/ArrayParser.cpp b/src/app/MessageDef/ArrayParser.cpp index 93bba53ec55886..e7356c20a6eb02 100644 --- a/src/app/MessageDef/ArrayParser.cpp +++ b/src/app/MessageDef/ArrayParser.cpp @@ -24,7 +24,7 @@ CHIP_ERROR ArrayParser::Init(const TLV::TLVReader & aReader) { mReader.Init(aReader); VerifyOrReturnError(TLV::kTLVType_Array == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - ReturnLogErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); + ReturnErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); return CHIP_NO_ERROR; } } // namespace app diff --git a/src/app/MessageDef/Builder.cpp b/src/app/MessageDef/Builder.cpp index fed0811a34b19c..035c88b3a32509 100644 --- a/src/app/MessageDef/Builder.cpp +++ b/src/app/MessageDef/Builder.cpp @@ -54,25 +54,11 @@ void Builder::ResetError(CHIP_ERROR aErr) void Builder::EndOfContainer() { // skip if error has already been set - SuccessOrExit(mError); - - mError = mpWriter->EndContainer(mOuterContainerType); - SuccessOrExit(mError); - + ReturnOnFailure(mError); + ReturnOnFailure(mError = mpWriter->EndContainer(mOuterContainerType)); // we've just closed properly // mark it so we do not panic when the build object destructor is called mOuterContainerType = chip::TLV::kTLVType_NotSpecified; - -exit:; -} - -CHIP_ERROR Builder::InitAnonymousStructure(chip::TLV::TLVWriter * const apWriter) -{ - mpWriter = apWriter; - mOuterContainerType = chip::TLV::kTLVType_NotSpecified; - mError = mpWriter->StartContainer(chip::TLV::AnonymousTag, chip::TLV::kTLVType_Structure, mOuterContainerType); - - return mError; } } // namespace app } // namespace chip diff --git a/src/app/MessageDef/EventFilterIB.cpp b/src/app/MessageDef/EventFilterIB.cpp index 09786dce6b8fe1..8eab8ffa92d69b 100644 --- a/src/app/MessageDef/EventFilterIB.cpp +++ b/src/app/MessageDef/EventFilterIB.cpp @@ -57,7 +57,7 @@ CHIP_ERROR EventFilterIB::Parser::CheckSchemaValidity() const #if CHIP_DETAIL_LOGGING { NodeId node; - ReturnLogErrorOnFailure(reader.Get(node)); + ReturnErrorOnFailure(reader.Get(node)); PRETTY_PRINT("\tNode = 0x%" PRIx64 ",", node); } #endif // CHIP_DETAIL_LOGGING @@ -69,7 +69,7 @@ CHIP_ERROR EventFilterIB::Parser::CheckSchemaValidity() const #if CHIP_DETAIL_LOGGING { uint64_t eventMin; - ReturnLogErrorOnFailure(reader.Get(eventMin)); + ReturnErrorOnFailure(reader.Get(eventMin)); PRETTY_PRINT("\tEventMin = 0x%" PRIx64 ",", eventMin); } #endif // CHIP_DETAIL_LOGGING diff --git a/src/app/MessageDef/InvokeRequestMessage.cpp b/src/app/MessageDef/InvokeRequestMessage.cpp index 2ae9b3dc75f3ae..2c69d6a41cacaf 100644 --- a/src/app/MessageDef/InvokeRequestMessage.cpp +++ b/src/app/MessageDef/InvokeRequestMessage.cpp @@ -25,14 +25,6 @@ namespace chip { namespace app { -CHIP_ERROR InvokeRequestMessage::Parser::Init(const TLV::TLVReader & aReader) -{ - mReader.Init(aReader); - VerifyOrReturnError(TLV::kTLVType_Structure == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - ReturnErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); - return CHIP_NO_ERROR; -} - #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR InvokeRequestMessage::Parser::CheckSchemaValidity() const { diff --git a/src/app/MessageDef/InvokeRequestMessage.h b/src/app/MessageDef/InvokeRequestMessage.h index 2b25d33684246b..dcf3bdf4c0353c 100644 --- a/src/app/MessageDef/InvokeRequestMessage.h +++ b/src/app/MessageDef/InvokeRequestMessage.h @@ -41,15 +41,6 @@ enum class Tag : uint8_t class Parser : public StructParser { public: - /** - * @brief Initialize the parser object with TLVReader - * - * @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this request - * - * @return #CHIP_NO_ERROR on success - */ - CHIP_ERROR Init(const TLV::TLVReader & aReader); - #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK /** * @brief Roughly verify the message is correctly formed diff --git a/src/app/MessageDef/ListParser.cpp b/src/app/MessageDef/ListParser.cpp index 4d0b7fbdf6c42e..fce62c3143a6d9 100644 --- a/src/app/MessageDef/ListParser.cpp +++ b/src/app/MessageDef/ListParser.cpp @@ -24,7 +24,7 @@ CHIP_ERROR ListParser::Init(const TLV::TLVReader & aReader) { mReader.Init(aReader); VerifyOrReturnError(TLV::kTLVType_List == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - ReturnLogErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); + ReturnErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); return CHIP_NO_ERROR; } } // namespace app diff --git a/src/app/MessageDef/ReadRequestMessage.cpp b/src/app/MessageDef/ReadRequestMessage.cpp index f4de6dc301d712..efe0693b91b29b 100644 --- a/src/app/MessageDef/ReadRequestMessage.cpp +++ b/src/app/MessageDef/ReadRequestMessage.cpp @@ -33,22 +33,6 @@ using namespace chip::TLV; namespace chip { namespace app { -CHIP_ERROR ReadRequestMessage::Parser::Init(const chip::TLV::TLVReader & aReader) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - // make a copy of the reader here - mReader.Init(aReader); - - VerifyOrExit(chip::TLV::kTLVType_Structure == mReader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - err = mReader.EnterContainer(mOuterContainerType); - -exit: - - return err; -} - #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR ReadRequestMessage::Parser::CheckSchemaValidity() const { @@ -224,11 +208,6 @@ CHIP_ERROR ReadRequestMessage::Parser::GetEventNumber(uint64_t * const apEventNu return GetUnsignedInteger(kCsTag_EventNumber, apEventNumber); } -CHIP_ERROR ReadRequestMessage::Builder::Init(chip::TLV::TLVWriter * const apWriter) -{ - return InitAnonymousStructure(apWriter); -} - AttributePathIBs::Builder & ReadRequestMessage::Builder::CreateAttributePathListBuilder() { // skip if error has already been set diff --git a/src/app/MessageDef/ReadRequestMessage.h b/src/app/MessageDef/ReadRequestMessage.h index 98d61e69c49a39..b065ce4d317686 100644 --- a/src/app/MessageDef/ReadRequestMessage.h +++ b/src/app/MessageDef/ReadRequestMessage.h @@ -48,17 +48,9 @@ enum kCsTag_EventNumber = 3, }; -class Parser : public chip::app::Parser +class Parser : public StructParser { public: - /** - * @brief Initialize the parser object with TLVReader - * - * @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this request - * - * @return #CHIP_NO_ERROR on success - */ - CHIP_ERROR Init(const chip::TLV::TLVReader & aReader); #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK /** * @brief Roughly verify the message is correctly formed @@ -117,18 +109,9 @@ class Parser : public chip::app::Parser CHIP_ERROR GetEventNumber(uint64_t * const apEventNumber) const; }; -class Builder : public chip::app::Builder +class Builder : public StructBuilder { public: - /** - * @brief Initialize a ReadRequestMessage::Builder for writing into a TLV stream - * - * @param [in] apWriter A pointer to TLVWriter - * - * @return #CHIP_NO_ERROR on success - */ - CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter); - /** * @brief Initialize a AttributePathIBs::Builder for writing into the TLV stream * diff --git a/src/app/MessageDef/StatusIB.cpp b/src/app/MessageDef/StatusIB.cpp index 77f72c5e388005..e767157078a009 100644 --- a/src/app/MessageDef/StatusIB.cpp +++ b/src/app/MessageDef/StatusIB.cpp @@ -36,15 +36,6 @@ using namespace chip::TLV; namespace chip { namespace app { -CHIP_ERROR StatusIB::Parser::Init(const TLV::TLVReader & aReader) -{ - // make a copy of the reader here - mReader.Init(aReader); - VerifyOrReturnError(TLV::kTLVType_Structure == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - ReturnErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); - return CHIP_NO_ERROR; -} - CHIP_ERROR StatusIB::Parser::DecodeStatusIB(StatusIB & aStatusIB) const { TLV::TLVReader reader; diff --git a/src/app/MessageDef/StatusIB.h b/src/app/MessageDef/StatusIB.h index 679680815714b8..3c634a64063fc5 100644 --- a/src/app/MessageDef/StatusIB.h +++ b/src/app/MessageDef/StatusIB.h @@ -55,15 +55,6 @@ struct StatusIB class Parser : public StructParser { public: - /** - * @brief Initialize the parser object with TLVReader - * - * @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this StatusIB - * - * @return #CHIP_NO_ERROR on success - */ - CHIP_ERROR Init(const TLV::TLVReader & aReader); - #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK /** * @brief Roughly verify the message is correctly formed diff --git a/src/app/MessageDef/StatusResponseMessage.cpp b/src/app/MessageDef/StatusResponseMessage.cpp index 6462af1724cd3d..6eb0422c8980d0 100644 --- a/src/app/MessageDef/StatusResponseMessage.cpp +++ b/src/app/MessageDef/StatusResponseMessage.cpp @@ -19,15 +19,6 @@ namespace chip { namespace app { -CHIP_ERROR StatusResponseMessage::Parser::Init(const TLV::TLVReader & aReader) -{ - // make a copy of the reader here - mReader.Init(aReader); - VerifyOrReturnLogError(TLV::kTLVType_Structure == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - ReturnLogErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); - return CHIP_NO_ERROR; -} - #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR StatusResponseMessage::Parser::CheckSchemaValidity() const { @@ -42,23 +33,23 @@ CHIP_ERROR StatusResponseMessage::Parser::CheckSchemaValidity() const while (CHIP_NO_ERROR == (err = reader.Next())) { - VerifyOrReturnLogError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); switch (TLV::TagNumFromTag(reader.GetTag())) { case kCsTag_Status: - VerifyOrReturnLogError(!statusTagPresence, CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(!statusTagPresence, CHIP_ERROR_INVALID_TLV_TAG); statusTagPresence = true; - VerifyOrReturnLogError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { uint16_t status; - ReturnLogErrorOnFailure(reader.Get(status)); + ReturnErrorOnFailure(reader.Get(status)); PRETTY_PRINT("\tStatus = 0x%" PRIx16 ",", status); } #endif // CHIP_DETAIL_LOGGING break; default: - ReturnLogErrorOnFailure(CHIP_ERROR_INVALID_TLV_TAG); + ReturnErrorOnFailure(CHIP_ERROR_INVALID_TLV_TAG); } } PRETTY_PRINT("}"); @@ -68,7 +59,7 @@ CHIP_ERROR StatusResponseMessage::Parser::CheckSchemaValidity() const { err = CHIP_NO_ERROR; } - ReturnLogErrorOnFailure(err); + ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -81,11 +72,6 @@ CHIP_ERROR StatusResponseMessage::Parser::GetStatus(Protocols::InteractionModel: return err; } -CHIP_ERROR StatusResponseMessage::Builder::Init(TLV::TLVWriter * const apWriter) -{ - return InitAnonymousStructure(apWriter); -} - StatusResponseMessage::Builder & StatusResponseMessage::Builder::Status(const Protocols::InteractionModel::Status aStatus) { // skip if error has already been set diff --git a/src/app/MessageDef/StatusResponseMessage.h b/src/app/MessageDef/StatusResponseMessage.h index cfd217dcea0675..ecec0dd5479a21 100644 --- a/src/app/MessageDef/StatusResponseMessage.h +++ b/src/app/MessageDef/StatusResponseMessage.h @@ -16,8 +16,8 @@ */ #pragma once -#include "Builder.h" -#include "Parser.h" +#include "StructBuilder.h" +#include "StructParser.h" #include #include #include @@ -34,13 +34,9 @@ enum kCsTag_Status = 0, }; -class Parser : public app::Parser +class Parser : public StructParser { public: - /** - * @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this response - */ - CHIP_ERROR Init(const TLV::TLVReader & aReader); #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK /** * @brief Roughly verify the message is correctly formed @@ -67,10 +63,9 @@ class Parser : public app::Parser CHIP_ERROR GetStatus(Protocols::InteractionModel::Status & aStatus) const; }; -class Builder : public app::Builder +class Builder : public StructBuilder { public: - CHIP_ERROR Init(TLV::TLVWriter * const apWriter); StatusResponseMessage::Builder & Status(const Protocols::InteractionModel::Status aStatus); }; } // namespace StatusResponseMessage diff --git a/src/app/MessageDef/StructParser.cpp b/src/app/MessageDef/StructParser.cpp index 8b960b81e3e8da..3e78b631c59727 100644 --- a/src/app/MessageDef/StructParser.cpp +++ b/src/app/MessageDef/StructParser.cpp @@ -22,7 +22,7 @@ CHIP_ERROR StructParser::Init(const TLV::TLVReader & aReader) { mReader.Init(aReader); VerifyOrReturnError(TLV::kTLVType_Structure == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - ReturnLogErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); + ReturnErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); return CHIP_NO_ERROR; } } // namespace app diff --git a/src/app/MessageDef/SubscribeRequestMessage.cpp b/src/app/MessageDef/SubscribeRequestMessage.cpp index 41756364d4ecf8..d529ab644e3e37 100644 --- a/src/app/MessageDef/SubscribeRequestMessage.cpp +++ b/src/app/MessageDef/SubscribeRequestMessage.cpp @@ -19,16 +19,6 @@ namespace chip { namespace app { -CHIP_ERROR SubscribeRequestMessage::Parser::Init(const chip::TLV::TLVReader & aReader) -{ - // make a copy of the reader here - mReader.Init(aReader); - - VerifyOrReturnLogError(chip::TLV::kTLVType_Structure == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - ReturnLogErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); - return CHIP_NO_ERROR; -} - #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const { @@ -46,106 +36,106 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const while (CHIP_NO_ERROR == (err = reader.Next())) { - VerifyOrReturnLogError(chip::TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(chip::TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); switch (chip::TLV::TagNumFromTag(reader.GetTag())) { case kCsTag_AttributePathList: - VerifyOrReturnLogError(!(TagPresenceMask & (1 << kCsTag_AttributePathList)), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_AttributePathList)), CHIP_ERROR_INVALID_TLV_TAG); TagPresenceMask |= (1 << kCsTag_AttributePathList); - VerifyOrReturnLogError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); AttributePathIBs.Init(reader); PRETTY_PRINT_INCDEPTH(); - ReturnLogErrorOnFailure(AttributePathIBs.CheckSchemaValidity()); + ReturnErrorOnFailure(AttributePathIBs.CheckSchemaValidity()); PRETTY_PRINT_DECDEPTH(); break; case kCsTag_EventPaths: - VerifyOrReturnLogError(!(TagPresenceMask & (1 << kCsTag_EventPaths)), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_EventPaths)), CHIP_ERROR_INVALID_TLV_TAG); TagPresenceMask |= (1 << kCsTag_EventPaths); - VerifyOrReturnLogError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); eventPathList.Init(reader); PRETTY_PRINT_INCDEPTH(); - ReturnLogErrorOnFailure(eventPathList.CheckSchemaValidity()); + ReturnErrorOnFailure(eventPathList.CheckSchemaValidity()); PRETTY_PRINT_DECDEPTH(); break; case kCsTag_AttributeDataVersionList: - VerifyOrReturnLogError(!(TagPresenceMask & (1 << kCsTag_AttributeDataVersionList)), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_AttributeDataVersionList)), CHIP_ERROR_INVALID_TLV_TAG); TagPresenceMask |= (1 << kCsTag_AttributeDataVersionList); - VerifyOrReturnLogError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); attributeDataVersionList.Init(reader); PRETTY_PRINT_INCDEPTH(); - ReturnLogErrorOnFailure(attributeDataVersionList.CheckSchemaValidity()); + ReturnErrorOnFailure(attributeDataVersionList.CheckSchemaValidity()); PRETTY_PRINT_DECDEPTH(); break; case kCsTag_EventNumber: - VerifyOrReturnLogError(!(TagPresenceMask & (1 << kCsTag_EventNumber)), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_EventNumber)), CHIP_ERROR_INVALID_TLV_TAG); TagPresenceMask |= (1 << kCsTag_EventNumber); - VerifyOrReturnLogError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { uint64_t eventNumber; - ReturnLogErrorOnFailure(reader.Get(eventNumber)); + ReturnErrorOnFailure(reader.Get(eventNumber)); PRETTY_PRINT("\tEventNumber = 0x%" PRIx64 ",", eventNumber); } #endif // CHIP_DETAIL_LOGGING break; case kCsTag_MinIntervalSeconds: - VerifyOrReturnLogError(!(TagPresenceMask & (1 << kCsTag_MinIntervalSeconds)), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_MinIntervalSeconds)), CHIP_ERROR_INVALID_TLV_TAG); TagPresenceMask |= (1 << kCsTag_MinIntervalSeconds); - VerifyOrReturnLogError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { uint16_t minIntervalSeconds; - ReturnLogErrorOnFailure(reader.Get(minIntervalSeconds)); + ReturnErrorOnFailure(reader.Get(minIntervalSeconds)); PRETTY_PRINT("\tMinIntervalSeconds = 0x%" PRIx16 ",", minIntervalSeconds); } #endif // CHIP_DETAIL_LOGGING break; case kCsTag_MaxIntervalSeconds: - VerifyOrReturnLogError(!(TagPresenceMask & (1 << kCsTag_MaxIntervalSeconds)), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_MaxIntervalSeconds)), CHIP_ERROR_INVALID_TLV_TAG); TagPresenceMask |= (1 << kCsTag_MaxIntervalSeconds); - VerifyOrReturnLogError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { uint16_t maxIntervalSeconds; - ReturnLogErrorOnFailure(reader.Get(maxIntervalSeconds)); + ReturnErrorOnFailure(reader.Get(maxIntervalSeconds)); PRETTY_PRINT("\tkMaxInterval = 0x%" PRIx16 ",", maxIntervalSeconds); } #endif // CHIP_DETAIL_LOGGING break; case kCsTag_KeepSubscriptions: - VerifyOrReturnLogError(!(TagPresenceMask & (1 << kCsTag_KeepSubscriptions)), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_KeepSubscriptions)), CHIP_ERROR_INVALID_TLV_TAG); TagPresenceMask |= (1 << kCsTag_KeepSubscriptions); - VerifyOrReturnLogError(chip::TLV::kTLVType_Boolean == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(chip::TLV::kTLVType_Boolean == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { bool keepSubscriptions; - ReturnLogErrorOnFailure(reader.Get(keepSubscriptions)); + ReturnErrorOnFailure(reader.Get(keepSubscriptions)); PRETTY_PRINT("\tKeepSubscriptions = %s, ", keepSubscriptions ? "true" : "false"); } #endif // CHIP_DETAIL_LOGGING break; case kCsTag_IsProxy: - VerifyOrReturnLogError(!(TagPresenceMask & (1 << kCsTag_IsProxy)), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_IsProxy)), CHIP_ERROR_INVALID_TLV_TAG); TagPresenceMask |= (1 << kCsTag_IsProxy); - VerifyOrReturnLogError(chip::TLV::kTLVType_Boolean == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(chip::TLV::kTLVType_Boolean == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { bool isProxy; - ReturnLogErrorOnFailure(reader.Get(isProxy)); + ReturnErrorOnFailure(reader.Get(isProxy)); PRETTY_PRINT("\tIsProxy = %s, ", isProxy ? "true" : "false"); } #endif // CHIP_DETAIL_LOGGING break; default: - ReturnLogErrorOnFailure(CHIP_ERROR_INVALID_TLV_TAG); + ReturnErrorOnFailure(CHIP_ERROR_INVALID_TLV_TAG); } } @@ -160,7 +150,7 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const err = CHIP_NO_ERROR; } } - ReturnLogErrorOnFailure(err); + ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -168,16 +158,16 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const CHIP_ERROR SubscribeRequestMessage::Parser::GetPathList(AttributePathIBs::Parser * const apAttributePathList) const { TLV::TLVReader reader; - ReturnLogErrorOnFailure(mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_AttributePathList), reader)); - VerifyOrReturnLogError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + ReturnErrorOnFailure(mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_AttributePathList), reader)); + VerifyOrReturnError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); return apAttributePathList->Init(reader); } CHIP_ERROR SubscribeRequestMessage::Parser::GetEventPaths(EventPaths::Parser * const apEventPaths) const { TLV::TLVReader reader; - ReturnLogErrorOnFailure(mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_EventPaths), reader)); - VerifyOrReturnLogError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + ReturnErrorOnFailure(mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_EventPaths), reader)); + VerifyOrReturnError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); return apEventPaths->Init(reader); } @@ -186,8 +176,8 @@ SubscribeRequestMessage::Parser::GetAttributeDataVersionList( AttributeDataVersionList::Parser * const apAttributeDataVersionList) const { TLV::TLVReader reader; - ReturnLogErrorOnFailure(mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_AttributeDataVersionList), reader)); - VerifyOrReturnLogError(TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + ReturnErrorOnFailure(mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_AttributeDataVersionList), reader)); + VerifyOrReturnError(TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); return apAttributeDataVersionList->Init(reader); } @@ -216,11 +206,6 @@ CHIP_ERROR SubscribeRequestMessage::Parser::GetIsProxy(bool * const apIsProxy) c return GetSimpleValue(kCsTag_IsProxy, chip::TLV::kTLVType_Boolean, apIsProxy); } -CHIP_ERROR SubscribeRequestMessage::Builder::Init(chip::TLV::TLVWriter * const apWriter) -{ - return InitAnonymousStructure(apWriter); -} - AttributePathIBs::Builder & SubscribeRequestMessage::Builder::CreateAttributePathListBuilder() { if (mError == CHIP_NO_ERROR) diff --git a/src/app/MessageDef/SubscribeRequestMessage.h b/src/app/MessageDef/SubscribeRequestMessage.h index c2536b5bd913ff..ea1802cf46afc1 100644 --- a/src/app/MessageDef/SubscribeRequestMessage.h +++ b/src/app/MessageDef/SubscribeRequestMessage.h @@ -19,9 +19,9 @@ #include "AttributeDataVersionList.h" #include "AttributePathIBs.h" -#include "Builder.h" #include "EventPaths.h" -#include "Parser.h" +#include "StructBuilder.h" +#include "StructParser.h" #include #include #include @@ -44,13 +44,9 @@ enum kCsTag_IsProxy = 7, }; -class Parser : public chip::app::Parser +class Parser : public StructParser { public: - /** - * @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this request - */ - CHIP_ERROR Init(const chip::TLV::TLVReader & aReader); #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK /** * @brief Roughly verify the message is correctly formed @@ -128,11 +124,9 @@ class Parser : public chip::app::Parser CHIP_ERROR GetIsProxy(bool * const apIsProxy) const; }; -class Builder : public chip::app::Builder +class Builder : public StructBuilder { public: - CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter); - AttributePathIBs::Builder & CreateAttributePathListBuilder(); /** diff --git a/src/app/MessageDef/SubscribeResponseMessage.cpp b/src/app/MessageDef/SubscribeResponseMessage.cpp index 8248058212b507..41684d5691edd2 100644 --- a/src/app/MessageDef/SubscribeResponseMessage.cpp +++ b/src/app/MessageDef/SubscribeResponseMessage.cpp @@ -19,17 +19,6 @@ namespace chip { namespace app { -CHIP_ERROR SubscribeResponseMessage::Parser::Init(const chip::TLV::TLVReader & aReader) -{ - // make a copy of the reader here - mReader.Init(aReader); - - VerifyOrReturnLogError(chip::TLV::kTLVType_Structure == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - - ReturnLogErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); - return CHIP_NO_ERROR; -} - #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR SubscribeResponseMessage::Parser::CheckSchemaValidity() const { @@ -44,47 +33,47 @@ CHIP_ERROR SubscribeResponseMessage::Parser::CheckSchemaValidity() const while (CHIP_NO_ERROR == (err = reader.Next())) { - VerifyOrReturnLogError(chip::TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(chip::TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); switch (chip::TLV::TagNumFromTag(reader.GetTag())) { case kCsTag_SubscriptionId: - VerifyOrReturnLogError(!(TagPresenceMask & (1 << kCsTag_SubscriptionId)), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_SubscriptionId)), CHIP_ERROR_INVALID_TLV_TAG); TagPresenceMask |= (1 << kCsTag_SubscriptionId); - VerifyOrReturnLogError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { uint64_t subscriptionId; - ReturnLogErrorOnFailure(reader.Get(subscriptionId)); + ReturnErrorOnFailure(reader.Get(subscriptionId)); PRETTY_PRINT("\tSubscriptionId = 0x%" PRIx64 ",", subscriptionId); } #endif // CHIP_DETAIL_LOGGING break; case kCsTag_MinIntervalFloorSeconds: - VerifyOrReturnLogError(!(TagPresenceMask & (1 << kCsTag_MinIntervalFloorSeconds)), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_MinIntervalFloorSeconds)), CHIP_ERROR_INVALID_TLV_TAG); TagPresenceMask |= (1 << kCsTag_MinIntervalFloorSeconds); - VerifyOrReturnLogError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { uint16_t minIntervalFloorSeconds; - ReturnLogErrorOnFailure(reader.Get(minIntervalFloorSeconds)); + ReturnErrorOnFailure(reader.Get(minIntervalFloorSeconds)); PRETTY_PRINT("\tMinIntervalFloorSeconds = 0x%" PRIx16 ",", minIntervalFloorSeconds); } #endif // CHIP_DETAIL_LOGGING break; case kCsTag_MaxIntervalCeilingSeconds: - VerifyOrReturnLogError(!(TagPresenceMask & (1 << kCsTag_MaxIntervalCeilingSeconds)), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(!(TagPresenceMask & (1 << kCsTag_MaxIntervalCeilingSeconds)), CHIP_ERROR_INVALID_TLV_TAG); TagPresenceMask |= (1 << kCsTag_MaxIntervalCeilingSeconds); - VerifyOrReturnLogError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + VerifyOrReturnError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { uint16_t maxIntervalCeilingSeconds; - ReturnLogErrorOnFailure(reader.Get(maxIntervalCeilingSeconds)); + ReturnErrorOnFailure(reader.Get(maxIntervalCeilingSeconds)); PRETTY_PRINT("\tMaxIntervalCeilingSeconds = 0x%" PRIx16 ",", maxIntervalCeilingSeconds); } #endif // CHIP_DETAIL_LOGGING break; default: - ReturnLogErrorOnFailure(CHIP_ERROR_INVALID_TLV_TAG); + ReturnErrorOnFailure(CHIP_ERROR_INVALID_TLV_TAG); } } PRETTY_PRINT("}"); @@ -100,7 +89,7 @@ CHIP_ERROR SubscribeResponseMessage::Parser::CheckSchemaValidity() const err = CHIP_NO_ERROR; } } - ReturnLogErrorOnFailure(err); + ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -120,11 +109,6 @@ CHIP_ERROR SubscribeResponseMessage::Parser::GetMaxIntervalCeilingSeconds(uint16 return GetUnsignedInteger(kCsTag_MaxIntervalCeilingSeconds, apMaxIntervalCeilingSeconds); } -CHIP_ERROR SubscribeResponseMessage::Builder::Init(chip::TLV::TLVWriter * const apWriter) -{ - return InitAnonymousStructure(apWriter); -} - SubscribeResponseMessage::Builder & SubscribeResponseMessage::Builder::SubscriptionId(const uint64_t aSubscribeId) { if (mError == CHIP_NO_ERROR) diff --git a/src/app/MessageDef/SubscribeResponseMessage.h b/src/app/MessageDef/SubscribeResponseMessage.h index e87f24a60ce468..8484a67d4ad984 100644 --- a/src/app/MessageDef/SubscribeResponseMessage.h +++ b/src/app/MessageDef/SubscribeResponseMessage.h @@ -16,9 +16,9 @@ */ #pragma once -#include "Builder.h" #include "EventPaths.h" -#include "Parser.h" +#include "StructBuilder.h" +#include "StructParser.h" #include #include #include @@ -36,13 +36,9 @@ enum kCsTag_MaxIntervalCeilingSeconds = 2, }; -class Parser : public chip::app::Parser +class Parser : public StructParser { public: - /** - * @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this response - */ - CHIP_ERROR Init(const chip::TLV::TLVReader & aReader); #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK /** * @brief Roughly verify the message is correctly formed @@ -83,11 +79,9 @@ class Parser : public chip::app::Parser CHIP_ERROR GetMaxIntervalCeilingSeconds(uint16_t * const apMaxIntervalCeilingSeconds) const; }; -class Builder : public chip::app::Builder +class Builder : public StructBuilder { public: - CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter); - /** * @brief final subscription Id for the subscription back to the client.s. */ diff --git a/src/app/MessageDef/TimedRequestMessage.cpp b/src/app/MessageDef/TimedRequestMessage.cpp index ef4e69248ea3da..e922842bde0ebf 100644 --- a/src/app/MessageDef/TimedRequestMessage.cpp +++ b/src/app/MessageDef/TimedRequestMessage.cpp @@ -19,15 +19,6 @@ namespace chip { namespace app { -CHIP_ERROR TimedRequestMessage::Parser::Init(const chip::TLV::TLVReader & aReader) -{ - // make a copy of the reader here - mReader.Init(aReader); - VerifyOrReturnError(TLV::kTLVType_Structure == mReader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - ReturnErrorOnFailure(mReader.EnterContainer(mOuterContainerType)); - return CHIP_NO_ERROR; -} - #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR TimedRequestMessage::Parser::CheckSchemaValidity() const { @@ -73,7 +64,7 @@ CHIP_ERROR TimedRequestMessage::Parser::CheckSchemaValidity() const err = CHIP_NO_ERROR; } } - ReturnLogErrorOnFailure(err); + ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK @@ -83,11 +74,6 @@ CHIP_ERROR TimedRequestMessage::Parser::GetTimeoutMs(uint16_t * const apTimeoutM return GetUnsignedInteger(to_underlying(Tag::kTimeoutMs), apTimeoutMs); } -CHIP_ERROR TimedRequestMessage::Builder::Init(TLV::TLVWriter * const apWriter) -{ - return InitAnonymousStructure(apWriter); -} - TimedRequestMessage::Builder & TimedRequestMessage::Builder::TimeoutMs(const uint16_t aTimeoutMs) { // skip if error has already been set diff --git a/src/app/MessageDef/TimedRequestMessage.h b/src/app/MessageDef/TimedRequestMessage.h index 6bdd6c30220ff8..8873ec3d0f0050 100644 --- a/src/app/MessageDef/TimedRequestMessage.h +++ b/src/app/MessageDef/TimedRequestMessage.h @@ -16,8 +16,8 @@ */ #pragma once -#include "Builder.h" -#include "Parser.h" +#include "StructBuilder.h" +#include "StructParser.h" #include #include #include @@ -33,13 +33,9 @@ enum class Tag : uint8_t kTimeoutMs = 0, }; -class Parser : public chip::app::Parser +class Parser : public StructParser { public: - /** - * @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this request - */ - CHIP_ERROR Init(const TLV::TLVReader & aReader); #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK /** * @brief Roughly verify the message is correctly formed @@ -66,11 +62,9 @@ class Parser : public chip::app::Parser CHIP_ERROR GetTimeoutMs(uint16_t * const apTimeoutMs) const; }; -class Builder : public chip::app::Builder +class Builder : public StructBuilder { public: - CHIP_ERROR Init(TLV::TLVWriter * const apWriter); - /** * @brief Timeout value, sent by a client to a server, if there is a preceding successful Timed Request action, * the following action SHALL be received before the end of the Timeout interval. diff --git a/src/app/MessageDef/WriteRequestMessage.cpp b/src/app/MessageDef/WriteRequestMessage.cpp index c45f3005277acd..e55db722cc9130 100644 --- a/src/app/MessageDef/WriteRequestMessage.cpp +++ b/src/app/MessageDef/WriteRequestMessage.cpp @@ -33,21 +33,6 @@ using namespace chip::TLV; namespace chip { namespace app { -CHIP_ERROR WriteRequestMessage::Parser::Init(const chip::TLV::TLVReader & aReader) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - mReader.Init(aReader); - - VerifyOrExit(chip::TLV::kTLVType_Structure == mReader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - err = mReader.EnterContainer(mOuterContainerType); - -exit: - - return err; -} - #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK CHIP_ERROR WriteRequestMessage::Parser::CheckSchemaValidity() const { @@ -190,11 +175,6 @@ CHIP_ERROR WriteRequestMessage::Parser::GetMoreChunkedMessages(bool * const apMo return GetSimpleValue(kCsTag_MoreChunkedMessages, chip::TLV::kTLVType_Boolean, apMoreChunkedMessages); } -CHIP_ERROR WriteRequestMessage::Builder::Init(chip::TLV::TLVWriter * const apWriter) -{ - return InitAnonymousStructure(apWriter); -} - WriteRequestMessage::Builder & WriteRequestMessage::Builder::SuppressResponse(const bool aSuppressResponse) { // skip if error has already been set diff --git a/src/app/MessageDef/WriteRequestMessage.h b/src/app/MessageDef/WriteRequestMessage.h index 8636b3579ffc8c..62abd141885352 100644 --- a/src/app/MessageDef/WriteRequestMessage.h +++ b/src/app/MessageDef/WriteRequestMessage.h @@ -24,8 +24,8 @@ #include "AttributeDataIBs.h" #include "AttributeDataVersionList.h" -#include "Builder.h" -#include "Parser.h" +#include "StructBuilder.h" +#include "StructParser.h" #include #include #include @@ -43,18 +43,9 @@ enum kCsTag_MoreChunkedMessages = 3, }; -class Parser : public chip::app::Parser +class Parser : public StructParser { public: - /** - * @brief Initialize the parser object with TLVReader - * - * @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this request - * - * @return #CHIP_NO_ERROR on success - */ - CHIP_ERROR Init(const chip::TLV::TLVReader & aReader); - /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present @@ -109,18 +100,9 @@ class Parser : public chip::app::Parser CHIP_ERROR GetMoreChunkedMessages(bool * const apMoreChunkedMessages) const; }; -class Builder : public chip::app::Builder +class Builder : public StructBuilder { public: - /** - * @brief Initialize a WriteRequestMessage::Builder for writing into a TLV stream - * - * @param [in] apWriter A pointer to TLVWriter - * - * @return #CHIP_NO_ERROR on success - */ - CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter); - /** * @brief This can be used to optionally signal to the server that no responses are to be sent back. * @param [in] aSuppressResponse true if client need to signal suppress response