root/trunk/src/gio/OutputStream.d

Revision 938, 19.8 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  = GOutputStream.html
27  * outPack = gio
28  * outFile = OutputStream
29  * strct   = GOutputStream
30  * realStrct=
31  * ctorStrct=
32  * clss    = OutputStream
33  * interf  =
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = GObject
38  * implements:
39  * prefixes:
40  *  - g_output_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  *  - gio.InputStream
51  * structWrap:
52  *  - GAsyncResult* -> AsyncResultIF
53  *  - GCancellable* -> Cancellable
54  *  - GInputStream* -> InputStream
55  * module aliases:
56  * local aliases:
57  * overrides:
58  */
59
60 module gio.OutputStream;
61
62 public  import gtkc.giotypes;
63
64 private import gtkc.gio;
65 private import glib.ConstructionException;
66
67
68 private import glib.ErrorG;
69 private import glib.GException;
70 private import gio.AsyncResultIF;
71 private import gio.Cancellable;
72 private import gio.InputStream;
73
74
75
76 private import gobject.ObjectG;
77
78 /**
79  * Description
80  * GOutputStream has functions to write to a stream (g_output_stream_write()),
81  * to close a stream (g_output_stream_close()) and to flush pending writes
82  * (g_output_stream_flush()).
83  * To copy the content of an input stream to an output stream without
84  * manually handling the reads and writes, use g_output_stream_splice().
85  * All of these functions have async variants too.
86  */
87 public class OutputStream : ObjectG
88 {
89    
90     /** the main Gtk struct */
91     protected GOutputStream* gOutputStream;
92    
93    
94     public GOutputStream* getOutputStreamStruct()
95     {
96         return gOutputStream;
97     }
98    
99    
100     /** the main Gtk struct as a void* */
101     protected override void* getStruct()
102     {
103         return cast(void*)gOutputStream;
104     }
105    
106     /**
107      * Sets our main struct and passes it to the parent class
108      */
109     public this (GOutputStream* gOutputStream)
110     {
111         if(gOutputStream is null)
112         {
113             this = null;
114             return;
115         }
116         //Check if there already is a D object for this gtk struct
117         void* ptr = getDObject(cast(GObject*)gOutputStream);
118         if( ptr !is null )
119         {
120             this = cast(OutputStream)ptr;
121             return;
122         }
123         super(cast(GObject*)gOutputStream);
124         this.gOutputStream = gOutputStream;
125     }
126    
127     protected override void setStruct(GObject* obj)
128     {
129         super.setStruct(obj);
130         gOutputStream = cast(GOutputStream*)obj;
131     }
132    
133     /**
134      */
135    
136     /**
137      * Tries to write count bytes from buffer into the stream. Will block
138      * during the operation.
139      * If count is 0, returns 0 and does nothing. A value of count
140      * larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error.
141      * On success, the number of bytes written to the stream is returned.
142      * It is not an error if this is not the same as the requested size, as it
143      * can happen e.g. on a partial I/O error, or if there is not enough
144      * storage in the stream. All writes block until at least one byte
145      * is written or an error occurs; 0 is never returned (unless
146      * count is 0).
147      * If cancellable is not NULL, then the operation can be cancelled by
148      * triggering the cancellable object from another thread. If the operation
149      * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an
150      * operation was partially finished when the operation was cancelled the
151      * partial result will be returned, without an error.
152      * On error -1 is returned and error is set accordingly.
153      * Params:
154      * buffer = the buffer containing the data to write. [array length=count][element-type guint8]
155      * count = the number of bytes to write
156      * cancellable = optional cancellable object. [allow-none]
157      * Returns: Number of bytes written, or -1 on error
158      * Throws: GException on failure.
159      */
160     public gssize write(void* buffer, gsize count, Cancellable cancellable)
161     {
162         // gssize g_output_stream_write (GOutputStream *stream,  const void *buffer,  gsize count,  GCancellable *cancellable,  GError **error);
163         GError* err = null;
164        
165         auto p = g_output_stream_write(gOutputStream, buffer, count, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
166        
167         if (err !is null)
168         {
169             throw new GException( new ErrorG(err) );
170         }
171        
172         return p;
173     }
174    
175     /**
176      * Tries to write count bytes from buffer into the stream. Will block
177      * during the operation.
178      * This function is similar to g_output_stream_write(), except it tries to
179      * write as many bytes as requested, only stopping on an error.
180      * On a successful write of count bytes, TRUE is returned, and bytes_written
181      * is set to count.
182      * If there is an error during the operation FALSE is returned and error
183      * is set to indicate the error status, bytes_written is updated to contain
184      * the number of bytes written into the stream before the error occurred.
185      * Params:
186      * buffer = the buffer containing the data to write. [array length=count][element-type guint8]
187      * count = the number of bytes to write
188      * bytesWritten = location to store the number of bytes that was
189      * written to the stream. [out]
190      * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
191      * Returns: TRUE on success, FALSE if there was an error
192      * Throws: GException on failure.
193      */
194     public int writeAll(void* buffer, gsize count, gsize* bytesWritten, Cancellable cancellable)
195     {
196         // gboolean g_output_stream_write_all (GOutputStream *stream,  const void *buffer,  gsize count,  gsize *bytes_written,  GCancellable *cancellable,  GError **error);
197         GError* err = null;
198        
199         auto p = g_output_stream_write_all(gOutputStream, buffer, count, bytesWritten, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
200        
201         if (err !is null)
202         {
203             throw new GException( new ErrorG(err) );
204         }
205        
206         return p;
207     }
208    
209     /**
210      * Splices an input stream into an output stream.
211      * Params:
212      * source = a GInputStream.
213      * flags = a set of GOutputStreamSpliceFlags.
214      * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
215      * Returns: a gssize containing the size of the data spliced, or -1 if an error occurred.
216      * Throws: GException on failure.
217      */
218     public gssize splice(InputStream source, GOutputStreamSpliceFlags flags, Cancellable cancellable)
219     {
220         // gssize g_output_stream_splice (GOutputStream *stream,  GInputStream *source,  GOutputStreamSpliceFlags flags,  GCancellable *cancellable,  GError **error);
221         GError* err = null;
222        
223         auto p = g_output_stream_splice(gOutputStream, (source is null) ? null : source.getInputStreamStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
224        
225         if (err !is null)
226         {
227             throw new GException( new ErrorG(err) );
228         }
229        
230         return p;
231     }
232    
233     /**
234      * Flushed any outstanding buffers in the stream. Will block during
235      * the operation. Closing the stream will implicitly cause a flush.
236      * This function is optional for inherited classes.
237      * If cancellable is not NULL, then the operation can be cancelled by
238      * triggering the cancellable object from another thread. If the operation
239      * was cancelled, the error G_IO_ERROR_CANCELLED will be returned.
240      * Params:
241      * cancellable = optional cancellable object. [allow-none]
242      * Returns: TRUE on success, FALSE on error
243      * Throws: GException on failure.
244      */
245     public int flush(Cancellable cancellable)
246     {
247         // gboolean g_output_stream_flush (GOutputStream *stream,  GCancellable *cancellable,  GError **error);
248         GError* err = null;
249        
250         auto p = g_output_stream_flush(gOutputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
251        
252         if (err !is null)
253         {
254             throw new GException( new ErrorG(err) );
255         }
256        
257         return p;
258     }
259    
260     /**
261      * Closes the stream, releasing resources related to it.
262      * Once the stream is closed, all other operations will return G_IO_ERROR_CLOSED.
263      * Closing a stream multiple times will not return an error.
264      * Closing a stream will automatically flush any outstanding buffers in the
265      * stream.
266      * Streams will be automatically closed when the last reference
267      * is dropped, but you might want to call this function to make sure
268      * resources are released as early as possible.
269      * Some streams might keep the backing store of the stream (e.g. a file descriptor)
270      * open after the stream is closed. See the documentation for the individual
271      * stream for details.
272      * On failure the first error that happened will be reported, but the close
273      * operation will finish as much as possible. A stream that failed to
274      * close will still return G_IO_ERROR_CLOSED for all operations. Still, it
275      * is important to check and report the error to the user, otherwise
276      * there might be a loss of data as all data might not be written.
277      * If cancellable is not NULL, then the operation can be cancelled by
278      * triggering the cancellable object from another thread. If the operation
279      * was cancelled, the error G_IO_ERROR_CANCELLED will be returned.
280      * Cancelling a close will still leave the stream closed, but there some streams
281      * can use a faster close that doesn't block to e.g. check errors. On
282      * cancellation (as with any error) there is no guarantee that all written
283      * data will reach the target.
284      * Params:
285      * cancellable = optional cancellable object. [allow-none]
286      * Returns: TRUE on success, FALSE on failure
287      * Throws: GException on failure.
288      */
289     public int close(Cancellable cancellable)
290     {
291         // gboolean g_output_stream_close (GOutputStream *stream,  GCancellable *cancellable,  GError **error);
292         GError* err = null;
293        
294         auto p = g_output_stream_close(gOutputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
295        
296         if (err !is null)
297         {
298             throw new GException( new ErrorG(err) );
299         }
300        
301         return p;
302     }
303    
304     /**
305      * Request an asynchronous write of count bytes from buffer into
306      * the stream. When the operation is finished callback will be called.
307      * You can then call g_output_stream_write_finish() to get the result of the
308      * operation.
309      * During an async request no other sync and async calls are allowed,
310      * and will result in G_IO_ERROR_PENDING errors.
311      * A value of count larger than G_MAXSSIZE will cause a
312      * G_IO_ERROR_INVALID_ARGUMENT error.
313      * On success, the number of bytes written will be passed to the
314      * callback. It is not an error if this is not the same as the
315      * requested size, as it can happen e.g. on a partial I/O error,
316      * but generally we try to write as many bytes as requested.
317      * You are guaranteed that this method will never fail with
318      * G_IO_ERROR_WOULD_BLOCK - if stream can't accept more data, the
319      * method will just wait until this changes.
320      * Any outstanding I/O request with higher priority (lower numerical
321      * value) will be executed before an outstanding request with lower
322      * priority. Default priority is G_PRIORITY_DEFAULT.
323      * The asyncronous methods have a default fallback that uses threads
324      * to implement asynchronicity, so they are optional for inheriting
325      * classes. However, if you override one you must override all.
326      * For the synchronous, blocking version of this function, see
327      * g_output_stream_write().
328      * Params:
329      * buffer = the buffer containing the data to write. [array length=count][element-type guint8]
330      * count = the number of bytes to write
331      * ioPriority = the io priority of the request.
332      * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
333      * callback = callback to call when the request is satisfied. [scope async]
334      * userData = the data to pass to callback function. [closure]
335      */
336     public void writeAsync(void* buffer, gsize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
337     {
338         // void g_output_stream_write_async (GOutputStream *stream,  const void *buffer,  gsize count,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
339         g_output_stream_write_async(gOutputStream, buffer, count, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
340     }
341    
342     /**
343      * Finishes a stream write operation.
344      * Params:
345      * result = a GAsyncResult.
346      * Returns: a gssize containing the number of bytes written to the stream.
347      * Throws: GException on failure.
348      */
349     public gssize writeFinish(AsyncResultIF result)
350     {
351         // gssize g_output_stream_write_finish (GOutputStream *stream,  GAsyncResult *result,  GError **error);
352         GError* err = null;
353        
354         auto p = g_output_stream_write_finish(gOutputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
355        
356         if (err !is null)
357         {
358             throw new GException( new ErrorG(err) );
359         }
360        
361         return p;
362     }
363    
364     /**
365      * Splices a stream asynchronously.
366      * When the operation is finished callback will be called.
367      * You can then call g_output_stream_splice_finish() to get the
368      * result of the operation.
369      * For the synchronous, blocking version of this function, see
370      * g_output_stream_splice().
371      * Params:
372      * source = a GInputStream.
373      * flags = a set of GOutputStreamSpliceFlags.
374      * ioPriority = the io priority of the request.
375      * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
376      * callback = a GAsyncReadyCallback. [scope async]
377      * userData = user data passed to callback. [closure]
378      */
379     public void spliceAsync(InputStream source, GOutputStreamSpliceFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
380     {
381         // void g_output_stream_splice_async (GOutputStream *stream,  GInputStream *source,  GOutputStreamSpliceFlags flags,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
382         g_output_stream_splice_async(gOutputStream, (source is null) ? null : source.getInputStreamStruct(), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
383     }
384    
385     /**
386      * Finishes an asynchronous stream splice operation.
387      * Params:
388      * result = a GAsyncResult.
389      * Returns: a gssize of the number of bytes spliced.
390      * Throws: GException on failure.
391      */
392     public gssize spliceFinish(AsyncResultIF result)
393     {
394         // gssize g_output_stream_splice_finish (GOutputStream *stream,  GAsyncResult *result,  GError **error);
395         GError* err = null;
396        
397         auto p = g_output_stream_splice_finish(gOutputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
398        
399         if (err !is null)
400         {
401             throw new GException( new ErrorG(err) );
402         }
403        
404         return p;
405     }
406    
407     /**
408      * Flushes a stream asynchronously.
409      * For behaviour details see g_output_stream_flush().
410      * When the operation is finished callback will be
411      * called. You can then call g_output_stream_flush_finish() to get the
412      * result of the operation.
413      * Params:
414      * ioPriority = the io priority of the request.
415      * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
416      * callback = a GAsyncReadyCallback to call when the request is satisfied. [scope async]
417      * userData = the data to pass to callback function. [closure]
418      */
419     public void flushAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
420     {
421         // void g_output_stream_flush_async (GOutputStream *stream,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
422         g_output_stream_flush_async(gOutputStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
423     }
424    
425     /**
426      * Finishes flushing an output stream.
427      * Params:
428      * result = a GAsyncResult.
429      * Returns: TRUE if flush operation suceeded, FALSE otherwise.
430      * Throws: GException on failure.
431      */
432     public int flushFinish(AsyncResultIF result)
433     {
434         // gboolean g_output_stream_flush_finish (GOutputStream *stream,  GAsyncResult *result,  GError **error);
435         GError* err = null;
436        
437         auto p = g_output_stream_flush_finish(gOutputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
438        
439         if (err !is null)
440         {
441             throw new GException( new ErrorG(err) );
442         }
443        
444         return p;
445     }
446    
447     /**
448      * Requests an asynchronous close of the stream, releasing resources
449      * related to it. When the operation is finished callback will be
450      * called. You can then call g_output_stream_close_finish() to get
451      * the result of the operation.
452      * For behaviour details see g_output_stream_close().
453      * The asyncronous methods have a default fallback that uses threads
454      * to implement asynchronicity, so they are optional for inheriting
455      * classes. However, if you override one you must override all.
456      * Params:
457      * ioPriority = the io priority of the request.
458      * cancellable = optional cancellable object. [allow-none]
459      * callback = callback to call when the request is satisfied. [scope async]
460      * userData = the data to pass to callback function. [closure]
461      */
462     public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
463     {
464         // void g_output_stream_close_async (GOutputStream *stream,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
465         g_output_stream_close_async(gOutputStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
466     }
467    
468     /**
469      * Closes an output stream.
470      * Params:
471      * result = a GAsyncResult.
472      * Returns: TRUE if stream was successfully closed, FALSE otherwise.
473      * Throws: GException on failure.
474      */
475     public int closeFinish(AsyncResultIF result)
476     {
477         // gboolean g_output_stream_close_finish (GOutputStream *stream,  GAsyncResult *result,  GError **error);
478         GError* err = null;
479        
480         auto p = g_output_stream_close_finish(gOutputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
481        
482         if (err !is null)
483         {
484             throw new GException( new ErrorG(err) );
485         }
486        
487         return p;
488     }
489    
490     /**
491      * Checks if an output stream is being closed. This can be
492      * used inside e.g. a flush implementation to see if the
493      * flush (or other i/o operation) is called from within
494      * the closing operation.
495      * Since 2.24
496      * Returns: TRUE if stream is being closed. FALSE otherwise.
497      */
498     public int isClosing()
499     {
500         // gboolean g_output_stream_is_closing (GOutputStream *stream);
501         return g_output_stream_is_closing(gOutputStream);
502     }
503    
504     /**
505      * Checks if an output stream has already been closed.
506      * Returns: TRUE if stream is closed. FALSE otherwise.
507      */
508     public int isClosed()
509     {
510         // gboolean g_output_stream_is_closed (GOutputStream *stream);
511         return g_output_stream_is_closed(gOutputStream);
512     }
513    
514     /**
515      * Checks if an ouput stream has pending actions.
516      * Returns: TRUE if stream has pending actions.
517      */
518     public int hasPending()
519     {
520         // gboolean g_output_stream_has_pending (GOutputStream *stream);
521         return g_output_stream_has_pending(gOutputStream);
522     }
523    
524     /**
525      * Sets stream to have actions pending. If the pending flag is
526      * already set or stream is closed, it will return FALSE and set
527      * error.
528      * Returns: TRUE if pending was previously unset and is now set.
529      * Throws: GException on failure.
530      */
531     public int setPending()
532     {
533         // gboolean g_output_stream_set_pending (GOutputStream *stream,  GError **error);
534         GError* err = null;
535        
536         auto p = g_output_stream_set_pending(gOutputStream, &err);
537        
538         if (err !is null)
539         {
540             throw new GException( new ErrorG(err) );
541         }
542        
543         return p;
544     }
545    
546     /**
547      * Clears the pending flag on stream.
548      */
549     public void clearPending()
550     {
551         // void g_output_stream_clear_pending (GOutputStream *stream);
552         g_output_stream_clear_pending(gOutputStream);
553     }
554 }
Note: See TracBrowser for help on using the browser.