comparison dstep/foundation/NSFileHandle.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
comparison
equal deleted inserted replaced
15:7ff919f595d5 16:19885b43130e
6 */ 6 */
7 module dstep.foundation.NSFileHandle; 7 module dstep.foundation.NSFileHandle;
8 8
9 import dstep.foundation.NSArray; 9 import dstep.foundation.NSArray;
10 import dstep.foundation.NSData; 10 import dstep.foundation.NSData;
11 import dstep.foundation.NSObjCRuntime;
11 import dstep.foundation.NSObject; 12 import dstep.foundation.NSObject;
12 import dstep.foundation.NSRange; 13 import dstep.foundation.NSRange;
13 import dstep.foundation.NSString; 14 import dstep.foundation.NSString;
14 import dstep.objc.bridge.Bridge; 15 import dstep.objc.bridge.Bridge;
15 import dstep.objc.objc : id; 16 import dstep.objc.objc;
16 17
17 import bindings = dstep.foundation.NSFileHandle_bindings; 18 import bindings = dstep.foundation.NSFileHandle_bindings;
18 19
19 const NSString NSFileHandleOperationException; 20 private
20 const NSString NSFileHandleReadCompletionNotification; 21 {
21 const NSString NSFileHandleReadToEndOfFileCompletionNotification; 22 NSString NSFileHandleOperationException_;
22 const NSString NSFileHandleConnectionAcceptedNotification; 23 NSString NSFileHandleReadCompletionNotification_;
23 const NSString NSFileHandleDataAvailableNotification; 24 NSString NSFileHandleReadToEndOfFileCompletionNotification_;
24 const NSString NSFileHandleNotificationDataItem; 25 NSString NSFileHandleConnectionAcceptedNotification_;
25 const NSString NSFileHandleNotificationFileHandleItem; 26 NSString NSFileHandleDataAvailableNotification_;
26 const NSString NSFileHandleNotificationMonitorModes; 27 NSString NSFileHandleNotificationDataItem_;
27 28 NSString NSFileHandleNotificationFileHandleItem_;
28 static this () 29 NSString NSFileHandleNotificationMonitorModes_;
29 { 30 }
30 NSFileHandleOperationException = new NSString(bindings.NSFileHandleOperationException); 31
31 NSFileHandleReadCompletionNotification = new NSString(bindings.NSFileHandleReadCompletionNotification); 32 NSString NSFileHandleOperationException ()
32 NSFileHandleReadToEndOfFileCompletionNotification = new NSString(bindings.NSFileHandleReadToEndOfFileCompletionNotification); 33 {
33 NSFileHandleConnectionAcceptedNotification = new NSString(bindings.NSFileHandleConnectionAcceptedNotification); 34 if (NSFileHandleOperationException_)
34 NSFileHandleDataAvailableNotification = new NSString(bindings.NSFileHandleDataAvailableNotification); 35 return NSFileHandleOperationException_;
35 NSFileHandleNotificationDataItem = new NSString(bindings.NSFileHandleNotificationDataItem); 36
36 NSFileHandleNotificationFileHandleItem = new NSString(bindings.NSFileHandleNotificationFileHandleItem); 37 return NSFileHandleOperationException_ = new NSString(bindings.NSFileHandleOperationException);
37 NSFileHandleNotificationMonitorModes = new NSString(bindings.NSFileHandleNotificationMonitorModes); 38 }
38 } 39
40 NSString NSFileHandleReadCompletionNotification ()
41 {
42 if (NSFileHandleReadCompletionNotification_)
43 return NSFileHandleReadCompletionNotification_;
44
45 return NSFileHandleReadCompletionNotification_ = new NSString(bindings.NSFileHandleReadCompletionNotification);
46 }
47
48 NSString NSFileHandleReadToEndOfFileCompletionNotification ()
49 {
50 if (NSFileHandleReadToEndOfFileCompletionNotification_)
51 return NSFileHandleReadToEndOfFileCompletionNotification_;
52
53 return NSFileHandleReadToEndOfFileCompletionNotification_ = new NSString(bindings.NSFileHandleReadToEndOfFileCompletionNotification);
54 }
55
56 NSString NSFileHandleConnectionAcceptedNotification ()
57 {
58 if (NSFileHandleConnectionAcceptedNotification_)
59 return NSFileHandleConnectionAcceptedNotification_;
60
61 return NSFileHandleConnectionAcceptedNotification_ = new NSString(bindings.NSFileHandleConnectionAcceptedNotification);
62 }
63
64 NSString NSFileHandleDataAvailableNotification ()
65 {
66 if (NSFileHandleDataAvailableNotification_)
67 return NSFileHandleDataAvailableNotification_;
68
69 return NSFileHandleDataAvailableNotification_ = new NSString(bindings.NSFileHandleDataAvailableNotification);
70 }
71
72 NSString NSFileHandleNotificationDataItem ()
73 {
74 if (NSFileHandleNotificationDataItem_)
75 return NSFileHandleNotificationDataItem_;
76
77 return NSFileHandleNotificationDataItem_ = new NSString(bindings.NSFileHandleNotificationDataItem);
78 }
79
80 NSString NSFileHandleNotificationFileHandleItem ()
81 {
82 if (NSFileHandleNotificationFileHandleItem_)
83 return NSFileHandleNotificationFileHandleItem_;
84
85 return NSFileHandleNotificationFileHandleItem_ = new NSString(bindings.NSFileHandleNotificationFileHandleItem);
86 }
87
88 NSString NSFileHandleNotificationMonitorModes ()
89 {
90 if (NSFileHandleNotificationMonitorModes_)
91 return NSFileHandleNotificationMonitorModes_;
92
93 return NSFileHandleNotificationMonitorModes_ = new NSString(bindings.NSFileHandleNotificationMonitorModes);
94 }
95
96 const TNSFileHandleAsynchronousAccess = `
97
98 void readInBackgroundAndNotifyForModes (NSArray modes)
99 {
100 return invokeObjcSelf!(void, "readInBackgroundAndNotifyForModes:", NSArray)(modes);
101 }
102
103 void readInBackgroundAndNotify ()
104 {
105 return invokeObjcSelf!(void, "readInBackgroundAndNotify");
106 }
107
108 void readToEndOfFileInBackgroundAndNotifyForModes (NSArray modes)
109 {
110 return invokeObjcSelf!(void, "readToEndOfFileInBackgroundAndNotifyForModes:", NSArray)(modes);
111 }
112
113 void readToEndOfFileInBackgroundAndNotify ()
114 {
115 return invokeObjcSelf!(void, "readToEndOfFileInBackgroundAndNotify");
116 }
117
118 void acceptConnectionInBackgroundAndNotifyForModes (NSArray modes)
119 {
120 return invokeObjcSelf!(void, "acceptConnectionInBackgroundAndNotifyForModes:", NSArray)(modes);
121 }
122
123 void acceptConnectionInBackgroundAndNotify ()
124 {
125 return invokeObjcSelf!(void, "acceptConnectionInBackgroundAndNotify");
126 }
127
128 void waitForDataInBackgroundAndNotifyForModes (NSArray modes)
129 {
130 return invokeObjcSelf!(void, "waitForDataInBackgroundAndNotifyForModes:", NSArray)(modes);
131 }
132
133 void waitForDataInBackgroundAndNotify ()
134 {
135 return invokeObjcSelf!(void, "waitForDataInBackgroundAndNotify");
136 }
137 `;
138
139 const TNSFileHandleCreation = `
140
141 static Object fileHandleWithStandardInput ()
142 {
143 return invokeObjcSuperClass!(Object, "fileHandleWithStandardInput");
144 }
145
146 static Object fileHandleWithStandardOutput ()
147 {
148 return invokeObjcSuperClass!(Object, "fileHandleWithStandardOutput");
149 }
150
151 static Object fileHandleWithStandardError ()
152 {
153 return invokeObjcSuperClass!(Object, "fileHandleWithStandardError");
154 }
155
156 static Object fileHandleWithNullDevice ()
157 {
158 return invokeObjcSuperClass!(Object, "fileHandleWithNullDevice");
159 }
160
161 static Object fileHandleForReadingAtPath (NSString path)
162 {
163 return invokeObjcSuperClass!(Object, "fileHandleForReadingAtPath:", NSString)(path);
164 }
165
166 static Object fileHandleForWritingAtPath (NSString path)
167 {
168 return invokeObjcSuperClass!(Object, "fileHandleForWritingAtPath:", NSString)(path);
169 }
170
171 static Object fileHandleForUpdatingAtPath (NSString path)
172 {
173 return invokeObjcSuperClass!(Object, "fileHandleForUpdatingAtPath:", NSString)(path);
174 }
175 `;
176
177 const TNSFileHandlePlatformSpecific = `
178
179 Object initWithFileDescriptor (int fd, bool closeopt)
180 {
181 return invokeObjcSelf!(Object, "initWithFileDescriptor:closeOnDealloc:", int, bool)(fd, closeopt);
182 }
183
184 this (int fd, bool closeopt)
185 {
186 typeof(this).alloc.initWithFileDescriptor(fd, closeopt);
187 }
188
189 Object initWithFileDescriptor (int fd)
190 {
191 return invokeObjcSelf!(Object, "initWithFileDescriptor:", int)(fd);
192 }
193
194 this (int fd)
195 {
196 typeof(this).alloc.initWithFileDescriptor(fd);
197 }
198
199 int fileDescriptor ()
200 {
201 return invokeObjcSelf!(int, "fileDescriptor");
202 }
203 `;
39 204
40 class NSPipe : NSObject 205 class NSPipe : NSObject
41 { 206 {
42 mixin ObjcWrap; 207 mixin (ObjcWrap);
208
209 this ()
210 {
211 super(typeof(this).alloc.init.objcObject);
212 }
213
214 typeof(this) init ()
215 {
216 return invokeObjcSelf!(typeof(this), "init");
217 }
43 218
44 NSFileHandle fileHandleForReading () 219 NSFileHandle fileHandleForReading ()
45 { 220 {
46 return invokeObjcSelf!(NSFileHandle, "fileHandleForReading"); 221 return invokeObjcSelf!(NSFileHandle, "fileHandleForReading");
47 } 222 }
49 NSFileHandle fileHandleForWriting () 224 NSFileHandle fileHandleForWriting ()
50 { 225 {
51 return invokeObjcSelf!(NSFileHandle, "fileHandleForWriting"); 226 return invokeObjcSelf!(NSFileHandle, "fileHandleForWriting");
52 } 227 }
53 228
54 Object init () 229 static Object pipe ()
55 { 230 {
56 return invokeObjcSelf!(Object, "init"); 231 return invokeObjcSuperClass!(Object, "pipe");
57 } 232 }
58 233 }
234
235 class NSFileHandle : NSObject
236 {
237 mixin (ObjcWrap);
238
59 this () 239 this ()
60 { 240 {
61 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 241 super(typeof(this).alloc.init.objcObject);
62 id result = Bridge.invokeObjcMethod!(id, "init")(objcObject); 242 }
63 243
64 if (result) 244 typeof(this) init ()
65 objcObject = ret; 245 {
66 246 return invokeObjcSelf!(typeof(this), "init");
67 dObject = this; 247 }
68 }
69
70 static Object pipe ()
71 {
72 return invokeObjcSelfClass!(Object, "pipe");
73 }
74 }
75
76 class NSFileHandle : NSObject
77 {
78 mixin ObjcWrap;
79 mixin TNSFileHandleAsynchronousAccess;
80 mixin TNSFileHandleCreation;
81 mixin TNSFileHandlePlatformSpecific;
82 248
83 NSData availableData () 249 NSData availableData ()
84 { 250 {
85 return invokeObjcSelf!(NSData, "availableData"); 251 return invokeObjcSelf!(NSData, "availableData");
86 } 252 }
127 293
128 void closeFile () 294 void closeFile ()
129 { 295 {
130 return invokeObjcSelf!(void, "closeFile"); 296 return invokeObjcSelf!(void, "closeFile");
131 } 297 }
132 } 298
133 299 // TNSFileHandleAsynchronousAccess
134 template TNSFileHandleAsynchronousAccess ()
135 {
136 void readInBackgroundAndNotifyForModes (NSArray modes) 300 void readInBackgroundAndNotifyForModes (NSArray modes)
137 { 301 {
138 return invokeObjcSelf!(void, "readInBackgroundAndNotifyForModes:", NSArray)(modes); 302 return invokeObjcSelf!(void, "readInBackgroundAndNotifyForModes:", NSArray)(modes);
139 } 303 }
140 304
141 void readInBackgroundAndNotify () 305 void readInBackgroundAndNotify ()
142 { 306 {
143 return invokeObjcSelf!(void, "readInBackgroundAndNotify"); 307 return invokeObjcSelf!(void, "readInBackgroundAndNotify");
144 } 308 }
145 309
146 void readToEndOfFileInBackgroundAndNotifyForModes (NSArray modes) 310 void readToEndOfFileInBackgroundAndNotifyForModes (NSArray modes)
147 { 311 {
148 return invokeObjcSelf!(void, "readToEndOfFileInBackgroundAndNotifyForModes:", NSArray)(modes); 312 return invokeObjcSelf!(void, "readToEndOfFileInBackgroundAndNotifyForModes:", NSArray)(modes);
149 } 313 }
150 314
151 void readToEndOfFileInBackgroundAndNotify () 315 void readToEndOfFileInBackgroundAndNotify ()
152 { 316 {
153 return invokeObjcSelf!(void, "readToEndOfFileInBackgroundAndNotify"); 317 return invokeObjcSelf!(void, "readToEndOfFileInBackgroundAndNotify");
154 } 318 }
155 319
156 void acceptConnectionInBackgroundAndNotifyForModes (NSArray modes) 320 void acceptConnectionInBackgroundAndNotifyForModes (NSArray modes)
157 { 321 {
158 return invokeObjcSelf!(void, "acceptConnectionInBackgroundAndNotifyForModes:", NSArray)(modes); 322 return invokeObjcSelf!(void, "acceptConnectionInBackgroundAndNotifyForModes:", NSArray)(modes);
159 } 323 }
160 324
161 void acceptConnectionInBackgroundAndNotify () 325 void acceptConnectionInBackgroundAndNotify ()
162 { 326 {
163 return invokeObjcSelf!(void, "acceptConnectionInBackgroundAndNotify"); 327 return invokeObjcSelf!(void, "acceptConnectionInBackgroundAndNotify");
164 } 328 }
165 329
166 void waitForDataInBackgroundAndNotifyForModes (NSArray modes) 330 void waitForDataInBackgroundAndNotifyForModes (NSArray modes)
167 { 331 {
168 return invokeObjcSelf!(void, "waitForDataInBackgroundAndNotifyForModes:", NSArray)(modes); 332 return invokeObjcSelf!(void, "waitForDataInBackgroundAndNotifyForModes:", NSArray)(modes);
169 } 333 }
170 334
171 void waitForDataInBackgroundAndNotify () 335 void waitForDataInBackgroundAndNotify ()
172 { 336 {
173 return invokeObjcSelf!(void, "waitForDataInBackgroundAndNotify"); 337 return invokeObjcSelf!(void, "waitForDataInBackgroundAndNotify");
174 } 338 }
175 } 339
176 340 // TNSFileHandleCreation
177 template TNSFileHandleCreation ()
178 {
179 static Object fileHandleWithStandardInput () 341 static Object fileHandleWithStandardInput ()
180 { 342 {
181 return invokeObjcSelfClass!(Object, "fileHandleWithStandardInput"); 343 return invokeObjcSuperClass!(Object, "fileHandleWithStandardInput");
182 } 344 }
183 345
184 static Object fileHandleWithStandardOutput () 346 static Object fileHandleWithStandardOutput ()
185 { 347 {
186 return invokeObjcSelfClass!(Object, "fileHandleWithStandardOutput"); 348 return invokeObjcSuperClass!(Object, "fileHandleWithStandardOutput");
187 } 349 }
188 350
189 static Object fileHandleWithStandardError () 351 static Object fileHandleWithStandardError ()
190 { 352 {
191 return invokeObjcSelfClass!(Object, "fileHandleWithStandardError"); 353 return invokeObjcSuperClass!(Object, "fileHandleWithStandardError");
192 } 354 }
193 355
194 static Object fileHandleWithNullDevice () 356 static Object fileHandleWithNullDevice ()
195 { 357 {
196 return invokeObjcSelfClass!(Object, "fileHandleWithNullDevice"); 358 return invokeObjcSuperClass!(Object, "fileHandleWithNullDevice");
197 } 359 }
198 360
199 static Object fileHandleForReadingAtPath (NSString path) 361 static Object fileHandleForReadingAtPath (NSString path)
200 { 362 {
201 return invokeObjcSelfClass!(Object, "fileHandleForReadingAtPath:", NSString)(path); 363 return invokeObjcSuperClass!(Object, "fileHandleForReadingAtPath:", NSString)(path);
202 } 364 }
203 365
204 static Object fileHandleForWritingAtPath (NSString path) 366 static Object fileHandleForWritingAtPath (NSString path)
205 { 367 {
206 return invokeObjcSelfClass!(Object, "fileHandleForWritingAtPath:", NSString)(path); 368 return invokeObjcSuperClass!(Object, "fileHandleForWritingAtPath:", NSString)(path);
207 } 369 }
208 370
209 static Object fileHandleForUpdatingAtPath (NSString path) 371 static Object fileHandleForUpdatingAtPath (NSString path)
210 { 372 {
211 return invokeObjcSelfClass!(Object, "fileHandleForUpdatingAtPath:", NSString)(path); 373 return invokeObjcSuperClass!(Object, "fileHandleForUpdatingAtPath:", NSString)(path);
212 } 374 }
213 } 375
214 376 // TNSFileHandlePlatformSpecific
215 template TNSFileHandlePlatformSpecific ()
216 {
217 Object initWithFileDescriptor (int fd, bool closeopt) 377 Object initWithFileDescriptor (int fd, bool closeopt)
218 { 378 {
219 return invokeObjcSelf!(Object, "initWithFileDescriptor:closeOnDealloc:", int, bool)(fd, closeopt); 379 return invokeObjcSelf!(Object, "initWithFileDescriptor:closeOnDealloc:", int, bool)(fd, closeopt);
220 } 380 }
221 381
222 this (int fd, bool closeopt) 382 this (int fd, bool closeopt)
223 { 383 {
224 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 384 typeof(this).alloc.initWithFileDescriptor(fd, closeopt);
225 id result = Bridge.invokeObjcMethod!(id, "initWithFileDescriptor:closeOnDealloc:", int, bool)(objcObject, fd, closeopt); 385 }
226 386
227 if (result)
228 objcObject = ret;
229
230 dObject = this;
231 }
232
233 Object initWithFileDescriptor (int fd) 387 Object initWithFileDescriptor (int fd)
234 { 388 {
235 return invokeObjcSelf!(Object, "initWithFileDescriptor:", int)(fd); 389 return invokeObjcSelf!(Object, "initWithFileDescriptor:", int)(fd);
236 } 390 }
237 391
238 this (int fd) 392 this (int fd)
239 { 393 {
240 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 394 typeof(this).alloc.initWithFileDescriptor(fd);
241 id result = Bridge.invokeObjcMethod!(id, "initWithFileDescriptor:", int)(objcObject, fd); 395 }
242 396
243 if (result)
244 objcObject = ret;
245
246 dObject = this;
247 }
248
249 int fileDescriptor () 397 int fileDescriptor ()
250 { 398 {
251 return invokeObjcSelf!(int, "fileDescriptor"); 399 return invokeObjcSelf!(int, "fileDescriptor");
252 } 400 }
253 } 401 }
254