@@ -29,20 +29,33 @@ namespace reporting {
29
29
*
30
30
* @brief This class extends ReportScheduler and provides a scheduling logic for the CHIP Interaction Model Reporting Engine.
31
31
*
32
- * It is reponsible for implementing the ReadHandler and ICD observers callbacks to the Scheduler can take actions whenever a
33
- * ReadHandler event occurs or the ICD changes modes .
32
+ * It is responsible for implementing the ReadHandler and ICD observers callbacks so the Scheduler can take action whenever a
33
+ * ReadHandler event occurs or the ICD mode change occurs .
34
34
*
35
- * All ReadHandlers Observers callbacks rely on the node pool to create or find the node associated to the ReadHandler that
35
+ * All ReadHandlers Observers callbacks rely on the node pool to create or find the node associated with the ReadHandler that
36
36
* triggered the callback and will use the FindReadHandlerNode() method to do so.
37
37
*
38
38
* ## Scheduling Logic
39
39
*
40
40
* This class implements a scheduling logic that calculates the next report timeout based on the current system timestamp, the state
41
41
* of the ReadHandlers associated with the scheduler nodes and the min and max intervals of the ReadHandlers.
42
42
*
43
- * @note This class mimics the original scheduling in which the ReadHandlers would schedule themselves. The key difference is that
44
- * this implementation only relies on a single timer from the scheduling moment rather than having a timer expiring on the min
45
- * interval that would trigger the start of a second timer expiring on the max interval.
43
+ * The logic is as follows:
44
+ *
45
+ * - When a ReadHandler is created for a subscription, the scheduler adds a node and registers it in the scheduler node pool.
46
+ *
47
+ * - Each node can schedule a report independently from the other nodes, and thus each node has its timer.
48
+ *
49
+ * - The timeout of each node timer is calculated when its associated ReadHandler becomes reportable, when a report is sent for
50
+ * the ReadHandler.
51
+ *
52
+ * - The scheduler calculates the next report timeout of each node timer based on the current system timestamp and the state of the
53
+ * ReadHandlers. If the ReadHandler is not reportable, the timeout is the difference between the next max interval and now. If the
54
+ * ReadHandler is reportable, the timeout is the difference between the next min interval and now. If that min interval is in the
55
+ * past, the scheduler directly calls the TimerFired() method instead of starting a timer.
56
+ *
57
+ *
58
+
46
59
*/
47
60
class ReportSchedulerImpl : public ReportScheduler
48
61
{
@@ -55,32 +68,35 @@ class ReportSchedulerImpl : public ReportScheduler
55
68
// ICDStateObserver
56
69
57
70
/* *
58
- * @brief When the ICD changes to Idle, no action is taken in this implementation.
71
+ * @brief This implementation is not attempting any synchronization on external events as each Node is scheduled independently
72
+ * solely based on its ReadHandler's state. Therefore, no synchronization action on the ICDState is needed in this
73
+ * implementation.
59
74
*/
60
75
void OnTransitionToIdle () override {};
61
76
62
77
/* *
63
- * @brief When the ICD changes to Active, this implementation will trigger a report emission on each ReadHandler that is not
64
- * blocked on its min interval.
78
+ * @brief When the ICD transitions to Active mode , this implementation will trigger a report emission on each ReadHandler that
79
+ * is not blocked by its min interval.
65
80
*
66
- * @note Most action triggering a change to the Active mode already trigger a report emission, so this method is optionnal as it
67
- * might be redundant.
81
+ * @note Most of the actions that trigger a change to the Active mode already trigger a report emission (e.g. Event or Attribute
82
+ * change), so this method is optional as it might be redundant.
68
83
*/
69
84
void OnEnterActiveMode () override ;
70
85
71
86
/* *
72
- * @brief When the ICD changes operation mode, no action is taken in this implementation.
87
+ * @brief Similar to the OnTransitionToIdle() method, this implementation does not attempt any synchronization on ICD events,
88
+ * therefore no action is needed on the ICDModeChange() method.
73
89
*/
74
90
void OnICDModeChange () override {};
75
91
76
92
// ReadHandlerObserver
77
93
78
94
/* *
79
- * @brief When a ReadHandler is added, adds a node and register it in the scheduler node pool. Scheduling the report here is
80
- * un-necessary since the ReadHandler will call MoveToState(HandlerState::CanStartReporting);, which will call
81
- * OnBecameReportable() and schedule the report.
95
+ * @brief When a ReadHandler is created for a subscription, the scheduler adds a node and registers it in the scheduler node
96
+ * pool. Scheduling the report here is unnecessary since the ReadHandler will call
97
+ * MoveToState(HandlerState::CanStartReporting);, which will call OnBecameReportable() and schedule a report.
82
98
*
83
- * @note This method sets a now Timestamp that is used to calculate the next report timeout .
99
+ * @note This method sets a timestamp to the call time that is used as an input parameter by the ScheduleReport method .
84
100
*/
85
101
void OnSubscriptionEstablished (ReadHandler * aReadHandler) final ;
86
102
@@ -94,9 +110,6 @@ class ReportSchedulerImpl : public ReportScheduler
94
110
/* *
95
111
* @brief When a ReadHandler report is sent, recalculate and reschedule the report.
96
112
*
97
- * @note This method is called after the report is sent, so the ReadHandler is no longer reportable, and thus CanBeSynced and
98
- * EngineRunScheduled of the node associated to the ReadHandler are set to false in this method.
99
- *
100
113
* @note This method sets a now Timestamp that is used to calculate the next report timeout.
101
114
*/
102
115
void OnSubscriptionReportSent (ReadHandler * aReadHandler) final ;
@@ -106,22 +119,27 @@ class ReportSchedulerImpl : public ReportScheduler
106
119
*/
107
120
void OnReadHandlerDestroyed (ReadHandler * aReadHandler) override ;
108
121
122
+ /* *
123
+ * @brief Checks if a report is scheduled for the ReadHandler by checking if the timer is active.
124
+ *
125
+ * @note If the CalculateNextReportTimeout outputs 0, the TimerFired() will be called directly instead of starting a timer,
126
+ * so this method will return false.
127
+ */
109
128
virtual bool IsReportScheduled (ReadHandler * aReadHandler);
110
129
111
130
void ReportTimerCallback () override ;
112
131
113
132
protected:
114
133
/* *
115
- * @brief Schedule a report for the ReadHandler associated to the node .
134
+ * @brief Schedule a report for the ReadHandler associated with a ReadHandlerNode .
116
135
*
117
- * If a report is already scheduled for the ReadHandler, cancel it and schedule a new one.
118
- * If the timeout is 0, directly calls the TimerFired() method of the node instead of scheduling a report.
136
+ * @note If a report is already scheduled for the ReadHandler, this method will cancel it and schedule a new one.
119
137
*
120
138
* @param[in] timeout The timeout to schedule the report.
121
- * @param[in] node The node associated to the ReadHandler.
139
+ * @param[in] node The node associated with the ReadHandler.
122
140
* @param[in] now The current system timestamp.
123
141
*
124
- * @return CHIP_ERROR CHIP_NO_ERROR on success, timer related error code otherwise (This can only fail on starting the timer)
142
+ * @return CHIP_ERROR CHIP_NO_ERROR on success, timer- related error code otherwise (This can only fail on starting the timer)
125
143
*/
126
144
virtual CHIP_ERROR ScheduleReport (Timeout timeout, ReadHandlerNode * node, const Timestamp & now);
127
145
void CancelReport (ReadHandler * aReadHandler);
@@ -131,19 +149,14 @@ class ReportSchedulerImpl : public ReportScheduler
131
149
friend class chip ::app::reporting::TestReportScheduler;
132
150
133
151
/* *
134
- * @brief Find the next timer when a report should be scheduled for a ReadHandler.
152
+ * @brief Find the next timestamp when a report should be scheduled for a ReadHandler.
135
153
*
136
- * @param[out] timeout The timeout to calculate .
154
+ * @param[out] timeout The timeout calculated from the "now" timestamp provided as an input parameter .
137
155
* @param[in] aNode The node associated to the ReadHandler.
138
156
* @param[in] now The current system timestamp.
139
157
*
140
158
* @return CHIP_ERROR CHIP_NO_ERROR on success or CHIP_ERROR_INVALID_ARGUMENT if aNode is not in the pool.
141
159
*
142
- * The logic is as follows:
143
- * - If the ReadHandler is reportable now, the timeout is 0.
144
- * - If the ReadHandler is reportable, but the current timestamp is earlier thant the next min interval's timestamp, the timeout
145
- * is the delta between the next min interval and now.
146
- * - If the ReadHandler is not reportable, the timeout is the difference between the next max interval and now.
147
160
*/
148
161
virtual CHIP_ERROR CalculateNextReportTimeout (Timeout & timeout, ReadHandlerNode * aNode, const Timestamp & now);
149
162
};
0 commit comments