@@ -355,6 +355,59 @@ ContentApp * ContentAppFactoryImpl::LoadContentApp(const CatalogVendorApp & vend
355
355
return nullptr ;
356
356
}
357
357
358
+ class DevicePairedCommand : public Controller ::DevicePairingDelegate
359
+ {
360
+ public:
361
+ struct CallbackContext
362
+ {
363
+ uint16_t vendorId;
364
+ uint16_t productId;
365
+ chip::NodeId nodeId;
366
+
367
+ CallbackContext (uint16_t vId, uint16_t pId, chip::NodeId nId)
368
+ : vendorId(vId), productId(pId), nodeId(nId) {}
369
+ };
370
+ DevicePairedCommand (uint16_t vendorId, uint16_t productId, chip::NodeId nodeId) :
371
+ mOnDeviceConnectedCallback (OnDeviceConnectedFn, this ),
372
+ mOnDeviceConnectionFailureCallback (OnDeviceConnectionFailureFn, this )
373
+ {
374
+ mContext = std::make_shared<CallbackContext>(vendorId, productId, nodeId);
375
+ }
376
+
377
+ static void OnDeviceConnectedFn (void * context, chip::Messaging::ExchangeManager & exchangeMgr,
378
+ const chip::SessionHandle & sessionHandle)
379
+ {
380
+ auto * pairingCommand = static_cast <DevicePairedCommand *>(context);
381
+ auto cbContext = pairingCommand->mContext ;
382
+
383
+ if (pairingCommand)
384
+ {
385
+ ChipLogProgress (DeviceLayer, " OnDeviceConnectedFn - Updating ACL for node id: %llu and vendor id: %d and product id: %d" , cbContext->nodeId , cbContext->vendorId , cbContext->productId );
386
+
387
+ GetCommissionerDiscoveryController ()->CommissioningSucceeded (cbContext->vendorId , cbContext->productId , cbContext->nodeId , exchangeMgr, sessionHandle);
388
+ }
389
+ }
390
+
391
+
392
+ static void OnDeviceConnectionFailureFn (void * context, const ScopedNodeId & peerId, CHIP_ERROR error)
393
+ {
394
+ auto * pairingCommand = static_cast <DevicePairedCommand *>(context);
395
+ auto cbContext = pairingCommand->mContext ;
396
+
397
+ if (pairingCommand)
398
+ {
399
+ ChipLogProgress (DeviceLayer, " OnDeviceConnectionFailureFn - Not updating ACL for node id: %llu and vendor id: %d and product id: %d" , cbContext->nodeId , cbContext->vendorId , cbContext->productId );
400
+ // TODO: Remove Node Id
401
+ }
402
+ }
403
+
404
+ chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback ;
405
+ chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback ;
406
+ std::shared_ptr<CallbackContext> mContext ;
407
+ };
408
+
409
+
410
+
358
411
EndpointId ContentAppFactoryImpl::AddContentApp (const char * szVendorName, uint16_t vendorId, const char * szApplicationName,
359
412
uint16_t productId, const char * szApplicationVersion,
360
413
std::vector<SupportedCluster> supportedClusters, jobject manager)
@@ -369,6 +422,17 @@ EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint1
369
422
app->GetEndpointId ());
370
423
mContentApps .push_back (app);
371
424
mDataVersions .push_back (dataVersionBuf);
425
+
426
+ std::set<NodeId> nodeIds = ContentAppPlatform::GetInstance ().GetNodeIdsForContentApp (vendorId, productId);
427
+
428
+ for (const auto & nodeId : nodeIds) {
429
+
430
+ ChipLogProgress (DeviceLayer, " Creating Pairing Command with node id: %llu and vendor id: %d and product id: %d" , nodeId, vendorId, productId);
431
+
432
+ std::shared_ptr<DevicePairedCommand> pairingCommand = std::make_shared<DevicePairedCommand>(vendorId, productId, nodeId);
433
+
434
+ GetDeviceCommissioner ()->GetConnectedDevice (nodeId, &pairingCommand->mOnDeviceConnectedCallback , &pairingCommand->mOnDeviceConnectionFailureCallback );
435
+ }
372
436
return epId;
373
437
}
374
438
@@ -387,6 +451,18 @@ EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint1
387
451
app->GetEndpointId ());
388
452
mContentApps .push_back (app);
389
453
mDataVersions .push_back (dataVersionBuf);
454
+
455
+ std::set<NodeId> nodeIds = ContentAppPlatform::GetInstance ().GetNodeIdsForContentApp (vendorId, productId);
456
+
457
+ for (const auto & nodeId : nodeIds) {
458
+
459
+ ChipLogProgress (DeviceLayer, " Creating Pairing Command with node id: %llu and vendor id: %d and product id: %d" , nodeId, vendorId, productId);
460
+
461
+ std::shared_ptr<DevicePairedCommand> pairingCommand = std::make_shared<DevicePairedCommand>(vendorId, productId, nodeId);
462
+
463
+ GetDeviceCommissioner ()->GetConnectedDevice (nodeId, &pairingCommand->mOnDeviceConnectedCallback , &pairingCommand->mOnDeviceConnectionFailureCallback );
464
+ }
465
+
390
466
return epId;
391
467
}
392
468
0 commit comments