root/trunk/src/gio/InputStream.d

Revision 938, 17.6 kB (checked in by Mike Wey, 3 months ago)

Update Gio to 2.28.

Line 
1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23
24 /*
25  * Conversion parameters:
26  * inFile  = GInputStream.html
27  * outPack = gio
28  * outFile = InputStream
29  * strct   = GInputStream
30  * realStrct=
31  * ctorStrct=
32  * clss    = InputStream
33  * interf  =
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  =
38  * implements:
39  * prefixes:
40  *  - g_input_stream_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  *  - glib.ErrorG
47  *  - glib.GException
48  *  - gio.AsyncResultIF
49  *  - gio.Cancellable
50  * structWrap:
51  *  - GAsyncResult* -> AsyncResultIF
52  *  - GCancellable* -> Cancellable
53  * module aliases:
54  * local aliases:
55  * overrides:
56  */
57
58 module gio.InputStream;
59
60 public  import gtkc.giotypes;
61
62 private import gtkc.gio;
63 private import glib.ConstructionException;
64
65
66 private import glib.ErrorG;
67 private import glib.GException;
68 private import gio.AsyncResultIF;
69 private import gio.Cancellable;
70
71
72
73 private import gobject.ObjectG;
74
75 /**
76  * Description
77  * GInputStream has functions to read from a stream (g_input_stream_read()),
78  * to close a stream (g_input_stream_close()) and to skip some content
79  * (g_input_stream_skip()).
80  * To copy the content of an input stream to an output stream without
81  * manually handling the reads and writes, use g_output_stream_splice().
82  * All of these functions have async variants too.
83  */
84 public class InputStream : ObjectG
85 {
86    
87     /** the main Gtk struct */
88     protected GInputStream* gInputStream;
89    
90    
91     public GInputStream* getInputStreamStruct()
92     {
93         return gInputStream;
94     }
95    
96    
97     /** the main Gtk struct as a void* */
98     protected override void* getStruct()
99     {
100         return cast(void*)gInputStream;
101     }
102    
103     /**
104      * Sets our main struct and passes it to the parent class
105      */
106     public this (GInputStream* gInputStream)
107     {
108         if(gInputStream is null)
109         {
110             this = null;
111             return;
112         }
113         //Check if there already is a D object for this gtk struct
114         void* ptr = getDObject(cast(GObject*)gInputStream);
115         if( ptr !is null )
116         {
117             this = cast(InputStream)ptr;
118             return;
119         }
120         super(cast(GObject*)gInputStream);
121         this.gInputStream = gInputStream;
122     }
123    
124     protected override void setStruct(GObject* obj)
125     {
126         super.setStruct(obj);
127         gInputStream = cast(GInputStream*)obj;
128     }
129    
130     /**
131      */
132    
133     /**
134      * Tries to read count bytes from the stream into the buffer starting at
135      * buffer. Will block during this read.
136      * If count is zero returns zero and does nothing. A value of count
137      * larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error.
138      * On success, the number of bytes read into the buffer is returned.
139      * It is not an error if this is not the same as the requested size, as it
140      * can happen e.g. near the end of a file. Zero is returned on end of file
141      * (or if count is zero), but never otherwise.
142      * If cancellable is not NULL, then the operation can be cancelled by
143      * triggering the cancellable object from another thread. If the operation
144      * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an
145      * operation was partially finished when the operation was cancelled the
146      * partial result will be returned, without an error.
147      * On error -1 is returned and error is set accordingly.
148      * Params:
149      * buffer = a buffer to read data into (which should be at least count bytes long).
150      * count = the number of bytes that will be read from the stream
151      * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
152      * Returns: Number of bytes read, or -1 on error
153      * Throws: GException on failure.
154      */
155     public gssize read(void* buffer, gsize count, Cancellable cancellable)
156     {
157         // gssize g_input_stream_read (GInputStream *stream,  void *buffer,  gsize count,  GCancellable *cancellable,  GError **error);
158         GError* err = null;
159        
160         auto p = g_input_stream_read(gInputStream, buffer, count, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
161        
162         if (err !is null)
163         {
164             throw new GException( new ErrorG(err) );
165         }
166        
167         return p;
168     }
169    
170     /**
171      * Tries to read count bytes from the stream into the buffer starting at
172      * buffer. Will block during this read.
173      * This function is similar to g_input_stream_read(), except it tries to
174      * read as many bytes as requested, only stopping on an error or end of stream.
175      * On a successful read of count bytes, or if we reached the end of the
176      * stream, TRUE is returned, and bytes_read is set to the number of bytes
177      * read into buffer.
178      * If there is an error during the operation FALSE is returned and error
179      * is set to indicate the error status, bytes_read is updated to contain
180      * the number of bytes read into buffer before the error occurred.
181      * Params:
182      * buffer = a buffer to read data into (which should be at least count bytes long).
183      * count = the number of bytes that will be read from the stream
184      * bytesRead = location to store the number of bytes that was read from the stream. [out]
185      * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
186      * Returns: TRUE on success, FALSE if there was an error
187      * Throws: GException on failure.
188      */
189     public int readAll(void* buffer, gsize count, out gsize bytesRead, Cancellable cancellable)
190     {
191         // gboolean g_input_stream_read_all (GInputStream *stream,  void *buffer,  gsize count,  gsize *bytes_read,  GCancellable *cancellable,  GError **error);
192         GError* err = null;
193        
194         auto p = g_input_stream_read_all(gInputStream, buffer, count, &bytesRead, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
195        
196         if (err !is null)
197         {
198             throw new GException( new ErrorG(err) );
199         }
200        
201         return p;
202     }
203    
204     /**
205      * Tries to skip count bytes from the stream. Will block during the operation.
206      * This is identical to g_input_stream_read(), from a behaviour standpoint,
207      * but the bytes that are skipped are not returned to the user. Some
208      * streams have an implementation that is more efficient than reading the data.
209      * This function is optional for inherited classes, as the default implementation
210      * emulates it using read.
211      * If cancellable is not NULL, then the operation can be cancelled by
212      * triggering the cancellable object from another thread. If the operation
213      * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an
214      * operation was partially finished when the operation was cancelled the
215      * partial result will be returned, without an error.
216      * Params:
217      * count = the number of bytes that will be skipped from the stream
218      * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
219      * Returns: Number of bytes skipped, or -1 on error
220      * Throws: GException on failure.
221      */
222     public gssize skip(gsize count, Cancellable cancellable)
223     {
224         // gssize g_input_stream_skip (GInputStream *stream,  gsize count,  GCancellable *cancellable,  GError **error);
225         GError* err = null;
226        
227         auto p = g_input_stream_skip(gInputStream, count, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
228        
229         if (err !is null)
230         {
231             throw new GException( new ErrorG(err) );
232         }
233        
234         return p;
235     }
236    
237     /**
238      * Closes the stream, releasing resources related to it.
239      * Once the stream is closed, all other operations will return G_IO_ERROR_CLOSED.
240      * Closing a stream multiple times will not return an error.
241      * Streams will be automatically closed when the last reference
242      * is dropped, but you might want to call this function to make sure
243      * resources are released as early as possible.
244      * Some streams might keep the backing store of the stream (e.g. a file descriptor)
245      * open after the stream is closed. See the documentation for the individual
246      * stream for details.
247      * On failure the first error that happened will be reported, but the close
248      * operation will finish as much as possible. A stream that failed to
249      * close will still return G_IO_ERROR_CLOSED for all operations. Still, it
250      * is important to check and report the error to the user.
251      * If cancellable is not NULL, then the operation can be cancelled by
252      * triggering the cancellable object from another thread. If the operation
253      * was cancelled, the error G_IO_ERROR_CANCELLED will be returned.
254      * Cancelling a close will still leave the stream closed, but some streams
255      * can use a faster close that doesn't block to e.g. check errors.
256      * Params:
257      * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
258      * Returns: TRUE on success, FALSE on failure
259      * Throws: GException on failure.
260      */
261     public int close(Cancellable cancellable)
262     {
263         // gboolean g_input_stream_close (GInputStream *stream,  GCancellable *cancellable,  GError **error);
264         GError* err = null;
265        
266         auto p = g_input_stream_close(gInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
267        
268         if (err !is null)
269         {
270             throw new GException( new ErrorG(err) );
271         }
272        
273         return p;
274     }
275    
276     /**
277      * Request an asynchronous read of count bytes from the stream into the buffer
278      * starting at buffer. When the operation is finished callback will be called.
279      * You can then call g_input_stream_read_finish() to get the result of the
280      * operation.
281      * During an async request no other sync and async calls are allowed on stream, and will
282      * result in G_IO_ERROR_PENDING errors.
283      * A value of count larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error.
284      * On success, the number of bytes read into the buffer will be passed to the
285      * callback. It is not an error if this is not the same as the requested size, as it
286      * can happen e.g. near the end of a file, but generally we try to read
287      * as many bytes as requested. Zero is returned on end of file
288      * (or if count is zero), but never otherwise.
289      * Any outstanding i/o request with higher priority (lower numerical value) will
290      * be executed before an outstanding request with lower priority. Default
291      * priority is G_PRIORITY_DEFAULT.
292      * The asyncronous methods have a default fallback that uses threads to implement
293      * asynchronicity, so they are optional for inheriting classes. However, if you
294      * override one you must override all.
295      * Params:
296      * buffer = a buffer to read data into (which should be at least count bytes long).
297      * count = the number of bytes that will be read from the stream
298      * ioPriority = the I/O priority
299      * of the request.
300      * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
301      * callback = callback to call when the request is satisfied. [scope async]
302      * userData = the data to pass to callback function. [closure]
303      */
304     public void readAsync(void* buffer, gsize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
305     {
306         // void g_input_stream_read_async (GInputStream *stream,  void *buffer,  gsize count,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
307         g_input_stream_read_async(gInputStream, buffer, count, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
308     }
309    
310     /**
311      * Finishes an asynchronous stream read operation.
312      * Params:
313      * result = a GAsyncResult.
314      * Returns: number of bytes read in, or -1 on error.
315      * Throws: GException on failure.
316      */
317     public gssize readFinish(AsyncResultIF result)
318     {
319         // gssize g_input_stream_read_finish (GInputStream *stream,  GAsyncResult *result,  GError **error);
320         GError* err = null;
321        
322         auto p = g_input_stream_read_finish(gInputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
323        
324         if (err !is null)
325         {
326             throw new GException( new ErrorG(err) );
327         }
328        
329         return p;
330     }
331    
332     /**
333      * Request an asynchronous skip of count bytes from the stream.
334      * When the operation is finished callback will be called.
335      * You can then call g_input_stream_skip_finish() to get the result
336      * of the operation.
337      * During an async request no other sync and async calls are allowed,
338      * and will result in G_IO_ERROR_PENDING errors.
339      * A value of count larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error.
340      * On success, the number of bytes skipped will be passed to the callback.
341      * It is not an error if this is not the same as the requested size, as it
342      * can happen e.g. near the end of a file, but generally we try to skip
343      * as many bytes as requested. Zero is returned on end of file
344      * (or if count is zero), but never otherwise.
345      * Any outstanding i/o request with higher priority (lower numerical value)
346      * will be executed before an outstanding request with lower priority.
347      * Default priority is G_PRIORITY_DEFAULT.
348      * The asynchronous methods have a default fallback that uses threads to
349      * implement asynchronicity, so they are optional for inheriting classes.
350      * However, if you override one, you must override all.
351      * Params:
352      * count = the number of bytes that will be skipped from the stream
353      * ioPriority = the I/O priority
354      * of the request.
355      * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
356      * callback = callback to call when the request is satisfied. [scope async]
357      * userData = the data to pass to callback function. [closure]
358      */
359     public void skipAsync(gsize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
360     {
361         // void g_input_stream_skip_async (GInputStream *stream,  gsize count,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
362         g_input_stream_skip_async(gInputStream, count, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
363     }
364    
365     /**
366      * Finishes a stream skip operation.
367      * Params:
368      * result = a GAsyncResult.
369      * Returns: the size of the bytes skipped, or -1 on error.
370      * Throws: GException on failure.
371      */
372     public gssize skipFinish(AsyncResultIF result)
373     {
374         // gssize g_input_stream_skip_finish (GInputStream *stream,  GAsyncResult *result,  GError **error);
375         GError* err = null;
376        
377         auto p = g_input_stream_skip_finish(gInputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
378        
379         if (err !is null)
380         {
381             throw new GException( new ErrorG(err) );
382         }
383        
384         return p;
385     }
386    
387     /**
388      * Requests an asynchronous closes of the stream, releasing resources related to it.
389      * When the operation is finished callback will be called.
390      * You can then call g_input_stream_close_finish() to get the result of the
391      * operation.
392      * For behaviour details see g_input_stream_close().
393      * The asyncronous methods have a default fallback that uses threads to implement
394      * asynchronicity, so they are optional for inheriting classes. However, if you
395      * override one you must override all.
396      * Params:
397      * ioPriority = the I/O priority
398      * of the request.
399      * cancellable = optional cancellable object. [allow-none]
400      * callback = callback to call when the request is satisfied. [scope async]
401      * userData = the data to pass to callback function. [closure]
402      */
403     public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
404     {
405         // void g_input_stream_close_async (GInputStream *stream,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
406         g_input_stream_close_async(gInputStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
407     }
408    
409     /**
410      * Finishes closing a stream asynchronously, started from g_input_stream_close_async().
411      * Params:
412      * result = a GAsyncResult.
413      * Returns: TRUE if the stream was closed successfully.
414      * Throws: GException on failure.
415      */
416     public int closeFinish(AsyncResultIF result)
417     {
418         // gboolean g_input_stream_close_finish (GInputStream *stream,  GAsyncResult *result,  GError **error);
419         GError* err = null;
420        
421         auto p = g_input_stream_close_finish(gInputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
422        
423         if (err !is null)
424         {
425             throw new GException( new ErrorG(err) );
426         }
427        
428         return p;
429     }
430    
431     /**
432      * Checks if an input stream is closed.
433      * Returns: TRUE if the stream is closed.
434      */
435     public int isClosed()
436     {
437         // gboolean g_input_stream_is_closed (GInputStream *stream);
438         return g_input_stream_is_closed(gInputStream);
439     }
440    
441     /**
442      * Checks if an input stream has pending actions.
443      * Returns: TRUE if stream has pending actions.
444      */
445     public int hasPending()
446     {
447         // gboolean g_input_stream_has_pending (GInputStream *stream);
448         return g_input_stream_has_pending(gInputStream);
449     }
450    
451     /**
452      * Sets stream to have actions pending. If the pending flag is
453      * already set or stream is closed, it will return FALSE and set
454      * error.
455      * Returns: TRUE if pending was previously unset and is now set.
456      * Throws: GException on failure.
457      */
458     public int setPending()
459     {
460         // gboolean g_input_stream_set_pending (GInputStream *stream,  GError **error);
461         GError* err = null;
462        
463         auto p = g_input_stream_set_pending(gInputStream, &err);
464        
465         if (err !is null)
466         {
467             throw new GException( new ErrorG(err) );
468         }
469        
470         return p;
471     }
472    
473     /**
474      * Clears the pending flag on stream.
475      */
476     public void clearPending()
477     {
478         // void g_input_stream_clear_pending (GInputStream *stream);
479         g_input_stream_clear_pending(gInputStream);
480     }
481 }
Note: See TracBrowser for help on using the browser.