Skip to content

Commit e5e5950

Browse files
committed
Update code per comments
1 parent 97cc513 commit e5e5950

File tree

4 files changed

+144
-31
lines changed

4 files changed

+144
-31
lines changed

examples/tv-app/android/java/AppImpl.cpp

+30-29
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate
381381
if (pairingCommand)
382382
{
383383
ChipLogProgress(DeviceLayer,
384-
"OnDeviceConnectedFn - Updating ACL for node id: %llu and vendor id: %d and product id: %d",
385-
cbContext->nodeId, cbContext->vendorId, cbContext->productId);
384+
"OnDeviceConnectedFn - Updating ACL for node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d",
385+
ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId);
386386

387387
GetCommissionerDiscoveryController()->CommissioningSucceeded(cbContext->vendorId, cbContext->productId,
388388
cbContext->nodeId, exchangeMgr, sessionHandle);
@@ -397,8 +397,8 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate
397397
if (pairingCommand)
398398
{
399399
ChipLogProgress(DeviceLayer,
400-
"OnDeviceConnectionFailureFn - Not updating ACL for node id: %llu and vendor id: %d and product id: %d",
401-
cbContext->nodeId, cbContext->vendorId, cbContext->productId);
400+
"OnDeviceConnectionFailureFn - Not updating ACL for node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d",
401+
ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId);
402402
// TODO: Remove Node Id
403403
}
404404
}
@@ -408,6 +408,30 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate
408408
std::shared_ptr<CallbackContext> mContext;
409409
};
410410

411+
void refreshConnectedClientsAcl(uint16_t vendorId, uint16_t productId, ContentAppImpl * app) {
412+
413+
std::set<NodeId> nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId);
414+
415+
for (const auto & allowedVendor : app->GetApplicationBasicDelegate()->GetAllowedVendorList())
416+
{
417+
std::set<NodeId> tempNodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForAllowVendorId(allowedVendor);
418+
419+
nodeIds.insert(tempNodeIds.begin(), tempNodeIds.end());
420+
}
421+
422+
for (const auto & nodeId : nodeIds)
423+
{
424+
425+
ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", ChipLogValueX64(nodeId),
426+
vendorId, productId);
427+
428+
std::shared_ptr<DevicePairedCommand> pairingCommand = std::make_shared<DevicePairedCommand>(vendorId, productId, nodeId);
429+
430+
GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback,
431+
&pairingCommand->mOnDeviceConnectionFailureCallback);
432+
}
433+
}
434+
411435
EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName,
412436
uint16_t productId, const char * szApplicationVersion,
413437
std::vector<SupportedCluster> supportedClusters, jobject manager)
@@ -423,19 +447,8 @@ EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint1
423447
mContentApps.push_back(app);
424448
mDataVersions.push_back(dataVersionBuf);
425449

426-
std::set<NodeId> nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId);
427-
428-
for (const auto & nodeId : nodeIds)
429-
{
430-
431-
ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: %llu and vendor id: %d and product id: %d", nodeId,
432-
vendorId, productId);
433-
434-
std::shared_ptr<DevicePairedCommand> pairingCommand = std::make_shared<DevicePairedCommand>(vendorId, productId, nodeId);
450+
refreshConnectedClientsAcl(vendorId, productId, app);
435451

436-
GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback,
437-
&pairingCommand->mOnDeviceConnectionFailureCallback);
438-
}
439452
return epId;
440453
}
441454

@@ -455,19 +468,7 @@ EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint1
455468
mContentApps.push_back(app);
456469
mDataVersions.push_back(dataVersionBuf);
457470

