Skip to content

Commit

Permalink
Fix to error response
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo committed Nov 2, 2023
1 parent 38e686b commit ab0f393
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/controller/java/OTAProviderDelegateBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ void OTAProviderDelegateBridge::HandleQueryImage(CommandHandler * commandObj, co
const QueryImage::DecodableType & commandData)
{
CHIP_ERROR err = CHIP_NO_ERROR;
uint8_t errorStatus = static_cast<uint8_t>(OTAQueryStatus::kNotAvailable);

NodeId nodeId = kUndefinedNodeId;

Expand Down Expand Up @@ -144,6 +143,8 @@ void OTAProviderDelegateBridge::HandleQueryImage(CommandHandler * commandObj, co

bool hasUpdate = false;
Commands::QueryImageResponse::Type response;
Commands::QueryImageResponse::Type errorResponse;
errorResponse.status = OTAQueryStatus::kNotAvailable;

char uriBuffer[kMaxBDXURILen];
MutableCharSpan uri(uriBuffer);
Expand Down Expand Up @@ -190,9 +191,8 @@ void OTAProviderDelegateBridge::HandleQueryImage(CommandHandler * commandObj, co
// If the protocol requested is not supported, return status - Protocol Not Supported
if (!isBDXProtocolSupported)
{
response.status = OTAQueryStatus::kDownloadProtocolNotSupported;
commandObj->AddResponse(cachedCommandPath, response);
ExitNow(errorStatus = static_cast<uint8_t>(response.status));
errorResponse.status = OTAQueryStatus::kDownloadProtocolNotSupported;
ExitNow();
}

otaProviderDelegate = mOtaProviderDelegate.ObjectRef();
Expand Down Expand Up @@ -242,10 +242,8 @@ void OTAProviderDelegateBridge::HandleQueryImage(CommandHandler * commandObj, co
// If update is not available, return the delegate response
if (!hasUpdate)
{
response.status = OTAQueryStatus::kNotAvailable;
commandObj->AddResponse(cachedCommandPath, response);
sendOTAQueryFailure(static_cast<uint8_t>(response.status));
return;
errorResponse.status = OTAQueryStatus::kNotAvailable;
ExitNow();
}

err = JniReferences::GetInstance().FindMethod(env, jResponse, "getSoftwareVersion", "()Ljava/lang/Long;",
Expand Down Expand Up @@ -292,39 +290,38 @@ void OTAProviderDelegateBridge::HandleQueryImage(CommandHandler * commandObj, co
if (err == CHIP_ERROR_BUSY)
{
ChipLogError(Controller, "Responding with Busy due to being in the middle of handling another BDX transfer");
Commands::QueryImageResponse::Type errorResponse;
errorResponse.status = OTAQueryStatus::kBusy;
errorResponse.delayedActionTime.SetValue(kDelayedActionTimeSeconds);
commandObj->AddResponse(cachedCommandPath, errorResponse);
// We do not reset state when we get the busy error because that means we are locked in a BDX transfer
// session with another requestor when we get this query image request. We do not want to interrupt the
// ongoing transfer instead just respond to the second requestor with a busy status and a delayedActionTime
// in which the requestor can retry.
ExitNow(errorStatus = static_cast<uint8_t>(errorResponse.status));
ExitNow();
}
LogErrorOnFailure(err);
commandObj->AddStatus(cachedCommandPath, StatusIB(err).mStatus);
// We need to reset state here to clean up any initialization we might have done including starting the BDX
// timeout timer while preparing for transfer if any failure occurs afterwards.
mBdxOTASender->ResetState();
ExitNow(errorStatus = static_cast<uint8_t>(OTAQueryStatus::kNotAvailable));
ExitNow();
}
err = bdx::MakeURI(ourNodeId.GetNodeId(), jniFilePath.c_str() != nullptr ? jniFilePath.charSpan() : CharSpan(), uri);
if (CHIP_NO_ERROR != err)
{
LogErrorOnFailure(err);
commandObj->AddStatus(cachedCommandPath, StatusIB(err).mStatus);
mBdxOTASender->ResetState();
ExitNow(errorStatus = static_cast<uint8_t>(OTAQueryStatus::kNotAvailable));
ExitNow();
}
response.imageURI.SetValue(uri);
commandObj->AddResponse(cachedCommandPath, response);
}
return;

exit:
ChipLogError(Controller, "OTA Query Failure : %u, %" CHIP_ERROR_FORMAT, errorStatus, err.Format());
sendOTAQueryFailure(errorStatus);
ChipLogError(Controller, "OTA Query Failure : %u, %" CHIP_ERROR_FORMAT, static_cast<uint8_t>(errorResponse.status), err.Format());
commandObj->AddResponse(cachedCommandPath, errorResponse);
sendOTAQueryFailure(static_cast<uint8_t>(errorResponse.status));
}

void OTAProviderDelegateBridge::HandleApplyUpdateRequest(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
Expand Down

0 comments on commit ab0f393

Please sign in to comment.