]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSResultOperation.h
20fc548de8805ff175da16034661e3be8fc891b7
[apple/security.git] / keychain / ckks / CKKSResultOperation.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 #ifndef CKKSResultOperation_h
25 #define CKKSResultOperation_h
26
27 #import <Foundation/Foundation.h>
28 #import <dispatch/dispatch.h>
29 #import "keychain/ckks/NSOperationCategories.h"
30
31 @class CKKSCondition;
32
33 #define CKKSResultErrorDomain @"CKKSResultOperationError"
34 enum {
35 CKKSResultSubresultError = 1,
36 CKKSResultSubresultCancelled = 2,
37 CKKSResultTimedOut = 3,
38 };
39
40 @interface CKKSResultOperation : NSBlockOperation
41 @property NSError* error;
42 @property NSDate* finishDate;
43 @property CKKSCondition* completionHandlerDidRunCondition;
44
45 // Very similar to addDependency, but:
46 // if the dependent operation has an error or is canceled, cancel this operation
47 - (void)addSuccessDependency: (CKKSResultOperation*) operation;
48 - (void)addNullableSuccessDependency:(CKKSResultOperation*)operation;
49
50 // Call to check if you should run.
51 // Note: all subclasses must call this if they'd like to comply with addSuccessDependency
52 // Also sets your .error property to encapsulate the upstream error
53 - (bool)allDependentsSuccessful;
54
55 // Allows you to time out CKKSResultOperations: if they haven't started by now, they'll cancel themselves
56 // and set their error to indicate the timeout
57 - (instancetype)timeout:(dispatch_time_t)timeout;
58
59 // Convenience constructor.
60 +(instancetype)operationWithBlock:(void (^)(void))block;
61 +(instancetype)named: (NSString*)name withBlock: (void(^)(void)) block;
62
63 // Determine if all these operations were successful, and set this operation's result if not.
64 - (bool)allSuccessful: (NSArray<CKKSResultOperation*>*) operations;
65
66 // Call this to prevent the timeout on this operation from occuring.
67 // Upon return, either this operation is cancelled, or the timeout will never fire.
68 -(void)invalidateTimeout;
69 @end
70
71 #endif // CKKSResultOperation_h
72