458-
std::set<NodeId> nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId);
459-
460-
for (const auto & nodeId : nodeIds)
461-
{
462-
463-
ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: %llu and vendor id: %d and product id: %d", nodeId,
464-
vendorId, productId);
465-
466-
std::shared_ptr<DevicePairedCommand> pairingCommand = std::make_shared<DevicePairedCommand>(vendorId, productId, nodeId);
467-
468-
GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback,
469-
&pairingCommand->mOnDeviceConnectionFailureCallback);
470-
}
471+
refreshConnectedClientsAcl(vendorId, productId, app);
471472

472473
return epId;
473474
}

examples/tv-app/tv-common/src/AppTv.cpp

+95-1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ class MyPostCommissioningListener : public PostCommissioningListener
164164
// read current binding list
165165
chip::Controller::ClusterBase cluster(exchangeMgr, sessionHandle, kTargetBindingClusterEndpointId);
166166

167+
ContentAppPlatform::GetInstance().StoreNodeIdForContentApp(vendorId, productId, nodeId);
168+
167169
cacheContext(vendorId, productId, nodeId, exchangeMgr, sessionHandle);
168170

169171
CHIP_ERROR err =
@@ -565,6 +567,59 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId)
565567
mAdminVendorIds.push_back(vendorId);
566568
}
567569

570+
class DevicePairedCommand : public Controller::DevicePairingDelegate
571+
{
572+
public:
573+
struct CallbackContext
574+
{
575+
uint16_t vendorId;
576+
uint16_t productId;
577+
chip::NodeId nodeId;
578+
579+
CallbackContext(uint16_t vId, uint16_t pId, chip::NodeId nId) : vendorId(vId), productId(pId), nodeId(nId) {}
580+
};
581+
DevicePairedCommand(uint16_t vendorId, uint16_t productId, chip::NodeId nodeId) :
582+
mOnDeviceConnectedCallback(OnDeviceConnectedFn, this), mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this)
583+
{
584+
mContext = std::make_shared<CallbackContext>(vendorId, productId, nodeId);
585+
}
586+
587+
static void OnDeviceConnectedFn(void * context, chip::Messaging::ExchangeManager & exchangeMgr,
588+
const chip::SessionHandle & sessionHandle)
589+
{
590+
auto * pairingCommand = static_cast<DevicePairedCommand *>(context);
591+
auto cbContext = pairingCommand->mContext;
592+
593+
if (pairingCommand)
594+
{
595+
ChipLogProgress(DeviceLayer,
596+
"OnDeviceConnectedFn - Updating ACL for node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d",
597+
ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId);
598+
599+
GetCommissionerDiscoveryController()->CommissioningSucceeded(cbContext->vendorId, cbContext->productId,
600+
cbContext->nodeId, exchangeMgr, sessionHandle);
601+
}
602+
}
603+
604+
static void OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error)
605+
{
606+
auto * pairingCommand = static_cast<DevicePairedCommand *>(context);
607+
auto cbContext = pairingCommand->mContext;
608+
609+
if (pairingCommand)
610+
{
611+
ChipLogProgress(DeviceLayer,
612+
"OnDeviceConnectionFailureFn - Not updating ACL for node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d",
613+
ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId);
614+
// TODO: Remove Node Id
615+
}
616+
}
617+
618+
chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback;
619+
chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
620+
std::shared_ptr<CallbackContext> mContext;
621+
};
622+
568623
void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t productId)
569624
{
570625
auto make_default_supported_clusters = []() {
@@ -605,6 +660,44 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc
605660
make_default_supported_clusters());
606661
mContentApps.emplace_back(std::move(ptr));
607662
}
663+
664+
// Get the list of node ids
665+
std::set<NodeId> nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId);
666+
667+
// update ACLs
668+
for (auto & contentApp : mContentApps)
669+
{
670+
auto app = contentApp.get();
671+
672+
if (app->MatchesPidVid(productId, vendorId))
673+
{
674+
CatalogVendorApp vendorApp = app->GetApplicationBasicDelegate()->GetCatalogVendorApp();
675+
676+
GetContentAppFactoryImpl()->LoadContentApp(vendorApp);
677+
}
678+
679+
// update the list of node ids with content apps allowed vendor list
680+
for (const auto & allowedVendor : app->GetApplicationBasicDelegate()->GetAllowedVendorList())
681+
{
682+
std::set<NodeId> tempNodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForAllowVendorId(allowedVendor);
683+
684+
nodeIds.insert(tempNodeIds.begin(), tempNodeIds.end());
685+
}
686+
}
687+
688+
// refresh ACLs
689+
for (const auto & nodeId : nodeIds)
690+
{
691+
692+
ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", ChipLogValueX64(nodeId),
693+
vendorId, productId);
694+
695+
std::shared_ptr<DevicePairedCommand> pairingCommand = std::make_shared<DevicePairedCommand>(vendorId, productId, nodeId);
696+
697+
GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback,
698+
&pairingCommand->mOnDeviceConnectionFailureCallback);
699+
}
700+
608701
}
609702

