Skip to content

Commit ffca294

Browse files
Address review comments.
1 parent bfe646f commit ffca294

File tree

3 files changed

+48
-78
lines changed

3 files changed

+48
-78
lines changed

examples/all-clusters-app/linux/main-common.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ void emberAfThermostatClusterInitCallback(EndpointId endpoint)
344344

345345
void emberAfActionsClusterInitCallback(EndpointId endpoint)
346346
{
347+
VerifyOrReturn(endpoint == 1);
347348
Clusters::Actions::ActionsServer::Instance().SetDefaultDelegate(endpoint, &sActionsDelegateImpl);
348349
}
349350

src/app/clusters/actions-server/actions-server.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ Delegate * GetDelegate(EndpointId aEndpoint)
4545
return (aEndpoint >= kActionsDelegateTableSize ? nullptr : gDelegateTable[aEndpoint]);
4646
}
4747

48-
CHIP_ERROR IsValid(Delegate * delegate)
48+
CHIP_ERROR ValidateDelegate(Delegate * aDelegate, EndpointId aEndpoint)
4949
{
50-
if (delegate == nullptr)
50+
if (aDelegate == nullptr)
5151
{
52-
ChipLogError(Zcl, "Actions delegate is null!!!");
52+
ChipLogError(Zcl, "Actions delegate is null for endpoint: %d !!!", aEndpoint);
5353
return CHIP_ERROR_INCORRECT_STATE;
5454
}
5555
return CHIP_NO_ERROR;
@@ -127,7 +127,7 @@ CHIP_ERROR ActionsServer::ReadActionListAttribute(const ConcreteReadAttributePat
127127
const AttributeValueEncoder::ListEncodeHelper & aEncoder)
128128
{
129129
Delegate * delegate = GetDelegate(aPath.mEndpointId);
130-
VerifyOrReturnError(IsValid(delegate) == CHIP_NO_ERROR, CHIP_ERROR_INCORRECT_STATE);
130+
ReturnErrorOnFailure(ValidateDelegate(delegate, aPath.mEndpointId));
131131

132132
for (uint16_t i = 0; i < kMaxActionListLength; i++)
133133
{
@@ -148,7 +148,7 @@ CHIP_ERROR ActionsServer::ReadEndpointListAttribute(const ConcreteReadAttributeP
148148
const AttributeValueEncoder::ListEncodeHelper & aEncoder)
149149
{
150150
Delegate * delegate = GetDelegate(aPath.mEndpointId);
151-
VerifyOrReturnError(IsValid(delegate) == CHIP_NO_ERROR, CHIP_ERROR_INCORRECT_STATE);
151+
ReturnErrorOnFailure(ValidateDelegate(delegate, aPath.mEndpointId));
152152

153153
for (uint16_t i = 0; i < kMaxEndpointListLength; i++)
154154
{
@@ -168,7 +168,7 @@ CHIP_ERROR ActionsServer::ReadEndpointListAttribute(const ConcreteReadAttributeP
168168
bool ActionsServer::HaveActionWithId(EndpointId aEndpointId, uint16_t aActionId)
169169
{
170170
Delegate * delegate = GetDelegate(aEndpointId);
171-
VerifyOrReturnValue(IsValid(delegate) == CHIP_NO_ERROR, false);
171+
VerifyOrReturnValue(ValidateDelegate(delegate, aEndpointId) == CHIP_NO_ERROR, false);
172172
return delegate->HaveActionWithId(aActionId);
173173
}
174174

@@ -193,7 +193,7 @@ void ActionsServer::HandleCommand(HandlerContext & handlerContext, FuncT func)
193193
return;
194194
}
195195

196-
if (HaveActionWithId(handlerContext.mRequestPath.mEndpointId, requestPayload.actionID))
196+
if (!HaveActionWithId(handlerContext.mRequestPath.mEndpointId, requestPayload.actionID))
197197
{
198198
handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, Protocols::InteractionModel::Status::NotFound);
199199
return;
@@ -404,7 +404,7 @@ void ActionsServer::InvokeCommand(HandlerContext & handlerContext)
404404
CHIP_ERROR ActionsServer::ModifyActionList(EndpointId aEndpoint, const ActionStructStorage & aAction)
405405
{
406406
Delegate * delegate = GetDelegate(aEndpoint);
407-
VerifyOrReturnError(IsValid(delegate) == CHIP_NO_ERROR, CHIP_ERROR_INCORRECT_STATE);
407+
ReturnErrorOnFailure(ValidateDelegate(delegate, aEndpoint));
408408

409409
// Read through the list to find and update the existing action that matches the passed-in action's ID.
410410
for (uint16_t i = 0; i < kMaxActionListLength; i++)
@@ -432,7 +432,7 @@ CHIP_ERROR ActionsServer::ModifyActionList(EndpointId aEndpoint, const ActionStr
432432
CHIP_ERROR ActionsServer::ModifyEndpointList(EndpointId aEndpoint, const EndpointListStorage & aEpList)
433433
{
434434
Delegate * delegate = GetDelegate(aEndpoint);
435-
VerifyOrReturnError(IsValid(delegate) == CHIP_NO_ERROR, CHIP_ERROR_INCORRECT_STATE);
435+
ReturnErrorOnFailure(ValidateDelegate(delegate, aEndpoint));
436436

437437
// Read through the list to find and update the existing action that matches the passed-in endpoint-list's ID
438438
for (uint16_t i = 0; i < kMaxEndpointListLength; i++)

src/app/clusters/actions-server/actions-server.h

+38-69
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ struct ActionStructStorage : public Structs::ActionStruct::Type
6161
endpointListID = aEpListID;
6262
supportedCommands = aCommands;
6363
state = aActionState;
64-
MutableCharSpan mActionName(mBuffer);
65-
CopyCharSpanToMutableCharSpanWithTruncation(aActionName, mActionName);
66-
name = mActionName;
64+
MutableCharSpan actionName(mBuffer);
65+
CopyCharSpanToMutableCharSpanWithTruncation(aActionName, actionName);
66+
name = actionName;
6767
}
6868

6969
private:
@@ -100,9 +100,9 @@ struct EndpointListStorage : public Structs::EndpointListStruct::Type
100100
mEpList[index] = aEndpointList[index];
101101
}
102102
endpoints = DataModel::List<const EndpointId>(Span(mEpList, epListSize));
103-
MutableCharSpan mEpListName(mBuffer);
104-
CopyCharSpanToMutableCharSpanWithTruncation(aEpListName, mEpListName);
105-
name = mEpListName;
103+
MutableCharSpan epListName(mBuffer);
104+
CopyCharSpanToMutableCharSpanWithTruncation(aEpListName, epListName);
105+
name = epListName;
106106
}
107107

108108
private:
@@ -122,13 +122,13 @@ class ActionsServer : public AttributeAccessInterface, public CommandHandlerInte
122122

123123
/**
124124
* @brief
125-
* Called when the state of action is changed.
125+
* Called when the state of an action is changed.
126126
*/
127127
void OnStateChanged(EndpointId aEndpoint, uint16_t aActionId, uint32_t aInvokeId, ActionStateEnum aActionState);
128128

129129
/**
130130
* @brief
131-
* Called when the action is failed..
131+
* Called when an action fails.
132132
*/
133133
void OnActionFailed(EndpointId aEndpoint, uint16_t aActionId, uint32_t aInvokeId, ActionStateEnum aActionState,
134134
ActionErrorEnum aActionError);
@@ -178,7 +178,7 @@ class ActionsServer : public AttributeAccessInterface, public CommandHandlerInte
178178
MatterReportingAttributeChangeCallback(aEndpointId, Id, aAttributeId);
179179
}
180180
// Cannot use CommandHandlerInterface::HandleCommand directly because we need to do the HaveActionWithId() check before
181-
// sending a command.
181+
// handling a command.
182182
template <typename RequestT, typename FuncT>
183183
void HandleCommand(HandlerContext & handlerContext, FuncT func);
184184

@@ -211,13 +211,14 @@ class Delegate
211211
* @param index The index of the action to be returned. It is assumed that actions are indexable from 0 and with no gaps.
212212
* @param action A reference to the ActionStructStorage which should be initialized via copy/assignments or calling Set().
213213
* @return Returns a CHIP_NO_ERROR if there was no error and the action was returned successfully.
214-
* CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the index is past the end of the list of actionList.
214+
* CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the index is past the end of the list of actions.
215215
*/
216216
virtual CHIP_ERROR ReadActionAtIndex(uint16_t index, ActionStructStorage & action) = 0;
217217

218218
/**
219219
* Get the EndpointList at the Nth index from list of endpointList.
220-
* @param index The index of the endpointList to be returned. It is assumed that actions are indexable from 0 and with no gaps.
220+
* @param index The index of the endpointList to be returned. It is assumed that endpoint lists are indexable from 0 and with no
221+
* gaps.
221222
* @param action A reference to the EndpointListStorage which should be initialized via copy/assignments or calling Set().
222223
* @return Returns a CHIP_NO_ERROR if there was no error and the epList was returned successfully.
223224
* CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the index is past the end of the list of endpointLists.
@@ -233,132 +234,100 @@ class Delegate
233234

234235
/**
235236
* On receipt of each and every command,
236-
* if the InvokeID data field is provided by the client when invoking a command, the server SHALL generate a StateChanged event
237-
* when the action changes to a new state or an ActionFailed event when execution of the action fails.
238-
*
239-
* If the command refers to an action which currently is not in a state where the command applies, a response SHALL be
240-
* generated with the Status::InvalidCommand.
237+
* the server shall generate a either StateChanged or ActionFailed event.
238+
* If the command is not supproted by the action, Status::InvalidCommand shall be reported.
241239
*/
242240

243241
/**
244-
* When an InstantAction command is received, an action (state change) on the involved endpoints shall trigger,
245-
* in a "fire and forget" manner. Afterwards, the action’s state SHALL be Inactive.
246-
*
242+
* @brief Delegate should implement a handler to InstantAction.
247243
* @param actionId The actionId of an action.
248-
* It should report Status::Success if successful and may report other Status codes if it fails
244+
* It should report Status::Success if successful and may report other Status codes if it fails.
249245
*/
250246
virtual Protocols::InteractionModel::Status HandleInstantAction(uint16_t actionId, Optional<uint32_t> invokeId) = 0;
251247

252248
/**
253-
* When an InstantActionWithTransition command is received, an action (state change) on the involved endpoints shall trigger,
254-
* with a specified time to transition from the current state to the new state. During the transition, the action’s state SHALL
255-
* be Active. Afterwards, the action’s state SHALL be Inactive.
256-
*
249+
* @brief Delegate should implement a handler to InstantActionWithTransition.
257250
* @param actionId The actionId of an action.
258251
* @param transitionTime The time for transition from the current state to the new state.
259-
* It should report Status::Success if successful and may report other Status codes if it fails
252+
* It should report Status::Success if successful and may report other Status codes if it fails.
260253
*/
261254
virtual Protocols::InteractionModel::Status HandleInstantActionWithTransition(uint16_t actionId, uint16_t transitionTime,
262255
Optional<uint32_t> invokeId) = 0;
263256

264257
/**
265-
* When a StartAction command is received, the commencement of an action on the involved endpoints shall trigger. Afterwards,
266-
* the action’s state SHALL be Inactive.
267-
*
258+
* @brief Delegate should implement a handler to StartAction.
268259
* @param actionId The actionId of an action.
269-
* It should report Status::Success if successful and may report other Status codes if it fails
260+
* It should report Status::Success if successful and may report other Status codes if it fails.
270261
*/
271262
virtual Protocols::InteractionModel::Status HandleStartAction(uint16_t actionId, Optional<uint32_t> invokeId) = 0;
272263

273264
/**
274-
* When a StartActionWithDuration command is received, the commencement of an action on the involved endpoints shall trigger,
275-
* and SHALL change the action’s state to Active. After the specified Duration, the action will stop, and the action’s state
276-
* SHALL change to Inactive.
277-
*
265+
* @brief Delegate should implement a handler to StartActionWithDuration.
278266
* @param actionId The actionId of an action.
279267
* @param duration The time for which an action shall be in start state.
280-
* It should report Status::Success if successful and may report other Status codes if it fails
268+
* It should report Status::Success if successful and may report other Status codes if it fails.
281269
*/
282270
virtual Protocols::InteractionModel::Status HandleStartActionWithDuration(uint16_t actionId, uint32_t duration,
283271
Optional<uint32_t> invokeId) = 0;
284272

285273
/**
286-
* When a StopAction command is received, the ongoing action on the involved endpoints shall stop. Afterwards, the action’s
287-
* state SHALL be Inactive.
288-
*
274+
* @brief Delegate should implement a handler to StopAction.
289275
* @param actionId The actionId of an action.
290-
* It should report Status::Success if successful and may report other Status codes if it fails
276+
* It should report Status::Success if successful and may report other Status codes if it fails.
291277
*/
292278
virtual Protocols::InteractionModel::Status HandleStopAction(uint16_t actionId, Optional<uint32_t> invokeId) = 0;
293279

294280
/**
295-
* When a PauseAction command is received, the ongoing action on the involved endpoints shall pause and SHALL change the
296-
* action’s state to Paused.
297-
*
281+
* @brief Delegate should implement a handler to PauseAction.
298282
* @param actionId The actionId of an action.
299-
* It should report Status::Success if successful and may report other Status codes if it fails
283+
* It should report Status::Success if successful and may report other Status codes if it fails.
300284
*/
301285
virtual Protocols::InteractionModel::Status HandlePauseAction(uint16_t actionId, Optional<uint32_t> invokeId) = 0;
302286

303287
/**
304-
* When a PauseActionWithDuration command is received, pauses an ongoing action, and SHALL change the action’s state to Paused.
305-
* After the specified Duration, the ongoing action will be automatically resumed. which SHALL change the action’s state to
306-
* Active.
307-
*
288+
* @brief Delegate should implement a handler to PauseActionWithDuration.
308289
* @param actionId The actionId of an action.
309290
* @param duration The time for which an action shall be in pause state.
310-
* It should report Status::Success if successful and may report other Status codes if it fails
291+
* It should report Status::Success if successful and may report other Status codes if it fails.
311292
*/
312293
virtual Protocols::InteractionModel::Status HandlePauseActionWithDuration(uint16_t actionId, uint32_t duration,
313294
Optional<uint32_t> invokeId) = 0;
314295

315296
/**
316-
* When a ResumeAction command is received, the previously paused action shall resume and SHALL change the action’s state to
317-
* Active.
318-
*
297+
* @brief Delegate should implement a handler to ResumeAction.
319298
* @param actionId The actionId of an action.
320-
* It should report Status::Success if successful and may report other Status codes if it fails
299+
* It should report Status::Success if successful and may report other Status codes if it fails.
321300
*/
322301
virtual Protocols::InteractionModel::Status HandleResumeAction(uint16_t actionId, Optional<uint32_t> invokeId) = 0;
323302

324303
/**
325-
* When an EnableAction command is received, it enables a certain action or automation. Afterwards, the action’s state SHALL be
326-
* Active.
327-
*
304+
* @brief Delegate should implement a handler to EnableAction.
328305
* @param actionId The actionId of an action.
329-
* It should report Status::Success if successful and may report other Status codes if it fails
306+
* It should report Status::Success if successful and may report other Status codes if it fails.
330307
*/
331308
virtual Protocols::InteractionModel::Status HandleEnableAction(uint16_t actionId, Optional<uint32_t> invokeId) = 0;
332309

333310
/**
334-
* When an EnableActionWithDuration command is received, it enables a certain action or automation, and SHALL change the
335-
* action’s state to be Active. After the specified Duration, the action or automation will stop, and the action’s state SHALL
336-
* change to Disabled.
337-
*
311+
* @brief Delegate should implement a handler to EnableActionWithDuration.
338312
* @param actionId The actionId of an action.
339313
* @param duration The time for which an action shall be in active state.
340-
* It should report Status::Success if successful and may report other Status codes if it fails
314+
* It should report Status::Success if successful and may report other Status codes if it fails.
341315
*/
342316
virtual Protocols::InteractionModel::Status HandleEnableActionWithDuration(uint16_t actionId, uint32_t duration,
343317
Optional<uint32_t> invokeId) = 0;
344318

345319
/**
346-
* When a DisableAction command is received, it disables a certain action or automation, and SHALL change the action’s state to
347-
* Inactive.
348-
*
320+
* @brief Delegate should implement a handler to DisableAction.
349321
* @param actionId The actionId of an action.
350-
* It should report Status::Success if successful and may report other Status codes if it fails
322+
* It should report Status::Success if successful and may report other Status codes if it fails.
351323
*/
352324
virtual Protocols::InteractionModel::Status HandleDisableAction(uint16_t actionId, Optional<uint32_t> invokeId) = 0;
353325

354326
/**
355-
* When a DisableActionWithDuration command is received, it disables a certain action or automation, and SHALL change the
356-
* action’s state to Disabled. After the specified Duration, the action or automation will re-start, and the action’s state
357-
* SHALL change to either Inactive or Active, depending on the actions.
358-
*
327+
* @brief Delegate should implement a handler to DisableActionWithDuration.
359328
* @param actionId The actionId of an action.
360329
* @param duration The time for which an action shall be in disable state.
361-
* It should report Status::Success if successful and may report other Status codes if it fails
330+
* It should report Status::Success if successful and may report other Status codes if it fails.
362331
*/
363332
virtual Protocols::InteractionModel::Status HandleDisableActionWithDuration(uint16_t actionId, uint32_t duration,
364333
Optional<uint32_t> invokeId) = 0;

0 commit comments

Comments
 (0)