]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSResultOperation.h
Security-58286.41.2.tar.gz
[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 #if OCTAGON
25
26 #import <Foundation/Foundation.h>
27 #import <dispatch/dispatch.h>
28 #import "keychain/ckks/NSOperationCategories.h"
29
30 @class CKKSCondition;
31
32 #define CKKSResultErrorDomain @"CKKSResultOperationError"
33 enum {
34 CKKSResultSubresultError = 1,
35 CKKSResultSubresultCancelled = 2,
36 CKKSResultTimedOut = 3,
37 };
38
39 @interface CKKSResultOperation : NSBlockOperation
40 @property NSError* error;
41 @property NSDate* finishDate;
42 @property CKKSCondition* completionHandlerDidRunCondition;
43
44 // Very similar to addDependency, but:
45 // if the dependent operation has an error or is canceled, cancel this operation
46 - (void)addSuccessDependency:(CKKSResultOperation*)operation;
47 - (void)addNullableSuccessDependency:(CKKSResultOperation*)operation;
48
49 // Call to check if you should run.
50 // Note: all subclasses must call this if they'd like to comply with addSuccessDependency
51 // Also sets your .error property to encapsulate the upstream error
52 - (bool)allDependentsSuccessful;
53
54 // Allows you to time out CKKSResultOperations: if they haven't started by now, they'll cancel themselves
55 // and set their error to indicate the timeout
56 - (instancetype)timeout:(dispatch_time_t)timeout;
57
58 // Convenience constructor.
59 + (instancetype)operationWithBlock:(void (^)(void))block;
60 + (instancetype)named:(NSString*)name withBlock:(void (^)(void))block;
61 + (instancetype)named:(NSString*)name withBlockTakingSelf:(void(^)(CKKSResultOperation* op))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 // OCTAGON
72