Skip to content

Commit

Permalink
Remove the boolean that tracks if we are in a BDX session
Browse files Browse the repository at this point in the history
  • Loading branch information
nivi-apple committed Nov 7, 2023
1 parent 7fadbd3 commit 7cf9d6d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
8 changes: 3 additions & 5 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,9 @@ - (void)_invokeCompletion:(void (^)(NSURL * _Nullable logResult, NSError * error
error:(NSError * _Nullable)error
{
if (self->_diagnosticLogsTransferHandler != nil) {
self->_diagnosticLogsTransferHandler->Reset();
delete (self->_diagnosticLogsTransferHandler);
self->_diagnosticLogsTransferHandler = nil;
}
dispatch_async(queue, ^{
completion(filepath, error);
Expand Down Expand Up @@ -1437,10 +1439,6 @@ - (void)_downloadLogOfType:(MTRDiagnosticLogType)type
[self _invokeCompletionWithError:completion queue:queue error:[NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeInvalidState userInfo:nil]];
}

if (self->_diagnosticLogsTransferHandler != nil && self->_diagnosticLogsTransferHandler->IsInBDXSession()) {
[self _invokeCompletionWithError:completion queue:queue error:[NSError errorWithDomain:MTRInteractionErrorDomain code:MTRInteractionErrorCodeBusy userInfo:nil]];
}

self->_diagnosticLogsTransferHandler = new MTRDiagnosticLogsTransferHandler(filePath, ^(bool result) {
if (result == YES) {
[self _invokeCompletion:completion filepath:filePath queue:queue error:nil];
Expand Down Expand Up @@ -1471,7 +1469,7 @@ - (void)_downloadLogOfType:(MTRDiagnosticLogType)type
[cluster retrieveLogsRequestWithParams:requestParams expectedValues:nil expectedValueInterval:nil
completion:^(MTRDiagnosticLogsClusterRetrieveLogsResponseParams * _Nullable response, NSError * _Nullable error) {
// If we are in a BDX session and there is no error, do nothing. Completion will be called when BDX succeeds or fails.
if (self->_diagnosticLogsTransferHandler != nil && self->_diagnosticLogsTransferHandler->IsInBDXSession() && error == nil) {
if (self->_diagnosticLogsTransferHandler != nil && error == nil) {
return;
}

Expand Down
6 changes: 2 additions & 4 deletions src/darwin/Framework/CHIP/MTRDiagnosticLogsTransferHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class MTRDiagnosticLogsTransferHandler : public chip::bdx::Responder {
void HandleTransferSessionOutput(chip::bdx::TransferSession::OutputEvent & event) override;

void AbortTransfer(chip::bdx::StatusCode reason);

bool IsInBDXSession() { return mInitialized; }
void Reset();

protected:
CHIP_ERROR OnMessageReceived(chip::Messaging::ExchangeContext * _Nonnull ec, const chip::PayloadHeader & payloadHeader,
Expand All @@ -70,8 +70,6 @@ class MTRDiagnosticLogsTransferHandler : public chip::bdx::Responder {

CHIP_ERROR OnBlockReceived(chip::bdx::TransferSession::OutputEvent & event);

void Reset();

// The fabric index of the node with which the BDX session is established.
chip::Optional<chip::FabricIndex> mFabricIndex;

Expand Down
3 changes: 0 additions & 3 deletions src/darwin/Framework/CHIP/MTRDiagnosticLogsTransferHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
acceptData.Length = mTransfer.GetTransferLength();

mTransfer.AcceptTransfer(acceptData);
mInitialized = true;
return CHIP_NO_ERROR;
}

Expand All @@ -93,7 +92,6 @@
} else if (event.EventType != TransferSession::OutputEventType::kMsgToSend || !event.msgTypeData.HasMessageType(MessageType::BlockAckEOF)) {
error = CHIP_ERROR_INTERNAL;
}
Reset();

// Notify the MTRDevice via the callback that the BDX transfer has completed with error or success.
if (mCallback) {
Expand Down Expand Up @@ -225,7 +223,6 @@
void MTRDiagnosticLogsTransferHandler::Reset()
{
assertChipStackLockedByCurrentThread();
mInitialized = false;
mFileURL = nil;
mFileHandle = nil;

Expand Down

0 comments on commit 7cf9d6d

Please sign in to comment.