Skip to content

Commit

Permalink
Restyled changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jtung-apple committed Sep 8, 2024
1 parent 7fb8684 commit 7e64c47
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@

@interface MTRDeviceControllerDelegateInfo : NSObject
- (instancetype)initWithDelegate:(id<MTRDeviceControllerDelegate>)delegate queue:(dispatch_queue_t)queue;
@property(nonatomic, weak, readonly) id<MTRDeviceControllerDelegate> delegate;
@property(nonatomic, readonly) dispatch_queue_t queue;
@property (nonatomic, weak, readonly) id<MTRDeviceControllerDelegate> delegate;
@property (nonatomic, readonly) dispatch_queue_t queue;
@end

@implementation MTRDeviceControllerDelegateInfo
Expand Down Expand Up @@ -161,7 +161,7 @@ @implementation MTRDeviceController {
BOOL _shutdownPending;
os_unfair_lock _assertionLock;

NSMutableSet<MTRDeviceControllerDelegateInfo *> *_delegates;
NSMutableSet<MTRDeviceControllerDelegateInfo *> * _delegates;
id<MTRDeviceControllerDelegate> _strongDelegateForSetDelegateAPI;
}

Expand Down Expand Up @@ -599,7 +599,7 @@ - (void)cleanup
if (_deviceControllerDelegateBridge) {
delete _deviceControllerDelegateBridge;
_deviceControllerDelegateBridge = nullptr;
@synchronized (self) {
@synchronized(self) {
_strongDelegateForSetDelegateAPI = nil;
[_delegates removeAllObjects];
}
Expand Down Expand Up @@ -1783,26 +1783,26 @@ + (void)forceLocalhostAdvertisingOnly
// Note these are implemented in the base class so that XPC subclass can use it as well when it
- (void)setDeviceControllerDelegate:(id<MTRDeviceControllerDelegate>)delegate queue:(dispatch_queue_t)queue
{
@synchronized (self) {
@synchronized(self) {
_strongDelegateForSetDelegateAPI = delegate;
[self addDeviceControllerDelegate:delegate queue:queue];
}
}

- (void)addDeviceControllerDelegate:(id<MTRDeviceControllerDelegate>)delegate queue:(dispatch_queue_t)queue
{
@synchronized (self) {
MTRDeviceControllerDelegateInfo *newDelegateInfo = [[MTRDeviceControllerDelegateInfo alloc] initWithDelegate:delegate queue:queue];
@synchronized(self) {
MTRDeviceControllerDelegateInfo * newDelegateInfo = [[MTRDeviceControllerDelegateInfo alloc] initWithDelegate:delegate queue:queue];
[_delegates addObject:newDelegateInfo];
MTR_LOG("%@ addDeviceControllerDelegate: added %p total %lu", self, delegate, static_cast<unsigned long>(_delegates.count));
}
}

- (void)removeDeviceControllerDelegate:(id<MTRDeviceControllerDelegate>)delegate
{
@synchronized (self) {
__block MTRDeviceControllerDelegateInfo *delegateInfoToRemove = nil;
[self _iterateDelegateInfoWithBlock:^(MTRDeviceControllerDelegateInfo *delegateInfo) {
@synchronized(self) {
__block MTRDeviceControllerDelegateInfo * delegateInfoToRemove = nil;
[self _iterateDelegateInfoWithBlock:^(MTRDeviceControllerDelegateInfo * delegateInfo) {
if (delegateInfo.delegate == delegate) {
delegateInfoToRemove = delegateInfo;
}
Expand All @@ -1822,17 +1822,17 @@ - (void)removeDeviceControllerDelegate:(id<MTRDeviceControllerDelegate>)delegate

// Iterates the delegates, and remove delegate info objects if the delegate object has dealloc'ed
// Returns number of delegates called
- (NSUInteger)_iterateDelegateInfoWithBlock:(void(^ _Nullable)(MTRDeviceControllerDelegateInfo * delegateInfo))block
- (NSUInteger)_iterateDelegateInfoWithBlock:(void (^_Nullable)(MTRDeviceControllerDelegateInfo * delegateInfo))block
{
@synchronized (self) {
@synchronized(self) {
if (!_delegates.count) {
MTR_LOG("%@ No delegates to iterate", self);
return 0;
}

// Opportunistically remove defunct delegate references on every iteration
NSMutableSet *delegatesToRemove = nil;
for (MTRDeviceControllerDelegateInfo *delegateInfo in _delegates) {
NSMutableSet * delegatesToRemove = nil;
for (MTRDeviceControllerDelegateInfo * delegateInfo in _delegates) {
id<MTRDeviceControllerDelegate> strongDelegate = delegateInfo.delegate;
if (strongDelegate) {
if (block) {
Expand All @@ -1855,9 +1855,9 @@ - (NSUInteger)_iterateDelegateInfoWithBlock:(void(^ _Nullable)(MTRDeviceControll
}
}

- (void)_callDelegatesWithBlock:(void(^ _Nullable)(id<MTRDeviceControllerDelegate> delegate))block logString:(const char *)logString;
- (void)_callDelegatesWithBlock:(void (^_Nullable)(id<MTRDeviceControllerDelegate> delegate))block logString:(const char *)logString;
{
NSUInteger delegatesCalled = [self _iterateDelegateInfoWithBlock:^(MTRDeviceControllerDelegateInfo *delegateInfo) {
NSUInteger delegatesCalled = [self _iterateDelegateInfoWithBlock:^(MTRDeviceControllerDelegateInfo * delegateInfo) {
id<MTRDeviceControllerDelegate> strongDelegate = delegateInfo.delegate;
dispatch_async(delegateInfo.queue, ^{
block(strongDelegate);
Expand Down Expand Up @@ -1886,9 +1886,9 @@ - (void)controller:(MTRDeviceController *)controller commissioningSessionEstabli
}

- (void)controller:(MTRDeviceController *)controller
commissioningComplete:(NSError * _Nullable)error
nodeID:(NSNumber * _Nullable)nodeID
metrics:(MTRMetrics *)metrics
commissioningComplete:(NSError * _Nullable)error
nodeID:(NSNumber * _Nullable)nodeID
metrics:(MTRMetrics *)metrics
{
[self _callDelegatesWithBlock:^(id<MTRDeviceControllerDelegate> delegate) {
if ([delegate respondsToSelector:@selector(controller:commissioningComplete:nodeID:metrics:)]) {
Expand Down

0 comments on commit 7e64c47

Please sign in to comment.