Skip to content

Commit

Permalink
Remove mMessageWriter member of WriteHandler. (#15068)
Browse files Browse the repository at this point in the history
Fixes #14943
  • Loading branch information
bzbarsky-apple authored Feb 14, 2022
1 parent 4d510a3 commit 129841e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
17 changes: 8 additions & 9 deletions src/app/WriteHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ void WriteHandler::Close()
{
VerifyOrReturn(mState != State::Uninitialized);

mMessageWriter.Reset();

if (mpExchangeCtx != nullptr)
{
mpExchangeCtx->SetDelegate(nullptr);
Expand Down Expand Up @@ -83,8 +81,9 @@ Status WriteHandler::HandleWriteRequestMessage(Messaging::ExchangeContext * apEx
System::PacketBufferHandle packet = System::PacketBufferHandle::New(chip::app::kMaxSecureSduLengthBytes);
VerifyOrReturnError(!packet.IsNull(), Status::Failure);

mMessageWriter.Init(std::move(packet));
VerifyOrReturnError(mWriteResponseBuilder.Init(&mMessageWriter) == CHIP_NO_ERROR, Status::Failure);
System::PacketBufferTLVWriter messageWriter;
messageWriter.Init(std::move(packet));
VerifyOrReturnError(mWriteResponseBuilder.Init(&messageWriter) == CHIP_NO_ERROR, Status::Failure);

mWriteResponseBuilder.CreateWriteResponses();
VerifyOrReturnError(mWriteResponseBuilder.GetError() == CHIP_NO_ERROR, Status::Failure);
Expand All @@ -94,7 +93,7 @@ Status WriteHandler::HandleWriteRequestMessage(Messaging::ExchangeContext * apEx
// Do not send response on Group Write
if (status == Status::Success && !apExchangeContext->IsGroupExchangeContext())
{
CHIP_ERROR err = SendWriteResponse();
CHIP_ERROR err = SendWriteResponse(std::move(messageWriter));
if (err != CHIP_NO_ERROR)
{
status = Status::Failure;
Expand Down Expand Up @@ -167,25 +166,25 @@ void WriteHandler::OnResponseTimeout(Messaging::ExchangeContext * apExchangeCont
Close();
}

CHIP_ERROR WriteHandler::FinalizeMessage(System::PacketBufferHandle & packet)
CHIP_ERROR WriteHandler::FinalizeMessage(System::PacketBufferTLVWriter && aMessageWriter, System::PacketBufferHandle & packet)
{
VerifyOrReturnError(mState == State::AddStatus, CHIP_ERROR_INCORRECT_STATE);
AttributeStatusIBs::Builder & attributeStatusIBs = mWriteResponseBuilder.GetWriteResponses().EndOfAttributeStatuses();
ReturnErrorOnFailure(attributeStatusIBs.GetError());
mWriteResponseBuilder.EndOfWriteResponseMessage();
ReturnErrorOnFailure(mWriteResponseBuilder.GetError());
ReturnErrorOnFailure(mMessageWriter.Finalize(&packet));
ReturnErrorOnFailure(aMessageWriter.Finalize(&packet));
return CHIP_NO_ERROR;
}

CHIP_ERROR WriteHandler::SendWriteResponse()
CHIP_ERROR WriteHandler::SendWriteResponse(System::PacketBufferTLVWriter && aMessageWriter)
{
CHIP_ERROR err = CHIP_NO_ERROR;
System::PacketBufferHandle packet;

VerifyOrExit(mState == State::AddStatus, err = CHIP_ERROR_INCORRECT_STATE);

err = FinalizeMessage(packet);
err = FinalizeMessage(std::move(aMessageWriter), packet);
SuccessOrExit(err);

VerifyOrExit(mpExchangeCtx != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
Expand Down
5 changes: 2 additions & 3 deletions src/app/WriteHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class WriteHandler : public Messaging::ExchangeDelegate
Protocols::InteractionModel::Status HandleWriteRequestMessage(Messaging::ExchangeContext * apExchangeContext,
System::PacketBufferHandle && aPayload, bool aIsTimedWrite);

CHIP_ERROR FinalizeMessage(System::PacketBufferHandle & packet);
CHIP_ERROR SendWriteResponse();
CHIP_ERROR FinalizeMessage(System::PacketBufferTLVWriter && aMessageWriter, System::PacketBufferHandle & packet);
CHIP_ERROR SendWriteResponse(System::PacketBufferTLVWriter && aMessageWriter);

void MoveToState(const State aTargetState);
void ClearState();
Expand All @@ -143,7 +143,6 @@ class WriteHandler : public Messaging::ExchangeDelegate
private:
Messaging::ExchangeContext * mpExchangeCtx = nullptr;
WriteResponseMessage::Builder mWriteResponseBuilder;
System::PacketBufferTLVWriter mMessageWriter;
State mState = State::Uninitialized;
bool mIsTimedRequest = false;
bool mHasMoreChunks = false;
Expand Down

0 comments on commit 129841e

Please sign in to comment.