Skip to content

Commit 1743379

Browse files
lpbeliveau-silabsbzbarsky-apple
authored andcommitted
Scenes: emberAfCurrentCommand and emberAfCurrentEndpoint removal (#25136)
* Removed use of emberAfCurrentCommand and emberAfCurrentEndpoint in scenes.cpp * Restyled by clang-format * Fix build. --------- Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent e0298a8 commit 1743379

File tree

2 files changed

+66
-97
lines changed

2 files changed

+66
-97
lines changed

src/app/clusters/scenes/scenes.cpp

+61-93
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ bool emberAfScenesClusterAddSceneCallback(app::CommandHandler * commandObj, cons
231231
auto & sceneName = commandData.sceneName;
232232
auto & extensionFieldSets = commandData.extensionFieldSets;
233233

234-
return emberAfPluginScenesServerParseAddScene(commandObj, emberAfCurrentCommand(), groupId, sceneId, transitionTime, sceneName,
234+
return emberAfPluginScenesServerParseAddScene(commandObj, commandPath, groupId, sceneId, transitionTime, sceneName,
235235
extensionFieldSets);
236236
}
237237

@@ -241,7 +241,7 @@ bool emberAfScenesClusterViewSceneCallback(app::CommandHandler * commandObj, con
241241
auto & groupId = commandData.groupID;
242242
auto & sceneId = commandData.sceneID;
243243

244-
return emberAfPluginScenesServerParseViewScene(commandObj, emberAfCurrentCommand(), groupId, sceneId);
244+
return emberAfPluginScenesServerParseViewScene(commandObj, commandPath, groupId, sceneId);
245245
}
246246

247247
bool emberAfScenesClusterRemoveSceneCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
@@ -256,7 +256,7 @@ bool emberAfScenesClusterRemoveSceneCallback(app::CommandHandler * commandObj, c
256256

257257
emberAfScenesClusterPrintln("RX: RemoveScene 0x%2x, 0x%x", groupId, sceneId);
258258

259-
if (!isEndpointInGroup(fabricIndex, emberAfCurrentEndpoint(), groupId))
259+
if (!isEndpointInGroup(fabricIndex, commandPath.mEndpointId, groupId))
260260
{
261261
status = EMBER_ZCL_STATUS_INVALID_COMMAND;
262262
}
@@ -267,33 +267,27 @@ bool emberAfScenesClusterRemoveSceneCallback(app::CommandHandler * commandObj, c
267267
{
268268
EmberAfSceneTableEntry entry;
269269
emberAfPluginScenesServerRetrieveSceneEntry(entry, i);
270-
if (entry.endpoint == emberAfCurrentEndpoint() && entry.groupId == groupId && entry.sceneId == sceneId)
270+
if (entry.endpoint == commandPath.mEndpointId && entry.groupId == groupId && entry.sceneId == sceneId)
271271
{
272272
entry.endpoint = EMBER_AF_SCENE_TABLE_UNUSED_ENDPOINT_ID;
273273
emberAfPluginScenesServerSaveSceneEntry(entry, i);
274274
emberAfPluginScenesServerDecrNumSceneEntriesInUse();
275-
emberAfScenesSetSceneCountAttribute(emberAfCurrentEndpoint(), emberAfPluginScenesServerNumSceneEntriesInUse());
275+
emberAfScenesSetSceneCountAttribute(commandPath.mEndpointId, emberAfPluginScenesServerNumSceneEntriesInUse());
276276
status = EMBER_ZCL_STATUS_SUCCESS;
277277
break;
278278
}
279279
}
280280
}
281281

282-
// Remove Scene commands are only responded to when they are addressed to a
283-
// single device.
284-
if (emberAfCurrentCommand()->type == EMBER_INCOMING_UNICAST || emberAfCurrentCommand()->type == EMBER_INCOMING_UNICAST_REPLY)
285-
{
286-
{
287-
app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), Scenes::Id, RemoveSceneResponse::Id };
288-
TLV::TLVWriter * writer = nullptr;
289-
SuccessOrExit(err = commandObj->PrepareCommand(path));
290-
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
291-
SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status));
292-
SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId));
293-
SuccessOrExit(err = writer->Put(TLV::ContextTag(2), sceneId));
294-
SuccessOrExit(err = commandObj->FinishCommand());
295-
}
296-
}
282+
app::ConcreteCommandPath path = { commandPath.mEndpointId, Scenes::Id, RemoveSceneResponse::Id };
283+
TLV::TLVWriter * writer = nullptr;
284+
SuccessOrExit(err = commandObj->PrepareCommand(path));
285+
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
286+
SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status));
287+
SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId));
288+
SuccessOrExit(err = writer->Put(TLV::ContextTag(2), sceneId));
289+
SuccessOrExit(err = commandObj->FinishCommand());
290+
297291
exit:
298292
if (err != CHIP_NO_ERROR)
299293
{
@@ -313,38 +307,31 @@ bool emberAfScenesClusterRemoveAllScenesCallback(app::CommandHandler * commandOb
313307

314308
emberAfScenesClusterPrintln("RX: RemoveAllScenes 0x%2x", groupId);
315309

316-
if (isEndpointInGroup(fabricIndex, emberAfCurrentEndpoint(), groupId))
310+
if (isEndpointInGroup(fabricIndex, commandPath.mEndpointId, groupId))
317311
{
318312
uint8_t i;
319313
status = EMBER_ZCL_STATUS_SUCCESS;
320314
for (i = 0; i < MATTER_SCENES_TABLE_SIZE; i++)
321315
{
322316
EmberAfSceneTableEntry entry;
323317
emberAfPluginScenesServerRetrieveSceneEntry(entry, i);
324-
if (entry.endpoint == emberAfCurrentEndpoint() && entry.groupId == groupId)
318+
if (entry.endpoint == commandPath.mEndpointId && entry.groupId == groupId)
325319
{
326320
entry.endpoint = EMBER_AF_SCENE_TABLE_UNUSED_ENDPOINT_ID;
327321
emberAfPluginScenesServerSaveSceneEntry(entry, i);
328322
emberAfPluginScenesServerDecrNumSceneEntriesInUse();
329323
}
330324
}
331-
emberAfScenesSetSceneCountAttribute(emberAfCurrentEndpoint(), emberAfPluginScenesServerNumSceneEntriesInUse());
325+
emberAfScenesSetSceneCountAttribute(commandPath.mEndpointId, emberAfPluginScenesServerNumSceneEntriesInUse());
332326
}
333327

334-
// Remove All Scenes commands are only responded to when they are addressed
335-
// to a single device.
336-
if (emberAfCurrentCommand()->type == EMBER_INCOMING_UNICAST || emberAfCurrentCommand()->type == EMBER_INCOMING_UNICAST_REPLY)
337-
{
338-
{
339-
app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), Scenes::Id, RemoveAllScenesResponse::Id };
340-
TLV::TLVWriter * writer = nullptr;
341-
SuccessOrExit(err = commandObj->PrepareCommand(path));
342-
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
343-
SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status));
344-
SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId));
345-
SuccessOrExit(err = commandObj->FinishCommand());
346-
}
347-
}
328+
app::ConcreteCommandPath path = { commandPath.mEndpointId, Scenes::Id, RemoveAllScenesResponse::Id };
329+
TLV::TLVWriter * writer = nullptr;
330+
SuccessOrExit(err = commandObj->PrepareCommand(path));
331+
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
332+
SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status));
333+
SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId));
334+
SuccessOrExit(err = commandObj->FinishCommand());
348335
exit:
349336
if (err != CHIP_NO_ERROR)
350337
{
@@ -363,23 +350,16 @@ bool emberAfScenesClusterStoreSceneCallback(app::CommandHandler * commandObj, co
363350
EmberAfStatus status;
364351
CHIP_ERROR err = CHIP_NO_ERROR;
365352
emberAfScenesClusterPrintln("RX: StoreScene 0x%2x, 0x%x", groupId, sceneId);
366-
status = emberAfScenesClusterStoreCurrentSceneCallback(fabricIndex, emberAfCurrentEndpoint(), groupId, sceneId);
353+
status = emberAfScenesClusterStoreCurrentSceneCallback(fabricIndex, commandPath.mEndpointId, groupId, sceneId);
367354

368-
// Store Scene commands are only responded to when they are addressed to a
369-
// single device.
370-
if (emberAfCurrentCommand()->type == EMBER_INCOMING_UNICAST || emberAfCurrentCommand()->type == EMBER_INCOMING_UNICAST_REPLY)
371-
{
372-
{
373-
app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), Scenes::Id, StoreSceneResponse::Id };
374-
TLV::TLVWriter * writer = nullptr;
375-
SuccessOrExit(err = commandObj->PrepareCommand(path));
376-
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
377-
SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status));
378-
SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId));
379-
SuccessOrExit(err = writer->Put(TLV::ContextTag(2), sceneId));
380-
SuccessOrExit(err = commandObj->FinishCommand());
381-
}
382-
}
355+
app::ConcreteCommandPath path = { commandPath.mEndpointId, Scenes::Id, StoreSceneResponse::Id };
356+
TLV::TLVWriter * writer = nullptr;
357+
SuccessOrExit(err = commandObj->PrepareCommand(path));
358+
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
359+
SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status));
360+
SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId));
361+
SuccessOrExit(err = writer->Put(TLV::ContextTag(2), sceneId));
362+
SuccessOrExit(err = commandObj->FinishCommand());
383363
exit:
384364
if (err != CHIP_NO_ERROR)
385365
{
@@ -410,11 +390,11 @@ bool emberAfScenesClusterRecallSceneCallback(app::CommandHandler * commandObj, c
410390

411391
EmberAfStatus status;
412392
emberAfScenesClusterPrintln("RX: RecallScene 0x%2x, 0x%x", groupId, sceneId);
413-
status = emberAfScenesClusterRecallSavedSceneCallback(fabricIndex, emberAfCurrentEndpoint(), groupId, sceneId);
393+
status = emberAfScenesClusterRecallSavedSceneCallback(fabricIndex, commandPath.mEndpointId, groupId, sceneId);
414394
#ifdef EMBER_AF_PLUGIN_ZLL_SCENES_SERVER
415395
if (status == EMBER_ZCL_STATUS_SUCCESS)
416396
{
417-
emberAfPluginZllScenesServerRecallSceneZllExtensions(emberAfCurrentEndpoint());
397+
emberAfPluginZllScenesServerRecallSceneZllExtensions(commandPath.mEndpointId);
418398
}
419399
#endif
420400
CHIP_ERROR sendErr = commandObj->AddStatus(commandPath, app::ToInteractionModelStatus(status));
@@ -438,7 +418,7 @@ bool emberAfScenesClusterGetSceneMembershipCallback(app::CommandHandler * comman
438418

439419
emberAfScenesClusterPrintln("RX: GetSceneMembership 0x%2x", groupId);
440420

441-
if (!isEndpointInGroup(fabricIndex, emberAfCurrentEndpoint(), groupId))
421+
if (!isEndpointInGroup(fabricIndex, commandPath.mEndpointId, groupId))
442422
{
443423
status = EMBER_ZCL_STATUS_INVALID_COMMAND;
444424
}
@@ -450,7 +430,7 @@ bool emberAfScenesClusterGetSceneMembershipCallback(app::CommandHandler * comman
450430
{
451431
EmberAfSceneTableEntry entry;
452432
emberAfPluginScenesServerRetrieveSceneEntry(entry, i);
453-
if (entry.endpoint == emberAfCurrentEndpoint() && entry.groupId == groupId)
433+
if (entry.endpoint == commandPath.mEndpointId && entry.groupId == groupId)
454434
{
455435
sceneList[sceneCount] = entry.sceneId;
456436
sceneCount++;
@@ -464,7 +444,7 @@ bool emberAfScenesClusterGetSceneMembershipCallback(app::CommandHandler * comman
464444
}
465445

466446
{
467-
app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), Scenes::Id, GetSceneMembershipResponse::Id };
447+
app::ConcreteCommandPath path = { commandPath.mEndpointId, Scenes::Id, GetSceneMembershipResponse::Id };
468448
TLV::TLVWriter * writer = nullptr;
469449
SuccessOrExit(err = commandObj->PrepareCommand(path));
470450
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
@@ -738,15 +718,16 @@ struct NullableUnderlyingType<app::DataModel::Nullable<T>>
738718
};
739719

740720
bool emberAfPluginScenesServerParseAddScene(
741-
app::CommandHandler * commandObj, const EmberAfClusterCommand * cmd, GroupId groupId, uint8_t sceneId, uint16_t transitionTime,
742-
const CharSpan & sceneName, const app::DataModel::DecodableList<Structs::ExtensionFieldSet::DecodableType> & extensionFieldSets)
721+
app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, GroupId groupId, uint8_t sceneId,
722+
uint16_t transitionTime, const CharSpan & sceneName,
723+
const app::DataModel::DecodableList<Structs::ExtensionFieldSet::DecodableType> & extensionFieldSets)
743724
{
744725
CHIP_ERROR err = CHIP_NO_ERROR;
745726
EmberAfSceneTableEntry entry;
746727
EmberAfStatus status;
747-
bool enhanced = (cmd->commandId == EnhancedAddScene::Id);
728+
bool enhanced = (commandPath.mCommandId == EnhancedAddScene::Id);
748729
auto fabricIndex = commandObj->GetAccessingFabricIndex();
749-
EndpointId endpoint = cmd->apsFrame->destinationEndpoint;
730+
EndpointId endpoint = commandPath.mEndpointId;
750731
uint8_t i, index = EMBER_AF_SCENE_TABLE_NULL_INDEX;
751732

752733
emberAfScenesClusterPrintln("RX: %pAddScene 0x%2x, 0x%x, 0x%2x, \"%.*s\"", (enhanced ? "Enhanced" : ""), groupId, sceneId,
@@ -1104,26 +1085,19 @@ bool emberAfPluginScenesServerParseAddScene(
11041085
status = EMBER_ZCL_STATUS_SUCCESS;
11051086

11061087
kickout:
1107-
// Add Scene commands are only responded to when they are addressed to a
1108-
// single device.
1109-
if (emberAfCurrentCommand()->type != EMBER_INCOMING_UNICAST && emberAfCurrentCommand()->type != EMBER_INCOMING_UNICAST_REPLY)
1110-
{
1111-
return true;
1112-
}
1088+
1089+
app::ConcreteCommandPath path = { commandPath.mEndpointId, Scenes::Id, AddSceneResponse::Id };
1090+
if (enhanced)
11131091
{
1114-
app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), Scenes::Id, AddSceneResponse::Id };
1115-
if (enhanced)
1116-
{
1117-
path = { emberAfCurrentEndpoint(), Scenes::Id, EnhancedAddSceneResponse::Id };
1118-
}
1119-
TLV::TLVWriter * writer = nullptr;
1120-
SuccessOrExit(err = commandObj->PrepareCommand(path));
1121-
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
1122-
SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status));
1123-
SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId));
1124-
SuccessOrExit(err = writer->Put(TLV::ContextTag(2), sceneId));
1125-
SuccessOrExit(err = commandObj->FinishCommand());
1092+
path = { commandPath.mEndpointId, Scenes::Id, EnhancedAddSceneResponse::Id };
11261093
}
1094+
TLV::TLVWriter * writer = nullptr;
1095+
SuccessOrExit(err = commandObj->PrepareCommand(path));
1096+
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
1097+
SuccessOrExit(err = writer->Put(TLV::ContextTag(0), status));
1098+
SuccessOrExit(err = writer->Put(TLV::ContextTag(1), groupId));
1099+
SuccessOrExit(err = writer->Put(TLV::ContextTag(2), sceneId));
1100+
SuccessOrExit(err = commandObj->FinishCommand());
11271101

