@@ -64,6 +64,8 @@ namespace app {
64
64
namespace reporting {
65
65
class Engine ;
66
66
class TestReportingEngine ;
67
+ class ReportScheduler ;
68
+ class TestReportScheduler ;
67
69
} // namespace reporting
68
70
69
71
class InteractionModelEngine ;
@@ -152,6 +154,38 @@ class ReadHandler : public Messaging::ExchangeDelegate
152
154
virtual ApplicationCallback * GetAppCallback () = 0;
153
155
};
154
156
157
+ // TODO (#27675) : Merge existing callback and observer into one class and have an observer pool in the Readhandler to notify
158
+ // every
159
+ /*
160
+ * Observer class for ReadHandler, meant to allow multiple objects to observe the ReadHandler. Currently only one observer is
161
+ * supported but all above callbacks should be merged into observer type and an observer pool should be added to allow multiple
162
+ * objects to observe ReadHandler
163
+ */
164
+ class Observer
165
+ {
166
+ public:
167
+ virtual ~Observer () = default ;
168
+
169
+ // / @brief Callback invoked to notify a ReadHandler was created and can be registered
170
+ // / @param[in] apReadHandler ReadHandler getting added
171
+ virtual void OnReadHandlerCreated (ReadHandler * apReadHandler) = 0;
172
+
173
+ // / @brief Callback invoked when a ReadHandler went from a non reportable state to a reportable state so a report can be
174
+ // / sent immediately if the minimal interval allows it. Otherwise the report should be rescheduled to the earliest time
175
+ // / allowed.
176
+ // / @param[in] apReadHandler ReadHandler that became dirty
177
+ virtual void OnBecameReportable (ReadHandler * apReadHandler) = 0;
178
+
179
+ // / @brief Callback invoked when the read handler needs to make sure to send a message to the subscriber within the next
180
+ // / maxInterval time period.
181
+ // / @param[in] apReadHandler ReadHandler that has generated a report
182
+ virtual void OnSubscriptionAction (ReadHandler * apReadHandler) = 0;
183
+
184
+ // / @brief Callback invoked when a ReadHandler is getting removed so it can be unregistered
185
+ // / @param[in] apReadHandler ReadHandler getting destroyed
186
+ virtual void OnReadHandlerDestroyed (ReadHandler * apReadHandler) = 0;
187
+ };
188
+
155
189
/*
156
190
* Destructor - as part of destruction, it will abort the exchange context
157
191
* if a valid one still exists.
@@ -167,7 +201,8 @@ class ReadHandler : public Messaging::ExchangeDelegate
167
201
* The callback passed in has to outlive this handler object.
168
202
*
169
203
*/
170
- ReadHandler (ManagementCallback & apCallback, Messaging::ExchangeContext * apExchangeContext, InteractionType aInteractionType);
204
+ ReadHandler (ManagementCallback & apCallback, Messaging::ExchangeContext * apExchangeContext, InteractionType aInteractionType,
205
+ Observer * observer = nullptr );
171
206
172
207
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
173
208
/* *
@@ -177,7 +212,7 @@ class ReadHandler : public Messaging::ExchangeDelegate
177
212
* The callback passed in has to outlive this handler object.
178
213
*
179
214
*/
180
- ReadHandler (ManagementCallback & apCallback);
215
+ ReadHandler (ManagementCallback & apCallback, Observer * observer = nullptr );
181
216
#endif
182
217
183
218
const ObjectList<AttributePathParams> * GetAttributePathList () const { return mpAttributePathList; }
@@ -190,13 +225,22 @@ class ReadHandler : public Messaging::ExchangeDelegate
190
225
aMaxInterval = mMaxInterval ;
191
226
}
192
227
228
+ CHIP_ERROR SetMinReportingIntervalForTests (uint16_t aMinInterval)
229
+ {
230
+ VerifyOrReturnError (IsIdle (), CHIP_ERROR_INCORRECT_STATE);
231
+ VerifyOrReturnError (aMinInterval <= mMaxInterval , CHIP_ERROR_INVALID_ARGUMENT);
232
+ // Ensures the new min interval is higher than the subscriber established one.
233
+ mMinIntervalFloorSeconds = std::max (mMinIntervalFloorSeconds , aMinInterval);
234
+ return CHIP_NO_ERROR;
235
+ }
236
+
193
237
/*
194
- * Set the reporting intervals for the subscription. This SHALL only be called
238
+ * Set the maximum reporting interval for the subscription. This SHALL only be called
195
239
* from the OnSubscriptionRequested callback above. The restriction is as below
196
240
* MinIntervalFloor ≤ MaxInterval ≤ MAX(SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT, MaxIntervalCeiling)
197
241
* Where SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT is set to 60m in the spec.
198
242
*/
199
- CHIP_ERROR SetReportingIntervals (uint16_t aMaxInterval)
243
+ CHIP_ERROR SetMaxReportingInterval (uint16_t aMaxInterval)
200
244
{
201
245
VerifyOrReturnError (IsIdle (), CHIP_ERROR_INCORRECT_STATE);
202
246
VerifyOrReturnError (mMinIntervalFloorSeconds <= aMaxInterval, CHIP_ERROR_INVALID_ARGUMENT);
@@ -206,6 +250,18 @@ class ReadHandler : public Messaging::ExchangeDelegate
206
250
return CHIP_NO_ERROR;
207
251
}
208
252
253
+ // / @brief Add an observer to the read handler, currently only one observer is supported but all other callbacks should be
254
+ // / merged with a general observer type to allow multiple object to observe readhandlers
255
+ // / @param aObserver observer to be added
256
+ // / @return CHIP_ERROR_INVALID_ARGUMENT if passing in nullptr
257
+ CHIP_ERROR SetObserver (Observer * aObserver)
258
+ {
259
+ VerifyOrReturnError (nullptr != aObserver, CHIP_ERROR_INVALID_ARGUMENT);
260
+ // TODO (#27675) : After merging the callbacks and observer, change so the method adds a new observer to an observer pool
261
+ mObserver = aObserver;
262
+ return CHIP_NO_ERROR;
263
+ }
264
+
209
265
private:
210
266
PriorityLevel GetCurrentPriority () const { return mCurrentPriority ; }
211
267
EventNumber & GetEventMin () { return mEventMin ; }
@@ -214,13 +270,13 @@ class ReadHandler : public Messaging::ExchangeDelegate
214
270
{
215
271
// WaitingUntilMinInterval is used to prevent subscription data delivery while we are
216
272
// waiting for the min reporting interval to elapse.
217
- WaitingUntilMinInterval = (1 << 0 ),
273
+ WaitingUntilMinInterval = (1 << 0 ), // TODO (#27672): Remove once ReportScheduler is implemented or change to test flag
218
274
219
275
// WaitingUntilMaxInterval is used to prevent subscription empty report delivery while we
220
276
// are waiting for the max reporting interval to elaps. When WaitingUntilMaxInterval
221
277
// becomes false, we are allowed to send an empty report to keep the
222
278
// subscription alive on the client.
223
- WaitingUntilMaxInterval = (1 << 1 ),
279
+ WaitingUntilMaxInterval = (1 << 1 ), // TODO (#27672): Remove once ReportScheduler is implemented
224
280
225
281
// The flag indicating we are in the middle of a series of chunked report messages, this flag will be cleared during
226
282
// sending last chunked message.
@@ -291,6 +347,8 @@ class ReadHandler : public Messaging::ExchangeDelegate
291
347
292
348
bool IsIdle () const { return mState == HandlerState::Idle; }
293
349
350
+ // TODO (#27672): Change back to IsReportable once ReportScheduler is implemented so this can assess reportability without
351
+ // considering timing. The ReporScheduler will handle timing.
294
352
// / @brief Returns whether the ReadHandler is in a state where it can immediately send a report. This function
295
353
// / is used to determine whether a report generation should be scheduled for the handler.
296
354
bool IsReportableNow () const
@@ -370,6 +428,7 @@ class ReadHandler : public Messaging::ExchangeDelegate
370
428
371
429
friend class TestReadInteraction ;
372
430
friend class chip ::app::reporting::TestReportingEngine;
431
+ friend class chip ::app::reporting::TestReportScheduler;
373
432
374
433
//
375
434
// The engine needs to be able to Abort/Close a ReadHandler instance upon completion of work for a given read/subscribe
@@ -379,6 +438,10 @@ class ReadHandler : public Messaging::ExchangeDelegate
379
438
friend class chip ::app::reporting::Engine;
380
439
friend class chip ::app::InteractionModelEngine;
381
440
441
+ // The report scheduler needs to be able to access StateFlag private functions IsGeneratingReports() and IsDirty() to
442
+ // know when to schedule a run so it is declared as a friend class.
443
+ friend class chip ::app::reporting::ReportScheduler;
444
+
382
445
enum class HandlerState : uint8_t
383
446
{
384
447
Idle, // /< The handler has been initialized and is ready
@@ -404,10 +467,13 @@ class ReadHandler : public Messaging::ExchangeDelegate
404
467
405
468
// / @brief This function is called when the min interval timer has expired, it restarts the timer on a timeout equal to the
406
469
// / difference between the max interval and the min interval.
407
- static void MinIntervalExpiredCallback (System::Layer * apSystemLayer, void * apAppState);
408
- static void MaxIntervalExpiredCallback (System::Layer * apSystemLayer, void * apAppState);
470
+ static void MinIntervalExpiredCallback (System::Layer * apSystemLayer, void * apAppState); // TODO (#27672): Remove once
471
+ // ReportScheduler is implemented.
472
+ static void MaxIntervalExpiredCallback (System::Layer * apSystemLayer, void * apAppState); // TODO (#27672): Remove once
473
+ // ReportScheduler is implemented.
409
474
// / @brief This function is called when a report is sent and it restarts the min interval timer.
410
- CHIP_ERROR UpdateReportTimer ();
475
+ CHIP_ERROR UpdateReportTimer (); // TODO (#27672) : Remove once ReportScheduler is implemented.
476
+
411
477
CHIP_ERROR SendSubscribeResponse ();
412
478
CHIP_ERROR ProcessSubscribeRequest (System::PacketBufferHandle && aPayload);
413
479
CHIP_ERROR ProcessReadRequest (System::PacketBufferHandle && aPayload);
@@ -520,6 +586,9 @@ class ReadHandler : public Messaging::ExchangeDelegate
520
586
BitFlags<ReadHandlerFlags> mFlags ;
521
587
InteractionType mInteractionType = InteractionType::Read;
522
588
589
+ // TODO (#27675): Merge all observers into one and that one will dispatch the callbacks to the right place.
590
+ Observer * mObserver = nullptr ;
591
+
523
592
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
524
593
// Callbacks to handle server-initiated session success/failure
525
594
chip::Callback::Callback<OnDeviceConnected> mOnConnectedCallback ;
0 commit comments