Mercurial > projects > dstep
annotate 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 |
rev | line source |
---|---|
14 | 1 /** |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Aug 3, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.foundation.NSOperation; | |
8 | |
9 import dstep.foundation.NSArray; | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
10 import dstep.foundation.NSInvocation; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
11 import dstep.foundation.NSObjCRuntime; |
14 | 12 import dstep.foundation.NSObject; |
13 import dstep.foundation.NSSet; | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
14 import dstep.foundation.NSString; |
14 | 15 import dstep.objc.bridge.Bridge; |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
16 import dstep.objc.objc; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
17 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
18 |
14 | 19 |
20 import bindings = dstep.foundation.NSOperation_bindings; | |
21 | |
22 alias NSInteger NSOperationQueuePriority; | |
23 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
24 private |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
25 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
26 NSString NSInvocationOperationVoidResultException_; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
27 NSString NSInvocationOperationCancelledException_; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
28 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
29 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
30 NSString NSInvocationOperationVoidResultException () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
31 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
32 if (NSInvocationOperationVoidResultException_) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
33 return NSInvocationOperationVoidResultException_; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
34 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
35 return NSInvocationOperationVoidResultException_ = new NSString(bindings.NSInvocationOperationVoidResultException); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
36 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
37 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
38 NSString NSInvocationOperationCancelledException () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
39 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
40 if (NSInvocationOperationCancelledException_) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
41 return NSInvocationOperationCancelledException_; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
42 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
43 return NSInvocationOperationCancelledException_ = new NSString(bindings.NSInvocationOperationCancelledException); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
44 } |
14 | 45 |
46 enum | |
47 { | |
48 NSOperationQueuePriorityVeryLow = -8, | |
49 NSOperationQueuePriorityLow = -4, | |
50 NSOperationQueuePriorityNormal = 0, | |
51 NSOperationQueuePriorityHigh = 4, | |
52 NSOperationQueuePriorityVeryHigh = 8 | |
53 } | |
54 | |
55 enum | |
56 { | |
57 NSOperationQueueDefaultMaxConcurrentOperationCount = -1 | |
58 } | |
59 | |
60 class NSOperation : NSObject | |
61 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
62 mixin (ObjcWrap); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
63 |
14 | 64 this () |
65 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
66 super(typeof(this).alloc.init.objcObject); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
67 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
68 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
69 typeof(this) init () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
70 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
71 return invokeObjcSelf!(typeof(this), "init"); |
14 | 72 } |
73 | |
74 void start () | |
75 { | |
76 return invokeObjcSelf!(void, "start"); | |
77 } | |
78 | |
79 void main () | |
80 { | |
81 return invokeObjcSelf!(void, "main"); | |
82 } | |
83 | |
84 bool isCancelled () | |
85 { | |
86 return invokeObjcSelf!(bool, "isCancelled"); | |
87 } | |
88 | |
89 void cancel () | |
90 { | |
91 return invokeObjcSelf!(void, "cancel"); | |
92 } | |
93 | |
94 bool isExecuting () | |
95 { | |
96 return invokeObjcSelf!(bool, "isExecuting"); | |
97 } | |
98 | |
99 bool isFinished () | |
100 { | |
101 return invokeObjcSelf!(bool, "isFinished"); | |
102 } | |
103 | |
104 bool isConcurrent () | |
105 { | |
106 return invokeObjcSelf!(bool, "isConcurrent"); | |
107 } | |
108 | |
109 bool isReady () | |
110 { | |
111 return invokeObjcSelf!(bool, "isReady"); | |
112 } | |
113 | |
114 void addDependency (NSOperation op) | |
115 { | |
116 return invokeObjcSelf!(void, "addDependency:", NSOperation)(op); | |
117 } | |
118 | |
119 void removeDependency (NSOperation op) | |
120 { | |
121 return invokeObjcSelf!(void, "removeDependency:", NSOperation)(op); | |
122 } | |
123 | |
124 NSArray dependencies () | |
125 { | |
126 return invokeObjcSelf!(NSArray, "dependencies"); | |
127 } | |
128 | |
129 int queuePriority () | |
130 { | |
131 return invokeObjcSelf!(int, "queuePriority"); | |
132 } | |
133 | |
134 void setQueuePriority (int p) | |
135 { | |
136 return invokeObjcSelf!(void, "setQueuePriority:", int)(p); | |
137 } | |
138 } | |
139 | |
140 class NSOperationQueue : NSObject | |
141 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
142 mixin (ObjcWrap); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
143 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
144 this () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
145 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
146 super(typeof(this).alloc.init.objcObject); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
147 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
148 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
149 typeof(this) init () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
150 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
151 return invokeObjcSelf!(typeof(this), "init"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
152 } |
14 | 153 |
154 void addOperation (NSOperation op) | |
155 { | |
156 return invokeObjcSelf!(void, "addOperation:", NSOperation)(op); | |
157 } | |
158 | |
159 NSArray operations () | |
160 { | |
161 return invokeObjcSelf!(NSArray, "operations"); | |
162 } | |
163 | |
164 NSInteger maxConcurrentOperationCount () | |
165 { | |
166 return invokeObjcSelf!(NSInteger, "maxConcurrentOperationCount"); | |
167 } | |
168 | |
169 void setMaxConcurrentOperationCount (NSInteger cnt) | |
170 { | |
171 return invokeObjcSelf!(void, "setMaxConcurrentOperationCount:", NSInteger)(cnt); | |
172 } | |
173 | |
174 void setSuspended (bool b) | |
175 { | |
176 return invokeObjcSelf!(void, "setSuspended:", bool)(b); | |
177 } | |
178 | |
179 bool isSuspended () | |
180 { | |
181 return invokeObjcSelf!(bool, "isSuspended"); | |
182 } | |
183 | |
184 void cancelAllOperations () | |
185 { | |
186 return invokeObjcSelf!(void, "cancelAllOperations"); | |
187 } | |
188 | |
189 void waitUntilAllOperationsAreFinished () | |
190 { | |
191 return invokeObjcSelf!(void, "waitUntilAllOperationsAreFinished"); | |
192 } | |
193 } | |
194 | |
195 class NSInvocationOperation : NSOperation | |
196 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
197 mixin (ObjcWrap); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
198 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
199 this () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
200 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
201 super(typeof(this).alloc.init.objcObject); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
202 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
203 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
204 typeof(this) init () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
205 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
206 return invokeObjcSelf!(typeof(this), "init"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
207 } |
14 | 208 |
209 Object initWithTarget (Object target, SEL sel, Object arg) | |
210 { | |
211 return invokeObjcSelf!(Object, "initWithTarget:selector:object:", Object, SEL, Object)(target, sel, arg); | |
212 } | |
213 | |
214 this (Object target, SEL sel, Object arg) | |
215 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
216 typeof(this).alloc.initWithTarget(target, sel, arg); |
14 | 217 } |
218 | |
219 Object initWithInvocation (NSInvocation inv) | |
220 { | |
221 return invokeObjcSelf!(Object, "initWithInvocation:", NSInvocation)(inv); | |
222 } | |
223 | |
224 this (NSInvocation inv) | |
225 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
226 typeof(this).alloc.initWithInvocation(inv); |
14 | 227 } |
228 | |
229 NSInvocation invocation () | |
230 { | |
231 return invokeObjcSelf!(NSInvocation, "invocation"); | |
232 } | |
233 | |
234 Object result () | |
235 { | |
236 return invokeObjcSelf!(Object, "result"); | |
237 } | |
238 } | |
239 |