root/trunk/src/gio/IOStream.d

Revision 938, 11.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  = GIOStream.html
27  * outPack = gio
28  * outFile = IOStream
29  * strct   = GIOStream
30  * realStrct=
31  * ctorStrct=
32  * clss    = IOStream
33  * interf  =
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  =
38  * implements:
39  * prefixes:
40  *  - g_io_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  *  - gio.OutputStream
52  * structWrap:
53  *  - GAsyncResult* -> AsyncResultIF
54  *  - GCancellable* -> Cancellable
55  *  - GIOStream* -> IOStream
56  *  - GInputStream* -> InputStream
57  *  - GOutputStream* -> OutputStream
58  * module aliases:
59  * local aliases:
60  * overrides:
61  */
62
63 module gio.IOStream;
64
65 public  import gtkc.giotypes;
66
67 private import gtkc.gio;
68 private import glib.ConstructionException;
69
70
71 private import glib.ErrorG;
72 private import glib.GException;
73 private import gio.AsyncResultIF;
74 private import gio.Cancellable;
75 private import gio.InputStream;
76 private import gio.OutputStream;
77
78
79
80 private import gobject.ObjectG;
81
82 /**
83  * Description
84  * GIOStream represents an object that has both read and write streams.
85  * Generally the two streams acts as separate input and output streams,
86  * but they share some common resources and state. For instance, for
87  * seekable streams they may use the same position in both streams.
88  * Examples of GIOStream objects are GSocketConnection which represents
89  * a two-way network connection, and GFileIOStream which represent a
90  * file handle opened in read-write mode.
91  * To do the actual reading and writing you need to get the substreams
92  * with g_io_stream_get_input_stream() and g_io_stream_get_output_stream().
93  * The GIOStream object owns the input and the output streams, not the other
94  * way around, so keeping the substreams alive will not keep the GIOStream
95  * object alive. If the GIOStream object is freed it will be closed, thus
96  * closing the substream, so even if the substreams stay alive they will
97  * always just return a G_IO_ERROR_CLOSED for all operations.
98  * To close a stream use g_io_stream_close() which will close the common
99  * stream object and also the individual substreams. You can also close
100  * the substreams themselves. In most cases this only marks the
101  * substream as closed, so further I/O on it fails. However, some streams
102  * may support "half-closed" states where one direction of the stream
103  * is actually shut down.
104  */
105 public class IOStream : ObjectG
106 {
107    
108     /** the main Gtk struct */
109     protected GIOStream* gIOStream;
110    
111    
112     public GIOStream* getIOStreamStruct()
113     {
114         return gIOStream;
115     }
116    
117    
118     /** the main Gtk struct as a void* */
119     protected override void* getStruct()
120     {
121         return cast(void*)gIOStream;
122     }
123    
124     /**
125      * Sets our main struct and passes it to the parent class
126      */
127     public this (GIOStream* gIOStream)
128     {
129         if(gIOStream is null)
130         {
131             this = null;
132             return;
133         }
134         //Check if there already is a D object for this gtk struct
135         void* ptr = getDObject(cast(GObject*)gIOStream);
136         if( ptr !is null )
137         {
138             this = cast(IOStream)ptr;
139             return;
140         }
141         super(cast(GObject*)gIOStream);
142         this.gIOStream = gIOStream;
143     }
144    
145     protected override void setStruct(GObject* obj)
146     {
147         super.setStruct(obj);
148         gIOStream = cast(GIOStream*)obj;
149     }
150    
151     /**
152      */
153    
154     /**
155      * Gets the input stream for this object. This is used
156      * for reading.
157      * Since 2.22
158      * Returns: a GInputStream, owned by the GIOStream. Do not free. [transfer none]
159      */
160     public InputStream getInputStream()
161     {
162         // GInputStream * g_io_stream_get_input_stream (GIOStream *stream);
163         auto p = g_io_stream_get_input_stream(gIOStream);
164         if(p is null)
165         {
166             return null;
167         }
168         return new InputStream(cast(GInputStream*) p);
169     }
170    
171     /**
172      * Gets the output stream for this object. This is used for
173      * writing.
174      * Since 2.22
175      * Returns: a GOutputStream, owned by the GIOStream. Do not free. [transfer none]
176      */
177     public OutputStream getOutputStream()
178     {
179         // GOutputStream * g_io_stream_get_output_stream (GIOStream *stream);
180         auto p = g_io_stream_get_output_stream(gIOStream);
181         if(p is null)
182         {
183             return null;
184         }
185         return new OutputStream(cast(GOutputStream*) p);
186     }
187    
188     /**
189      * Asyncronously splice the output stream of stream1 to the input stream of
190      * stream2, and splice the output stream of stream2 to the input stream of
191      * stream1.
192      * When the operation is finished callback will be called.
193      * You can then call g_io_stream_splice_finish() to get the
194      * result of the operation.
195      * Since 2.28
196      * Params:
197      * stream2 = a GIOStream.
198      * flags = a set of GIOStreamSpliceFlags.
199      * ioPriority = the io priority of the request.
200      * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
201      * callback = a GAsyncReadyCallback. [scope async]
202      * userData = user data passed to callback. [closure]
203      */
204     public void spliceAsync(IOStream stream2, GIOStreamSpliceFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
205     {
206         // void g_io_stream_splice_async (GIOStream *stream1,  GIOStream *stream2,  GIOStreamSpliceFlags flags,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
207         g_io_stream_splice_async(gIOStream, (stream2 is null) ? null : stream2.getIOStreamStruct(), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
208     }
209    
210     /**
211      * Finishes an asynchronous io stream splice operation.
212      * Since 2.28
213      * Params:
214      * result = a GAsyncResult.
215      * Returns: TRUE on success, FALSE otherwise.
216      * Throws: GException on failure.
217      */
218     public static int spliceFinish(AsyncResultIF result)
219     {
220         // gboolean g_io_stream_splice_finish (GAsyncResult *result,  GError **error);
221         GError* err = null;
222        
223         auto p = g_io_stream_splice_finish((result is null) ? null : result.getAsyncResultTStruct(), &err);
224        
225         if (err !is null)
226         {
227             throw new GException( new ErrorG(err) );
228         }
229        
230         return p;
231     }
232    
233     /**
234      * Closes the stream, releasing resources related to it. This will also
235      * closes the individual input and output streams, if they are not already
236      * closed.
237      * Once the stream is closed, all other operations will return
238      * G_IO_ERROR_CLOSED. Closing a stream multiple times will not
239      * return an error.
240      * Closing a stream will automatically flush any outstanding buffers
241      * in the stream.
242      * Streams will be automatically closed when the last reference
243      * is dropped, but you might want to call this function to make sure
244      * resources are released as early as possible.
245      * Some streams might keep the backing store of the stream (e.g. a file
246      * descriptor) open after the stream is closed. See the documentation for
247      * the individual stream for details.
248      * On failure the first error that happened will be reported, but the
249      * close operation will finish as much as possible. A stream that failed
250      * to close will still return G_IO_ERROR_CLOSED for all operations.
251      * Still, it is important to check and report the error to the user,
252      * otherwise there might be a loss of data as all data might not be written.
253      * If cancellable is not NULL, then the operation can be cancelled by
254      * triggering the cancellable object from another thread. If the operation
255      * was cancelled, the error G_IO_ERROR_CANCELLED will be returned.
256      * Cancelling a close will still leave the stream closed, but some streams
257      * can use a faster close that doesn't block to e.g. check errors.
258      * The default implementation of this method just calls close on the
259      * individual input/output streams.
260      * Since 2.22
261      * Params:
262      * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
263      * Returns: TRUE on success, FALSE on failure
264      * Throws: GException on failure.
265      */
266     public int close(Cancellable cancellable)
267     {
268         // gboolean g_io_stream_close (GIOStream *stream,  GCancellable *cancellable,  GError **error);
269         GError* err = null;
270        
271         auto p = g_io_stream_close(gIOStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
272        
273         if (err !is null)
274         {
275             throw new GException( new ErrorG(err) );
276         }
277        
278         return p;
279     }
280    
281     /**
282      * Requests an asynchronous close of the stream, releasing resources
283      * related to it. When the operation is finished callback will be
284      * called. You can then call g_io_stream_close_finish() to get
285      * the result of the operation.
286      * For behaviour details see g_io_stream_close().
287      * The asynchronous methods have a default fallback that uses threads
288      * to implement asynchronicity, so they are optional for inheriting
289      * classes. However, if you override one you must override all.
290      * Since 2.22
291      * Params:
292      * ioPriority = the io priority of the request
293      * cancellable = optional cancellable object. [allow-none]
294      * callback = callback to call when the request is satisfied. [scope async]
295      * userData = the data to pass to callback function. [closure]
296      */
297     public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
298     {
299         // void g_io_stream_close_async (GIOStream *stream,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
300         g_io_stream_close_async(gIOStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
301     }
302    
303     /**
304      * Closes a stream.
305      * Since 2.22
306      * Params:
307      * result = a GAsyncResult
308      * Returns: TRUE if stream was successfully closed, FALSE otherwise.
309      * Throws: GException on failure.
310      */
311     public int closeFinish(AsyncResultIF result)
312     {
313         // gboolean g_io_stream_close_finish (GIOStream *stream,  GAsyncResult *result,  GError **error);
314         GError* err = null;
315        
316         auto p = g_io_stream_close_finish(gIOStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
317        
318         if (err !is null)
319         {
320             throw new GException( new ErrorG(err) );
321         }
322        
323         return p;
324     }
325    
326     /**
327      * Checks if a stream is closed.
328      * Since 2.22
329      * Returns: TRUE if the stream is closed.
330      */
331     public int isClosed()
332     {
333         // gboolean g_io_stream_is_closed (GIOStream *stream);
334         return g_io_stream_is_closed(gIOStream);
335     }
336    
337     /**
338      * Checks if a stream has pending actions.
339      * Since 2.22
340      * Returns: TRUE if stream has pending actions.
341      */
342     public int hasPending()
343     {
344         // gboolean g_io_stream_has_pending (GIOStream *stream);
345         return g_io_stream_has_pending(gIOStream);
346     }
347    
348     /**
349      * Sets stream to have actions pending. If the pending flag is
350      * already set or stream is closed, it will return FALSE and set
351      * error.
352      * Since 2.22
353      * Returns: TRUE if pending was previously unset and is now set.
354      * Throws: GException on failure.
355      */
356     public int setPending()
357     {
358         // gboolean g_io_stream_set_pending (GIOStream *stream,  GError **error);
359         GError* err = null;
360        
361         auto p = g_io_stream_set_pending(gIOStream, &err);
362        
363         if (err !is null)
364         {
365             throw new GException( new ErrorG(err) );
366         }
367        
368         return p;
369     }
370    
371     /**
372      * Clears the pending flag on stream.
373      * Since 2.22
374      */
375     public void clearPending()
376     {
377         // void g_io_stream_clear_pending (GIOStream *stream);
378         g_io_stream_clear_pending(gIOStream);
379     }
380 }
Note: See TracBrowser for help on using the browser.