From fe9d52d32767c84391198cc45143d9505c523341 Mon Sep 17 00:00:00 2001 From: Yunhan Wang Date: Wed, 3 Nov 2021 13:03:39 -0700 Subject: [PATCH] Update/Rename attributePath/AttributePaths/AttributeStatus/WriteResponse with latest encoding spec --- src/app/BUILD.gn | 12 +- src/app/MessageDef/AttributeDataElement.cpp | 6 +- src/app/MessageDef/AttributeDataElement.h | 14 +- src/app/MessageDef/AttributePath.cpp | 272 ------------------ src/app/MessageDef/AttributePathIB.cpp | 254 ++++++++++++++++ .../{AttributePath.h => AttributePathIB.h} | 138 ++++----- src/app/MessageDef/AttributePathList.cpp | 107 ------- src/app/MessageDef/AttributePaths.cpp | 92 ++++++ .../{AttributePathList.h => AttributePaths.h} | 27 +- src/app/MessageDef/AttributeStatusIB.cpp | 186 ++++-------- src/app/MessageDef/AttributeStatusIB.h | 114 +++----- ...teStatusList.cpp => AttributeStatuses.cpp} | 62 ++-- ...ributeStatusList.h => AttributeStatuses.h} | 26 +- src/app/MessageDef/ReadRequestMessage.cpp | 14 +- src/app/MessageDef/ReadRequestMessage.h | 14 +- .../MessageDef/SubscribeRequestMessage.cpp | 10 +- src/app/MessageDef/SubscribeRequestMessage.h | 10 +- src/app/MessageDef/WriteRequestMessage.h | 2 +- src/app/MessageDef/WriteResponseMessage.cpp | 117 +++----- src/app/MessageDef/WriteResponseMessage.h | 63 ++-- src/app/ReadClient.cpp | 30 +- src/app/ReadClient.h | 2 +- src/app/ReadHandler.cpp | 16 +- src/app/ReadHandler.h | 2 +- src/app/WriteClient.cpp | 40 +-- src/app/WriteHandler.cpp | 39 ++- src/app/reporting/Engine.cpp | 12 +- src/app/tests/TestMessageDef.cpp | 134 ++++----- src/app/tests/TestReadInteraction.cpp | 32 +-- src/app/tests/TestReportingEngine.cpp | 30 +- src/app/tests/TestWriteInteraction.cpp | 20 +- 31 files changed, 833 insertions(+), 1064 deletions(-) delete mode 100644 src/app/MessageDef/AttributePath.cpp create mode 100644 src/app/MessageDef/AttributePathIB.cpp rename src/app/MessageDef/{AttributePath.h => AttributePathIB.h} (50%) delete mode 100644 src/app/MessageDef/AttributePathList.cpp create mode 100644 src/app/MessageDef/AttributePaths.cpp rename src/app/MessageDef/{AttributePathList.h => AttributePaths.h} (75%) rename src/app/MessageDef/{AttributeStatusList.cpp => AttributeStatuses.cpp} (56%) rename src/app/MessageDef/{AttributeStatusList.h => AttributeStatuses.h} (76%) diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index 35ad1b6a57247c..dd95ba85291e21 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -49,14 +49,14 @@ static_library("app") { "MessageDef/AttributeDataList.h", "MessageDef/AttributeDataVersionList.cpp", "MessageDef/AttributeDataVersionList.h", - "MessageDef/AttributePath.cpp", - "MessageDef/AttributePath.h", - "MessageDef/AttributePathList.cpp", - "MessageDef/AttributePathList.h", + "MessageDef/AttributePathIB.cpp", + "MessageDef/AttributePathIB.h", + "MessageDef/AttributePaths.cpp", + "MessageDef/AttributePaths.h", "MessageDef/AttributeStatusIB.cpp", "MessageDef/AttributeStatusIB.h", - "MessageDef/AttributeStatusList.cpp", - "MessageDef/AttributeStatusList.h", + "MessageDef/AttributeStatuses.cpp", + "MessageDef/AttributeStatuses.h", "MessageDef/Builder.cpp", "MessageDef/Builder.h", "MessageDef/CommandDataIB.cpp", diff --git a/src/app/MessageDef/AttributeDataElement.cpp b/src/app/MessageDef/AttributeDataElement.cpp index 56211e31699faa..22668de361da92 100644 --- a/src/app/MessageDef/AttributeDataElement.cpp +++ b/src/app/MessageDef/AttributeDataElement.cpp @@ -243,7 +243,7 @@ CHIP_ERROR AttributeDataElement::Parser::CheckSchemaValidity() const VerifyOrExit(chip::TLV::kTLVType_List == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); { - AttributePath::Parser path; + AttributePathIB::Parser path; err = path.Init(reader); SuccessOrExit(err); @@ -348,7 +348,7 @@ CHIP_ERROR AttributeDataElement::Parser::CheckSchemaValidity() const } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK -CHIP_ERROR AttributeDataElement::Parser::GetAttributePath(AttributePath::Parser * const apAttributePath) const +CHIP_ERROR AttributeDataElement::Parser::GetAttributePath(AttributePathIB::Parser * const apAttributePath) const { CHIP_ERROR err = CHIP_NO_ERROR; chip::TLV::TLVReader reader; @@ -403,7 +403,7 @@ CHIP_ERROR AttributeDataElement::Builder::Init(chip::TLV::TLVWriter * const apWr return InitAnonymousStructure(apWriter); } -AttributePath::Builder & AttributeDataElement::Builder::CreateAttributePathBuilder() +AttributePathIB::Builder & AttributeDataElement::Builder::CreateAttributePath() { // skip if error has already been set VerifyOrExit(CHIP_NO_ERROR == mError, mAttributePathBuilder.ResetError(mError)); diff --git a/src/app/MessageDef/AttributeDataElement.h b/src/app/MessageDef/AttributeDataElement.h index dea631b90ce6bb..0b019814f26f4b 100644 --- a/src/app/MessageDef/AttributeDataElement.h +++ b/src/app/MessageDef/AttributeDataElement.h @@ -23,7 +23,7 @@ #pragma once -#include "AttributePath.h" +#include "AttributePathIB.h" #include "Builder.h" #include "Parser.h" @@ -76,7 +76,7 @@ class Parser : public chip::app::Parser #endif /** - * @brief Get a TLVReader for the AttributePath. Next() must be called before accessing them. + * @brief Get a TLVReader for the AttributePathIB. Next() must be called before accessing them. * * @param [in] apAttributePath A pointer to apAttributePath * @@ -84,7 +84,7 @@ class Parser : public chip::app::Parser * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not a Path * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetAttributePath(AttributePath::Parser * const apAttributePath) const; + CHIP_ERROR GetAttributePath(AttributePathIB::Parser * const apAttributePath) const; /** * @brief Get a TLVReader for the DataVersion. Next() must be called before accessing them. @@ -145,11 +145,11 @@ class Builder : public chip::app::Builder CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter); /** - * @brief Initialize a AttributePath::Builder for writing into the TLV stream + * @brief Initialize a AttributePathIB::Builder for writing into the TLV stream * - * @return A reference to AttributePath::Builder + * @return A reference to AttributePathIB::Builder */ - AttributePath::Builder & CreateAttributePathBuilder(); + AttributePathIB::Builder & CreateAttributePath(); /** * @brief Inject DataVersion into the TLV stream to indicate the numerical data version associated with @@ -180,7 +180,7 @@ class Builder : public chip::app::Builder AttributeDataElement::Builder & EndOfAttributeDataElement(); private: - AttributePath::Builder mAttributePathBuilder; + AttributePathIB::Builder mAttributePathBuilder; }; }; // namespace AttributeDataElement diff --git a/src/app/MessageDef/AttributePath.cpp b/src/app/MessageDef/AttributePath.cpp deleted file mode 100644 index 0489eb0695fe6a..00000000000000 --- a/src/app/MessageDef/AttributePath.cpp +++ /dev/null @@ -1,272 +0,0 @@ -/** - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2018 Google LLC. - * Copyright (c) 2016-2017 Nest Labs, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * This file defines AttributePath parser and builder in CHIP interaction model - * - */ - -#include "AttributePath.h" -#include "MessageDefHelper.h" - -#include -#include -#include - -#include - -using namespace chip; -using namespace chip::TLV; - -namespace chip { -namespace app { -CHIP_ERROR AttributePath::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_List == mReader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - err = mReader.EnterContainer(mOuterContainerType); - -exit: - - return err; -} - -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK -CHIP_ERROR AttributePath::Parser::CheckSchemaValidity() const -{ - CHIP_ERROR err = CHIP_NO_ERROR; - uint16_t TagPresenceMask = 0; - chip::TLV::TLVReader reader; - - PRETTY_PRINT("AttributePath ="); - PRETTY_PRINT("{"); - - // make a copy of the Path reader - reader.Init(mReader); - - while (CHIP_NO_ERROR == (err = reader.Next())) - { - VerifyOrExit(chip::TLV::IsContextTag(reader.GetTag()), err = CHIP_ERROR_INVALID_TLV_TAG); - switch (chip::TLV::TagNumFromTag(reader.GetTag())) - { - case kCsTag_NodeId: - // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_NodeId)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_NodeId); - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - -#if CHIP_DETAIL_LOGGING - { - chip::NodeId nodeId; - reader.Get(nodeId); - PRETTY_PRINT("\tNodeId = 0x%" PRIx64 ",", nodeId); - } -#endif // CHIP_DETAIL_LOGGING - break; - case kCsTag_EndpointId: - // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_EndpointId)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_EndpointId); - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); -#if CHIP_DETAIL_LOGGING - { - chip::EndpointId endpointId; - reader.Get(endpointId); - PRETTY_PRINT("\tEndpointId = 0x%" PRIx16 ",", endpointId); - } -#endif // CHIP_DETAIL_LOGGING - break; - case kCsTag_ClusterId: - // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_ClusterId)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_ClusterId); - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - -#if CHIP_DETAIL_LOGGING - if (chip::TLV::kTLVType_UnsignedInteger == reader.GetType()) - { - chip::ClusterId clusterId; - reader.Get(clusterId); - PRETTY_PRINT("\tClusterId = 0x%" PRIx32 ",", clusterId); - } -#endif // CHIP_DETAIL_LOGGING - break; - case kCsTag_FieldId: - // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_FieldId)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_FieldId); - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); -#if CHIP_DETAIL_LOGGING - { - chip::AttributeId fieldTag; - reader.Get(fieldTag); - PRETTY_PRINT("\tFieldTag = " ChipLogFormatMEI ",", ChipLogValueMEI(fieldTag)); - } -#endif // CHIP_DETAIL_LOGGING - break; - case kCsTag_ListIndex: - // check if this tag has appeared before - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_ListIndex)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_ListIndex); - VerifyOrExit(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); -#if CHIP_DETAIL_LOGGING - if (chip::TLV::kTLVType_UnsignedInteger == reader.GetType()) - { - uint16_t listIndex; - reader.Get(listIndex); - PRETTY_PRINT("\tListIndex = 0x%" PRIx16 ",", listIndex); - } -#endif // CHIP_DETAIL_LOGGING - break; - default: - ExitNow(err = CHIP_ERROR_INVALID_TLV_TAG); - } - } - - PRETTY_PRINT("}"); - PRETTY_PRINT("\t"); - // if we have exhausted this container - if (CHIP_END_OF_TLV == err) - { - // Not allow for situation where ListIndex exists, but FieldId not exists - if ((TagPresenceMask & (1 << kCsTag_FieldId)) == 0 && (TagPresenceMask & (1 << kCsTag_ListIndex)) != 0) - { - err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH; - } - else - { - err = CHIP_NO_ERROR; - } - } - - SuccessOrExit(err); - err = reader.ExitContainer(mOuterContainerType); - -exit: - - return err; -} -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK - -CHIP_ERROR AttributePath::Parser::GetNodeId(chip::NodeId * const apNodeId) const -{ - return GetUnsignedInteger(kCsTag_NodeId, apNodeId); -} - -CHIP_ERROR AttributePath::Parser::GetEndpointId(chip::EndpointId * const apEndpointId) const -{ - return GetUnsignedInteger(kCsTag_EndpointId, apEndpointId); -} - -CHIP_ERROR AttributePath::Parser::GetClusterId(chip::ClusterId * const apClusterId) const -{ - return GetUnsignedInteger(kCsTag_ClusterId, apClusterId); -} - -CHIP_ERROR AttributePath::Parser::GetFieldId(chip::AttributeId * const apFieldId) const -{ - return GetUnsignedInteger(kCsTag_FieldId, apFieldId); -} - -CHIP_ERROR AttributePath::Parser::GetListIndex(chip::ListIndex * const apListIndex) const -{ - return GetUnsignedInteger(kCsTag_ListIndex, apListIndex); -} - -CHIP_ERROR AttributePath::Builder::_Init(chip::TLV::TLVWriter * const apWriter, const Tag aTag) -{ - mpWriter = apWriter; - mError = mpWriter->StartContainer(aTag, chip::TLV::kTLVType_List, mOuterContainerType); - SuccessOrExit(mError); - -exit: - return mError; -} - -CHIP_ERROR AttributePath::Builder::Init(chip::TLV::TLVWriter * const apWriter) -{ - return _Init(apWriter, chip::TLV::AnonymousTag); -} - -CHIP_ERROR AttributePath::Builder::Init(chip::TLV::TLVWriter * const apWriter, const uint8_t aContextTagToUse) -{ - return _Init(apWriter, chip::TLV::ContextTag(aContextTagToUse)); -} - -AttributePath::Builder & AttributePath::Builder::NodeId(const uint64_t aNodeId) -{ - // skip if error has already been set - if (mError == CHIP_NO_ERROR) - { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_NodeId), aNodeId); - } - return *this; -} - -AttributePath::Builder & AttributePath::Builder::EndpointId(const chip::EndpointId aEndpointId) -{ - // skip if error has already been set - if (mError == CHIP_NO_ERROR) - { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_EndpointId), aEndpointId); - } - return *this; -} - -AttributePath::Builder & AttributePath::Builder::ClusterId(const chip::ClusterId aClusterId) -{ - // skip if error has already been set - if (mError == CHIP_NO_ERROR) - { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_ClusterId), aClusterId); - } - return *this; -} - -AttributePath::Builder & AttributePath::Builder::FieldId(const chip::AttributeId aFieldId) -{ - // skip if error has already been set - if (mError == CHIP_NO_ERROR) - { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_FieldId), aFieldId); - } - return *this; -} - -AttributePath::Builder & AttributePath::Builder::ListIndex(const chip::ListIndex aListIndex) -{ - // skip if error has already been set - if (mError == CHIP_NO_ERROR) - { - mError = mpWriter->Put(chip::TLV::ContextTag(kCsTag_ListIndex), aListIndex); - } - return *this; -} - -AttributePath::Builder & AttributePath::Builder::EndOfAttributePath() -{ - EndOfContainer(); - return *this; -} -}; // namespace app -}; // namespace chip diff --git a/src/app/MessageDef/AttributePathIB.cpp b/src/app/MessageDef/AttributePathIB.cpp new file mode 100644 index 00000000000000..1fbecd7ead99ae --- /dev/null +++ b/src/app/MessageDef/AttributePathIB.cpp @@ -0,0 +1,254 @@ +/** + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2018 Google LLC. + * Copyright (c) 2016-2017 Nest Labs, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AttributePathIB.h" +#include "MessageDefHelper.h" + +#include +#include +#include + +#include + +namespace chip { +namespace app { +#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +CHIP_ERROR AttributePathIB::Parser::CheckSchemaValidity() const +{ + CHIP_ERROR err = CHIP_NO_ERROR; + int TagPresenceMask = 0; + TLV::TLVReader reader; + + PRETTY_PRINT("AttributePathIB ="); + PRETTY_PRINT("{"); + + // make a copy of the Path reader + reader.Init(mReader); + + while (CHIP_NO_ERROR == (err = reader.Next())) + { + VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); + uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); + switch (tagNum) + { + case to_underlying(Tag::kEnableTagCompression): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kEnableTagCompression))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kEnableTagCompression)); +#if CHIP_DETAIL_LOGGING + { + bool enableTagCompression; + ReturnErrorOnFailure(reader.Get(enableTagCompression)); + PRETTY_PRINT("\tenableTagCompression = %s, ", enableTagCompression ? "true" : "false"); + } +#endif // CHIP_DETAIL_LOGGING + break; + case to_underlying(Tag::kNode): + // check if this tag has appeared before + + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kNode))), err = CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kNode)); + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); + +#if CHIP_DETAIL_LOGGING + { + NodeId node; + reader.Get(node); + PRETTY_PRINT("\tNode = 0x%" PRIx64 ",", node); + } +#endif // CHIP_DETAIL_LOGGING + break; + case to_underlying(Tag::kEndpoint): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kEndpoint))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kEndpoint)); + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); +#if CHIP_DETAIL_LOGGING + { + EndpointId endpoint; + reader.Get(endpoint); + PRETTY_PRINT("\tEndpoint = 0x%" PRIx16 ",", endpoint); + } +#endif // CHIP_DETAIL_LOGGING + break; + case to_underlying(Tag::kCluster): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kCluster))), err = CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kCluster)); + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); + +#if CHIP_DETAIL_LOGGING + { + ClusterId cluster; + ReturnErrorOnFailure(reader.Get(cluster)); + PRETTY_PRINT("\tCluster = 0x%" PRIx32 ",", cluster); + } +#endif // CHIP_DETAIL_LOGGING + break; + case to_underlying(Tag::kAttribute): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kAttribute))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kAttribute)); + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); +#if CHIP_DETAIL_LOGGING + { + AttributeId attribute; + ReturnErrorOnFailure(reader.Get(attribute)); + PRETTY_PRINT("\tAttribute = " ChipLogFormatMEI ",", ChipLogValueMEI(attribute)); + } +#endif // CHIP_DETAIL_LOGGING + break; + case to_underlying(Tag::kListIndex): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kListIndex))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kListIndex)); + VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); +#if CHIP_DETAIL_LOGGING + if (TLV::kTLVType_UnsignedInteger == reader.GetType()) + { + uint16_t listIndex; + ReturnErrorOnFailure(reader.Get(listIndex)); + PRETTY_PRINT("\tListIndex = 0x%" PRIx16 ",", listIndex); + } +#endif // CHIP_DETAIL_LOGGING + break; + default: + PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); + break; + } + } + + PRETTY_PRINT("}"); + PRETTY_PRINT("\t"); + // if we have exhausted this container + if (CHIP_END_OF_TLV == err) + { + if ((TagPresenceMask & (1 << to_underlying(Tag::kAttribute))) == 0 && + (TagPresenceMask & (1 << to_underlying(Tag::kListIndex))) != 0) + { + err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH; + } + else + { + err = CHIP_NO_ERROR; + } + } + + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); + return CHIP_NO_ERROR; +} +#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK + +CHIP_ERROR AttributePathIB::Parser::GetEnableTagCompression(bool * const apEnableTagCompression) const +{ + return GetSimpleValue(to_underlying(Tag::kEnableTagCompression), TLV::kTLVType_Boolean, apEnableTagCompression); +} + +CHIP_ERROR AttributePathIB::Parser::GetNode(NodeId * const apNode) const +{ + return GetUnsignedInteger(to_underlying(Tag::kNode), apNode); +} + +CHIP_ERROR AttributePathIB::Parser::GetEndpoint(EndpointId * const apEndpoint) const +{ + return GetUnsignedInteger(to_underlying(Tag::kEndpoint), apEndpoint); +} + +CHIP_ERROR AttributePathIB::Parser::GetCluster(ClusterId * const apCluster) const +{ + return GetUnsignedInteger(to_underlying(Tag::kCluster), apCluster); +} + +CHIP_ERROR AttributePathIB::Parser::GetAttribute(AttributeId * const apAttribute) const +{ + return GetUnsignedInteger(to_underlying(Tag::kAttribute), apAttribute); +} + +CHIP_ERROR AttributePathIB::Parser::GetListIndex(ListIndex * const apListIndex) const +{ + return GetUnsignedInteger(to_underlying(Tag::kListIndex), apListIndex); +} + +AttributePathIB::Builder & AttributePathIB::Builder::EnableTagCompression(const bool aEnableTagCompression) +{ + // skip if error has already been set + if (mError == CHIP_NO_ERROR) + { + mError = mpWriter->PutBoolean(TLV::ContextTag(to_underlying(Tag::kEnableTagCompression)), aEnableTagCompression); + } + return *this; +} + +AttributePathIB::Builder & AttributePathIB::Builder::Node(const NodeId aNode) +{ + // skip if error has already been set + if (mError == CHIP_NO_ERROR) + { + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kNode)), aNode); + } + return *this; +} + +AttributePathIB::Builder & AttributePathIB::Builder::Endpoint(const EndpointId aEndpoint) +{ + // skip if error has already been set + if (mError == CHIP_NO_ERROR) + { + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kEndpoint)), aEndpoint); + } + return *this; +} + +AttributePathIB::Builder & AttributePathIB::Builder::Cluster(const ClusterId aCluster) +{ + // skip if error has already been set + if (mError == CHIP_NO_ERROR) + { + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kCluster)), aCluster); + } + return *this; +} + +AttributePathIB::Builder & AttributePathIB::Builder::Attribute(const AttributeId aAttribute) +{ + // skip if error has already been set + if (mError == CHIP_NO_ERROR) + { + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kAttribute)), aAttribute); + } + return *this; +} + +AttributePathIB::Builder & AttributePathIB::Builder::ListIndex(const chip::ListIndex aListIndex) +{ + // skip if error has already been set + if (mError == CHIP_NO_ERROR) + { + mError = mpWriter->Put(TLV::ContextTag(to_underlying(Tag::kListIndex)), aListIndex); + } + return *this; +} + +AttributePathIB::Builder & AttributePathIB::Builder::EndOfAttributePathIB() +{ + EndOfContainer(); + return *this; +} +}; // namespace app +}; // namespace chip diff --git a/src/app/MessageDef/AttributePath.h b/src/app/MessageDef/AttributePathIB.h similarity index 50% rename from src/app/MessageDef/AttributePath.h rename to src/app/MessageDef/AttributePathIB.h index 790581dd74b178..2c45ce992710e1 100644 --- a/src/app/MessageDef/AttributePath.h +++ b/src/app/MessageDef/AttributePathIB.h @@ -15,16 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @file - * This file defines AttributePath parser and builder in CHIP interaction model - * - */ #pragma once -#include "Builder.h" -#include "Parser.h" +#include "ListBuilder.h" +#include "ListParser.h" #include #include @@ -35,28 +30,20 @@ namespace chip { namespace app { -namespace AttributePath { -enum +namespace AttributePathIB { +enum class Tag : uint8_t { - kCsTag_NodeId = 0, - kCsTag_EndpointId = 1, - kCsTag_ClusterId = 2, - kCsTag_FieldId = 3, - kCsTag_ListIndex = 4, + kEnableTagCompression = 0, + kNode = 1, + kEndpoint = 2, + kCluster = 3, + kAttribute = 4, + kListIndex = 5, }; -class Parser : public chip::app::Parser +class Parser : public ListParser { public: - /** - * @brief Initialize the parser object with TLVReader - * - * @param [in] aReader A pointer to a TLVReader, which should point to the beginning of this AttributePath - * - * @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 @@ -74,141 +61,138 @@ class Parser : public chip::app::Parser CHIP_ERROR CheckSchemaValidity() const; #endif /** - * @brief Get a TLVReader for the NodeId. Next() must be called before accessing them. + * @brief Get the EnableTagCompression * * @param [in] apNodeId A pointer to apNodeId * * @return #CHIP_NO_ERROR on success - * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types + * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not boolean types * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetNodeId(chip::NodeId * const apNodeId) const; + CHIP_ERROR GetEnableTagCompression(bool * const apEnableTagCompression) const; /** - * @brief Get a TLVReader for the EndpointId. Next() must be called before accessing them. + * @brief Get the NodeId * - * @param [in] apEndpointId A pointer to apEndpointId + * @param [in] apNodeId A pointer to apNodeId * * @return #CHIP_NO_ERROR on success * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetEndpointId(chip::EndpointId * const apEndpointId) const; + CHIP_ERROR GetNode(NodeId * const apNode) const; /** - * @brief Get a TLVReader for the ClusterId. Next() must be called before accessing them. + * @brief Get the Endpoint. * - * @param [in] apClusterId A pointer to apClusterId + * @param [in] apEndpoint A pointer to apEndpoint * * @return #CHIP_NO_ERROR on success * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetClusterId(chip::ClusterId * const apClusterId) const; + CHIP_ERROR GetEndpoint(EndpointId * const apEndpoint) const; /** - * @brief Get a TLVReader for the FieldId. Next() must be called before accessing them. + * @brief Get the Cluster. * - * @param [in] apFieldId A pointer to apFieldId + * @param [in] apCluster A pointer to apCluster * * @return #CHIP_NO_ERROR on success * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetFieldId(chip::AttributeId * const apFieldId) const; + CHIP_ERROR GetCluster(ClusterId * const apCluster) const; /** - * @brief Get a TLVReader for the ListIndex. Next() must be called before accessing them. + * @brief Get the Attribute. * - * @param [in] apListIndex A pointer to apListIndex + * @param [in] apAttribute A pointer to apAttribute * * @return #CHIP_NO_ERROR on success * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetListIndex(chip::ListIndex * const apListIndex) const; -}; + CHIP_ERROR GetAttribute(AttributeId * const apAttribute) const; -class Builder : public chip::app::Builder -{ -public: /** - * @brief Initialize a AttributePath::Builder for writing into a TLV stream + * @brief Get the ListIndex. * - * @param [in] apWriter A pointer to TLVWriter + * @param [in] apListIndex A pointer to apListIndex * * @return #CHIP_NO_ERROR on success + * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types + * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter); + CHIP_ERROR GetListIndex(ListIndex * const apListIndex) const; +}; +class Builder : public ListBuilder +{ +public: /** - * Init the AttributePath container with an particular context tag. - * Required to implement arrays of arrays, and to test ListBuilder. + * @brief Inject EnableTagCompression into the TLV stream. * - * @param[in] apWriter Pointer to the TLVWriter that is encoding the message. - * @param[in] aContextTagToUse A contextTag to use. + * @param [in] aEnableTagCompression When false or not present, omission of any of the tags in question + * (with the exception of Node) indicates wildcard semantics. When true, indicates the use of + * a tag compression scheme * - * @return CHIP_ERROR codes returned by chip::TLV objects. + * @return A reference to *this */ - CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter, const uint8_t aContextTagToUse); + AttributePathIB::Builder & EnableTagCompression(const bool aEnableTagCompression); /** - * @brief Inject NodeId into the TLV stream. + * @brief Inject Node into the TLV stream. * - * @param [in] aNodeId NodeId for this attribute path + * @param [in] aNode Node for this attribute path * * @return A reference to *this */ - AttributePath::Builder & NodeId(const chip::NodeId aNodeId); + AttributePathIB::Builder & Node(const NodeId aNode); /** - * @brief Inject EndpointId into the TLV stream. + * @brief Inject Endpoint into the TLV stream. * - * @param [in] aEndpointId NodeId for this attribute path + * @param [in] aEndpoint Endpoint for this attribute path * * @return A reference to *this */ - AttributePath::Builder & EndpointId(const chip::EndpointId aEndpointId); + AttributePathIB::Builder & Endpoint(const EndpointId aEndpoint); /** - * @brief Inject ClusterId into the TLV stream. + * @brief Inject Cluster into the TLV stream. * - * @param [in] aClusterId ClusterId for this attribute path + * @param [in] aCluster Cluster for this attribute path * * @return A reference to *this */ - AttributePath::Builder & ClusterId(const chip::ClusterId aClusterId); + AttributePathIB::Builder & Cluster(const ClusterId aCluster); /** - * @brief Inject FieldId into the TLV stream. + * @brief Inject Attribute into the TLV stream. * - * @param [in] aFieldId FieldId for this attribute path + * @param [in] aAttribute Attribute for this attribute path * * @return A reference to *this */ - AttributePath::Builder & FieldId(const chip::AttributeId aFieldId); + AttributePathIB::Builder & Attribute(const AttributeId aAttribute); /** - * @brief Inject NodeId into the TLV stream. + * @brief Inject ListIndex into the TLV stream. * - * @param [in] aListIndex NodeId for this attribute path + * @param [in] aListIndex ListIndex for this attribute path * * @return A reference to *this */ - AttributePath::Builder & ListIndex(const chip::ListIndex aListIndex); + AttributePathIB::Builder & ListIndex(const chip::ListIndex aListIndex); /** - * @brief Mark the end of this AttributePath + * @brief Mark the end of this AttributePathIB * * @return A reference to *this */ - AttributePath::Builder & EndOfAttributePath(); - -private: - CHIP_ERROR _Init(TLV::TLVWriter * const apWriter, const TLV::Tag aTag); + AttributePathIB::Builder & EndOfAttributePathIB(); }; - -}; // namespace AttributePath - -}; // namespace app -}; // namespace chip +}; // namespace AttributePathIB +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/AttributePathList.cpp b/src/app/MessageDef/AttributePathList.cpp deleted file mode 100644 index 3bf40fec4cf054..00000000000000 --- a/src/app/MessageDef/AttributePathList.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/** - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2018 Google LLC. - * Copyright (c) 2016-2017 Nest Labs, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * This file defines AttributePathList parser and builder in CHIP interaction model - * - */ - -#include "AttributePathList.h" - -#include "MessageDefHelper.h" - -#include -#include -#include - -#include - -using namespace chip; -using namespace chip::TLV; - -namespace chip { -namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK -CHIP_ERROR AttributePathList::Parser::CheckSchemaValidity() const -{ - CHIP_ERROR err = CHIP_NO_ERROR; - size_t NumPath = 0; - chip::TLV::TLVReader reader; - - PRETTY_PRINT("AttributePathList ="); - PRETTY_PRINT("["); - - // make a copy of the AttributePathList reader - reader.Init(mReader); - - while (CHIP_NO_ERROR == (err = reader.Next())) - { - VerifyOrExit(chip::TLV::AnonymousTag == reader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG); - VerifyOrExit(chip::TLV::kTLVType_List == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - { - AttributePath::Parser path; - err = path.Init(reader); - SuccessOrExit(err); - - PRETTY_PRINT_INCDEPTH(); - err = path.CheckSchemaValidity(); - SuccessOrExit(err); - PRETTY_PRINT_DECDEPTH(); - } - - ++NumPath; - } - - PRETTY_PRINT("],"); - PRETTY_PRINT("\t"); - // if we have exhausted this container - if (CHIP_END_OF_TLV == err) - { - err = CHIP_NO_ERROR; - } - SuccessOrExit(err); - err = reader.ExitContainer(mOuterContainerType); - -exit: - - return err; -} -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK - -// Re-initialize the shared PathBuilder with anonymous tag -AttributePath::Builder & AttributePathList::Builder::CreateAttributePathBuilder() -{ - // skip if error has already been set - VerifyOrExit(CHIP_NO_ERROR == mError, mAttributePathBuilder.ResetError(mError)); - - mError = mAttributePathBuilder.Init(mpWriter); - -exit: - // on error, mAttributePathBuilder would be un-/partial initialized and cannot be used to write anything - return mAttributePathBuilder; -} - -// Mark the end of this array and recover the type for outer container -AttributePathList::Builder & AttributePathList::Builder::EndOfAttributePathList() -{ - EndOfContainer(); - - return *this; -} -}; // namespace app -}; // namespace chip diff --git a/src/app/MessageDef/AttributePaths.cpp b/src/app/MessageDef/AttributePaths.cpp new file mode 100644 index 00000000000000..37da11584d0f01 --- /dev/null +++ b/src/app/MessageDef/AttributePaths.cpp @@ -0,0 +1,92 @@ +/** + * + * Copyright (c) 2020 Project CHIP Authors + * Copyright (c) 2018 Google LLC. + * Copyright (c) 2016-2017 Nest Labs, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AttributePaths.h" +#include "MessageDefHelper.h" + +#include +#include +#include + +#include + +namespace chip { +namespace app { +#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +CHIP_ERROR AttributePaths::Parser::CheckSchemaValidity() const +{ + CHIP_ERROR err = CHIP_NO_ERROR; + size_t numAttributePath = 0; + TLV::TLVReader reader; + + PRETTY_PRINT("AttributePaths ="); + PRETTY_PRINT("["); + + // make a copy of the AttributePaths reader + reader.Init(mReader); + + while (CHIP_NO_ERROR == (err = reader.Next())) + { + VerifyOrReturnError(TLV::AnonymousTag == reader.GetTag(), CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrReturnError(TLV::kTLVType_List == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + { + AttributePathIB::Parser path; + ReturnErrorOnFailure(path.Init(reader)); + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(path.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + + ++numAttributePath; + } + + PRETTY_PRINT("],"); + PRETTY_PRINT("\t"); + + // if we have exhausted this container + if (CHIP_END_OF_TLV == err) + { + // if we have at least one data element + if (numAttributePath > 0) + { + err = CHIP_NO_ERROR; + } + } + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); + return CHIP_NO_ERROR; +} +#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK + +AttributePathIB::Builder & AttributePaths::Builder::CreateAttributePath() +{ + if (mError == CHIP_NO_ERROR) + { + mError = mAttributePath.Init(mpWriter); + } + return mAttributePath; +} + +// Mark the end of this array and recover the type for outer container +AttributePaths::Builder & AttributePaths::Builder::EndOfAttributePaths() +{ + EndOfContainer(); + return *this; +} +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/AttributePathList.h b/src/app/MessageDef/AttributePaths.h similarity index 75% rename from src/app/MessageDef/AttributePathList.h rename to src/app/MessageDef/AttributePaths.h index 11b475596a228b..d5a2836fb1b5fc 100644 --- a/src/app/MessageDef/AttributePathList.h +++ b/src/app/MessageDef/AttributePaths.h @@ -15,17 +15,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @file - * This file defines AttributePathList parser and builder in CHIP interaction model - * - */ #pragma once #include "ArrayBuilder.h" #include "ArrayParser.h" -#include "AttributePath.h" +#include "AttributePathIB.h" #include #include @@ -36,7 +31,7 @@ namespace chip { namespace app { -namespace AttributePathList { +namespace AttributePaths { class Parser : public ArrayParser { public: @@ -62,22 +57,22 @@ class Builder : public ArrayBuilder { public: /** - * @brief Initialize a AttributePath::Builder for writing into the TLV stream + * @brief Initialize a AttributePathIB::Builder for writing into the TLV stream * - * @return A reference to AttributePath::Builder + * @return A reference to AttributePathIB::Builder */ - AttributePath::Builder & CreateAttributePathBuilder(); + AttributePathIB::Builder & CreateAttributePath(); /** - * @brief Mark the end of this AttributePath + * @brief Mark the end of this AttributePathIB * * @return A reference to *this */ - AttributePathList::Builder & EndOfAttributePathList(); + AttributePaths::Builder & EndOfAttributePaths(); private: - AttributePath::Builder mAttributePathBuilder; + AttributePathIB::Builder mAttributePath; }; -}; // namespace AttributePathList -}; // namespace app -}; // namespace chip +} // namespace AttributePaths +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/AttributeStatusIB.cpp b/src/app/MessageDef/AttributeStatusIB.cpp index ddd7f9389524a6..c6124ed3c2669e 100644 --- a/src/app/MessageDef/AttributeStatusIB.cpp +++ b/src/app/MessageDef/AttributeStatusIB.cpp @@ -1,8 +1,6 @@ /** * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2018 Google LLC. - * Copyright (c) 2016-2017 Nest Labs, Inc. + * Copyright (c) 2021 Project CHIP Authors * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,15 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @file - * This file defines AttributeStatusIB parser and builder in CHIP interaction model - * - */ #include "AttributeStatusIB.h" - #include "MessageDefHelper.h" +#include "StructBuilder.h" +#include "StructParser.h" #include #include @@ -31,64 +25,14 @@ #include -using namespace chip; -using namespace chip::TLV; - namespace chip { namespace app { -CHIP_ERROR AttributeStatusIB::Builder::Init(chip::TLV::TLVWriter * const apWriter) -{ - return InitAnonymousStructure(apWriter); -} - -AttributePath::Builder & AttributeStatusIB::Builder::CreateAttributePathBuilder() -{ - // skip if error has already been set - VerifyOrExit(CHIP_NO_ERROR == mError, mAttributePathBuilder.ResetError(mError)); - - mError = mAttributePathBuilder.Init(mpWriter, kCsTag_AttributePath); - -exit: - return mAttributePathBuilder; -} - -StatusIB::Builder & AttributeStatusIB::Builder::CreateStatusIBBuilder() -{ - // skip if error has already been set - VerifyOrExit(CHIP_NO_ERROR == mError, mStatusIBBuilder.ResetError(mError)); - - mError = mStatusIBBuilder.Init(mpWriter, kCsTag_StatusIB); - -exit: - return mStatusIBBuilder; -} - -AttributeStatusIB::Builder & AttributeStatusIB::Builder::EndOfAttributeStatusIB() -{ - EndOfContainer(); - return *this; -} - -CHIP_ERROR AttributeStatusIB::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 AttributeStatusIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - uint16_t TagPresenceMask = 0; - chip::TLV::TLVReader reader; + CHIP_ERROR err = CHIP_NO_ERROR; + int TagPresenceMask = 0; + TLV::TLVReader reader; PRETTY_PRINT("AttributeStatusIB ="); PRETTY_PRINT("{"); @@ -98,105 +42,99 @@ CHIP_ERROR AttributeStatusIB::Parser::CheckSchemaValidity() const while (CHIP_NO_ERROR == (err = reader.Next())) { - VerifyOrExit(chip::TLV::IsContextTag(reader.GetTag()), err = CHIP_ERROR_INVALID_TLV_TAG); - switch (chip::TLV::TagNumFromTag(reader.GetTag())) + VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG); + uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); + switch (tagNum) { - case kCsTag_AttributePath: - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_AttributePath)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_AttributePath); + case to_underlying(Tag::kPath): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kPath))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kPath)); { - AttributePath::Parser path; - err = path.Init(reader); - SuccessOrExit(err); + AttributePathIB::Parser path; + ReturnErrorOnFailure(path.Init(reader)); PRETTY_PRINT_INCDEPTH(); - err = path.CheckSchemaValidity(); - SuccessOrExit(err); + ReturnErrorOnFailure(path.CheckSchemaValidity()); PRETTY_PRINT_DECDEPTH(); } break; - case kCsTag_StatusIB: - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_StatusIB)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_StatusIB); + case to_underlying(Tag::kErrorStatus): + // check if this tag has appeared before + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kErrorStatus))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kErrorStatus)); { - StatusIB::Parser status; - err = status.Init(reader); - SuccessOrExit(err); + StatusIB::Parser errorStatus; + ReturnErrorOnFailure(errorStatus.Init(reader)); PRETTY_PRINT_INCDEPTH(); - err = status.CheckSchemaValidity(); - SuccessOrExit(err); + ReturnErrorOnFailure(errorStatus.CheckSchemaValidity()); PRETTY_PRINT_DECDEPTH(); } break; default: - ExitNow(err = CHIP_ERROR_INVALID_TLV_TAG); + PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); + break; } } PRETTY_PRINT("},"); PRETTY_PRINT(""); - // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - // check for required fields: - const uint16_t RequiredFields = (1 << kCsTag_AttributePath) | (1 << kCsTag_StatusIB); + const int RequiredFields = (1 << to_underlying(Tag::kPath)) | (1 << to_underlying(Tag::kErrorStatus)); if ((TagPresenceMask & RequiredFields) == RequiredFields) { err = CHIP_NO_ERROR; } - else - { - err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_STATUS_ELEMENT; - } } - SuccessOrExit(err); - err = reader.ExitContainer(mOuterContainerType); - -exit: - return err; + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); + return CHIP_NO_ERROR; } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK -CHIP_ERROR AttributeStatusIB::Parser::GetAttributePath(AttributePath::Parser * const apAttributePath) const +CHIP_ERROR AttributeStatusIB::Parser::GetPath(AttributePathIB::Parser * const apPath) const { - CHIP_ERROR err = CHIP_NO_ERROR; - chip::TLV::TLVReader reader; - - err = mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_AttributePath), reader); - SuccessOrExit(err); - - VerifyOrExit(chip::TLV::kTLVType_List == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - err = apAttributePath->Init(reader); - SuccessOrExit(err); - -exit: - ChipLogIfFalse((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err)); - - return err; + TLV::TLVReader reader; + ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kPath)), reader)); + ReturnErrorOnFailure(apPath->Init(reader)); + return CHIP_NO_ERROR; } -CHIP_ERROR AttributeStatusIB::Parser::GetStatusIB(StatusIB::Parser * const apStatusIB) const +CHIP_ERROR AttributeStatusIB::Parser::GetErrorStatus(StatusIB::Parser * const apErrorStatus) const { - CHIP_ERROR err = CHIP_NO_ERROR; - chip::TLV::TLVReader reader; - - err = mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_StatusIB), reader); - SuccessOrExit(err); - - VerifyOrExit(chip::TLV::kTLVType_Structure == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); + TLV::TLVReader reader; + ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kErrorStatus)), reader)); + ReturnErrorOnFailure(apErrorStatus->Init(reader)); + return CHIP_NO_ERROR; +} - err = apStatusIB->Init(reader); - SuccessOrExit(err); +AttributePathIB::Builder & AttributeStatusIB::Builder::CreatePath() +{ + if (mError == CHIP_NO_ERROR) + { + mError = mPath.Init(mpWriter, to_underlying(Tag::kPath)); + } + return mPath; +} -exit: - ChipLogIfFalse((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err)); +StatusIB::Builder & AttributeStatusIB::Builder::CreateErrorStatus() +{ + if (mError == CHIP_NO_ERROR) + { + mError = mErrorStatus.Init(mpWriter, to_underlying(Tag::kErrorStatus)); + } + return mErrorStatus; +} - return err; +AttributeStatusIB::Builder & AttributeStatusIB::Builder::EndOfAttributeStatusIB() +{ + EndOfContainer(); + return *this; } -}; // namespace app -}; // namespace chip +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/AttributeStatusIB.h b/src/app/MessageDef/AttributeStatusIB.h index 05918d6df72f10..35358fc2d2d8f5 100644 --- a/src/app/MessageDef/AttributeStatusIB.h +++ b/src/app/MessageDef/AttributeStatusIB.h @@ -1,7 +1,6 @@ /** * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2016-2017 Nest Labs, Inc. + * Copyright (c) 2021 Project CHIP Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,18 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @file - * This file defines AttributeStatusIB parser and builder in CHIP interaction model - * - */ #pragma once -#include "AttributePath.h" -#include "Builder.h" -#include "Parser.h" +#include "AttributePathIB.h" #include "StatusIB.h" +#include "StructBuilder.h" +#include "StructParser.h" #include #include @@ -38,61 +32,15 @@ namespace chip { namespace app { namespace AttributeStatusIB { -enum -{ - kCsTag_AttributePath = 0, - kCsTag_StatusIB = 1, -}; - -class Builder : public chip::app::Builder +enum class Tag : uint8_t { -public: - /** - * @brief Initialize a AttributeStatusIB::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 AttributePath::Builder for writing into the TLV stream - * - * @return A reference to AttributePath::Builder - */ - AttributePath::Builder & CreateAttributePathBuilder(); - - /** - * @brief Initialize a StatusIB::Builder for writing into the TLV stream - * - * @return A reference to StatusIB::Builder - */ - StatusIB::Builder & CreateStatusIBBuilder(); - - /** - * @brief Mark the end of this AttributeStatusIB - * - * @return A reference to *this - */ - AttributeStatusIB::Builder & EndOfAttributeStatusIB(); - -private: - AttributePath::Builder mAttributePathBuilder; - StatusIB::Builder mStatusIBBuilder; + kPath = 0, + kErrorStatus = 1, }; -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 AttributeStatusIB - * - * @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 @@ -111,28 +59,56 @@ class Parser : public chip::app::Parser #endif /** - * @brief Get a TLVReader for the AttributePath. Next() must be called before accessing them. + * @brief Get a TLVReader for the AttributePathIB. Next() must be called before accessing them. * - * @param [in] apAttributePath A pointer to apAttributePath + * @param [in] apPath A pointer to apPath * * @return #CHIP_NO_ERROR on success * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not a Path * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetAttributePath(AttributePath::Parser * const apAttributePath) const; + CHIP_ERROR GetPath(AttributePathIB::Parser * const apPath) const; /** * @brief Get a TLVReader for the StatusIB. Next() must be called before accessing them. * - * @param [in] apStatusIB A pointer to apStatusIB + * @param [in] apErrorStatus A pointer to apErrorStatus * * @return #CHIP_NO_ERROR on success - * #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not a Path + * # CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not a structure * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetStatusIB(StatusIB::Parser * const apStatusIB) const; + CHIP_ERROR GetErrorStatus(StatusIB::Parser * const apErrorStatus) const; }; -}; // namespace AttributeStatusIB -}; // namespace app -}; // namespace chip +class Builder : public StructBuilder +{ +public: + /** + * @brief Initialize a AttributePathIB::Builder for writing into the TLV stream + * + * @return A reference to AttributePathIB::Builder + */ + AttributePathIB::Builder & CreatePath(); + + /** + * @brief Initialize a StatusIB::Builder for writing into the TLV stream + * + * @return A reference to StatusIB::Builder + */ + StatusIB::Builder & CreateErrorStatus(); + + /** + * @brief Mark the end of this AttributeStatusIB + * + * @return A reference to *this + */ + AttributeStatusIB::Builder & EndOfAttributeStatusIB(); + +private: + AttributePathIB::Builder mPath; + StatusIB::Builder mErrorStatus; +}; +} // namespace AttributeStatusIB +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/AttributeStatusList.cpp b/src/app/MessageDef/AttributeStatuses.cpp similarity index 56% rename from src/app/MessageDef/AttributeStatusList.cpp rename to src/app/MessageDef/AttributeStatuses.cpp index e9d231edaa42d7..d2ff58ad866b92 100644 --- a/src/app/MessageDef/AttributeStatusList.cpp +++ b/src/app/MessageDef/AttributeStatuses.cpp @@ -15,13 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @file - * This file defines AttributeStatusList parser and builder in CHIP interaction model - * - */ -#include "AttributeStatusList.h" +#include "AttributeStatuses.h" #include "AttributeStatusIB.h" #include "MessageDefHelper.h" @@ -32,36 +27,31 @@ #include -using namespace chip; -using namespace chip::TLV; - namespace chip { namespace app { -AttributeStatusIB::Builder & AttributeStatusList::Builder::CreateAttributeStatusBuilder() +AttributeStatusIB::Builder & AttributeStatuses::Builder::CreateAttributeStatus() { - // skip if error has already been set - VerifyOrExit(CHIP_NO_ERROR == mError, mAttributeStatusBuilder.ResetError(mError)); - - mError = mAttributeStatusBuilder.Init(mpWriter); - -exit: - // on error, mAttributeStatusBuilder would be un-/partial initialized and cannot be used to write anything - return mAttributeStatusBuilder; + if (mError == CHIP_NO_ERROR) + { + mError = mAttributeStatus.Init(mpWriter); + } + return mAttributeStatus; } -AttributeStatusList::Builder & AttributeStatusList::Builder::EndOfAttributeStatusList() +AttributeStatuses::Builder & AttributeStatuses::Builder::EndOfAttributeStatuses() { EndOfContainer(); return *this; } + #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK -CHIP_ERROR AttributeStatusList::Parser::CheckSchemaValidity() const +CHIP_ERROR AttributeStatuses::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - size_t NumAttributeStateElement = 0; - chip::TLV::TLVReader reader; + CHIP_ERROR err = CHIP_NO_ERROR; + size_t NumAttributeStatus = 0; + TLV::TLVReader reader; - PRETTY_PRINT("AttributeStatusList ="); + PRETTY_PRINT("AttributeStatuses ="); PRETTY_PRINT("["); // make a copy of the EventReports reader @@ -69,20 +59,17 @@ CHIP_ERROR AttributeStatusList::Parser::CheckSchemaValidity() const while (CHIP_NO_ERROR == (err = reader.Next())) { - VerifyOrExit(chip::TLV::AnonymousTag == reader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG); - + VerifyOrReturnError(TLV::AnonymousTag == reader.GetTag(), CHIP_ERROR_INVALID_TLV_TAG); { AttributeStatusIB::Parser status; - err = status.Init(reader); - SuccessOrExit(err); + ReturnErrorOnFailure(status.Init(reader)); PRETTY_PRINT_INCDEPTH(); - err = status.CheckSchemaValidity(); - SuccessOrExit(err); + ReturnErrorOnFailure(status.CheckSchemaValidity()); PRETTY_PRINT_DECDEPTH(); } - ++NumAttributeStateElement; + ++NumAttributeStatus; } PRETTY_PRINT("],"); @@ -91,23 +78,20 @@ CHIP_ERROR AttributeStatusList::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { // if we have at least one data element - if (NumAttributeStateElement > 0) + if (NumAttributeStatus > 0) { err = CHIP_NO_ERROR; } // NOTE: temporarily disable this check, to allow test to continue else { - ChipLogError(DataManagement, "PROTOCOL ERROR: Empty attribute status list"); + ChipLogError(DataManagement, "PROTOCOL ERROR: Empty attribute statuses"); err = CHIP_NO_ERROR; } } - SuccessOrExit(err); - err = reader.ExitContainer(mOuterContainerType); - -exit: - - return err; + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); + return CHIP_NO_ERROR; } #endif }; // namespace app diff --git a/src/app/MessageDef/AttributeStatusList.h b/src/app/MessageDef/AttributeStatuses.h similarity index 76% rename from src/app/MessageDef/AttributeStatusList.h rename to src/app/MessageDef/AttributeStatuses.h index 78774a7fea11ee..8996d519e08700 100644 --- a/src/app/MessageDef/AttributeStatusList.h +++ b/src/app/MessageDef/AttributeStatuses.h @@ -15,11 +15,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @file - * This file defines AttributeStatusList parser and builder in CHIP interaction model - * - */ #pragma once @@ -36,26 +31,26 @@ namespace chip { namespace app { -namespace AttributeStatusList { +namespace AttributeStatuses { class Builder : public ArrayBuilder { public: /** - * @brief Initialize a AttributeStatus::Builder for writing into the TLV stream + * @brief Initialize a AttributeStatusIB::Builder for writing into the TLV stream * - * @return A reference to AttributeStatus::Builder + * @return A reference to AttributeStatusIB::Builder */ - AttributeStatusIB::Builder & CreateAttributeStatusBuilder(); + AttributeStatusIB::Builder & CreateAttributeStatus(); /** - * @brief Mark the end of this AttributeStatusList + * @brief Mark the end of this AttributeStatuses * * @return A reference to *this */ - AttributeStatusList::Builder & EndOfAttributeStatusList(); + AttributeStatuses::Builder & EndOfAttributeStatuses(); private: - AttributeStatusIB::Builder mAttributeStatusBuilder; + AttributeStatusIB::Builder mAttributeStatus; }; class Parser : public ArrayParser @@ -78,7 +73,6 @@ class Parser : public ArrayParser CHIP_ERROR CheckSchemaValidity() const; #endif }; -}; // namespace AttributeStatusList - -}; // namespace app -}; // namespace chip +} // namespace AttributeStatuses +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/ReadRequestMessage.cpp b/src/app/MessageDef/ReadRequestMessage.cpp index 911f33a48841f1..5e979cfbc026b3 100644 --- a/src/app/MessageDef/ReadRequestMessage.cpp +++ b/src/app/MessageDef/ReadRequestMessage.cpp @@ -55,7 +55,7 @@ CHIP_ERROR ReadRequestMessage::Parser::CheckSchemaValidity() const CHIP_ERROR err = CHIP_NO_ERROR; uint16_t TagPresenceMask = 0; chip::TLV::TLVReader reader; - AttributePathList::Parser attributePathList; + AttributePaths::Parser AttributePaths; EventPaths::Parser eventPathList; AttributeDataVersionList::Parser attributeDataVersionList; PRETTY_PRINT("ReadRequestMessage ="); @@ -74,11 +74,11 @@ CHIP_ERROR ReadRequestMessage::Parser::CheckSchemaValidity() const TagPresenceMask |= (1 << kCsTag_AttributePathList); VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - attributePathList.Init(reader); + AttributePaths.Init(reader); PRETTY_PRINT_INCDEPTH(); - err = attributePathList.CheckSchemaValidity(); + err = AttributePaths.CheckSchemaValidity(); SuccessOrExit(err); PRETTY_PRINT_DECDEPTH(); @@ -119,11 +119,11 @@ CHIP_ERROR ReadRequestMessage::Parser::CheckSchemaValidity() const TagPresenceMask |= (1 << kCsTag_AttributePathList); VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - attributePathList.Init(reader); + AttributePaths.Init(reader); PRETTY_PRINT_INCDEPTH(); - err = attributePathList.CheckSchemaValidity(); + err = AttributePaths.CheckSchemaValidity(); SuccessOrExit(err); PRETTY_PRINT_DECDEPTH(); @@ -161,7 +161,7 @@ CHIP_ERROR ReadRequestMessage::Parser::CheckSchemaValidity() const } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK -CHIP_ERROR ReadRequestMessage::Parser::GetAttributePathList(AttributePathList::Parser * const apAttributePathList) const +CHIP_ERROR ReadRequestMessage::Parser::GetAttributePathList(AttributePaths::Parser * const apAttributePathList) const { CHIP_ERROR err = CHIP_NO_ERROR; chip::TLV::TLVReader reader; @@ -229,7 +229,7 @@ CHIP_ERROR ReadRequestMessage::Builder::Init(chip::TLV::TLVWriter * const apWrit return InitAnonymousStructure(apWriter); } -AttributePathList::Builder & ReadRequestMessage::Builder::CreateAttributePathListBuilder() +AttributePaths::Builder & ReadRequestMessage::Builder::CreateAttributePathListBuilder() { // skip if error has already been set VerifyOrExit(CHIP_NO_ERROR == mError, mAttributePathListBuilder.ResetError(mError)); diff --git a/src/app/MessageDef/ReadRequestMessage.h b/src/app/MessageDef/ReadRequestMessage.h index 66137d53f0d602..de9e05ef6ab308 100644 --- a/src/app/MessageDef/ReadRequestMessage.h +++ b/src/app/MessageDef/ReadRequestMessage.h @@ -24,7 +24,7 @@ #pragma once #include "AttributeDataVersionList.h" -#include "AttributePathList.h" +#include "AttributePaths.h" #include "Builder.h" #include "EventPaths.h" @@ -77,14 +77,14 @@ class Parser : public chip::app::Parser #endif /** - * @brief Get a TLVReader for the AttributePathList. Next() must be called before accessing them. + * @brief Get a TLVReader for the AttributePaths. Next() must be called before accessing them. * * @param [in] apAttributePathList A pointer to an attribute path list parser. * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetAttributePathList(AttributePathList::Parser * const apAttributePathList) const; + CHIP_ERROR GetAttributePathList(AttributePaths::Parser * const apAttributePathList) const; /** * @brief Get a TLVReader for the EventPaths. Next() must be called before accessing them. @@ -130,11 +130,11 @@ class Builder : public chip::app::Builder CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter); /** - * @brief Initialize a AttributePathList::Builder for writing into the TLV stream + * @brief Initialize a AttributePaths::Builder for writing into the TLV stream * - * @return A reference to AttributePathList::Builder + * @return A reference to AttributePaths::Builder */ - AttributePathList::Builder & CreateAttributePathListBuilder(); + AttributePaths::Builder & CreateAttributePathListBuilder(); /** * @brief Initialize a EventPaths::Builder for writing into the TLV stream @@ -165,7 +165,7 @@ class Builder : public chip::app::Builder ReadRequestMessage::Builder & EndOfReadRequestMessage(); private: - AttributePathList::Builder mAttributePathListBuilder; + AttributePaths::Builder mAttributePathListBuilder; EventPaths::Builder mEventPathsBuilder; AttributeDataVersionList::Builder mAttributeDataVersionListBuilder; }; diff --git a/src/app/MessageDef/SubscribeRequestMessage.cpp b/src/app/MessageDef/SubscribeRequestMessage.cpp index 91d63c8812ce6d..75c1f5806adbbc 100644 --- a/src/app/MessageDef/SubscribeRequestMessage.cpp +++ b/src/app/MessageDef/SubscribeRequestMessage.cpp @@ -35,7 +35,7 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const CHIP_ERROR err = CHIP_NO_ERROR; uint16_t TagPresenceMask = 0; chip::TLV::TLVReader reader; - AttributePathList::Parser attributePathList; + AttributePaths::Parser AttributePaths; EventPaths::Parser eventPathList; AttributeDataVersionList::Parser attributeDataVersionList; PRETTY_PRINT("SubscribeRequestMessage ="); @@ -54,10 +54,10 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const TagPresenceMask |= (1 << kCsTag_AttributePathList); VerifyOrReturnLogError(chip::TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - attributePathList.Init(reader); + AttributePaths.Init(reader); PRETTY_PRINT_INCDEPTH(); - ReturnLogErrorOnFailure(attributePathList.CheckSchemaValidity()); + ReturnLogErrorOnFailure(AttributePaths.CheckSchemaValidity()); PRETTY_PRINT_DECDEPTH(); break; case kCsTag_EventPaths: @@ -165,7 +165,7 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK -CHIP_ERROR SubscribeRequestMessage::Parser::GetAttributePathList(AttributePathList::Parser * const apAttributePathList) const +CHIP_ERROR SubscribeRequestMessage::Parser::GetAttributePathList(AttributePaths::Parser * const apAttributePathList) const { TLV::TLVReader reader; ReturnLogErrorOnFailure(mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_AttributePathList), reader)); @@ -221,7 +221,7 @@ CHIP_ERROR SubscribeRequestMessage::Builder::Init(chip::TLV::TLVWriter * const a return InitAnonymousStructure(apWriter); } -AttributePathList::Builder & SubscribeRequestMessage::Builder::CreateAttributePathListBuilder() +AttributePaths::Builder & SubscribeRequestMessage::Builder::CreateAttributePathListBuilder() { if (mError == CHIP_NO_ERROR) { diff --git a/src/app/MessageDef/SubscribeRequestMessage.h b/src/app/MessageDef/SubscribeRequestMessage.h index 07a66db9b06c9d..c1271dfb3840a9 100644 --- a/src/app/MessageDef/SubscribeRequestMessage.h +++ b/src/app/MessageDef/SubscribeRequestMessage.h @@ -18,7 +18,7 @@ #pragma once #include "AttributeDataVersionList.h" -#include "AttributePathList.h" +#include "AttributePaths.h" #include "Builder.h" #include "EventPaths.h" #include "Parser.h" @@ -67,12 +67,12 @@ class Parser : public chip::app::Parser #endif /** - * @brief Get a TLVReader for the AttributePathList. Next() must be called before accessing them. + * @brief Get a TLVReader for the AttributePaths. Next() must be called before accessing them. * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetAttributePathList(AttributePathList::Parser * const apAttributePathList) const; + CHIP_ERROR GetAttributePathList(AttributePaths::Parser * const apAttributePathList) const; /** * @brief Get a TLVReader for the EventPaths. Next() must be called before accessing them. @@ -133,7 +133,7 @@ class Builder : public chip::app::Builder public: CHIP_ERROR Init(chip::TLV::TLVWriter * const apWriter); - AttributePathList::Builder & CreateAttributePathListBuilder(); + AttributePaths::Builder & CreateAttributePathListBuilder(); /** * @brief Initialize a EventPaths::Builder for writing into the TLV stream @@ -174,7 +174,7 @@ class Builder : public chip::app::Builder SubscribeRequestMessage::Builder & EndOfSubscribeRequestMessage(); private: - AttributePathList::Builder mAttributePathListBuilder; + AttributePaths::Builder mAttributePathListBuilder; EventPaths::Builder mEventPathsBuilder; AttributeDataVersionList::Builder mAttributeDataVersionListBuilder; }; diff --git a/src/app/MessageDef/WriteRequestMessage.h b/src/app/MessageDef/WriteRequestMessage.h index 273d932ae461bf..118dbb8bdb868d 100644 --- a/src/app/MessageDef/WriteRequestMessage.h +++ b/src/app/MessageDef/WriteRequestMessage.h @@ -79,7 +79,7 @@ class Parser : public chip::app::Parser CHIP_ERROR GetSuppressResponse(bool * const apSuppressResponse) const; /** - * @brief Get a TLVReader for the AttributePathList. Next() must be called before accessing them. + * @brief Get a TLVReader for the AttributePaths. Next() must be called before accessing them. * * @param [in] apAttributeDataList A pointer to apAttributeDataList * diff --git a/src/app/MessageDef/WriteResponseMessage.cpp b/src/app/MessageDef/WriteResponseMessage.cpp index 12cc547e23b43f..00e51a3d3a8a64 100644 --- a/src/app/MessageDef/WriteResponseMessage.cpp +++ b/src/app/MessageDef/WriteResponseMessage.cpp @@ -13,11 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @file - * This file defines WriteResponseMessage parser and builder in CHIP interaction model - * - */ #include "WriteResponseMessage.h" #include "MessageDefHelper.h" @@ -28,34 +23,15 @@ #include -using namespace chip; -using namespace chip::TLV; - namespace chip { namespace app { -CHIP_ERROR WriteResponseMessage::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 WriteResponseMessage::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - uint16_t TagPresenceMask = 0; - chip::TLV::TLVReader reader; - AttributeStatusList::Parser attributeStatusList; + CHIP_ERROR err = CHIP_NO_ERROR; + int TagPresenceMask = 0; + TLV::TLVReader reader; + AttributeStatuses::Parser writeResponses; PRETTY_PRINT("WriteResponseMessage ="); PRETTY_PRINT("{"); @@ -64,87 +40,66 @@ CHIP_ERROR WriteResponseMessage::Parser::CheckSchemaValidity() const while (CHIP_NO_ERROR == (err = reader.Next())) { - VerifyOrExit(chip::TLV::IsContextTag(reader.GetTag()), err = CHIP_ERROR_INVALID_TLV_TAG); - switch (chip::TLV::TagNumFromTag(reader.GetTag())) + VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), err = CHIP_ERROR_INVALID_TLV_TAG); + uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); + switch (tagNum) { - case kCsTag_AttributeStatusList: - VerifyOrExit(!(TagPresenceMask & (1 << kCsTag_AttributeStatusList)), err = CHIP_ERROR_INVALID_TLV_TAG); - TagPresenceMask |= (1 << kCsTag_AttributeStatusList); - VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - attributeStatusList.Init(reader); + case to_underlying(Tag::kWriteResponses): + VerifyOrReturnError(!(TagPresenceMask & (1 << to_underlying(Tag::kWriteResponses))), CHIP_ERROR_INVALID_TLV_TAG); + TagPresenceMask |= (1 << to_underlying(Tag::kWriteResponses)); + VerifyOrReturnError(TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); + ReturnErrorOnFailure(writeResponses.Init(reader)); PRETTY_PRINT_INCDEPTH(); - - err = attributeStatusList.CheckSchemaValidity(); - SuccessOrExit(err); - + ReturnErrorOnFailure(writeResponses.CheckSchemaValidity()); PRETTY_PRINT_DECDEPTH(); break; default: - ExitNow(err = CHIP_ERROR_INVALID_TLV_TAG); + PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); + break; } } PRETTY_PRINT("}"); PRETTY_PRINT(""); - // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - err = CHIP_NO_ERROR; - } - SuccessOrExit(err); - err = reader.ExitContainer(mOuterContainerType); + const int RequiredFields = (1 << to_underlying(Tag::kWriteResponses)); -exit: + if ((TagPresenceMask & RequiredFields) == RequiredFields) + { + err = CHIP_NO_ERROR; + } + } - return err; + ReturnErrorOnFailure(err); + ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType)); + return CHIP_NO_ERROR; } #endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK -CHIP_ERROR WriteResponseMessage::Parser::GetAttributeStatusList(AttributeStatusList::Parser * const apAttributeStatusList) const +CHIP_ERROR WriteResponseMessage::Parser::GetWriteResponses(AttributeStatuses::Parser * const apWriteResponses) const { - CHIP_ERROR err = CHIP_NO_ERROR; - chip::TLV::TLVReader reader; - - err = mReader.FindElementWithTag(chip::TLV::ContextTag(kCsTag_AttributeStatusList), reader); - SuccessOrExit(err); - - VerifyOrExit(chip::TLV::kTLVType_Array == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); - - err = apAttributeStatusList->Init(reader); - SuccessOrExit(err); - -exit: - ChipLogIfFalse((CHIP_NO_ERROR == err) || (CHIP_END_OF_TLV == err)); - - return err; -} - -CHIP_ERROR WriteResponseMessage::Builder::Init(chip::TLV::TLVWriter * const apWriter) -{ - return InitAnonymousStructure(apWriter); + TLV::TLVReader reader; + ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(to_underlying(Tag::kWriteResponses)), reader)); + ReturnErrorOnFailure(apWriteResponses->Init(reader)); + return CHIP_NO_ERROR; } -AttributeStatusList::Builder & WriteResponseMessage::Builder::CreateAttributeStatusListBuilder() +AttributeStatuses::Builder & WriteResponseMessage::Builder::CreateWriteResponses() { // skip if error has already been set if (mError == CHIP_NO_ERROR) { - mError = mAttributeStatusListBuilder.Init(mpWriter, kCsTag_AttributeStatusList); + mError = mWriteResponses.Init(mpWriter, to_underlying(Tag::kWriteResponses)); } - else - { - mAttributeStatusListBuilder.ResetError(mError); - } - - return mAttributeStatusListBuilder; + return mWriteResponses; } -AttributeStatusList::Builder & WriteResponseMessage::Builder::GetAttributeStatusListBuilder() +AttributeStatuses::Builder & WriteResponseMessage::Builder::GetWriteResponses() { - return mAttributeStatusListBuilder; + return mWriteResponses; } WriteResponseMessage::Builder & WriteResponseMessage::Builder::EndOfWriteResponseMessage() @@ -152,5 +107,5 @@ WriteResponseMessage::Builder & WriteResponseMessage::Builder::EndOfWriteRespons EndOfContainer(); return *this; } -}; // namespace app -}; // namespace chip +} // namespace app +} // namespace chip diff --git a/src/app/MessageDef/WriteResponseMessage.h b/src/app/MessageDef/WriteResponseMessage.h index fe41902ff356b3..c777f2c7d566d8 100644 --- a/src/app/MessageDef/WriteResponseMessage.h +++ b/src/app/MessageDef/WriteResponseMessage.h @@ -14,18 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @file - * This file defines WriteResponseMessage parser and builder in CHIP interaction model - * - */ #pragma once -#include "AttributeStatusList.h" -#include "Builder.h" +#include "AttributeStatuses.h" +#include "StructBuilder.h" -#include "Parser.h" +#include "StructParser.h" #include #include #include @@ -35,23 +30,14 @@ namespace chip { namespace app { namespace WriteResponseMessage { -enum +enum class Tag : uint8_t { - kCsTag_AttributeStatusList = 0, + kWriteResponses = 0, }; -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 response - * - * @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 @@ -66,41 +52,32 @@ class Parser : public chip::app::Parser CHIP_ERROR CheckSchemaValidity() const; /** - * @brief Get a TLVReader for the AttributeStatusList. Next() must be called before accessing them. + * @brief Get a TLVReader for the AttributeStatuses. Next() must be called before accessing them. * - * @param [in] apAttributeStatusList A pointer to apAttributeStatusList + * @param [in] apWriteResponses A pointer to apWriteResponses * * @return #CHIP_NO_ERROR on success * #CHIP_END_OF_TLV if there is no such element */ - CHIP_ERROR GetAttributeStatusList(AttributeStatusList::Parser * const apAttributeStatusList) const; + CHIP_ERROR GetWriteResponses(AttributeStatuses::Parser * const apWriteResponses) const; }; -class Builder : public chip::app::Builder +class Builder : public StructBuilder { public: /** - * @brief Initialize a WriteResponseMessage::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 AttributeStatusList::Builder for writing into the TLV stream + * @brief Initialize a AttributeStatuses::Builder for writing into the TLV stream * - * @return A reference to AttributeStatusList::Builder + * @return A reference to AttributeStatuses::Builder */ - AttributeStatusList::Builder & CreateAttributeStatusListBuilder(); + AttributeStatuses::Builder & CreateWriteResponses(); /** - * @brief Get reference to AttributeStatusList::Builder + * @brief Get reference to AttributeStatuses::Builder * - * @return A reference to AttributeStatusList::Builder + * @return A reference to AttributeStatuses::Builder */ - AttributeStatusList::Builder & GetAttributeStatusListBuilder(); + AttributeStatuses::Builder & GetWriteResponses(); /** * @brief Mark the end of this WriteResponseMessage @@ -110,8 +87,8 @@ class Builder : public chip::app::Builder WriteResponseMessage::Builder & EndOfWriteResponseMessage(); private: - AttributeStatusList::Builder mAttributeStatusListBuilder; + AttributeStatuses::Builder mWriteResponses; }; -}; // namespace WriteResponseMessage -}; // namespace app -}; // namespace chip +} // namespace WriteResponseMessage +} // namespace app +} // namespace chip diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index e72563973b65c5..29b55f91559cdf 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -151,7 +151,7 @@ CHIP_ERROR ReadClient::SendReadRequest(ReadPrepareParams & aReadPrepareParams) if (aReadPrepareParams.mAttributePathParamsListSize != 0 && aReadPrepareParams.mpAttributePathParamsList != nullptr) { - AttributePathList::Builder attributePathListBuilder = request.CreateAttributePathListBuilder(); + AttributePaths::Builder attributePathListBuilder = request.CreateAttributePathListBuilder(); SuccessOrExit(err = attributePathListBuilder.GetError()); err = GenerateAttributePathList(attributePathListBuilder, aReadPrepareParams.mpAttributePathParamsList, aReadPrepareParams.mAttributePathParamsListSize); @@ -251,19 +251,19 @@ CHIP_ERROR ReadClient::GenerateEventPaths(EventPaths::Builder & aEventPathsBuild return err; } -CHIP_ERROR ReadClient::GenerateAttributePathList(AttributePathList::Builder & aAttributePathListBuilder, +CHIP_ERROR ReadClient::GenerateAttributePathList(AttributePaths::Builder & aAttributePathListBuilder, AttributePathParams * apAttributePathParamsList, size_t aAttributePathParamsListSize) { for (size_t index = 0; index < aAttributePathParamsListSize; index++) { - AttributePath::Builder attributePathBuilder = aAttributePathListBuilder.CreateAttributePathBuilder(); - attributePathBuilder.NodeId(apAttributePathParamsList[index].mNodeId) - .EndpointId(apAttributePathParamsList[index].mEndpointId) - .ClusterId(apAttributePathParamsList[index].mClusterId); + AttributePathIB::Builder attributePathBuilder = aAttributePathListBuilder.CreateAttributePath(); + attributePathBuilder.Node(apAttributePathParamsList[index].mNodeId) + .Endpoint(apAttributePathParamsList[index].mEndpointId) + .Cluster(apAttributePathParamsList[index].mClusterId); if (apAttributePathParamsList[index].mFlags.Has(AttributePathParams::Flags::kFieldIdValid)) { - attributePathBuilder.FieldId(apAttributePathParamsList[index].mFieldId); + attributePathBuilder.Attribute(apAttributePathParamsList[index].mFieldId); } if (apAttributePathParamsList[index].mFlags.Has(AttributePathParams::Flags::kListIndexValid)) @@ -273,10 +273,10 @@ CHIP_ERROR ReadClient::GenerateAttributePathList(AttributePathList::Builder & aA attributePathBuilder.ListIndex(apAttributePathParamsList[index].mListIndex); } - attributePathBuilder.EndOfAttributePath(); + attributePathBuilder.EndOfAttributePathIB(); ReturnErrorOnFailure(attributePathBuilder.GetError()); } - aAttributePathListBuilder.EndOfAttributePathList(); + aAttributePathListBuilder.EndOfAttributePaths(); return aAttributePathListBuilder.GetError(); } @@ -463,7 +463,7 @@ CHIP_ERROR ReadClient::ProcessAttributeDataList(TLV::TLVReader & aAttributeDataL { chip::TLV::TLVReader dataReader; AttributeDataElement::Parser element; - AttributePath::Parser attributePathParser; + AttributePathIB::Parser attributePathParser; ClusterInfo clusterInfo; uint16_t statusU16 = 0; auto status = Protocols::InteractionModel::Status::Success; @@ -475,16 +475,16 @@ CHIP_ERROR ReadClient::ProcessAttributeDataList(TLV::TLVReader & aAttributeDataL err = element.GetAttributePath(&attributePathParser); SuccessOrExit(err); - err = attributePathParser.GetNodeId(&(clusterInfo.mNodeId)); + err = attributePathParser.GetNode(&(clusterInfo.mNodeId)); SuccessOrExit(err); - err = attributePathParser.GetEndpointId(&(clusterInfo.mEndpointId)); + err = attributePathParser.GetEndpoint(&(clusterInfo.mEndpointId)); SuccessOrExit(err); - err = attributePathParser.GetClusterId(&(clusterInfo.mClusterId)); + err = attributePathParser.GetCluster(&(clusterInfo.mClusterId)); SuccessOrExit(err); - err = attributePathParser.GetFieldId(&(clusterInfo.mFieldId)); + err = attributePathParser.GetAttribute(&(clusterInfo.mFieldId)); if (CHIP_NO_ERROR == err) { clusterInfo.mFlags.Set(ClusterInfo::Flags::kFieldIdValid); @@ -633,7 +633,7 @@ CHIP_ERROR ReadClient::SendSubscribeRequest(ReadPrepareParams & aReadPreparePara if (aReadPrepareParams.mAttributePathParamsListSize != 0 && aReadPrepareParams.mpAttributePathParamsList != nullptr) { - AttributePathList::Builder & attributePathListBuilder = request.CreateAttributePathListBuilder(); + AttributePaths::Builder & attributePathListBuilder = request.CreateAttributePathListBuilder(); SuccessOrExit(err = attributePathListBuilder.GetError()); err = GenerateAttributePathList(attributePathListBuilder, aReadPrepareParams.mpAttributePathParamsList, aReadPrepareParams.mAttributePathParamsListSize); diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h index 86508c425c3ada..718dbd11594027 100644 --- a/src/app/ReadClient.h +++ b/src/app/ReadClient.h @@ -239,7 +239,7 @@ class ReadClient : public Messaging::ExchangeDelegate CHIP_ERROR GenerateEventPaths(EventPaths::Builder & aEventPathsBuilder, EventPathParams * apEventPathParamsList, size_t aEventPathParamsListSize); - CHIP_ERROR GenerateAttributePathList(AttributePathList::Builder & aAttributeathListBuilder, + CHIP_ERROR GenerateAttributePathList(AttributePaths::Builder & aAttributeathListBuilder, AttributePathParams * apAttributePathParamsList, size_t aAttributePathParamsListSize); CHIP_ERROR ProcessAttributeDataList(TLV::TLVReader & aAttributeDataListReader); diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index c2ec72d32f3924..f6d5b1f4eb30cc 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -259,7 +259,7 @@ CHIP_ERROR ReadHandler::ProcessReadRequest(System::PacketBufferHandle && aPayloa ReadRequestMessage::Parser readRequestParser; EventPaths::Parser eventPathListParser; - AttributePathList::Parser attributePathListParser; + AttributePaths::Parser attributePathListParser; reader.Init(std::move(aPayload)); @@ -321,7 +321,7 @@ CHIP_ERROR ReadHandler::ProcessReadRequest(System::PacketBufferHandle && aPayloa return err; } -CHIP_ERROR ReadHandler::ProcessAttributePathList(AttributePathList::Parser & aAttributePathListParser) +CHIP_ERROR ReadHandler::ProcessAttributePathList(AttributePaths::Parser & aAttributePathListParser) { CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; @@ -332,16 +332,16 @@ CHIP_ERROR ReadHandler::ProcessAttributePathList(AttributePathList::Parser & aAt VerifyOrExit(TLV::AnonymousTag == reader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG); VerifyOrExit(TLV::kTLVType_List == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); ClusterInfo clusterInfo; - AttributePath::Parser path; + AttributePathIB::Parser path; err = path.Init(reader); SuccessOrExit(err); - err = path.GetNodeId(&(clusterInfo.mNodeId)); + err = path.GetNode(&(clusterInfo.mNodeId)); SuccessOrExit(err); - err = path.GetEndpointId(&(clusterInfo.mEndpointId)); + err = path.GetEndpoint(&(clusterInfo.mEndpointId)); SuccessOrExit(err); - err = path.GetClusterId(&(clusterInfo.mClusterId)); + err = path.GetCluster(&(clusterInfo.mClusterId)); SuccessOrExit(err); - err = path.GetFieldId(&(clusterInfo.mFieldId)); + err = path.GetAttribute(&(clusterInfo.mFieldId)); if (CHIP_NO_ERROR == err) { clusterInfo.mFlags.Set(ClusterInfo::Flags::kFieldIdValid); @@ -532,7 +532,7 @@ CHIP_ERROR ReadHandler::ProcessSubscribeRequest(System::PacketBufferHandle && aP ReturnLogErrorOnFailure(subscribeRequestParser.CheckSchemaValidity()); #endif - AttributePathList::Parser attributePathListParser; + AttributePaths::Parser attributePathListParser; CHIP_ERROR err = subscribeRequestParser.GetAttributePathList(&attributePathListParser); if (err == CHIP_END_OF_TLV) { diff --git a/src/app/ReadHandler.h b/src/app/ReadHandler.h index da7e3dcc76866f..9e1b276dc32779 100644 --- a/src/app/ReadHandler.h +++ b/src/app/ReadHandler.h @@ -152,7 +152,7 @@ class ReadHandler : public Messaging::ExchangeDelegate CHIP_ERROR SendSubscribeResponse(); CHIP_ERROR ProcessSubscribeRequest(System::PacketBufferHandle && aPayload); CHIP_ERROR ProcessReadRequest(System::PacketBufferHandle && aPayload); - CHIP_ERROR ProcessAttributePathList(AttributePathList::Parser & aAttributePathListParser); + CHIP_ERROR ProcessAttributePathList(AttributePaths::Parser & aAttributePathListParser); CHIP_ERROR ProcessEventPaths(EventPaths::Parser & aEventPathsParser); CHIP_ERROR OnStatusResponse(Messaging::ExchangeContext * apExchangeContext, System::PacketBufferHandle && aPayload); CHIP_ERROR OnMessageReceived(Messaging::ExchangeContext * apExchangeContext, const PayloadHeader & aPayloadHeader, diff --git a/src/app/WriteClient.cpp b/src/app/WriteClient.cpp index ad18fa9399baa9..8681ad7ce0cd9f 100644 --- a/src/app/WriteClient.cpp +++ b/src/app/WriteClient.cpp @@ -90,9 +90,9 @@ CHIP_ERROR WriteClient::ProcessWriteResponseMessage(System::PacketBufferHandle & { CHIP_ERROR err = CHIP_NO_ERROR; System::PacketBufferTLVReader reader; - TLV::TLVReader attributeStatusListReader; + TLV::TLVReader attributeStatusesReader; WriteResponseMessage::Parser writeResponse; - AttributeStatusList::Parser attributeStatusListParser; + AttributeStatuses::Parser attributeStatusesParser; reader.Init(std::move(payload)); err = reader.Next(); @@ -105,18 +105,18 @@ CHIP_ERROR WriteClient::ProcessWriteResponseMessage(System::PacketBufferHandle & err = writeResponse.CheckSchemaValidity(); SuccessOrExit(err); #endif - err = writeResponse.GetAttributeStatusList(&attributeStatusListParser); + err = writeResponse.GetWriteResponses(&attributeStatusesParser); SuccessOrExit(err); - attributeStatusListParser.GetReader(&attributeStatusListReader); + attributeStatusesParser.GetReader(&attributeStatusesReader); - while (CHIP_NO_ERROR == (err = attributeStatusListReader.Next())) + while (CHIP_NO_ERROR == (err = attributeStatusesReader.Next())) { - VerifyOrExit(TLV::AnonymousTag == attributeStatusListReader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG); + VerifyOrExit(TLV::AnonymousTag == attributeStatusesReader.GetTag(), err = CHIP_ERROR_INVALID_TLV_TAG); AttributeStatusIB::Parser element; - err = element.Init(attributeStatusListReader); + err = element.Init(attributeStatusesReader); SuccessOrExit(err); err = ProcessAttributeStatusIB(element); @@ -171,10 +171,10 @@ TLV::TLVWriter * WriteClient::GetAttributeDataElementTLVWriter() CHIP_ERROR WriteClient::ConstructAttributePath(const AttributePathParams & aAttributePathParams, AttributeDataElement::Builder aAttributeDataElement) { - AttributePath::Builder attributePath = aAttributeDataElement.CreateAttributePathBuilder(); + AttributePathIB::Builder attributePath = aAttributeDataElement.CreateAttributePath(); if (aAttributePathParams.mFlags.Has(AttributePathParams::Flags::kFieldIdValid)) { - attributePath.FieldId(aAttributePathParams.mFieldId); + attributePath.Attribute(aAttributePathParams.mFieldId); } if (aAttributePathParams.mFlags.Has(AttributePathParams::Flags::kListIndexValid)) @@ -182,10 +182,10 @@ CHIP_ERROR WriteClient::ConstructAttributePath(const AttributePathParams & aAttr attributePath.ListIndex(aAttributePathParams.mListIndex); } - attributePath.NodeId(aAttributePathParams.mNodeId) - .ClusterId(aAttributePathParams.mClusterId) - .EndpointId(aAttributePathParams.mEndpointId) - .EndOfAttributePath(); + attributePath.Node(aAttributePathParams.mNodeId) + .Cluster(aAttributePathParams.mClusterId) + .Endpoint(aAttributePathParams.mEndpointId) + .EndOfAttributePathIB(); return attributePath.GetError(); } @@ -320,22 +320,22 @@ void WriteClient::OnResponseTimeout(Messaging::ExchangeContext * apExchangeConte CHIP_ERROR WriteClient::ProcessAttributeStatusIB(AttributeStatusIB::Parser & aAttributeStatusIB) { CHIP_ERROR err = CHIP_NO_ERROR; - AttributePath::Parser attributePath; + AttributePathIB::Parser attributePath; StatusIB statusIB; StatusIB::Parser StatusIBParser; AttributePathParams attributePathParams; mAttributeStatusIndex++; - err = aAttributeStatusIB.GetAttributePath(&attributePath); + err = aAttributeStatusIB.GetPath(&attributePath); SuccessOrExit(err); - err = attributePath.GetNodeId(&(attributePathParams.mNodeId)); + err = attributePath.GetNode(&(attributePathParams.mNodeId)); SuccessOrExit(err); - err = attributePath.GetClusterId(&(attributePathParams.mClusterId)); + err = attributePath.GetCluster(&(attributePathParams.mClusterId)); SuccessOrExit(err); - err = attributePath.GetEndpointId(&(attributePathParams.mEndpointId)); + err = attributePath.GetEndpoint(&(attributePathParams.mEndpointId)); SuccessOrExit(err); - err = attributePath.GetFieldId(&(attributePathParams.mFieldId)); + err = attributePath.GetAttribute(&(attributePathParams.mFieldId)); if (CHIP_NO_ERROR == err) { attributePathParams.mFlags.Set(AttributePathParams::Flags::kFieldIdValid); @@ -354,7 +354,7 @@ CHIP_ERROR WriteClient::ProcessAttributeStatusIB(AttributeStatusIB::Parser & aAt attributePathParams.mFlags.Set(AttributePathParams::Flags::kListIndexValid); } - err = aAttributeStatusIB.GetStatusIB(&(StatusIBParser)); + err = aAttributeStatusIB.GetErrorStatus(&(StatusIBParser)); if (CHIP_NO_ERROR == err) { err = StatusIBParser.DecodeStatusIB(statusIB); diff --git a/src/app/WriteHandler.cpp b/src/app/WriteHandler.cpp index 87d8a9eeb7c6c5..78f802a1306340 100644 --- a/src/app/WriteHandler.cpp +++ b/src/app/WriteHandler.cpp @@ -37,8 +37,8 @@ CHIP_ERROR WriteHandler::Init(InteractionModelDelegate * apDelegate) mMessageWriter.Init(std::move(packet)); ReturnLogErrorOnFailure(mWriteResponseBuilder.Init(&mMessageWriter)); - AttributeStatusList::Builder attributeStatusListBuilder = mWriteResponseBuilder.CreateAttributeStatusListBuilder(); - ReturnLogErrorOnFailure(attributeStatusListBuilder.GetError()); + AttributeStatuses::Builder attributeStatusesBuilder = mWriteResponseBuilder.CreateWriteResponses(); + ReturnLogErrorOnFailure(attributeStatusesBuilder.GetError()); MoveToState(State::Initialized); @@ -70,10 +70,10 @@ CHIP_ERROR WriteHandler::OnWriteRequest(Messaging::ExchangeContext * apExchangeC CHIP_ERROR WriteHandler::FinalizeMessage(System::PacketBufferHandle & packet) { CHIP_ERROR err = CHIP_NO_ERROR; - AttributeStatusList::Builder attributeStatusList; + AttributeStatuses::Builder attributeStatuses; VerifyOrExit(mState == State::AddStatus, err = CHIP_ERROR_INCORRECT_STATE); - attributeStatusList = mWriteResponseBuilder.GetAttributeStatusListBuilder().EndOfAttributeStatusList(); - err = attributeStatusList.GetError(); + attributeStatuses = mWriteResponseBuilder.GetWriteResponses().EndOfAttributeStatuses(); + err = attributeStatuses.GetError(); SuccessOrExit(err); mWriteResponseBuilder.EndOfWriteResponseMessage(); @@ -114,7 +114,7 @@ CHIP_ERROR WriteHandler::ProcessAttributeDataList(TLV::TLVReader & aAttributeDat { chip::TLV::TLVReader dataReader; AttributeDataElement::Parser element; - AttributePath::Parser attributePath; + AttributePathIB::Parser attributePath; ClusterInfo clusterInfo; TLV::TLVReader reader = aAttributeDataListReader; err = element.Init(reader); @@ -123,16 +123,16 @@ CHIP_ERROR WriteHandler::ProcessAttributeDataList(TLV::TLVReader & aAttributeDat err = element.GetAttributePath(&attributePath); SuccessOrExit(err); - err = attributePath.GetNodeId(&(clusterInfo.mNodeId)); + err = attributePath.GetNode(&(clusterInfo.mNodeId)); SuccessOrExit(err); - err = attributePath.GetEndpointId(&(clusterInfo.mEndpointId)); + err = attributePath.GetEndpoint(&(clusterInfo.mEndpointId)); SuccessOrExit(err); - err = attributePath.GetClusterId(&(clusterInfo.mClusterId)); + err = attributePath.GetCluster(&(clusterInfo.mClusterId)); SuccessOrExit(err); - err = attributePath.GetFieldId(&(clusterInfo.mFieldId)); + err = attributePath.GetAttribute(&(clusterInfo.mFieldId)); if (CHIP_NO_ERROR == err) { clusterInfo.mFlags.Set(ClusterInfo::Flags::kFieldIdValid); @@ -213,10 +213,10 @@ CHIP_ERROR WriteHandler::ProcessWriteRequest(System::PacketBufferHandle && aPayl CHIP_ERROR WriteHandler::ConstructAttributePath(const AttributePathParams & aAttributePathParams, AttributeStatusIB::Builder aAttributeStatusIB) { - AttributePath::Builder attributePath = aAttributeStatusIB.CreateAttributePathBuilder(); + AttributePathIB::Builder attributePath = aAttributeStatusIB.CreatePath(); if (aAttributePathParams.mFlags.Has(AttributePathParams::Flags::kFieldIdValid)) { - attributePath.FieldId(aAttributePathParams.mFieldId); + attributePath.Attribute(aAttributePathParams.mFieldId); } if (aAttributePathParams.mFlags.Has(AttributePathParams::Flags::kListIndexValid)) @@ -224,10 +224,10 @@ CHIP_ERROR WriteHandler::ConstructAttributePath(const AttributePathParams & aAtt attributePath.ListIndex(aAttributePathParams.mListIndex); } - attributePath.NodeId(aAttributePathParams.mNodeId) - .ClusterId(aAttributePathParams.mClusterId) - .EndpointId(aAttributePathParams.mEndpointId) - .EndOfAttributePath(); + attributePath.Node(aAttributePathParams.mNodeId) + .Cluster(aAttributePathParams.mClusterId) + .Endpoint(aAttributePathParams.mEndpointId) + .EndOfAttributePathIB(); return attributePath.GetError(); } @@ -238,16 +238,15 @@ CHIP_ERROR WriteHandler::AddStatus(const AttributePathParams & aAttributePathPar CHIP_ERROR err = CHIP_NO_ERROR; StatusIB::Builder statusIBBuilder; StatusIB statusIB; - AttributeStatusIB::Builder attributeStatusIB = - mWriteResponseBuilder.GetAttributeStatusListBuilder().CreateAttributeStatusBuilder(); - err = attributeStatusIB.GetError(); + AttributeStatusIB::Builder attributeStatusIB = mWriteResponseBuilder.GetWriteResponses().CreateAttributeStatus(); + err = attributeStatusIB.GetError(); SuccessOrExit(err); err = ConstructAttributePath(aAttributePathParams, attributeStatusIB); SuccessOrExit(err); statusIB.mStatus = aStatus; - statusIBBuilder = attributeStatusIB.CreateStatusIBBuilder(); + statusIBBuilder = attributeStatusIB.CreateErrorStatus(); statusIBBuilder.EncodeStatusIB(statusIB); err = statusIBBuilder.GetError(); SuccessOrExit(err); diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp index 7c839dd5aa4d9c..7e455843d1bcd7 100644 --- a/src/app/reporting/Engine.cpp +++ b/src/app/reporting/Engine.cpp @@ -69,12 +69,12 @@ Engine::RetrieveClusterData(FabricIndex aAccessingFabricIndex, AttributeDataList CHIP_ERROR err = CHIP_NO_ERROR; ConcreteAttributePath path(aClusterInfo.mEndpointId, aClusterInfo.mClusterId, aClusterInfo.mFieldId); AttributeDataElement::Builder attributeDataElementBuilder = aAttributeDataList.CreateAttributeDataElementBuilder(); - AttributePath::Builder attributePathBuilder = attributeDataElementBuilder.CreateAttributePathBuilder(); - attributePathBuilder.NodeId(aClusterInfo.mNodeId) - .EndpointId(aClusterInfo.mEndpointId) - .ClusterId(aClusterInfo.mClusterId) - .FieldId(aClusterInfo.mFieldId) - .EndOfAttributePath(); + AttributePathIB::Builder attributePathBuilder = attributeDataElementBuilder.CreateAttributePath(); + attributePathBuilder.Node(aClusterInfo.mNodeId) + .Endpoint(aClusterInfo.mEndpointId) + .Cluster(aClusterInfo.mClusterId) + .Attribute(aClusterInfo.mFieldId) + .EndOfAttributePathIB(); err = attributePathBuilder.GetError(); SuccessOrExit(err); diff --git a/src/app/tests/TestMessageDef.cpp b/src/app/tests/TestMessageDef.cpp index 574ac8206ef314..419878872b51a2 100644 --- a/src/app/tests/TestMessageDef.cpp +++ b/src/app/tests/TestMessageDef.cpp @@ -139,7 +139,7 @@ void ParseEventFilters(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; EventFilters::Parser eventFiltersParser; - AttributePath::Parser attributePathParser; + AttributePathIB::Parser attributePathParser; err = eventFiltersParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -150,22 +150,22 @@ void ParseEventFilters(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) #endif } -void BuildAttributePath(nlTestSuite * apSuite, AttributePath::Builder & aAttributePathBuilder) +void BuildAttributePath(nlTestSuite * apSuite, AttributePathIB::Builder & aAttributePathBuilder) { CHIP_ERROR err = CHIP_NO_ERROR; - aAttributePathBuilder.NodeId(1).EndpointId(2).ClusterId(3).FieldId(4).ListIndex(5).EndOfAttributePath(); + aAttributePathBuilder.Node(1).Endpoint(2).Cluster(3).Attribute(4).ListIndex(5).EndOfAttributePathIB(); err = aAttributePathBuilder.GetError(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); } void ParseAttributePath(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) { - AttributePath::Parser attributePathParser; + AttributePathIB::Parser attributePathParser; CHIP_ERROR err = CHIP_NO_ERROR; - chip::NodeId nodeId = 1; - chip::EndpointId endpointId = 2; - chip::ClusterId clusterId = 3; - chip::AttributeId fieldId = 4; + chip::NodeId node = 1; + chip::EndpointId endpoint = 2; + chip::ClusterId cluster = 3; + chip::AttributeId attribute = 4; chip::ListIndex listIndex = 5; err = attributePathParser.Init(aReader); @@ -174,37 +174,37 @@ void ParseAttributePath(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) err = attributePathParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif - err = attributePathParser.GetNodeId(&nodeId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && nodeId == 1); + err = attributePathParser.GetNode(&node); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && node == 1); - err = attributePathParser.GetEndpointId(&endpointId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpointId == 2); + err = attributePathParser.GetEndpoint(&endpoint); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpoint == 2); - err = attributePathParser.GetClusterId(&clusterId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && clusterId == 3); + err = attributePathParser.GetCluster(&cluster); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && cluster == 3); - err = attributePathParser.GetFieldId(&fieldId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && fieldId == 4); + err = attributePathParser.GetAttribute(&attribute); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && attribute == 4); err = attributePathParser.GetListIndex(&listIndex); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && listIndex == 5); } -void BuildAttributePathList(nlTestSuite * apSuite, AttributePathList::Builder & aAttributePathListBuilder) +void BuildAttributePathList(nlTestSuite * apSuite, AttributePaths::Builder & aAttributePathListBuilder) { - AttributePath::Builder attributePathBuilder = aAttributePathListBuilder.CreateAttributePathBuilder(); + AttributePathIB::Builder attributePathBuilder = aAttributePathListBuilder.CreateAttributePath(); NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); BuildAttributePath(apSuite, attributePathBuilder); - aAttributePathListBuilder.EndOfAttributePathList(); + aAttributePathListBuilder.EndOfAttributePaths(); NL_TEST_ASSERT(apSuite, aAttributePathListBuilder.GetError() == CHIP_NO_ERROR); } void ParseAttributePathList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; - AttributePathList::Parser attributePathListParser; - AttributePath::Parser attributePathParser; + AttributePaths::Parser attributePathListParser; + AttributePathIB::Parser attributePathParser; err = attributePathListParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -225,28 +225,28 @@ void BuildEventPath(nlTestSuite * apSuite, EventPathIB::Builder & aEventPathBuil void ParseEventPath(nlTestSuite * apSuite, EventPathIB::Parser & aEventPathParser) { - CHIP_ERROR err = CHIP_NO_ERROR; - chip::NodeId nodeId = 1; - chip::EndpointId endpointId = 2; - chip::ClusterId clusterId = 3; - chip::EventId eventId = 4; - bool isUrgent = false; + CHIP_ERROR err = CHIP_NO_ERROR; + chip::NodeId node = 1; + chip::EndpointId endpoint = 2; + chip::ClusterId cluster = 3; + chip::EventId event = 4; + bool isUrgent = false; #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK err = aEventPathParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif - err = aEventPathParser.GetNode(&nodeId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && nodeId == 1); + err = aEventPathParser.GetNode(&node); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && node == 1); - err = aEventPathParser.GetEndpoint(&endpointId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpointId == 2); + err = aEventPathParser.GetEndpoint(&endpoint); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && endpoint == 2); - err = aEventPathParser.GetCluster(&clusterId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && clusterId == 3); + err = aEventPathParser.GetCluster(&cluster); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && cluster == 3); - err = aEventPathParser.GetEvent(&eventId); - NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && eventId == 4); + err = aEventPathParser.GetEvent(&event); + NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && event == 4); err = aEventPathParser.GetIsUrgent(&isUrgent); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR && isUrgent == true); @@ -474,11 +474,11 @@ void ParseEventReports(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) void BuildAttributeStatusIB(nlTestSuite * apSuite, AttributeStatusIB::Builder & aAttributeStatusIBBuilder) { - AttributePath::Builder attributePathBuilder = aAttributeStatusIBBuilder.CreateAttributePathBuilder(); + AttributePathIB::Builder attributePathBuilder = aAttributeStatusIBBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); BuildAttributePath(apSuite, attributePathBuilder); - StatusIB::Builder statusIBBuilder = aAttributeStatusIBBuilder.CreateStatusIBBuilder(); + StatusIB::Builder statusIBBuilder = aAttributeStatusIBBuilder.CreateErrorStatus(); NL_TEST_ASSERT(apSuite, statusIBBuilder.GetError() == CHIP_NO_ERROR); BuildStatusIB(apSuite, statusIBBuilder); @@ -489,34 +489,34 @@ void BuildAttributeStatusIB(nlTestSuite * apSuite, AttributeStatusIB::Builder & void ParseAttributeStatusIB(nlTestSuite * apSuite, AttributeStatusIB::Parser & aAttributeStatusIBParser) { CHIP_ERROR err = CHIP_NO_ERROR; - AttributePath::Parser attributePathParser; + AttributePathIB::Parser attributePathParser; StatusIB::Parser StatusIBParser; #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK err = aAttributeStatusIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif - err = aAttributeStatusIBParser.GetAttributePath(&attributePathParser); + err = aAttributeStatusIBParser.GetPath(&attributePathParser); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - err = aAttributeStatusIBParser.GetStatusIB(&StatusIBParser); + err = aAttributeStatusIBParser.GetErrorStatus(&StatusIBParser); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); } -void BuildAttributeStatusList(nlTestSuite * apSuite, AttributeStatusList::Builder & aAttributeStatusListBuilder) +void BuildAttributeStatuses(nlTestSuite * apSuite, AttributeStatuses::Builder & aAttributeStatusesBuilder) { - AttributeStatusIB::Builder aAttributeStatusIBBuilder = aAttributeStatusListBuilder.CreateAttributeStatusBuilder(); - NL_TEST_ASSERT(apSuite, aAttributeStatusListBuilder.GetError() == CHIP_NO_ERROR); + AttributeStatusIB::Builder aAttributeStatusIBBuilder = aAttributeStatusesBuilder.CreateAttributeStatus(); + NL_TEST_ASSERT(apSuite, aAttributeStatusesBuilder.GetError() == CHIP_NO_ERROR); BuildAttributeStatusIB(apSuite, aAttributeStatusIBBuilder); - aAttributeStatusListBuilder.EndOfAttributeStatusList(); - NL_TEST_ASSERT(apSuite, aAttributeStatusListBuilder.GetError() == CHIP_NO_ERROR); + aAttributeStatusesBuilder.EndOfAttributeStatuses(); + NL_TEST_ASSERT(apSuite, aAttributeStatusesBuilder.GetError() == CHIP_NO_ERROR); } -void ParseAttributeStatusList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) +void ParseAttributeStatuses(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) { CHIP_ERROR err = CHIP_NO_ERROR; - AttributeStatusList::Parser attributeStatusParser; + AttributeStatuses::Parser attributeStatusParser; err = attributeStatusParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -531,7 +531,7 @@ void BuildAttributeDataElement(nlTestSuite * apSuite, AttributeDataElement::Buil { CHIP_ERROR err = CHIP_NO_ERROR; - AttributePath::Builder attributePathBuilder = aAttributeDataElementBuilder.CreateAttributePathBuilder(); + AttributePathIB::Builder attributePathBuilder = aAttributeDataElementBuilder.CreateAttributePath(); NL_TEST_ASSERT(apSuite, aAttributeDataElementBuilder.GetError() == CHIP_NO_ERROR); BuildAttributePath(apSuite, attributePathBuilder); @@ -565,7 +565,7 @@ void BuildAttributeDataElement(nlTestSuite * apSuite, AttributeDataElement::Buil void ParseAttributeDataElement(nlTestSuite * apSuite, AttributeDataElement::Parser & aAttributeDataElementParser) { CHIP_ERROR err = CHIP_NO_ERROR; - AttributePath::Parser attributePathParser; + AttributePathIB::Parser attributePathParser; StatusIB::Parser StatusIBParser; chip::DataVersion version = 0; bool moreClusterDataFlag = false; @@ -981,9 +981,9 @@ void BuildReadRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWrit err = readRequestBuilder.Init(&aWriter); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributePathList::Builder attributePathList = readRequestBuilder.CreateAttributePathListBuilder(); + AttributePaths::Builder AttributePaths = readRequestBuilder.CreateAttributePathListBuilder(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributePathList(apSuite, attributePathList); + BuildAttributePathList(apSuite, AttributePaths); EventPaths::Builder eventPathList = readRequestBuilder.CreateEventPathsBuilder(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); @@ -1005,7 +1005,7 @@ void ParseReadRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aRead CHIP_ERROR err = CHIP_NO_ERROR; ReadRequestMessage::Parser readRequestParser; - AttributePathList::Parser attributePathListParser; + AttributePaths::Parser attributePathListParser; EventPaths::Parser eventPathListParser; AttributeDataVersionList::Parser attributeDataVersionListParser; uint64_t eventNumber; @@ -1092,9 +1092,9 @@ void BuildWriteResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWr err = writeResponseBuilder.Init(&aWriter); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributeStatusList::Builder attributeStatusList = writeResponseBuilder.CreateAttributeStatusListBuilder(); + AttributeStatuses::Builder attributeStatuses = writeResponseBuilder.CreateWriteResponses(); NL_TEST_ASSERT(apSuite, writeResponseBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeStatusList(apSuite, attributeStatusList); + BuildAttributeStatuses(apSuite, attributeStatuses); writeResponseBuilder.EndOfWriteResponseMessage(); NL_TEST_ASSERT(apSuite, writeResponseBuilder.GetError() == CHIP_NO_ERROR); @@ -1105,14 +1105,14 @@ void ParseWriteResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aRe CHIP_ERROR err = CHIP_NO_ERROR; WriteResponseMessage::Parser writeResponseParser; - AttributeStatusList::Parser attributeStatusListParser; + AttributeStatuses::Parser attributeStatusesParser; err = writeResponseParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK err = writeResponseParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif - err = writeResponseParser.GetAttributeStatusList(&attributeStatusListParser); + err = writeResponseParser.GetWriteResponses(&attributeStatusesParser); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); } @@ -1124,9 +1124,9 @@ void BuildSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & err = subscribeRequestBuilder.Init(&aWriter); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributePathList::Builder attributePathList = subscribeRequestBuilder.CreateAttributePathListBuilder(); + AttributePaths::Builder AttributePaths = subscribeRequestBuilder.CreateAttributePathListBuilder(); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributePathList(apSuite, attributePathList); + BuildAttributePathList(apSuite, AttributePaths); EventPaths::Builder eventPathList = subscribeRequestBuilder.CreateEventPathsBuilder(); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); @@ -1160,7 +1160,7 @@ void ParseSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & CHIP_ERROR err = CHIP_NO_ERROR; SubscribeRequestMessage::Parser subscribeRequestParser; - AttributePathList::Parser attributePathListParser; + AttributePaths::Parser attributePathListParser; EventPaths::Parser eventPathListParser; AttributeDataVersionList::Parser attributeDataVersionListParser; uint64_t eventNumber = 0; @@ -1324,7 +1324,7 @@ void EventFiltersTest(nlTestSuite * apSuite, void * apContext) void AttributePathTest(nlTestSuite * apSuite, void * apContext) { CHIP_ERROR err = CHIP_NO_ERROR; - AttributePath::Builder attributePathBuilder; + AttributePathIB::Builder attributePathBuilder; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); @@ -1348,7 +1348,7 @@ void AttributePathListTest(nlTestSuite * apSuite, void * apContext) CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; - AttributePathList::Builder attributePathListBuilder; + AttributePaths::Builder attributePathListBuilder; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); @@ -1583,16 +1583,16 @@ void AttributeStatusIBTest(nlTestSuite * apSuite, void * apContext) ParseAttributeStatusIB(apSuite, attributeStatusIBParser); } -void AttributeStatusListTest(nlTestSuite * apSuite, void * apContext) +void AttributeStatusesTest(nlTestSuite * apSuite, void * apContext) { CHIP_ERROR err = CHIP_NO_ERROR; chip::System::PacketBufferTLVWriter writer; chip::System::PacketBufferTLVReader reader; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - AttributeStatusList::Builder attributeStatusListBuilder; - err = attributeStatusListBuilder.Init(&writer); + AttributeStatuses::Builder attributeStatusesBuilder; + err = attributeStatusesBuilder.Init(&writer); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - BuildAttributeStatusList(apSuite, attributeStatusListBuilder); + BuildAttributeStatuses(apSuite, attributeStatusesBuilder); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -1602,7 +1602,7 @@ void AttributeStatusListTest(nlTestSuite * apSuite, void * apContext) reader.Init(std::move(buf)); err = reader.Next(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - ParseAttributeStatusList(apSuite, reader); + ParseAttributeStatuses(apSuite, reader); } void AttributeDataElementTest(nlTestSuite * apSuite, void * apContext) @@ -2076,7 +2076,7 @@ const nlTest sTests[] = NL_TEST_DEF("StatusIBTest", StatusIBTest), NL_TEST_DEF("EventStatusIBTest", EventStatusIBTest), NL_TEST_DEF("AttributeStatusIBTest", AttributeStatusIBTest), - NL_TEST_DEF("AttributeStatusListTest", AttributeStatusListTest), + NL_TEST_DEF("AttributeStatusesTest", AttributeStatusesTest), NL_TEST_DEF("AttributeDataElementTest", AttributeDataElementTest), NL_TEST_DEF("AttributeDataListTest", AttributeDataListTest), NL_TEST_DEF("AttributeDataVersionListTest", AttributeDataVersionListTest), diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index b1cae917314721..01904ea1ca5b67 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -295,16 +295,16 @@ void TestReadInteraction::GenerateReportData(nlTestSuite * apSuite, void * apCon AttributeDataElement::Builder attributeDataElementBuilder = attributeDataListBuilder.CreateAttributeDataElementBuilder(); NL_TEST_ASSERT(apSuite, attributeDataListBuilder.GetError() == CHIP_NO_ERROR); - AttributePath::Builder attributePathBuilder = attributeDataElementBuilder.CreateAttributePathBuilder(); + AttributePathIB::Builder attributePathBuilder = attributeDataElementBuilder.CreateAttributePath(); NL_TEST_ASSERT(apSuite, attributeDataElementBuilder.GetError() == CHIP_NO_ERROR); if (aNeedInvalidReport) { - attributePathBuilder.NodeId(1).EndpointId(2).ClusterId(3).ListIndex(5).EndOfAttributePath(); + attributePathBuilder.Node(1).Endpoint(2).Cluster(3).ListIndex(5).EndOfAttributePathIB(); } else { - attributePathBuilder.NodeId(1).EndpointId(2).ClusterId(3).FieldId(4).ListIndex(5).EndOfAttributePath(); + attributePathBuilder.Node(1).Endpoint(2).Cluster(3).Attribute(4).ListIndex(5).EndOfAttributePathIB(); } err = attributePathBuilder.GetError(); @@ -398,17 +398,17 @@ void TestReadInteraction::TestReadHandler(nlTestSuite * apSuite, void * apContex err = readRequestBuilder.Init(&writer); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributePathList::Builder attributePathListBuilder = readRequestBuilder.CreateAttributePathListBuilder(); + AttributePaths::Builder attributePathListBuilder = readRequestBuilder.CreateAttributePathListBuilder(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); - AttributePath::Builder attributePathBuilder = attributePathListBuilder.CreateAttributePathBuilder(); + AttributePathIB::Builder attributePathBuilder = attributePathListBuilder.CreateAttributePath(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); - attributePathBuilder.NodeId(1).EndpointId(2).ClusterId(3).FieldId(4).ListIndex(5).EndOfAttributePath(); + attributePathBuilder.Node(1).Endpoint(2).Cluster(3).Attribute(4).ListIndex(5).EndOfAttributePathIB(); err = attributePathBuilder.GetError(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - attributePathListBuilder.EndOfAttributePathList(); + attributePathListBuilder.EndOfAttributePaths(); err = attributePathListBuilder.GetError(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -447,7 +447,7 @@ void TestReadInteraction::TestReadClientGenerateAttributePathList(nlTestSuite * attributePathParams[0].mFlags.Set(AttributePathParams::Flags::kFieldIdValid); attributePathParams[1].mFlags.Set(AttributePathParams::Flags::kFieldIdValid); attributePathParams[1].mFlags.Set(AttributePathParams::Flags::kListIndexValid); - AttributePathList::Builder & attributePathListBuilder = request.CreateAttributePathListBuilder(); + AttributePaths::Builder & attributePathListBuilder = request.CreateAttributePathListBuilder(); err = readClient.GenerateAttributePathList(attributePathListBuilder, attributePathParams, 2 /*aAttributePathParamsListSize*/); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); } @@ -473,7 +473,7 @@ void TestReadInteraction::TestReadClientGenerateInvalidAttributePathList(nlTestS AttributePathParams attributePathParams[2]; attributePathParams[0].mFlags.Set(AttributePathParams::Flags::kFieldIdValid); attributePathParams[1].mFlags.Set(AttributePathParams::Flags::kListIndexValid); - AttributePathList::Builder & attributePathListBuilder = request.CreateAttributePathListBuilder(); + AttributePaths::Builder & attributePathListBuilder = request.CreateAttributePathListBuilder(); err = readClient.GenerateAttributePathList(attributePathListBuilder, attributePathParams, 2 /*aAttributePathParamsListSize*/); NL_TEST_ASSERT(apSuite, err == CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); } @@ -527,13 +527,13 @@ void TestReadInteraction::TestReadHandlerInvalidAttributePath(nlTestSuite * apSu err = readRequestBuilder.Init(&writer); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributePathList::Builder attributePathListBuilder = readRequestBuilder.CreateAttributePathListBuilder(); + AttributePaths::Builder attributePathListBuilder = readRequestBuilder.CreateAttributePathListBuilder(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); - AttributePath::Builder attributePathBuilder = attributePathListBuilder.CreateAttributePathBuilder(); + AttributePathIB::Builder attributePathBuilder = attributePathListBuilder.CreateAttributePath(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); - attributePathBuilder.NodeId(1).EndpointId(2).ClusterId(3).ListIndex(5).EndOfAttributePath(); + attributePathBuilder.Node(1).Endpoint(2).Cluster(3).ListIndex(5).EndOfAttributePathIB(); err = attributePathBuilder.GetError(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -797,17 +797,17 @@ void TestReadInteraction::TestProcessSubscribeRequest(nlTestSuite * apSuite, voi err = subscribeRequestBuilder.Init(&writer); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributePathList::Builder attributePathListBuilder = subscribeRequestBuilder.CreateAttributePathListBuilder(); + AttributePaths::Builder attributePathListBuilder = subscribeRequestBuilder.CreateAttributePathListBuilder(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); - AttributePath::Builder attributePathBuilder = attributePathListBuilder.CreateAttributePathBuilder(); + AttributePathIB::Builder attributePathBuilder = attributePathListBuilder.CreateAttributePath(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); - attributePathBuilder.NodeId(1).EndpointId(2).ClusterId(3).FieldId(4).ListIndex(5).EndOfAttributePath(); + attributePathBuilder.Node(1).Endpoint(2).Cluster(3).Attribute(4).ListIndex(5).EndOfAttributePathIB(); err = attributePathBuilder.GetError(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - attributePathListBuilder.EndOfAttributePathList(); + attributePathListBuilder.EndOfAttributePaths(); err = attributePathListBuilder.GetError(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); diff --git a/src/app/tests/TestReportingEngine.cpp b/src/app/tests/TestReportingEngine.cpp index 3498fb4095552a..b1c6cc9470af50 100644 --- a/src/app/tests/TestReportingEngine.cpp +++ b/src/app/tests/TestReportingEngine.cpp @@ -73,8 +73,8 @@ void TestReportingEngine::TestBuildAndSendSingleReportData(nlTestSuite * apSuite System::PacketBufferTLVWriter writer; System::PacketBufferHandle readRequestbuf = System::PacketBufferHandle::New(System::PacketBuffer::kMaxSize); ReadRequestMessage::Builder readRequestBuilder; - AttributePathList::Builder attributePathListBuilder; - AttributePath::Builder attributePathBuilder; + AttributePaths::Builder attributePathListBuilder; + AttributePathIB::Builder attributePathBuilder; err = InteractionModelEngine::GetInstance()->Init(&ctx.GetExchangeManager(), nullptr); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -87,24 +87,24 @@ void TestReportingEngine::TestBuildAndSendSingleReportData(nlTestSuite * apSuite NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); attributePathListBuilder = readRequestBuilder.CreateAttributePathListBuilder(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); - attributePathBuilder = attributePathListBuilder.CreateAttributePathBuilder(); + attributePathBuilder = attributePathListBuilder.CreateAttributePath(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); - attributePathBuilder = attributePathBuilder.NodeId(1) - .EndpointId(kTestEndpointId) - .ClusterId(kTestClusterId) - .FieldId(kTestFieldId1) - .EndOfAttributePath(); + attributePathBuilder = attributePathBuilder.Node(1) + .Endpoint(kTestEndpointId) + .Cluster(kTestClusterId) + .Attribute(kTestFieldId1) + .EndOfAttributePathIB(); NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); - attributePathBuilder = attributePathListBuilder.CreateAttributePathBuilder(); + attributePathBuilder = attributePathListBuilder.CreateAttributePath(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); - attributePathBuilder = attributePathBuilder.NodeId(1) - .EndpointId(kTestEndpointId) - .ClusterId(kTestClusterId) - .FieldId(kTestFieldId2) - .EndOfAttributePath(); + attributePathBuilder = attributePathBuilder.Node(1) + .Endpoint(kTestEndpointId) + .Cluster(kTestClusterId) + .Attribute(kTestFieldId2) + .EndOfAttributePathIB(); NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); - attributePathListBuilder.EndOfAttributePathList(); + attributePathListBuilder.EndOfAttributePaths(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); readRequestBuilder.EndOfReadRequestMessage(); diff --git a/src/app/tests/TestWriteInteraction.cpp b/src/app/tests/TestWriteInteraction.cpp index b5c028f5a6b369..b117b752920181 100644 --- a/src/app/tests/TestWriteInteraction.cpp +++ b/src/app/tests/TestWriteInteraction.cpp @@ -134,9 +134,9 @@ void TestWriteInteraction::GenerateWriteRequest(nlTestSuite * apSuite, void * ap AttributeDataElement::Builder attributeDataElementBuilder = attributeDataListBuilder.CreateAttributeDataElementBuilder(); NL_TEST_ASSERT(apSuite, attributeDataElementBuilder.GetError() == CHIP_NO_ERROR); - AttributePath::Builder attributePathBuilder = attributeDataElementBuilder.CreateAttributePathBuilder(); + AttributePathIB::Builder attributePathBuilder = attributeDataElementBuilder.CreateAttributePath(); NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); - attributePathBuilder.NodeId(1).EndpointId(2).ClusterId(3).FieldId(4).ListIndex(5).EndOfAttributePath(); + attributePathBuilder.Node(1).Endpoint(2).Cluster(3).Attribute(4).ListIndex(5).EndOfAttributePathIB(); err = attributePathBuilder.GetError(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -177,18 +177,18 @@ void TestWriteInteraction::GenerateWriteResponse(nlTestSuite * apSuite, void * a WriteResponseMessage::Builder writeResponseBuilder; err = writeResponseBuilder.Init(&writer); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributeStatusList::Builder attributeStatusListBuilder = writeResponseBuilder.CreateAttributeStatusListBuilder(); - NL_TEST_ASSERT(apSuite, attributeStatusListBuilder.GetError() == CHIP_NO_ERROR); - AttributeStatusIB::Builder attributeStatusIBBuilder = attributeStatusListBuilder.CreateAttributeStatusBuilder(); + AttributeStatuses::Builder attributeStatusesBuilder = writeResponseBuilder.CreateWriteResponses(); + NL_TEST_ASSERT(apSuite, attributeStatusesBuilder.GetError() == CHIP_NO_ERROR); + AttributeStatusIB::Builder attributeStatusIBBuilder = attributeStatusesBuilder.CreateAttributeStatus(); NL_TEST_ASSERT(apSuite, attributeStatusIBBuilder.GetError() == CHIP_NO_ERROR); - AttributePath::Builder attributePathBuilder = attributeStatusIBBuilder.CreateAttributePathBuilder(); + AttributePathIB::Builder attributePathBuilder = attributeStatusIBBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); - attributePathBuilder.NodeId(1).EndpointId(2).ClusterId(3).FieldId(4).ListIndex(5).EndOfAttributePath(); + attributePathBuilder.Node(1).Endpoint(2).Cluster(3).Attribute(4).ListIndex(5).EndOfAttributePathIB(); err = attributePathBuilder.GetError(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - StatusIB::Builder statusIBBuilder = attributeStatusIBBuilder.CreateStatusIBBuilder(); + StatusIB::Builder statusIBBuilder = attributeStatusIBBuilder.CreateErrorStatus(); StatusIB statusIB; statusIB.mStatus = chip::Protocols::InteractionModel::Status::InvalidSubscription; NL_TEST_ASSERT(apSuite, statusIBBuilder.GetError() == CHIP_NO_ERROR); @@ -199,8 +199,8 @@ void TestWriteInteraction::GenerateWriteResponse(nlTestSuite * apSuite, void * a attributeStatusIBBuilder.EndOfAttributeStatusIB(); NL_TEST_ASSERT(apSuite, attributeStatusIBBuilder.GetError() == CHIP_NO_ERROR); - attributeStatusListBuilder.EndOfAttributeStatusList(); - NL_TEST_ASSERT(apSuite, attributeStatusListBuilder.GetError() == CHIP_NO_ERROR); + attributeStatusesBuilder.EndOfAttributeStatuses(); + NL_TEST_ASSERT(apSuite, attributeStatusesBuilder.GetError() == CHIP_NO_ERROR); writeResponseBuilder.EndOfWriteResponseMessage(); NL_TEST_ASSERT(apSuite, writeResponseBuilder.GetError() == CHIP_NO_ERROR);