comparison dstep/foundation/NSPort.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.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 {
48 return invokeObjcSelfClass!(NSPort, "port"return result is this.objcObject ? this : (result !is null ? new NSPort(result) : null); }
49
50 void invalidate ()
51 {
52 return invokeObjcSelf!(void, "invalidate");
53 }
54
55 bool isValid ()
56 {
57 return invokeObjcSelf!(bool, "isValid");
58 }
59
60 void setDelegate (Object anId)
61 {
62 return invokeObjcSelf!(void, "setDelegate:", Object)(anId);
63 }
64
65 Object delegate_ ()
66 {
67 return invokeObjcSelf!(Object, "delegate");
68 }
69
70 void scheduleInRunLoop (NSRunLoop runLoop, NSString mode)
71 {
72 return invokeObjcSelf!(void, "scheduleInRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode);
73 }
74
75 void removeFromRunLoop (NSRunLoop runLoop, NSString mode)
76 {
77 return invokeObjcSelf!(void, "removeFromRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode);
78 }
79
80 NSUInteger reservedSpaceLength ()
81 {
82 return invokeObjcSelf!(NSUInteger, "reservedSpaceLength");
83 }
84
85 bool sendBeforeDate (NSDate limitDate, NSMutableArray components, NSPort receivePort, NSUInteger headerSpaceReserved)
86 {
87 return invokeObjcSelf!(bool, "sendBeforeDate:components:from:reserved:", NSDate, NSMutableArray, NSPort, NSUInteger)(limitDate, components, receivePort, headerSpaceReserved);
88 }
89
90 bool sendBeforeDate (NSDate limitDate, NSUInteger msgID, NSMutableArray components, NSPort receivePort, NSUInteger headerSpaceReserved)
91 {
92 return invokeObjcSelf!(bool, "sendBeforeDate:msgid:components:from:reserved:", NSDate, NSUInteger, NSMutableArray, NSPort, NSUInteger)(limitDate, msgID, components, receivePort, headerSpaceReserved);
93 }
94
95 void addConnection (NSConnection conn, NSRunLoop runLoop, NSString mode)
96 {
97 return invokeObjcSelf!(void, "addConnection:toRunLoop:forMode:", NSConnection, NSRunLoop, NSString)(conn, runLoop, mode);
98 }
99
100 void removeConnection (NSConnection conn, NSRunLoop runLoop, NSString mode)
101 {
102 return invokeObjcSelf!(void, "removeConnection:fromRunLoop:forMode:", NSConnection, NSRunLoop, NSString)(conn, runLoop, mode);
103 }
104
105 Object copyWithZone (NSZone* zone)
106 {
107 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
108 }
109
110 void encodeWithCoder (NSCoder aCoder)
111 {
112 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
113 }
114
115 Object initWithCoder (NSCoder aDecoder)
116 {
117 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
118 }
119
120 this (NSCoder aDecoder)
121 {
122 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
123 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);
124
125 if (result)
126 objcObject = ret;
127
128 dObject = this;
129 }
130 }
131
132 class NSSocketPort : NSPort
133 {
134 mixin ObjcWrap;
135
136 Object init ()
137 {
138 return invokeObjcSelf!(Object, "init");
139 }
140
141 this ()
142 {
143 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
144 id result = Bridge.invokeObjcMethod!(id, "init")(objcObject);
145
146 if (result)
147 objcObject = ret;
148
149 dObject = this;
150 }
151
152 Object initWithTCPPort (ushort port)
153 {
154 return invokeObjcSelf!(Object, "initWithTCPPort:", ushort)(port);
155 }
156
157 this (ushort port)
158 {
159 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
160 id result = Bridge.invokeObjcMethod!(id, "initWithTCPPort:", ushort)(objcObject, port);
161
162 if (result)
163 objcObject = ret;
164
165 dObject = this;
166 }
167
168 Object initWithProtocolFamily (int family, int type, int protocol, NSData address)
169 {
170 return invokeObjcSelf!(Object, "initWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(family, type, protocol, address);
171 }
172
173 this (int family, int type, int protocol, NSData address)
174 {
175 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
176 id result = Bridge.invokeObjcMethod!(id, "initWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(objcObject, family, type, protocol, address);
177
178 if (result)
179 objcObject = ret;
180
181 dObject = this;
182 }
183
184 Object initWithProtocolFamily (int family, int type, int protocol, int sock)
185 {
186 return invokeObjcSelf!(Object, "initWithProtocolFamily:socketType:protocol:socket:", int, int, int, int)(family, type, protocol, sock);
187 }
188
189 this (int family, int type, int protocol, int sock)
190 {
191 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
192 id result = Bridge.invokeObjcMethod!(id, "initWithProtocolFamily:socketType:protocol:socket:", int, int, int, int)(objcObject, family, type, protocol, sock);
193
194 if (result)
195 objcObject = ret;
196
197 dObject = this;
198 }
199
200 Object initRemoteWithTCPPort (ushort port, NSString hostName)
201 {
202 return invokeObjcSelf!(Object, "initRemoteWithTCPPort:host:", ushort, NSString)(port, hostName);
203 }
204
205 this (ushort port, NSString hostName)
206 {
207 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
208 id result = Bridge.invokeObjcMethod!(id, "initRemoteWithTCPPort:host:", ushort, NSString)(objcObject, port, hostName);
209
210 if (result)
211 objcObject = ret;
212
213 dObject = this;
214 }
215
216 Object initRemoteWithProtocolFamily (int family, int type, int protocol, NSData address)
217 {
218 return invokeObjcSelf!(Object, "initRemoteWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(family, type, protocol, address);
219 }
220
221 this (int family, int type, int protocol, NSData address)
222 {
223 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
224 id result = Bridge.invokeObjcMethod!(id, "initRemoteWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(objcObject, family, type, protocol, address);
225
226 if (result)
227 objcObject = ret;
228
229 dObject = this;
230 }
231
232 int protocolFamily ()
233 {
234 return invokeObjcSelf!(int, "protocolFamily");
235 }
236
237 int socketType ()
238 {
239 return invokeObjcSelf!(int, "socketType");
240 }
241
242 int protocol ()
243 {
244 return invokeObjcSelf!(int, "protocol");
245 }
246
247 NSData address ()
248 {
249 return invokeObjcSelf!(NSData, "address");
250 }
251
252 int socket ()
253 {
254 return invokeObjcSelf!(int, "socket");
255 }
256 }
257
258 class NSMachPort : NSPort
259 {
260 mixin ObjcWrap;
261
262 static NSPort portWithMachPort (uint machPort)
263 {
264 return invokeObjcSelfClass!(NSPort, "portWithMachPort:", uint)(machPort);
265 }
266
267 Object initWithMachPort (uint machPort)
268 {
269 return invokeObjcSelf!(Object, "initWithMachPort:", uint)(machPort);
270 }
271
272 this (uint machPort)
273 {
274 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
275 id result = Bridge.invokeObjcMethod!(id, "initWithMachPort:", uint)(objcObject, machPort);
276
277 if (result)
278 objcObject = ret;
279
280 dObject = this;
281 }
282
283 static NSPort portWithMachPort (uint machPort, NSUInteger f)
284 {
285 return invokeObjcSelfClass!(NSPort, "portWithMachPort:options:", uint, NSUInteger)(machPort, f);
286 }
287
288 Object initWithMachPort (uint machPort, NSUInteger f)
289 {
290 return invokeObjcSelf!(Object, "initWithMachPort:options:", uint, NSUInteger)(machPort, f);
291 }
292
293 this (uint machPort, NSUInteger f)
294 {
295 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
296 id result = Bridge.invokeObjcMethod!(id, "initWithMachPort:options:", uint, NSUInteger)(objcObject, machPort, f);
297
298 if (result)
299 objcObject = ret;
300
301 dObject = this;
302 }
303
304 uint machPort ()
305 {
306 return invokeObjcSelf!(uint, "machPort");
307 }
308
309 void scheduleInRunLoop (NSRunLoop runLoop, NSString mode)
310 {
311 return invokeObjcSelf!(void, "scheduleInRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode);
312 }
313
314 void removeFromRunLoop (NSRunLoop runLoop, NSString mode)
315 {
316 return invokeObjcSelf!(void, "removeFromRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode);
317 }
318 }
319
320 template TNSMachPortDelegateMethods ()
321 {
322 void handleMachMessage (void* msg);
323 }
324
325 template TNSPortDelegateMethods ()
326 {
327 void handlePortMessage (NSPortMessage message);
328 }
329