Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On kBindingsChangedViaCluster during UDC, pick target video player's nodeID from BindingTable #24706

Merged
merged 3 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 31 additions & 30 deletions examples/tv-casting-app/tv-casting-common/src/CastingServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ void CastingServer::DeviceEventCallback(const DeviceLayer::ChipDeviceEvent * eve
if (event->Type == DeviceLayer::DeviceEventType::kBindingsChangedViaCluster)
{
ChipLogProgress(AppServer, "CastingServer::DeviceEventCallback kBindingsChangedViaCluster received");
if (CastingServer::GetInstance()->GetActiveTargetVideoPlayer()->IsInitialized())
if (CastingServer::GetInstance()->GetActiveTargetVideoPlayer()->IsInitialized() &&
CastingServer::GetInstance()->GetActiveTargetVideoPlayer()->GetOperationalDeviceProxy() != nullptr)
{
ChipLogProgress(AppServer,
"CastingServer::DeviceEventCallback already connected to video player, reading server clusters");
Expand All @@ -351,40 +352,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 accessingFabricIndex: %d did not match bindings",
event->BindingsChanged.fabricIndex);
CastingServer::GetInstance()->mCommissioningCompleteCallback(CHIP_ERROR_INCORRECT_STATE);
return;
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/app/clusters/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class BindingTableAccess : public AttributeAccessInterface
CHIP_ERROR WriteBindingTable(const ConcreteDataAttributePath & path, AttributeValueDecoder & decoder);

CHIP_ERROR NotifyBindingsChanged();

FabricIndex mAccessingFabricIndex;
};

BindingTableAccess gAttrAccess;
Expand Down Expand Up @@ -195,19 +197,19 @@ void BindingTableAccess::OnListWriteEnd(const app::ConcreteAttributePath & aPath

CHIP_ERROR BindingTableAccess::WriteBindingTable(const ConcreteDataAttributePath & path, AttributeValueDecoder & decoder)
{
FabricIndex accessingFabricIndex = decoder.AccessingFabricIndex();
mAccessingFabricIndex = decoder.AccessingFabricIndex();
if (!path.IsListOperation() || path.mListOp == ConcreteDataAttributePath::ListOperation::ReplaceAll)
{
DecodableBindingListType newBindingList;

ReturnErrorOnFailure(decoder.Decode(newBindingList));
ReturnErrorOnFailure(CheckValidBindingList(path.mEndpointId, newBindingList, accessingFabricIndex));
ReturnErrorOnFailure(CheckValidBindingList(path.mEndpointId, newBindingList, mAccessingFabricIndex));

// Clear all entries for the current accessing fabric and endpoint
auto bindingTableIter = BindingTable::GetInstance().begin();
while (bindingTableIter != BindingTable::GetInstance().end())
{
if (bindingTableIter->local == path.mEndpointId && bindingTableIter->fabricIndex == accessingFabricIndex)
if (bindingTableIter->local == path.mEndpointId && bindingTableIter->fabricIndex == mAccessingFabricIndex)
{
if (bindingTableIter->type == EMBER_UNICAST_BINDING)
{
Expand Down Expand Up @@ -254,7 +256,8 @@ CHIP_ERROR BindingTableAccess::WriteBindingTable(const ConcreteDataAttributePath
CHIP_ERROR BindingTableAccess::NotifyBindingsChanged()
{
DeviceLayer::ChipDeviceEvent event;
event.Type = DeviceLayer::DeviceEventType::kBindingsChangedViaCluster;
event.Type = DeviceLayer::DeviceEventType::kBindingsChangedViaCluster;
event.BindingsChanged.fabricIndex = mAccessingFabricIndex;
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