@@ -77,16 +77,9 @@ ReadHandler::ReadHandler(ManagementCallback & apCallback, Messaging::ExchangeCon
77
77
78
78
mSessionHandle .Grab (mExchangeCtx ->GetSessionHandle ());
79
79
80
- // TODO (#27672): Uncomment when the ReportScheduler is implemented
81
- #if 0
82
- if (nullptr != observer)
83
- {
84
- if (CHIP_NO_ERROR == SetObserver(observer))
85
- {
86
- mObserver->OnReadHandlerCreated(this);
87
- }
88
- }
89
- #endif
80
+ VerifyOrDie (observer != nullptr );
81
+ mObserver = observer;
82
+ mObserver ->OnReadHandlerCreated (this );
90
83
}
91
84
92
85
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
@@ -97,16 +90,9 @@ ReadHandler::ReadHandler(ManagementCallback & apCallback, Observer * observer) :
97
90
mInteractionType = InteractionType::Subscribe;
98
91
mFlags .ClearAll ();
99
92
100
- // TODO (#27672): Uncomment when the ReportScheduler is implemented
101
- #if 0
102
- if (nullptr != observer)
103
- {
104
- if (CHIP_NO_ERROR == SetObserver(observer))
105
- {
106
- mObserver->OnReadHandlerCreated(this);
107
- }
108
- }
109
- #endif
93
+ VerifyOrDie (observer != nullptr );
94
+ mObserver = observer;
95
+ mObserver ->OnReadHandlerCreated (this );
110
96
}
111
97
112
98
void ReadHandler::ResumeSubscription (CASESessionManager & caseSessionManager,
@@ -150,28 +136,14 @@ void ReadHandler::ResumeSubscription(CASESessionManager & caseSessionManager,
150
136
151
137
ReadHandler::~ReadHandler ()
152
138
{
153
- // TODO (#27672): Enable when the ReportScheduler is implemented and move in Close() after testing
154
- #if 0
155
- if (nullptr != mObserver)
156
- {
157
- mObserver->OnReadHandlerDestroyed(this);
158
- }
159
- #endif
139
+ mObserver ->OnReadHandlerDestroyed (this );
140
+
160
141
auto * appCallback = mManagementCallback .GetAppCallback ();
161
142
if (mFlags .Has (ReadHandlerFlags::ActiveSubscription) && appCallback)
162
143
{
163
144
appCallback->OnSubscriptionTerminated (*this );
164
145
}
165
146
166
- if (IsType (InteractionType::Subscribe))
167
- {
168
- InteractionModelEngine::GetInstance ()->GetExchangeManager ()->GetSessionManager ()->SystemLayer ()->CancelTimer (
169
- MinIntervalExpiredCallback, this );
170
-
171
- InteractionModelEngine::GetInstance ()->GetExchangeManager ()->GetSessionManager ()->SystemLayer ()->CancelTimer (
172
- MaxIntervalExpiredCallback, this );
173
- }
174
-
175
147
if (IsAwaitingReportResponse ())
176
148
{
177
149
InteractionModelEngine::GetInstance ()->GetReportingEngine ().OnReportConfirm ();
@@ -290,7 +262,7 @@ CHIP_ERROR ReadHandler::OnStatusResponse(Messaging::ExchangeContext * apExchange
290
262
291
263
CHIP_ERROR ReadHandler::SendStatusReport (Protocols::InteractionModel::Status aStatus)
292
264
{
293
- VerifyOrReturnLogError (IsReportableNow () , CHIP_ERROR_INCORRECT_STATE);
265
+ VerifyOrReturnLogError (mState == HandlerState::GeneratingReports , CHIP_ERROR_INCORRECT_STATE);
294
266
if (IsPriming () || IsChunkedReport ())
295
267
{
296
268
mSessionHandle .Grab (mExchangeCtx ->GetSessionHandle ());
@@ -314,7 +286,7 @@ CHIP_ERROR ReadHandler::SendStatusReport(Protocols::InteractionModel::Status aSt
314
286
315
287
CHIP_ERROR ReadHandler::SendReportData (System::PacketBufferHandle && aPayload, bool aMoreChunks)
316
288
{
317
- VerifyOrReturnLogError (IsReportableNow () , CHIP_ERROR_INCORRECT_STATE);
289
+ VerifyOrReturnLogError (mState == HandlerState::GeneratingReports , CHIP_ERROR_INCORRECT_STATE);
318
290
VerifyOrDie (!IsAwaitingReportResponse ()); // Should not be reportable!
319
291
if (IsPriming () || IsChunkedReport ())
320
292
{
@@ -359,21 +331,11 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, b
359
331
InteractionModelEngine::GetInstance ()->GetReportingEngine ().OnReportConfirm ();
360
332
}
361
333
362
- if (IsType (InteractionType::Subscribe) && !IsPriming ())
334
+ // If we just finished a non-priming subscription report, notify our observers.
335
+ // Priming reports are handled when we send a SubscribeResponse.
336
+ if (IsType (InteractionType::Subscribe) && !IsPriming () && !IsChunkedReport ())
363
337
{
364
- // TODO (#27672): Enable when the ReportScheduler is implemented and remove call to UpdateReportTimer, will be handled by
365
- // the report Scheduler
366
- #if 0
367
- if (nullptr != mObserver)
368
- {
369
- mObserver->OnSubscriptionAction(this);
370
- }
371
- #endif
372
-
373
- // Ignore the error from UpdateReportTimer. If we've
374
- // successfully sent the message, we need to return success from
375
- // this method.
376
- UpdateReportTimer ();
338
+ mObserver ->OnSubscriptionAction (this );
377
339
}
378
340
}
379
341
if (!aMoreChunks)
@@ -641,16 +603,10 @@ void ReadHandler::MoveToState(const HandlerState aTargetState)
641
603
// If we just unblocked sending reports, let's go ahead and schedule the reporting
642
604
// engine to run to kick that off.
643
605
//
644
- if (aTargetState == HandlerState::GeneratingReports && IsReportableNow () )
606
+ if (aTargetState == HandlerState::GeneratingReports)
645
607
{
646
- // TODO (#27672): Enable when the ReportScheduler is implemented and remove the call to ScheduleRun()
647
- #if 0
648
- if(nullptr != mObserver)
649
- {
650
- mObserver->OnBecameReportable(this);
651
- }
652
- #endif
653
- InteractionModelEngine::GetInstance ()->GetReportingEngine ().ScheduleRun ();
608
+ // mObserver will take care of scheduling the report as soon as allowed
609
+ mObserver ->OnBecameReportable (this );
654
610
}
655
611
}
656
612
@@ -691,15 +647,7 @@ CHIP_ERROR ReadHandler::SendSubscribeResponse()
691
647
ReturnErrorOnFailure (writer.Finalize (&packet));
692
648
VerifyOrReturnLogError (mExchangeCtx , CHIP_ERROR_INCORRECT_STATE);
693
649
694
- // TODO (#27672): Uncomment when the ReportScheduler is implemented and remove call to UpdateReportTimer, handled by
695
- // the report Scheduler
696
- #if 0
697
- if (nullptr != mObserver)
698
- {
699
- mObserver->OnSubscriptionAction(this);
700
- }
701
- #endif
702
- ReturnErrorOnFailure (UpdateReportTimer ());
650
+ mObserver ->OnSubscriptionAction (this );
703
651
704
652
ClearStateFlag (ReadHandlerFlags::PrimingReports);
705
653
return mExchangeCtx ->SendMessage (Protocols::InteractionModel::MsgType::SubscribeResponse, std::move (packet));
@@ -818,50 +766,6 @@ void ReadHandler::PersistSubscription()
818
766
}
819
767
}
820
768
821
- // TODO (#27672): Remove when ReportScheduler is enabled as timing will now be handled by the ReportScheduler
822
- void ReadHandler::MinIntervalExpiredCallback (System::Layer * apSystemLayer, void * apAppState)
823
- {
824
- VerifyOrReturn (apAppState != nullptr );
825
- ReadHandler * readHandler = static_cast <ReadHandler *>(apAppState);
826
- ChipLogDetail (DataManagement, " Unblock report hold after min %d seconds" , readHandler->mMinIntervalFloorSeconds );
827
- readHandler->ClearStateFlag (ReadHandlerFlags::WaitingUntilMinInterval);
828
- InteractionModelEngine::GetInstance ()->GetExchangeManager ()->GetSessionManager ()->SystemLayer ()->StartTimer (
829
- System::Clock::Seconds16 (readHandler->mMaxInterval - readHandler->mMinIntervalFloorSeconds ), MaxIntervalExpiredCallback,
830
- readHandler);
831
- }
832
-
833
- // TODO (#27672): Remove when ReportScheduler is enabled as timing will now be handled by the ReportScheduler
834
- void ReadHandler::MaxIntervalExpiredCallback (System::Layer * apSystemLayer, void * apAppState)
835
- {
836
- VerifyOrReturn (apAppState != nullptr );
837
- ReadHandler * readHandler = static_cast <ReadHandler *>(apAppState);
838
- readHandler->ClearStateFlag (ReadHandlerFlags::WaitingUntilMaxInterval);
839
- ChipLogProgress (DataManagement, " Refresh subscribe timer sync after %d seconds" ,
840
- readHandler->mMaxInterval - readHandler->mMinIntervalFloorSeconds );
841
- }
842
-
843
- // TODO (#27672): Remove when ReportScheduler is enabled as timing will now be handled by the ReportScheduler
844
- CHIP_ERROR ReadHandler::UpdateReportTimer ()
845
- {
846
- InteractionModelEngine::GetInstance ()->GetExchangeManager ()->GetSessionManager ()->SystemLayer ()->CancelTimer (
847
- MinIntervalExpiredCallback, this );
848
- InteractionModelEngine::GetInstance ()->GetExchangeManager ()->GetSessionManager ()->SystemLayer ()->CancelTimer (
849
- MaxIntervalExpiredCallback, this );
850
-
851
- if (!IsChunkedReport ())
852
- {
853
- ChipLogProgress (DataManagement, " Refresh Subscribe Sync Timer with min %d seconds and max %d seconds" ,
854
- mMinIntervalFloorSeconds , mMaxInterval );
855
- SetStateFlag (ReadHandlerFlags::WaitingUntilMinInterval);
856
- SetStateFlag (ReadHandlerFlags::WaitingUntilMaxInterval);
857
- ReturnErrorOnFailure (
858
- InteractionModelEngine::GetInstance ()->GetExchangeManager ()->GetSessionManager ()->SystemLayer ()->StartTimer (
859
- System::Clock::Seconds16 (mMinIntervalFloorSeconds ), MinIntervalExpiredCallback, this ));
860
- }
861
-
862
- return CHIP_NO_ERROR;
863
- }
864
-
865
769
void ReadHandler::ResetPathIterator ()
866
770
{
867
771
mAttributePathExpandIterator = AttributePathExpandIterator (mpAttributePathList);
@@ -897,17 +801,8 @@ void ReadHandler::AttributePathIsDirty(const AttributePathParams & aAttributeCha
897
801
mAttributeEncoderState = AttributeValueEncoder::AttributeEncodeState ();
898
802
}
899
803
900
- if (IsReportableNow ())
901
- {
902
- // TODO (#27672): Enable when the ReportScheduler is implemented and remove the call to ScheduleRun()
903
- #if 0
904
- if(nullptr != mObserver)
905
- {
906
- mObserver->OnBecameReportable(this);
907
- }
908
- #endif
909
- InteractionModelEngine::GetInstance ()->GetReportingEngine ().ScheduleRun ();
910
- }
804
+ // ReportScheduler will take care of verifying the reportability of the handler and schedule the run
805
+ mObserver ->OnBecameReportable (this );
911
806
}
912
807
913
808
Transport::SecureSession * ReadHandler::GetSession () const
@@ -926,20 +821,14 @@ void ReadHandler::ForceDirtyState()
926
821
927
822
void ReadHandler::SetStateFlag (ReadHandlerFlags aFlag, bool aValue)
928
823
{
929
- bool oldReportable = IsReportableNow ();
824
+ bool oldReportable = IsReportable ();
930
825
mFlags .Set (aFlag, aValue);
931
826
932
827
// If we became reportable, schedule a reporting run.
933
- if (!oldReportable && IsReportableNow ())
828
+ if (!oldReportable && IsReportable ())
934
829
{
935
- // TODO (#27672): Enable when the ReportScheduler is implemented and remove the call to ScheduleRun()
936
- #if 0
937
- if(nullptr != mObserver)
938
- {
939
- mObserver->OnBecameReportable(this);
940
- }
941
- #endif
942
- InteractionModelEngine::GetInstance ()->GetReportingEngine ().ScheduleRun ();
830
+ // If we became reportable, the scheduler will schedule a run as soon as allowed
831
+ mObserver ->OnBecameReportable (this );
943
832
}
944
833
}
945
834
0 commit comments