Mercurial > projects > dstep
comparison dstep/foundation/NSOperation.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | 89f3c3ef1fd2 |
children | b9de51448c6b |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) |
6 */ | 6 */ |
7 module dstep.foundation.NSOperation; | 7 module dstep.foundation.NSOperation; |
8 | 8 |
9 import dstep.foundation.NSArray; | 9 import dstep.foundation.NSArray; |
10 import dstep.foundation.NSInvocation; | |
11 import dstep.foundation.NSObjCRuntime; | |
10 import dstep.foundation.NSObject; | 12 import dstep.foundation.NSObject; |
11 import dstep.foundation.NSSet; | 13 import dstep.foundation.NSSet; |
14 import dstep.foundation.NSString; | |
12 import dstep.objc.bridge.Bridge; | 15 import dstep.objc.bridge.Bridge; |
13 import dstep.objc.objc : id; | 16 import dstep.objc.objc; |
17 | |
18 | |
14 | 19 |
15 import bindings = dstep.foundation.NSOperation_bindings; | 20 import bindings = dstep.foundation.NSOperation_bindings; |
16 | 21 |
17 alias NSInteger NSOperationQueuePriority; | 22 alias NSInteger NSOperationQueuePriority; |
18 | 23 |
19 const NSString NSInvocationOperationVoidResultException; | 24 private |
20 const NSString NSInvocationOperationCancelledException; | 25 { |
26 NSString NSInvocationOperationVoidResultException_; | |
27 NSString NSInvocationOperationCancelledException_; | |
28 } | |
29 | |
30 NSString NSInvocationOperationVoidResultException () | |
31 { | |
32 if (NSInvocationOperationVoidResultException_) | |
33 return NSInvocationOperationVoidResultException_; | |
34 | |
35 return NSInvocationOperationVoidResultException_ = new NSString(bindings.NSInvocationOperationVoidResultException); | |
36 } | |
37 | |
38 NSString NSInvocationOperationCancelledException () | |
39 { | |
40 if (NSInvocationOperationCancelledException_) | |
41 return NSInvocationOperationCancelledException_; | |
42 | |
43 return NSInvocationOperationCancelledException_ = new NSString(bindings.NSInvocationOperationCancelledException); | |
44 } | |
21 | 45 |
22 enum | 46 enum |
23 { | 47 { |
24 NSOperationQueuePriorityVeryLow = -8, | 48 NSOperationQueuePriorityVeryLow = -8, |
25 NSOperationQueuePriorityLow = -4, | 49 NSOperationQueuePriorityLow = -4, |
31 enum | 55 enum |
32 { | 56 { |
33 NSOperationQueueDefaultMaxConcurrentOperationCount = -1 | 57 NSOperationQueueDefaultMaxConcurrentOperationCount = -1 |
34 } | 58 } |
35 | 59 |
36 static this () | |
37 { | |
38 NSInvocationOperationVoidResultException = new NSString(bindings.NSInvocationOperationVoidResultException); | |
39 NSInvocationOperationCancelledException = new NSString(bindings.NSInvocationOperationCancelledException); | |
40 } | |
41 | |
42 class NSOperation : NSObject | 60 class NSOperation : NSObject |
43 { | 61 { |
44 mixin ObjcWrap; | 62 mixin (ObjcWrap); |
45 | 63 |
46 Object init () | |
47 { | |
48 return invokeObjcSelf!(Object, "init"); | |
49 } | |
50 | |
51 this () | 64 this () |
52 { | 65 { |
53 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 66 super(typeof(this).alloc.init.objcObject); |
54 id result = Bridge.invokeObjcMethod!(id, "init")(objcObject); | 67 } |
55 | 68 |
56 if (result) | 69 typeof(this) init () |
57 objcObject = ret; | 70 { |
58 | 71 return invokeObjcSelf!(typeof(this), "init"); |
59 dObject = this; | |
60 } | 72 } |
61 | 73 |
62 void start () | 74 void start () |
63 { | 75 { |
64 return invokeObjcSelf!(void, "start"); | 76 return invokeObjcSelf!(void, "start"); |
125 } | 137 } |
126 } | 138 } |
127 | 139 |
128 class NSOperationQueue : NSObject | 140 class NSOperationQueue : NSObject |
129 { | 141 { |
130 mixin ObjcWrap; | 142 mixin (ObjcWrap); |
143 | |
144 this () | |
145 { | |
146 super(typeof(this).alloc.init.objcObject); | |
147 } | |
148 | |
149 typeof(this) init () | |
150 { | |
151 return invokeObjcSelf!(typeof(this), "init"); | |
152 } | |
131 | 153 |
132 void addOperation (NSOperation op) | 154 void addOperation (NSOperation op) |
133 { | 155 { |
134 return invokeObjcSelf!(void, "addOperation:", NSOperation)(op); | 156 return invokeObjcSelf!(void, "addOperation:", NSOperation)(op); |
135 } | 157 } |
170 } | 192 } |
171 } | 193 } |
172 | 194 |
173 class NSInvocationOperation : NSOperation | 195 class NSInvocationOperation : NSOperation |
174 { | 196 { |
175 mixin ObjcWrap; | 197 mixin (ObjcWrap); |
198 | |
199 this () | |
200 { | |
201 super(typeof(this).alloc.init.objcObject); | |
202 } | |
203 | |
204 typeof(this) init () | |
205 { | |
206 return invokeObjcSelf!(typeof(this), "init"); | |
207 } | |
176 | 208 |
177 Object initWithTarget (Object target, SEL sel, Object arg) | 209 Object initWithTarget (Object target, SEL sel, Object arg) |
178 { | 210 { |
179 return invokeObjcSelf!(Object, "initWithTarget:selector:object:", Object, SEL, Object)(target, sel, arg); | 211 return invokeObjcSelf!(Object, "initWithTarget:selector:object:", Object, SEL, Object)(target, sel, arg); |
180 } | 212 } |
181 | 213 |
182 this (Object target, SEL sel, Object arg) | 214 this (Object target, SEL sel, Object arg) |
183 { | 215 { |
184 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 216 typeof(this).alloc.initWithTarget(target, sel, arg); |
185 id result = Bridge.invokeObjcMethod!(id, "initWithTarget:selector:object:", Object, SEL, Object)(objcObject, target, sel, arg); | |
186 | |
187 if (result) | |
188 objcObject = ret; | |
189 | |
190 dObject = this; | |
191 } | 217 } |
192 | 218 |
193 Object initWithInvocation (NSInvocation inv) | 219 Object initWithInvocation (NSInvocation inv) |
194 { | 220 { |
195 return invokeObjcSelf!(Object, "initWithInvocation:", NSInvocation)(inv); | 221 return invokeObjcSelf!(Object, "initWithInvocation:", NSInvocation)(inv); |
196 } | 222 } |
197 | 223 |
198 this (NSInvocation inv) | 224 this (NSInvocation inv) |
199 { | 225 { |
200 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 226 typeof(this).alloc.initWithInvocation(inv); |
201 id result = Bridge.invokeObjcMethod!(id, "initWithInvocation:", NSInvocation)(objcObject, inv); | |
202 | |
203 if (result) | |
204 objcObject = ret; | |
205 | |
206 dObject = this; | |
207 } | 227 } |
208 | 228 |
209 NSInvocation invocation () | 229 NSInvocation invocation () |
210 { | 230 { |
211 return invokeObjcSelf!(NSInvocation, "invocation"); | 231 return invokeObjcSelf!(NSInvocation, "invocation"); |