11281102
exit:
11291103
if (err != CHIP_NO_ERROR)
@@ -1133,15 +1107,15 @@ bool emberAfPluginScenesServerParseAddScene(
11331107
return true;
11341108
}
11351109

1136-
bool emberAfPluginScenesServerParseViewScene(app::CommandHandler * commandObj, const EmberAfClusterCommand * cmd, GroupId groupId,
1137-
uint8_t sceneId)
1110+
bool emberAfPluginScenesServerParseViewScene(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
1111+
GroupId groupId, uint8_t sceneId)
11381112
{
11391113
CHIP_ERROR err = CHIP_NO_ERROR;
11401114
EmberAfSceneTableEntry entry = {};
11411115
EmberAfStatus status = EMBER_ZCL_STATUS_NOT_FOUND;
1142-
bool enhanced = (cmd->commandId == EnhancedViewScene::Id);
1116+
bool enhanced = (commandPath.mCommandId == EnhancedViewScene::Id);
11431117
FabricIndex fabricIndex = commandObj->GetAccessingFabricIndex();
1144-
EndpointId endpoint = cmd->apsFrame->destinationEndpoint;
1118+
EndpointId endpoint = commandPath.mEndpointId;
11451119

11461120
emberAfScenesClusterPrintln("RX: %pViewScene 0x%2x, 0x%x", (enhanced ? "Enhanced" : ""), groupId, sceneId);
11471121

@@ -1167,10 +1141,10 @@ bool emberAfPluginScenesServerParseViewScene(app::CommandHandler * commandObj, c
11671141
// The status, group id, and scene id are always included in the response, but
11681142
// the transition time, name, and extension fields are only included if the
11691143
// scene was found.
1170-
app::ConcreteCommandPath path = { emberAfCurrentEndpoint(), Scenes::Id, ViewSceneResponse::Id };
1144+
app::ConcreteCommandPath path = { commandPath.mEndpointId, Scenes::Id, ViewSceneResponse::Id };
11711145
if (enhanced)
11721146
{
1173-
path = { emberAfCurrentEndpoint(), Scenes::Id, EnhancedViewSceneResponse::Id };
1147+
path = { commandPath.mEndpointId, Scenes::Id, EnhancedViewSceneResponse::Id };
11741148
}
11751149
TLV::TLVWriter * writer = nullptr;
11761150
SuccessOrExit(err = commandObj->PrepareCommand(path));
@@ -1324,12 +1298,6 @@ bool emberAfPluginScenesServerParseViewScene(app::CommandHandler * commandObj, c
13241298
#endif
13251299
}
13261300
1327-
// View Scene commands are only responded to when they are addressed to a
1328-
// single device.
1329-
if (emberAfCurrentCommand()->type != EMBER_INCOMING_UNICAST && emberAfCurrentCommand()->type != EMBER_INCOMING_UNICAST_REPLY)
1330-
{
1331-
return true;
1332-
}
13331301
sendStatus = emberAfSendResponse();
13341302
if (EMBER_SUCCESS != sendStatus)
13351303
{
@@ -1358,7 +1326,7 @@ void emberAfScenesClusterRemoveScenesInGroupCallback(EndpointId endpoint, GroupI
13581326
entry.endpoint = EMBER_AF_SCENE_TABLE_UNUSED_ENDPOINT_ID;
13591327
emberAfPluginScenesServerSaveSceneEntry(entry, i);
13601328
emberAfPluginScenesServerDecrNumSceneEntriesInUse();
1361-
emberAfScenesSetSceneCountAttribute(emberAfCurrentEndpoint(), emberAfPluginScenesServerNumSceneEntriesInUse());
1329+
emberAfScenesSetSceneCountAttribute(endpoint, emberAfPluginScenesServerNumSceneEntriesInUse());
13621330
}
13631331
}
13641332
}

src/app/clusters/scenes/scenes.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ extern EmberAfSceneTableEntry emberAfPluginScenesServerSceneTable[];
6262
#endif // Use tokens
6363

6464
bool emberAfPluginScenesServerParseAddScene(
65-
chip::app::CommandHandler * commandObj, const EmberAfClusterCommand * cmd, chip::GroupId groupId, uint8_t sceneId,
66-
uint16_t transitionTime, const chip::CharSpan & sceneName,
65+
chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, chip::GroupId groupId,
66+
uint8_t sceneId, uint16_t transitionTime, const chip::CharSpan & sceneName,
6767
const chip::app::DataModel::DecodableList<chip::app::Clusters::Scenes::Structs::ExtensionFieldSet::DecodableType> &
6868
extensionFieldSets);
69-
bool emberAfPluginScenesServerParseViewScene(chip::app::CommandHandler * commandObj, const EmberAfClusterCommand * cmd,
70-
chip::GroupId groupId, uint8_t sceneId);
69+
bool emberAfPluginScenesServerParseViewScene(chip::app::CommandHandler * commandObj,
70+
const chip::app::ConcreteCommandPath & commandPath, chip::GroupId groupId,
71+
uint8_t sceneId);
7172

7273
/** @brief Scenes Cluster Recall Saved Scene
7374
*

0 commit comments

Comments
 (0)