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