Skip to content

Commit

Permalink
Addressing these
Browse files Browse the repository at this point in the history
  • Loading branch information
woody-apple committed Oct 28, 2024
1 parent a376079 commit d975f78
Showing 1 changed file with 20 additions and 48 deletions.
68 changes: 20 additions & 48 deletions src/darwin/Framework/CHIP/MTRDevice_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,14 @@

#import <os/lock.h>

#define MTR_DEVICE_SIMPLE_REMOTE_XPC_GETTER(NAME, TYPE, DEFAULT_VALUE, GETTER_NAME) \
MTR_SIMPLE_REMOTE_XPC_GETTER([(MTRDeviceController_XPC *) [self deviceController] xpcConnection], NAME, TYPE, DEFAULT_VALUE, GETTER_NAME, deviceController \
: [[self deviceController] uniqueIdentifier] nodeID \
: [self nodeID])
#define MTR_DEVICE_SIMPLE_REMOTE_XPC_GETTER(NAME, TYPE, DEFAULT_VALUE, GETTER_NAME) \
MTR_SIMPLE_REMOTE_XPC_GETTER([(MTRDeviceController_XPC *) [self deviceController] xpcConnection], NAME, TYPE, DEFAULT_VALUE, GETTER_NAME, deviceController : [[self deviceController] uniqueIdentifier] nodeID : [self nodeID])

#define MTR_DEVICE_COMPLEX_REMOTE_XPC_GETTER(SIGNATURE, TYPE, DEFAULT_VALUE, ADDITIONAL_ARGUMENTS) \
MTR_COMPLEX_REMOTE_XPC_GETTER([(MTRDeviceController_XPC *) [self deviceController] xpcConnection], SIGNATURE, TYPE, DEFAULT_VALUE, ADDITIONAL_ARGUMENTS, deviceController \
: [[self deviceController] uniqueIdentifier] nodeID \
: [self nodeID])
#define MTR_DEVICE_COMPLEX_REMOTE_XPC_GETTER(SIGNATURE, TYPE, DEFAULT_VALUE, ADDITIONAL_ARGUMENTS) \
MTR_COMPLEX_REMOTE_XPC_GETTER([(MTRDeviceController_XPC *) [self deviceController] xpcConnection], SIGNATURE, TYPE, DEFAULT_VALUE, ADDITIONAL_ARGUMENTS, deviceController : [[self deviceController] uniqueIdentifier] nodeID : [self nodeID])

#define MTR_DEVICE_SIMPLE_REMOTE_XPC_COMMAND(METHOD_SIGNATURE, ADDITIONAL_ARGUMENTS) \
MTR_SIMPLE_REMOTE_XPC_COMMAND([(MTRDeviceController_XPC *) [self deviceController] xpcConnection], METHOD_SIGNATURE, ADDITIONAL_ARGUMENTS, deviceController \
: [[self deviceController] uniqueIdentifier] nodeID \
: [self nodeID])
#define MTR_DEVICE_SIMPLE_REMOTE_XPC_COMMAND(METHOD_SIGNATURE, ADDITIONAL_ARGUMENTS) \
MTR_SIMPLE_REMOTE_XPC_COMMAND([(MTRDeviceController_XPC *) [self deviceController] xpcConnection], METHOD_SIGNATURE, ADDITIONAL_ARGUMENTS, deviceController : [[self deviceController] uniqueIdentifier] nodeID : [self nodeID])

@implementation MTRDevice_XPC

Expand Down Expand Up @@ -278,8 +272,8 @@ - (oneway void)device:(NSNumber *)nodeID internalStateUpdated:(NSDictionary *)di
return;
}

NSNumber * oldStateNumber = self._internalState[kMTRDeviceInternalPropertyDeviceState];
NSNumber * newStateNumber = dictionary[kMTRDeviceInternalPropertyDeviceState];
NSNumber * oldStateNumber = MTR_SAFE_CAST(self._internalState[kMTRDeviceInternalPropertyDeviceState], NSNumber);
NSNumber * newStateNumber = MTR_SAFE_CAST(MTR_dictionary[kMTRDeviceInternalPropertyDeviceState], NSNumber);

