From 10786086891ce33058307122e4f62d507f9c58be Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Mon, 6 Dec 2021 09:59:34 -0800 Subject: [PATCH] Cleanup IM (#12606) --Move ConstructCommandPath function into CommandPathIB, update all usage across the codes. --Use reference delcartion for usages on all Create* functions from IM MessageDef, update all usage across the code. --Update the missing error-check for IM messageDef. --- src/app/AttributeAccessInterface.cpp | 24 ++-- src/app/AttributeAccessInterface.h | 16 +-- src/app/Command.cpp | 11 -- src/app/Command.h | 1 - src/app/CommandHandler.cpp | 47 ++++--- src/app/CommandHandler.h | 8 +- src/app/CommandSender.cpp | 16 +-- src/app/EventManagement.cpp | 82 +++++------- src/app/MessageDef/AttributeReportIB.h | 1 + src/app/MessageDef/AttributeReportIBs.h | 2 + src/app/MessageDef/CommandPathIB.cpp | 20 +++ src/app/MessageDef/CommandPathIB.h | 5 + src/app/ReadClient.cpp | 24 ++-- src/app/WriteClient.cpp | 13 +- src/app/WriteHandler.cpp | 42 +++---- .../account-login-server.cpp | 9 +- .../application-launcher-server.cpp | 9 +- .../door-lock-server-logging.cpp | 9 +- .../door-lock-server-schedule.cpp | 21 ++-- .../door-lock-server-user.cpp | 23 ++-- .../clusters/groups-server/groups-server.cpp | 21 ++-- .../identify-server/identify-server.cpp | 7 +- .../keypad-input-server.cpp | 9 +- .../media-playback-server.cpp | 9 +- .../operational-credentials-server.cpp | 7 +- src/app/clusters/scenes/scenes.cpp | 48 ++++--- .../target-navigator-server.cpp | 11 +- .../tv-channel-server/tv-channel-server.cpp | 9 +- src/app/reporting/Engine.cpp | 119 +++++++++--------- src/app/tests/TestCommandInteraction.cpp | 42 +++---- src/app/tests/TestMessageDef.cpp | 106 ++++++++-------- src/app/tests/TestReadInteraction.cpp | 35 +++--- src/app/tests/TestReportingEngine.cpp | 34 +++-- src/app/tests/TestWriteInteraction.cpp | 14 +-- .../tests/integration/chip_im_initiator.cpp | 12 +- .../tests/integration/chip_im_responder.cpp | 18 ++- .../util/ember-compatibility-functions.cpp | 15 ++- src/app/util/mock/attribute-storage.cpp | 28 +++-- 38 files changed, 450 insertions(+), 477 deletions(-) diff --git a/src/app/AttributeAccessInterface.cpp b/src/app/AttributeAccessInterface.cpp index 040a199a272bb2..0e7723b6059a19 100644 --- a/src/app/AttributeAccessInterface.cpp +++ b/src/app/AttributeAccessInterface.cpp @@ -24,16 +24,16 @@ namespace app { CHIP_ERROR AttributeReportBuilder::PrepareAttribute(AttributeReportIBs::Builder & aAttributeReportIBsBuilder, const ConcreteDataAttributePath & aPath, DataVersion aDataVersion) { - mAttributeReportIBBuilder = aAttributeReportIBsBuilder.CreateAttributeReport(); + AttributeReportIB::Builder & attributeReportIBBuilder = aAttributeReportIBsBuilder.CreateAttributeReport(); ReturnErrorOnFailure(aAttributeReportIBsBuilder.GetError()); - mAttributeDataIBBuilder = mAttributeReportIBBuilder.CreateAttributeData(); - ReturnErrorOnFailure(mAttributeReportIBBuilder.GetError()); + AttributeDataIB::Builder & attributeDataIBBuilder = attributeReportIBBuilder.CreateAttributeData(); + ReturnErrorOnFailure(attributeReportIBBuilder.GetError()); - mAttributeDataIBBuilder.DataVersion(aDataVersion); + attributeDataIBBuilder.DataVersion(aDataVersion); - auto attributePathIBBuilder = mAttributeDataIBBuilder.CreatePath(); - ReturnErrorOnFailure(mAttributeDataIBBuilder.GetError()); + AttributePathIB::Builder & attributePathIBBuilder = attributeDataIBBuilder.CreatePath(); + ReturnErrorOnFailure(attributeDataIBBuilder.GetError()); attributePathIBBuilder.Endpoint(aPath.mEndpointId).Cluster(aPath.mClusterId).Attribute(aPath.mAttributeId); @@ -46,13 +46,13 @@ CHIP_ERROR AttributeReportBuilder::PrepareAttribute(AttributeReportIBs::Builder ReturnErrorOnFailure(attributePathIBBuilder.EndOfAttributePathIB().GetError()); - return mAttributeDataIBBuilder.GetError(); + return attributeDataIBBuilder.GetError(); } -CHIP_ERROR AttributeReportBuilder::FinishAttribute() +CHIP_ERROR AttributeReportBuilder::FinishAttribute(AttributeReportIBs::Builder & aAttributeReportIBsBuilder) { - ReturnErrorOnFailure(mAttributeDataIBBuilder.EndOfAttributeDataIB().GetError()); - return mAttributeReportIBBuilder.EndOfAttributeReportIB().GetError(); + ReturnErrorOnFailure(aAttributeReportIBsBuilder.GetAttributeReport().GetAttributeData().EndOfAttributeDataIB().GetError()); + return aAttributeReportIBsBuilder.GetAttributeReport().EndOfAttributeReportIB().GetError(); } CHIP_ERROR AttributeValueEncoder::EncodeEmptyList() @@ -70,9 +70,9 @@ CHIP_ERROR AttributeValueEncoder::EncodeEmptyList() AttributeReportBuilder builder; ReturnErrorOnFailure(builder.PrepareAttribute(mAttributeReportIBsBuilder, mPath, mDataVersion)); - ReturnErrorOnFailure(builder.EncodeValue(DataModel::List())); + ReturnErrorOnFailure(builder.EncodeValue(mAttributeReportIBsBuilder, DataModel::List())); - ReturnErrorOnFailure(builder.FinishAttribute()); + ReturnErrorOnFailure(builder.FinishAttribute(mAttributeReportIBsBuilder)); mEncodeState.mCurrentEncodingListIndex = 0; } mCurrentEncodingListIndex = 0; diff --git a/src/app/AttributeAccessInterface.h b/src/app/AttributeAccessInterface.h index 9f7cca71761cf5..796f7b6de46696 100644 --- a/src/app/AttributeAccessInterface.h +++ b/src/app/AttributeAccessInterface.h @@ -68,21 +68,17 @@ class AttributeReportBuilder /** * FinishAttribute encodes the "footer" part of an attribute report (it closes the containers opened in PrepareAttribute) */ - CHIP_ERROR FinishAttribute(); + CHIP_ERROR FinishAttribute(AttributeReportIBs::Builder & aAttributeReportIBs); /** * EncodeValue encodes the value field of the report, it should be called exactly once. */ template - CHIP_ERROR EncodeValue(Ts... aArgs) + CHIP_ERROR EncodeValue(AttributeReportIBs::Builder & aAttributeReportIBs, Ts... aArgs) { - return DataModel::Encode(*mAttributeDataIBBuilder.GetWriter(), TLV::ContextTag(to_underlying(AttributeDataIB::Tag::kData)), - std::forward(aArgs)...); + return DataModel::Encode(*(aAttributeReportIBs.GetAttributeReport().GetAttributeData().GetWriter()), + TLV::ContextTag(to_underlying(AttributeDataIB::Tag::kData)), std::forward(aArgs)...); } - -private: - AttributeReportIB::Builder mAttributeReportIBBuilder; - AttributeDataIB::Builder mAttributeDataIBBuilder; }; /** @@ -252,9 +248,9 @@ class AttributeValueEncoder AttributeReportBuilder builder; ReturnErrorOnFailure(builder.PrepareAttribute(mAttributeReportIBsBuilder, mPath, mDataVersion)); - ReturnErrorOnFailure(builder.EncodeValue(std::forward(aArgs)...)); + ReturnErrorOnFailure(builder.EncodeValue(mAttributeReportIBsBuilder, std::forward(aArgs)...)); - return builder.FinishAttribute(); + return builder.FinishAttribute(mAttributeReportIBsBuilder); } /** diff --git a/src/app/Command.cpp b/src/app/Command.cpp index 1d9d14d68dac6d..b73c074c6ac8a2 100644 --- a/src/app/Command.cpp +++ b/src/app/Command.cpp @@ -37,17 +37,6 @@ CHIP_ERROR Command::Finalize(System::PacketBufferHandle & commandPacket) return mCommandMessageWriter.Finalize(&commandPacket); } -CHIP_ERROR Command::ConstructCommandPath(const CommandPathParams & aCommandPathParams, CommandPathIB::Builder & aCommandPath) -{ - if (aCommandPathParams.mFlags.Has(CommandPathFlags::kEndpointIdValid)) - { - aCommandPath.EndpointId(aCommandPathParams.mEndpointId); - } - - aCommandPath.ClusterId(aCommandPathParams.mClusterId).CommandId(aCommandPathParams.mCommandId).EndOfCommandPathIB(); - return aCommandPath.GetError(); -} - void Command::Abort() { // diff --git a/src/app/Command.h b/src/app/Command.h index 4e3a698d910f17..9fbeff757fcc4a 100644 --- a/src/app/Command.h +++ b/src/app/Command.h @@ -101,7 +101,6 @@ class Command void Close(); void MoveToState(const CommandState aTargetState); - CHIP_ERROR ConstructCommandPath(const CommandPathParams & aCommandPathParams, CommandPathIB::Builder & aCommandPath); const char * GetStateStr() const; Messaging::ExchangeContext * mpExchangeCtx = nullptr; diff --git a/src/app/CommandHandler.cpp b/src/app/CommandHandler.cpp index 96dbdf4d93e019..66324e08e9b9f3 100644 --- a/src/app/CommandHandler.cpp +++ b/src/app/CommandHandler.cpp @@ -295,17 +295,11 @@ CHIP_ERROR CommandHandler::AddStatusInternal(const ConcreteCommandPath & aComman const Protocols::InteractionModel::Status aStatus, const Optional & aClusterStatus) { - StatusIB::Builder statusIBBuilder; StatusIB statusIB; - - CommandPathParams commandPathParams = { aCommandPath.mEndpointId, - 0, // GroupId - aCommandPath.mClusterId, aCommandPath.mCommandId, - chip::app::CommandPathFlags::kEndpointIdValid }; - - ReturnLogErrorOnFailure(PrepareStatus(commandPathParams)); - statusIBBuilder = mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().GetStatus().CreateErrorStatus(); - + ReturnLogErrorOnFailure(PrepareStatus(aCommandPath)); + CommandStatusIB::Builder & commandStatus = mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().GetStatus(); + StatusIB::Builder & statusIBBuilder = commandStatus.CreateErrorStatus(); + ReturnErrorOnFailure(commandStatus.GetError()); // // TODO: Most of the callers are incorrectly passing SecureChannel as the protocol ID, when in fact, the status code provided // above is always an IM code. Instead of fixing all the callers (which is a fairly sizeable change), we'll embark on fixing @@ -314,7 +308,7 @@ CHIP_ERROR CommandHandler::AddStatusInternal(const ConcreteCommandPath & aComman statusIB.mStatus = aStatus; statusIB.mClusterStatus = aClusterStatus; statusIBBuilder.EncodeStatusIB(statusIB); - ReturnLogErrorOnFailure(statusIBBuilder.GetError()); + ReturnErrorOnFailure(statusIBBuilder.GetError()); return FinishStatus(); } @@ -336,24 +330,22 @@ CHIP_ERROR CommandHandler::AddClusterSpecificFailure(const ConcreteCommandPath & return AddStatusInternal(aCommandPath, Protocols::InteractionModel::Status::Failure, clusterStatus); } -CHIP_ERROR CommandHandler::PrepareResponse(const ConcreteCommandPath & aRequestCommandPath, CommandId aResponseCommand) -{ - CommandPathParams params = { aRequestCommandPath.mEndpointId, - 0, // GroupId - aRequestCommandPath.mClusterId, aResponseCommand, (CommandPathFlags::kEndpointIdValid) }; - return PrepareCommand(params, false /* aStartDataStruct */); -} - -CHIP_ERROR CommandHandler::PrepareCommand(const CommandPathParams & aCommandPathParams, bool aStartDataStruct) +CHIP_ERROR CommandHandler::PrepareCommand(const ConcreteCommandPath & aCommandPath, bool aStartDataStruct) { ReturnErrorOnFailure(AllocateBuffer()); // // We must not be in the middle of preparing a command, or having prepared or sent one. // VerifyOrReturnError(mState == CommandState::Idle, CHIP_ERROR_INCORRECT_STATE); - CommandDataIB::Builder commandData = mInvokeResponseBuilder.GetInvokeResponses().CreateInvokeResponse().CreateCommand(); + InvokeResponseIBs::Builder & invokeResponses = mInvokeResponseBuilder.GetInvokeResponses(); + InvokeResponseIB::Builder & invokeResponse = invokeResponses.CreateInvokeResponse(); + ReturnErrorOnFailure(invokeResponses.GetError()); + + CommandDataIB::Builder & commandData = invokeResponse.CreateCommand(); ReturnErrorOnFailure(commandData.GetError()); - ReturnErrorOnFailure(ConstructCommandPath(aCommandPathParams, commandData.CreatePath())); + CommandPathIB::Builder & path = commandData.CreatePath(); + ReturnErrorOnFailure(commandData.GetError()); + ReturnErrorOnFailure(path.Encode(aCommandPath)); if (aStartDataStruct) { ReturnErrorOnFailure(commandData.GetWriter()->StartContainer(TLV::ContextTag(to_underlying(CommandDataIB::Tag::kData)), @@ -379,16 +371,21 @@ CHIP_ERROR CommandHandler::FinishCommand(bool aStartDataStruct) return CHIP_NO_ERROR; } -CHIP_ERROR CommandHandler::PrepareStatus(const CommandPathParams & aCommandPathParams) +CHIP_ERROR CommandHandler::PrepareStatus(const ConcreteCommandPath & aCommandPath) { ReturnErrorOnFailure(AllocateBuffer()); // // We must not be in the middle of preparing a command, or having prepared or sent one. // VerifyOrReturnError(mState == CommandState::Idle, CHIP_ERROR_INCORRECT_STATE); - CommandStatusIB::Builder commandStatus = mInvokeResponseBuilder.GetInvokeResponses().CreateInvokeResponse().CreateStatus(); + InvokeResponseIBs::Builder & invokeResponses = mInvokeResponseBuilder.GetInvokeResponses(); + InvokeResponseIB::Builder & invokeResponse = invokeResponses.CreateInvokeResponse(); + ReturnErrorOnFailure(invokeResponses.GetError()); + CommandStatusIB::Builder & commandStatus = invokeResponse.CreateStatus(); + ReturnErrorOnFailure(commandStatus.GetError()); + CommandPathIB::Builder & path = commandStatus.CreatePath(); ReturnErrorOnFailure(commandStatus.GetError()); - ReturnErrorOnFailure(ConstructCommandPath(aCommandPathParams, commandStatus.CreatePath())); + ReturnErrorOnFailure(path.Encode(aCommandPath)); MoveToState(CommandState::AddingCommand); return CHIP_NO_ERROR; } diff --git a/src/app/CommandHandler.h b/src/app/CommandHandler.h index 29cc3b62b80896..97bb39b3fffa62 100644 --- a/src/app/CommandHandler.h +++ b/src/app/CommandHandler.h @@ -142,9 +142,9 @@ class CommandHandler : public Command CHIP_ERROR AddClusterSpecificFailure(const ConcreteCommandPath & aCommandPath, ClusterStatus aClusterStatus) override; CHIP_ERROR ProcessInvokeRequest(System::PacketBufferHandle && payload, bool isTimedInvoke); - CHIP_ERROR PrepareCommand(const CommandPathParams & aCommandPathParams, bool aStartDataStruct = true); + CHIP_ERROR PrepareCommand(const ConcreteCommandPath & aCommandPath, bool aStartDataStruct = true); CHIP_ERROR FinishCommand(bool aStartDataStruct = true); - CHIP_ERROR PrepareStatus(const CommandPathParams & aCommandPathParams); + CHIP_ERROR PrepareStatus(const ConcreteCommandPath & aCommandPath); CHIP_ERROR FinishStatus(); TLV::TLVWriter * GetCommandDataIBTLVWriter(); FabricIndex GetAccessingFabricIndex() const; @@ -162,7 +162,8 @@ class CommandHandler : public Command template CHIP_ERROR AddResponseData(const ConcreteCommandPath & aRequestCommandPath, const CommandData & aData) { - ReturnErrorOnFailure(PrepareResponse(aRequestCommandPath, CommandData::GetCommandId())); + ConcreteCommandPath path = { aRequestCommandPath.mEndpointId, aRequestCommandPath.mClusterId, CommandData::GetCommandId() }; + ReturnErrorOnFailure(PrepareCommand(path, false)); TLV::TLVWriter * writer = GetCommandDataIBTLVWriter(); VerifyOrReturnError(writer != nullptr, CHIP_ERROR_INCORRECT_STATE); ReturnErrorOnFailure(DataModel::Encode(*writer, TLV::ContextTag(to_underlying(CommandDataIB::Tag::kData)), aData)); @@ -210,7 +211,6 @@ class CommandHandler : public Command CHIP_ERROR ProcessCommandDataIB(CommandDataIB::Parser & aCommandElement); CHIP_ERROR SendCommandResponse(); - CHIP_ERROR PrepareResponse(const ConcreteCommandPath & aRequestCommandPath, CommandId aResponseCommand); CHIP_ERROR AddStatusInternal(const ConcreteCommandPath & aCommandPath, const Protocols::InteractionModel::Status aStatus, const Optional & aClusterStatus); diff --git a/src/app/CommandSender.cpp b/src/app/CommandSender.cpp index fa6a2e5bf9000e..894cb3089fc6ec 100644 --- a/src/app/CommandSender.cpp +++ b/src/app/CommandSender.cpp @@ -298,23 +298,23 @@ CHIP_ERROR CommandSender::ProcessInvokeResponseIB(InvokeResponseIB::Parser & aIn CHIP_ERROR CommandSender::PrepareCommand(const CommandPathParams & aCommandPathParams, bool aStartDataStruct) { - CommandDataIB::Builder commandData; ReturnLogErrorOnFailure(AllocateBuffer()); // // We must not be in the middle of preparing a command, or having prepared or sent one. // VerifyOrReturnError(mState == CommandState::Idle, CHIP_ERROR_INCORRECT_STATE); - - commandData = mInvokeRequestBuilder.GetInvokeRequests().CreateCommandData(); - ReturnLogErrorOnFailure(commandData.GetError()); - - ReturnLogErrorOnFailure(ConstructCommandPath(aCommandPathParams, commandData.CreatePath())); + InvokeRequests::Builder & invokeRequests = mInvokeRequestBuilder.GetInvokeRequests(); + CommandDataIB::Builder & invokeRequest = invokeRequests.CreateCommandData(); + ReturnErrorOnFailure(invokeRequests.GetError()); + CommandPathIB::Builder & path = invokeRequest.CreatePath(); + ReturnErrorOnFailure(invokeRequest.GetError()); + ReturnErrorOnFailure(path.Encode(aCommandPathParams)); if (aStartDataStruct) { - ReturnLogErrorOnFailure(commandData.GetWriter()->StartContainer(TLV::ContextTag(to_underlying(CommandDataIB::Tag::kData)), - TLV::kTLVType_Structure, mDataElementContainerType)); + ReturnLogErrorOnFailure(invokeRequest.GetWriter()->StartContainer(TLV::ContextTag(to_underlying(CommandDataIB::Tag::kData)), + TLV::kTLVType_Structure, mDataElementContainerType)); } MoveToState(CommandState::AddingCommand); diff --git a/src/app/EventManagement.cpp b/src/app/EventManagement.cpp index 481234b0d9f003..a84d694cde6007 100644 --- a/src/app/EventManagement.cpp +++ b/src/app/EventManagement.cpp @@ -289,10 +289,20 @@ CHIP_ERROR EventManagement::CalculateEventSize(EventLoggingDelegate * apDelegate ctxt.mCurrentEventNumber = GetPriorityBuffer(apOptions->mpEventSchema->mPriority)->GetLastEventNumber(); ctxt.mCurrentTime.mValue = GetPriorityBuffer(apOptions->mpEventSchema->mPriority)->GetLastEventTimestamp(); - err = ConstructEvent(&ctxt, apDelegate, apOptions); - if (CHIP_NO_ERROR == err) + + TLVWriter checkpoint = ctxt.mWriter; + err = ConstructEvent(&ctxt, apDelegate, apOptions); + if (err != CHIP_NO_ERROR) { - requiredSize = writer.GetLengthWritten(); + ctxt.mWriter = checkpoint; + } + else + { + // update these variables since ConstructEvent can be used to track the + // state of a set of events over multiple calls. + ctxt.mCurrentEventNumber++; + ctxt.mCurrentTime = apOptions->mTimestamp; + requiredSize = writer.GetLengthWritten(); } return err; } @@ -300,27 +310,22 @@ CHIP_ERROR EventManagement::CalculateEventSize(EventLoggingDelegate * apDelegate CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, EventLoggingDelegate * apDelegate, const EventOptions * apOptions) { - - CHIP_ERROR err = CHIP_NO_ERROR; - TLVWriter checkpoint = apContext->mWriter; TLV::TLVType dataContainerType; - EventReportIB::Builder eventReportBuilder; - EventDataIB::Builder eventDataIBBuilder; - EventPathIB::Builder eventPathBuilder; uint64_t deltatime = 0; - VerifyOrExit(apContext->mCurrentEventNumber >= apContext->mStartingEventNumber, - /* no-op: don't write event, but advance current event Number */); + VerifyOrReturnError(apContext->mCurrentEventNumber >= apContext->mStartingEventNumber, CHIP_NO_ERROR + /* no-op: don't write event, but advance current event Number */); - VerifyOrExit(apOptions != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(apOptions != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + EventReportIB::Builder eventReportBuilder; eventReportBuilder.Init(&(apContext->mWriter)); // TODO: Update IsUrgent, issue 11386 // TODO: Update statusIB, issue 11388 - eventDataIBBuilder = eventReportBuilder.CreateEventData(); - eventPathBuilder = eventDataIBBuilder.CreatePath(); - err = eventDataIBBuilder.GetError(); - SuccessOrExit(err); + EventDataIB::Builder & eventDataIBBuilder = eventReportBuilder.CreateEventData(); + ReturnErrorOnFailure(eventReportBuilder.GetError()); + EventPathIB::Builder & eventPathBuilder = eventDataIBBuilder.CreatePath(); + ReturnErrorOnFailure(eventDataIBBuilder.GetError()); // TODO: Revisit NodeId since the the encoding spec and the IM seem to disagree on how this stuff works eventPathBuilder.Node(apOptions->mpEventSchema->mNodeId) @@ -329,10 +334,9 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even .Event(apOptions->mpEventSchema->mEventId) .IsUrgent(false) .EndOfEventPathIB(); - err = eventPathBuilder.GetError(); - SuccessOrExit(err); - + ReturnErrorOnFailure(eventPathBuilder.GetError()); eventDataIBBuilder.Priority(chip::to_underlying(apContext->mPriority)); + ReturnErrorOnFailure(eventDataIBBuilder.GetError()); deltatime = apOptions->mTimestamp.mValue - apContext->mCurrentTime.mValue; if (apOptions->mTimestamp.IsSystem()) @@ -344,42 +348,20 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even eventDataIBBuilder.DeltaEpochTimestamp(deltatime); } - err = eventDataIBBuilder.GetError(); - SuccessOrExit(err); + ReturnErrorOnFailure(eventDataIBBuilder.GetError()); - err = apContext->mWriter.StartContainer(ContextTag(chip::to_underlying(EventDataIB::Tag::kData)), TLV::kTLVType_Structure, - dataContainerType); - SuccessOrExit(err); + ReturnErrorOnFailure(apContext->mWriter.StartContainer(ContextTag(chip::to_underlying(EventDataIB::Tag::kData)), + TLV::kTLVType_Structure, dataContainerType)); // Callback to write the EventData - err = apDelegate->WriteEvent(apContext->mWriter); - SuccessOrExit(err); - - err = apContext->mWriter.EndContainer(dataContainerType); - SuccessOrExit(err); - + ReturnErrorOnFailure(apDelegate->WriteEvent(apContext->mWriter)); + ReturnErrorOnFailure(apContext->mWriter.EndContainer(dataContainerType)); eventDataIBBuilder.EndOfEventDataIB(); - SuccessOrExit(err = eventDataIBBuilder.GetError()); + ReturnErrorOnFailure(eventDataIBBuilder.GetError()); eventReportBuilder.EndOfEventReportIB(); - SuccessOrExit(err = eventReportBuilder.GetError()); - - err = apContext->mWriter.Finalize(); - SuccessOrExit(err); - + ReturnErrorOnFailure(eventReportBuilder.GetError()); + ReturnErrorOnFailure(apContext->mWriter.Finalize()); apContext->mFirst = false; - -exit: - if (err != CHIP_NO_ERROR) - { - apContext->mWriter = checkpoint; - } - else - { - // update these variables since ConstructEvent can be used to track the - // state of a set of events over multiple calls. - apContext->mCurrentEventNumber++; - apContext->mCurrentTime = apOptions->mTimestamp; - } - return err; + return CHIP_NO_ERROR; } void EventManagement::CreateEventManagement(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers, diff --git a/src/app/MessageDef/AttributeReportIB.h b/src/app/MessageDef/AttributeReportIB.h index d5f47183fe4d61..f237fb695ef620 100644 --- a/src/app/MessageDef/AttributeReportIB.h +++ b/src/app/MessageDef/AttributeReportIB.h @@ -91,6 +91,7 @@ class Builder : public StructBuilder */ AttributeDataIB::Builder & CreateAttributeData(); + AttributeDataIB::Builder & GetAttributeData() { return mAttributeData; } /** * @brief Initialize a StatusIB::Builder for writing into the TLV stream * diff --git a/src/app/MessageDef/AttributeReportIBs.h b/src/app/MessageDef/AttributeReportIBs.h index 88630f722db1e4..3f241cedfb798f 100644 --- a/src/app/MessageDef/AttributeReportIBs.h +++ b/src/app/MessageDef/AttributeReportIBs.h @@ -68,6 +68,8 @@ class Builder : public ArrayBuilder */ AttributeReportIB::Builder & CreateAttributeReport(); + AttributeReportIB::Builder & GetAttributeReport() { return mAttributeReport; } + /** * @brief Mark the end of this AttributeReportIBs * diff --git a/src/app/MessageDef/CommandPathIB.cpp b/src/app/MessageDef/CommandPathIB.cpp index d0fe5e805bc852..cb99837c91c6ec 100644 --- a/src/app/MessageDef/CommandPathIB.cpp +++ b/src/app/MessageDef/CommandPathIB.cpp @@ -169,5 +169,25 @@ CommandPathIB::Builder & CommandPathIB::Builder::EndOfCommandPathIB() return *this; } +CHIP_ERROR CommandPathIB::Builder::Encode(const CommandPathParams & aCommandPathParams) +{ + if (aCommandPathParams.mFlags.Has(CommandPathFlags::kEndpointIdValid)) + { + EndpointId(aCommandPathParams.mEndpointId); + } + + ClusterId(aCommandPathParams.mClusterId).CommandId(aCommandPathParams.mCommandId).EndOfCommandPathIB(); + return GetError(); +} + +CHIP_ERROR CommandPathIB::Builder::Encode(const ConcreteCommandPath & aConcreteCommandPath) +{ + EndpointId(aConcreteCommandPath.mEndpointId) + .ClusterId(aConcreteCommandPath.mClusterId) + .CommandId(aConcreteCommandPath.mCommandId) + .EndOfCommandPathIB(); + return GetError(); +} + }; // namespace app }; // namespace chip diff --git a/src/app/MessageDef/CommandPathIB.h b/src/app/MessageDef/CommandPathIB.h index 62296b5da568a5..35d0bad6f94451 100644 --- a/src/app/MessageDef/CommandPathIB.h +++ b/src/app/MessageDef/CommandPathIB.h @@ -22,6 +22,8 @@ #include "ListParser.h" #include +#include +#include #include #include #include @@ -128,6 +130,9 @@ class Builder : public ListBuilder * @return A reference to *this */ CommandPathIB::Builder & EndOfCommandPathIB(); + + CHIP_ERROR Encode(const CommandPathParams & aCommandPathParams); + CHIP_ERROR Encode(const ConcreteCommandPath & aConcreteCommandPath); }; } // namespace CommandPathIB } // namespace app diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index 0c2dd35c474c6f..2110044bd996b3 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -142,8 +142,8 @@ CHIP_ERROR ReadClient::SendReadRequest(ReadPrepareParams & aReadPrepareParams) if (aReadPrepareParams.mAttributePathParamsListSize != 0 && aReadPrepareParams.mpAttributePathParamsList != nullptr) { - AttributePathIBs::Builder attributePathListBuilder = request.CreateAttributeRequests(); - SuccessOrExit(err = attributePathListBuilder.GetError()); + AttributePathIBs::Builder & attributePathListBuilder = request.CreateAttributeRequests(); + SuccessOrExit(err = request.GetError()); err = GenerateAttributePathList(attributePathListBuilder, aReadPrepareParams.mpAttributePathParamsList, aReadPrepareParams.mAttributePathParamsListSize); SuccessOrExit(err); @@ -152,16 +152,17 @@ CHIP_ERROR ReadClient::SendReadRequest(ReadPrepareParams & aReadPrepareParams) if (aReadPrepareParams.mEventPathParamsListSize != 0 && aReadPrepareParams.mpEventPathParamsList != nullptr) { EventPathIBs::Builder & eventPathListBuilder = request.CreateEventRequests(); - SuccessOrExit(err = eventPathListBuilder.GetError()); + SuccessOrExit(err = request.GetError()); err = GenerateEventPaths(eventPathListBuilder, aReadPrepareParams.mpEventPathParamsList, aReadPrepareParams.mEventPathParamsListSize); SuccessOrExit(err); if (aReadPrepareParams.mEventNumber != 0) { // EventFilter is optional - EventFilterIBs::Builder eventFilters = request.CreateEventFilters(); + EventFilterIBs::Builder & eventFilters = request.CreateEventFilters(); SuccessOrExit(err = request.GetError()); - EventFilterIB::Builder eventFilter = eventFilters.CreateEventFilter(); + EventFilterIB::Builder & eventFilter = eventFilters.CreateEventFilter(); + SuccessOrExit(err = eventFilters.GetError()); eventFilter.EventMin(aReadPrepareParams.mEventNumber).EndOfEventFilterIB(); SuccessOrExit(err = eventFilter.GetError()); eventFilters.EndOfEventFilters(); @@ -205,7 +206,9 @@ CHIP_ERROR ReadClient::GenerateEventPaths(EventPathIBs::Builder & aEventPathsBui for (size_t index = 0; index < aEventPathParamsListSize; ++index) { VerifyOrReturnError(apEventPathParamsList[index].IsValidEventPath(), CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); - ReturnErrorOnFailure(aEventPathsBuilder.CreatePath().Encode(apEventPathParamsList[index])); + EventPathIB::Builder & path = aEventPathsBuilder.CreatePath(); + ReturnErrorOnFailure(aEventPathsBuilder.GetError()); + ReturnErrorOnFailure(path.Encode(apEventPathParamsList[index])); } aEventPathsBuilder.EndOfEventPaths(); @@ -219,7 +222,9 @@ CHIP_ERROR ReadClient::GenerateAttributePathList(AttributePathIBs::Builder & aAt for (size_t index = 0; index < aAttributePathParamsListSize; index++) { VerifyOrReturnError(apAttributePathParamsList[index].IsValidAttributePath(), CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH); - ReturnErrorOnFailure(aAttributePathIBsBuilder.CreatePath().Encode(apAttributePathParamsList[index])); + AttributePathIB::Builder path = aAttributePathIBsBuilder.CreatePath(); + ReturnErrorOnFailure(aAttributePathIBsBuilder.GetError()); + ReturnErrorOnFailure(path.Encode(apAttributePathParamsList[index])); } aAttributePathIBsBuilder.EndOfAttributePathIBs(); return aAttributePathIBsBuilder.GetError(); @@ -662,9 +667,10 @@ CHIP_ERROR ReadClient::SendSubscribeRequest(ReadPrepareParams & aReadPreparePara if (aReadPrepareParams.mEventNumber != 0) { // EventNumber is optional - EventFilterIBs::Builder eventFilters = request.CreateEventFilters(); + EventFilterIBs::Builder & eventFilters = request.CreateEventFilters(); SuccessOrExit(err = request.GetError()); - EventFilterIB::Builder eventFilter = eventFilters.CreateEventFilter(); + EventFilterIB::Builder & eventFilter = eventFilters.CreateEventFilter(); + SuccessOrExit(err = eventFilters.GetError()); eventFilter.EventMin(aReadPrepareParams.mEventNumber).EndOfEventFilterIB(); SuccessOrExit(err = eventFilter.GetError()); eventFilters.EndOfEventFilters(); diff --git a/src/app/WriteClient.cpp b/src/app/WriteClient.cpp index 50d6f71d29c9cd..270ced59c6bf89 100644 --- a/src/app/WriteClient.cpp +++ b/src/app/WriteClient.cpp @@ -36,7 +36,6 @@ CHIP_ERROR WriteClient::Init(Messaging::ExchangeManager * apExchangeMgr, Callbac VerifyOrReturnError(mpExchangeMgr == nullptr, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(mpExchangeCtx == nullptr, CHIP_ERROR_INCORRECT_STATE); - AttributeDataIBs::Builder attributeDataIBsBuilder; System::PacketBufferHandle packet = System::PacketBufferHandle::New(chip::app::kMaxSecureSduLengthBytes); VerifyOrReturnError(!packet.IsNull(), CHIP_ERROR_NO_MEMORY); @@ -45,8 +44,8 @@ CHIP_ERROR WriteClient::Init(Messaging::ExchangeManager * apExchangeMgr, Callbac ReturnErrorOnFailure(mWriteRequestBuilder.Init(&mMessageWriter)); mWriteRequestBuilder.TimedRequest(false); ReturnErrorOnFailure(mWriteRequestBuilder.GetError()); - attributeDataIBsBuilder = mWriteRequestBuilder.CreateWriteRequests(); - ReturnErrorOnFailure(attributeDataIBsBuilder.GetError()); + mWriteRequestBuilder.CreateWriteRequests(); + ReturnErrorOnFailure(mWriteRequestBuilder.GetError()); ClearExistingExchangeContext(); mpExchangeMgr = apExchangeMgr; mpCallback = apCallback; @@ -136,12 +135,14 @@ CHIP_ERROR WriteClient::ProcessWriteResponseMessage(System::PacketBufferHandle & CHIP_ERROR WriteClient::PrepareAttribute(const AttributePathParams & attributePathParams) { VerifyOrReturnError(attributePathParams.IsValidAttributePath(), CHIP_ERROR_INVALID_PATH_LIST); - AttributeDataIB::Builder attributeDataIB = mWriteRequestBuilder.GetWriteRequests().CreateAttributeDataIBBuilder(); - ReturnErrorOnFailure(attributeDataIB.GetError()); + AttributeDataIBs::Builder & writeRequests = mWriteRequestBuilder.GetWriteRequests(); + AttributeDataIB::Builder & attributeDataIB = writeRequests.CreateAttributeDataIBBuilder(); + ReturnErrorOnFailure(writeRequests.GetError()); // TODO: Add attribute version support attributeDataIB.DataVersion(0); ReturnErrorOnFailure(attributeDataIB.GetError()); - ReturnErrorOnFailure(attributeDataIB.CreatePath().Encode(attributePathParams)); + AttributePathIB::Builder & path = attributeDataIB.CreatePath(); + ReturnErrorOnFailure(path.Encode(attributePathParams)); return CHIP_NO_ERROR; } diff --git a/src/app/WriteHandler.cpp b/src/app/WriteHandler.cpp index e1b551862968f2..8b76d2ace34406 100644 --- a/src/app/WriteHandler.cpp +++ b/src/app/WriteHandler.cpp @@ -32,16 +32,16 @@ using namespace Protocols::InteractionModel; CHIP_ERROR WriteHandler::Init(InteractionModelDelegate * apDelegate) { IgnoreUnusedVariable(apDelegate); - VerifyOrReturnLogError(mpExchangeCtx == nullptr, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(mpExchangeCtx == nullptr, CHIP_ERROR_INCORRECT_STATE); System::PacketBufferHandle packet = System::PacketBufferHandle::New(chip::app::kMaxSecureSduLengthBytes); - VerifyOrReturnLogError(!packet.IsNull(), CHIP_ERROR_NO_MEMORY); + VerifyOrReturnError(!packet.IsNull(), CHIP_ERROR_NO_MEMORY); mMessageWriter.Init(std::move(packet)); - ReturnLogErrorOnFailure(mWriteResponseBuilder.Init(&mMessageWriter)); + ReturnErrorOnFailure(mWriteResponseBuilder.Init(&mMessageWriter)); - AttributeStatusIBs::Builder attributeStatusesBuilder = mWriteResponseBuilder.CreateWriteResponses(); - ReturnLogErrorOnFailure(attributeStatusesBuilder.GetError()); + mWriteResponseBuilder.CreateWriteResponses(); + ReturnErrorOnFailure(mWriteResponseBuilder.GetError()); MoveToState(State::Initialized); @@ -263,29 +263,25 @@ Status WriteHandler::ProcessWriteRequest(System::PacketBufferHandle && aPayload, CHIP_ERROR WriteHandler::AddStatus(const AttributePathParams & aAttributePathParams, const Protocols::InteractionModel::Status aStatus) { - CHIP_ERROR err = CHIP_NO_ERROR; - StatusIB::Builder statusIBBuilder; - StatusIB statusIB; - AttributeStatusIB::Builder attributeStatusIB = mWriteResponseBuilder.GetWriteResponses().CreateAttributeStatus(); - err = attributeStatusIB.GetError(); - SuccessOrExit(err); + AttributeStatusIBs::Builder & writeResponses = mWriteResponseBuilder.GetWriteResponses(); + AttributeStatusIB::Builder & attributeStatusIB = writeResponses.CreateAttributeStatus(); + ReturnErrorOnFailure(writeResponses.GetError()); - err = attributeStatusIB.CreatePath().Encode(aAttributePathParams); - SuccessOrExit(err); + AttributePathIB::Builder & path = attributeStatusIB.CreatePath(); + ReturnErrorOnFailure(attributeStatusIB.GetError()); + ReturnErrorOnFailure(path.Encode(aAttributePathParams)); - statusIB.mStatus = aStatus; - statusIBBuilder = attributeStatusIB.CreateErrorStatus(); + StatusIB statusIB; + statusIB.mStatus = aStatus; + StatusIB::Builder & statusIBBuilder = attributeStatusIB.CreateErrorStatus(); + ReturnErrorOnFailure(attributeStatusIB.GetError()); statusIBBuilder.EncodeStatusIB(statusIB); - err = statusIBBuilder.GetError(); - SuccessOrExit(err); - + ReturnErrorOnFailure(statusIBBuilder.GetError()); attributeStatusIB.EndOfAttributeStatusIB(); - err = attributeStatusIB.GetError(); - SuccessOrExit(err); - MoveToState(State::AddStatus); + ReturnErrorOnFailure(attributeStatusIB.GetError()); -exit: - return err; + MoveToState(State::AddStatus); + return CHIP_NO_ERROR; } FabricIndex WriteHandler::GetAccessingFabricIndex() const diff --git a/src/app/clusters/account-login-server/account-login-server.cpp b/src/app/clusters/account-login-server/account-login-server.cpp index 7b6b847eae3fc4..117cb464a68351 100644 --- a/src/app/clusters/account-login-server/account-login-server.cpp +++ b/src/app/clusters/account-login-server/account-login-server.cpp @@ -36,11 +36,10 @@ std::string accountLoginClusterGetSetupPin(std::string requestTempAccountIdentif void sendResponse(app::CommandHandler * command, const char * responseSetupPin) { - CHIP_ERROR err = CHIP_NO_ERROR; - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, AccountLogin::Id, - Commands::GetSetupPINResponse::Id, (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = command->PrepareCommand(cmdParams)); + CHIP_ERROR err = CHIP_NO_ERROR; + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), AccountLogin::Id, Commands::GetSetupPINResponse::Id }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = command->PrepareCommand(path)); VerifyOrExit((writer = command->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->PutString(TLV::ContextTag(0), responseSetupPin)); SuccessOrExit(err = command->FinishCommand()); diff --git a/src/app/clusters/application-launcher-server/application-launcher-server.cpp b/src/app/clusters/application-launcher-server/application-launcher-server.cpp index f7b892b3d43b5f..4f8da043335aa4 100644 --- a/src/app/clusters/application-launcher-server/application-launcher-server.cpp +++ b/src/app/clusters/application-launcher-server/application-launcher-server.cpp @@ -47,11 +47,10 @@ bool emberAfApplicationLauncherClusterLaunchAppCallback(app::CommandHandler * co void sendResponse(app::CommandHandler * command, ApplicationLauncherResponse response) { - CHIP_ERROR err = CHIP_NO_ERROR; - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ApplicationLauncher::Id, - Commands::LaunchAppResponse::Id, (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = command->PrepareCommand(cmdParams)); + CHIP_ERROR err = CHIP_NO_ERROR; + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ApplicationLauncher::Id, Commands::LaunchAppResponse::Id }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = command->PrepareCommand(path)); VerifyOrExit((writer = command->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), response.status)); SuccessOrExit(err = writer->PutString(TLV::ContextTag(1), reinterpret_cast(response.data))); diff --git a/src/app/clusters/door-lock-server/door-lock-server-logging.cpp b/src/app/clusters/door-lock-server/door-lock-server-logging.cpp index df42d8d924b2e8..c13b2b248e1d61 100644 --- a/src/app/clusters/door-lock-server/door-lock-server-logging.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server-logging.cpp @@ -140,11 +140,10 @@ bool emberAfDoorLockClusterGetLogRecordCallback(app::CommandHandler * commandObj else { { - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_DOOR_LOCK_CLUSTER_ID, - ZCL_GET_LOG_RECORD_RESPONSE_COMMAND_ID, - (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ZCL_DOOR_LOCK_CLUSTER_ID, + ZCL_GET_LOG_RECORD_RESPONSE_COMMAND_ID }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), entry.logEntryId)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), entry.timestamp)); diff --git a/src/app/clusters/door-lock-server/door-lock-server-schedule.cpp b/src/app/clusters/door-lock-server/door-lock-server-schedule.cpp index fea472f8c5cb67..0952b3c65a20bc 100644 --- a/src/app/clusters/door-lock-server/door-lock-server-schedule.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server-schedule.cpp @@ -197,10 +197,9 @@ bool emberAfDoorLockClusterGetWeekDayScheduleCallback(app::CommandHandler * comm } { - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ::Id, - Commands::GetWeekDayScheduleResponse::Id, (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ::Id, Commands::GetWeekDayScheduleResponse::Id }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), scheduleId)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), userId)); @@ -302,10 +301,9 @@ bool emberAfDoorLockClusterGetYearDayScheduleCallback(app::CommandHandler * comm } { - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ::Id, - Commands::GetYearDayScheduleResponse::Id, (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ::Id, Commands::GetYearDayScheduleResponse::Id }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), scheduleId)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), userId)); @@ -407,10 +405,9 @@ bool emberAfDoorLockClusterGetHolidayScheduleCallback(app::CommandHandler * comm } { - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ::Id, - Commands::GetHolidayScheduleResponse::Id, (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ::Id, Commands::GetHolidayScheduleResponse::Id }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), holidayScheduleId)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), zclStatus)); diff --git a/src/app/clusters/door-lock-server/door-lock-server-user.cpp b/src/app/clusters/door-lock-server/door-lock-server-user.cpp index ea5a8cfe6c7080..48c3c02889ea18 100644 --- a/src/app/clusters/door-lock-server/door-lock-server-user.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server-user.cpp @@ -236,10 +236,10 @@ bool emberAfDoorLockClusterGetUserTypeCallback(app::CommandHandler * commandObj, EmberAfPluginDoorLockServerUser * user = &pinUserTable[userId]; { - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_DOOR_LOCK_CLUSTER_ID, - ZCL_GET_USER_TYPE_RESPONSE_COMMAND_ID, (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ZCL_DOOR_LOCK_CLUSTER_ID, + ZCL_GET_USER_TYPE_RESPONSE_COMMAND_ID }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), userId)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), user->type)); @@ -350,10 +350,9 @@ bool emberAfDoorLockClusterGetPINCodeCallback(app::CommandHandler * commandObj, if (getUser(userId, pinUserTable, EMBER_AF_PLUGIN_DOOR_LOCK_SERVER_PIN_USER_TABLE_SIZE, &user)) { { - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ::Id, Commands::GetPINCodeResponse::Id, - (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ::Id, Commands::GetPINCodeResponse::Id }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), userId)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), user.status)); @@ -472,10 +471,10 @@ bool emberAfDoorLockClusterGetRFIDCodeCallback(app::CommandHandler * commandObj, if (getUser(userId, rfidUserTable, EMBER_AF_PLUGIN_DOOR_LOCK_SERVER_RFID_USER_TABLE_SIZE, &user)) { { - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_DOOR_LOCK_CLUSTER_ID, - Commands::GetRFIDCodeResponse::Id, (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ZCL_DOOR_LOCK_CLUSTER_ID, + Commands::GetRFIDCodeResponse::Id }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), userId)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), user.status)); diff --git a/src/app/clusters/groups-server/groups-server.cpp b/src/app/clusters/groups-server/groups-server.cpp index 452813c919f8ce..9ad7ead5edeec5 100644 --- a/src/app/clusters/groups-server/groups-server.cpp +++ b/src/app/clusters/groups-server/groups-server.cpp @@ -171,10 +171,9 @@ bool emberAfGroupsClusterAddGroupCallback(app::CommandHandler * commandObj, cons } { - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, Groups::Id, Commands::AddGroupResponse::Id, - (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), Groups::Id, Commands::AddGroupResponse::Id }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId)); @@ -230,10 +229,9 @@ bool emberAfGroupsClusterViewGroupCallback(app::CommandHandler * commandObj, con } { - app::CommandPathParams cmdParams = { endpointId, /* group id */ 0, Groups::Id, Commands::ViewGroupResponse::Id, - (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + app::ConcreteCommandPath path = { endpointId, Groups::Id, Commands::ViewGroupResponse::Id }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId)); @@ -380,10 +378,9 @@ bool emberAfGroupsClusterRemoveGroupCallback(app::CommandHandler * commandObj, c emberAfScenesClusterRemoveScenesInGroupCallback(endpointId, groupId); #endif { - app::CommandPathParams cmdParams = { endpointId, /* group id */ 0, Groups::Id, Commands::RemoveGroupResponse::Id, - (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + app::ConcreteCommandPath path = { endpointId, Groups::Id, Commands::RemoveGroupResponse::Id }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId)); diff --git a/src/app/clusters/identify-server/identify-server.cpp b/src/app/clusters/identify-server/identify-server.cpp index d01a8ec7487dce..c2f0fa4610d19f 100644 --- a/src/app/clusters/identify-server/identify-server.cpp +++ b/src/app/clusters/identify-server/identify-server.cpp @@ -261,13 +261,12 @@ bool emberAfIdentifyClusterIdentifyQueryCallback(CommandHandler * commandObj, co emberAfIdentifyClusterPrintln("Identifying for %u more seconds", identifyTime); { - app::CommandPathParams cmdParams = { endpoint, /* group id */ 0, Clusters::Identify::Id, - ZCL_IDENTIFY_QUERY_RESPONSE_COMMAND_ID, (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; + app::ConcreteCommandPath path = { endpoint, Clusters::Identify::Id, ZCL_IDENTIFY_QUERY_RESPONSE_COMMAND_ID }; + TLV::TLVWriter * writer = nullptr; VerifyOrExit(commandObj != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), identifyTime)); SuccessOrExit(err = commandObj->FinishCommand()); diff --git a/src/app/clusters/keypad-input-server/keypad-input-server.cpp b/src/app/clusters/keypad-input-server/keypad-input-server.cpp index 21602da1d07cc7..026eca546dc61e 100644 --- a/src/app/clusters/keypad-input-server/keypad-input-server.cpp +++ b/src/app/clusters/keypad-input-server/keypad-input-server.cpp @@ -38,13 +38,12 @@ EmberAfKeypadInputStatus keypadInputClusterSendKey(EmberAfKeypadInputCecKeyCode static void sendResponse(app::CommandHandler * command, EmberAfKeypadInputStatus keypadInputStatus) { - CHIP_ERROR err = CHIP_NO_ERROR; - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, KeypadInput::Id, - KeypadInput::Commands::SendKeyResponse::Id, (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; + CHIP_ERROR err = CHIP_NO_ERROR; + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), KeypadInput::Id, KeypadInput::Commands::SendKeyResponse::Id }; + TLV::TLVWriter * writer = nullptr; VerifyOrExit(command != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - SuccessOrExit(err = command->PrepareCommand(cmdParams)); + SuccessOrExit(err = command->PrepareCommand(path)); VerifyOrExit((writer = command->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), keypadInputStatus)); SuccessOrExit(err = command->FinishCommand()); diff --git a/src/app/clusters/media-playback-server/media-playback-server.cpp b/src/app/clusters/media-playback-server/media-playback-server.cpp index 6fadc47980baa8..3574f7822aa505 100644 --- a/src/app/clusters/media-playback-server/media-playback-server.cpp +++ b/src/app/clusters/media-playback-server/media-playback-server.cpp @@ -74,13 +74,12 @@ void storeNewPlaybackState(EndpointId endpoint, uint8_t newPlaybackState) static void sendResponse(app::CommandHandler * command, const char * responseName, CommandId commandId, EmberAfMediaPlaybackStatus mediaPlaybackStatus) { - CHIP_ERROR err = CHIP_NO_ERROR; - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, MediaPlayback::Id, commandId, - (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; + CHIP_ERROR err = CHIP_NO_ERROR; + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), MediaPlayback::Id, commandId }; + TLV::TLVWriter * writer = nullptr; VerifyOrExit(command != nullptr, err = CHIP_ERROR_INCORRECT_STATE); - SuccessOrExit(err = command->PrepareCommand(cmdParams)); + SuccessOrExit(err = command->PrepareCommand(path)); VerifyOrExit((writer = command->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), mediaPlaybackStatus)); SuccessOrExit(err = command->FinishCommand()); diff --git a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp index 0133a29a97c0e0..e9151697e14918 100644 --- a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp +++ b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp @@ -362,13 +362,12 @@ FabricInfo gFabricBeingCommissioned; CHIP_ERROR SendNOCResponse(app::CommandHandler * commandObj, EmberAfNodeOperationalCertStatus status, uint8_t index, CharSpan debug_text) { - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, OperationalCredentials::Id, - Commands::NOCResponse::Id, (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), OperationalCredentials::Id, Commands::NOCResponse::Id }; + TLV::TLVWriter * writer = nullptr; VerifyOrReturnError(commandObj != nullptr, CHIP_ERROR_INCORRECT_STATE); - ReturnErrorOnFailure(commandObj->PrepareCommand(cmdParams)); + ReturnErrorOnFailure(commandObj->PrepareCommand(path)); writer = commandObj->GetCommandDataIBTLVWriter(); ReturnErrorOnFailure(writer->Put(TLV::ContextTag(0), status)); if (status == EMBER_ZCL_NODE_OPERATIONAL_CERT_STATUS_SUCCESS) diff --git a/src/app/clusters/scenes/scenes.cpp b/src/app/clusters/scenes/scenes.cpp index 3a7fca8dd7b35d..126a17f48b92f8 100644 --- a/src/app/clusters/scenes/scenes.cpp +++ b/src/app/clusters/scenes/scenes.cpp @@ -289,10 +289,10 @@ bool emberAfScenesClusterRemoveSceneCallback(app::CommandHandler * commandObj, c if (emberAfCurrentCommand()->type == EMBER_INCOMING_UNICAST || emberAfCurrentCommand()->type == EMBER_INCOMING_UNICAST_REPLY) { { - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_SCENES_CLUSTER_ID, - ZCL_REMOVE_SCENE_RESPONSE_COMMAND_ID, (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ZCL_SCENES_CLUSTER_ID, + ZCL_REMOVE_SCENE_RESPONSE_COMMAND_ID }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId)); @@ -342,11 +342,10 @@ bool emberAfScenesClusterRemoveAllScenesCallback(app::CommandHandler * commandOb if (emberAfCurrentCommand()->type == EMBER_INCOMING_UNICAST || emberAfCurrentCommand()->type == EMBER_INCOMING_UNICAST_REPLY) { { - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_SCENES_CLUSTER_ID, - ZCL_REMOVE_ALL_SCENES_RESPONSE_COMMAND_ID, - (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ZCL_SCENES_CLUSTER_ID, + ZCL_REMOVE_ALL_SCENES_RESPONSE_COMMAND_ID }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId)); @@ -378,10 +377,10 @@ bool emberAfScenesClusterStoreSceneCallback(app::CommandHandler * commandObj, co if (emberAfCurrentCommand()->type == EMBER_INCOMING_UNICAST || emberAfCurrentCommand()->type == EMBER_INCOMING_UNICAST_REPLY) { { - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_SCENES_CLUSTER_ID, - ZCL_STORE_SCENE_RESPONSE_COMMAND_ID, (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ZCL_SCENES_CLUSTER_ID, + ZCL_STORE_SCENE_RESPONSE_COMMAND_ID }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId)); @@ -474,11 +473,10 @@ bool emberAfScenesClusterGetSceneMembershipCallback(app::CommandHandler * comman } { - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_SCENES_CLUSTER_ID, - ZCL_GET_SCENE_MEMBERSHIP_RESPONSE_COMMAND_ID, - (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ZCL_SCENES_CLUSTER_ID, + ZCL_GET_SCENE_MEMBERSHIP_RESPONSE_COMMAND_ID }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), @@ -1078,14 +1076,13 @@ bool emberAfPluginScenesServerParseAddScene( return true; } { - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_SCENES_CLUSTER_ID, - ZCL_ADD_SCENE_RESPONSE_COMMAND_ID, (app::CommandPathFlags::kEndpointIdValid) }; + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ZCL_SCENES_CLUSTER_ID, ZCL_ADD_SCENE_RESPONSE_COMMAND_ID }; if (enhanced) { - cmdParams.mCommandId = ZCL_ENHANCED_ADD_SCENE_RESPONSE_COMMAND_ID; + path = { emberAfCurrentEndpoint(), ZCL_SCENES_CLUSTER_ID, ZCL_ENHANCED_ADD_SCENE_RESPONSE_COMMAND_ID }; } TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId)); @@ -1135,14 +1132,13 @@ bool emberAfPluginScenesServerParseViewScene(app::CommandHandler * commandObj, c // The status, group id, and scene id are always included in the response, but // the transition time, name, and extension fields are only included if the // scene was found. - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_SCENES_CLUSTER_ID, - ZCL_VIEW_SCENE_RESPONSE_COMMAND_ID, (app::CommandPathFlags::kEndpointIdValid) }; + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), ZCL_SCENES_CLUSTER_ID, ZCL_VIEW_SCENE_RESPONSE_COMMAND_ID }; if (enhanced) { - cmdParams.mCommandId = ZCL_ENHANCED_VIEW_SCENE_RESPONSE_COMMAND_ID; + path = { emberAfCurrentEndpoint(), ZCL_SCENES_CLUSTER_ID, ZCL_ENHANCED_VIEW_SCENE_RESPONSE_COMMAND_ID }; } TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = commandObj->PrepareCommand(cmdParams)); + SuccessOrExit(err = commandObj->PrepareCommand(path)); VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status)); SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId)); diff --git a/src/app/clusters/target-navigator-server/target-navigator-server.cpp b/src/app/clusters/target-navigator-server/target-navigator-server.cpp index 9b5f420bf09dc8..1250cc5afa1dce 100644 --- a/src/app/clusters/target-navigator-server/target-navigator-server.cpp +++ b/src/app/clusters/target-navigator-server/target-navigator-server.cpp @@ -36,12 +36,11 @@ TargetNavigatorResponse targetNavigatorClusterNavigateTarget(uint8_t target, std void sendResponse(app::CommandHandler * command, TargetNavigatorResponse response) { - CHIP_ERROR err = CHIP_NO_ERROR; - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, TargetNavigator::Id, - TargetNavigator::Commands::NavigateTargetResponse::Id, - (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = command->PrepareCommand(cmdParams)); + CHIP_ERROR err = CHIP_NO_ERROR; + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), TargetNavigator::Id, + TargetNavigator::Commands::NavigateTargetResponse::Id }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = command->PrepareCommand(path)); VerifyOrExit((writer = command->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); SuccessOrExit(err = writer->Put(TLV::ContextTag(0), response.status)); SuccessOrExit(err = writer->PutString(TLV::ContextTag(1), reinterpret_cast(response.data))); diff --git a/src/app/clusters/tv-channel-server/tv-channel-server.cpp b/src/app/clusters/tv-channel-server/tv-channel-server.cpp index 9c81fc2beaa8fd..5068015c072ff4 100644 --- a/src/app/clusters/tv-channel-server/tv-channel-server.cpp +++ b/src/app/clusters/tv-channel-server/tv-channel-server.cpp @@ -54,11 +54,10 @@ bool tvChannelClusterSkipChannel(uint16_t count); void sendResponse(app::CommandHandler * command, ::TvChannelInfo channelInfo) { - CHIP_ERROR err = CHIP_NO_ERROR; - app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, TvChannel::Id, - Commands::ChangeChannelResponse::Id, (app::CommandPathFlags::kEndpointIdValid) }; - TLV::TLVWriter * writer = nullptr; - SuccessOrExit(err = command->PrepareCommand(cmdParams)); + CHIP_ERROR err = CHIP_NO_ERROR; + app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), TvChannel::Id, Commands::ChangeChannelResponse::Id }; + TLV::TLVWriter * writer = nullptr; + SuccessOrExit(err = command->PrepareCommand(path)); VerifyOrExit((writer = command->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE); // TODO: Enable this once struct as param is supported // SuccessOrExit(err = writer->Put(TLV::ContextTag(0), channelInfo)); diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp index 36d8cf2288e121..2aa1dfc5481b75 100644 --- a/src/app/reporting/Engine.cpp +++ b/src/app/reporting/Engine.cpp @@ -64,24 +64,12 @@ CHIP_ERROR Engine::RetrieveClusterData(FabricIndex aAccessingFabricIndex, AttributeReportIBs::Builder & aAttributeReportIBs, const ConcreteReadAttributePath & aPath, AttributeValueEncoder::AttributeEncodeState * aEncoderState) { - CHIP_ERROR err = CHIP_NO_ERROR; - ChipLogDetail(DataManagement, " Cluster %" PRIx32 ", Attribute %" PRIx32 " is dirty", aPath.mClusterId, aPath.mAttributeId); - MatterPreAttributeReadCallback(aPath); - err = ReadSingleClusterData(aAccessingFabricIndex, aPath, aAttributeReportIBs, aEncoderState); + ReturnErrorOnFailure(ReadSingleClusterData(aAccessingFabricIndex, aPath, aAttributeReportIBs, aEncoderState)); MatterPostAttributeReadCallback(aPath); - SuccessOrExit(err); - -exit: - if (err != CHIP_NO_ERROR) - { - ChipLogError(DataManagement, "Error retrieving data from clusterId: " ChipLogFormatMEI ", err = %" CHIP_ERROR_FORMAT, - ChipLogValueMEI(aPath.mClusterId), err.Format()); - } - - return err; + return CHIP_NO_ERROR; } CHIP_ERROR Engine::BuildSingleReportDataAttributeReportIBs(ReportDataMessage::Builder & aReportDataBuilder, @@ -95,8 +83,9 @@ CHIP_ERROR Engine::BuildSingleReportDataAttributeReportIBs(ReportDataMessage::Bu const uint32_t kReservedSizeEndOfReportIBs = 1; aReportDataBuilder.Checkpoint(backup); - auto attributeReportIBs = aReportDataBuilder.CreateAttributeReportIBs(); - size_t emptyReportDataLength = 0; + + AttributeReportIBs::Builder & attributeReportIBs = aReportDataBuilder.CreateAttributeReportIBs(); + size_t emptyReportDataLength = 0; SuccessOrExit(err = aReportDataBuilder.GetError()); @@ -144,6 +133,10 @@ CHIP_ERROR Engine::BuildSingleReportDataAttributeReportIBs(ReportDataMessage::Bu err = RetrieveClusterData(apReadHandler->GetAccessingFabricIndex(), attributeReportIBs, pathForRetrieval, &encodeState); if (err != CHIP_NO_ERROR) { + ChipLogError(DataManagement, + "Error retrieving data from clusterId: " ChipLogFormatMEI ", err = %" CHIP_ERROR_FORMAT, + ChipLogValueMEI(pathForRetrieval.mClusterId), err.Format()); + if (encodeState.AllowPartialData()) { // Encoding is aborted but partial data is allowed, then we don't rollback and save the state for next chunk. @@ -245,20 +238,16 @@ CHIP_ERROR Engine::BuildSingleReportDataEventReports(ReportDataMessage::Builder ClusterInfo * clusterInfoList = apReadHandler->GetEventClusterInfolist(); EventNumber * eventNumberList = apReadHandler->GetVendedEventNumberList(); EventManagement & eventManager = EventManagement::GetInstance(); - EventReportIBs::Builder EventReportIBs; - bool hasMoreChunks = false; + bool hasMoreChunks = false; aReportDataBuilder.Checkpoint(backup); VerifyOrExit(clusterInfoList != nullptr, ); - VerifyOrExit(apReadHandler != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); + // If the eventManager is not valid or has not been initialized, // skip the rest of processing VerifyOrExit(eventManager.IsValid(), ChipLogError(DataManagement, "EventManagement has not yet initialized")); - EventReportIBs = aReportDataBuilder.CreateEventReports(); - SuccessOrExit(err = EventReportIBs.GetError()); - memcpy(initialEvents, eventNumberList, sizeof(initialEvents)); for (size_t index = 0; index < kNumPriorityLevel; index++) @@ -278,57 +267,60 @@ CHIP_ERROR Engine::BuildSingleReportDataEventReports(ReportDataMessage::Builder ExitNow(); // Read clean, move along } - while (apReadHandler->GetCurrentPriority() != PriorityLevel::Invalid) { - uint8_t priorityIndex = static_cast(apReadHandler->GetCurrentPriority()); - err = eventManager.FetchEventsSince(*(EventReportIBs.GetWriter()), clusterInfoList, apReadHandler->GetCurrentPriority(), - eventNumberList[priorityIndex], eventCount); - - if ((err == CHIP_END_OF_TLV) || (err == CHIP_ERROR_TLV_UNDERRUN) || (err == CHIP_NO_ERROR)) + EventReportIBs::Builder & eventReportIBs = aReportDataBuilder.CreateEventReports(); + SuccessOrExit(err = aReportDataBuilder.GetError()); + while (apReadHandler->GetCurrentPriority() != PriorityLevel::Invalid) { - // We have successfully reached the end of the log for - // the current priority. Advance to the next - // priority level. - err = CHIP_NO_ERROR; - apReadHandler->MoveToNextScheduledDirtyPriority(); - hasMoreChunks = false; - } - else if ((err == CHIP_ERROR_BUFFER_TOO_SMALL) || (err == CHIP_ERROR_NO_MEMORY)) - { - // when first cluster event is too big to fit in the packet, ignore that cluster event. - if (eventCount == 0) + uint8_t priorityIndex = static_cast(apReadHandler->GetCurrentPriority()); + err = eventManager.FetchEventsSince(*(eventReportIBs.GetWriter()), clusterInfoList, apReadHandler->GetCurrentPriority(), + eventNumberList[priorityIndex], eventCount); + + if ((err == CHIP_END_OF_TLV) || (err == CHIP_ERROR_TLV_UNDERRUN) || (err == CHIP_NO_ERROR)) { - eventNumberList[priorityIndex]++; - ChipLogDetail(DataManagement, " first cluster event is too big so that it fails to fit in the packet!"); + // We have successfully reached the end of the log for + // the current priority. Advance to the next + // priority level. err = CHIP_NO_ERROR; + apReadHandler->MoveToNextScheduledDirtyPriority(); + hasMoreChunks = false; + } + else if ((err == CHIP_ERROR_BUFFER_TOO_SMALL) || (err == CHIP_ERROR_NO_MEMORY)) + { + // when first cluster event is too big to fit in the packet, ignore that cluster event. + if (eventCount == 0) + { + eventNumberList[priorityIndex]++; + ChipLogDetail(DataManagement, " first cluster event is too big so that it fails to fit in the packet!"); + err = CHIP_NO_ERROR; + } + else + { + // `FetchEventsSince` has filled the available space + // within the allowed buffer before it fit all the + // available events. This is an expected condition, + // so we do not propagate the error to higher levels; + // instead, we terminate the event processing for now + // (we will get another chance immediately afterwards, + // with a ew buffer) and do not advance the processing + // to the next priority level. + err = CHIP_NO_ERROR; + break; + } + hasMoreChunks = true; } else { - // `FetchEventsSince` has filled the available space - // within the allowed buffer before it fit all the - // available events. This is an expected condition, - // so we do not propagate the error to higher levels; - // instead, we terminate the event processing for now - // (we will get another chance immediately afterwards, - // with a ew buffer) and do not advance the processing - // to the next priority level. - err = CHIP_NO_ERROR; - break; + // All other errors are propagated to higher level. + // Exiting here and returning an error will lead to + // abandoning subscription. + ExitNow(); } - hasMoreChunks = true; - } - else - { - // All other errors are propagated to higher level. - // Exiting here and returning an error will lead to - // abandoning subscription. - ExitNow(); } - } - - EventReportIBs.EndOfEventReports(); - SuccessOrExit(err = EventReportIBs.GetError()); + eventReportIBs.EndOfEventReports(); + SuccessOrExit(err = eventReportIBs.GetError()); + } ChipLogDetail(DataManagement, "Fetched %zu events", eventCount); exit: @@ -367,6 +359,7 @@ CHIP_ERROR Engine::BuildAndSendSingleReportData(ReadHandler * apReadHandler) // Reserved size for the end of report message, which is an end-of-container (i.e 1 byte for the control tag). const uint32_t kReservedSizeForEndOfReportMessage = 1; + VerifyOrExit(apReadHandler != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); VerifyOrExit(!bufHandle.IsNull(), err = CHIP_ERROR_NO_MEMORY); if (bufHandle->AvailableDataLength() > kMaxSecureSduLengthBytes) diff --git a/src/app/tests/TestCommandInteraction.cpp b/src/app/tests/TestCommandInteraction.cpp index 34a27058176aa9..23a54ecb993aca 100644 --- a/src/app/tests/TestCommandInteraction.cpp +++ b/src/app/tests/TestCommandInteraction.cpp @@ -93,10 +93,7 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, chip } else { - CommandPathParams responseParams = { aCommandPath.mEndpointId, /* groupId */ 0, aCommandPath.mClusterId, - aCommandPath.mCommandId, (chip::app::CommandPathFlags::kEndpointIdValid) }; - - apCommandObj->PrepareCommand(responseParams); + apCommandObj->PrepareCommand(aCommandPath); chip::TLV::TLVWriter * writer = apCommandObj->GetCommandDataIBTLVWriter(); writer->PutBoolean(chip::TLV::ContextTag(1), true); apCommandObj->FinishCommand(); @@ -232,13 +229,13 @@ void TestCommandInteraction::GenerateInvokeRequest(nlTestSuite * apSuite, void * NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); invokeRequestMessageBuilder.SuppressResponse(true).TimedRequest(aIsTimedRequest); - InvokeRequests::Builder invokeRequests = invokeRequestMessageBuilder.CreateInvokeRequests(); + InvokeRequests::Builder & invokeRequests = invokeRequestMessageBuilder.CreateInvokeRequests(); NL_TEST_ASSERT(apSuite, invokeRequestMessageBuilder.GetError() == CHIP_NO_ERROR); - CommandDataIB::Builder commandDataIBBuilder = invokeRequests.CreateCommandData(); + CommandDataIB::Builder & commandDataIBBuilder = invokeRequests.CreateCommandData(); NL_TEST_ASSERT(apSuite, invokeRequests.GetError() == CHIP_NO_ERROR); - CommandPathIB::Builder commandPathBuilder = commandDataIBBuilder.CreatePath(); + CommandPathIB::Builder & commandPathBuilder = commandDataIBBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, commandDataIBBuilder.GetError() == CHIP_NO_ERROR); commandPathBuilder.EndpointId(aEndpointId).ClusterId(aClusterId).CommandId(aCommandId).EndOfCommandPathIB(); @@ -286,16 +283,16 @@ void TestCommandInteraction::GenerateInvokeResponse(nlTestSuite * apSuite, void NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); invokeResponseMessageBuilder.SuppressResponse(true); - InvokeResponseIBs::Builder invokeResponses = invokeResponseMessageBuilder.CreateInvokeResponses(); + InvokeResponseIBs::Builder & invokeResponses = invokeResponseMessageBuilder.CreateInvokeResponses(); NL_TEST_ASSERT(apSuite, invokeResponseMessageBuilder.GetError() == CHIP_NO_ERROR); - InvokeResponseIB::Builder invokeResponseIBBuilder = invokeResponses.CreateInvokeResponse(); + InvokeResponseIB::Builder & invokeResponseIBBuilder = invokeResponses.CreateInvokeResponse(); NL_TEST_ASSERT(apSuite, invokeResponses.GetError() == CHIP_NO_ERROR); - CommandDataIB::Builder commandDataIBBuilder = invokeResponseIBBuilder.CreateCommand(); + CommandDataIB::Builder & commandDataIBBuilder = invokeResponseIBBuilder.CreateCommand(); NL_TEST_ASSERT(apSuite, commandDataIBBuilder.GetError() == CHIP_NO_ERROR); - CommandPathIB::Builder commandPathBuilder = commandDataIBBuilder.CreatePath(); + CommandPathIB::Builder & commandPathBuilder = commandDataIBBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, commandDataIBBuilder.GetError() == CHIP_NO_ERROR); commandPathBuilder.EndpointId(aEndpointId).ClusterId(aClusterId).CommandId(aCommandId).EndOfCommandPathIB(); @@ -353,8 +350,7 @@ void TestCommandInteraction::AddInvokeRequestData(nlTestSuite * apSuite, void * void TestCommandInteraction::AddInvokeResponseData(nlTestSuite * apSuite, void * apContext, CommandHandler * apCommandHandler, bool aNeedStatusCode, CommandId aCommandId) { - CHIP_ERROR err = CHIP_NO_ERROR; - auto commandPathParams = MakeTestCommandPath(aCommandId); + CHIP_ERROR err = CHIP_NO_ERROR; if (aNeedStatusCode) { @@ -366,7 +362,8 @@ void TestCommandInteraction::AddInvokeResponseData(nlTestSuite * apSuite, void * } else { - err = apCommandHandler->PrepareCommand(commandPathParams); + ConcreteCommandPath path = { kTestEndpointId, kTestClusterId, aCommandId }; + err = apCommandHandler->PrepareCommand(path); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); chip::TLV::TLVWriter * writer = apCommandHandler->GetCommandDataIBTLVWriter(); @@ -393,13 +390,13 @@ void TestCommandInteraction::TestCommandSenderWithWrongState(nlTestSuite * apSui void TestCommandInteraction::TestCommandHandlerWithWrongState(nlTestSuite * apSuite, void * apContext) { - TestContext & ctx = *static_cast(apContext); - CHIP_ERROR err = CHIP_NO_ERROR; - auto commandPathParams = MakeTestCommandPath(); + TestContext & ctx = *static_cast(apContext); + CHIP_ERROR err = CHIP_NO_ERROR; + ConcreteCommandPath path = { kTestEndpointId, kTestClusterId, kTestCommandId }; app::CommandHandler commandHandler(&mockCommandHandlerDelegate); - err = commandHandler.PrepareCommand(commandPathParams); + err = commandHandler.PrepareCommand(path); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); TestExchangeDelegate delegate; @@ -429,16 +426,17 @@ void TestCommandInteraction::TestCommandSenderWithSendCommand(nlTestSuite * apSu void TestCommandInteraction::TestCommandHandlerWithSendEmptyCommand(nlTestSuite * apSuite, void * apContext) { - TestContext & ctx = *static_cast(apContext); - CHIP_ERROR err = CHIP_NO_ERROR; - auto commandPathParams = MakeTestCommandPath(); + TestContext & ctx = *static_cast(apContext); + CHIP_ERROR err = CHIP_NO_ERROR; + ConcreteCommandPath path = { kTestEndpointId, kTestClusterId, kTestCommandId }; app::CommandHandler commandHandler(&mockCommandHandlerDelegate); System::PacketBufferHandle commandDatabuf = System::PacketBufferHandle::New(System::PacketBuffer::kMaxSize); TestExchangeDelegate delegate; commandHandler.mpExchangeCtx = ctx.NewExchangeToAlice(&delegate); - err = commandHandler.PrepareCommand(commandPathParams); + + err = commandHandler.PrepareCommand(path); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); err = commandHandler.FinishCommand(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); diff --git a/src/app/tests/TestMessageDef.cpp b/src/app/tests/TestMessageDef.cpp index b984621e2f7e1b..cef68604872580 100644 --- a/src/app/tests/TestMessageDef.cpp +++ b/src/app/tests/TestMessageDef.cpp @@ -128,7 +128,7 @@ void ParseEventFilterIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) void BuildEventFilters(nlTestSuite * apSuite, EventFilterIBs::Builder & aEventFiltersBuilder) { - EventFilterIB::Builder eventFilterBuilder = aEventFiltersBuilder.CreateEventFilter(); + EventFilterIB::Builder & eventFilterBuilder = aEventFiltersBuilder.CreateEventFilter(); NL_TEST_ASSERT(apSuite, aEventFiltersBuilder.GetError() == CHIP_NO_ERROR); BuildEventFilterIB(apSuite, eventFilterBuilder); aEventFiltersBuilder.EndOfEventFilters(); @@ -201,7 +201,7 @@ void ParseAttributePathIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) void BuildAttributePathList(nlTestSuite * apSuite, AttributePathIBs::Builder & aAttributePathListBuilder) { - AttributePathIB::Builder attributePathBuilder = aAttributePathListBuilder.CreatePath(); + AttributePathIB::Builder & attributePathBuilder = aAttributePathListBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); BuildAttributePathIB(apSuite, attributePathBuilder); @@ -263,7 +263,7 @@ void ParseEventPath(nlTestSuite * apSuite, EventPathIB::Parser & aEventPathParse void BuildEventPaths(nlTestSuite * apSuite, EventPathIBs::Builder & aEventPathsBuilder) { - EventPathIB::Builder eventPathBuilder = aEventPathsBuilder.CreatePath(); + EventPathIB::Builder & eventPathBuilder = aEventPathsBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, eventPathBuilder.GetError() == CHIP_NO_ERROR); BuildEventPath(apSuite, eventPathBuilder); @@ -319,7 +319,7 @@ void BuildEventDataIB(nlTestSuite * apSuite, EventDataIB::Builder & aEventDataIB { CHIP_ERROR err = CHIP_NO_ERROR; - EventPathIB::Builder eventPathBuilder = aEventDataIBBuilder.CreatePath(); + EventPathIB::Builder & eventPathBuilder = aEventDataIBBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, eventPathBuilder.GetError() == CHIP_NO_ERROR); BuildEventPath(apSuite, eventPathBuilder); @@ -400,11 +400,11 @@ void ParseEventDataIB(nlTestSuite * apSuite, EventDataIB::Parser & aEventDataIBP void BuildEventStatusIB(nlTestSuite * apSuite, EventStatusIB::Builder & aEventStatusIBBuilder) { - EventPathIB::Builder eventPathBuilder = aEventStatusIBBuilder.CreatePath(); + EventPathIB::Builder & eventPathBuilder = aEventStatusIBBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, aEventStatusIBBuilder.GetError() == CHIP_NO_ERROR); BuildEventPath(apSuite, eventPathBuilder); - StatusIB::Builder statusIBBuilder = aEventStatusIBBuilder.CreateErrorStatus(); + StatusIB::Builder & statusIBBuilder = aEventStatusIBBuilder.CreateErrorStatus(); NL_TEST_ASSERT(apSuite, statusIBBuilder.GetError() == CHIP_NO_ERROR); BuildStatusIB(apSuite, statusIBBuilder); @@ -430,7 +430,7 @@ void ParseEventStatusIB(nlTestSuite * apSuite, EventStatusIB::Parser & aEventSta void BuildEventReportIB(nlTestSuite * apSuite, EventReportIB::Builder & aEventReportIBBuilder) { - EventDataIB::Builder eventDataIBBuilder = aEventReportIBBuilder.CreateEventData(); + EventDataIB::Builder & eventDataIBBuilder = aEventReportIBBuilder.CreateEventData(); NL_TEST_ASSERT(apSuite, aEventReportIBBuilder.GetError() == CHIP_NO_ERROR); BuildEventDataIB(apSuite, eventDataIBBuilder); @@ -455,7 +455,7 @@ void ParseEventReportIB(nlTestSuite * apSuite, EventReportIB::Parser & aEventRep void BuildEventReports(nlTestSuite * apSuite, EventReportIBs::Builder & aEventReportsBuilder) { - EventReportIB::Builder eventReportIBBuilder = aEventReportsBuilder.CreateEventReport(); + EventReportIB::Builder & eventReportIBBuilder = aEventReportsBuilder.CreateEventReport(); NL_TEST_ASSERT(apSuite, aEventReportsBuilder.GetError() == CHIP_NO_ERROR); BuildEventReportIB(apSuite, eventReportIBBuilder); @@ -478,11 +478,11 @@ void ParseEventReports(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) void BuildAttributeStatusIB(nlTestSuite * apSuite, AttributeStatusIB::Builder & aAttributeStatusIBBuilder) { - AttributePathIB::Builder attributePathBuilder = aAttributeStatusIBBuilder.CreatePath(); + AttributePathIB::Builder & attributePathBuilder = aAttributeStatusIBBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); BuildAttributePathIB(apSuite, attributePathBuilder); - StatusIB::Builder statusIBBuilder = aAttributeStatusIBBuilder.CreateErrorStatus(); + StatusIB::Builder & statusIBBuilder = aAttributeStatusIBBuilder.CreateErrorStatus(); NL_TEST_ASSERT(apSuite, statusIBBuilder.GetError() == CHIP_NO_ERROR); BuildStatusIB(apSuite, statusIBBuilder); @@ -509,7 +509,7 @@ void ParseAttributeStatusIB(nlTestSuite * apSuite, AttributeStatusIB::Parser & a void BuildAttributeStatuses(nlTestSuite * apSuite, AttributeStatusIBs::Builder & aAttributeStatusesBuilder) { - AttributeStatusIB::Builder aAttributeStatusIBBuilder = aAttributeStatusesBuilder.CreateAttributeStatus(); + AttributeStatusIB::Builder & aAttributeStatusIBBuilder = aAttributeStatusesBuilder.CreateAttributeStatus(); NL_TEST_ASSERT(apSuite, aAttributeStatusesBuilder.GetError() == CHIP_NO_ERROR); BuildAttributeStatusIB(apSuite, aAttributeStatusIBBuilder); @@ -536,7 +536,7 @@ void BuildAttributeDataIB(nlTestSuite * apSuite, AttributeDataIB::Builder & aAtt CHIP_ERROR err = CHIP_NO_ERROR; aAttributeDataIBBuilder.DataVersion(2); - AttributePathIB::Builder attributePathBuilder = aAttributeDataIBBuilder.CreatePath(); + AttributePathIB::Builder & attributePathBuilder = aAttributeDataIBBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, aAttributeDataIBBuilder.GetError() == CHIP_NO_ERROR); BuildAttributePathIB(apSuite, attributePathBuilder); @@ -597,9 +597,9 @@ void ParseAttributeDataIB(nlTestSuite * apSuite, AttributeDataIB::Parser & aAttr void BuildAttributeDataIBs(nlTestSuite * apSuite, AttributeDataIBs::Builder & aAttributeDataIBsBuilder) { - AttributeDataIB::Builder AttributeDataIBBuilder = aAttributeDataIBsBuilder.CreateAttributeDataIBBuilder(); + AttributeDataIB::Builder & attributeDataIBBuilder = aAttributeDataIBsBuilder.CreateAttributeDataIBBuilder(); NL_TEST_ASSERT(apSuite, aAttributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeDataIB(apSuite, AttributeDataIBBuilder); + BuildAttributeDataIB(apSuite, attributeDataIBBuilder); aAttributeDataIBsBuilder.EndOfAttributeDataIBs(); NL_TEST_ASSERT(apSuite, aAttributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); @@ -620,7 +620,7 @@ void ParseAttributeDataIBs(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader void BuildAttributeReportIB(nlTestSuite * apSuite, AttributeReportIB::Builder & aAttributeReportIBBuilder) { - AttributeDataIB::Builder attributeDataIBBuilder = aAttributeReportIBBuilder.CreateAttributeData(); + AttributeDataIB::Builder & attributeDataIBBuilder = aAttributeReportIBBuilder.CreateAttributeData(); NL_TEST_ASSERT(apSuite, aAttributeReportIBBuilder.GetError() == CHIP_NO_ERROR); BuildAttributeDataIB(apSuite, attributeDataIBBuilder); @@ -644,7 +644,7 @@ void ParseAttributeReportIB(nlTestSuite * apSuite, AttributeReportIB::Parser & a void BuildAttributeReportIBs(nlTestSuite * apSuite, AttributeReportIBs::Builder & aAttributeReportIBsBuilder) { - AttributeReportIB::Builder attributeReportIBBuilder = aAttributeReportIBsBuilder.CreateAttributeReport(); + AttributeReportIB::Builder & attributeReportIBBuilder = aAttributeReportIBsBuilder.CreateAttributeReport(); NL_TEST_ASSERT(apSuite, aAttributeReportIBsBuilder.GetError() == CHIP_NO_ERROR); BuildAttributeReportIB(apSuite, attributeReportIBBuilder); @@ -693,7 +693,7 @@ void BuildCommandDataIB(nlTestSuite * apSuite, CommandDataIB::Builder & aCommand { CHIP_ERROR err = CHIP_NO_ERROR; - CommandPathIB::Builder commandPathBuilder = aCommandDataIBBuilder.CreatePath(); + CommandPathIB::Builder & commandPathBuilder = aCommandDataIBBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, aCommandDataIBBuilder.GetError() == CHIP_NO_ERROR); BuildCommandPath(apSuite, commandPathBuilder); @@ -748,11 +748,11 @@ void ParseCommandDataIB(nlTestSuite * apSuite, CommandDataIB::Parser & aCommandD void BuildCommandStatusIB(nlTestSuite * apSuite, CommandStatusIB::Builder & aCommandStatusIBBuilder) { - CommandPathIB::Builder commandPathBuilder = aCommandStatusIBBuilder.CreatePath(); + CommandPathIB::Builder & commandPathBuilder = aCommandStatusIBBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, aCommandStatusIBBuilder.GetError() == CHIP_NO_ERROR); BuildCommandPath(apSuite, commandPathBuilder); - StatusIB::Builder statusIBBuilder = aCommandStatusIBBuilder.CreateErrorStatus(); + StatusIB::Builder & statusIBBuilder = aCommandStatusIBBuilder.CreateErrorStatus(); NL_TEST_ASSERT(apSuite, statusIBBuilder.GetError() == CHIP_NO_ERROR); BuildStatusIB(apSuite, statusIBBuilder); @@ -778,10 +778,10 @@ void ParseCommandStatusIB(nlTestSuite * apSuite, CommandStatusIB::Parser & aComm void BuildWrongInvokeResponseIB(nlTestSuite * apSuite, InvokeResponseIB::Builder & aInvokeResponseIBBuilder) { - CommandDataIB::Builder commandDataBuilder = aInvokeResponseIBBuilder.CreateCommand(); + CommandDataIB::Builder & commandDataBuilder = aInvokeResponseIBBuilder.CreateCommand(); NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); BuildCommandDataIB(apSuite, commandDataBuilder); - CommandStatusIB::Builder commandStatusBuilder = aInvokeResponseIBBuilder.CreateStatus(); + CommandStatusIB::Builder & commandStatusBuilder = aInvokeResponseIBBuilder.CreateStatus(); NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); BuildCommandStatusIB(apSuite, commandStatusBuilder); aInvokeResponseIBBuilder.EndOfInvokeResponseIB(); @@ -790,7 +790,7 @@ void BuildWrongInvokeResponseIB(nlTestSuite * apSuite, InvokeResponseIB::Builder void BuildInvokeResponseIBWithCommandDataIB(nlTestSuite * apSuite, InvokeResponseIB::Builder & aInvokeResponseIBBuilder) { - CommandDataIB::Builder commandDataBuilder = aInvokeResponseIBBuilder.CreateCommand(); + CommandDataIB::Builder & commandDataBuilder = aInvokeResponseIBBuilder.CreateCommand(); NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); BuildCommandDataIB(apSuite, commandDataBuilder); aInvokeResponseIBBuilder.EndOfInvokeResponseIB(); @@ -799,7 +799,7 @@ void BuildInvokeResponseIBWithCommandDataIB(nlTestSuite * apSuite, InvokeRespons void BuildInvokeResponseIBWithCommandStatusIB(nlTestSuite * apSuite, InvokeResponseIB::Builder & aInvokeResponseIBBuilder) { - CommandStatusIB::Builder commandStatusBuilder = aInvokeResponseIBBuilder.CreateStatus(); + CommandStatusIB::Builder & commandStatusBuilder = aInvokeResponseIBBuilder.CreateStatus(); NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); BuildCommandStatusIB(apSuite, commandStatusBuilder); aInvokeResponseIBBuilder.EndOfInvokeResponseIB(); @@ -844,7 +844,7 @@ void ParseWrongInvokeResponseIB(nlTestSuite * apSuite, InvokeResponseIB::Parser void BuildInvokeRequests(nlTestSuite * apSuite, InvokeRequests::Builder & aInvokeRequestsBuilder) { - CommandDataIB::Builder aCommandDataIBBuilder = aInvokeRequestsBuilder.CreateCommandData(); + CommandDataIB::Builder & aCommandDataIBBuilder = aInvokeRequestsBuilder.CreateCommandData(); NL_TEST_ASSERT(apSuite, aInvokeRequestsBuilder.GetError() == CHIP_NO_ERROR); BuildCommandDataIB(apSuite, aCommandDataIBBuilder); @@ -867,7 +867,7 @@ void ParseInvokeRequests(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) void BuildInvokeResponses(nlTestSuite * apSuite, InvokeResponseIBs::Builder & aInvokeResponsesBuilder) { - InvokeResponseIB::Builder invokeResponseIBBuilder = aInvokeResponsesBuilder.CreateInvokeResponse(); + InvokeResponseIB::Builder & invokeResponseIBBuilder = aInvokeResponsesBuilder.CreateInvokeResponse(); NL_TEST_ASSERT(apSuite, aInvokeResponsesBuilder.GetError() == CHIP_NO_ERROR); BuildInvokeResponseIBWithCommandDataIB(apSuite, invokeResponseIBBuilder); @@ -896,7 +896,7 @@ void BuildInvokeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWr NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); invokeRequestMessageBuilder.SuppressResponse(true); invokeRequestMessageBuilder.TimedRequest(true); - InvokeRequests::Builder invokeRequestsBuilder = invokeRequestMessageBuilder.CreateInvokeRequests(); + InvokeRequests::Builder & invokeRequestsBuilder = invokeRequestMessageBuilder.CreateInvokeRequests(); NL_TEST_ASSERT(apSuite, invokeRequestsBuilder.GetError() == CHIP_NO_ERROR); BuildInvokeRequests(apSuite, invokeRequestsBuilder); @@ -931,7 +931,7 @@ void BuildInvokeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aW err = invokeResponseMessageBuilder.Init(&aWriter); invokeResponseMessageBuilder.SuppressResponse(true); - InvokeResponseIBs::Builder invokeResponsesBuilder = invokeResponseMessageBuilder.CreateInvokeResponses(); + InvokeResponseIBs::Builder & invokeResponsesBuilder = invokeResponseMessageBuilder.CreateInvokeResponses(); NL_TEST_ASSERT(apSuite, invokeResponseMessageBuilder.GetError() == CHIP_NO_ERROR); BuildInvokeResponses(apSuite, invokeResponsesBuilder); @@ -967,13 +967,13 @@ void BuildReportDataMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWrite reportDataMessageBuilder.SubscriptionId(2); NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); - AttributeReportIBs::Builder AttributeReportIBs = reportDataMessageBuilder.CreateAttributeReportIBs(); + AttributeReportIBs::Builder & attributeReportIBs = reportDataMessageBuilder.CreateAttributeReportIBs(); NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeReportIBs(apSuite, AttributeReportIBs); + BuildAttributeReportIBs(apSuite, attributeReportIBs); - EventReportIBs::Builder EventReportIBs = reportDataMessageBuilder.CreateEventReports(); + EventReportIBs::Builder & eventReportIBs = reportDataMessageBuilder.CreateEventReports(); NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); - BuildEventReports(apSuite, EventReportIBs); + BuildEventReports(apSuite, eventReportIBs); reportDataMessageBuilder.MoreChunkedMessages(true).SuppressResponse(true); NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); @@ -1022,15 +1022,15 @@ void BuildReadRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWrit err = readRequestBuilder.Init(&aWriter); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributePathIBs::Builder AttributePathIBs = readRequestBuilder.CreateAttributeRequests(); + AttributePathIBs::Builder & attributePathIBs = readRequestBuilder.CreateAttributeRequests(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributePathList(apSuite, AttributePathIBs); + BuildAttributePathList(apSuite, attributePathIBs); - EventPathIBs::Builder eventPathList = readRequestBuilder.CreateEventRequests(); + EventPathIBs::Builder & eventPathList = readRequestBuilder.CreateEventRequests(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); BuildEventPaths(apSuite, eventPathList); - EventFilterIBs::Builder eventFilters = readRequestBuilder.CreateEventFilters(); + EventFilterIBs::Builder & eventFilters = readRequestBuilder.CreateEventFilters(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); BuildEventFilters(apSuite, eventFilters); @@ -1084,9 +1084,9 @@ void BuildWriteRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWri writeRequestBuilder.TimedRequest(true); NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); - AttributeDataIBs::Builder AttributeDataIBs = writeRequestBuilder.CreateWriteRequests(); + AttributeDataIBs::Builder & attributeDataIBs = writeRequestBuilder.CreateWriteRequests(); NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeDataIBs(apSuite, AttributeDataIBs); + BuildAttributeDataIBs(apSuite, attributeDataIBs); writeRequestBuilder.MoreChunkedMessages(true); NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); @@ -1139,7 +1139,7 @@ void BuildWriteResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWr err = writeResponseBuilder.Init(&aWriter); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributeStatusIBs::Builder attributeStatuses = writeResponseBuilder.CreateWriteResponses(); + AttributeStatusIBs::Builder & attributeStatuses = writeResponseBuilder.CreateWriteResponses(); NL_TEST_ASSERT(apSuite, writeResponseBuilder.GetError() == CHIP_NO_ERROR); BuildAttributeStatuses(apSuite, attributeStatuses); @@ -1180,15 +1180,15 @@ void BuildSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & subscribeRequestBuilder.MaxIntervalCeilingSeconds(3); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - AttributePathIBs::Builder attributePathIBs = subscribeRequestBuilder.CreateAttributeRequests(); + AttributePathIBs::Builder & attributePathIBs = subscribeRequestBuilder.CreateAttributeRequests(); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); BuildAttributePathList(apSuite, attributePathIBs); - EventPathIBs::Builder eventPathList = subscribeRequestBuilder.CreateEventRequests(); + EventPathIBs::Builder & eventPathList = subscribeRequestBuilder.CreateEventRequests(); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); BuildEventPaths(apSuite, eventPathList); - EventFilterIBs::Builder eventFilters = subscribeRequestBuilder.CreateEventFilters(); + EventFilterIBs::Builder & eventFilters = subscribeRequestBuilder.CreateEventFilters(); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); BuildEventFilters(apSuite, eventFilters); @@ -2104,24 +2104,24 @@ void CheckPointRollbackTest(nlTestSuite * apSuite, void * apContext) AttributeDataIBs::Parser AttributeDataIBsParser; chip::TLV::TLVWriter checkpoint; writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize)); - AttributeDataIBs::Builder AttributeDataIBsBuilder; - AttributeDataIBsBuilder.Init(&writer); + AttributeDataIBs::Builder attributeDataIBsBuilder; + attributeDataIBsBuilder.Init(&writer); // encode one attribute element - AttributeDataIB::Builder AttributeDataIBBuilder1 = AttributeDataIBsBuilder.CreateAttributeDataIBBuilder(); - NL_TEST_ASSERT(apSuite, AttributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeDataIB(apSuite, AttributeDataIBBuilder1); + AttributeDataIB::Builder & attributeDataIBBuilder1 = attributeDataIBsBuilder.CreateAttributeDataIBBuilder(); + NL_TEST_ASSERT(apSuite, attributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); + BuildAttributeDataIB(apSuite, attributeDataIBBuilder1); // checkpoint - AttributeDataIBsBuilder.Checkpoint(checkpoint); + attributeDataIBsBuilder.Checkpoint(checkpoint); // encode another attribute element - AttributeDataIB::Builder AttributeDataIBBuilder2 = AttributeDataIBsBuilder.CreateAttributeDataIBBuilder(); - NL_TEST_ASSERT(apSuite, AttributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); - BuildAttributeDataIB(apSuite, AttributeDataIBBuilder2); + AttributeDataIB::Builder & attributeDataIBBuilder2 = attributeDataIBsBuilder.CreateAttributeDataIBBuilder(); + NL_TEST_ASSERT(apSuite, attributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); + BuildAttributeDataIB(apSuite, attributeDataIBBuilder2); // rollback to previous checkpoint - AttributeDataIBsBuilder.Rollback(checkpoint); + attributeDataIBsBuilder.Rollback(checkpoint); - AttributeDataIBsBuilder.EndOfAttributeDataIBs(); - NL_TEST_ASSERT(apSuite, AttributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); + attributeDataIBsBuilder.EndOfAttributeDataIBs(); + NL_TEST_ASSERT(apSuite, attributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); chip::System::PacketBufferHandle buf; err = writer.Finalize(&buf); diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index e8a3f58171d205..d9ec63db51b8b3 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -233,18 +233,21 @@ CHIP_ERROR ReadSingleClusterData(FabricIndex aAccessingFabricIndex, const Concre if (!(aPath.mClusterId == kTestClusterId && aPath.mEndpointId == kTestEndpointId)) { - AttributeReportIB::Builder attributeReport = aAttributeReports.CreateAttributeReport(); - AttributeDataIB::Builder attributeData; - AttributePathIB::Builder attributePath; + AttributeReportIB::Builder & attributeReport = aAttributeReports.CreateAttributeReport(); + ReturnErrorOnFailure(aAttributeReports.GetError()); ChipLogDetail(DataManagement, "TEST Cluster %" PRIx32 ", Field %" PRIx32 " is dirty", aPath.mClusterId, aPath.mAttributeId); - AttributeStatusIB::Builder attributeStatus; - attributeStatus = attributeReport.CreateAttributeStatus(); - attributePath = attributeStatus.CreatePath(); + AttributeStatusIB::Builder & attributeStatus = attributeReport.CreateAttributeStatus(); + ReturnErrorOnFailure(attributeReport.GetError()); + AttributePathIB::Builder & attributePath = attributeStatus.CreatePath(); + ReturnErrorOnFailure(attributeStatus.GetError()); + attributePath.Endpoint(aPath.mEndpointId).Cluster(aPath.mClusterId).Attribute(aPath.mAttributeId).EndOfAttributePathIB(); ReturnErrorOnFailure(attributePath.GetError()); - StatusIB::Builder errorStatus = attributeStatus.CreateErrorStatus(); + StatusIB::Builder & errorStatus = attributeStatus.CreateErrorStatus(); + ReturnErrorOnFailure(attributeStatus.GetError()); errorStatus.EncodeStatusIB(StatusIB(Protocols::InteractionModel::Status::UnsupportedAttribute)); + ReturnErrorOnFailure(errorStatus.GetError()); attributeStatus.EndOfAttributeStatusIB(); ReturnErrorOnFailure(attributeStatus.GetError()); return attributeReport.EndOfAttributeReportIB().GetError(); @@ -294,20 +297,20 @@ void TestReadInteraction::GenerateReportData(nlTestSuite * apSuite, void * apCon err = reportDataMessageBuilder.Init(&writer); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributeReportIBs::Builder attributeReportIBsBuilder = reportDataMessageBuilder.CreateAttributeReportIBs(); + AttributeReportIBs::Builder & attributeReportIBsBuilder = reportDataMessageBuilder.CreateAttributeReportIBs(); NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR); - AttributeReportIB::Builder attributeReportIBBuilder = attributeReportIBsBuilder.CreateAttributeReport(); + AttributeReportIB::Builder & attributeReportIBBuilder = attributeReportIBsBuilder.CreateAttributeReport(); NL_TEST_ASSERT(apSuite, attributeReportIBsBuilder.GetError() == CHIP_NO_ERROR); - AttributeDataIB::Builder attributeDataIBBuilder = attributeReportIBBuilder.CreateAttributeData(); + AttributeDataIB::Builder & attributeDataIBBuilder = attributeReportIBBuilder.CreateAttributeData(); NL_TEST_ASSERT(apSuite, attributeReportIBBuilder.GetError() == CHIP_NO_ERROR); attributeDataIBBuilder.DataVersion(2); err = attributeDataIBBuilder.GetError(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributePathIB::Builder attributePathBuilder = attributeDataIBBuilder.CreatePath(); + AttributePathIB::Builder & attributePathBuilder = attributeDataIBBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, attributeDataIBBuilder.GetError() == CHIP_NO_ERROR); if (aNeedInvalidReport) @@ -404,10 +407,10 @@ void TestReadInteraction::TestReadHandler(nlTestSuite * apSuite, void * apContex err = readRequestBuilder.Init(&writer); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - AttributePathIBs::Builder attributePathListBuilder = readRequestBuilder.CreateAttributeRequests(); + AttributePathIBs::Builder & attributePathListBuilder = readRequestBuilder.CreateAttributeRequests(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); - AttributePathIB::Builder attributePathBuilder = attributePathListBuilder.CreatePath(); + AttributePathIB::Builder & attributePathBuilder = attributePathListBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); attributePathBuilder.Node(1).Endpoint(2).Cluster(3).Attribute(4).EndOfAttributePathIB(); @@ -536,7 +539,7 @@ void TestReadInteraction::TestReadHandlerInvalidAttributePath(nlTestSuite * apSu AttributePathIBs::Builder attributePathListBuilder = readRequestBuilder.CreateAttributeRequests(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); - AttributePathIB::Builder attributePathBuilder = attributePathListBuilder.CreatePath(); + AttributePathIB::Builder & attributePathBuilder = attributePathListBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); attributePathBuilder.Node(1).Endpoint(2).Cluster(3).ListIndex(5).EndOfAttributePathIB(); @@ -944,10 +947,10 @@ void TestReadInteraction::TestProcessSubscribeRequest(nlTestSuite * apSuite, voi subscribeRequestBuilder.MaxIntervalCeilingSeconds(3); NL_TEST_ASSERT(apSuite, subscribeRequestBuilder.GetError() == CHIP_NO_ERROR); - AttributePathIBs::Builder attributePathListBuilder = subscribeRequestBuilder.CreateAttributeRequests(); + AttributePathIBs::Builder & attributePathListBuilder = subscribeRequestBuilder.CreateAttributeRequests(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); - AttributePathIB::Builder attributePathBuilder = attributePathListBuilder.CreatePath(); + AttributePathIB::Builder & attributePathBuilder = attributePathListBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); attributePathBuilder.Node(1).Endpoint(2).Cluster(3).Attribute(4).ListIndex(5).EndOfAttributePathIB(); diff --git a/src/app/tests/TestReportingEngine.cpp b/src/app/tests/TestReportingEngine.cpp index 16070422c5b386..dac801851cc044 100644 --- a/src/app/tests/TestReportingEngine.cpp +++ b/src/app/tests/TestReportingEngine.cpp @@ -73,8 +73,6 @@ void TestReportingEngine::TestBuildAndSendSingleReportData(nlTestSuite * apSuite System::PacketBufferTLVWriter writer; System::PacketBufferHandle readRequestbuf = System::PacketBufferHandle::New(System::PacketBuffer::kMaxSize); ReadRequestMessage::Builder readRequestBuilder; - AttributePathIBs::Builder attributePathListBuilder; - AttributePathIB::Builder attributePathBuilder; err = InteractionModelEngine::GetInstance()->Init(&ctx.GetExchangeManager(), nullptr); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); @@ -85,25 +83,25 @@ void TestReportingEngine::TestBuildAndSendSingleReportData(nlTestSuite * apSuite writer.Init(std::move(readRequestbuf)); err = readRequestBuilder.Init(&writer); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - attributePathListBuilder = readRequestBuilder.CreateAttributeRequests(); + AttributePathIBs::Builder & attributePathListBuilder = readRequestBuilder.CreateAttributeRequests(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); - attributePathBuilder = attributePathListBuilder.CreatePath(); + AttributePathIB::Builder & attributePathBuilder1 = attributePathListBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); - attributePathBuilder = attributePathBuilder.Node(1) - .Endpoint(kTestEndpointId) - .Cluster(kTestClusterId) - .Attribute(kTestFieldId1) - .EndOfAttributePathIB(); - NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); - - attributePathBuilder = attributePathListBuilder.CreatePath(); + attributePathBuilder1 = attributePathBuilder1.Node(1) + .Endpoint(kTestEndpointId) + .Cluster(kTestClusterId) + .Attribute(kTestFieldId1) + .EndOfAttributePathIB(); + NL_TEST_ASSERT(apSuite, attributePathBuilder1.GetError() == CHIP_NO_ERROR); + + AttributePathIB::Builder & attributePathBuilder2 = attributePathListBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, attributePathListBuilder.GetError() == CHIP_NO_ERROR); - attributePathBuilder = attributePathBuilder.Node(1) - .Endpoint(kTestEndpointId) - .Cluster(kTestClusterId) - .Attribute(kTestFieldId2) - .EndOfAttributePathIB(); - NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); + attributePathBuilder2 = attributePathBuilder2.Node(1) + .Endpoint(kTestEndpointId) + .Cluster(kTestClusterId) + .Attribute(kTestFieldId2) + .EndOfAttributePathIB(); + NL_TEST_ASSERT(apSuite, attributePathBuilder2.GetError() == CHIP_NO_ERROR); attributePathListBuilder.EndOfAttributePathIBs(); NL_TEST_ASSERT(apSuite, readRequestBuilder.GetError() == CHIP_NO_ERROR); diff --git a/src/app/tests/TestWriteInteraction.cpp b/src/app/tests/TestWriteInteraction.cpp index c850a4b40a38d0..bfb9bf3d2e8fb1 100644 --- a/src/app/tests/TestWriteInteraction.cpp +++ b/src/app/tests/TestWriteInteraction.cpp @@ -128,14 +128,14 @@ void TestWriteInteraction::GenerateWriteRequest(nlTestSuite * apSuite, void * ap NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); writeRequestBuilder.TimedRequest(aIsTimedWrite); NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); - AttributeDataIBs::Builder attributeDataIBsBuilder = writeRequestBuilder.CreateWriteRequests(); + AttributeDataIBs::Builder & attributeDataIBsBuilder = writeRequestBuilder.CreateWriteRequests(); NL_TEST_ASSERT(apSuite, writeRequestBuilder.GetError() == CHIP_NO_ERROR); - AttributeDataIB::Builder attributeDataIBBuilder = attributeDataIBsBuilder.CreateAttributeDataIBBuilder(); + AttributeDataIB::Builder & attributeDataIBBuilder = attributeDataIBsBuilder.CreateAttributeDataIBBuilder(); NL_TEST_ASSERT(apSuite, attributeDataIBsBuilder.GetError() == CHIP_NO_ERROR); attributeDataIBBuilder.DataVersion(0); NL_TEST_ASSERT(apSuite, attributeDataIBBuilder.GetError() == CHIP_NO_ERROR); - AttributePathIB::Builder attributePathBuilder = attributeDataIBBuilder.CreatePath(); + AttributePathIB::Builder & attributePathBuilder = attributeDataIBBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); attributePathBuilder.Node(1).Endpoint(2).Cluster(3).Attribute(4).ListIndex(5).EndOfAttributePathIB(); err = attributePathBuilder.GetError(); @@ -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); - AttributeStatusIBs::Builder attributeStatusesBuilder = writeResponseBuilder.CreateWriteResponses(); + AttributeStatusIBs::Builder & attributeStatusesBuilder = writeResponseBuilder.CreateWriteResponses(); NL_TEST_ASSERT(apSuite, attributeStatusesBuilder.GetError() == CHIP_NO_ERROR); - AttributeStatusIB::Builder attributeStatusIBBuilder = attributeStatusesBuilder.CreateAttributeStatus(); + AttributeStatusIB::Builder & attributeStatusIBBuilder = attributeStatusesBuilder.CreateAttributeStatus(); NL_TEST_ASSERT(apSuite, attributeStatusIBBuilder.GetError() == CHIP_NO_ERROR); - AttributePathIB::Builder attributePathBuilder = attributeStatusIBBuilder.CreatePath(); + AttributePathIB::Builder & attributePathBuilder = attributeStatusIBBuilder.CreatePath(); NL_TEST_ASSERT(apSuite, attributePathBuilder.GetError() == CHIP_NO_ERROR); 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.CreateErrorStatus(); + StatusIB::Builder & statusIBBuilder = attributeStatusIBBuilder.CreateErrorStatus(); StatusIB statusIB; statusIB.mStatus = chip::Protocols::InteractionModel::Status::InvalidSubscription; NL_TEST_ASSERT(apSuite, statusIBBuilder.GetError() == CHIP_NO_ERROR); diff --git a/src/app/tests/integration/chip_im_initiator.cpp b/src/app/tests/integration/chip_im_initiator.cpp index 32f6dfcbd71eb1..5b1d07f7eed010 100644 --- a/src/app/tests/integration/chip_im_initiator.cpp +++ b/src/app/tests/integration/chip_im_initiator.cpp @@ -630,13 +630,17 @@ CHIP_ERROR ReadSingleClusterData(FabricIndex aAccessingFabricIndex, const Concre AttributeReportIBs::Builder & aAttributeReports, AttributeValueEncoder::AttributeEncodeState * apEncoderState) { - AttributeReportIB::Builder attributeReport = aAttributeReports.CreateAttributeReport(); - AttributeStatusIB::Builder attributeStatus = attributeReport.CreateAttributeStatus(); - AttributePathIB::Builder attributePath = attributeStatus.CreatePath(); + AttributeReportIB::Builder & attributeReport = aAttributeReports.CreateAttributeReport(); + ReturnErrorOnFailure(aAttributeReports.GetError()); + AttributeStatusIB::Builder & attributeStatus = attributeReport.CreateAttributeStatus(); + ReturnErrorOnFailure(attributeReport.GetError()); + AttributePathIB::Builder & attributePath = attributeStatus.CreatePath(); + ReturnErrorOnFailure(attributeStatus.GetError()); attributePath.Endpoint(aPath.mEndpointId).Cluster(aPath.mClusterId).Attribute(aPath.mAttributeId).EndOfAttributePathIB(); ReturnErrorOnFailure(attributePath.GetError()); - StatusIB::Builder errorStatus = attributeStatus.CreateErrorStatus(); + StatusIB::Builder & errorStatus = attributeStatus.CreateErrorStatus(); errorStatus.EncodeStatusIB(StatusIB(Protocols::InteractionModel::Status::UnsupportedAttribute)); + ReturnErrorOnFailure(errorStatus.GetError()); attributeStatus.EndOfAttributeStatusIB(); ReturnErrorOnFailure(attributeStatus.GetError()); return attributeReport.EndOfAttributeReportIB().GetError(); diff --git a/src/app/tests/integration/chip_im_responder.cpp b/src/app/tests/integration/chip_im_responder.cpp index fcbf7c46d25c7d..84ff6566b7e84a 100644 --- a/src/app/tests/integration/chip_im_responder.cpp +++ b/src/app/tests/integration/chip_im_responder.cpp @@ -67,21 +67,17 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, chip chip::TLV::Debug::Dump(aReader, TLVPrettyPrinter); } - chip::app::CommandPathParams commandPathParams = { kTestEndpointId, // Endpoint - kTestGroupId, // GroupId - kTestClusterId, // ClusterId - kTestCommandId, // CommandId - (chip::app::CommandPathFlags::kEndpointIdValid) }; + chip::app::ConcreteCommandPath path = { + kTestEndpointId, // Endpoint + kTestClusterId, // ClusterId + kTestCommandId, // CommandId + }; // Add command data here if (statusCodeFlipper) { - chip::app::ConcreteCommandPath commandPath(kTestEndpointId, // Endpoint - kTestClusterId, // ClusterId - kTestCommandId // CommandId - ); printf("responder constructing status code in command"); - apCommandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::Success); + apCommandObj->AddStatus(path, Protocols::InteractionModel::Status::Success); } else { @@ -89,7 +85,7 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aCommandPath, chip chip::TLV::TLVWriter * writer; - ReturnOnFailure(apCommandObj->PrepareCommand(commandPathParams)); + ReturnOnFailure(apCommandObj->PrepareCommand(path)); writer = apCommandObj->GetCommandDataIBTLVWriter(); ReturnOnFailure(writer->Put(chip::TLV::ContextTag(kTestFieldId1), kTestFieldValue1)); diff --git a/src/app/util/ember-compatibility-functions.cpp b/src/app/util/ember-compatibility-functions.cpp index 7433fe29311f1a..cf196ddf61748c 100644 --- a/src/app/util/ember-compatibility-functions.cpp +++ b/src/app/util/ember-compatibility-functions.cpp @@ -231,14 +231,18 @@ CHIP_ERROR SendFailureStatus(const ConcreteAttributePath & aPath, AttributeRepor { aAttributeReport.Rollback(*aReportCheckpoint); } - AttributeStatusIB::Builder attributeStatusIBBuilder = aAttributeReport.CreateAttributeStatus(); - AttributePathIB::Builder attributePathIBBuilder = attributeStatusIBBuilder.CreatePath(); + AttributeStatusIB::Builder & attributeStatusIBBuilder = aAttributeReport.CreateAttributeStatus(); + ReturnErrorOnFailure(aAttributeReport.GetError()); + AttributePathIB::Builder & attributePathIBBuilder = attributeStatusIBBuilder.CreatePath(); + ReturnErrorOnFailure(attributeStatusIBBuilder.GetError()); + attributePathIBBuilder.Endpoint(aPath.mEndpointId) .Cluster(aPath.mClusterId) .Attribute(aPath.mAttributeId) .EndOfAttributePathIB(); ReturnErrorOnFailure(attributePathIBBuilder.GetError()); - StatusIB::Builder statusIBBuilder = attributeStatusIBBuilder.CreateErrorStatus(); + StatusIB::Builder & statusIBBuilder = attributeStatusIBBuilder.CreateErrorStatus(); + ReturnErrorOnFailure(attributeStatusIBBuilder.GetError()); statusIBBuilder.EncodeStatusIB(StatusIB(aStatus)); ReturnErrorOnFailure(statusIBBuilder.GetError()); @@ -306,13 +310,14 @@ CHIP_ERROR ReadSingleClusterData(FabricIndex aAccessingFabricIndex, const Concre attributeReport.Checkpoint(backup); // We have verified that the attribute exists. - AttributeDataIB::Builder attributeDataIBBuilder = attributeReport.CreateAttributeData(); + AttributeDataIB::Builder & attributeDataIBBuilder = attributeReport.CreateAttributeData(); + ReturnErrorOnFailure(attributeDataIBBuilder.GetError()); attributeDataIBBuilder.DataVersion(kTemporaryDataVersion); ReturnErrorOnFailure(attributeDataIBBuilder.GetError()); - AttributePathIB::Builder attributePathIBBuilder = attributeDataIBBuilder.CreatePath(); + AttributePathIB::Builder & attributePathIBBuilder = attributeDataIBBuilder.CreatePath(); ReturnErrorOnFailure(attributeDataIBBuilder.GetError()); attributePathIBBuilder.Endpoint(aPath.mEndpointId) diff --git a/src/app/util/mock/attribute-storage.cpp b/src/app/util/mock/attribute-storage.cpp index ec5a1b6b626e92..6966b0ce4ae7da 100644 --- a/src/app/util/mock/attribute-storage.cpp +++ b/src/app/util/mock/attribute-storage.cpp @@ -224,16 +224,18 @@ CHIP_ERROR ReadSingleMockClusterData(FabricIndex aAccessingFabricIndex, const Co if (!dataExists) { - AttributeReportIB::Builder attributeReport = aAttributeReports.CreateAttributeReport(); - AttributeDataIB::Builder attributeData; - AttributePathIB::Builder attributePath; - AttributeStatusIB::Builder attributeStatus; - attributeStatus = attributeReport.CreateAttributeStatus(); - attributePath = attributeStatus.CreatePath(); + AttributeReportIB::Builder & attributeReport = aAttributeReports.CreateAttributeReport(); + ReturnErrorOnFailure(aAttributeReports.GetError()); + AttributeStatusIB::Builder & attributeStatus = attributeReport.CreateAttributeStatus(); + ReturnErrorOnFailure(attributeReport.GetError()); + AttributePathIB::Builder & attributePath = attributeStatus.CreatePath(); + ReturnErrorOnFailure(attributeStatus.GetError()); attributePath.Endpoint(aPath.mEndpointId).Cluster(aPath.mClusterId).Attribute(aPath.mAttributeId).EndOfAttributePathIB(); ReturnErrorOnFailure(attributePath.GetError()); - StatusIB::Builder errorStatus = attributeStatus.CreateErrorStatus(); + StatusIB::Builder & errorStatus = attributeStatus.CreateErrorStatus(); + ReturnErrorOnFailure(attributeStatus.GetError()); errorStatus.EncodeStatusIB(StatusIB(Protocols::InteractionModel::Status::UnsupportedAttribute)); + ReturnErrorOnFailure(errorStatus.GetError()); attributeStatus.EndOfAttributeStatusIB(); ReturnErrorOnFailure(attributeStatus.GetError()); return attributeReport.EndOfAttributeReportIB().GetError(); @@ -261,13 +263,13 @@ CHIP_ERROR ReadSingleMockClusterData(FabricIndex aAccessingFabricIndex, const Co return err; } - AttributeReportIB::Builder attributeReport = aAttributeReports.CreateAttributeReport(); - AttributeDataIB::Builder attributeData; - AttributePathIB::Builder attributePath; - - attributeData = attributeReport.CreateAttributeData(); + AttributeReportIB::Builder & attributeReport = aAttributeReports.CreateAttributeReport(); + ReturnErrorOnFailure(aAttributeReports.GetError()); + AttributeDataIB::Builder & attributeData = attributeReport.CreateAttributeData(); + ReturnErrorOnFailure(attributeReport.GetError()); attributeData.DataVersion(0); - attributePath = attributeData.CreatePath(); + AttributePathIB::Builder & attributePath = attributeData.CreatePath(); + ReturnErrorOnFailure(attributeData.GetError()); attributePath.Endpoint(aPath.mEndpointId).Cluster(aPath.mClusterId).Attribute(aPath.mAttributeId).EndOfAttributePathIB(); ReturnErrorOnFailure(attributePath.GetError());