@@ -32,44 +32,22 @@ 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;
56
- }
57
-
58
- } // namespace
59
-
60
- ActionsServer ActionsServer::sInstance ;
61
-
62
- void ActionsServer::SetDefaultDelegate (EndpointId aEndpoint, Delegate * aDelegate)
63
- {
64
- if (aEndpoint < kActionsDelegateTableSize )
65
- {
66
- gDelegateTable [aEndpoint] = aDelegate;
67
- }
42
+ CommandHandlerInterfaceRegistry::Instance ().UnregisterCommandHandler (this );
43
+ AttributeAccessInterfaceRegistry::Instance ().Unregister (this );
68
44
}
69
45
70
- ActionsServer & ActionsServer::Instance ()
46
+ CHIP_ERROR ActionsServer::Init ()
71
47
{
72
- return sInstance ;
48
+ ReturnErrorOnFailure (CommandHandlerInterfaceRegistry::Instance ().RegisterCommandHandler (this ));
49
+ VerifyOrReturnError (AttributeAccessInterfaceRegistry::Instance ().Register (this ), CHIP_ERROR_INCORRECT_STATE);
50
+ return CHIP_NO_ERROR;
73
51
}
74
52
75
53
void ActionsServer::OnStateChanged (EndpointId aEndpoint, uint16_t aActionId, uint32_t aInvokeId, ActionStateEnum aActionState)
@@ -126,14 +104,10 @@ CHIP_ERROR ActionsServer::Read(const ConcreteReadAttributePath & aPath, Attribut
126
104
CHIP_ERROR ActionsServer::ReadActionListAttribute (const ConcreteReadAttributePath & aPath,
127
105
const AttributeValueEncoder::ListEncodeHelper & aEncoder)
128
106
{
129
- Delegate * delegate = GetDelegate (aPath.mEndpointId );
130
- ReturnErrorOnFailure (ValidateDelegate (delegate, aPath.mEndpointId ));
131
-
132
107
for (uint16_t i = 0 ; i < kMaxActionListLength ; i++)
133
108
{
134
109
ActionStructStorage action;
135
- CHIP_ERROR err = delegate->ReadActionAtIndex (i, action);
136
-
110
+ CHIP_ERROR err = mDelegate .ReadActionAtIndex (i, action);
137
111
if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED)
138
112
{
139
113
return CHIP_NO_ERROR;
@@ -147,14 +121,10 @@ CHIP_ERROR ActionsServer::ReadActionListAttribute(const ConcreteReadAttributePat
147
121
CHIP_ERROR ActionsServer::ReadEndpointListAttribute (const ConcreteReadAttributePath & aPath,
148
122
const AttributeValueEncoder::ListEncodeHelper & aEncoder)
149
123
{
150
- Delegate * delegate = GetDelegate (aPath.mEndpointId );
151
- ReturnErrorOnFailure (ValidateDelegate (delegate, aPath.mEndpointId ));
152
-
153
124
for (uint16_t i = 0 ; i < kMaxEndpointListLength ; i++)
154
125
{
155
126
EndpointListStorage epList;
156
-
157
- CHIP_ERROR err = delegate->ReadEndpointListAtIndex (i, epList);
127
+ CHIP_ERROR err = mDelegate .ReadEndpointListAtIndex (i, epList);
158
128
if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED)
159
129
{
160
130
return CHIP_NO_ERROR;
@@ -167,9 +137,7 @@ CHIP_ERROR ActionsServer::ReadEndpointListAttribute(const ConcreteReadAttributeP
167
137
168
138
bool ActionsServer::HaveActionWithId (EndpointId aEndpointId, uint16_t aActionId, uint16_t & aActionIndex)
169
139
{
170
- Delegate * delegate = GetDelegate (aEndpointId);
171
- VerifyOrReturnValue (ValidateDelegate (delegate, aEndpointId) == CHIP_NO_ERROR, false );
172
- return delegate->HaveActionWithId (aActionId, aActionIndex);
140
+ return mDelegate .HaveActionWithId (aActionId, aActionIndex);
173
141
}
174
142
175
143
template <typename RequestT, typename FuncT>
@@ -201,10 +169,8 @@ void ActionsServer::HandleCommand(HandlerContext & handlerContext, FuncT func)
201
169
}
202
170
if (actionIndex != kMaxActionListLength )
203
171
{
204
- Delegate * delegate = GetDelegate (handlerContext.mRequestPath .mEndpointId );
205
- ReturnOnFailure (ValidateDelegate (delegate, handlerContext.mRequestPath .mEndpointId ));
206
172
ActionStructStorage action;
207
- delegate-> ReadActionAtIndex (actionIndex, action);
173
+ mDelegate . ReadActionAtIndex (actionIndex, action);
208
174
// Check if the command bit is set in the SupportedCommands of an ations.
209
175
if (!(action.supportedCommands .Raw () & (1 << handlerContext.mRequestPath .mCommandId )))
210
176
{
@@ -220,139 +186,79 @@ void ActionsServer::HandleCommand(HandlerContext & handlerContext, FuncT func)
220
186
221
187
void ActionsServer::HandleInstantAction (HandlerContext & ctx, const Commands::InstantAction::DecodableType & commandData)
222
188
{
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
- }
189
+ Status status = mDelegate .HandleInstantAction (commandData.actionID , commandData.invokeID );
229
190
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
230
191
}
231
192
232
193
void ActionsServer::HandleInstantActionWithTransition (HandlerContext & ctx,
233
194
const Commands::InstantActionWithTransition::DecodableType & commandData)
234
195
{
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
- }
196
+ Status status =
197
+ mDelegate .HandleInstantActionWithTransition (commandData.actionID , commandData.transitionTime , commandData.invokeID );
242
198
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
243
199
}
244
200
245
201
void ActionsServer::HandleStartAction (HandlerContext & ctx, const Commands::StartAction::DecodableType & commandData)
246
202
{
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
- }
203
+ Status status = mDelegate .HandleStartAction (commandData.actionID , commandData.invokeID );
253
204
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
254
205
}
255
206
256
207
void ActionsServer::HandleStartActionWithDuration (HandlerContext & ctx,
257
208
const Commands::StartActionWithDuration::DecodableType & commandData)
258
209
{
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
- }
210
+ Status status = mDelegate .HandleStartActionWithDuration (commandData.actionID , commandData.duration , commandData.invokeID );
265
211
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
266
212
}
267
213
268
214
void ActionsServer::HandleStopAction (HandlerContext & ctx, const Commands::StopAction::DecodableType & commandData)
269
215
{
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
- }
216
+ Status status = mDelegate .HandleStopAction (commandData.actionID , commandData.invokeID );
276
217
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
277
218
}
278
219
279
220
void ActionsServer::HandlePauseAction (HandlerContext & ctx, const Commands::PauseAction::DecodableType & commandData)
280
221
{
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
- }
222
+ Status status = mDelegate .HandlePauseAction (commandData.actionID , commandData.invokeID );
287
223
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
288
224
}
289
225
290
226
void ActionsServer::HandlePauseActionWithDuration (HandlerContext & ctx,
291
227
const Commands::PauseActionWithDuration::DecodableType & commandData)
292
228
{
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
- }
229
+ Status status = mDelegate .HandlePauseActionWithDuration (commandData.actionID , commandData.duration , commandData.invokeID );
299
230
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
300
231
}
301
232
302
233
void ActionsServer::HandleResumeAction (HandlerContext & ctx, const Commands::ResumeAction::DecodableType & commandData)
303
234
{
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
- }
235
+ Status status = mDelegate .HandleResumeAction (commandData.actionID , commandData.invokeID );
310
236
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
311
237
}
312
238
313
239
void ActionsServer::HandleEnableAction (HandlerContext & ctx, const Commands::EnableAction::DecodableType & commandData)
314
240
{
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
- }
241
+ Status status = mDelegate .HandleEnableAction (commandData.actionID , commandData.invokeID );
321
242
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
322
243
}
323
244
324
245
void ActionsServer::HandleEnableActionWithDuration (HandlerContext & ctx,
325
246
const Commands::EnableActionWithDuration::DecodableType & commandData)
326
247
{
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
- }
248
+ Status status = mDelegate .HandleEnableActionWithDuration (commandData.actionID , commandData.duration , commandData.invokeID );
333
249
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
334
250
}
335
251
336
252
void ActionsServer::HandleDisableAction (HandlerContext & ctx, const Commands::DisableAction::DecodableType & commandData)
337
253
{
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
- }
254
+ Status status = mDelegate .HandleDisableAction (commandData.actionID , commandData.invokeID );
344
255
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
345
256
}
346
257
347
258
void ActionsServer::HandleDisableActionWithDuration (HandlerContext & ctx,
348
259
const Commands::DisableActionWithDuration::DecodableType & commandData)
349
260
{
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
- }
261
+ Status status = mDelegate .HandleDisableActionWithDuration (commandData.actionID , commandData.duration , commandData.invokeID );
356
262
ctx.mCommandHandler .AddStatus (ctx.mRequestPath , status);
357
263
}
358
264
@@ -426,8 +332,4 @@ void ActionsServer::EndpointListModified(EndpointId aEndpoint)
426
332
MarkDirty (aEndpoint, Attributes::EndpointLists::Id);
427
333
}
428
334
429
- void MatterActionsPluginServerInitCallback ()
430
- {
431
- AttributeAccessInterfaceRegistry::Instance ().Register (&ActionsServer::Instance ());
432
- CommandHandlerInterfaceRegistry::Instance ().RegisterCommandHandler (&ActionsServer::Instance ());
433
- }
335
+ void MatterActionsPluginServerInitCallback () {}
0 commit comments