Mercurial > projects > dstep
comparison dstep/foundation/NSPort.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 | 7ff919f595d5 |
children | b9de51448c6b |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
4 * Version: Initial created: Aug 3, 2009 | 4 * Version: Initial created: Aug 3, 2009 |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) |
6 */ | 6 */ |
7 module dstep.foundation.NSPort; | 7 module dstep.foundation.NSPort; |
8 | 8 |
9 import dstep.foundation.NSArray; | |
10 import dstep.foundation.NSCoder; | |
9 import dstep.foundation.NSConnection; | 11 import dstep.foundation.NSConnection; |
10 import dstep.foundation.NSData; | 12 import dstep.foundation.NSData; |
11 import dstep.foundation.NSDate; | 13 import dstep.foundation.NSDate; |
12 import dstep.foundation.NSMutableArray; | 14 import dstep.foundation.NSObjCRuntime; |
13 import dstep.foundation.NSObject; | 15 import dstep.foundation.NSObject; |
14 import dstep.foundation.NSPortMessage; | 16 import dstep.foundation.NSPortMessage; |
15 import dstep.foundation.NSRunLoop; | 17 import dstep.foundation.NSRunLoop; |
18 import dstep.foundation.NSString; | |
19 import dstep.foundation.NSZone; | |
16 import dstep.objc.bridge.Bridge; | 20 import dstep.objc.bridge.Bridge; |
17 import dstep.objc.objc : id; | 21 import dstep.objc.objc; |
18 | |
19 import bindings = dstep.foundation.NSPort_bindings; | 22 import bindings = dstep.foundation.NSPort_bindings; |
20 | 23 |
21 alias int NSSocketNativeHandle; | 24 alias int NSSocketNativeHandle; |
22 | 25 |
23 const NSString NSPortDidBecomeInvalidNotification; | 26 private NSString NSPortDidBecomeInvalidNotification_; |
27 | |
28 NSString NSPortDidBecomeInvalidNotification () | |
29 { | |
30 if (NSPortDidBecomeInvalidNotification_) | |
31 return NSPortDidBecomeInvalidNotification_; | |
32 | |
33 return NSPortDidBecomeInvalidNotification_ = new NSString(bindings.NSPortDidBecomeInvalidNotification); | |
34 } | |
24 | 35 |
25 enum | 36 enum |
26 { | 37 { |
27 NSMachPortDeallocateNone = 0, | 38 NSMachPortDeallocateNone = 0, |
28 NSMachPortDeallocateSendRight = (1 << 0), | 39 NSMachPortDeallocateSendRight = (1 << 0), |
29 NSMachPortDeallocateReceiveRight = (1 << 1) | 40 NSMachPortDeallocateReceiveRight = (1 << 1) |
30 } | 41 } |
31 | 42 |
32 static this () | 43 const TNSMachPortDelegateMethods = ` |
33 { | 44 |
34 NSPortDidBecomeInvalidNotification = new NSString(bindings.NSPortDidBecomeInvalidNotification); | 45 void handleMachMessage (void* msg) |
35 } | 46 { |
47 return invokeObjcSelf!(void, "handleMachMessage:", void*)(msg); | |
48 } | |
49 | |
50 //mixin ObjcBindMethod!(handleMachMessage, "handleMachMessage:"); | |
51 `; | |
52 | |
53 const TNSPortDelegateMethods = ` | |
54 | |
55 void handlePortMessage (NSPortMessage message) | |
56 { | |
57 return invokeObjcSelf!(void, "handlePortMessage:", NSPortMessage)(message); | |
58 } | |
59 | |
60 //mixin ObjcBindMethod!(handlePortMessage, "handlePortMessage:"); | |
61 `; | |
36 | 62 |
37 class NSPort : NSObject, INSCopying, INSCoding | 63 class NSPort : NSObject, INSCopying, INSCoding |
38 { | 64 { |
39 mixin ObjcWrap; | 65 mixin (ObjcWrap); |
66 | |
67 this () | |
68 { | |
69 super(typeof(this).alloc.init.objcObject); | |
70 } | |
71 | |
72 typeof(this) init () | |
73 { | |
74 return invokeObjcSelf!(typeof(this), "init"); | |
75 } | |
40 | 76 |
41 static Object allocWithZone (NSZone* zone) | 77 static Object allocWithZone (NSZone* zone) |
42 { | 78 { |
43 return invokeObjcSelfClass!(Object, "allocWithZone:", NSZone*)(zone); | 79 return invokeObjcSuperClass!(Object, "allocWithZone:", NSZone*)(zone); |
44 } | 80 } |
45 | 81 |
46 static NSPort port () | 82 static NSPort port () |
47 { | 83 { |
48 return invokeObjcSelfClass!(NSPort, "port"); | 84 return invokeObjcSuperClass!(NSPort, "port"); |
49 } | 85 } |
50 | 86 |
51 void invalidate () | 87 void invalidate () |
52 { | 88 { |
53 return invokeObjcSelf!(void, "invalidate"); | 89 return invokeObjcSelf!(void, "invalidate"); |
118 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | 154 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); |
119 } | 155 } |
120 | 156 |
121 this (NSCoder aDecoder) | 157 this (NSCoder aDecoder) |
122 { | 158 { |
123 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 159 typeof(this).alloc.initWithCoder(aDecoder); |
124 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | |
125 | |
126 if (result) | |
127 objcObject = ret; | |
128 | |
129 dObject = this; | |
130 } | 160 } |
131 } | 161 } |
132 | 162 |
133 class NSSocketPort : NSPort | 163 class NSSocketPort : NSPort |
134 { | 164 { |
135 mixin ObjcWrap; | 165 mixin (ObjcWrap); |
136 | 166 |
137 Object init () | |
138 { | |
139 return invokeObjcSelf!(Object, "init"); | |
140 } | |
141 | |
142 this () | 167 this () |
143 { | 168 { |
144 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 169 super(typeof(this).alloc.init.objcObject); |
145 id result = Bridge.invokeObjcMethod!(id, "init")(objcObject); | 170 } |
146 | 171 |
147 if (result) | 172 typeof(this) init () |
148 objcObject = ret; | 173 { |
149 | 174 return invokeObjcSelf!(typeof(this), "init"); |
150 dObject = this; | |
151 } | 175 } |
152 | 176 |
153 Object initWithTCPPort (ushort port) | 177 Object initWithTCPPort (ushort port) |
154 { | 178 { |
155 return invokeObjcSelf!(Object, "initWithTCPPort:", ushort)(port); | 179 return invokeObjcSelf!(Object, "initWithTCPPort:", ushort)(port); |
156 } | 180 } |
157 | 181 |
158 this (ushort port) | 182 this (ushort port) |
159 { | 183 { |
160 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 184 typeof(this).alloc.initWithTCPPort(port); |
161 id result = Bridge.invokeObjcMethod!(id, "initWithTCPPort:", ushort)(objcObject, port); | |
162 | |
163 if (result) | |
164 objcObject = ret; | |
165 | |
166 dObject = this; | |
167 } | 185 } |
168 | 186 |
169 Object initWithProtocolFamily (int family, int type, int protocol, NSData address) | 187 Object initWithProtocolFamily (int family, int type, int protocol, NSData address) |
170 { | 188 { |
171 return invokeObjcSelf!(Object, "initWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(family, type, protocol, address); | 189 return invokeObjcSelf!(Object, "initWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(family, type, protocol, address); |
172 } | 190 } |
173 | 191 |
174 this (int family, int type, int protocol, NSData address) | 192 this (int family, int type, int protocol, NSData address) |
175 { | 193 { |
176 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 194 typeof(this).alloc.initWithProtocolFamily(family, type, protocol, address); |
177 id result = Bridge.invokeObjcMethod!(id, "initWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(objcObject, family, type, protocol, address); | |
178 | |
179 if (result) | |
180 objcObject = ret; | |
181 | |
182 dObject = this; | |
183 } | 195 } |
184 | 196 |
185 Object initWithProtocolFamily (int family, int type, int protocol, int sock) | 197 Object initWithProtocolFamily (int family, int type, int protocol, int sock) |
186 { | 198 { |
187 return invokeObjcSelf!(Object, "initWithProtocolFamily:socketType:protocol:socket:", int, int, int, int)(family, type, protocol, sock); | 199 return invokeObjcSelf!(Object, "initWithProtocolFamily:socketType:protocol:socket:", int, int, int, int)(family, type, protocol, sock); |
188 } | 200 } |
189 | 201 |
190 this (int family, int type, int protocol, int sock) | 202 this (int family, int type, int protocol, int sock) |
191 { | 203 { |
192 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 204 typeof(this).alloc.initWithProtocolFamily(family, type, protocol, sock); |
193 id result = Bridge.invokeObjcMethod!(id, "initWithProtocolFamily:socketType:protocol:socket:", int, int, int, int)(objcObject, family, type, protocol, sock); | |
194 | |
195 if (result) | |
196 objcObject = ret; | |
197 | |
198 dObject = this; | |
199 } | 205 } |
200 | 206 |
201 Object initRemoteWithTCPPort (ushort port, NSString hostName) | 207 Object initRemoteWithTCPPort (ushort port, NSString hostName) |
202 { | 208 { |
203 return invokeObjcSelf!(Object, "initRemoteWithTCPPort:host:", ushort, NSString)(port, hostName); | 209 return invokeObjcSelf!(Object, "initRemoteWithTCPPort:host:", ushort, NSString)(port, hostName); |
204 } | 210 } |
205 | 211 |
206 this (ushort port, NSString hostName) | 212 this (ushort port, NSString hostName) |
207 { | 213 { |
208 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 214 typeof(this).alloc.initRemoteWithTCPPort(port, hostName); |
209 id result = Bridge.invokeObjcMethod!(id, "initRemoteWithTCPPort:host:", ushort, NSString)(objcObject, port, hostName); | |
210 | |
211 if (result) | |
212 objcObject = ret; | |
213 | |
214 dObject = this; | |
215 } | 215 } |
216 | 216 |
217 Object initRemoteWithProtocolFamily (int family, int type, int protocol, NSData address) | 217 Object initRemoteWithProtocolFamily (int family, int type, int protocol, NSData address) |
218 { | 218 { |
219 return invokeObjcSelf!(Object, "initRemoteWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(family, type, protocol, address); | 219 return invokeObjcSelf!(Object, "initRemoteWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(family, type, protocol, address); |
220 } | 220 } |
221 | 221 |
222 this (int family, int type, int protocol, NSData address) | |
223 { | |
224 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
225 id result = Bridge.invokeObjcMethod!(id, "initRemoteWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(objcObject, family, type, protocol, address); | |
226 | |
227 if (result) | |
228 objcObject = ret; | |
229 | |
230 dObject = this; | |
231 } | |
232 | |
233 int protocolFamily () | 222 int protocolFamily () |
234 { | 223 { |
235 return invokeObjcSelf!(int, "protocolFamily"); | 224 return invokeObjcSelf!(int, "protocolFamily"); |
236 } | 225 } |
237 | 226 |
256 } | 245 } |
257 } | 246 } |
258 | 247 |
259 class NSMachPort : NSPort | 248 class NSMachPort : NSPort |
260 { | 249 { |
261 mixin ObjcWrap; | 250 mixin (ObjcWrap); |
251 | |
252 this () | |
253 { | |
254 super(typeof(this).alloc.init.objcObject); | |
255 } | |
256 | |
257 typeof(this) init () | |
258 { | |
259 return invokeObjcSelf!(typeof(this), "init"); | |
260 } | |
262 | 261 |
263 static NSPort portWithMachPort (uint machPort) | 262 static NSPort portWithMachPort (uint machPort) |
264 { | 263 { |
265 return invokeObjcSelfClass!(NSPort, "portWithMachPort:", uint)(machPort); | 264 return invokeObjcSuperClass!(NSPort, "portWithMachPort:", uint)(machPort); |
266 } | 265 } |
267 | 266 |
268 Object initWithMachPort (uint machPort) | 267 Object initWithMachPort (uint machPort) |
269 { | 268 { |
270 return invokeObjcSelf!(Object, "initWithMachPort:", uint)(machPort); | 269 return invokeObjcSelf!(Object, "initWithMachPort:", uint)(machPort); |
271 } | 270 } |
272 | 271 |
273 this (uint machPort) | 272 this (uint machPort) |
274 { | 273 { |
275 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 274 typeof(this).alloc.initWithMachPort(machPort); |
276 id result = Bridge.invokeObjcMethod!(id, "initWithMachPort:", uint)(objcObject, machPort); | |
277 | |
278 if (result) | |
279 objcObject = ret; | |
280 | |
281 dObject = this; | |
282 } | 275 } |
283 | 276 |
284 static NSPort portWithMachPort (uint machPort, NSUInteger f) | 277 static NSPort portWithMachPort (uint machPort, NSUInteger f) |
285 { | 278 { |
286 return invokeObjcSelfClass!(NSPort, "portWithMachPort:options:", uint, NSUInteger)(machPort, f); | 279 return invokeObjcSuperClass!(NSPort, "portWithMachPort:options:", uint, NSUInteger)(machPort, f); |
287 } | 280 } |
288 | 281 |
289 Object initWithMachPort (uint machPort, NSUInteger f) | 282 Object initWithMachPort (uint machPort, NSUInteger f) |
290 { | 283 { |
291 return invokeObjcSelf!(Object, "initWithMachPort:options:", uint, NSUInteger)(machPort, f); | 284 return invokeObjcSelf!(Object, "initWithMachPort:options:", uint, NSUInteger)(machPort, f); |
292 } | 285 } |
293 | 286 |
294 this (uint machPort, NSUInteger f) | 287 this (uint machPort, NSUInteger f) |
295 { | 288 { |
296 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 289 typeof(this).alloc.initWithMachPort(machPort, f); |
297 id result = Bridge.invokeObjcMethod!(id, "initWithMachPort:options:", uint, NSUInteger)(objcObject, machPort, f); | |
298 | |
299 if (result) | |
300 objcObject = ret; | |
301 | |
302 dObject = this; | |
303 } | 290 } |
304 | 291 |
305 uint machPort () | 292 uint machPort () |
306 { | 293 { |
307 return invokeObjcSelf!(uint, "machPort"); | 294 return invokeObjcSelf!(uint, "machPort"); |
315 void removeFromRunLoop (NSRunLoop runLoop, NSString mode) | 302 void removeFromRunLoop (NSRunLoop runLoop, NSString mode) |
316 { | 303 { |
317 return invokeObjcSelf!(void, "removeFromRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode); | 304 return invokeObjcSelf!(void, "removeFromRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode); |
318 } | 305 } |
319 } | 306 } |
320 | |
321 template TNSMachPortDelegateMethods () | |
322 { | |
323 void handleMachMessage (void* msg); | |
324 } | |
325 | |
326 template TNSPortDelegateMethods () | |
327 { | |
328 void handlePortMessage (NSPortMessage message); | |
329 } | |
330 |