From 5f8b98283058d8e4b0a3df73dceefdcd134ecb3f Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 10 Dec 2024 11:09:06 +0530 Subject: [PATCH] BDX: update reset and endLogCollection to distinguish success and failure cases --- .../diagnostic-logs-provider-delegate-impl.cpp | 4 ++-- .../diagnostic-logs-provider-delegate-impl.h | 2 +- .../include/DiagnosticLogsProviderDelegateImpl.h | 2 +- .../DiagnosticLogsProviderDelegateImpl.cpp | 4 ++-- .../diagnostic-logs-provider-delegate-impl.cpp | 4 ++-- .../diagnostic-logs-provider-delegate-impl.h | 2 +- .../BDXDiagnosticLogsProvider.cpp | 16 ++++++++-------- .../BDXDiagnosticLogsProvider.h | 2 +- .../DiagnosticLogsProviderDelegate.h | 3 ++- 9 files changed, 20 insertions(+), 19 deletions(-) diff --git a/examples/all-clusters-app/linux/diagnostic-logs-provider-delegate-impl.cpp b/examples/all-clusters-app/linux/diagnostic-logs-provider-delegate-impl.cpp index afb75a7ef666c4..9d641fc824f16c 100644 --- a/examples/all-clusters-app/linux/diagnostic-logs-provider-delegate-impl.cpp +++ b/examples/all-clusters-app/linux/diagnostic-logs-provider-delegate-impl.cpp @@ -79,7 +79,7 @@ CHIP_ERROR LogProvider::GetLogForIntent(IntentEnum intent, MutableByteSpan & out err = CollectLog(sessionHandle, outBuffer, unusedOutIsEndOfLog); VerifyOrReturnError(CHIP_NO_ERROR == err, err, outBuffer.reduce_size(0)); - err = EndLogCollection(sessionHandle); + err = EndLogCollection(sessionHandle, CHIP_NO_ERROR); VerifyOrReturnError(CHIP_NO_ERROR == err, err, outBuffer.reduce_size(0)); return CHIP_NO_ERROR; @@ -106,7 +106,7 @@ CHIP_ERROR LogProvider::StartLogCollection(IntentEnum intent, LogSessionHandle & return CHIP_NO_ERROR; } -CHIP_ERROR LogProvider::EndLogCollection(LogSessionHandle sessionHandle) +CHIP_ERROR LogProvider::EndLogCollection(LogSessionHandle sessionHandle, CHIP_ERROR error) { VerifyOrReturnValue(sessionHandle != kInvalidLogSessionHandle, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnValue(mFiles.count(sessionHandle), CHIP_ERROR_INVALID_ARGUMENT); diff --git a/examples/all-clusters-app/linux/include/diagnostic-logs-provider-delegate-impl.h b/examples/all-clusters-app/linux/include/diagnostic-logs-provider-delegate-impl.h index f90c8d600f4526..f52ffda3fde03a 100644 --- a/examples/all-clusters-app/linux/include/diagnostic-logs-provider-delegate-impl.h +++ b/examples/all-clusters-app/linux/include/diagnostic-logs-provider-delegate-impl.h @@ -48,7 +48,7 @@ class LogProvider : public DiagnosticLogsProviderDelegate /////////// DiagnosticLogsProviderDelegate Interface ///////// CHIP_ERROR StartLogCollection(IntentEnum intent, LogSessionHandle & outHandle, Optional & outTimeStamp, Optional & outTimeSinceBoot) override; - CHIP_ERROR EndLogCollection(LogSessionHandle sessionHandle) override; + CHIP_ERROR EndLogCollection(LogSessionHandle sessionHandle, CHIP_ERROR error) override; CHIP_ERROR CollectLog(LogSessionHandle sessionHandle, MutableByteSpan & outBuffer, bool & outIsEndOfLog) override; size_t GetSizeForIntent(IntentEnum intent) override; CHIP_ERROR GetLogForIntent(IntentEnum intent, MutableByteSpan & outBuffer, Optional & outTimeStamp, diff --git a/examples/platform/nxp/common/diagnostic_logs/include/DiagnosticLogsProviderDelegateImpl.h b/examples/platform/nxp/common/diagnostic_logs/include/DiagnosticLogsProviderDelegateImpl.h index 73d60f542aacdc..b1ff9b453563f2 100644 --- a/examples/platform/nxp/common/diagnostic_logs/include/DiagnosticLogsProviderDelegateImpl.h +++ b/examples/platform/nxp/common/diagnostic_logs/include/DiagnosticLogsProviderDelegateImpl.h @@ -41,7 +41,7 @@ class LogProvider : public DiagnosticLogsProviderDelegate /////////// DiagnosticLogsProviderDelegate Interface ///////// CHIP_ERROR StartLogCollection(IntentEnum intent, LogSessionHandle & outHandle, Optional & outTimeStamp, Optional & outTimeSinceBoot) override; - CHIP_ERROR EndLogCollection(LogSessionHandle sessionHandle) override; + CHIP_ERROR EndLogCollection(LogSessionHandle sessionHandle, CHIP_ERROR error) override; CHIP_ERROR CollectLog(LogSessionHandle sessionHandle, MutableByteSpan & outBuffer, bool & outIsEndOfLog) override; size_t GetSizeForIntent(IntentEnum intent) override; CHIP_ERROR GetLogForIntent(IntentEnum intent, MutableByteSpan & outBuffer, Optional & outTimeStamp, diff --git a/examples/platform/nxp/common/diagnostic_logs/source/DiagnosticLogsProviderDelegateImpl.cpp b/examples/platform/nxp/common/diagnostic_logs/source/DiagnosticLogsProviderDelegateImpl.cpp index 929905afad828f..12c4e0a3dac291 100644 --- a/examples/platform/nxp/common/diagnostic_logs/source/DiagnosticLogsProviderDelegateImpl.cpp +++ b/examples/platform/nxp/common/diagnostic_logs/source/DiagnosticLogsProviderDelegateImpl.cpp @@ -48,7 +48,7 @@ CHIP_ERROR LogProvider::GetLogForIntent(IntentEnum intent, MutableByteSpan & out err = CollectLog(sessionHandle, outBuffer, unusedOutIsEndOfLog); VerifyOrReturnError(CHIP_NO_ERROR == err, err, outBuffer.reduce_size(0)); - err = EndLogCollection(sessionHandle); + err = EndLogCollection(sessionHandle, CHIP_NO_ERROR); VerifyOrReturnError(CHIP_NO_ERROR == err, err, outBuffer.reduce_size(0)); return CHIP_NO_ERROR; @@ -89,7 +89,7 @@ CHIP_ERROR LogProvider::StartLogCollection(IntentEnum intent, LogSessionHandle & return CHIP_NO_ERROR; } -CHIP_ERROR LogProvider::EndLogCollection(LogSessionHandle sessionHandle) +CHIP_ERROR LogProvider::EndLogCollection(LogSessionHandle sessionHandle, CHIP_ERROR error) { VerifyOrReturnValue(sessionHandle != kInvalidLogSessionHandle, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnValue(mSessionSpanMap.count(sessionHandle), CHIP_ERROR_INVALID_ARGUMENT); diff --git a/examples/temperature-measurement-app/esp32/main/diagnostic-logs-provider-delegate-impl.cpp b/examples/temperature-measurement-app/esp32/main/diagnostic-logs-provider-delegate-impl.cpp index 55336ea76030dd..9ece5cee34bc20 100644 --- a/examples/temperature-measurement-app/esp32/main/diagnostic-logs-provider-delegate-impl.cpp +++ b/examples/temperature-measurement-app/esp32/main/diagnostic-logs-provider-delegate-impl.cpp @@ -65,7 +65,7 @@ CHIP_ERROR LogProvider::GetLogForIntent(IntentEnum intent, MutableByteSpan & out err = CollectLog(sessionHandle, outBuffer, unusedOutIsEndOfLog); VerifyOrReturnError(CHIP_NO_ERROR == err, err, outBuffer.reduce_size(0)); - err = EndLogCollection(sessionHandle); + err = EndLogCollection(sessionHandle, CHIP_NO_ERROR); VerifyOrReturnError(CHIP_NO_ERROR == err, err, outBuffer.reduce_size(0)); return CHIP_NO_ERROR; @@ -276,7 +276,7 @@ CHIP_ERROR LogProvider::StartLogCollection(IntentEnum intent, LogSessionHandle & return CHIP_NO_ERROR; } -CHIP_ERROR LogProvider::EndLogCollection(LogSessionHandle sessionHandle) +CHIP_ERROR LogProvider::EndLogCollection(LogSessionHandle sessionHandle, CHIP_ERROR error) { VerifyOrReturnValue(sessionHandle != kInvalidLogSessionHandle, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnValue(mSessionContextMap.count(sessionHandle), CHIP_ERROR_INVALID_ARGUMENT); diff --git a/examples/temperature-measurement-app/esp32/main/include/diagnostic-logs-provider-delegate-impl.h b/examples/temperature-measurement-app/esp32/main/include/diagnostic-logs-provider-delegate-impl.h index 3431a54adc86a8..fc1350ed3ec265 100644 --- a/examples/temperature-measurement-app/esp32/main/include/diagnostic-logs-provider-delegate-impl.h +++ b/examples/temperature-measurement-app/esp32/main/include/diagnostic-logs-provider-delegate-impl.h @@ -44,7 +44,7 @@ class LogProvider : public DiagnosticLogsProviderDelegate /////////// DiagnosticLogsProviderDelegate Interface ///////// CHIP_ERROR StartLogCollection(IntentEnum intent, LogSessionHandle & outHandle, Optional & outTimeStamp, Optional & outTimeSinceBoot) override; - CHIP_ERROR EndLogCollection(LogSessionHandle sessionHandle) override; + CHIP_ERROR EndLogCollection(LogSessionHandle sessionHandle, CHIP_ERROR error) override; CHIP_ERROR CollectLog(LogSessionHandle sessionHandle, MutableByteSpan & outBuffer, bool & outIsEndOfLog) override; size_t GetSizeForIntent(IntentEnum intent) override; CHIP_ERROR GetLogForIntent(IntentEnum intent, MutableByteSpan & outBuffer, Optional & outTimeStamp, diff --git a/src/app/clusters/diagnostic-logs-server/BDXDiagnosticLogsProvider.cpp b/src/app/clusters/diagnostic-logs-server/BDXDiagnosticLogsProvider.cpp index 6119652990679f..469f462b872c5e 100644 --- a/src/app/clusters/diagnostic-logs-server/BDXDiagnosticLogsProvider.cpp +++ b/src/app/clusters/diagnostic-logs-server/BDXDiagnosticLogsProvider.cpp @@ -162,7 +162,7 @@ void BDXDiagnosticLogsProvider::OnMsgToSend(TransferSession::OutputEvent & event auto err = mBDXTransferExchangeCtx->SendMessage(msgTypeData.ProtocolId, msgTypeData.MessageType, std::move(event.MsgData), sendFlags); - VerifyOrDo(CHIP_NO_ERROR == err, Reset()); + VerifyOrDo(CHIP_NO_ERROR == err, Reset(err)); } void BDXDiagnosticLogsProvider::OnAcceptReceived() @@ -191,7 +191,7 @@ void BDXDiagnosticLogsProvider::OnAckReceived() // If the buffer has empty space, end the log collection session. if (isEndOfLog) { - mDelegate->EndLogCollection(mLogSessionHandle); + mDelegate->EndLogCollection(mLogSessionHandle, CHIP_NO_ERROR); mLogSessionHandle = kInvalidLogSessionHandle; } @@ -213,7 +213,7 @@ void BDXDiagnosticLogsProvider::OnAckEOFReceived() { ChipLogProgress(BDX, "Diagnostic logs transfer: Success"); - Reset(); + Reset(CHIP_NO_ERROR); } void BDXDiagnosticLogsProvider::OnStatusReceived(TransferSession::OutputEvent & event) @@ -223,21 +223,21 @@ void BDXDiagnosticLogsProvider::OnStatusReceived(TransferSession::OutputEvent & // If a failure StatusReport is received in response to the SendInit message, the Node SHALL send a RetrieveLogsResponse command // with a Status of Denied. VerifyOrDo(mIsAcceptReceived, SendCommandResponse(StatusEnum::kDenied)); - Reset(); + Reset(CHIP_ERROR_INCORRECT_STATE); } void BDXDiagnosticLogsProvider::OnInternalError() { ChipLogError(BDX, "Internal Error"); VerifyOrDo(mIsAcceptReceived, SendCommandResponse(StatusEnum::kDenied)); - Reset(); + Reset(CHIP_ERROR_INTERNAL); } void BDXDiagnosticLogsProvider::OnTimeout() { ChipLogError(BDX, "Timeout"); VerifyOrDo(mIsAcceptReceived, SendCommandResponse(StatusEnum::kDenied)); - Reset(); + Reset(CHIP_ERROR_TIMEOUT); } void BDXDiagnosticLogsProvider::SendCommandResponse(StatusEnum status) @@ -264,7 +264,7 @@ void BDXDiagnosticLogsProvider::SendCommandResponse(StatusEnum status) commandHandle->AddResponse(mRequestPath, response); } -void BDXDiagnosticLogsProvider::Reset() +void BDXDiagnosticLogsProvider::Reset(CHIP_ERROR error) { assertChipStackLockedByCurrentThread(); @@ -279,7 +279,7 @@ void BDXDiagnosticLogsProvider::Reset() if (mDelegate != nullptr) { - mDelegate->EndLogCollection(mLogSessionHandle); + mDelegate->EndLogCollection(mLogSessionHandle, error); mDelegate = nullptr; } diff --git a/src/app/clusters/diagnostic-logs-server/BDXDiagnosticLogsProvider.h b/src/app/clusters/diagnostic-logs-server/BDXDiagnosticLogsProvider.h index 6122998eae986c..b4294fcc756759 100644 --- a/src/app/clusters/diagnostic-logs-server/BDXDiagnosticLogsProvider.h +++ b/src/app/clusters/diagnostic-logs-server/BDXDiagnosticLogsProvider.h @@ -77,7 +77,7 @@ class BDXDiagnosticLogsProvider : public bdx::Initiator * This method is called to reset state. It resets the transfer, cleans up the * exchange and ends log collection. */ - void Reset(); + void Reset(CHIP_ERROR error); Messaging::ExchangeContext * mBDXTransferExchangeCtx; DiagnosticLogsProviderDelegate * mDelegate; diff --git a/src/app/clusters/diagnostic-logs-server/DiagnosticLogsProviderDelegate.h b/src/app/clusters/diagnostic-logs-server/DiagnosticLogsProviderDelegate.h index dc511fdacadeaa..96bbae63ef558c 100644 --- a/src/app/clusters/diagnostic-logs-server/DiagnosticLogsProviderDelegate.h +++ b/src/app/clusters/diagnostic-logs-server/DiagnosticLogsProviderDelegate.h @@ -59,9 +59,10 @@ class DiagnosticLogsProviderDelegate * returned from StartLogCollection. * * @param[in] sessionHandle The unique handle for this log session returned from a call to StartLogCollection. + * @param[in] error A CHIP_ERROR value that indicates the reason for ending the log collection. * */ - virtual CHIP_ERROR EndLogCollection(LogSessionHandle sessionHandle) = 0; + virtual CHIP_ERROR EndLogCollection(LogSessionHandle sessionHandle, CHIP_ERROR error) = 0; /** * Called to get the next chunk for the log session identified by sessionHandle.