Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize report delivery timing for subscribe #12398

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/app/ReadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ CHIP_ERROR ReadHandler::Init(Messaging::ExchangeManager * apExchangeMgr, Interac
mInteractionType = aInteractionType;
mInitiatorNodeId = apExchangeContext->GetSessionHandle().GetPeerNodeId();
mFabricIndex = apExchangeContext->GetSessionHandle().GetFabricIndex();

mHoldSync = false;
if (apExchangeContext != nullptr)
{
apExchangeContext->SetDelegate(this);
Expand Down Expand Up @@ -110,6 +110,7 @@ void ReadHandler::Shutdown(ShutdownOptions aOptions)
mActiveSubscription = false;
mIsChunkedReport = false;
mInitiatorNodeId = kUndefinedNodeId;
mHoldSync = false;
}

CHIP_ERROR ReadHandler::OnReadInitialRequest(System::PacketBufferHandle && aPayload)
Expand Down Expand Up @@ -637,17 +638,21 @@ void ReadHandler::OnUnblockHoldReportCallback(System::Layer * apSystemLayer, voi
void ReadHandler::OnRefreshSubscribeTimerSyncCallback(System::Layer * apSystemLayer, void * apAppState)
{
VerifyOrReturn(apAppState != nullptr);
ReadHandler * readHandler = static_cast<ReadHandler *>(apAppState);
readHandler->mHoldSync = false;
ChipLogProgress(DataManagement, "Refresh subscribe timer sync after max %d seconds", readHandler->mMaxIntervalCeilingSeconds);
InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleRun();
}

CHIP_ERROR ReadHandler::RefreshSubscribeSyncTimer()
{
ChipLogProgress(DataManagement, "ReadHandler::Refresh Subscribe Sync Timer with %d seconds", mMaxIntervalCeilingSeconds);
ChipLogProgress(DataManagement, "Refresh Subscribe Sync Timer with %d seconds", mMaxIntervalCeilingSeconds);
InteractionModelEngine::GetInstance()->GetExchangeManager()->GetSessionManager()->SystemLayer()->CancelTimer(
OnUnblockHoldReportCallback, this);
InteractionModelEngine::GetInstance()->GetExchangeManager()->GetSessionManager()->SystemLayer()->CancelTimer(
OnRefreshSubscribeTimerSyncCallback, this);
mHoldReport = true;
mHoldSync = true;
ReturnErrorOnFailure(
InteractionModelEngine::GetInstance()->GetExchangeManager()->GetSessionManager()->SystemLayer()->StartTimer(
System::Clock::Seconds16(mMinIntervalFloorSeconds), OnUnblockHoldReportCallback, this));
Expand Down
3 changes: 2 additions & 1 deletion src/app/ReadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ReadHandler : public Messaging::ExchangeDelegate
CHIP_ERROR SendReportData(System::PacketBufferHandle && aPayload, bool mMoreChunks);

bool IsFree() const { return mState == HandlerState::Uninitialized; }
bool IsReportable() const { return mState == HandlerState::GeneratingReports && !mHoldReport; }
bool IsReportable() const { return mState == HandlerState::GeneratingReports && !mHoldReport && (mDirty || !mHoldSync); }
bool IsGeneratingReports() const { return mState == HandlerState::GeneratingReports; }
bool IsAwaitingReportResponse() const { return mState == HandlerState::AwaitingReportResponse; }
virtual ~ReadHandler() = default;
Expand Down Expand Up @@ -214,6 +214,7 @@ class ReadHandler : public Messaging::ExchangeDelegate
FabricIndex mFabricIndex = 0;
AttributePathExpandIterator mAttributePathExpandIterator = AttributePathExpandIterator(nullptr);
bool mIsFabricFiltered = false;
bool mHoldSync = false;
};
} // namespace app
} // namespace chip
1 change: 1 addition & 0 deletions src/app/tests/TestReadInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,7 @@ void TestReadInteraction::TestSubscribeRoundtrip(nlTestSuite * apSuite, void * a

// Test empty report
delegate.mpReadHandler->mHoldReport = false;
delegate.mpReadHandler->mHoldSync = false;
delegate.mGotReport = false;
delegate.mNumAttributeResponse = 0;
engine->GetReportingEngine().Run();
Expand Down