Mercurial > projects > dstep
annotate dstep/foundation/NSThread.d @ 15:7ff919f595d5
Added the Foundation framework, again
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 03 Aug 2009 15:31:48 +0200 |
parents | 89f3c3ef1fd2 |
children | 19885b43130e |
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.NSThread; | |
8 | |
9 import dstep.foundation.NSArray; | |
10 import dstep.foundation.NSDate; | |
11 import dstep.foundation.NSMutableDictionary; | |
12 import dstep.foundation.NSObject; | |
13 import dstep.objc.bridge.Bridge; | |
14 import dstep.objc.objc : id; | |
15 | |
16 import bindings = dstep.foundation.NSThread_bindings; | |
17 | |
18 const NSString NSWillBecomeMultiThreadedNotification; | |
19 const NSString NSDidBecomeSingleThreadedNotification; | |
20 const NSString NSThreadWillExitNotification; | |
21 | |
22 static this () | |
23 { | |
24 NSWillBecomeMultiThreadedNotification = new NSString(bindings.NSWillBecomeMultiThreadedNotification); | |
25 NSDidBecomeSingleThreadedNotification = new NSString(bindings.NSDidBecomeSingleThreadedNotification); | |
26 NSThreadWillExitNotification = new NSString(bindings.NSThreadWillExitNotification); | |
27 } | |
28 | |
29 class NSThread : NSObject | |
30 { | |
31 mixin ObjcWrap; | |
32 | |
33 static NSThread currentThread () | |
34 { | |
15
7ff919f595d5
Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
35 return invokeObjcSelfClass!(NSThread, "currentThread"); |
7ff919f595d5
Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
36 } |
14 | 37 |
38 static void detachNewThreadSelector (SEL selector, Object target, Object argument) | |
39 { | |
40 return invokeObjcSelfClass!(void, "detachNewThreadSelector:toTarget:withObject:", SEL, Object, Object)(selector, target, argument); | |
41 } | |
42 | |
43 static bool isMultiThreaded () | |
44 { | |
45 return invokeObjcSelfClass!(bool, "isMultiThreaded"); | |
46 } | |
47 | |
48 NSMutableDictionary threadDictionary () | |
49 { | |
50 return invokeObjcSelf!(NSMutableDictionary, "threadDictionary"); | |
51 } | |
52 | |
53 static void sleepUntilDate (NSDate date) | |
54 { | |
55 return invokeObjcSelfClass!(void, "sleepUntilDate:", NSDate)(date); | |
56 } | |
57 | |
58 static void sleepForTimeInterval (double ti) | |
59 { | |
60 return invokeObjcSelfClass!(void, "sleepForTimeInterval:", double)(ti); | |
61 } | |
62 | |
63 static void exit () | |
64 { | |
65 return invokeObjcSelfClass!(void, "exit"); | |
66 } | |
67 | |
68 static double threadPriority () | |
69 { | |
70 return invokeObjcSelfClass!(double, "threadPriority"); | |
71 } | |
72 | |
73 static bool setThreadPriority (double p) | |
74 { | |
75 return invokeObjcSelfClass!(bool, "setThreadPriority:", double)(p); | |
76 } | |
77 | |
78 static NSArray callStackReturnAddresses () | |
79 { | |
80 return invokeObjcSelfClass!(NSArray, "callStackReturnAddresses"); | |
81 } | |
82 | |
83 void setName (NSString n) | |
84 { | |
85 return invokeObjcSelf!(void, "setName:", NSString)(n); | |
86 } | |
87 | |
88 NSString name () | |
89 { | |
90 return invokeObjcSelf!(NSString, "name"); | |
91 } | |
92 | |
93 NSUInteger stackSize () | |
94 { | |
95 return invokeObjcSelf!(NSUInteger, "stackSize"); | |
96 } | |
97 | |
98 void setStackSize (NSUInteger s) | |
99 { | |
100 return invokeObjcSelf!(void, "setStackSize:", NSUInteger)(s); | |
101 } | |
102 | |
103 bool isMainThread () | |
104 { | |
105 return invokeObjcSelf!(bool, "isMainThread"); | |
106 } | |
107 | |
108 static bool isMainThread () | |
109 { | |
110 return invokeObjcSelfClass!(bool, "isMainThread"); | |
111 } | |
112 | |
113 static NSThread mainThread () | |
114 { | |
15
7ff919f595d5
Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
115 return invokeObjcSelfClass!(NSThread, "mainThread"); |
7ff919f595d5
Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
116 } |
14 | 117 |
118 Object init () | |
119 { | |
120 return invokeObjcSelf!(Object, "init"); | |
121 } | |
122 | |
123 this () | |
124 { | |
125 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
126 id result = Bridge.invokeObjcMethod!(id, "init")(objcObject); | |
127 | |
128 if (result) | |
129 objcObject = ret; | |
130 | |
131 dObject = this; | |
132 } | |
133 | |
134 Object initWithTarget (Object target, SEL selector, Object argument) | |
135 { | |
136 return invokeObjcSelf!(Object, "initWithTarget:selector:object:", Object, SEL, Object)(target, selector, argument); | |
137 } | |
138 | |
139 this (Object target, SEL selector, Object argument) | |
140 { | |
141 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
142 id result = Bridge.invokeObjcMethod!(id, "initWithTarget:selector:object:", Object, SEL, Object)(objcObject, target, selector, argument); | |
143 | |
144 if (result) | |
145 objcObject = ret; | |
146 | |
147 dObject = this; | |
148 } | |
149 | |
150 bool isExecuting () | |
151 { | |
152 return invokeObjcSelf!(bool, "isExecuting"); | |
153 } | |
154 | |
155 bool isFinished () | |
156 { | |
157 return invokeObjcSelf!(bool, "isFinished"); | |
158 } | |
159 | |
160 bool isCancelled () | |
161 { | |
162 return invokeObjcSelf!(bool, "isCancelled"); | |
163 } | |
164 | |
165 void cancel () | |
166 { | |
167 return invokeObjcSelf!(void, "cancel"); | |
168 } | |
169 | |
170 void start () | |
171 { | |
172 return invokeObjcSelf!(void, "start"); | |
173 } | |
174 | |
175 void main () | |
176 { | |
177 return invokeObjcSelf!(void, "main"); | |
178 } | |
179 } | |
180 | |
181 template TNSThreadPerformAdditions () | |
182 { | |
183 void performSelectorOnMainThread (SEL aSelector, Object arg, bool wait, NSArray array); | |
184 void performSelectorOnMainThread (SEL aSelector, Object arg, bool wait); | |
185 void performSelector (SEL aSelector, NSThread thr, Object arg, bool wait, NSArray array); | |
186 void performSelector (SEL aSelector, NSThread thr, Object arg, bool wait); | |
187 void performSelectorInBackground (SEL aSelector, Object arg); | |
188 } | |
189 |