@@ -57,7 +57,9 @@ class TestICDManager;
57
57
class ICDManager : public ICDListener , public TestEventTriggerHandler
58
58
{
59
59
public:
60
- // This structure is used for the creation an ObjectPool of ICDStateObserver pointers
60
+ /* *
61
+ * @brief This structure is used for the creation an ObjectPool of ICDStateObserver pointers
62
+ */
61
63
struct ObserverPointer
62
64
{
63
65
ObserverPointer (ICDStateObserver * obs) : mObserver (obs) {}
@@ -71,11 +73,31 @@ class ICDManager : public ICDListener, public TestEventTriggerHandler
71
73
ActiveMode,
72
74
};
73
75
74
- // This enum class represents to all ICDStateObserver callbacks available from the
75
- // mStateObserverPool for the ICDManager.
76
+ /* *
77
+ * @brief This enum class represents to all ICDStateObserver callbacks available from the
78
+ * mStateObserverPool for the ICDManager.
79
+ *
80
+ * EnterActiveMode, TransitionToIdle and EnterIdleMode will always be called as a trio in the same order.
81
+ * Each event will only be called once per cycle.
82
+ * EnterActiveMode will always be called first, when the ICD has transitioned to ActiveMode.
83
+ * TransitionToIdle will always be second. This event will only be called the first time there is
84
+ * `ICD_ACTIVE_TIME_JITTER_MS` remaining to the ActiveMode timer.
85
+ * When this event is called, the ICD is still in ActiveMode.
86
+ * If the ActiveMode timer is increased due to the TransitionToIdle event, the event will not be called a second time in
87
+ * a given cycle.
88
+ * OnEnterIdleMode will always the third when the ICD has transitioned to IdleMode.
89
+ *
90
+ * The ICDModeChange event can occur independently from the EnterActiveMode, TransitionToIdle and EnterIdleMode.
91
+ * It will typpically hapen at the ICDManager init when a client is already registered with the ICD before the
92
+ * OnEnterIdleMode event or when a client send a register command after the OnEnterActiveMode event. Nothing prevents the
93
+ * ICDModeChange event to happen multiple times per cycle or while the ICD is in IdleMode.
94
+ *
95
+ * See src/app/icd/server/ICDStateObserver.h for more information on the APIs each event triggers
96
+ */
76
97
enum class ObserverEventType : uint8_t
77
98
{
78
99
EnterActiveMode,
100
+ EnterIdleMode,
79
101
TransitionToIdle,
80
102
ICDModeChange,
81
103
};
@@ -85,22 +107,31 @@ class ICDManager : public ICDListener, public TestEventTriggerHandler
85
107
* This type can be used to implement specific verifiers that can be used in the CheckInMessagesWouldBeSent function.
86
108
* The goal is to avoid having multiple functions that implement the iterator loop with only the check changing.
87
109
*
88
- * @return true if at least one Check-In message would be sent
89
- * false No Check-In messages would be sent
110
+ * @return true: if at least one Check-In message would be sent
111
+ * false: No Check-In messages would be sent
90
112
*/
91
-
92
113
using ShouldCheckInMsgsBeSentFunction = bool (FabricIndex aFabricIndex, NodeId subjectID);
93
114
94
- ICDManager () {}
115
+ ICDManager () = default ;
116
+ ~ICDManager () = default ;
117
+
95
118
void Init (PersistentStorageDelegate * storage, FabricTable * fabricTable, Crypto::SymmetricKeystore * symmetricKeyStore,
96
- Messaging::ExchangeManager * exchangeManager, SubscriptionsInfoProvider * manager );
119
+ Messaging::ExchangeManager * exchangeManager, SubscriptionsInfoProvider * subInfoProvider );
97
120
void Shutdown ();
98
- void UpdateICDMode ();
99
- void UpdateOperationState (OperationalState state);
100
- void SetKeepActiveModeRequirements (KeepActiveFlags flag, bool state);
101
- bool IsKeepActive () { return mKeepActiveFlags .HasAny (); }
121
+
122
+ /* *
123
+ * @brief SupportsFeature verifies if a given FeatureMap bit is enabled
124
+ *
125
+ * @param[in] feature FeatureMap bit to verify
126
+ *
127
+ * @return true: if the FeatureMap bit is enabled in the ICDM cluster attribute.
128
+ * false: if the FeatureMap bit is not enabled in the ICDM cluster attribute.
129
+ * if we failed to read the FeatureMap attribute.
130
+ */
102
131
bool SupportsFeature (Clusters::IcdManagement::Feature feature);
132
+
103
133
ICDConfigurationData::ICDMode GetICDMode () { return ICDConfigurationData::GetInstance ().GetICDMode (); };
134
+
104
135
/* *
105
136
* @brief Adds the referenced observer in parameters to the mStateObserverPool
106
137
* A maximum of CHIP_CONFIG_ICD_OBSERVERS_POOL_SIZE observers can be concurrently registered
@@ -111,36 +142,29 @@ class ICDManager : public ICDListener, public TestEventTriggerHandler
111
142
112
143
/* *
113
144
* @brief Remove the referenced observer in parameters from the mStateObserverPool
145
+ * If the observer is not present in the object pool, we do nothing
114
146
*/
115
147
void ReleaseObserver (ICDStateObserver * observer);
116
148
117
- /* *
118
- * @brief Associates the ObserverEventType parameters to the correct
119
- * ICDStateObservers function and calls it for all observers in the mStateObserverPool
120
- */
121
- void postObserverEvent (ObserverEventType event);
122
- OperationalState GetOperationalState () { return mOperationalState ; }
123
-
124
149
/* *
125
150
* @brief Ensures that the remaining Active Mode duration is at least the smaller of 30000 milliseconds and stayActiveDuration.
126
151
*
127
- * @param stayActiveDuration The duration (in milliseconds) requested by the client to stay in Active Mode
152
+ * @param[in] stayActiveDuration The duration (in milliseconds) requested by the client to stay in Active Mode
128
153
* @return The duration (in milliseconds) the device will stay in Active Mode
129
154
*/
130
155
uint32_t StayActiveRequest (uint32_t stayActiveDuration);
131
156
132
157
/* *
133
158
* @brief TestEventTriggerHandler for the ICD feature set
134
159
*
135
- * @param eventTrigger Event trigger to handle.
160
+ * @param[in] eventTrigger Event trigger to handle.
161
+ *
136
162
* @return CHIP_ERROR CHIP_NO_ERROR - No erros during the processing
137
163
* CHIP_ERROR_INVALID_ARGUMENT - eventTrigger isn't a valid value
138
164
*/
139
165
CHIP_ERROR HandleEventTrigger (uint64_t eventTrigger) override ;
140
166
141
167
#if CHIP_CONFIG_ENABLE_ICD_CIP
142
- void SendCheckInMsgs ();
143
-
144
168
/* *
145
169
* @brief Trigger the ICDManager to send Check-In message if necessary
146
170
*
@@ -160,47 +184,108 @@ class ICDManager : public ICDListener, public TestEventTriggerHandler
160
184
161
185
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
162
186
void SetTestFeatureMapValue (uint32_t featureMap) { mFeatureMap = featureMap; };
163
- #if !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
187
+ #if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
164
188
bool GetIsBootUpResumeSubscriptionExecuted () { return mIsBootUpResumeSubscriptionExecuted ; };
165
189
#endif // !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
166
190
#endif
167
191
168
192
// Implementation of ICDListener functions.
169
193
// Callers must origin from the chip task context or hold the ChipStack lock.
194
+
170
195
void OnNetworkActivity () override ;
171
196
void OnKeepActiveRequest (KeepActiveFlags request) override ;
172
197
void OnActiveRequestWithdrawal (KeepActiveFlags request) override ;
173
198
void OnICDManagementServerEvent (ICDManagementEvents event) override ;
174
199
void OnSubscriptionReport () override ;
175
200
176
- protected :
201
+ private :
177
202
friend class TestICDManager ;
203
+ /* *
204
+ * @brief UpdateICDMode evaluates in which mode the ICD can be in; SIT or LIT mode.
205
+ * If the current operating mode does not match the evaluated operating mode, function updates the ICDMode and triggers
206
+ * all necessary operations.
207
+ * For a SIT ICD, this function does nothing.
208
+ * For a LIT ICD, the function checks if the ICD has a registration in the ICDMonitoringTable to determine which ICDMode
209
+ * the ICD must be in.
210
+ */
211
+ void UpdateICDMode ();
178
212
179
213
/* *
180
- * @brief Hepler function that extends the Active Mode duration as well as the Active Mode Jitter timer for the transition to
181
- * iddle mode.
214
+ * @brief UpdateOperationState updates the OperationState of the ICD to the requested one.
215
+ * IdleMode -> IdleMode : No actions are necessary, do nothing.
216
+ * IdleMode -> ActiveMode : Transition the device to ActiveMode, start the ActiveMode timer and trigger all necessary
217
+ * operations. These operations could be : Send Check-In messages
218
+ * Send subscription reports
219
+ * Process user actions
220
+ * ActiveMode -> ActiveMode : Increase remaining ActiveMode timer to one ActiveModeThreshold.
221
+ * If ActiveModeThreshold is 0, do nothing.
222
+ * ActiveMode -> IdleMode : Transition ICD to IdleMode and start the IdleMode timer.
223
+ *
224
+ * @param state requested OperationalState for the ICD to transition to
225
+ */
226
+ void UpdateOperationState (OperationalState state);
227
+
228
+ /* *
229
+ * @brief Set or Remove a keep ActiveMode requirement for the given flag
230
+ * If state is true and the ICD is in IdleMode, transition the ICD to ActiveMode
231
+ * If state is false and the ICD is in ActiveMode, check whether we can transition the ICD to IdleMode.
232
+ * If we can, transition the ICD to IdleMode.
233
+ *
234
+ * @param flag KeepActiveFlag to remove or add
235
+ * @param state true: adding a flag requirement
236
+ * false: removing a flag requirement
237
+ */
238
+ void SetKeepActiveModeRequirements (KeepActiveFlags flag, bool state);
239
+
240
+ /* *
241
+ * @brief Associates the ObserverEventType parameters to the correct
242
+ * ICDStateObservers function and calls it for all observers in the mStateObserverPool
243
+ */
244
+ void postObserverEvent (ObserverEventType event);
245
+
246
+ /* *
247
+ * @brief Hepler function that extends the ActiveMode timer as well as the Active Mode Jitter timer for the transition to
248
+ * idle mode event.
182
249
*/
183
250
void ExtendActiveMode (System::Clock::Milliseconds16 extendDuration);
184
251
252
+ /* *
253
+ * @brief Timer callback function for when the IdleMode timer expires
254
+ *
255
+ * @param appState pointer to the ICDManager
256
+ */
185
257
static void OnIdleModeDone (System::Layer * aLayer, void * appState);
258
+
259
+ /* *
260
+ * @brief Timer callback function for when the ActiveMode timer expires
261
+ *
262
+ * @param appState pointer to the ICDManager
263
+ */
186
264
static void OnActiveModeDone (System::Layer * aLayer, void * appState);
187
265
188
266
/* *
189
- * @brief Callback function called shortly before the device enters idle mode to allow checks to be made. This is currently only
190
- * called once to prevent entering in a loop if some events re-trigger this check (for instance if a check for subscription
191
- * before entering idle mode leads to emiting a report, we will re-enter UpdateOperationState and check again for subscription,
192
- * etc.)
267
+ * @brief Timer Callback function called shortly before the device enters idle mode to allow checks to be made.
268
+ * This is currently only called once to prevent entering in a loop if some events re-trigger this check (for instance if
269
+ * a check for subscriptions before entering idle mode leads to emiting a report, we will re-enter UpdateOperationState
270
+ * and check again for subscription, etc.)
271
+ *
272
+ * @param appState pointer to the ICDManager
193
273
*/
194
274
static void OnTransitionToIdle (System::Layer * aLayer, void * appState);
195
275
196
276
#if CHIP_CONFIG_ENABLE_ICD_CIP
197
- uint8_t mCheckInRequestCount = 0 ;
198
- #endif // CHIP_CONFIG_ENABLE_ICD_CIP
199
-
200
- uint8_t mOpenExchangeContextCount = 0 ;
277
+ /* *
278
+ * @brief Function triggers all necessary Check-In messages to be sent.
279
+ *
280
+ * @note For each ICDMonitoring entry, we check if should send a Check-In message with
281
+ * ShouldCheckInMsgsBeSentAtActiveModeFunction. If we should, we allocate an ICDCheckInSender which tries to send a
282
+ * Check-In message to the registered client.
283
+ */
284
+ void SendCheckInMsgs ();
201
285
202
- private:
203
- #if CHIP_CONFIG_ENABLE_ICD_CIP
286
+ /* *
287
+ * @brief See function implementation in .cpp for details on this function.
288
+ */
204
289
bool ShouldCheckInMsgsBeSentAtActiveModeFunction (FabricIndex aFabricIndex, NodeId subjectID);
205
290
206
291
/* *
@@ -221,11 +306,15 @@ class ICDManager : public ICDListener, public TestEventTriggerHandler
221
306
OperationalState mOperationalState = OperationalState::ActiveMode;
222
307
bool mTransitionToIdleCalled = false ;
223
308
ObjectPool<ObserverPointer, CHIP_CONFIG_ICD_OBSERVERS_POOL_SIZE> mStateObserverPool ;
309
+ uint8_t mOpenExchangeContextCount = 0 ;
224
310
225
311
#if CHIP_CONFIG_ENABLE_ICD_CIP
312
+ uint8_t mCheckInRequestCount = 0 ;
313
+
226
314
#if !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
227
315
bool mIsBootUpResumeSubscriptionExecuted = false ;
228
316
#endif // !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION && CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
317
+
229
318
PersistentStorageDelegate * mStorage = nullptr ;
230
319
FabricTable * mFabricTable = nullptr ;
231
320
Messaging::ExchangeManager * mExchangeManager = nullptr ;
0 commit comments