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