Mercurial > projects > dstep
comparison dstep/foundation/NSOperation.d @ 14:89f3c3ef1fd2
Added the Foundation framework
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 03 Aug 2009 15:23:15 +0200 |
parents | |
children | 19885b43130e |
comparison
equal
deleted
inserted
replaced
13:4f583f7e242e | 14:89f3c3ef1fd2 |
---|---|
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; | |
10 import dstep.foundation.NSObject; | |
11 import dstep.foundation.NSSet; | |
12 import dstep.objc.bridge.Bridge; | |
13 import dstep.objc.objc : id; | |
14 | |
15 import bindings = dstep.foundation.NSOperation_bindings; | |
16 | |
17 alias NSInteger NSOperationQueuePriority; | |
18 | |
19 const NSString NSInvocationOperationVoidResultException; | |
20 const NSString NSInvocationOperationCancelledException; | |
21 | |
22 enum | |
23 { | |
24 NSOperationQueuePriorityVeryLow = -8, | |
25 NSOperationQueuePriorityLow = -4, | |
26 NSOperationQueuePriorityNormal = 0, | |
27 NSOperationQueuePriorityHigh = 4, | |
28 NSOperationQueuePriorityVeryHigh = 8 | |
29 } | |
30 | |
31 enum | |
32 { | |
33 NSOperationQueueDefaultMaxConcurrentOperationCount = -1 | |
34 } | |
35 | |
36 static this () | |
37 { | |
38 NSInvocationOperationVoidResultException = new NSString(bindings.NSInvocationOperationVoidResultException); | |
39 NSInvocationOperationCancelledException = new NSString(bindings.NSInvocationOperationCancelledException); | |
40 } | |
41 | |
42 class NSOperation : NSObject | |
43 { | |
44 mixin ObjcWrap; | |
45 | |
46 Object init () | |
47 { | |
48 return invokeObjcSelf!(Object, "init"); | |
49 } | |
50 | |
51 this () | |
52 { | |
53 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
54 id result = Bridge.invokeObjcMethod!(id, "init")(objcObject); | |
55 | |
56 if (result) | |
57 objcObject = ret; | |
58 | |
59 dObject = this; | |
60 } | |
61 | |
62 void start () | |
63 { | |
64 return invokeObjcSelf!(void, "start"); | |
65 } | |
66 | |
67 void main () | |
68 { | |
69 return invokeObjcSelf!(void, "main"); | |
70 } | |
71 | |
72 bool isCancelled () | |
73 { | |
74 return invokeObjcSelf!(bool, "isCancelled"); | |
75 } | |
76 | |
77 void cancel () | |
78 { | |
79 return invokeObjcSelf!(void, "cancel"); | |
80 } | |
81 | |
82 bool isExecuting () | |
83 { | |
84 return invokeObjcSelf!(bool, "isExecuting"); | |
85 } | |
86 | |
87 bool isFinished () | |
88 { | |
89 return invokeObjcSelf!(bool, "isFinished"); | |
90 } | |
91 | |
92 bool isConcurrent () | |
93 { | |
94 return invokeObjcSelf!(bool, "isConcurrent"); | |
95 } | |
96 | |
97 bool isReady () | |
98 { | |
99 return invokeObjcSelf!(bool, "isReady"); | |
100 } | |
101 | |
102 void addDependency (NSOperation op) | |
103 { | |
104 return invokeObjcSelf!(void, "addDependency:", NSOperation)(op); | |
105 } | |
106 | |
107 void removeDependency (NSOperation op) | |
108 { | |
109 return invokeObjcSelf!(void, "removeDependency:", NSOperation)(op); | |
110 } | |
111 | |
112 NSArray dependencies () | |
113 { | |
114 return invokeObjcSelf!(NSArray, "dependencies"); | |
115 } | |
116 | |
117 int queuePriority () | |
118 { | |
119 return invokeObjcSelf!(int, "queuePriority"); | |
120 } | |
121 | |
122 void setQueuePriority (int p) | |
123 { | |
124 return invokeObjcSelf!(void, "setQueuePriority:", int)(p); | |
125 } | |
126 } | |
127 | |
128 class NSOperationQueue : NSObject | |
129 { | |
130 mixin ObjcWrap; | |
131 | |
132 void addOperation (NSOperation op) | |
133 { | |
134 return invokeObjcSelf!(void, "addOperation:", NSOperation)(op); | |
135 } | |
136 | |
137 NSArray operations () | |
138 { | |
139 return invokeObjcSelf!(NSArray, "operations"); | |
140 } | |
141 | |
142 NSInteger maxConcurrentOperationCount () | |
143 { | |
144 return invokeObjcSelf!(NSInteger, "maxConcurrentOperationCount"); | |
145 } | |
146 | |
147 void setMaxConcurrentOperationCount (NSInteger cnt) | |
148 { | |
149 return invokeObjcSelf!(void, "setMaxConcurrentOperationCount:", NSInteger)(cnt); | |
150 } | |
151 | |
152 void setSuspended (bool b) | |
153 { | |
154 return invokeObjcSelf!(void, "setSuspended:", bool)(b); | |
155 } | |
156 | |
157 bool isSuspended () | |
158 { | |
159 return invokeObjcSelf!(bool, "isSuspended"); | |
160 } | |
161 | |
162 void cancelAllOperations () | |
163 { | |
164 return invokeObjcSelf!(void, "cancelAllOperations"); | |
165 } | |
166 | |
167 void waitUntilAllOperationsAreFinished () | |
168 { | |
169 return invokeObjcSelf!(void, "waitUntilAllOperationsAreFinished"); | |
170 } | |
171 } | |
172 | |
173 class NSInvocationOperation : NSOperation | |
174 { | |
175 mixin ObjcWrap; | |
176 | |
177 Object initWithTarget (Object target, SEL sel, Object arg) | |
178 { | |
179 return invokeObjcSelf!(Object, "initWithTarget:selector:object:", Object, SEL, Object)(target, sel, arg); | |
180 } | |
181 | |
182 this (Object target, SEL sel, Object arg) | |
183 { | |
184 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
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 } | |
192 | |
193 Object initWithInvocation (NSInvocation inv) | |
194 { | |
195 return invokeObjcSelf!(Object, "initWithInvocation:", NSInvocation)(inv); | |
196 } | |
197 | |
198 this (NSInvocation inv) | |
199 { | |
200 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
201 id result = Bridge.invokeObjcMethod!(id, "initWithInvocation:", NSInvocation)(objcObject, inv); | |
202 | |
203 if (result) | |
204 objcObject = ret; | |
205 | |
206 dObject = this; | |
207 } | |
208 | |
209 NSInvocation invocation () | |
210 { | |
211 return invokeObjcSelf!(NSInvocation, "invocation"); | |
212 } | |
213 | |
214 Object result () | |
215 { | |
216 return invokeObjcSelf!(Object, "result"); | |
217 } | |
218 } | |
219 |