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.NSFileHandle;
|
|
8
|
|
9 import dstep.foundation.NSArray;
|
|
10 import dstep.foundation.NSData;
|
|
11 import dstep.foundation.NSObject;
|
|
12 import dstep.foundation.NSRange;
|
|
13 import dstep.foundation.NSString;
|
|
14 import dstep.objc.bridge.Bridge;
|
|
15 import dstep.objc.objc : id;
|
|
16
|
|
17 import bindings = dstep.foundation.NSFileHandle_bindings;
|
|
18
|
|
19 const NSString NSFileHandleOperationException;
|
|
20 const NSString NSFileHandleReadCompletionNotification;
|
|
21 const NSString NSFileHandleReadToEndOfFileCompletionNotification;
|
|
22 const NSString NSFileHandleConnectionAcceptedNotification;
|
|
23 const NSString NSFileHandleDataAvailableNotification;
|
|
24 const NSString NSFileHandleNotificationDataItem;
|
|
25 const NSString NSFileHandleNotificationFileHandleItem;
|
|
26 const NSString NSFileHandleNotificationMonitorModes;
|
|
27
|
|
28 static this ()
|
|
29 {
|
|
30 NSFileHandleOperationException = new NSString(bindings.NSFileHandleOperationException);
|
|
31 NSFileHandleReadCompletionNotification = new NSString(bindings.NSFileHandleReadCompletionNotification);
|
|
32 NSFileHandleReadToEndOfFileCompletionNotification = new NSString(bindings.NSFileHandleReadToEndOfFileCompletionNotification);
|
|
33 NSFileHandleConnectionAcceptedNotification = new NSString(bindings.NSFileHandleConnectionAcceptedNotification);
|
|
34 NSFileHandleDataAvailableNotification = new NSString(bindings.NSFileHandleDataAvailableNotification);
|
|
35 NSFileHandleNotificationDataItem = new NSString(bindings.NSFileHandleNotificationDataItem);
|
|
36 NSFileHandleNotificationFileHandleItem = new NSString(bindings.NSFileHandleNotificationFileHandleItem);
|
|
37 NSFileHandleNotificationMonitorModes = new NSString(bindings.NSFileHandleNotificationMonitorModes);
|
|
38 }
|
|
39
|
|
40 class NSPipe : NSObject
|
|
41 {
|
|
42 mixin ObjcWrap;
|
|
43
|
|
44 NSFileHandle fileHandleForReading ()
|
|
45 {
|
|
46 return invokeObjcSelf!(NSFileHandle, "fileHandleForReading");
|
|
47 }
|
|
48
|
|
49 NSFileHandle fileHandleForWriting ()
|
|
50 {
|
|
51 return invokeObjcSelf!(NSFileHandle, "fileHandleForWriting");
|
|
52 }
|
|
53
|
|
54 Object init ()
|
|
55 {
|
|
56 return invokeObjcSelf!(Object, "init");
|
|
57 }
|
|
58
|
|
59 this ()
|
|
60 {
|
|
61 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
62 id result = Bridge.invokeObjcMethod!(id, "init")(objcObject);
|
|
63
|
|
64 if (result)
|
|
65 objcObject = ret;
|
|
66
|
|
67 dObject = this;
|
|
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
|
|
83 NSData availableData ()
|
|
84 {
|
|
85 return invokeObjcSelf!(NSData, "availableData");
|
|
86 }
|
|
87
|
|
88 NSData readDataToEndOfFile ()
|
|
89 {
|
|
90 return invokeObjcSelf!(NSData, "readDataToEndOfFile");
|
|
91 }
|
|
92
|
|
93 NSData readDataOfLength (NSUInteger length)
|
|
94 {
|
|
95 return invokeObjcSelf!(NSData, "readDataOfLength:", NSUInteger)(length);
|
|
96 }
|
|
97
|
|
98 void writeData (NSData data)
|
|
99 {
|
|
100 return invokeObjcSelf!(void, "writeData:", NSData)(data);
|
|
101 }
|
|
102
|
|
103 ulong offsetInFile ()
|
|
104 {
|
|
105 return invokeObjcSelf!(ulong, "offsetInFile");
|
|
106 }
|
|
107
|
|
108 ulong seekToEndOfFile ()
|
|
109 {
|
|
110 return invokeObjcSelf!(ulong, "seekToEndOfFile");
|
|
111 }
|
|
112
|
|
113 void seekToFileOffset (ulong offset)
|
|
114 {
|
|
115 return invokeObjcSelf!(void, "seekToFileOffset:", ulong)(offset);
|
|
116 }
|
|
117
|
|
118 void truncateFileAtOffset (ulong offset)
|
|
119 {
|
|
120 return invokeObjcSelf!(void, "truncateFileAtOffset:", ulong)(offset);
|
|
121 }
|
|
122
|
|
123 void synchronizeFile ()
|
|
124 {
|
|
125 return invokeObjcSelf!(void, "synchronizeFile");
|
|
126 }
|
|
127
|
|
128 void closeFile ()
|
|
129 {
|
|
130 return invokeObjcSelf!(void, "closeFile");
|
|
131 }
|
|
132 }
|
|
133
|
|
134 template TNSFileHandleAsynchronousAccess ()
|
|
135 {
|
|
136 void readInBackgroundAndNotifyForModes (NSArray modes)
|
|
137 {
|
|
138 return invokeObjcSelf!(void, "readInBackgroundAndNotifyForModes:", NSArray)(modes);
|
|
139 }
|
|
140
|
|
141 void readInBackgroundAndNotify ()
|
|
142 {
|
|
143 return invokeObjcSelf!(void, "readInBackgroundAndNotify");
|
|
144 }
|
|
145
|
|
146 void readToEndOfFileInBackgroundAndNotifyForModes (NSArray modes)
|
|
147 {
|
|
148 return invokeObjcSelf!(void, "readToEndOfFileInBackgroundAndNotifyForModes:", NSArray)(modes);
|
|
149 }
|
|
150
|
|
151 void readToEndOfFileInBackgroundAndNotify ()
|
|
152 {
|
|
153 return invokeObjcSelf!(void, "readToEndOfFileInBackgroundAndNotify");
|
|
154 }
|
|
155
|
|
156 void acceptConnectionInBackgroundAndNotifyForModes (NSArray modes)
|
|
157 {
|
|
158 return invokeObjcSelf!(void, "acceptConnectionInBackgroundAndNotifyForModes:", NSArray)(modes);
|
|
159 }
|
|
160
|
|
161 void acceptConnectionInBackgroundAndNotify ()
|
|
162 {
|
|
163 return invokeObjcSelf!(void, "acceptConnectionInBackgroundAndNotify");
|
|
164 }
|
|
165
|
|
166 void waitForDataInBackgroundAndNotifyForModes (NSArray modes)
|
|
167 {
|
|
168 return invokeObjcSelf!(void, "waitForDataInBackgroundAndNotifyForModes:", NSArray)(modes);
|
|
169 }
|
|
170
|
|
171 void waitForDataInBackgroundAndNotify ()
|
|
172 {
|
|
173 return invokeObjcSelf!(void, "waitForDataInBackgroundAndNotify");
|
|
174 }
|
|
175 }
|
|
176
|
|
177 template TNSFileHandleCreation ()
|
|
178 {
|
|
179 static Object fileHandleWithStandardInput ()
|
|
180 {
|
|
181 return invokeObjcSelfClass!(Object, "fileHandleWithStandardInput");
|
|
182 }
|
|
183
|
|
184 static Object fileHandleWithStandardOutput ()
|
|
185 {
|
|
186 return invokeObjcSelfClass!(Object, "fileHandleWithStandardOutput");
|
|
187 }
|
|
188
|
|
189 static Object fileHandleWithStandardError ()
|
|
190 {
|
|
191 return invokeObjcSelfClass!(Object, "fileHandleWithStandardError");
|
|
192 }
|
|
193
|
|
194 static Object fileHandleWithNullDevice ()
|
|
195 {
|
|
196 return invokeObjcSelfClass!(Object, "fileHandleWithNullDevice");
|
|
197 }
|
|
198
|
|
199 static Object fileHandleForReadingAtPath (NSString path)
|
|
200 {
|
|
201 return invokeObjcSelfClass!(Object, "fileHandleForReadingAtPath:", NSString)(path);
|
|
202 }
|
|
203
|
|
204 static Object fileHandleForWritingAtPath (NSString path)
|
|
205 {
|
|
206 return invokeObjcSelfClass!(Object, "fileHandleForWritingAtPath:", NSString)(path);
|
|
207 }
|
|
208
|
|
209 static Object fileHandleForUpdatingAtPath (NSString path)
|
|
210 {
|
|
211 return invokeObjcSelfClass!(Object, "fileHandleForUpdatingAtPath:", NSString)(path);
|
|
212 }
|
|
213 }
|
|
214
|
|
215 template TNSFileHandlePlatformSpecific ()
|
|
216 {
|
|
217 Object initWithFileDescriptor (int fd, bool closeopt)
|
|
218 {
|
|
219 return invokeObjcSelf!(Object, "initWithFileDescriptor:closeOnDealloc:", int, bool)(fd, closeopt);
|
|
220 }
|
|
221
|
|
222 this (int fd, bool closeopt)
|
|
223 {
|
|
224 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
225 id result = Bridge.invokeObjcMethod!(id, "initWithFileDescriptor:closeOnDealloc:", int, bool)(objcObject, fd, closeopt);
|
|
226
|
|
227 if (result)
|
|
228 objcObject = ret;
|
|
229
|
|
230 dObject = this;
|
|
231 }
|
|
232
|
|
233 Object initWithFileDescriptor (int fd)
|
|
234 {
|
|
235 return invokeObjcSelf!(Object, "initWithFileDescriptor:", int)(fd);
|
|
236 }
|
|
237
|
|
238 this (int fd)
|
|
239 {
|
|
240 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
241 id result = Bridge.invokeObjcMethod!(id, "initWithFileDescriptor:", int)(objcObject, fd);
|
|
242
|
|
243 if (result)
|
|
244 objcObject = ret;
|
|
245
|
|
246 dObject = this;
|
|
247 }
|
|
248
|
|
249 int fileDescriptor ()
|
|
250 {
|
|
251 return invokeObjcSelf!(int, "fileDescriptor");
|
|
252 }
|
|
253 }
|
|
254
|