Skip to content

Commit 2201922

Browse files
sharadb-amazonpull[bot]
authored andcommitted
On kBindingsChangedViaCluster during UDC, pick target video player's nodeID from BindingTable (#24706)
* tv-casting-app: On kBindingsChangedViaCluster during UDC, pick out nodeId of video player from BindingTable * Avoiding passing a default accessing fabricIndex * Setting mAccessingFabricIndex used in NotifyBindingsChanged() as data member of BindingTableAccess
1 parent fb84171 commit 2201922

File tree

3 files changed

+42
-34
lines changed

3 files changed

+42
-34
lines changed

examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp

+31-30
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ void CastingServer::DeviceEventCallback(const DeviceLayer::ChipDeviceEvent * eve
345345
if (event->Type == DeviceLayer::DeviceEventType::kBindingsChangedViaCluster)
346346
{
347347
ChipLogProgress(AppServer, "CastingServer::DeviceEventCallback kBindingsChangedViaCluster received");
348-
if (CastingServer::GetInstance()->GetActiveTargetVideoPlayer()->IsInitialized())
348+
if (CastingServer::GetInstance()->GetActiveTargetVideoPlayer()->IsInitialized() &&
349+
CastingServer::GetInstance()->GetActiveTargetVideoPlayer()->GetOperationalDeviceProxy() != nullptr)
349350
{
350351
ChipLogProgress(AppServer,
351352
"CastingServer::DeviceEventCallback already connected to video player, reading server clusters");
@@ -355,40 +356,40 @@ void CastingServer::DeviceEventCallback(const DeviceLayer::ChipDeviceEvent * eve
355356
else if (CastingServer::GetInstance()->mUdcInProgress)
356357
{
357358
ChipLogProgress(AppServer,
358-
"CastingServer::DeviceEventCallback UDC is in progress while handling kBindingsChangedViaCluster");
359+
"CastingServer::DeviceEventCallback UDC is in progress while handling kBindingsChangedViaCluster with "
360+
"fabricIndex: %d",
361+
event->BindingsChanged.fabricIndex);
359362
CastingServer::GetInstance()->mUdcInProgress = false;
360-
if (CastingServer::GetInstance()->mTargetVideoPlayerNumIPs > 0)
361-
{
362-
TargetVideoPlayerInfo * connectableVideoPlayerList =
363-
CastingServer::GetInstance()->ReadCachedTargetVideoPlayerInfos();
364-
if (connectableVideoPlayerList == nullptr || !connectableVideoPlayerList[0].IsInitialized())
365-
{
366-
ChipLogError(AppServer, "CastingServer::DeviceEventCallback No cached video players found");
367-
CastingServer::GetInstance()->mCommissioningCompleteCallback(CHIP_ERROR_INCORRECT_STATE);
368-
return;
369-
}
370363

371-
for (size_t i = 0; i < kMaxCachedVideoPlayers && connectableVideoPlayerList[i].IsInitialized(); i++)
364+
// find targetPeerNodeId from binding table by matching the binding's fabricIndex with the accessing fabricIndex
365+
// received in BindingsChanged event
366+
for (const auto & binding : BindingTable::GetInstance())
367+
{
368+
ChipLogProgress(
369+
AppServer,
370+
"CastingServer::DeviceEventCallback Read cached binding type=%d fabrixIndex=%d nodeId=0x" ChipLogFormatX64
371+
" groupId=%d local endpoint=%d remote endpoint=%d cluster=" ChipLogFormatMEI,
372+
binding.type, binding.fabricIndex, ChipLogValueX64(binding.nodeId), binding.groupId, binding.local,
373+
binding.remote, ChipLogValueMEI(binding.clusterId.ValueOr(0)));
374+
if (binding.type == EMBER_UNICAST_BINDING && event->BindingsChanged.fabricIndex == binding.fabricIndex)
372375
{
373-
if (connectableVideoPlayerList[i].IsSameAs(CastingServer::GetInstance()->mTargetVideoPlayerDeviceName,
374-
CastingServer::GetInstance()->mTargetVideoPlayerNumIPs,
375-
CastingServer::GetInstance()->mTargetVideoPlayerIpAddress))
376-
{
377-
ChipLogProgress(AppServer,
378-
"CastingServer::DeviceEventCallback found the video player to initialize/connect to");
379-
targetPeerNodeId = connectableVideoPlayerList[i].GetNodeId();
380-
targetFabricIndex = connectableVideoPlayerList[i].GetFabricIndex();
381-
runPostCommissioning = true;
382-
}
376+
ChipLogProgress(
377+
NotSpecified,
378+
"CastingServer::DeviceEventCallback Matched accessingFabricIndex with nodeId=0x" ChipLogFormatX64,
379+
ChipLogValueX64(binding.nodeId));
380+
targetPeerNodeId = binding.nodeId;
381+
targetFabricIndex = binding.fabricIndex;
382+
runPostCommissioning = true;
383+
break;
383384
}
385+
}
384386

385-
if (targetPeerNodeId == 0 && runPostCommissioning == false)
386-
{
387-
ChipLogError(AppServer,
388-
"CastingServer::DeviceEventCallback did NOT find the video player to initialize/connect to");
389-
CastingServer::GetInstance()->mCommissioningCompleteCallback(CHIP_ERROR_INCORRECT_STATE);
390-
return;
391-
}
387+
if (targetPeerNodeId == 0 && runPostCommissioning == false)
388+
{
389+
ChipLogError(AppServer, "CastingServer::DeviceEventCallback accessingFabricIndex: %d did not match bindings",
390+
event->BindingsChanged.fabricIndex);
391+
CastingServer::GetInstance()->mCommissioningCompleteCallback(CHIP_ERROR_INCORRECT_STATE);
392+
return;
392393
}
393394
}
394395
}

src/app/clusters/bindings/bindings.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class BindingTableAccess : public AttributeAccessInterface
5454
CHIP_ERROR WriteBindingTable(const ConcreteDataAttributePath & path, AttributeValueDecoder & decoder);
5555

5656
CHIP_ERROR NotifyBindingsChanged();
57+
58+
FabricIndex mAccessingFabricIndex;
5759
};
5860

5961
BindingTableAccess gAttrAccess;
@@ -196,19 +198,19 @@ void BindingTableAccess::OnListWriteEnd(const app::ConcreteAttributePath & aPath
196198

197199
CHIP_ERROR BindingTableAccess::WriteBindingTable(const ConcreteDataAttributePath & path, AttributeValueDecoder & decoder)
198200
{
199-
FabricIndex accessingFabricIndex = decoder.AccessingFabricIndex();
201+
mAccessingFabricIndex = decoder.AccessingFabricIndex();
200202
if (!path.IsListOperation() || path.mListOp == ConcreteDataAttributePath::ListOperation::ReplaceAll)
201203
{
202204
DecodableBindingListType newBindingList;
203205

204206
ReturnErrorOnFailure(decoder.Decode(newBindingList));
205-
ReturnErrorOnFailure(CheckValidBindingList(path.mEndpointId, newBindingList, accessingFabricIndex));
207+
ReturnErrorOnFailure(CheckValidBindingList(path.mEndpointId, newBindingList, mAccessingFabricIndex));
206208

207209
// Clear all entries for the current accessing fabric and endpoint
208210
auto bindingTableIter = BindingTable::GetInstance().begin();
209211
while (bindingTableIter != BindingTable::GetInstance().end())
210212
{
211-
if (bindingTableIter->local == path.mEndpointId && bindingTableIter->fabricIndex == accessingFabricIndex)
213+
if (bindingTableIter->local == path.mEndpointId && bindingTableIter->fabricIndex == mAccessingFabricIndex)
212214
{
213215
if (bindingTableIter->type == EMBER_UNICAST_BINDING)
214216
{
@@ -255,7 +257,8 @@ CHIP_ERROR BindingTableAccess::WriteBindingTable(const ConcreteDataAttributePath
255257
CHIP_ERROR BindingTableAccess::NotifyBindingsChanged()
256258
{
257259
DeviceLayer::ChipDeviceEvent event;
258-
event.Type = DeviceLayer::DeviceEventType::kBindingsChangedViaCluster;
260+
event.Type = DeviceLayer::DeviceEventType::kBindingsChangedViaCluster;
261+
event.BindingsChanged.fabricIndex = mAccessingFabricIndex;
259262
return chip::DeviceLayer::PlatformMgr().PostEvent(&event);
260263
}
261264

src/include/platform/CHIPDeviceEvent.h

+4
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,10 @@ struct ChipDeviceEvent final
494494
uint64_t nodeId;
495495
FabricIndex fabricIndex;
496496
} CommissioningComplete;
497+
struct
498+
{
499+
FabricIndex fabricIndex;
500+
} BindingsChanged;
497501

498502
struct
499503
{

0 commit comments

Comments
 (0)