@@ -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,63 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId)
565
567
mAdminVendorIds .push_back (vendorId);
566
568
}
567
569
570
+ #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
571
+ class DevicePairedCommand : public Controller ::DevicePairingDelegate
572
+ {
573
+ public:
574
+ struct CallbackContext
575
+ {
576
+ uint16_t vendorId;
577
+ uint16_t productId;
578
+ chip::NodeId nodeId;
579
+
580
+ CallbackContext (uint16_t vId, uint16_t pId, chip::NodeId nId) : vendorId(vId), productId(pId), nodeId(nId) {}
581
+ };
582
+ DevicePairedCommand (uint16_t vendorId, uint16_t productId, chip::NodeId nodeId) :
583
+ mOnDeviceConnectedCallback (OnDeviceConnectedFn, this ), mOnDeviceConnectionFailureCallback (OnDeviceConnectionFailureFn, this )
584
+ {
585
+ mContext = std::make_shared<CallbackContext>(vendorId, productId, nodeId);
586
+ }
587
+
588
+ static void OnDeviceConnectedFn (void * context, chip::Messaging::ExchangeManager & exchangeMgr,
589
+ const chip::SessionHandle & sessionHandle)
590
+ {
591
+ auto * pairingCommand = static_cast <DevicePairedCommand *>(context);
592
+ auto cbContext = pairingCommand->mContext ;
593
+
594
+ if (pairingCommand)
595
+ {
596
+ ChipLogProgress (DeviceLayer,
597
+ " OnDeviceConnectedFn - Updating ACL for node id: " ChipLogFormatX64
598
+ " and vendor id: %d and product id: %d" ,
599
+ ChipLogValueX64 (cbContext->nodeId ), cbContext->vendorId , cbContext->productId );
600
+
601
+ GetCommissionerDiscoveryController ()->CommissioningSucceeded (cbContext->vendorId , cbContext->productId ,
602
+ cbContext->nodeId , exchangeMgr, sessionHandle);
603
+ }
604
+ }
605
+
606
+ static void OnDeviceConnectionFailureFn (void * context, const ScopedNodeId & peerId, CHIP_ERROR error)
607
+ {
608
+ auto * pairingCommand = static_cast <DevicePairedCommand *>(context);
609
+ auto cbContext = pairingCommand->mContext ;
610
+
611
+ if (pairingCommand)
612
+ {
613
+ ChipLogProgress (DeviceLayer,
614
+ " OnDeviceConnectionFailureFn - Not updating ACL for node id: " ChipLogFormatX64
615
+ " and vendor id: %d and product id: %d" ,
616
+ ChipLogValueX64 (cbContext->nodeId ), cbContext->vendorId , cbContext->productId );
617
+ // TODO: Remove Node Id
618
+ }
619
+ }
620
+
621
+ chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback ;
622
+ chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback ;
623
+ std::shared_ptr<CallbackContext> mContext ;
624
+ };
625
+ #endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
626
+
568
627
void ContentAppFactoryImpl::InstallContentApp (uint16_t vendorId, uint16_t productId)
569
628
{
570
629
auto make_default_supported_clusters = []() {
@@ -605,6 +664,46 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc
605
664
make_default_supported_clusters ());
606
665
mContentApps .emplace_back (std::move (ptr));
607
666
}
667
+
668
+ #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
669
+ // Get the list of node ids
670
+ std::set<NodeId> nodeIds = ContentAppPlatform::GetInstance ().GetNodeIdsForContentApp (vendorId, productId);
671
+
672
+ // update ACLs
673
+ for (auto & contentApp : mContentApps )
674
+ {
675
+ auto app = contentApp.get ();
676
+
677
+ if (app->MatchesPidVid (productId, vendorId))
678
+ {
679
+ CatalogVendorApp vendorApp = app->GetApplicationBasicDelegate ()->GetCatalogVendorApp ();
680
+
681
+ GetContentAppFactoryImpl ()->LoadContentApp (vendorApp);
682
+ }
683
+
684
+ // update the list of node ids with content apps allowed vendor list
685
+ for (const auto & allowedVendor : app->GetApplicationBasicDelegate ()->GetAllowedVendorList ())
686
+ {
687
+ std::set<NodeId> tempNodeIds = ContentAppPlatform::GetInstance ().GetNodeIdsForAllowVendorId (allowedVendor);
688
+
689
+ nodeIds.insert (tempNodeIds.begin (), tempNodeIds.end ());
690
+ }
691
+ }
692
+
693
+ // refresh ACLs
694
+ for (const auto & nodeId : nodeIds)
695
+ {
696
+
697
+ ChipLogProgress (DeviceLayer,
698
+ " Creating Pairing Command with node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d" ,
699
+ ChipLogValueX64 (nodeId), vendorId, productId);
700
+
701
+ std::shared_ptr<DevicePairedCommand> pairingCommand = std::make_shared<DevicePairedCommand>(vendorId, productId, nodeId);
702
+
703
+ GetDeviceCommissioner ()->GetConnectedDevice (nodeId, &pairingCommand->mOnDeviceConnectedCallback ,
704
+ &pairingCommand->mOnDeviceConnectionFailureCallback );
705
+ }
706
+ #endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
608
707
}
609
708
610
709
bool ContentAppFactoryImpl::UninstallContentApp (uint16_t vendorId, uint16_t productId)
@@ -625,8 +724,9 @@ bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t prod
625
724
ChipLogProgress (DeviceLayer, " Found an app vid=%d pid=%d. Uninstalling it." ,
626
725
app->GetApplicationBasicDelegate ()->HandleGetVendorId (),
627
726
app->GetApplicationBasicDelegate ()->HandleGetProductId ());
727
+ EndpointId removedEndpointID = ContentAppPlatform::GetInstance ().RemoveContentApp (app);
728
+ ChipLogProgress (DeviceLayer, " Removed content app at endpoint id: %d" , removedEndpointID);
628
729
mContentApps .erase (mContentApps .begin () + index );
629
- // TODO: call ContentAppPlatform->RemoveContentApp(ids...)
630
730
return true ;
631
731
}
632
732
@@ -701,22 +801,8 @@ std::list<ClusterId> ContentAppFactoryImpl::GetAllowedClusterListForStaticEndpoi
701
801
CHIP_ERROR AppTvInit ()
702
802
{
703
803
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
704
- // test data for apps
705
- constexpr uint16_t kApp1VendorId = 1 ;
706
- constexpr uint16_t kApp1ProductId = 11 ;
707
- constexpr uint16_t kApp2VendorId = 65521 ;
708
- constexpr uint16_t kApp2ProductId = 32769 ;
709
- constexpr uint16_t kApp3VendorId = 9050 ;
710
- constexpr uint16_t kApp3ProductId = 22 ;
711
- constexpr uint16_t kApp4VendorId = 1111 ;
712
- constexpr uint16_t kApp4ProductId = 22 ;
713
-
714
804
ContentAppPlatform::GetInstance ().SetupAppPlatform ();
715
805
ContentAppPlatform::GetInstance ().SetContentAppFactory (&gFactory );
716
- gFactory .InstallContentApp (kApp1VendorId , kApp1ProductId );
717
- gFactory .InstallContentApp (kApp2VendorId , kApp2ProductId );
718
- gFactory .InstallContentApp (kApp3VendorId , kApp3ProductId );
719
- gFactory .InstallContentApp (kApp4VendorId , kApp4ProductId );
720
806
uint16_t value;
721
807
if (DeviceLayer::GetDeviceInstanceInfoProvider ()->GetVendorId (value) != CHIP_NO_ERROR)
722
808
{
0 commit comments