From 129852040b6d76c609dc453fa0e51348939466ab Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 8 Feb 2023 11:02:49 -0500 Subject: [PATCH] Remove WriteHandler::Abort. (#24880) It's basically just Close, except missing some state updates, and not doing the "is this actually in use" check that Close does. We can guard on that check in the caller and call Close. Fixes https://github.com/project-chip/connectedhomeip/issues/21740 --- src/app/InteractionModelEngine.cpp | 5 ++++- src/app/WriteHandler.cpp | 22 ++++++++-------------- src/app/WriteHandler.h | 7 ------- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 7662ca2d540832..1e6c3ed198ea3a 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -132,7 +132,10 @@ void InteractionModelEngine::Shutdown() for (auto & writeHandler : mWriteHandlers) { - writeHandler.Abort(); + if (!writeHandler.IsFree()) + { + writeHandler.Close(); + } } mReportingEngine.Shutdown(); diff --git a/src/app/WriteHandler.cpp b/src/app/WriteHandler.cpp index a79cab52c556f3..1e5343432a3709 100644 --- a/src/app/WriteHandler.cpp +++ b/src/app/WriteHandler.cpp @@ -48,15 +48,16 @@ CHIP_ERROR WriteHandler::Init() void WriteHandler::Close() { - mSuppressResponse = false; VerifyOrReturn(mState != State::Uninitialized); - ClearState(); -} - -void WriteHandler::Abort() -{ - ClearState(); + // DeliverFinalListWriteEnd will be a no-op if we have called + // DeliverFinalListWriteEnd in success conditions, so passing false for + // wasSuccessful here is safe: if it does anything, we were in fact not + // successful. + DeliverFinalListWriteEnd(false /* wasSuccessful */); + mExchangeCtx.Release(); + mSuppressResponse = false; + MoveToState(State::Uninitialized); } Status WriteHandler::HandleWriteRequestMessage(Messaging::ExchangeContext * apExchangeContext, @@ -691,13 +692,6 @@ void WriteHandler::MoveToState(const State aTargetState) ChipLogDetail(DataManagement, "IM WH moving to [%s]", GetStateStr()); } -void WriteHandler::ClearState() -{ - DeliverFinalListWriteEnd(false /* wasSuccessful */); - mExchangeCtx.Release(); - MoveToState(State::Uninitialized); -} - } // namespace app } // namespace chip diff --git a/src/app/WriteHandler.h b/src/app/WriteHandler.h index 577a991d923bfb..9a004d9b0e5e60 100644 --- a/src/app/WriteHandler.h +++ b/src/app/WriteHandler.h @@ -70,12 +70,6 @@ class WriteHandler : public Messaging::ExchangeDelegate Protocols::InteractionModel::Status OnWriteRequest(Messaging::ExchangeContext * apExchangeContext, System::PacketBufferHandle && aPayload, bool aIsTimedWrite); - /* - * This forcibly closes the exchange context if a valid one is pointed to and de-initializes the object. Such a situation does - * not arise during normal message processing flows that all normally call Close() below. - */ - void Abort(); - /** * Clean up state when we are done sending the write response. */ @@ -136,7 +130,6 @@ class WriteHandler : public Messaging::ExchangeDelegate CHIP_ERROR SendWriteResponse(System::PacketBufferTLVWriter && aMessageWriter); void MoveToState(const State aTargetState); - void ClearState(); const char * GetStateStr() const; void DeliverListWriteBegin(const ConcreteAttributePath & aPath);