Skip to content

Commit

Permalink
Use GetAccessingFabricIndex in a few more places. (#13395)
Browse files Browse the repository at this point in the history
People keep copy/pasting the
GetExchangeContext()->GetSessionHandle()->AsSecureSession()->GetFabricIndex()
when they really don't need it....
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jul 12, 2023
1 parent b262cf0 commit 2024137
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c
{
// TODO: This uses the current node as the provider to supply the OTA image. This can be configurable such that the provider
// supplying the response is not the provider supplying the OTA image.
FabricIndex fabricIndex = commandObj->GetExchangeContext()->GetSessionHandle()->AsSecureSession()->GetFabricIndex();
FabricIndex fabricIndex = commandObj->GetAccessingFabricIndex();
FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(fabricIndex);
NodeId nodeId = fabricInfo->GetPeerId().GetNodeId();

Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/ota-requestor/OTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ EmberAfStatus OTARequestor::HandleAnnounceOTAProvider(app::CommandHandler * comm
}

mProviderNodeId = providerNodeId;
mProviderFabricIndex = commandObj->GetExchangeContext()->GetSessionHandle()->AsSecureSession()->GetFabricIndex();
mProviderFabricIndex = commandObj->GetAccessingFabricIndex();
mProviderEndpointId = providerEndpoint;

ChipLogProgress(SoftwareUpdate, "OTA Requestor received AnnounceOTAProvider");
Expand Down
21 changes: 7 additions & 14 deletions src/app/clusters/scenes/scenes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ uint8_t emberAfPluginScenesServerEntriesInUse = 0;
EmberAfSceneTableEntry emberAfPluginScenesServerSceneTable[EMBER_AF_PLUGIN_SCENES_TABLE_SIZE];
#endif

static FabricIndex GetFabricIndex(app::CommandHandler * commandObj)
{
VerifyOrReturnError(nullptr != commandObj, 0);
VerifyOrReturnError(nullptr != commandObj->GetExchangeContext(), 0);
return commandObj->GetExchangeContext()->GetSessionHandle()->AsSecureSession()->GetFabricIndex();
}

static bool readServerAttribute(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId, const char * name,
uint8_t * data, uint8_t size)
{
Expand Down Expand Up @@ -252,7 +245,7 @@ bool emberAfScenesClusterViewSceneCallback(app::CommandHandler * commandObj, con
bool emberAfScenesClusterRemoveSceneCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
const Commands::RemoveScene::DecodableType & commandData)
{
auto fabricIndex = GetFabricIndex(commandObj);
auto fabricIndex = commandObj->GetAccessingFabricIndex();
auto & groupId = commandData.groupId;
auto & sceneId = commandData.sceneId;

Expand Down Expand Up @@ -311,7 +304,7 @@ bool emberAfScenesClusterRemoveSceneCallback(app::CommandHandler * commandObj, c
bool emberAfScenesClusterRemoveAllScenesCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
const Commands::RemoveAllScenes::DecodableType & commandData)
{
auto fabricIndex = GetFabricIndex(commandObj);
auto fabricIndex = commandObj->GetAccessingFabricIndex();
auto & groupId = commandData.groupId;

EmberAfStatus status = EMBER_ZCL_STATUS_INVALID_FIELD;
Expand Down Expand Up @@ -363,7 +356,7 @@ bool emberAfScenesClusterRemoveAllScenesCallback(app::CommandHandler * commandOb
bool emberAfScenesClusterStoreSceneCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
const Commands::StoreScene::DecodableType & commandData)
{
auto fabricIndex = GetFabricIndex(commandObj);
auto fabricIndex = commandObj->GetAccessingFabricIndex();
auto & groupId = commandData.groupId;
auto & sceneId = commandData.sceneId;

Expand Down Expand Up @@ -399,7 +392,7 @@ bool emberAfScenesClusterStoreSceneCallback(app::CommandHandler * commandObj, co
bool emberAfScenesClusterRecallSceneCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
const Commands::RecallScene::DecodableType & commandData)
{
auto fabricIndex = GetFabricIndex(commandObj);
auto fabricIndex = commandObj->GetAccessingFabricIndex();
auto & groupId = commandData.groupId;
auto & sceneId = commandData.sceneId;

Expand Down Expand Up @@ -437,7 +430,7 @@ bool emberAfScenesClusterRecallSceneCallback(app::CommandHandler * commandObj, c
bool emberAfScenesClusterGetSceneMembershipCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
const Commands::GetSceneMembership::DecodableType & commandData)
{
auto fabricIndex = GetFabricIndex(commandObj);
auto fabricIndex = commandObj->GetAccessingFabricIndex();
auto & groupId = commandData.groupId;

CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down Expand Up @@ -768,7 +761,7 @@ bool emberAfPluginScenesServerParseAddScene(
EmberAfSceneTableEntry entry;
EmberAfStatus status;
bool enhanced = (cmd->commandId == ZCL_ENHANCED_ADD_SCENE_COMMAND_ID);
auto fabricIndex = GetFabricIndex(commandObj);
auto fabricIndex = commandObj->GetAccessingFabricIndex();
EndpointId endpoint = cmd->apsFrame->destinationEndpoint;
uint8_t i, index = EMBER_AF_SCENE_TABLE_NULL_INDEX;

Expand Down Expand Up @@ -1105,7 +1098,7 @@ bool emberAfPluginScenesServerParseViewScene(app::CommandHandler * commandObj, c
EmberAfSceneTableEntry entry = {};
EmberAfStatus status = EMBER_ZCL_STATUS_NOT_FOUND;
bool enhanced = (cmd->commandId == ZCL_ENHANCED_VIEW_SCENE_COMMAND_ID);
FabricIndex fabricIndex = GetFabricIndex(commandObj);
FabricIndex fabricIndex = commandObj->GetAccessingFabricIndex();
EndpointId endpoint = cmd->apsFrame->destinationEndpoint;

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

0 comments on commit 2024137

Please sign in to comment.