diff --git a/src/app/BufferedReadCallback.cpp b/src/app/BufferedReadCallback.cpp index 3752a3e65aef08..3e6c28abf28023 100644 --- a/src/app/BufferedReadCallback.cpp +++ b/src/app/BufferedReadCallback.cpp @@ -37,12 +37,8 @@ void BufferedReadCallback::OnReportBegin() void BufferedReadCallback::OnReportEnd() { CHIP_ERROR err = DispatchBufferedData(mBufferedPath, StatusIB(), true); - if (err != CHIP_NO_ERROR) - { - mCallback.OnError(err); - return; - } - + SetFatalReportError(err); + ReturnOnFailure(err); mCallback.OnReportEnd(); } @@ -230,13 +226,12 @@ CHIP_ERROR BufferedReadCallback::DispatchBufferedData(const ConcreteAttributePat void BufferedReadCallback::OnAttributeData(const ConcreteDataAttributePath & aPath, TLV::TLVReader * apData, const StatusIB & aStatus) { - CHIP_ERROR err; - // // First, let's dispatch to our registered callback any buffered up list data from previous calls. // - err = DispatchBufferedData(aPath, aStatus); - SuccessOrExit(err); + CHIP_ERROR err = DispatchBufferedData(aPath, aStatus); + SetFatalReportError(err); + ReturnOnFailure(err); // // We buffer up list data (only if the status was successful) @@ -244,7 +239,8 @@ void BufferedReadCallback::OnAttributeData(const ConcreteDataAttributePath & aPa if (aPath.IsListOperation() && aStatus.mStatus == Protocols::InteractionModel::Status::Success) { err = BufferData(aPath, apData); - SuccessOrExit(err); + SetFatalReportError(err); + ReturnOnFailure(err); } else { @@ -255,12 +251,6 @@ void BufferedReadCallback::OnAttributeData(const ConcreteDataAttributePath & aPa // Update our latched buffered path. // mBufferedPath = aPath; - -exit: - if (err != CHIP_NO_ERROR) - { - mCallback.OnError(err); - } } } // namespace app diff --git a/src/app/BufferedReadCallback.h b/src/app/BufferedReadCallback.h index b24257884e1a77..b3504e70fec7d5 100644 --- a/src/app/BufferedReadCallback.h +++ b/src/app/BufferedReadCallback.h @@ -44,7 +44,7 @@ class BufferedReadCallback : public ReadClient::Callback private: /* - * Generates the reconsistuted TLV array from the stored individual list elements + * Generates the reconstituted TLV array from the stored individual list elements */ CHIP_ERROR GenerateListTLV(TLV::ScopedBufferTLVReader & reader); diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index 2d609eb1afa05a..87c208a9aa91f1 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -231,7 +231,7 @@ void ReadClient::Close(CHIP_ERROR aError, bool allowResubscription) } mExchange.Release(); - + mpCallback.ClearFatalReportError(); mpCallback.OnDone(this); } @@ -805,6 +805,7 @@ CHIP_ERROR ReadClient::ProcessAttributeReportIBs(TLV::TLVReader & aAttributeRepo ReturnErrorOnFailure(errorStatus.DecodeStatusIB(statusIB)); NoteReportingData(); mpCallback.OnAttributeData(attributePath, nullptr, statusIB); + ReturnErrorOnFailure(mpCallback.GetLastFatalReportError()); } else if (CHIP_END_OF_TLV == err) { @@ -861,6 +862,7 @@ CHIP_ERROR ReadClient::ProcessAttributeReportIBs(TLV::TLVReader & aAttributeRepo NoteReportingData(); mpCallback.OnAttributeData(attributePath, &dataReader, statusIB); + ReturnErrorOnFailure(mpCallback.GetLastFatalReportError()); } } @@ -868,7 +870,6 @@ CHIP_ERROR ReadClient::ProcessAttributeReportIBs(TLV::TLVReader & aAttributeRepo { err = CHIP_NO_ERROR; } - return err; } @@ -905,6 +906,7 @@ CHIP_ERROR ReadClient::ProcessEventReportIBs(TLV::TLVReader & aEventReportIBsRea NoteReportingData(); mpCallback.OnEventData(header, &dataReader, nullptr); + ReturnErrorOnFailure(mpCallback.GetLastFatalReportError()); } else if (err == CHIP_END_OF_TLV) { @@ -919,6 +921,7 @@ CHIP_ERROR ReadClient::ProcessEventReportIBs(TLV::TLVReader & aEventReportIBsRea NoteReportingData(); mpCallback.OnEventData(header, nullptr, &statusIB); + ReturnErrorOnFailure(mpCallback.GetLastFatalReportError()); } } diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h index d8b8a971db8c28..4cb7acc370d90d 100644 --- a/src/app/ReadClient.h +++ b/src/app/ReadClient.h @@ -202,6 +202,8 @@ class ReadClient : public Messaging::ExchangeDelegate * This object MUST continue to exist after this call is completed. The application shall wait until it * receives an OnDone call to destroy the object. * + * This callback is expected to be called inside the ReadClient. + * * @param[in] aError A system error code that conveys the overall error code. */ virtual void OnError(CHIP_ERROR aError) {} @@ -284,6 +286,25 @@ class ReadClient : public Messaging::ExchangeDelegate * things like min/max intervals based on the session parameters). */ virtual void OnCASESessionEstablished(const SessionHandle & aSession, ReadPrepareParams & aSubscriptionParams) {} + + /* + * Get the last internal fatal error in callback + */ + CHIP_ERROR GetLastFatalReportError() const { return mLastFatalReportError; } + + protected: + /* + * Set the fatal report fatal error in callback which would lead to ReadClient::Close() + */ + void SetFatalReportError(CHIP_ERROR aError) { mLastFatalReportError = aError; } + + /* + * Clear the fatal report fatal error + */ + void ClearFatalReportError() { mLastFatalReportError = CHIP_NO_ERROR; } + + private: + CHIP_ERROR mLastFatalReportError = CHIP_NO_ERROR; }; enum class InteractionType : uint8_t