From 2796663724a497a290a00cf096d47ccf0b59a903 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 22 Aug 2024 13:13:04 -0400 Subject: [PATCH] Remove unnecessary invokeCommand overrides from MTRDevice_Concrete. (#35151) The one part that is not shared with the XPC implementation is _invokeCommandWithEndpointID:.... Everything else is just generic argument massaging and forwarding that can keep living in the base MTRDevice. --- .../Framework/CHIP/MTRDevice_Concrete.mm | 126 ------------------ 1 file changed, 126 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm b/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm index 120d29aff122d4..12614ea4091b0c 100644 --- a/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm +++ b/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm @@ -2835,59 +2835,6 @@ - (void)writeAttributeWithEndpointID:(NSNumber *)endpointID [_asyncWorkQueue enqueueWorkItem:workItem descriptionWithFormat:@"write %@ 0x%llx 0x%llx", endpointID, clusterID.unsignedLongLongValue, attributeID.unsignedLongLongValue]; } -- (void)invokeCommandWithEndpointID:(NSNumber *)endpointID - clusterID:(NSNumber *)clusterID - commandID:(NSNumber *)commandID - commandFields:(NSDictionary * _Nullable)commandFields - expectedValues:(NSArray *> * _Nullable)expectedValues - expectedValueInterval:(NSNumber * _Nullable)expectedValueInterval - queue:(dispatch_queue_t)queue - completion:(MTRDeviceResponseHandler)completion -{ - if (commandFields == nil) { - commandFields = @{ - MTRTypeKey : MTRStructureValueType, - MTRValueKey : @[], - }; - } - - [self invokeCommandWithEndpointID:endpointID - clusterID:clusterID - commandID:commandID - commandFields:commandFields - expectedValues:expectedValues - expectedValueInterval:expectedValueInterval - timedInvokeTimeout:nil - queue:queue - completion:completion]; -} - -- (void)invokeCommandWithEndpointID:(NSNumber *)endpointID - clusterID:(NSNumber *)clusterID - commandID:(NSNumber *)commandID - commandFields:(id)commandFields - expectedValues:(NSArray *> * _Nullable)expectedValues - expectedValueInterval:(NSNumber * _Nullable)expectedValueInterval - timedInvokeTimeout:(NSNumber * _Nullable)timeout - queue:(dispatch_queue_t)queue - completion:(MTRDeviceResponseHandler)completion -{ - // We don't have a way to communicate a non-default invoke timeout - // here for now. - // TODO: https://github.com/project-chip/connectedhomeip/issues/24563 - - [self _invokeCommandWithEndpointID:endpointID - clusterID:clusterID - commandID:commandID - commandFields:commandFields - expectedValues:expectedValues - expectedValueInterval:expectedValueInterval - timedInvokeTimeout:timeout - serverSideProcessingTimeout:nil - queue:queue - completion:completion]; -} - - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID clusterID:(NSNumber *)clusterID commandID:(NSNumber *)commandID @@ -2985,58 +2932,6 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID [_asyncWorkQueue enqueueWorkItem:workItem descriptionWithFormat:@"invoke %@ 0x%llx 0x%llx", endpointID, clusterID.unsignedLongLongValue, commandID.unsignedLongLongValue]; } -- (void)_invokeKnownCommandWithEndpointID:(NSNumber *)endpointID - clusterID:(NSNumber *)clusterID - commandID:(NSNumber *)commandID - commandPayload:(id)commandPayload - expectedValues:(NSArray *> * _Nullable)expectedValues - expectedValueInterval:(NSNumber * _Nullable)expectedValueInterval - timedInvokeTimeout:(NSNumber * _Nullable)timeout - serverSideProcessingTimeout:(NSNumber * _Nullable)serverSideProcessingTimeout - responseClass:(Class _Nullable)responseClass - queue:(dispatch_queue_t)queue - completion:(void (^)(id _Nullable response, NSError * _Nullable error))completion -{ - if (![commandPayload respondsToSelector:@selector(_encodeAsDataValue:)]) { - dispatch_async(queue, ^{ - completion(nil, [MTRError errorForCHIPErrorCode:CHIP_ERROR_INVALID_ARGUMENT]); - }); - return; - } - - NSError * encodingError; - auto * commandFields = [commandPayload _encodeAsDataValue:&encodingError]; - if (commandFields == nil) { - dispatch_async(queue, ^{ - completion(nil, encodingError); - }); - return; - } - - auto responseHandler = ^(NSArray *> * _Nullable values, NSError * _Nullable error) { - id _Nullable response = nil; - if (error == nil) { - if (values.count != 1) { - error = [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeSchemaMismatch userInfo:nil]; - } else if (responseClass != nil) { - response = [[responseClass alloc] initWithResponseValue:values[0] error:&error]; - } - } - completion(response, error); - }; - - [self _invokeCommandWithEndpointID:endpointID - clusterID:clusterID - commandID:commandID - commandFields:commandFields - expectedValues:expectedValues - expectedValueInterval:expectedValueInterval - timedInvokeTimeout:timeout - serverSideProcessingTimeout:serverSideProcessingTimeout - queue:queue - completion:responseHandler]; -} - - (void)openCommissioningWindowWithSetupPasscode:(NSNumber *)setupPasscode discriminator:(NSNumber *)discriminator duration:(NSNumber *)duration @@ -4072,27 +3967,6 @@ + (MTRDevice *)deviceWithNodeID:(uint64_t)nodeID deviceController:(MTRDeviceCont return [self deviceWithNodeID:@(nodeID) controller:deviceController]; } -- (void)invokeCommandWithEndpointID:(NSNumber *)endpointID - clusterID:(NSNumber *)clusterID - commandID:(NSNumber *)commandID - commandFields:(id)commandFields - expectedValues:(NSArray *> * _Nullable)expectedValues - expectedValueInterval:(NSNumber * _Nullable)expectedValueInterval - timedInvokeTimeout:(NSNumber * _Nullable)timeout - clientQueue:(dispatch_queue_t)queue - completion:(MTRDeviceResponseHandler)completion -{ - [self invokeCommandWithEndpointID:endpointID - clusterID:clusterID - commandID:commandID - commandFields:commandFields - expectedValues:expectedValues - expectedValueInterval:expectedValueInterval - timedInvokeTimeout:timeout - queue:queue - completion:completion]; -} - @end #pragma mark - SubscriptionCallback