Mercurial > projects > dstep
annotate dstep/foundation/NSPort.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.NSPort; | |
8 | |
9 import dstep.foundation.NSConnection; | |
10 import dstep.foundation.NSData; | |
11 import dstep.foundation.NSDate; | |
12 import dstep.foundation.NSMutableArray; | |
13 import dstep.foundation.NSObject; | |
14 import dstep.foundation.NSPortMessage; | |
15 import dstep.foundation.NSRunLoop; | |
16 import dstep.objc.bridge.Bridge; | |
17 import dstep.objc.objc : id; | |
18 | |
19 import bindings = dstep.foundation.NSPort_bindings; | |
20 | |
21 alias int NSSocketNativeHandle; | |
22 | |
23 const NSString NSPortDidBecomeInvalidNotification; | |
24 | |
25 enum | |
26 { | |
27 NSMachPortDeallocateNone = 0, | |
28 NSMachPortDeallocateSendRight = (1 << 0), | |
29 NSMachPortDeallocateReceiveRight = (1 << 1) | |
30 } | |
31 | |
32 static this () | |
33 { | |
34 NSPortDidBecomeInvalidNotification = new NSString(bindings.NSPortDidBecomeInvalidNotification); | |
35 } | |
36 | |
37 class NSPort : NSObject, INSCopying, INSCoding | |
38 { | |
39 mixin ObjcWrap; | |
40 | |
41 static Object allocWithZone (NSZone* zone) | |
42 { | |
43 return invokeObjcSelfClass!(Object, "allocWithZone:", NSZone*)(zone); | |
44 } | |
45 | |
46 static NSPort port () | |
47 { | |
15
7ff919f595d5
Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
48 return invokeObjcSelfClass!(NSPort, "port"); |
7ff919f595d5
Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
49 } |
14 | 50 |
51 void invalidate () | |
52 { | |
53 return invokeObjcSelf!(void, "invalidate"); | |
54 } | |
55 | |
56 bool isValid () | |
57 { | |
58 return invokeObjcSelf!(bool, "isValid"); | |
59 } | |
60 | |
61 void setDelegate (Object anId) | |
62 { | |
63 return invokeObjcSelf!(void, "setDelegate:", Object)(anId); | |
64 } | |
65 | |
66 Object delegate_ () | |
67 { | |
68 return invokeObjcSelf!(Object, "delegate"); | |
69 } | |
70 | |
71 void scheduleInRunLoop (NSRunLoop runLoop, NSString mode) | |
72 { | |
73 return invokeObjcSelf!(void, "scheduleInRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode); | |
74 } | |
75 | |
76 void removeFromRunLoop (NSRunLoop runLoop, NSString mode) | |
77 { | |
78 return invokeObjcSelf!(void, "removeFromRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode); | |
79 } | |
80 | |
81 NSUInteger reservedSpaceLength () | |
82 { | |
83 return invokeObjcSelf!(NSUInteger, "reservedSpaceLength"); | |
84 } | |
85 | |
86 bool sendBeforeDate (NSDate limitDate, NSMutableArray components, NSPort receivePort, NSUInteger headerSpaceReserved) | |
87 { | |
88 return invokeObjcSelf!(bool, "sendBeforeDate:components:from:reserved:", NSDate, NSMutableArray, NSPort, NSUInteger)(limitDate, components, receivePort, headerSpaceReserved); | |
89 } | |
90 | |
91 bool sendBeforeDate (NSDate limitDate, NSUInteger msgID, NSMutableArray components, NSPort receivePort, NSUInteger headerSpaceReserved) | |
92 { | |
93 return invokeObjcSelf!(bool, "sendBeforeDate:msgid:components:from:reserved:", NSDate, NSUInteger, NSMutableArray, NSPort, NSUInteger)(limitDate, msgID, components, receivePort, headerSpaceReserved); | |
94 } | |
95 | |
96 void addConnection (NSConnection conn, NSRunLoop runLoop, NSString mode) | |
97 { | |
98 return invokeObjcSelf!(void, "addConnection:toRunLoop:forMode:", NSConnection, NSRunLoop, NSString)(conn, runLoop, mode); | |
99 } | |
100 | |
101 void removeConnection (NSConnection conn, NSRunLoop runLoop, NSString mode) | |
102 { | |
103 return invokeObjcSelf!(void, "removeConnection:fromRunLoop:forMode:", NSConnection, NSRunLoop, NSString)(conn, runLoop, mode); | |
104 } | |
105 | |
106 Object copyWithZone (NSZone* zone) | |
107 { | |
108 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); | |
109 } | |
110 | |
111 void encodeWithCoder (NSCoder aCoder) | |
112 { | |
113 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); | |
114 } | |
115 | |
116 Object initWithCoder (NSCoder aDecoder) | |
117 { | |
118 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | |
119 } | |
120 | |
121 this (NSCoder aDecoder) | |
122 { | |
123 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
124 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | |
125 | |
126 if (result) | |
127 objcObject = ret; | |
128 | |
129 dObject = this; | |
130 } | |
131 } | |
132 | |
133 class NSSocketPort : NSPort | |
134 { | |
135 mixin ObjcWrap; | |
136 | |
137 Object init () | |
138 { | |
139 return invokeObjcSelf!(Object, "init"); | |
140 } | |
141 | |
142 this () | |
143 { | |
144 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
145 id result = Bridge.invokeObjcMethod!(id, "init")(objcObject); | |
146 | |
147 if (result) | |
148 objcObject = ret; | |
149 | |
150 dObject = this; | |
151 } | |
152 | |
153 Object initWithTCPPort (ushort port) | |
154 { | |
155 return invokeObjcSelf!(Object, "initWithTCPPort:", ushort)(port); | |
156 } | |
157 | |
158 this (ushort port) | |
159 { | |
160 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
161 id result = Bridge.invokeObjcMethod!(id, "initWithTCPPort:", ushort)(objcObject, port); | |
162 | |
163 if (result) | |
164 objcObject = ret; | |
165 | |
166 dObject = this; | |
167 } | |
168 | |
169 Object initWithProtocolFamily (int family, int type, int protocol, NSData address) | |
170 { | |
171 return invokeObjcSelf!(Object, "initWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(family, type, protocol, address); | |
172 } | |
173 | |
174 this (int family, int type, int protocol, NSData address) | |
175 { | |
176 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
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 } | |
184 | |
185 Object initWithProtocolFamily (int family, int type, int protocol, int sock) | |
186 { | |
187 return invokeObjcSelf!(Object, "initWithProtocolFamily:socketType:protocol:socket:", int, int, int, int)(family, type, protocol, sock); | |
188 } | |
189 | |
190 this (int family, int type, int protocol, int sock) | |
191 { | |
192 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
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 } | |
200 | |
201 Object initRemoteWithTCPPort (ushort port, NSString hostName) | |
202 { | |
203 return invokeObjcSelf!(Object, "initRemoteWithTCPPort:host:", ushort, NSString)(port, hostName); | |
204 } | |
205 | |
206 this (ushort port, NSString hostName) | |
207 { | |
208 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
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 } | |
216 | |
217 Object initRemoteWithProtocolFamily (int family, int type, int protocol, NSData address) | |
218 { | |
219 return invokeObjcSelf!(Object, "initRemoteWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(family, type, protocol, address); | |
220 } | |
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 () | |
234 { | |
235 return invokeObjcSelf!(int, "protocolFamily"); | |
236 } | |
237 | |
238 int socketType () | |
239 { | |
240 return invokeObjcSelf!(int, "socketType"); | |
241 } | |
242 | |
243 int protocol () | |
244 { | |
245 return invokeObjcSelf!(int, "protocol"); | |
246 } | |
247 | |
248 NSData address () | |
249 { | |
250 return invokeObjcSelf!(NSData, "address"); | |
251 } | |
252 | |
253 int socket () | |
254 { | |
255 return invokeObjcSelf!(int, "socket"); | |
256 } | |
257 } | |
258 | |
259 class NSMachPort : NSPort | |
260 { | |
261 mixin ObjcWrap; | |
262 | |
263 static NSPort portWithMachPort (uint machPort) | |
264 { | |
265 return invokeObjcSelfClass!(NSPort, "portWithMachPort:", uint)(machPort); | |
266 } | |
267 | |
268 Object initWithMachPort (uint machPort) | |
269 { | |
270 return invokeObjcSelf!(Object, "initWithMachPort:", uint)(machPort); | |
271 } | |
272 | |
273 this (uint machPort) | |
274 { | |
275 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
276 id result = Bridge.invokeObjcMethod!(id, "initWithMachPort:", uint)(objcObject, machPort); | |
277 | |
278 if (result) | |
279 objcObject = ret; | |
280 | |
281 dObject = this; | |
282 } | |
283 | |
284 static NSPort portWithMachPort (uint machPort, NSUInteger f) | |
285 { | |
286 return invokeObjcSelfClass!(NSPort, "portWithMachPort:options:", uint, NSUInteger)(machPort, f); | |
287 } | |
288 | |
289 Object initWithMachPort (uint machPort, NSUInteger f) | |
290 { | |
291 return invokeObjcSelf!(Object, "initWithMachPort:options:", uint, NSUInteger)(machPort, f); | |
292 } | |
293 | |
294 this (uint machPort, NSUInteger f) | |
295 { | |
296 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
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 } | |
304 | |
305 uint machPort () | |
306 { | |
307 return invokeObjcSelf!(uint, "machPort"); | |
308 } | |
309 | |
310 void scheduleInRunLoop (NSRunLoop runLoop, NSString mode) | |
311 { | |
312 return invokeObjcSelf!(void, "scheduleInRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode); | |
313 } | |
314 | |
315 void removeFromRunLoop (NSRunLoop runLoop, NSString mode) | |
316 { | |
317 return invokeObjcSelf!(void, "removeFromRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode); | |
318 } | |
319 } | |
320 | |
321 template TNSMachPortDelegateMethods () | |
322 { | |
323 void handleMachMessage (void* msg); | |
324 } | |
325 | |
326 template TNSPortDelegateMethods () | |
327 { | |
328 void handlePortMessage (NSPortMessage message); | |
329 } | |
330 |