@@ -164,6 +164,8 @@ class MyPostCommissioningListener : public PostCommissioningListener
164
164
// read current binding list
165
165
chip::Controller::ClusterBase cluster (exchangeMgr, sessionHandle, kTargetBindingClusterEndpointId );
166
166
167
+ ContentAppPlatform::GetInstance ().StoreNodeIdForContentApp (vendorId, productId, nodeId);
168
+
167
169
cacheContext (vendorId, productId, nodeId, exchangeMgr, sessionHandle);
168
170
169
171
CHIP_ERROR err =
@@ -565,6 +567,59 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId)
565
567
mAdminVendorIds .push_back (vendorId);
566
568
}
567
569
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
+
568
623
void ContentAppFactoryImpl::InstallContentApp (uint16_t vendorId, uint16_t productId)
569
624
{
570
625
auto make_default_supported_clusters = []() {
@@ -605,6 +660,44 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc
605
660
make_default_supported_clusters ());
606
661
mContentApps .emplace_back (std::move (ptr));
607
662
}
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
+
608
701
}
609
702
610
703
bool ContentAppFactoryImpl::UninstallContentApp (uint16_t vendorId, uint16_t productId)
@@ -625,8 +718,9 @@ bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t prod
625
718
ChipLogProgress (DeviceLayer, " Found an app vid=%d pid=%d. Uninstalling it." ,
626
719
app->GetApplicationBasicDelegate ()->HandleGetVendorId (),
627
720
app->GetApplicationBasicDelegate ()->HandleGetProductId ());
721
+ EndpointId removedEndpointID = ContentAppPlatform::GetInstance ().RemoveContentApp (app);
722
+ ChipLogProgress (DeviceLayer, " Removed content app at endpoint id: %d" , removedEndpointID);
628
723
mContentApps .erase (mContentApps .begin () + index );
629
- // TODO: call ContentAppPlatform->RemoveContentApp(ids...)
630
724
return true ;
631
725
}
632
726
0 commit comments