]>
Commit | Line | Data |
---|---|---|
8a50f688 A |
1 | /* |
2 | * Copyright (c) 2017 Apple Inc. All Rights Reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | ||
3f0f0d49 | 24 | #if OCTAGON |
8a50f688 A |
25 | |
26 | #import <Foundation/Foundation.h> | |
27 | #import <dispatch/dispatch.h> | |
28 | #import "keychain/ckks/NSOperationCategories.h" | |
29 | ||
ecaf5866 A |
30 | NS_ASSUME_NONNULL_BEGIN |
31 | ||
8a50f688 A |
32 | @class CKKSCondition; |
33 | ||
34 | #define CKKSResultErrorDomain @"CKKSResultOperationError" | |
35 | enum { | |
36 | CKKSResultSubresultError = 1, | |
37 | CKKSResultSubresultCancelled = 2, | |
38 | CKKSResultTimedOut = 3, | |
39 | }; | |
40 | ||
ecaf5866 A |
41 | #define CKKSResultDescriptionErrorDomain @"CKKSResultOperationDescriptionError" |
42 | ||
8a50f688 | 43 | @interface CKKSResultOperation : NSBlockOperation |
ecaf5866 A |
44 | @property (nullable) NSError* error; |
45 | @property (nullable) NSDate* finishDate; | |
8a50f688 A |
46 | @property CKKSCondition* completionHandlerDidRunCondition; |
47 | ||
ecaf5866 A |
48 | @property NSInteger descriptionErrorCode; // Set to non-0 for inclusion of this operation in NSError chains. Code is application-dependent. |
49 | ||
50 | // If you subclass CKKSResultOperation, this is the method corresponding to descriptionErrorCode. Fill it in to your heart's content. | |
51 | - (NSError* _Nullable)descriptionError; | |
52 | ||
8a50f688 A |
53 | // Very similar to addDependency, but: |
54 | // if the dependent operation has an error or is canceled, cancel this operation | |
3f0f0d49 | 55 | - (void)addSuccessDependency:(CKKSResultOperation*)operation; |
8a50f688 A |
56 | - (void)addNullableSuccessDependency:(CKKSResultOperation*)operation; |
57 | ||
58 | // Call to check if you should run. | |
59 | // Note: all subclasses must call this if they'd like to comply with addSuccessDependency | |
60 | // Also sets your .error property to encapsulate the upstream error | |
61 | - (bool)allDependentsSuccessful; | |
62 | ||
63 | // Allows you to time out CKKSResultOperations: if they haven't started by now, they'll cancel themselves | |
64 | // and set their error to indicate the timeout | |
65 | - (instancetype)timeout:(dispatch_time_t)timeout; | |
66 | ||
67 | // Convenience constructor. | |
3f0f0d49 A |
68 | + (instancetype)operationWithBlock:(void (^)(void))block; |
69 | + (instancetype)named:(NSString*)name withBlock:(void (^)(void))block; | |
70 | + (instancetype)named:(NSString*)name withBlockTakingSelf:(void(^)(CKKSResultOperation* op))block; | |
8a50f688 A |
71 | |
72 | // Determine if all these operations were successful, and set this operation's result if not. | |
3f0f0d49 | 73 | - (bool)allSuccessful:(NSArray<CKKSResultOperation*>*)operations; |
8a50f688 A |
74 | |
75 | // Call this to prevent the timeout on this operation from occuring. | |
76 | // Upon return, either this operation is cancelled, or the timeout will never fire. | |
3f0f0d49 | 77 | - (void)invalidateTimeout; |
ecaf5866 A |
78 | |
79 | // Reports the state of this operation. Used for making up description strings. | |
80 | - (NSString*)operationStateString; | |
8a50f688 A |
81 | @end |
82 | ||
ecaf5866 | 83 | NS_ASSUME_NONNULL_END |
3f0f0d49 | 84 | #endif // OCTAGON |
8a50f688 | 85 |