Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit fec77c1

Browse files
committed
create queue helper
1 parent c742524 commit fec77c1

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

packages/camera/camera/example/ios/RunnerTests/FLTCamPhotoCaptureTests.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ - (void)testCaptureToFile_mustReportErrorToResultIfSavePhotoDelegateCompletionsW
1919
[self expectationWithDescription:
2020
@"Must send error to result if save photo delegate completes with error."];
2121

22-
dispatch_queue_t captureSessionQueue = dispatch_queue_create("capture_session_queue", NULL);
23-
[QueueHelper setSpecific:FLTCaptureSessionQueueSpecific forQueue:captureSessionQueue];
22+
dispatch_queue_t captureSessionQueue =
23+
[QueueHelper createQueueWithLabel:"capture_session_queue"
24+
specific:FLTCaptureSessionQueueSpecific];
2425
FLTCam *cam = [self createFLTCamWithCaptureSessionQueue:captureSessionQueue];
2526
AVCapturePhotoSettings *settings = [AVCapturePhotoSettings photoSettings];
2627
id mockSettings = OCMClassMock([AVCapturePhotoSettings class]);
@@ -57,8 +58,9 @@ - (void)testCaptureToFile_mustReportPathToResultIfSavePhotoDelegateCompletionsWi
5758
[self expectationWithDescription:
5859
@"Must send file path to result if save photo delegate completes with file path."];
5960

60-
dispatch_queue_t captureSessionQueue = dispatch_queue_create("capture_session_queue", NULL);
61-
[QueueHelper setSpecific:FLTCaptureSessionQueueSpecific forQueue:captureSessionQueue];
61+
dispatch_queue_t captureSessionQueue =
62+
[QueueHelper createQueueWithLabel:"capture_session_queue"
63+
specific:FLTCaptureSessionQueueSpecific];
6264
FLTCam *cam = [self createFLTCamWithCaptureSessionQueue:captureSessionQueue];
6365

6466
AVCapturePhotoSettings *settings = [AVCapturePhotoSettings photoSettings];

packages/camera/camera/example/ios/RunnerTests/QueueHelperTests.m

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,18 @@ - (void)testShouldDispatchToMainQueueIfCalledFromBackgroundQueue {
3535
[self waitForExpectationsWithTimeout:1 handler:nil];
3636
}
3737

38-
- (void)testSetAndCheckQueueSpecific {
39-
dispatch_queue_t queue = dispatch_queue_create("test", NULL);
38+
- (void)testCreateQueue {
39+
const char *label = "label";
4040
const char *specific = "specific";
41-
[QueueHelper setSpecific:specific forQueue:queue];
41+
dispatch_queue_t queue = [QueueHelper createQueueWithLabel:label specific:specific];
42+
XCTAssert(0 == strcmp(label, dispatch_queue_get_label(queue)), "Must set the correct label.");
43+
XCTAssert(0 == strcmp(specific, dispatch_queue_get_specific(queue, specific)),
44+
"Must set the correct specific.");
45+
}
4246

47+
- (void)testIsCurrentlyOnQueueWithSpecific {
48+
const char *specific = "specific";
49+
dispatch_queue_t queue = [QueueHelper createQueueWithLabel:"test" specific:specific];
4350
XCTAssertFalse([QueueHelper isCurrentlyOnQueueWithSpecific:specific],
4451
@"Must not be on the test queue before dispatching to it.");
4552

packages/camera/camera/ios/Classes/CameraPlugin.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ - (instancetype)initWithRegistry:(NSObject<FlutterTextureRegistry> *)registry
3838
NSAssert(self, @"super init cannot be nil");
3939
_registry = [[FLTThreadSafeTextureRegistry alloc] initWithTextureRegistry:registry];
4040
_messenger = messenger;
41-
_captureSessionQueue = dispatch_queue_create("io.flutter.camera.captureSessionQueue", NULL);
42-
[QueueHelper setSpecific:FLTCaptureSessionQueueSpecific forQueue:_captureSessionQueue];
41+
_captureSessionQueue = [QueueHelper createQueueWithLabel:"io.flutter.camera.captureSessionQueue"
42+
specific:FLTCaptureSessionQueueSpecific];
4343

4444
[self initDeviceEventMethodChannel];
4545
[self startOrientationListener];

packages/camera/camera/ios/Classes/QueueHelper.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ extern const char *FLTCaptureSessionQueueSpecific;
1414

1515
/// Ensure the given block to be run on the main queue.
1616
/// If caller site is already on the main queue, the block will be run synchronously. Otherwise, the
17-
/// block will be dispatch asynchronously to the main queue.
17+
/// block will be dispatched asynchronously to the main queue.
1818
/// @param block the block to be run on the main queue.
1919
+ (void)ensureToRunOnMainQueue:(void (^)(void))block;
2020

21-
/// Sets the queue-specific context data for a given queue.
22-
/// @param specific the queue-specific context data.
23-
/// @param queue the queue to be associated with the context data.
24-
+ (void)setSpecific:(const char *)specific forQueue:(dispatch_queue_t)queue;
21+
/// Creates a dispatch queue with a label and queue-specific context data.
22+
/// @param label label for debugging purpose.
23+
/// @param specific queue-specific context data.
24+
/// @return the created dispatch queue with the given label and queue-specific context data.
25+
+ (dispatch_queue_t)createQueueWithLabel:(const char *)label specific:(const char *)specific;
2526

2627
/// Check if the caller is on a certain queue specified by its queue-specifc context data.
27-
/// @returns YES if the caller is on a certain queue specified by its queue-specific context data.
28+
/// @param specific queue-specific context data.
29+
/// @return YES if the caller is on a certain queue specified by its queue-specific context data;
2830
/// NO otherwise.
2931
+ (BOOL)isCurrentlyOnQueueWithSpecific:(const char *)specific;
3032

packages/camera/camera/ios/Classes/QueueHelper.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ + (void)ensureToRunOnMainQueue:(void (^)(void))block {
1616
}
1717
}
1818

19-
+ (void)setSpecific:(const char *)specific forQueue:(dispatch_queue_t)queue {
19+
+ (dispatch_queue_t)createQueueWithLabel:(const char *)label specific:(const char *)specific {
20+
dispatch_queue_t queue = dispatch_queue_create(label, NULL);
2021
dispatch_queue_set_specific(queue, specific, (void *)specific, NULL);
22+
return queue;
2123
}
2224

2325
+ (BOOL)isCurrentlyOnQueueWithSpecific:(const char *)specific {

0 commit comments

Comments
 (0)