]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSGroupOperation.h
Security-58286.1.32.tar.gz
[apple/security.git] / keychain / ckks / CKKSGroupOperation.h
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
24
25 #ifndef CKKSGroupOperation_h
26 #define CKKSGroupOperation_h
27
28 #import <Foundation/Foundation.h>
29 #include <dispatch/dispatch.h>
30
31 @class CKKSCondition;
32
33 @interface NSOperation (CKKSUsefulPrintingOperation)
34 - (NSString*)description;
35 - (BOOL)isPending;
36
37 // If op is nonnull, op becomes a dependency of this operation
38 - (void)addNullableDependency: (NSOperation*) op;
39
40 // Add all operations in this collection as dependencies, then add yourself to the collection
41 -(void)linearDependencies:(NSHashTable*)collection;
42 @end
43
44 @interface NSBlockOperation (CKKSUsefulConstructorOperation)
45 +(instancetype)named: (NSString*)name withBlock: (void(^)(void)) block;
46 @end
47
48
49 #define CKKSResultErrorDomain @"CKKSResultOperationError"
50 enum {
51 CKKSResultSubresultError = 1,
52 CKKSResultSubresultCancelled = 2,
53 CKKSResultTimedOut = 3,
54 };
55
56 @interface CKKSResultOperation : NSBlockOperation
57 @property NSError* error;
58 @property NSDate* finishDate;
59 @property CKKSCondition* completionHandlerDidRunCondition;
60
61 // Very similar to addDependency, but:
62 // if the dependent operation has an error or is canceled, cancel this operation
63 - (void)addSuccessDependency: (CKKSResultOperation*) operation;
64
65 // Call to check if you should run.
66 // Note: all subclasses must call this if they'd like to comply with addSuccessDependency
67 // Also sets your .error property to encapsulate the upstream error
68 - (bool)allDependentsSuccessful;
69
70 // Allows you to time out CKKSResultOperations: if they haven't started by now, they'll cancel themselves
71 // and set their error to indicate the timeout
72 - (instancetype)timeout:(dispatch_time_t)timeout;
73
74 // Convenience constructor.
75 +(instancetype)operationWithBlock:(void (^)(void))block;
76 +(instancetype)named: (NSString*)name withBlock: (void(^)(void)) block;
77 @end
78
79 @interface CKKSGroupOperation : CKKSResultOperation {
80 BOOL executing;
81 BOOL finished;
82 }
83
84 @property NSOperationQueue* operationQueue;
85
86 - (instancetype)init;
87
88 // For subclasses: override this to execute at Group operation start time
89 - (void)groupStart;
90
91 - (void)runBeforeGroupFinished: (NSOperation*) suboperation;
92 - (void)dependOnBeforeGroupFinished: (NSOperation*) suboperation;
93 @end
94
95 #endif // CKKSGroupOperation_h