Skip to content

Commit

Permalink
Fix issue 14776 (#14805)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google authored and pull[bot] committed Aug 21, 2023
1 parent 7951971 commit 2537192
Show file tree
Hide file tree
Showing 5 changed files with 540 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/app/ReadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ ReadHandler::~ReadHandler()
{
InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm();
}

InteractionModelEngine::GetInstance()->ReleaseClusterInfoList(mpAttributeClusterInfoList);
InteractionModelEngine::GetInstance()->ReleaseClusterInfoList(mpEventClusterInfoList);
InteractionModelEngine::GetInstance()->ReleaseClusterInfoList(mpDataVersionFilterList);
Expand Down Expand Up @@ -150,7 +149,6 @@ CHIP_ERROR ReadHandler::OnStatusResponse(Messaging::ExchangeContext * apExchange
case HandlerState::AwaitingReportResponse:
if (IsChunkedReport())
{
InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm();
MoveToState(HandlerState::GeneratingReports);
mpExchangeCtx->WillSendMessage();

Expand All @@ -159,7 +157,6 @@ CHIP_ERROR ReadHandler::OnStatusResponse(Messaging::ExchangeContext * apExchange
}
else if (IsType(InteractionType::Subscribe))
{
InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm();
if (IsPriming())
{
err = SendSubscribeResponse();
Expand Down Expand Up @@ -209,7 +206,6 @@ CHIP_ERROR ReadHandler::SendStatusReport(Protocols::InteractionModel::Status aSt
mpExchangeCtx = mpExchangeMgr->NewContext(mSessionHandle.Get(), this);
}
VerifyOrReturnLogError(mpExchangeCtx != nullptr, CHIP_ERROR_INCORRECT_STATE);
mpExchangeCtx->SetResponseTimeout(kImMessageTimeout);

return StatusResponse::Send(aStatus, mpExchangeCtx,
/* aExpectResponse = */ false);
Expand All @@ -227,15 +223,16 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, b
VerifyOrReturnLogError(mpExchangeCtx == nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnLogError(mSessionHandle, CHIP_ERROR_INCORRECT_STATE);
mpExchangeCtx = mpExchangeMgr->NewContext(mSessionHandle.Get(), this);
mpExchangeCtx->SetResponseTimeout(kImMessageTimeout);
}

VerifyOrReturnLogError(mpExchangeCtx != nullptr, CHIP_ERROR_INCORRECT_STATE);
mIsChunkedReport = aMoreChunks;
bool noResponseExpected = IsType(InteractionType::Read) && !mIsChunkedReport;
if (!noResponseExpected)
{
MoveToState(HandlerState::AwaitingReportResponse);
}
mpExchangeCtx->SetResponseTimeout(kImMessageTimeout);
CHIP_ERROR err =
mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::ReportData, std::move(aPayload),
Messaging::SendFlags(noResponseExpected ? Messaging::SendMessageFlags::kNone
Expand Down Expand Up @@ -571,6 +568,11 @@ const char * ReadHandler::GetStateStr() const

void ReadHandler::MoveToState(const HandlerState aTargetState)
{
if (IsAwaitingReportResponse() && aTargetState != HandlerState::AwaitingReportResponse)
{
InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm();
}

mState = aTargetState;
ChipLogDetail(DataManagement, "IM RH moving to [%s]", GetStateStr());
}
Expand Down Expand Up @@ -620,7 +622,6 @@ CHIP_ERROR ReadHandler::SendSubscribeResponse()

mIsPrimingReports = false;
MoveToState(HandlerState::GeneratingReports);

return mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::SubscribeResponse, std::move(packet));
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/StatusResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

#include <app/InteractionModelTimeout.h>
#include <app/MessageDef/StatusResponseMessage.h>
#include <app/StatusResponse.h>

Expand All @@ -36,6 +37,7 @@ CHIP_ERROR StatusResponse::Send(Protocols::InteractionModel::Status aStatus, Mes
response.Status(aStatus);
ReturnErrorOnFailure(response.GetError());
ReturnErrorOnFailure(writer.Finalize(&msgBuf));
apExchangeContext->SetResponseTimeout(kImMessageTimeout);
ReturnErrorOnFailure(apExchangeContext->SendMessage(Protocols::InteractionModel::MsgType::StatusResponse, std::move(msgBuf),
aExpectResponse ? Messaging::SendMessageFlags::kExpectResponse
: Messaging::SendMessageFlags::kNone));
Expand Down
1 change: 1 addition & 0 deletions src/app/WriteHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ CHIP_ERROR WriteHandler::SendWriteResponse(System::PacketBufferTLVWriter && aMes
SuccessOrExit(err);

VerifyOrExit(mpExchangeCtx != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
mpExchangeCtx->SetResponseTimeout(kImMessageTimeout);
err = mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::WriteResponse, std::move(packet),
mHasMoreChunks ? Messaging::SendMessageFlags::kExpectResponse
: Messaging::SendMessageFlags::kNone);
Expand Down
2 changes: 2 additions & 0 deletions src/app/reporting/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class Engine
}
}

uint32_t GetNumReportsInFlight() { return mNumReportsInFlight; }

private:
friend class TestReportingEngine;
/**
Expand Down
Loading

0 comments on commit 2537192

Please sign in to comment.