610703
bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t productId)
@@ -625,8 +718,9 @@ bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t prod
625718
ChipLogProgress(DeviceLayer, "Found an app vid=%d pid=%d. Uninstalling it.",
626719
app->GetApplicationBasicDelegate()->HandleGetVendorId(),
627720
app->GetApplicationBasicDelegate()->HandleGetProductId());
721+
EndpointId removedEndpointID = ContentAppPlatform::GetInstance().RemoveContentApp(app);
722+
ChipLogProgress(DeviceLayer, "Removed content app at endpoint id: %d", removedEndpointID);
628723
mContentApps.erase(mContentApps.begin() + index);
629-
// TODO: call ContentAppPlatform->RemoveContentApp(ids...)
630724
return true;
631725
}
632726

src/app/app-platform/ContentAppPlatform.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ void ContentAppPlatform::StoreNodeIdForContentApp(uint16_t vendorId, uint16_t pr
397397
{
398398
std::string key = createKey(vendorId, productId);
399399

400-
ChipLogProgress(DeviceLayer, "Stored node id: %llu for key: %s", nodeId, key.c_str());
400+
ChipLogProgress(DeviceLayer, "Stored node id: " ChipLogFormatX64 " for key: %s", ChipLogValueX64(nodeId), key.c_str());
401401

402402
mConnectedContentAppNodeIds[key].insert(nodeId);
403403
}
@@ -420,6 +420,21 @@ std::set<NodeId> ContentAppPlatform::GetNodeIdsForContentApp(uint16_t vendorId,
420420
return {};
421421
}
422422

423+
std::set<NodeId> ContentAppPlatform::GetNodeIdsForAllowVendorId(uint16_t vendorId) {
424+
std::set<NodeId> result;
425+
std::string vendorPrefix = std::to_string(vendorId) + ":";
426+
427+
for (const auto& pair : mConnectedContentAppNodeIds) {
428+
const std::string& key = pair.first;
429+
if (key.find(vendorPrefix) == 0) { // Check if the key starts with the vendor prefix
430+
const std::set<NodeId>& nodeIds = pair.second;
431+
result.insert(nodeIds.begin(), nodeIds.end());
432+
}
433+
}
434+
435+
return result;
436+
}
437+
423438
void ContentAppPlatform::SetCurrentApp(ContentApp * app)
424439
{
425440
if (!HasCurrentApp())

src/app/app-platform/ContentAppPlatform.h

+3
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ class DLL_EXPORT ContentAppPlatform
164164
// returns set of connected nodes for a given content app
165165
std::set<NodeId> GetNodeIdsForContentApp(uint16_t vendorId, uint16_t productId);
166166

167+
// returns set of connected nodes for a given allowed vendor id
168+
std::set<NodeId> GetNodeIdsForAllowVendorId(uint16_t vendorId);
169+
167170
// store node id for content app after commissioning
168171
// node id can be used later on to update ACL
169172
// in case app is not installed

0 commit comments

Comments
 (0)