@@ -32,44 +32,25 @@ using namespace chip::app::Clusters::Actions;
32
32
using namespace chip ::app::Clusters::Actions::Attributes;
33
33
using namespace chip ::Protocols::InteractionModel;
34
34
35
- namespace {
36
- static constexpr size_t kActionsDelegateTableSize =
37
- MATTER_DM_ACTIONS_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT;
38
- static_assert (kActionsDelegateTableSize <= kEmberInvalidEndpointIndex , " Actions Delegate table size error" );
39
-
40
- // TODO: We should not use global array, instead we can use one cluster instance per endpoint.
41
- Delegate * gDelegateTable [kActionsDelegateTableSize ] = { nullptr };
42
-
43
- Delegate * GetDelegate (EndpointId aEndpoint)
35
+ ActionsServer::~ActionsServer ()
44
36
{
45
- return (aEndpoint >= kActionsDelegateTableSize ? nullptr : gDelegateTable [aEndpoint] );
37
+ Shutdown ( );
46
38
}
47
39
48
- CHIP_ERROR ValidateDelegate (Delegate * aDelegate, EndpointId aEndpoint )
40
+ void ActionsServer::Shutdown ( )
49
41
{
50
- if (aDelegate == nullptr )
51
- {
52
- ChipLogError (Zcl, " Actions delegate is null for endpoint: %d !!!" , aEndpoint);
53
- return CHIP_ERROR_INCORRECT_STATE;
54
- }
55
- return CHIP_NO_ERROR;
42
+ CommandHandlerInterfaceRegistry::Instance ().UnregisterCommandHandler (this );
43
+ AttributeAccessInterfaceRegistry::Instance ().Unregister (this );
56
44
}
57
45
58
- } // namespace
59
-
60
- ActionsServer ActionsServer::sInstance ;
61
-
62
- void ActionsServer::SetDefaultDelegate (EndpointId aEndpoint, Delegate * aDelegate)
46
+ CHIP_ERROR ActionsServer::Init ()
63
47
{
64
- if (aEndpoint < kActionsDelegateTableSize )
65
- {
66
- gDelegateTable [aEndpoint] = aDelegate;
67
- }
68
- }
48
+ // Check if the cluster has been selected in zap
49
+ VerifyOrDie (emberAfContainsServer (mEndpointId , Actions::Id) == true );
69
50
70
- ActionsServer & ActionsServer ::Instance ()
71
- {
72
- return sInstance ;
51
+ ReturnErrorOnFailure ( CommandHandlerInterfaceRegistry ::Instance (). RegisterCommandHandler ( this ));
52
+ VerifyOrReturnError ( AttributeAccessInterfaceRegistry::Instance (). Register ( this ), CHIP_ERROR_INCORRECT_STATE);
53
+ return CHIP_NO_ERROR ;
73
54
}
74
55
75
56
void ActionsServer::OnStateChanged (EndpointId aEndpoint, uint16_t aActionId, uint32_t aInvokeId, ActionStateEnum aActionState)
@@ -126,13 +107,10 @@ CHIP_ERROR ActionsServer::Read(const ConcreteReadAttributePath & aPath, Attribut
126
107
CHIP_ERROR ActionsServer::ReadActionListAttribute (const ConcreteReadAttributePath & aPath,
127
108
const AttributeValueEncoder::ListEncodeHelper & aEncoder)
128
109
{
129
- Delegate * delegate = GetDelegate (aPath.mEndpointId );
130
- ReturnErrorOnFailure (ValidateDelegate (delegate, aPath.mEndpointId ));
131
-
132
110
for (uint16_t i = 0 ; i < kMaxActionListLength ; i++)
133
111
{
134
112
ActionStructStorage action;
135
- CHIP_ERROR err = delegate ->ReadActionAtIndex (i, action);
113
+ CHIP_ERROR err = mDelegate ->ReadActionAtIndex (i, action);
136
114
137
115
if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED)
138
116
{
@@ -147,14 +125,11 @@ CHIP_ERROR ActionsServer::ReadActionListAttribute(const ConcreteReadAttributePat
147
125
CHIP_ERROR ActionsServer::ReadEndpointListAttribute (const ConcreteReadAttributePath & aPath,
148
126
const AttributeValueEncoder::ListEncodeHelper & aEncoder)
149
127
{
150
- Delegate * delegate = GetDelegate (aPath.mEndpointId );
151
- ReturnErrorOnFailure (ValidateDelegate (delegate, aPath.mEndpointId ));
152
-
153
128
for (uint16_t i = 0 ; i < kMaxEndpointListLength ; i++)
154
129
{
155
130
EndpointListStorage epList;
156
131
157
- CHIP_ERROR err = delegate ->ReadEndpointListAtIndex (i, epList);
132
+ CHIP_ERROR err = mDelegate ->ReadEndpointListAtIndex (i, epList);
158
133
if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED)
159
134
{
160
135
return CHIP_NO_ERROR;
@@ -167,9 +142,7 @@ CHIP_ERROR ActionsServer::ReadEndpointListAttribute(const ConcreteReadAttributeP
167
142
168
143
bool ActionsServer::HaveActionWithId (EndpointId aEndpointId, uint16_t aActionId, uint16_t & aActionIndex)
169
144
{
170
- Delegate * delegate = GetDelegate (aEndpointId);
171
- VerifyOrReturnValue (ValidateDelegate (delegate, aEndpointId) == CHIP_NO_ERROR, false );
172
- return delegate->HaveActionWithId (aActionId, aActionIndex);
145
+ return mDelegate ->HaveActionWithId (aActionId, aActionIndex);
173
146
}
174
147
175
148
template <typename RequestT, typename FuncT>
@@ -201,10 +174,8 @@ void ActionsServer::HandleCommand(HandlerContext & handlerContext, FuncT func)
201
174
}
202
175
if (actionIndex != kMaxActionListLength )
203
176
{
204
- Delegate * delegate = GetDelegate (handlerContext.mRequestPath .mEndpointId );
205
- ReturnOnFailure (ValidateDelegate (delegate, handlerContext.mRequestPath .mEndpointId ));
206
177
ActionStructStorage action;
207
- delegate ->ReadActionAtIndex (actionIndex, action);
178
+ mDelegate ->ReadActionAtIndex (actionIndex, action);
208
179
// Check if the command bit is set in the SupportedCommands of an ations.
209
180
if (!(action.supportedCommands .Raw () & (1 << handlerContext.mRequestPath .mCommandId )))
210
181
{
@@ -220,139 +191,90 @@ void ActionsServer::HandleCommand(HandlerContext & handlerContext, FuncT func)
220
191
221
192
void ActionsServer::HandleInstantAction (HandlerContext & ctx, const Commands::InstantAction::DecodableType & commandData)
222
193
{
223
- Delegate * delegate = GetDelegate (ctx.mRequestPath .mEndpointId );
224
- Status status = Status::InvalidInState;
225
- if (delegate != nullptr )
226
- {
227
- status = delegate->HandleInstantAction (commandData.actionID , commandData.invokeID );
228
- }
194
+ Status status = Status::InvalidInState;
195
+ status = mDelegate ->HandleInstantAction (commandData.actionID , commandData.invokeID );
229
196
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
230
197
}
231
198
232
199
void ActionsServer::HandleInstantActionWithTransition (HandlerContext & ctx,
233
200
const Commands::InstantActionWithTransition::DecodableType & commandData)
234
201
{
235
- Delegate * delegate = GetDelegate (ctx.mRequestPath .mEndpointId );
236
- Status status = Status::InvalidInState;
237
- if (delegate != nullptr )
238
- {
239
- status =
240
- delegate->HandleInstantActionWithTransition (commandData.actionID , commandData.transitionTime , commandData.invokeID );
241
- }
202
+ Status status = Status::InvalidInState;
203
+ status = mDelegate ->HandleInstantActionWithTransition (commandData.actionID , commandData.transitionTime , commandData.invokeID );
242
204
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
243
205
}
244
206
245
207
void ActionsServer::HandleStartAction (HandlerContext & ctx, const Commands::StartAction::DecodableType & commandData)
246
208
{
247
- Delegate * delegate = GetDelegate (ctx.mRequestPath .mEndpointId );
248
- Status status = Status::InvalidInState;
249
- if (delegate != nullptr )
250
- {
251
- status = delegate->HandleStartAction (commandData.actionID , commandData.invokeID );
252
- }
209
+ Status status = Status::InvalidInState;
210
+ status = mDelegate ->HandleStartAction (commandData.actionID , commandData.invokeID );
253
211
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
254
212
}
255
213
256
214
void ActionsServer::HandleStartActionWithDuration (HandlerContext & ctx,
257
215
const Commands::StartActionWithDuration::DecodableType & commandData)
258
216
{
259
- Delegate * delegate = GetDelegate (ctx.mRequestPath .mEndpointId );
260
- Status status = Status::InvalidInState;
261
- if (delegate != nullptr )
262
- {
263
- status = delegate->HandleStartActionWithDuration (commandData.actionID , commandData.duration , commandData.invokeID );
264
- }
217
+ Status status = Status::InvalidInState;
218
+ status = mDelegate ->HandleStartActionWithDuration (commandData.actionID , commandData.duration , commandData.invokeID );
265
219
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
266
220
}
267
221
268
222
void ActionsServer::HandleStopAction (HandlerContext & ctx, const Commands::StopAction::DecodableType & commandData)
269
223
{
270
- Delegate * delegate = GetDelegate (ctx.mRequestPath .mEndpointId );
271
- Status status = Status::InvalidInState;
272
- if (delegate != nullptr )
273
- {
274
- status = delegate->HandleStopAction (commandData.actionID , commandData.invokeID );
275
- }
224
+ Status status = Status::InvalidInState;
225
+ status = mDelegate ->HandleStopAction (commandData.actionID , commandData.invokeID );
276
226
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
277
227
}
278
228
279
229
void ActionsServer::HandlePauseAction (HandlerContext & ctx, const Commands::PauseAction::DecodableType & commandData)
280
230
{
281
- Delegate * delegate = GetDelegate (ctx.mRequestPath .mEndpointId );
282
- Status status = Status::InvalidInState;
283
- if (delegate != nullptr )
284
- {
285
- status = delegate->HandlePauseAction (commandData.actionID , commandData.invokeID );
286
- }
231
+ Status status = Status::InvalidInState;
232
+ status = mDelegate ->HandlePauseAction (commandData.actionID , commandData.invokeID );
287
233
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
288
234
}
289
235
290
236
void ActionsServer::HandlePauseActionWithDuration (HandlerContext & ctx,
291
237
const Commands::PauseActionWithDuration::DecodableType & commandData)
292
238
{
293
- Delegate * delegate = GetDelegate (ctx.mRequestPath .mEndpointId );
294
- Status status = Status::InvalidInState;
295
- if (delegate != nullptr )
296
- {
297
- status = delegate->HandlePauseActionWithDuration (commandData.actionID , commandData.duration , commandData.invokeID );
298
- }
239
+ Status status = Status::InvalidInState;
240
+ status = mDelegate ->HandlePauseActionWithDuration (commandData.actionID , commandData.duration , commandData.invokeID );
299
241
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
300
242
}
301
243
302
244
void ActionsServer::HandleResumeAction (HandlerContext & ctx, const Commands::ResumeAction::DecodableType & commandData)
303
245
{
304
- Delegate * delegate = GetDelegate (ctx.mRequestPath .mEndpointId );
305
- Status status = Status::InvalidInState;
306
- if (delegate != nullptr )
307
- {
308
- status = delegate->HandleResumeAction (commandData.actionID , commandData.invokeID );
309
- }
246
+ Status status = Status::InvalidInState;
247
+ status = mDelegate ->HandleResumeAction (commandData.actionID , commandData.invokeID );
310
248
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
311
249
}
312
250
313
251
void ActionsServer::HandleEnableAction (HandlerContext & ctx, const Commands::EnableAction::DecodableType & commandData)
314
252
{
315
- Delegate * delegate = GetDelegate (ctx.mRequestPath .mEndpointId );
316
- Status status = Status::InvalidInState;
317
- if (delegate != nullptr )
318
- {
319
- status = delegate->HandleEnableAction (commandData.actionID , commandData.invokeID );
320
- }
253
+ Status status = Status::InvalidInState;
254
+ status = mDelegate ->HandleEnableAction (commandData.actionID , commandData.invokeID );
321
255
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
322
256
}
323
257
324
258
void ActionsServer::HandleEnableActionWithDuration (HandlerContext & ctx,
325
259
const Commands::EnableActionWithDuration::DecodableType & commandData)
326
260
{
327
- Delegate * delegate = GetDelegate (ctx.mRequestPath .mEndpointId );
328
- Status status = Status::InvalidInState;
329
- if (delegate != nullptr )
330
- {
331
- status = delegate->HandleEnableActionWithDuration (commandData.actionID , commandData.duration , commandData.invokeID );
332
- }
261
+ Status status = Status::InvalidInState;
262
+ status = mDelegate ->HandleEnableActionWithDuration (commandData.actionID , commandData.duration , commandData.invokeID );
333
263
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
334
264
}
335
265
336
266
void ActionsServer::HandleDisableAction (HandlerContext & ctx, const Commands::DisableAction::DecodableType & commandData)
337
267
{
338
- Delegate * delegate = GetDelegate (ctx.mRequestPath .mEndpointId );
339
- Status status = Status::InvalidInState;
340
- if (delegate != nullptr )
341
- {
342
- status = delegate->HandleDisableAction (commandData.actionID , commandData.invokeID );
343
- }
268
+ Status status = Status::InvalidInState;
269
+ status = mDelegate ->HandleDisableAction (commandData.actionID , commandData.invokeID );
344
270
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
345
271
}
346
272
347
273
void ActionsServer::HandleDisableActionWithDuration (HandlerContext & ctx,
348
274
const Commands::DisableActionWithDuration::DecodableType & commandData)
349
275
{
350
- Delegate * delegate = GetDelegate (ctx.mRequestPath .mEndpointId );
351
- Status status = Status::InvalidInState;
352
- if (delegate != nullptr )
353
- {
354
- status = delegate->HandleDisableActionWithDuration (commandData.actionID , commandData.duration , commandData.invokeID );
355
- }
276
+ Status status = Status::InvalidInState;
277
+ status = mDelegate ->HandleDisableActionWithDuration (commandData.actionID , commandData.duration , commandData.invokeID );
356
278
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
357
279
}
358
280
@@ -426,8 +348,4 @@ void ActionsServer::EndpointListModified(EndpointId aEndpoint)
426
348
MarkDirty (aEndpoint, Attributes::EndpointLists::Id);
427
349
}
428
350
429
- void MatterActionsPluginServerInitCallback ()
430
- {
431
- AttributeAccessInterfaceRegistry::Instance ().Register (&ActionsServer::Instance ());
432
- CommandHandlerInterfaceRegistry::Instance ().RegisterCommandHandler (&ActionsServer::Instance ());
433
- }
351
+ void MatterActionsPluginServerInitCallback () {}
0 commit comments