diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 7a7570b817e375..68da0859fe0659 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -130,7 +130,6 @@ - (id)strongObject #pragma mark - MTRDevice @interface MTRDevice () @property (nonatomic, readonly) os_unfair_lock lock; // protects the caches and device state -@property (nonatomic) dispatch_queue_t queue; @property (nonatomic) MTRWeakReference> * weakDelegate; @property (nonatomic) dispatch_queue_t delegateQueue; @property (nonatomic) NSArray *> * unreportedEvents; @@ -156,8 +155,7 @@ - (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceControlle _lock = OS_UNFAIR_LOCK_INIT; _nodeID = [nodeID copy]; _deviceController = controller; - _queue = dispatch_queue_create("com.apple.matter.framework.xpc.workqueue", DISPATCH_QUEUE_SERIAL); - ; + _queue = dispatch_queue_create("com.apple.matter.framework.device.workqueue", DISPATCH_QUEUE_SERIAL); _readCache = [NSMutableDictionary dictionary]; _expectedValueCache = [NSMutableDictionary dictionary]; _asyncCallbackWorkQueue = [[MTRAsyncCallbackWorkQueue alloc] initWithContext:self queue:_queue]; @@ -413,7 +411,7 @@ - (void)setupSubscription NSString * logPrefix = [NSString stringWithFormat:@"MTRDevice read %u %@ %@ %@", _deviceController.fabricIndex, endpointID, clusterID, attributeID]; // Create work item, set ready handler to perform task, then enqueue the work - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:_queue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTR_LOG_INFO("%@ dequeueWorkItem %@", logPrefix, self->_asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [self newBaseDevice]; @@ -468,7 +466,7 @@ - (void)writeAttributeWithEndpointID:(NSNumber *)endpointID timeout = MTRClampedNumber(timeout, @(1), @(UINT16_MAX)); } expectedValueInterval = MTRClampedNumber(expectedValueInterval, @(1), @(UINT32_MAX)); - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:_queue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTR_LOG_INFO("%@ dequeueWorkItem %@", logPrefix, self->_asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [self newBaseDevice]; @@ -517,7 +515,7 @@ - (void)invokeCommandWithEndpointID:(NSNumber *)endpointID } else { expectedValueInterval = MTRClampedNumber(expectedValueInterval, @(1), @(UINT32_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:_queue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTR_LOG_INFO("%@ dequeueWorkItem %@", logPrefix, self->_asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [self newBaseDevice]; @@ -611,7 +609,7 @@ - (void)_checkExpiredExpectedValues waitTime = MTR_DEVICE_EXPIRATION_CHECK_TIMER_MINIMUM_WAIT_TIME; } MTRWeakReference * weakSelf = [MTRWeakReference weakReferenceWithObject:self]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(waitTime * NSEC_PER_SEC)), _queue, ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(waitTime * NSEC_PER_SEC)), self.queue, ^{ MTRDevice * strongSelf = weakSelf.strongObject; [strongSelf _performScheduledExpirationCheck]; }); diff --git a/src/darwin/Framework/CHIP/MTRDevice_Internal.h b/src/darwin/Framework/CHIP/MTRDevice_Internal.h index 9d2e77876261f0..f752ed5632c680 100644 --- a/src/darwin/Framework/CHIP/MTRDevice_Internal.h +++ b/src/darwin/Framework/CHIP/MTRDevice_Internal.h @@ -35,6 +35,10 @@ typedef void (^MTRDevicePerformAsyncBlock)(MTRBaseDevice * baseDevice); @property (nonatomic, readonly) MTRDeviceController * deviceController; @property (nonatomic, readonly, copy) NSNumber * nodeID; +// Queue used for various internal bookkeeping work. In general endWork calls +// on work items should happen on this queue, so we don't block progress of the +// asyncCallbackWorkQueue on any client code. +@property (nonatomic) dispatch_queue_t queue; @property (nonatomic, readonly) MTRAsyncCallbackWorkQueue * asyncCallbackWorkQueue; @end diff --git a/src/darwin/Framework/CHIP/templates/MTRClusters-src.zapt b/src/darwin/Framework/CHIP/templates/MTRClusters-src.zapt index dcb06b5321854f..a8dc906972e105 100644 --- a/src/darwin/Framework/CHIP/templates/MTRClusters-src.zapt +++ b/src/darwin/Framework/CHIP/templates/MTRClusters-src.zapt @@ -73,12 +73,14 @@ static void MTRClustersLogCompletion(NSString *logPrefix, id value, NSError *err if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice *baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; - auto * bridge = new MTR{{>callbackName}}CallbackBridge(self.callbackQueue, + auto * bridge = new MTR{{>callbackName}}CallbackBridge(self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { + MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ {{#if hasSpecificResponse}} {{! This treats completion as taking an id for the data. This is not great from a type-safety perspective, of course. }} @@ -89,7 +91,7 @@ static void MTRClustersLogCompletion(NSString *logPrefix, id value, NSError *err type-safety perspective, of course. }} completion(error); {{/if}} - MTRClustersLogCompletion(logPrefix, value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, {{>callbackName}}CallbackType successCb, MTRErrorCallback failureCb, MTRCallbackBridgeBase * bridge) { diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm b/src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm index 46da7e4c81f63c..795bea30c58be3 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm @@ -84,16 +84,18 @@ - (void)identifyWithParams:(MTRIdentifyClusterIdentifyParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -139,16 +141,18 @@ - (void)triggerEffectWithParams:(MTRIdentifyClusterTriggerEffectParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -318,16 +322,18 @@ - (void)addGroupWithParams:(MTRGroupsClusterAddGroupParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRGroupsClusterAddGroupResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, GroupsClusterAddGroupResponseCallbackType successCb, @@ -375,16 +381,18 @@ - (void)viewGroupWithParams:(MTRGroupsClusterViewGroupParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRGroupsClusterViewGroupResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -431,16 +439,18 @@ - (void)getGroupMembershipWithParams:(MTRGroupsClusterGetGroupMembershipParams * if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRGroupsClusterGetGroupMembershipResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -509,16 +519,18 @@ - (void)removeGroupWithParams:(MTRGroupsClusterRemoveGroupParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRGroupsClusterRemoveGroupResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -574,16 +586,18 @@ - (void)removeAllGroupsWithParams:(MTRGroupsClusterRemoveAllGroupsParams * _Null if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -628,16 +642,18 @@ - (void)addGroupIfIdentifyingWithParams:(MTRGroupsClusterAddGroupIfIdentifyingPa if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -844,16 +860,18 @@ - (void)addSceneWithParams:(MTRScenesClusterAddSceneParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRScenesClusterAddSceneResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, ScenesClusterAddSceneResponseCallbackType successCb, @@ -977,16 +995,18 @@ - (void)viewSceneWithParams:(MTRScenesClusterViewSceneParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRScenesClusterViewSceneResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -1034,16 +1054,18 @@ - (void)removeSceneWithParams:(MTRScenesClusterRemoveSceneParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRScenesClusterRemoveSceneResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -1092,16 +1114,18 @@ - (void)removeAllScenesWithParams:(MTRScenesClusterRemoveAllScenesParams *)param if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRScenesClusterRemoveAllScenesResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -1149,16 +1173,18 @@ - (void)storeSceneWithParams:(MTRScenesClusterStoreSceneParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRScenesClusterStoreSceneResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -1205,16 +1231,18 @@ - (void)recallSceneWithParams:(MTRScenesClusterRecallSceneParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -1271,16 +1299,18 @@ - (void)getSceneMembershipWithParams:(MTRScenesClusterGetSceneMembershipParams * if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRScenesClusterGetSceneMembershipResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -1328,16 +1358,18 @@ - (void)enhancedAddSceneWithParams:(MTRScenesClusterEnhancedAddSceneParams *)par if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRScenesClusterEnhancedAddSceneResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -1462,16 +1494,18 @@ - (void)enhancedViewSceneWithParams:(MTRScenesClusterEnhancedViewSceneParams *)p if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRScenesClusterEnhancedViewSceneResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -1520,16 +1554,18 @@ - (void)copySceneWithParams:(MTRScenesClusterCopySceneParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRScenesClusterCopySceneResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -1837,16 +1873,18 @@ - (void)offWithParams:(MTROnOffClusterOffParams * _Nullable)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -1897,16 +1935,18 @@ - (void)onWithParams:(MTROnOffClusterOnParams * _Nullable)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -1957,16 +1997,18 @@ - (void)toggleWithParams:(MTROnOffClusterToggleParams * _Nullable)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -2011,16 +2053,18 @@ - (void)offWithEffectWithParams:(MTROnOffClusterOffWithEffectParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -2078,16 +2122,18 @@ - (void)onWithRecallGlobalSceneWithParams:(MTROnOffClusterOnWithRecallGlobalScen if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -2132,16 +2178,18 @@ - (void)onWithTimedOffWithParams:(MTROnOffClusterOnWithTimedOffParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -2552,16 +2600,18 @@ - (void)moveToLevelWithParams:(MTRLevelControlClusterMoveToLevelParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -2617,16 +2667,18 @@ - (void)moveWithParams:(MTRLevelControlClusterMoveParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -2683,16 +2735,18 @@ - (void)stepWithParams:(MTRLevelControlClusterStepParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -2750,16 +2804,18 @@ - (void)stopWithParams:(MTRLevelControlClusterStopParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -2808,16 +2864,18 @@ - (void)moveToLevelWithOnOffWithParams:(MTRLevelControlClusterMoveToLevelWithOnO if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -2873,16 +2931,18 @@ - (void)moveWithOnOffWithParams:(MTRLevelControlClusterMoveWithOnOffParams *)par if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -2939,16 +2999,18 @@ - (void)stepWithOnOffWithParams:(MTRLevelControlClusterStepWithOnOffParams *)par if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -3006,16 +3068,18 @@ - (void)stopWithOnOffWithParams:(MTRLevelControlClusterStopWithOnOffParams *)par if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -3064,16 +3128,18 @@ - (void)moveToClosestFrequencyWithParams:(MTRLevelControlClusterMoveToClosestFre if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -4128,16 +4194,18 @@ - (void)instantActionWithParams:(MTRActionsClusterInstantActionParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -4187,16 +4255,18 @@ - (void)instantActionWithTransitionWithParams:(MTRActionsClusterInstantActionWit if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -4247,16 +4317,18 @@ - (void)startActionWithParams:(MTRActionsClusterStartActionParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -4306,16 +4378,18 @@ - (void)startActionWithDurationWithParams:(MTRActionsClusterStartActionWithDurat if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -4366,16 +4440,18 @@ - (void)stopActionWithParams:(MTRActionsClusterStopActionParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -4425,16 +4501,18 @@ - (void)pauseActionWithParams:(MTRActionsClusterPauseActionParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -4484,16 +4562,18 @@ - (void)pauseActionWithDurationWithParams:(MTRActionsClusterPauseActionWithDurat if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -4544,16 +4624,18 @@ - (void)resumeActionWithParams:(MTRActionsClusterResumeActionParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -4603,16 +4685,18 @@ - (void)enableActionWithParams:(MTRActionsClusterEnableActionParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -4662,16 +4746,18 @@ - (void)enableActionWithDurationWithParams:(MTRActionsClusterEnableActionWithDur if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -4722,16 +4808,18 @@ - (void)disableActionWithParams:(MTRActionsClusterDisableActionParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -4781,16 +4869,18 @@ - (void)disableActionWithDurationWithParams:(MTRActionsClusterDisableActionWithD if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -5060,16 +5150,18 @@ - (void)mfgSpecificPingWithParams:(MTRBasicClusterMfgSpecificPingParams * _Nulla if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -5417,16 +5509,18 @@ - (void)queryImageWithParams:(MTROTASoftwareUpdateProviderClusterQueryImageParam if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTROTASoftwareUpdateProviderClusterQueryImageResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -5516,16 +5610,18 @@ - (void)applyUpdateRequestWithParams:(MTROTASoftwareUpdateProviderClusterApplyUp if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTROTASoftwareUpdateProviderClusterApplyUpdateResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -5573,16 +5669,18 @@ - (void)notifyUpdateAppliedWithParams:(MTROTASoftwareUpdateProviderClusterNotify if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -5741,16 +5839,18 @@ - (void)announceOtaProviderWithParams:(MTROTASoftwareUpdateRequestorClusterAnnou if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -6656,16 +6756,18 @@ - (void)armFailSafeWithParams:(MTRGeneralCommissioningClusterArmFailSafeParams * if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRGeneralCommissioningClusterArmFailSafeResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -6714,16 +6816,18 @@ - (void)setRegulatoryConfigWithParams:(MTRGeneralCommissioningClusterSetRegulato if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRGeneralCommissioningClusterSetRegulatoryConfigResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -6787,16 +6891,18 @@ - (void)commissioningCompleteWithParams:(MTRGeneralCommissioningClusterCommissio if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRGeneralCommissioningClusterCommissioningCompleteResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -7030,16 +7136,18 @@ - (void)scanNetworksWithParams:(MTRNetworkCommissioningClusterScanNetworksParams if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRNetworkCommissioningClusterScanNetworksResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -7101,16 +7209,18 @@ - (void)addOrUpdateWiFiNetworkWithParams:(MTRNetworkCommissioningClusterAddOrUpd if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRNetworkCommissioningClusterNetworkConfigResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -7163,16 +7273,18 @@ - (void)addOrUpdateThreadNetworkWithParams:(MTRNetworkCommissioningClusterAddOrU if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRNetworkCommissioningClusterNetworkConfigResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -7224,16 +7336,18 @@ - (void)removeNetworkWithParams:(MTRNetworkCommissioningClusterRemoveNetworkPara if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRNetworkCommissioningClusterNetworkConfigResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -7285,16 +7399,18 @@ - (void)connectNetworkWithParams:(MTRNetworkCommissioningClusterConnectNetworkPa if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRNetworkCommissioningClusterConnectNetworkResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -7346,16 +7462,18 @@ - (void)reorderNetworkWithParams:(MTRNetworkCommissioningClusterReorderNetworkPa if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRNetworkCommissioningClusterNetworkConfigResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -7651,16 +7769,18 @@ - (void)retrieveLogsRequestWithParams:(MTRDiagnosticLogsClusterRetrieveLogsReque if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRDiagnosticLogsClusterRetrieveLogsResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -7791,16 +7911,18 @@ - (void)testEventTriggerWithParams:(MTRGeneralDiagnosticsClusterTestEventTrigger if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -8005,16 +8127,18 @@ - (void)resetWatermarksWithParams:(MTRSoftwareDiagnosticsClusterResetWatermarksP if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -8186,16 +8310,18 @@ - (void)resetCountsWithParams:(MTRThreadNetworkDiagnosticsClusterResetCountsPara if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -8856,16 +8982,18 @@ - (void)resetCountsWithParams:(MTRWiFiNetworkDiagnosticsClusterResetCountsParams if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -9113,16 +9241,18 @@ - (void)resetCountsWithParams:(MTREthernetNetworkDiagnosticsClusterResetCountsPa if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -9622,16 +9752,18 @@ - (void)openCommissioningWindowWithParams:(MTRAdministratorCommissioningClusterO if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -9685,16 +9817,18 @@ - (void)openBasicCommissioningWindowWithParams:(MTRAdministratorCommissioningClu if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -9752,16 +9886,18 @@ - (void)revokeCommissioningWithParams:(MTRAdministratorCommissioningClusterRevok if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -9942,16 +10078,18 @@ - (void)attestationRequestWithParams:(MTROperationalCredentialsClusterAttestatio if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTROperationalCredentialsClusterAttestationResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -9999,16 +10137,18 @@ - (void)certificateChainRequestWithParams:(MTROperationalCredentialsClusterCerti if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTROperationalCredentialsClusterCertificateChainResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -10056,16 +10196,18 @@ - (void)CSRRequestWithParams:(MTROperationalCredentialsClusterCSRRequestParams * if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTROperationalCredentialsClusterCSRResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -10117,16 +10259,18 @@ - (void)addNOCWithParams:(MTROperationalCredentialsClusterAddNOCParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTROperationalCredentialsClusterNOCResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -10182,16 +10326,18 @@ - (void)updateNOCWithParams:(MTROperationalCredentialsClusterUpdateNOCParams *)p if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTROperationalCredentialsClusterNOCResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -10243,16 +10389,18 @@ - (void)updateFabricLabelWithParams:(MTROperationalCredentialsClusterUpdateFabri if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTROperationalCredentialsClusterNOCResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -10300,16 +10448,18 @@ - (void)removeFabricWithParams:(MTROperationalCredentialsClusterRemoveFabricPara if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTROperationalCredentialsClusterNOCResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -10357,16 +10507,18 @@ - (void)addTrustedRootCertificateWithParams:(MTROperationalCredentialsClusterAdd if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -10642,16 +10794,18 @@ - (void)keySetWriteWithParams:(MTRGroupKeyManagementClusterKeySetWriteParams *)p if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -10737,16 +10891,18 @@ - (void)keySetReadWithParams:(MTRGroupKeyManagementClusterKeySetReadParams *)par if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRGroupKeyManagementClusterKeySetReadResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -10793,16 +10949,18 @@ - (void)keySetRemoveWithParams:(MTRGroupKeyManagementClusterKeySetRemoveParams * if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -10849,16 +11007,18 @@ - (void)keySetReadAllIndicesWithParams:(MTRGroupKeyManagementClusterKeySetReadAl if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRGroupKeyManagementClusterKeySetReadAllIndicesResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -11334,16 +11494,18 @@ - (void)changeToModeWithParams:(MTRModeSelectClusterChangeToModeParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -11551,16 +11713,18 @@ - (void)lockDoorWithParams:(MTRDoorLockClusterLockDoorParams * _Nullable)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -11614,16 +11778,18 @@ - (void)unlockDoorWithParams:(MTRDoorLockClusterUnlockDoorParams * _Nullable)par if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -11677,16 +11843,18 @@ - (void)unlockWithTimeoutWithParams:(MTRDoorLockClusterUnlockWithTimeoutParams * if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -11739,16 +11907,18 @@ - (void)setWeekDayScheduleWithParams:(MTRDoorLockClusterSetWeekDayScheduleParams if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -11802,16 +11972,18 @@ - (void)getWeekDayScheduleWithParams:(MTRDoorLockClusterGetWeekDayScheduleParams if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRDoorLockClusterGetWeekDayScheduleResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -11859,16 +12031,18 @@ - (void)clearWeekDayScheduleWithParams:(MTRDoorLockClusterClearWeekDaySchedulePa if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -11915,16 +12089,18 @@ - (void)setYearDayScheduleWithParams:(MTRDoorLockClusterSetYearDayScheduleParams if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -11974,16 +12150,18 @@ - (void)getYearDayScheduleWithParams:(MTRDoorLockClusterGetYearDayScheduleParams if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRDoorLockClusterGetYearDayScheduleResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -12031,16 +12209,18 @@ - (void)clearYearDayScheduleWithParams:(MTRDoorLockClusterClearYearDaySchedulePa if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -12087,16 +12267,18 @@ - (void)setHolidayScheduleWithParams:(MTRDoorLockClusterSetHolidayScheduleParams if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -12147,16 +12329,18 @@ - (void)getHolidayScheduleWithParams:(MTRDoorLockClusterGetHolidayScheduleParams if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRDoorLockClusterGetHolidayScheduleResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -12203,16 +12387,18 @@ - (void)clearHolidayScheduleWithParams:(MTRDoorLockClusterClearHolidaySchedulePa if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -12258,16 +12444,18 @@ - (void)setUserWithParams:(MTRDoorLockClusterSetUserParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -12351,16 +12539,18 @@ - (void)getUserWithParams:(MTRDoorLockClusterGetUserParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRDoorLockClusterGetUserResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -12406,16 +12596,18 @@ - (void)clearUserWithParams:(MTRDoorLockClusterClearUserParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -12465,16 +12657,18 @@ - (void)setCredentialWithParams:(MTRDoorLockClusterSetCredentialParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRDoorLockClusterSetCredentialResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -12551,16 +12745,18 @@ - (void)getCredentialStatusWithParams:(MTRDoorLockClusterGetCredentialStatusPara if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRDoorLockClusterGetCredentialStatusResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -12610,16 +12806,18 @@ - (void)clearCredentialWithParams:(MTRDoorLockClusterClearCredentialParams *)par if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -13602,16 +13800,18 @@ - (void)upOrOpenWithParams:(MTRWindowCoveringClusterUpOrOpenParams * _Nullable)p if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -13665,16 +13865,18 @@ - (void)downOrCloseWithParams:(MTRWindowCoveringClusterDownOrCloseParams * _Null if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -13728,16 +13930,18 @@ - (void)stopMotionWithParams:(MTRWindowCoveringClusterStopMotionParams * _Nullab if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -13782,16 +13986,18 @@ - (void)goToLiftValueWithParams:(MTRWindowCoveringClusterGoToLiftValueParams *)p if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -13837,16 +14043,18 @@ - (void)goToLiftPercentageWithParams:(MTRWindowCoveringClusterGoToLiftPercentage if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -13892,16 +14100,18 @@ - (void)goToTiltValueWithParams:(MTRWindowCoveringClusterGoToTiltValueParams *)p if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -13947,16 +14157,18 @@ - (void)goToTiltPercentageWithParams:(MTRWindowCoveringClusterGoToTiltPercentage if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -14366,16 +14578,18 @@ - (void)barrierControlGoToPercentWithParams:(MTRBarrierControlClusterBarrierCont if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -14430,16 +14644,18 @@ - (void)barrierControlStopWithParams:(MTRBarrierControlClusterBarrierControlStop if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -15117,16 +15333,18 @@ - (void)setpointRaiseLowerWithParams:(MTRThermostatClusterSetpointRaiseLowerPara if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -15173,16 +15391,18 @@ - (void)setWeeklyScheduleWithParams:(MTRThermostatClusterSetWeeklyScheduleParams if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -15267,16 +15487,18 @@ - (void)getWeeklyScheduleWithParams:(MTRThermostatClusterGetWeeklyScheduleParams if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRThermostatClusterGetWeeklyScheduleResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -15335,16 +15557,18 @@ - (void)clearWeeklyScheduleWithParams:(MTRThermostatClusterClearWeeklySchedulePa if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -16869,16 +17093,18 @@ - (void)moveToHueWithParams:(MTRColorControlClusterMoveToHueParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -16929,16 +17155,18 @@ - (void)moveHueWithParams:(MTRColorControlClusterMoveHueParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -16988,16 +17216,18 @@ - (void)stepHueWithParams:(MTRColorControlClusterStepHueParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17048,16 +17278,18 @@ - (void)moveToSaturationWithParams:(MTRColorControlClusterMoveToSaturationParams if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17106,16 +17338,18 @@ - (void)moveSaturationWithParams:(MTRColorControlClusterMoveSaturationParams *)p if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17165,16 +17399,18 @@ - (void)stepSaturationWithParams:(MTRColorControlClusterStepSaturationParams *)p if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17225,16 +17461,18 @@ - (void)moveToHueAndSaturationWithParams:(MTRColorControlClusterMoveToHueAndSatu if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17284,16 +17522,18 @@ - (void)moveToColorWithParams:(MTRColorControlClusterMoveToColorParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17343,16 +17583,18 @@ - (void)moveColorWithParams:(MTRColorControlClusterMoveColorParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17401,16 +17643,18 @@ - (void)stepColorWithParams:(MTRColorControlClusterStepColorParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17460,16 +17704,18 @@ - (void)moveToColorTemperatureWithParams:(MTRColorControlClusterMoveToColorTempe if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17518,16 +17764,18 @@ - (void)enhancedMoveToHueWithParams:(MTRColorControlClusterEnhancedMoveToHuePara if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17578,16 +17826,18 @@ - (void)enhancedMoveHueWithParams:(MTRColorControlClusterEnhancedMoveHueParams * if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17637,16 +17887,18 @@ - (void)enhancedStepHueWithParams:(MTRColorControlClusterEnhancedStepHueParams * if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17697,16 +17949,18 @@ - (void)enhancedMoveToHueAndSaturationWithParams:(MTRColorControlClusterEnhanced if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17756,16 +18010,18 @@ - (void)colorLoopSetWithParams:(MTRColorControlClusterColorLoopSetParams *)param if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17819,16 +18075,18 @@ - (void)stopMoveStepWithParams:(MTRColorControlClusterStopMoveStepParams *)param if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17875,16 +18133,18 @@ - (void)moveColorTemperatureWithParams:(MTRColorControlClusterMoveColorTemperatu if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -17936,16 +18196,18 @@ - (void)stepColorTemperatureWithParams:(MTRColorControlClusterStepColorTemperatu if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -20342,16 +20604,18 @@ - (void)changeChannelWithParams:(MTRChannelClusterChangeChannelParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRChannelClusterChangeChannelResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -20398,16 +20662,18 @@ - (void)changeChannelByNumberWithParams:(MTRChannelClusterChangeChannelByNumberP if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -20454,16 +20720,18 @@ - (void)skipChannelWithParams:(MTRChannelClusterSkipChannelParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -20634,16 +20902,18 @@ - (void)navigateTargetWithParams:(MTRTargetNavigatorClusterNavigateTargetParams if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRTargetNavigatorClusterNavigateTargetResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -20799,16 +21069,18 @@ - (void)playWithParams:(MTRMediaPlaybackClusterPlayParams * _Nullable)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRMediaPlaybackClusterPlaybackResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -20862,16 +21134,18 @@ - (void)pauseWithParams:(MTRMediaPlaybackClusterPauseParams * _Nullable)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRMediaPlaybackClusterPlaybackResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -20928,16 +21202,18 @@ - (void)stopPlaybackWithParams:(MTRMediaPlaybackClusterStopPlaybackParams * _Nul if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRMediaPlaybackClusterPlaybackResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -20994,16 +21270,18 @@ - (void)startOverWithParams:(MTRMediaPlaybackClusterStartOverParams * _Nullable) if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRMediaPlaybackClusterPlaybackResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -21057,16 +21335,18 @@ - (void)previousWithParams:(MTRMediaPlaybackClusterPreviousParams * _Nullable)pa if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRMediaPlaybackClusterPlaybackResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -21120,16 +21400,18 @@ - (void)nextWithParams:(MTRMediaPlaybackClusterNextParams * _Nullable)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRMediaPlaybackClusterPlaybackResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -21183,16 +21465,18 @@ - (void)rewindWithParams:(MTRMediaPlaybackClusterRewindParams * _Nullable)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRMediaPlaybackClusterPlaybackResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -21249,16 +21533,18 @@ - (void)fastForwardWithParams:(MTRMediaPlaybackClusterFastForwardParams * _Nulla if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRMediaPlaybackClusterPlaybackResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -21305,16 +21591,18 @@ - (void)skipForwardWithParams:(MTRMediaPlaybackClusterSkipForwardParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRMediaPlaybackClusterPlaybackResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -21362,16 +21650,18 @@ - (void)skipBackwardWithParams:(MTRMediaPlaybackClusterSkipBackwardParams *)para if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRMediaPlaybackClusterPlaybackResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -21419,16 +21709,18 @@ - (void)seekWithParams:(MTRMediaPlaybackClusterSeekParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRMediaPlaybackClusterPlaybackResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -21831,16 +22123,18 @@ - (void)selectInputWithParams:(MTRMediaInputClusterSelectInputParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -21895,16 +22189,18 @@ - (void)showInputStatusWithParams:(MTRMediaInputClusterShowInputStatusParams * _ if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -21958,16 +22254,18 @@ - (void)hideInputStatusWithParams:(MTRMediaInputClusterHideInputStatusParams * _ if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -22012,16 +22310,18 @@ - (void)renameInputWithParams:(MTRMediaInputClusterRenameInputParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -22214,16 +22514,18 @@ - (void)sleepWithParams:(MTRLowPowerClusterSleepParams * _Nullable)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -22354,16 +22656,18 @@ - (void)sendKeyWithParams:(MTRKeypadInputClusterSendKeyParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRKeypadInputClusterSendKeyResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -22491,16 +22795,18 @@ - (void)launchContentWithParams:(MTRContentLauncherClusterLaunchContentParams *) if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRContentLauncherClusterLaunchResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -22605,16 +22911,18 @@ - (void)launchURLWithParams:(MTRContentLauncherClusterLaunchURLParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRContentLauncherClusterLaunchResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -22891,16 +23199,18 @@ - (void)selectOutputWithParams:(MTRAudioOutputClusterSelectOutputParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -22946,16 +23256,18 @@ - (void)renameOutputWithParams:(MTRAudioOutputClusterRenameOutputParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -23105,16 +23417,18 @@ - (void)launchAppWithParams:(MTRApplicationLauncherClusterLaunchAppParams *)para if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRApplicationLauncherClusterLauncherResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -23167,16 +23481,18 @@ - (void)stopAppWithParams:(MTRApplicationLauncherClusterStopAppParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRApplicationLauncherClusterLauncherResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -23225,16 +23541,18 @@ - (void)hideAppWithParams:(MTRApplicationLauncherClusterHideAppParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRApplicationLauncherClusterLauncherResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -23556,16 +23874,18 @@ - (void)getSetupPINWithParams:(MTRAccountLoginClusterGetSetupPINParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRAccountLoginClusterGetSetupPINResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -23615,16 +23935,18 @@ - (void)loginWithParams:(MTRAccountLoginClusterLoginParams *)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -23680,16 +24002,18 @@ - (void)logoutWithParams:(MTRAccountLoginClusterLogoutParams * _Nullable)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -23855,16 +24179,18 @@ - (void)getProfileInfoCommandWithParams:(MTRElectricalMeasurementClusterGetProfi if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -23910,16 +24236,18 @@ - (void)getMeasurementProfileCommandWithParams:(MTRElectricalMeasurementClusterG if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -25305,16 +25633,18 @@ - (void)testWithParams:(MTRUnitTestingClusterTestParams * _Nullable)params if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -25368,16 +25698,18 @@ - (void)testNotHandledWithParams:(MTRUnitTestingClusterTestNotHandledParams * _N if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -25433,16 +25765,18 @@ - (void)testSpecificWithParams:(MTRUnitTestingClusterTestSpecificParams * _Nulla if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterTestSpecificResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -25497,16 +25831,18 @@ - (void)testUnknownCommandWithParams:(MTRUnitTestingClusterTestUnknownCommandPar if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -25552,16 +25888,18 @@ - (void)testAddArgumentsWithParams:(MTRUnitTestingClusterTestAddArgumentsParams if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterTestAddArgumentsResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -25610,16 +25948,18 @@ - (void)testSimpleArgumentRequestWithParams:(MTRUnitTestingClusterTestSimpleArgu if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterTestSimpleArgumentResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -25668,16 +26008,18 @@ - (void)testStructArrayArgumentRequestWithParams:(MTRUnitTestingClusterTestStruc if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterTestStructArrayArgumentResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -25936,16 +26278,18 @@ - (void)testStructArgumentRequestWithParams:(MTRUnitTestingClusterTestStructArgu if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterBooleanResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -26000,16 +26344,18 @@ - (void)testNestedStructArgumentRequestWithParams:(MTRUnitTestingClusterTestNest if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterBooleanResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -26068,16 +26414,18 @@ - (void)testListStructArgumentRequestWithParams:(MTRUnitTestingClusterTestListSt if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterBooleanResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -26155,16 +26503,18 @@ - (void)testListInt8UArgumentRequestWithParams:(MTRUnitTestingClusterTestListInt if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterBooleanResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -26233,16 +26583,18 @@ - (void)testNestedStructListArgumentRequestWithParams:(MTRUnitTestingClusterTest if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterBooleanResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -26400,16 +26752,18 @@ - (void)testListNestedStructListArgumentRequestWithParams: if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterBooleanResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -26590,16 +26944,18 @@ - (void)testListInt8UReverseRequestWithParams:(MTRUnitTestingClusterTestListInt8 if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterTestListInt8UReverseResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -26668,16 +27024,18 @@ - (void)testEnumsRequestWithParams:(MTRUnitTestingClusterTestEnumsRequestParams if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterTestEnumsResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -26726,16 +27084,18 @@ - (void)testNullableOptionalRequestWithParams:(MTRUnitTestingClusterTestNullable if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterTestNullableOptionalResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -26795,16 +27155,18 @@ - (void)testComplexNullableOptionalRequestWithParams:(MTRUnitTestingClusterTestC if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterTestComplexNullableOptionalResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -27021,16 +27383,18 @@ - (void)simpleStructEchoRequestWithParams:(MTRUnitTestingClusterSimpleStructEcho if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterSimpleStructResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -27093,16 +27457,18 @@ - (void)timedInvokeRequestWithParams:(MTRUnitTestingClusterTimedInvokeRequestPar if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -27150,16 +27516,18 @@ - (void)testSimpleOptionalArgumentRequestWithParams:(MTRUnitTestingClusterTestSi if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRCommandSuccessCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, CommandSuccessCallbackType successCb, @@ -27211,16 +27579,18 @@ - (void)testEmitTestEventRequestWithParams:(MTRUnitTestingClusterTestEmitTestEve if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterTestEmitTestEventResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session, @@ -27274,16 +27644,18 @@ - (void)testEmitTestEventRequestWithParams:(MTRUnitTestingClusterTestEmitTestEve if (timedInvokeTimeoutMsParam) { timedInvokeTimeoutMsParam = MTRClampedNumber(timedInvokeTimeoutMsParam, @(1), @(UINT16_MAX)); } - MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue]; + MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.device.queue]; MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) { MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue); MTRBaseDevice * baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController]; auto * bridge = new MTRUnitTestingClusterTestEmitTestFabricScopedEventResponseCallbackBridge( - self.callbackQueue, + self.device.queue, ^(id _Nullable value, NSError * _Nullable error) { - completion(value, error); MTRClustersLogCompletion(logPrefix, value, error); + dispatch_async(self.callbackQueue, ^{ + completion(value, error); + }); [workItem endWork]; }, ^(ExchangeManager & exchangeManager, const SessionHandle & session,