@@ -244,6 +244,16 @@ - (instancetype)initWithDevice:(chip::DeviceProxy *)device
244
244
return _cppDevice;
245
245
}
246
246
247
+ - (void )invalidateCASESession
248
+ {
249
+ dispatch_sync (DeviceLayer::PlatformMgrImpl ().GetWorkQueue (), ^{
250
+ DeviceProxy * device = [self internalDevice ];
251
+ if (device != nullptr ) {
252
+ device->Disconnect ();
253
+ }
254
+ });
255
+ }
256
+
247
257
typedef void (^ReportCallback)(NSArray * _Nullable value, NSError * _Nullable error);
248
258
typedef void (^DataReportCallback)(NSArray * value);
249
259
typedef void (^ErrorCallback)(NSError * error);
@@ -371,76 +381,78 @@ - (void)subscribeWithQueue:(dispatch_queue_t)queue
371
381
errorHandler: (void (^)(NSError * error))errorHandler
372
382
subscriptionEstablished: (nullable void (^)(void ))subscriptionEstablishedHandler
373
383
{
374
- DeviceProxy * device = [self internalDevice ];
375
- if (!device) {
376
- dispatch_async (queue, ^{
377
- errorHandler ([CHIPError errorForCHIPErrorCode: CHIP_ERROR_INCORRECT_STATE]);
378
- });
379
- return ;
380
- }
381
-
382
- // Wildcard endpoint, cluster, attribute, event.
383
- auto attributePath = std::make_unique<AttributePathParams>();
384
- auto eventPath = std::make_unique<EventPathParams>();
385
- ReadPrepareParams readParams (device->GetSecureSession ().Value ());
386
- readParams.mMinIntervalFloorSeconds = minInterval;
387
- readParams.mMaxIntervalCeilingSeconds = maxInterval;
388
- readParams.mpAttributePathParamsList = attributePath.get ();
389
- readParams.mAttributePathParamsListSize = 1 ;
390
- readParams.mpEventPathParamsList = eventPath.get ();
391
- readParams.mEventPathParamsListSize = 1 ;
392
- readParams.mKeepSubscriptions
393
- = (params != nil ) && (params.keepPreviousSubscriptions != nil ) && [params.keepPreviousSubscriptions boolValue ];
394
-
395
- std::unique_ptr<SubscriptionCallback> callback;
396
- std::unique_ptr<ReadClient> readClient;
397
- std::unique_ptr<ClusterStateCache> attributeCache;
398
- if (attributeCacheContainer) {
399
- __weak CHIPAttributeCacheContainer * weakPtr = attributeCacheContainer;
400
- callback = std::make_unique<SubscriptionCallback>(
401
- queue, attributeReportHandler, eventReportHandler, errorHandler, subscriptionEstablishedHandler, ^{
402
- CHIPAttributeCacheContainer * container = weakPtr;
403
- if (container) {
404
- container.cppAttributeCache = nullptr ;
405
- }
384
+ dispatch_async (DeviceLayer::PlatformMgrImpl ().GetWorkQueue (), ^{
385
+ DeviceProxy * device = [self internalDevice ];
386
+ if (!device) {
387
+ dispatch_async (queue, ^{
388
+ errorHandler ([CHIPError errorForCHIPErrorCode: CHIP_ERROR_INCORRECT_STATE]);
406
389
});
407
- attributeCache = std::make_unique<ClusterStateCache>(*callback.get ());
408
- readClient = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance (), device->GetExchangeManager (),
409
- attributeCache->GetBufferedCallback (), ReadClient::InteractionType::Subscribe);
410
- } else {
411
- callback = std::make_unique<SubscriptionCallback>(
412
- queue, attributeReportHandler, eventReportHandler, errorHandler, subscriptionEstablishedHandler);
413
- readClient = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance (), device->GetExchangeManager (),
414
- callback->GetBufferedCallback (), ReadClient::InteractionType::Subscribe);
415
- }
390
+ return ;
391
+ }
416
392
417
- CHIP_ERROR err;
418
- if (params != nil && params.autoResubscribe != nil && ![params.autoResubscribe boolValue ]) {
419
- err = readClient->SendRequest (readParams);
420
- } else {
421
- // SendAutoResubscribeRequest cleans up the params, even on failure.
422
- attributePath.release ();
423
- eventPath.release ();
424
- err = readClient->SendAutoResubscribeRequest (std::move (readParams));
425
- }
393
+ // Wildcard endpoint, cluster, attribute, event.
394
+ auto attributePath = std::make_unique<AttributePathParams>();
395
+ auto eventPath = std::make_unique<EventPathParams>();
396
+ ReadPrepareParams readParams (device->GetSecureSession ().Value ());
397
+ readParams.mMinIntervalFloorSeconds = minInterval;
398
+ readParams.mMaxIntervalCeilingSeconds = maxInterval;
399
+ readParams.mpAttributePathParamsList = attributePath.get ();
400
+ readParams.mAttributePathParamsListSize = 1 ;
401
+ readParams.mpEventPathParamsList = eventPath.get ();
402
+ readParams.mEventPathParamsListSize = 1 ;
403
+ readParams.mKeepSubscriptions
404
+ = (params != nil ) && (params.keepPreviousSubscriptions != nil ) && [params.keepPreviousSubscriptions boolValue ];
405
+
406
+ std::unique_ptr<SubscriptionCallback> callback;
407
+ std::unique_ptr<ReadClient> readClient;
408
+ std::unique_ptr<ClusterStateCache> attributeCache;
409
+ if (attributeCacheContainer) {
410
+ __weak CHIPAttributeCacheContainer * weakPtr = attributeCacheContainer;
411
+ callback = std::make_unique<SubscriptionCallback>(
412
+ queue, attributeReportHandler, eventReportHandler, errorHandler, subscriptionEstablishedHandler, ^{
413
+ CHIPAttributeCacheContainer * container = weakPtr;
414
+ if (container) {
415
+ container.cppAttributeCache = nullptr ;
416
+ }
417
+ });
418
+ attributeCache = std::make_unique<ClusterStateCache>(*callback.get ());
419
+ readClient = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance (), device->GetExchangeManager (),
420
+ attributeCache->GetBufferedCallback (), ReadClient::InteractionType::Subscribe);
421
+ } else {
422
+ callback = std::make_unique<SubscriptionCallback>(
423
+ queue, attributeReportHandler, eventReportHandler, errorHandler, subscriptionEstablishedHandler);
424
+ readClient = std::make_unique<ReadClient>(InteractionModelEngine::GetInstance (), device->GetExchangeManager (),
425
+ callback->GetBufferedCallback (), ReadClient::InteractionType::Subscribe);
426
+ }
426
427
427
- if (err != CHIP_NO_ERROR) {
428
- dispatch_async (queue, ^{
429
- errorHandler ([CHIPError errorForCHIPErrorCode: err]);
430
- });
428
+ CHIP_ERROR err;
429
+ if (params != nil && params.autoResubscribe != nil && ![params.autoResubscribe boolValue ]) {
430
+ err = readClient->SendRequest (readParams);
431
+ } else {
432
+ // SendAutoResubscribeRequest cleans up the params, even on failure.
433
+ attributePath.release ();
434
+ eventPath.release ();
435
+ err = readClient->SendAutoResubscribeRequest (std::move (readParams));
436
+ }
431
437
432
- return ;
433
- }
438
+ if (err != CHIP_NO_ERROR) {
439
+ dispatch_async (queue, ^{
440
+ errorHandler ([CHIPError errorForCHIPErrorCode: err]);
441
+ });
434
442
435
- if (attributeCacheContainer) {
436
- attributeCacheContainer.cppAttributeCache = attributeCache.get ();
437
- // ClusterStateCache will be deleted when OnDone is called or an error is encountered as well.
438
- callback->AdoptAttributeCache (std::move (attributeCache));
439
- }
440
- // Callback and ReadClient will be deleted when OnDone is called or an error is
441
- // encountered.
442
- callback->AdoptReadClient (std::move (readClient));
443
- callback.release ();
443
+ return ;
444
+ }
445
+
446
+ if (attributeCacheContainer) {
447
+ attributeCacheContainer.cppAttributeCache = attributeCache.get ();
448
+ // ClusterStateCache will be deleted when OnDone is called or an error is encountered as well.
449
+ callback->AdoptAttributeCache (std::move (attributeCache));
450
+ }
451
+ // Callback and ReadClient will be deleted when OnDone is called or an error is
452
+ // encountered.
453
+ callback->AdoptReadClient (std::move (readClient));
454
+ callback.release ();
455
+ });
444
456
}
445
457
446
458
// Convert TLV data into NSObject
0 commit comments