Mercurial > projects > dstep
annotate dstep/foundation/NSLock.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.NSLock; | |
8 | |
9 import dstep.foundation.NSDate; | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
10 import dstep.foundation.NSObjCRuntime; |
14 | 11 import dstep.foundation.NSObject; |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
12 import dstep.foundation.NSString; |
14 | 13 import dstep.objc.bridge.Bridge; |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
14 import dstep.objc.objc; |
14 | 15 |
16 class NSLock : NSObject, INSLocking | |
17 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
18 mixin (ObjcWrap); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
19 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
20 this () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
21 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
22 super(typeof(this).alloc.init.objcObject); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
23 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
24 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
25 typeof(this) init () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
26 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
27 return invokeObjcSelf!(typeof(this), "init"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
28 } |
14 | 29 |
30 bool tryLock () | |
31 { | |
32 return invokeObjcSelf!(bool, "tryLock"); | |
33 } | |
34 | |
35 bool lockBeforeDate (NSDate limit) | |
36 { | |
37 return invokeObjcSelf!(bool, "lockBeforeDate:", NSDate)(limit); | |
38 } | |
39 | |
40 void setName (NSString n) | |
41 { | |
42 return invokeObjcSelf!(void, "setName:", NSString)(n); | |
43 } | |
44 | |
45 NSString name () | |
46 { | |
47 return invokeObjcSelf!(NSString, "name"); | |
48 } | |
49 | |
50 void lock () | |
51 { | |
52 return invokeObjcSelf!(void, "lock"); | |
53 } | |
54 | |
55 void unlock () | |
56 { | |
57 return invokeObjcSelf!(void, "unlock"); | |
58 } | |
59 } | |
60 | |
61 class NSCondition : NSObject, INSLocking | |
62 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
63 mixin (ObjcWrap); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
64 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
65 this () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
66 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
67 super(typeof(this).alloc.init.objcObject); |
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 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
70 typeof(this) init () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
71 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
72 return invokeObjcSelf!(typeof(this), "init"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
73 } |
14 | 74 |
75 void wait () | |
76 { | |
77 return invokeObjcSelf!(void, "wait"); | |
78 } | |
79 | |
80 bool waitUntilDate (NSDate limit) | |
81 { | |
82 return invokeObjcSelf!(bool, "waitUntilDate:", NSDate)(limit); | |
83 } | |
84 | |
85 void signal () | |
86 { | |
87 return invokeObjcSelf!(void, "signal"); | |
88 } | |
89 | |
90 void broadcast () | |
91 { | |
92 return invokeObjcSelf!(void, "broadcast"); | |
93 } | |
94 | |
95 void setName (NSString n) | |
96 { | |
97 return invokeObjcSelf!(void, "setName:", NSString)(n); | |
98 } | |
99 | |
100 NSString name () | |
101 { | |
102 return invokeObjcSelf!(NSString, "name"); | |
103 } | |
104 | |
105 void lock () | |
106 { | |
107 return invokeObjcSelf!(void, "lock"); | |
108 } | |
109 | |
110 void unlock () | |
111 { | |
112 return invokeObjcSelf!(void, "unlock"); | |
113 } | |
114 } | |
115 | |
116 class NSConditionLock : NSObject, INSLocking | |
117 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
118 mixin (ObjcWrap); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
119 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
120 this () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
121 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
122 super(typeof(this).alloc.init.objcObject); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
123 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
124 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
125 typeof(this) init () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
126 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
127 return invokeObjcSelf!(typeof(this), "init"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
128 } |
14 | 129 |
130 Object initWithCondition (NSInteger condition) | |
131 { | |
132 return invokeObjcSelf!(Object, "initWithCondition:", NSInteger)(condition); | |
133 } | |
134 | |
135 this (NSInteger condition) | |
136 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
137 typeof(this).alloc.initWithCondition(condition); |
14 | 138 } |
139 | |
140 NSInteger condition () | |
141 { | |
142 return invokeObjcSelf!(NSInteger, "condition"); | |
143 } | |
144 | |
145 void lockWhenCondition (NSInteger condition) | |
146 { | |
147 return invokeObjcSelf!(void, "lockWhenCondition:", NSInteger)(condition); | |
148 } | |
149 | |
150 bool tryLock () | |
151 { | |
152 return invokeObjcSelf!(bool, "tryLock"); | |
153 } | |
154 | |
155 bool tryLockWhenCondition (NSInteger condition) | |
156 { | |
157 return invokeObjcSelf!(bool, "tryLockWhenCondition:", NSInteger)(condition); | |
158 } | |
159 | |
160 void unlockWithCondition (NSInteger condition) | |
161 { | |
162 return invokeObjcSelf!(void, "unlockWithCondition:", NSInteger)(condition); | |
163 } | |
164 | |
165 bool lockBeforeDate (NSDate limit) | |
166 { | |
167 return invokeObjcSelf!(bool, "lockBeforeDate:", NSDate)(limit); | |
168 } | |
169 | |
170 bool lockWhenCondition (NSInteger condition, NSDate limit) | |
171 { | |
172 return invokeObjcSelf!(bool, "lockWhenCondition:beforeDate:", NSInteger, NSDate)(condition, limit); | |
173 } | |
174 | |
175 void setName (NSString n) | |
176 { | |
177 return invokeObjcSelf!(void, "setName:", NSString)(n); | |
178 } | |
179 | |
180 NSString name () | |
181 { | |
182 return invokeObjcSelf!(NSString, "name"); | |
183 } | |
184 | |
185 void lock () | |
186 { | |
187 return invokeObjcSelf!(void, "lock"); | |
188 } | |
189 | |
190 void unlock () | |
191 { | |
192 return invokeObjcSelf!(void, "unlock"); | |
193 } | |
194 } | |
195 | |
196 class NSRecursiveLock : NSObject, INSLocking | |
197 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
198 mixin (ObjcWrap); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
199 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
200 this () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
201 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
202 super(typeof(this).alloc.init.objcObject); |
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 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
205 typeof(this) init () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
206 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
207 return invokeObjcSelf!(typeof(this), "init"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
208 } |
14 | 209 |
210 bool tryLock () | |
211 { | |
212 return invokeObjcSelf!(bool, "tryLock"); | |
213 } | |
214 | |
215 bool lockBeforeDate (NSDate limit) | |
216 { | |
217 return invokeObjcSelf!(bool, "lockBeforeDate:", NSDate)(limit); | |
218 } | |
219 | |
220 void setName (NSString n) | |
221 { | |
222 return invokeObjcSelf!(void, "setName:", NSString)(n); | |
223 } | |
224 | |
225 NSString name () | |
226 { | |
227 return invokeObjcSelf!(NSString, "name"); | |
228 } | |
229 | |
230 void lock () | |
231 { | |
232 return invokeObjcSelf!(void, "lock"); | |
233 } | |
234 | |
235 void unlock () | |
236 { | |
237 return invokeObjcSelf!(void, "unlock"); | |
238 } | |
239 } | |
240 | |
241 interface INSLocking | |
242 { | |
243 void lock (); | |
244 void unlock (); | |
245 } | |
246 |