Line data Source code
1 0 : /* 2 : 3 : NSOperationQueue was introduced in Mac OS X 10.5 and GNUstep 0.19.x. 4 : 5 : This header helps us use it if it's available at runtime without requiring 6 : it (see OOAsyncWorkManager.m). 7 : -- Ahruman 2009-09-04 8 : 9 : 10 : Copyright (C) 2009-2013 Jens Ayton 11 : 12 : Permission is hereby granted, free of charge, to any person obtaining a copy 13 : of this software and associated documentation files (the "Software"), to deal 14 : in the Software without restriction, including without limitation the rights 15 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 : copies of the Software, and to permit persons to whom the Software is 17 : furnished to do so, subject to the following conditions: 18 : 19 : The above copyright notice and this permission notice shall be included in all 20 : copies or substantial portions of the Software. 21 : 22 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 : SOFTWARE. 29 : 30 : */ 31 : 32 : 33 : #ifndef OO_HAVE_NSOPERATION 34 : #if OOLITE_MAC_OS_X 35 : #define OO_HAVE_NSOPERATION (1) 36 : #elif OOLITE_GNUSTEP 37 : // #define OO_HAVE_NSOPERATION OOLITE_GNUSTEP_1_20 && OS_API_VERSION(100500, GS_API_LATEST) 38 : // GNUstep (even current trunk - 1.21 @ 2010.06.06) only contains an 39 : // incomplete implementation of NSOperation. Namely, it's missing 40 : // NSInvocationOperation which is used in OOAsyncWorkManager.m 41 : #define OO_HAVE_NSOPERATION (0) 42 : #endif 43 : #endif 44 : 45 : #ifndef OO_ALLOW_NSOPERATION 46 0 : #define OO_ALLOW_NSOPERATION 1 47 : #endif 48 : 49 : 50 : #if OO_ALLOW_NSOPERATION 51 : #if !OO_HAVE_NSOPERATION 52 : 53 : #import "OOFunctionAttributes.h" 54 : 55 0 : #define OONSOperationQueue id 56 0 : #define OONSOperation id 57 0 : #define OONSInvocationOperation id 58 : 59 : /* NOTE: if OO_HAVE_NSOPERATION, these will compile to class names, which are 60 : not values. If you want an actual Class object, use [OONSOperationClass() class]. 61 : */ 62 : OOINLINE Class OONSOperationQueueClass() PURE_FUNC; 63 : OOINLINE Class OONSOperationClass() PURE_FUNC; 64 : OOINLINE Class OONSInvocationOperationClass() PURE_FUNC; 65 : 66 0 : OOINLINE Class OONSOperationQueueClass() 67 : { 68 : return NSClassFromString(@"NSOperationQueue"); 69 : } 70 : 71 0 : OOINLINE Class OONSOperationClass() 72 : { 73 : return NSClassFromString(@"NSOperation"); 74 : } 75 : 76 : 77 0 : OOINLINE Class OONSInvocationOperationClass() 78 : { 79 : return NSClassFromString(@"NSInvocationOperation"); 80 : } 81 : 82 : 83 : @class NSOperationQueue; 84 : @class NSOperation; 85 : @class NSInvocationOperation; 86 : 87 : 88 0 : enum { 89 : OONSOperationQueuePriorityVeryLow = -8, 90 : OONSOperationQueuePriorityLow = -4, 91 : OONSOperationQueuePriorityNormal = 0, 92 : OONSOperationQueuePriorityHigh = 4, 93 : OONSOperationQueuePriorityVeryHigh = 8 94 : }; 95 : 96 : 97 : /* These classes are (deliberately) not implemented. Their declarations exist 98 : only so that the type system will know about the methods when they're used 99 : on id variables. 100 : */ 101 : 102 0 : @interface OONSOperationProto 103 : 104 0 : - (void) start; 105 0 : - (void) main; 106 : 107 0 : - (BOOL) isCancelled; 108 0 : - (void) cancel; 109 : 110 0 : - (BOOL) isExecuting; 111 0 : - (BOOL) isFinished; 112 : 113 0 : - (BOOL) isConcurrent; 114 : 115 0 : - (BOOL) isReady; 116 : 117 0 : - (void) addDependency:(NSOperation *)op; 118 0 : - (void) removeDependency:(NSOperation *)op; 119 : 120 0 : - (NSArray *) dependencies; 121 : 122 0 : - (NSInteger) queuePriority; 123 0 : - (void) setQueuePriority:(NSInteger)p; 124 : 125 : @end 126 : 127 : 128 0 : @interface OONSInvocationOperationProto 129 : 130 0 : - (id) initWithTarget:(id)target selector:(SEL)sel object:(id)arg; 131 0 : - (id) initWithInvocation:(NSInvocation *)inv; 132 : 133 0 : - (NSInvocation *) invocation; 134 : 135 0 : - (id) result; 136 : 137 : @end 138 : 139 : 140 0 : @interface OONSOperationQueueProto 141 : 142 0 : - (void) addOperation:(NSOperation *)op; 143 : 144 0 : - (NSArray *) operations; 145 : 146 0 : - (NSInteger) maxConcurrentOperationCount; 147 0 : - (void) setMaxConcurrentOperationCount:(NSInteger)cnt; 148 : 149 0 : - (void) setSuspended:(BOOL)b; 150 0 : - (BOOL) isSuspended; 151 : 152 0 : - (void) cancelAllOperations; 153 : 154 0 : - (void) waitUntilAllOperationsAreFinished; 155 : 156 : @end 157 : 158 : #else 159 : 160 : #define OONSOperationQueue NSOperationQueue * 161 : #define OONSOperation NSOperation * 162 : #define OONSInvocationOperation NSInvocationOperation * 163 : 164 : #define OONSOperationQueueClass() NSOperationQueue 165 : #define OONSOperationClass() NSOperation 166 : #define OONSInvocationOperationClass() NSInvocationOperation 167 : 168 : 169 : enum { 170 : OONSOperationQueuePriorityVeryLow = NSOperationQueuePriorityVeryLow, 171 : OONSOperationQueuePriorityLow = NSOperationQueuePriorityLow, 172 : OONSOperationQueuePriorityNormal = NSOperationQueuePriorityNormal, 173 : OONSOperationQueuePriorityHigh = NSOperationQueuePriorityHigh, 174 : OONSOperationQueuePriorityVeryHigh = NSOperationQueuePriorityVeryHigh 175 : }; 176 : 177 : #endif 178 : #endif