From 5574dfe8b6bdb7a15f505236139b3bda708e181f Mon Sep 17 00:00:00 2001 From: Jeff Tung Date: Fri, 29 Jul 2022 13:44:14 -0700 Subject: [PATCH] fixed warnings for github --- .../CHIP/MTRAsyncCallbackWorkQueue.h | 3 +-- .../CHIP/MTRAsyncCallbackWorkQueue.mm | 14 ++++++------ .../CHIP/MTRAsyncCallbackWorkQueue_Internal.h | 2 +- src/darwin/Framework/CHIP/MTRDevice.mm | 2 +- .../CHIPTests/MTRAsyncCallbackQueueTests.m | 22 ++++++++++--------- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue.h b/src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue.h index 473aed2797c9f0..8793a688934ff3 100644 --- a/src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue.h +++ b/src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue.h @@ -19,10 +19,9 @@ NS_ASSUME_NONNULL_BEGIN -@class MTRDevice; @class MTRAsyncCallbackQueueWorkItem; -typedef void (^MTRAsyncCallbackReadyHandler)(MTRDevice * device, NSUInteger retryCount); +typedef void (^MTRAsyncCallbackReadyHandler)(id context, NSUInteger retryCount); // How to queue a new work item: // - Create MTRAsyncCallbackQueueWorkItem object diff --git a/src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue.mm b/src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue.mm index 26c9f664646349..7e09b55890ac81 100644 --- a/src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue.mm +++ b/src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue.mm @@ -25,7 +25,7 @@ @interface MTRAsyncCallbackWorkQueue () @property (nonatomic, readonly) os_unfair_lock lock; -@property (nonatomic, strong, readonly) MTRDevice * device; +@property (nonatomic, strong, readonly) id context; @property (nonatomic, strong, readonly) dispatch_queue_t queue; @property (nonatomic, strong, readonly) NSMutableArray * items; @property (nonatomic, readwrite) NSUInteger runningWorkItemCount; @@ -40,18 +40,18 @@ @interface MTRAsyncCallbackQueueWorkItem () @property (nonatomic, readwrite) NSUInteger retryCount; @property (nonatomic, strong) MTRAsyncCallbackWorkQueue * workQueue; // Called by the queue -- (void)callReadyHandlerWithDevice:(MTRDevice *)device; +- (void)callReadyHandlerWithContext:(id)context; - (void)cancel; @end #pragma mark - Class implementations @implementation MTRAsyncCallbackWorkQueue -- (instancetype)initWithDevice:(MTRDevice *)device queue:(dispatch_queue_t)queue +- (instancetype)initWithContext:(id)context queue:(dispatch_queue_t)queue { if (self = [super init]) { _lock = OS_UNFAIR_LOCK_INIT; - _device = device; + _context = context; _queue = queue; _items = [NSMutableArray array]; } @@ -152,7 +152,7 @@ - (void)_callNextReadyWorkItem self.runningWorkItemCount = 1; MTRAsyncCallbackQueueWorkItem * workItem = self.items.firstObject; - [workItem callReadyHandlerWithDevice:self.device]; + [workItem callReadyHandlerWithContext:self.context]; } @end @@ -179,10 +179,10 @@ - (void)retryWork } // Called by the work queue -- (void)callReadyHandlerWithDevice:(MTRDevice *)device +- (void)callReadyHandlerWithContext:(id)context { dispatch_async(self.queue, ^{ - self.readyHandler(device, self.retryCount); + self.readyHandler(context, self.retryCount); self.retryCount++; }); } diff --git a/src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue_Internal.h b/src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue_Internal.h index 6a727d08aecaaf..35eb765c3914ce 100644 --- a/src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue_Internal.h +++ b/src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue_Internal.h @@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN @interface MTRAsyncCallbackWorkQueue () // The MTRDevice object is only held and passed back as a reference and is opaque to the queue -- (instancetype)initWithDevice:(MTRDevice *)device queue:(dispatch_queue_t)queue; +- (instancetype)initWithContext:(id _Nullable)context queue:(dispatch_queue_t)queue; // Called by DeviceController at device clean up time - (void)invalidate; diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 4d5a1f95f53348..1a9e70d38f6f34 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -221,7 +221,7 @@ - (instancetype)initWithDeviceID:(uint64_t)deviceID _queue = queue; _readCache = [NSMutableDictionary dictionary]; _expectedValueCache = [NSMutableDictionary dictionary]; - _asyncCallbackWorkQueue = [[MTRAsyncCallbackWorkQueue alloc] initWithDevice:self queue:queue]; + _asyncCallbackWorkQueue = [[MTRAsyncCallbackWorkQueue alloc] initWithContext:self queue:queue]; } return self; } diff --git a/src/darwin/Framework/CHIPTests/MTRAsyncCallbackQueueTests.m b/src/darwin/Framework/CHIPTests/MTRAsyncCallbackQueueTests.m index c672046db297f5..d87a88a733ecbb 100644 --- a/src/darwin/Framework/CHIPTests/MTRAsyncCallbackQueueTests.m +++ b/src/darwin/Framework/CHIPTests/MTRAsyncCallbackQueueTests.m @@ -31,7 +31,7 @@ - (void)testRunItem { XCTestExpectation * expectation = [self expectationWithDescription:@"Work item called"]; - MTRAsyncCallbackWorkQueue * workQueue = [[MTRAsyncCallbackWorkQueue alloc] initWithDevice:nil queue:dispatch_get_main_queue()]; + MTRAsyncCallbackWorkQueue * workQueue = [[MTRAsyncCallbackWorkQueue alloc] initWithContext:nil queue:dispatch_get_main_queue()]; MTRAsyncCallbackQueueWorkItem * workItem1 = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)]; @@ -56,26 +56,26 @@ - (void)testRunItemsSerialized { XCTestExpectation * expectation = [self expectationWithDescription:@"Work item called in order"]; - MTRAsyncCallbackWorkQueue * workQueue = [[MTRAsyncCallbackWorkQueue alloc] initWithDevice:nil queue:dispatch_get_main_queue()]; + MTRAsyncCallbackWorkQueue * workQueue = [[MTRAsyncCallbackWorkQueue alloc] initWithContext:nil queue:dispatch_get_main_queue()]; MTRAsyncCallbackQueueWorkItem * workItem1 = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)]; __block int counter = 0; - MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * _Nonnull device, NSUInteger retryCount) { + MTRAsyncCallbackReadyHandler readyHandler1 = ^(MTRDevice * _Nonnull device, NSUInteger retryCount) { NSLog(@"Item 1 called with counter %d", counter); sleep(1); counter++; NSLog(@"Item 1 woke after sleep with counter %d", counter); [workItem1 endWork]; }; - workItem1.readyHandler = readyHandler; + workItem1.readyHandler = readyHandler1; workItem1.cancelHandler = ^{ }; [workQueue enqueueWorkItem:workItem1]; MTRAsyncCallbackQueueWorkItem * workItem2 = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)]; - workItem2.readyHandler = ^(MTRDevice * _Nonnull device, NSUInteger retryCount) { + MTRAsyncCallbackReadyHandler readyHandler2 = ^(MTRDevice * _Nonnull device, NSUInteger retryCount) { // expect this to have waited until workItem1's sleep(1) finished and incremented counter NSLog(@"Item 2 called with counter %d", counter); if (counter == 1) { @@ -83,6 +83,7 @@ - (void)testRunItemsSerialized } [workItem2 endWork]; }; + workItem2.readyHandler = readyHandler2; workItem2.cancelHandler = ^{ }; [workQueue enqueueWorkItem:workItem2]; @@ -99,13 +100,13 @@ - (void)testRunItemsRetry { XCTestExpectation * expectation = [self expectationWithDescription:@"Work item called in order"]; - MTRAsyncCallbackWorkQueue * workQueue = [[MTRAsyncCallbackWorkQueue alloc] initWithDevice:nil queue:dispatch_get_main_queue()]; + MTRAsyncCallbackWorkQueue * workQueue = [[MTRAsyncCallbackWorkQueue alloc] initWithContext:nil queue:dispatch_get_main_queue()]; MTRAsyncCallbackQueueWorkItem * workItem1 = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)]; __block int counter = 0; - MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * _Nonnull device, NSUInteger retryCount) { - NSLog(@"Item 1 called with counter %d retryCount %d", counter, retryCount); + MTRAsyncCallbackReadyHandler readyHandler1 = ^(MTRDevice * _Nonnull device, NSUInteger retryCount) { + NSLog(@"Item 1 called with counter %d retryCount %lu", counter, (unsigned long) retryCount); sleep(1); counter++; NSLog(@"Item 1 woke after sleep with counter %d", counter); @@ -117,14 +118,14 @@ - (void)testRunItemsRetry [workItem1 retryWork]; } }; - workItem1.readyHandler = readyHandler; + workItem1.readyHandler = readyHandler1; workItem1.cancelHandler = ^{ }; [workQueue enqueueWorkItem:workItem1]; MTRAsyncCallbackQueueWorkItem * workItem2 = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)]; - workItem2.readyHandler = ^(MTRDevice * _Nonnull device, NSUInteger retryCount) { + MTRAsyncCallbackReadyHandler readyHandler2 = ^(MTRDevice * _Nonnull device, NSUInteger retryCount) { // expect this to have waited until workItem1's sleep(1) finished and incremented counter NSLog(@"Item 2 called with counter %d", counter); if (counter == 2) { @@ -132,6 +133,7 @@ - (void)testRunItemsRetry } [workItem2 endWork]; }; + workItem2.readyHandler = readyHandler2; workItem2.cancelHandler = ^{ }; [workQueue enqueueWorkItem:workItem2];