VerifyOrReturn([self _internalState:dictionary hasValidValuesForKeys:requiredInternalStateKeys valueRequired:YES]);
VerifyOrReturn([self _internalState:dictionary hasValidValuesForKeys:optionalInternalStateKeys valueRequired:NO]);
Expand All @@ -290,8 +284,8 @@ - (oneway void)device:(NSNumber *)nodeID internalStateUpdated:(NSDictionary *)di
// 1) old state is nil but new state is not nil
// 2) old state is not nil but new state is nil
// 3) both old and new state are not nil, and they are not equal
if ((!oldStateNumber && newStateNumber) || (oldStateNumber && !newStateNumber) || (oldStateNumber && newStateNumber && ![newStateNumber isEqualToNumber:oldStateNumber])) {
MTRDeviceState state = static_cast<MTRDeviceState>(newStateNumber ? newStateNumber.unsignedIntegerValue : MTRDeviceStateUnknown);
if (!MTREqualObjects(oldStateNumber, newStateNumber)) {
MTRDeviceState state = self.state;
[self _lockAndCallDelegatesWithBlock:^(id<MTRDeviceDelegate> delegate) {
[delegate device:self stateChanged:state];
}];
Expand Down Expand Up @@ -323,40 +317,18 @@ - (nullable NSNumber *)estimatedSubscriptionLatency
#pragma mark - Remote Commands

typedef NSDictionary<NSString *, id> * _Nullable ReadAttributeResponseType;
MTR_DEVICE_COMPLEX_REMOTE_XPC_GETTER(readAttributeWithEndpointID
: (NSNumber *) endpointID clusterID
: (NSNumber *) clusterID attributeID
: (NSNumber *) attributeID params
: (MTRReadParams * _Nullable) params,
ReadAttributeResponseType,
nil,
readAttributeWithEndpointID
: endpointID clusterID
: clusterID attributeID
: attributeID params
: params withReply)

MTR_DEVICE_SIMPLE_REMOTE_XPC_COMMAND(writeAttributeWithEndpointID
: (NSNumber *) endpointID clusterID
: (NSNumber *) clusterID attributeID
: (NSNumber *) attributeID value
: (id) value expectedValueInterval
: (NSNumber *) expectedValueInterval timedWriteTimeout
: (NSNumber * _Nullable) timeout, writeAttributeWithEndpointID
: endpointID clusterID
: clusterID attributeID
: attributeID value
: value expectedValueInterval
: expectedValueInterval timedWriteTimeout
: timeout)
MTR_DEVICE_COMPLEX_REMOTE_XPC_GETTER(readAttributeWithEndpointID : (NSNumber *) endpointID clusterID : (NSNumber *) clusterID attributeID : (NSNumber *) attributeID params : (MTRReadParams * _Nullable) params,
ReadAttributeResponseType,
nil,
readAttributeWithEndpointID : endpointID clusterID : clusterID attributeID : attributeID params : params withReply)

MTR_DEVICE_SIMPLE_REMOTE_XPC_COMMAND(writeAttributeWithEndpointID : (NSNumber *) endpointID clusterID : (NSNumber *) clusterID attributeID : (NSNumber *) attributeID value : (id) value expectedValueInterval : (NSNumber *) expectedValueInterval timedWriteTimeout : (NSNumber * _Nullable) timeout, writeAttributeWithEndpointID : endpointID clusterID : clusterID attributeID : attributeID value : value expectedValueInterval : expectedValueInterval timedWriteTimeout : timeout)

typedef NSArray<NSDictionary<NSString *, id> *> * ReadAttributePathsResponseType;
MTR_DEVICE_COMPLEX_REMOTE_XPC_GETTER(readAttributePaths
: (NSArray<MTRAttributeRequestPath *> *) attributePaths,
ReadAttributePathsResponseType,
[NSArray array], // Default return value
readAttributePaths
: attributePaths withReply)
MTR_DEVICE_COMPLEX_REMOTE_XPC_GETTER(readAttributePaths : (NSArray<MTRAttributeRequestPath *> *) attributePaths,
ReadAttributePathsResponseType,
[NSArray array], // Default return value
readAttributePaths : attributePaths withReply)

- (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
clusterID:(NSNumber *)clusterID
Expand Down

0 comments on commit d975f78

Please sign in to comment.