Skip to content

Commit

Permalink
Optimize report delivery timing for subscribe
Browse files Browse the repository at this point in the history
--Between min and max, only send the report when the handler is dirty
--At max, mNeedRefreshSubscribe is set, server would send the report
  • Loading branch information
yunhanw-google committed Dec 1, 2021
1 parent a7b18b8 commit e6f663d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
27 changes: 16 additions & 11 deletions src/app/ReadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ CHIP_ERROR ReadHandler::Init(Messaging::ExchangeManager * apExchangeMgr, Interac
mCurrentPriority = PriorityLevel::Invalid;
mIsPrimingReports = true;
MoveToState(HandlerState::Initialized);
mpDelegate = apDelegate;
mSubscriptionId = 0;
mHoldReport = false;
mDirty = false;
mActiveSubscription = false;
mIsChunkedReport = false;
mInteractionType = aInteractionType;
mInitiatorNodeId = apExchangeContext->GetSessionHandle().GetPeerNodeId();
mFabricIndex = apExchangeContext->GetSessionHandle().GetFabricIndex();

mpDelegate = apDelegate;
mSubscriptionId = 0;
mHoldReport = false;
mDirty = false;
mActiveSubscription = false;
mIsChunkedReport = false;
mInteractionType = aInteractionType;
mInitiatorNodeId = apExchangeContext->GetSessionHandle().GetPeerNodeId();
mFabricIndex = apExchangeContext->GetSessionHandle().GetFabricIndex();
mNeedRefreshSubscribe = 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;
mNeedRefreshSubscribe = false;
}

CHIP_ERROR ReadHandler::OnReadInitialRequest(System::PacketBufferHandle && aPayload)
Expand Down Expand Up @@ -637,6 +638,9 @@ 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->mNeedRefreshSubscribe = true;
ChipLogProgress(DataManagement, "Refresh subscribe timer sync after max %d seconds", readHandler->mMaxIntervalFloorSeconds);
InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleRun();
}

Expand All @@ -647,7 +651,8 @@ CHIP_ERROR ReadHandler::RefreshSubscribeSyncTimer()
OnUnblockHoldReportCallback, this);
InteractionModelEngine::GetInstance()->GetExchangeManager()->GetSessionManager()->SystemLayer()->CancelTimer(
OnRefreshSubscribeTimerSyncCallback, this);
mHoldReport = true;
mHoldReport = true;
mNeedRefreshSubscribe = false;
ReturnErrorOnFailure(
InteractionModelEngine::GetInstance()->GetExchangeManager()->GetSessionManager()->SystemLayer()->StartTimer(
System::Clock::Seconds16(mMinIntervalFloorSeconds), OnUnblockHoldReportCallback, this));
Expand Down
6 changes: 5 additions & 1 deletion src/app/ReadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ 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 || mNeedRefreshSubscribe);
}
bool IsGeneratingReports() const { return mState == HandlerState::GeneratingReports; }
bool IsAwaitingReportResponse() const { return mState == HandlerState::AwaitingReportResponse; }
virtual ~ReadHandler() = default;
Expand Down Expand Up @@ -214,6 +217,7 @@ class ReadHandler : public Messaging::ExchangeDelegate
FabricIndex mFabricIndex = 0;
AttributePathExpandIterator mAttributePathExpandIterator = AttributePathExpandIterator(nullptr);
bool mIsFabricFiltered = false;
bool mNeedRefreshSubscribe = false;
};
} // namespace app
} // namespace chip

0 comments on commit e6f663d

Please sign in to comment.