Skip to content

Commit

Permalink
Restyled and also remove commented out code
Browse files Browse the repository at this point in the history
  • Loading branch information
jtung-apple committed Oct 16, 2024
1 parent 8234e8c commit 97926a2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/MTRDeviceController_XPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ MTR_TESTABLE
- (id)initWithUniqueIdentifier:(NSUUID *)UUID machServiceName:(NSString *)machServiceName options:(NSXPCConnectionOptions)options
#endif

@property(nullable, atomic, retain, readwrite) NSXPCConnection * xpcConnection;
@property(atomic, readonly) BOOL isRunning;
@property(nullable, atomic, retain, readwrite)NSXPCConnection * xpcConnection;
@property (atomic, readonly) BOOL isRunning;

@end

Expand Down
17 changes: 7 additions & 10 deletions src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,6 @@ - (MTRDevice *)_setupDeviceForNodeID:(NSNumber *)nodeID prefetchedClusterData:(N

#pragma mark - XPC Action Overrides

//MTR_DEVICECONTROLLER_SIMPLE_REMOTE_XPC_GETTER(isRunning, BOOL, NO, getIsRunningWithReply)
//MTR_DEVICECONTROLLER_SIMPLE_REMOTE_XPC_GETTER(controllerNodeID, NSNumber *, nil, controllerNodeIDWithReply)

// Not Supported via XPC
// - (oneway void)deviceController:(NSUUID *)controller setupCommissioningSessionWithPayload:(MTRSetupPayload *)payload newNodeID:(NSNumber *)newNodeID withReply:(void(^)(BOOL success, NSError * _Nullable error))reply;
// - (oneway void)deviceController:(NSUUID *)controller setupCommissioningSessionWithDiscoveredDevice:(MTRCommissionableBrowserResult *)discoveredDevice payload:(MTRSetupPayload *)payload newNodeID:(NSNumber *)newNodeID withReply:(void(^)(BOOL success, NSError * _Nullable error))reply;
Expand Down Expand Up @@ -452,31 +449,31 @@ - (oneway void)controller:(NSUUID *)controller controllerConfigurationUpdated:(N
// ]
// }

NSDictionary *controllerContext = configuration[MTRDeviceControllerRegistrationControllerContextKey];
NSNumber *controllerNodeID = controllerContext[MTRDeviceControllerRegistrationControllerNodeIDKey];
NSDictionary * controllerContext = configuration[MTRDeviceControllerRegistrationControllerContextKey];
NSNumber * controllerNodeID = controllerContext[MTRDeviceControllerRegistrationControllerNodeIDKey];
if (controllerNodeID && [controllerNodeID isKindOfClass:[NSNumber class]]) {
_controllerNodeID = controllerContext[MTRDeviceControllerRegistrationControllerNodeIDKey];
}
NSNumber *isRunning = controllerContext[MTRDeviceControllerRegistrationControllerIsRunningKey];
NSNumber * isRunning = controllerContext[MTRDeviceControllerRegistrationControllerIsRunningKey];
if (isRunning && [isRunning isKindOfClass:[NSNumber class]]) {
_isRunning = isRunning.boolValue;
}

NSArray *deviceInfoList = configuration[MTRDeviceControllerRegistrationNodeIDsKey];
NSArray * deviceInfoList = configuration[MTRDeviceControllerRegistrationNodeIDsKey];

MTR_LOG("Received controllerConfigurationUpdated: controllerNode ID %@ deviceInfoList %@", self.controllerNodeID, deviceInfoList);

for (NSDictionary *deviceInfo in deviceInfoList) {
for (NSDictionary * deviceInfo in deviceInfoList) {
if (![deviceInfo isKindOfClass:[NSDictionary class]]) {
MTR_LOG_ERROR(" - deviceInfo %@ not NSDictionary class %@", deviceInfo, NSStringFromClass([deviceInfo class]));
continue;
}
NSNumber *nodeID = deviceInfo[MTRDeviceControllerRegistrationNodeIDKey];
NSNumber * nodeID = deviceInfo[MTRDeviceControllerRegistrationNodeIDKey];
if (nodeID && ![nodeID isKindOfClass:[NSNumber class]]) {
MTR_LOG_ERROR(" - deviceInfo %@ nodeID not NSNumber class %@", deviceInfo, NSStringFromClass([nodeID class]));
continue;
}
NSDictionary *deviceInternalState = deviceInfo[MTRDeviceControllerRegistrationDeviceInternalStateKey];
NSDictionary * deviceInternalState = deviceInfo[MTRDeviceControllerRegistrationDeviceInternalStateKey];
if (deviceInternalState && ![deviceInternalState isKindOfClass:[NSDictionary class]]) {
MTR_LOG_ERROR(" - deviceInfo %@ deviceInternalState not NSNumber class %@", deviceInfo, NSStringFromClass([deviceInternalState class]));
continue;
Expand Down
17 changes: 5 additions & 12 deletions src/darwin/Framework/CHIP/MTRDevice_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,15 @@ - (oneway void)device:(NSNumber *)nodeID internalStateUpdated:(NSDictionary *)di
MTR_LOG("%@ %s", self, __PRETTY_FUNCTION__);

// Save old state for comparison later
NSNumber *oldStateNumber = self._internalState[kMTRDeviceInternalPropertyDeviceState];
NSNumber *newStateNumber = dictionary[kMTRDeviceInternalPropertyDeviceState];
NSNumber * oldStateNumber = self._internalState[kMTRDeviceInternalPropertyDeviceState];
NSNumber * newStateNumber = dictionary[kMTRDeviceInternalPropertyDeviceState];
[self _setInternalState:dictionary];

// Call delegate if state changed. State is considered changed if:
// 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])) {
if ((!oldStateNumber && newStateNumber) || (oldStateNumber && !newStateNumber) || (oldStateNumber && newStateNumber && ![newStateNumber isEqualToNumber:oldStateNumber])) {
MTRDeviceState state = static_cast<MTRDeviceState>(newStateNumber ? newStateNumber.unsignedIntegerValue : MTRDeviceStateUnknown);
[self _lockAndCallDelegatesWithBlock:^(id<MTRDeviceDelegate> delegate) {
[delegate device:self stateChanged:state];
Expand All @@ -213,13 +211,13 @@ - (oneway void)device:(NSNumber *)nodeID internalStateUpdated:(NSDictionary *)di

- (MTRDeviceState)state
{
NSNumber *stateNumber = self._internalState[kMTRDeviceInternalPropertyDeviceState];
NSNumber * stateNumber = self._internalState[kMTRDeviceInternalPropertyDeviceState];
return stateNumber ? static_cast<MTRDeviceState>(stateNumber.unsignedIntegerValue) : MTRDeviceStateUnknown;
}

- (BOOL)deviceCachePrimed
{
NSNumber *deviceCachePrimedNumber = self._internalState[kMTRDeviceInternalPropertyDeviceCachePrimed];
NSNumber * deviceCachePrimedNumber = self._internalState[kMTRDeviceInternalPropertyDeviceCachePrimed];
return deviceCachePrimedNumber.boolValue;
}

Expand All @@ -235,11 +233,6 @@ - (NSNumber *)estimatedSubscriptionLatency

#pragma mark - Remote Commands

//MTR_DEVICE_SIMPLE_REMOTE_XPC_GETTER(state, MTRDeviceState, MTRDeviceStateUnknown, getStateWithReply)
//MTR_DEVICE_SIMPLE_REMOTE_XPC_GETTER(deviceCachePrimed, BOOL, NO, getDeviceCachePrimedWithReply)
//MTR_DEVICE_SIMPLE_REMOTE_XPC_GETTER(estimatedStartTime, NSDate * _Nullable, nil, getEstimatedStartTimeWithReply)
//MTR_DEVICE_SIMPLE_REMOTE_XPC_GETTER(estimatedSubscriptionLatency, NSNumber * _Nullable, nil, getEstimatedSubscriptionLatencyWithReply)

typedef NSDictionary<NSString *, id> * _Nullable ReadAttributeResponseType;
MTR_DEVICE_COMPLEX_REMOTE_XPC_GETTER(readAttributeWithEndpointID
: (NSNumber *) endpointID clusterID
Expand Down

0 comments on commit 97926a2

Please sign in to comment.