Skip to content

Commit

Permalink
tv-casting-app: On kBindingsChangedViaCluster during UDC, pick out no…
Browse files Browse the repository at this point in the history
…deId of video player from BindingTable
  • Loading branch information
sharadb-amazon committed Jan 27, 2023
1 parent 21b19a9 commit a3dbb24
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
58 changes: 29 additions & 29 deletions examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,40 +351,40 @@ void CastingServer::DeviceEventCallback(const DeviceLayer::ChipDeviceEvent * eve
else if (CastingServer::GetInstance()->mUdcInProgress)
{
ChipLogProgress(AppServer,
"CastingServer::DeviceEventCallback UDC is in progress while handling kBindingsChangedViaCluster");
"CastingServer::DeviceEventCallback UDC is in progress while handling kBindingsChangedViaCluster with "
"fabricIndex: %d",
event->BindingsChanged.fabricIndex);
CastingServer::GetInstance()->mUdcInProgress = false;
if (CastingServer::GetInstance()->mTargetVideoPlayerNumIPs > 0)
{
TargetVideoPlayerInfo * connectableVideoPlayerList =
CastingServer::GetInstance()->ReadCachedTargetVideoPlayerInfos();
if (connectableVideoPlayerList == nullptr || !connectableVideoPlayerList[0].IsInitialized())
{
ChipLogError(AppServer, "CastingServer::DeviceEventCallback No cached video players found");
CastingServer::GetInstance()->mCommissioningCompleteCallback(CHIP_ERROR_INCORRECT_STATE);
return;
}

for (size_t i = 0; i < kMaxCachedVideoPlayers && connectableVideoPlayerList[i].IsInitialized(); i++)
// find targetPeerNodeId from binding table by matching the binding's fabricIndex with the accessing fabricIndex
// received in BindingsChanged event
for (const auto & binding : BindingTable::GetInstance())
{
ChipLogProgress(
AppServer,
"CastingServer::DeviceEventCallback Read cached binding type=%d fabrixIndex=%d nodeId=0x" ChipLogFormatX64
" groupId=%d local endpoint=%d remote endpoint=%d cluster=" ChipLogFormatMEI,
binding.type, binding.fabricIndex, ChipLogValueX64(binding.nodeId), binding.groupId, binding.local,
binding.remote, ChipLogValueMEI(binding.clusterId.ValueOr(0)));
if (binding.type == EMBER_UNICAST_BINDING && event->BindingsChanged.fabricIndex == binding.fabricIndex)
{
if (connectableVideoPlayerList[i].IsSameAs(CastingServer::GetInstance()->mTargetVideoPlayerDeviceName,
CastingServer::GetInstance()->mTargetVideoPlayerNumIPs,
CastingServer::GetInstance()->mTargetVideoPlayerIpAddress))
{
ChipLogProgress(AppServer,
"CastingServer::DeviceEventCallback found the video player to initialize/connect to");
targetPeerNodeId = connectableVideoPlayerList[i].GetNodeId();
targetFabricIndex = connectableVideoPlayerList[i].GetFabricIndex();
runPostCommissioning = true;
}
ChipLogProgress(
NotSpecified,
"CastingServer::DeviceEventCallback Matched accessingFabricIndex with nodeId=0x" ChipLogFormatX64,
ChipLogValueX64(binding.nodeId));
targetPeerNodeId = binding.nodeId;
targetFabricIndex = binding.fabricIndex;
runPostCommissioning = true;
break;
}
}

if (targetPeerNodeId == 0 && runPostCommissioning == false)
{
ChipLogError(AppServer,
"CastingServer::DeviceEventCallback did NOT find the video player to initialize/connect to");
CastingServer::GetInstance()->mCommissioningCompleteCallback(CHIP_ERROR_INCORRECT_STATE);
return;
}
if (targetPeerNodeId == 0 && runPostCommissioning == false)
{
ChipLogError(AppServer,
"CastingServer::DeviceEventCallback did NOT find the video player to initialize/connect to");
CastingServer::GetInstance()->mCommissioningCompleteCallback(CHIP_ERROR_INCORRECT_STATE);
return;
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/app/clusters/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class BindingTableAccess : public AttributeAccessInterface
CHIP_ERROR ReadBindingTable(EndpointId endpoint, AttributeValueEncoder & encoder);
CHIP_ERROR WriteBindingTable(const ConcreteDataAttributePath & path, AttributeValueDecoder & decoder);

CHIP_ERROR NotifyBindingsChanged();
CHIP_ERROR NotifyBindingsChanged(FabricIndex accessingFabricIndex = 0);
};

BindingTableAccess gAttrAccess;
Expand Down Expand Up @@ -233,7 +233,7 @@ CHIP_ERROR BindingTableAccess::WriteBindingTable(const ConcreteDataAttributePath
if (!path.IsListOperation())
{
// Notify binding table has changed
LogErrorOnFailure(NotifyBindingsChanged());
LogErrorOnFailure(NotifyBindingsChanged(accessingFabricIndex));
}
return CHIP_NO_ERROR;
}
Expand All @@ -251,10 +251,11 @@ CHIP_ERROR BindingTableAccess::WriteBindingTable(const ConcreteDataAttributePath
return CHIP_IM_GLOBAL_STATUS(UnsupportedWrite);
}

CHIP_ERROR BindingTableAccess::NotifyBindingsChanged()
CHIP_ERROR BindingTableAccess::NotifyBindingsChanged(FabricIndex accessingFabricIndex)
{
DeviceLayer::ChipDeviceEvent event;
event.Type = DeviceLayer::DeviceEventType::kBindingsChangedViaCluster;
event.Type = DeviceLayer::DeviceEventType::kBindingsChangedViaCluster;
event.BindingsChanged.fabricIndex = accessingFabricIndex;
return chip::DeviceLayer::PlatformMgr().PostEvent(&event);
}

Expand Down
4 changes: 4 additions & 0 deletions src/include/platform/CHIPDeviceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ struct ChipDeviceEvent final
uint64_t nodeId;
FabricIndex fabricIndex;
} CommissioningComplete;
struct
{
FabricIndex fabricIndex;
} BindingsChanged;

struct
{
Expand Down

0 comments on commit a3dbb24

Please sign in to comment.