]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSGroupOperation.h
f366093b8c203472c7841fff59d71abd0c6efe58
[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
43 // Insert yourself as high up the linearized list of dependencies as possible
44 -(void)linearDependenciesWithSelfFirst: (NSHashTable*) collection;
45 @end
46
47 @interface NSBlockOperation (CKKSUsefulConstructorOperation)
48 +(instancetype)named: (NSString*)name withBlock: (void(^)(void)) block;
49 @end
50
51
52 #define CKKSResultErrorDomain @"CKKSResultOperationError"
53 enum {
54 CKKSResultSubresultError = 1,
55 CKKSResultSubresultCancelled = 2,
56 CKKSResultTimedOut = 3,
57 };
58
59 @interface CKKSResultOperation : NSBlockOperation
60 @property NSError* error;
61 @property NSDate* finishDate;
62 @property CKKSCondition* completionHandlerDidRunCondition;
63
64 // Very similar to addDependency, but:
65 // if the dependent operation has an error or is canceled, cancel this operation
66 - (void)addSuccessDependency: (CKKSResultOperation*) operation;
67
68 // Call to check if you should run.
69 // Note: all subclasses must call this if they'd like to comply with addSuccessDependency
70 // Also sets your .error property to encapsulate the upstream error
71 - (bool)allDependentsSuccessful;
72
73 // Allows you to time out CKKSResultOperations: if they haven't started by now, they'll cancel themselves
74 // and set their error to indicate the timeout
75 - (instancetype)timeout:(dispatch_time_t)timeout;
76
77 // Convenience constructor.
78 +(instancetype)operationWithBlock:(void (^)(void))block;
79 +(instancetype)named: (NSString*)name withBlock: (void(^)(void)) block;
80 @end
81
82 @interface CKKSGroupOperation : CKKSResultOperation {
83 BOOL executing;
84 BOOL finished;
85 }
86
87 @property NSOperationQueue* operationQueue;
88
89 - (instancetype)init;
90
91 // For subclasses: override this to execute at Group operation start time
92 - (void)groupStart;
93
94 - (void)runBeforeGroupFinished: (NSOperation*) suboperation;
95 - (void)dependOnBeforeGroupFinished: (NSOperation*) suboperation;
96 @end
97
98 #endif // CKKSGroupOperation_h