source: appstream-generator/build/girepo/gio/IOStream.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 10.0 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.IOStream;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.AsyncResultIF;
26private import gio.Cancellable;
27private import gio.InputStream;
28private import gio.OutputStream;
29private import glib.ErrorG;
30private import glib.GException;
31private import gobject.ObjectG;
32
33
34/**
35 * GIOStream represents an object that has both read and write streams.
36 * Generally the two streams acts as separate input and output streams,
37 * but they share some common resources and state. For instance, for
38 * seekable streams they may use the same position in both streams.
39 *
40 * Examples of #GIOStream objects are #GSocketConnection which represents
41 * a two-way network connection, and #GFileIOStream which represent a
42 * file handle opened in read-write mode.
43 *
44 * To do the actual reading and writing you need to get the substreams
45 * with g_io_stream_get_input_stream() and g_io_stream_get_output_stream().
46 *
47 * The #GIOStream object owns the input and the output streams, not the other
48 * way around, so keeping the substreams alive will not keep the #GIOStream
49 * object alive. If the #GIOStream object is freed it will be closed, thus
50 * closing the substream, so even if the substreams stay alive they will
51 * always just return a %G_IO_ERROR_CLOSED for all operations.
52 *
53 * To close a stream use g_io_stream_close() which will close the common
54 * stream object and also the individual substreams. You can also close
55 * the substreams themselves. In most cases this only marks the
56 * substream as closed, so further I/O on it fails but common state in the
57 * #GIOStream may still be open. However, some streams may support
58 * "half-closed" states where one direction of the stream is actually shut down.
59 */
60public class IOStream : ObjectG
61{
62        /** the main Gtk struct */
63        protected GIOStream* gIOStream;
64
65        /** Get the main Gtk struct */
66        public GIOStream* getIOStreamStruct()
67        {
68                return gIOStream;
69        }
70
71        /** the main Gtk struct as a void* */
72        protected override void* getStruct()
73        {
74                return cast(void*)gIOStream;
75        }
76
77        protected override void setStruct(GObject* obj)
78        {
79                gIOStream = cast(GIOStream*)obj;
80                super.setStruct(obj);
81        }
82
83        /**
84         * Sets our main struct and passes it to the parent class.
85         */
86        public this (GIOStream* gIOStream, bool ownedRef = false)
87        {
88                this.gIOStream = gIOStream;
89                super(cast(GObject*)gIOStream, ownedRef);
90        }
91
92
93        /** */
94        public static GType getType()
95        {
96                return g_io_stream_get_type();
97        }
98
99        /**
100         * Finishes an asynchronous io stream splice operation.
101         *
102         * Params:
103         *     result = a #GAsyncResult.
104         *
105         * Returns: %TRUE on success, %FALSE otherwise.
106         *
107         * Since: 2.28
108         *
109         * Throws: GException on failure.
110         */
111        public static bool spliceFinish(AsyncResultIF result)
112        {
113                GError* err = null;
114               
115                auto p = g_io_stream_splice_finish((result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
116               
117                if (err !is null)
118                {
119                        throw new GException( new ErrorG(err) );
120                }
121               
122                return p;
123        }
124
125        /**
126         * Clears the pending flag on @stream.
127         *
128         * Since: 2.22
129         */
130        public void clearPending()
131        {
132                g_io_stream_clear_pending(gIOStream);
133        }
134
135        /**
136         * Closes the stream, releasing resources related to it. This will also
137         * closes the individual input and output streams, if they are not already
138         * closed.
139         *
140         * Once the stream is closed, all other operations will return
141         * %G_IO_ERROR_CLOSED. Closing a stream multiple times will not
142         * return an error.
143         *
144         * Closing a stream will automatically flush any outstanding buffers
145         * in the stream.
146         *
147         * Streams will be automatically closed when the last reference
148         * is dropped, but you might want to call this function to make sure
149         * resources are released as early as possible.
150         *
151         * Some streams might keep the backing store of the stream (e.g. a file
152         * descriptor) open after the stream is closed. See the documentation for
153         * the individual stream for details.
154         *
155         * On failure the first error that happened will be reported, but the
156         * close operation will finish as much as possible. A stream that failed
157         * to close will still return %G_IO_ERROR_CLOSED for all operations.
158         * Still, it is important to check and report the error to the user,
159         * otherwise there might be a loss of data as all data might not be written.
160         *
161         * If @cancellable is not NULL, then the operation can be cancelled by
162         * triggering the cancellable object from another thread. If the operation
163         * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
164         * Cancelling a close will still leave the stream closed, but some streams
165         * can use a faster close that doesn't block to e.g. check errors.
166         *
167         * The default implementation of this method just calls close on the
168         * individual input/output streams.
169         *
170         * Params:
171         *     cancellable = optional #GCancellable object, %NULL to ignore
172         *
173         * Returns: %TRUE on success, %FALSE on failure
174         *
175         * Since: 2.22
176         *
177         * Throws: GException on failure.
178         */
179        public bool close(Cancellable cancellable)
180        {
181                GError* err = null;
182               
183                auto p = g_io_stream_close(gIOStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
184               
185                if (err !is null)
186                {
187                        throw new GException( new ErrorG(err) );
188                }
189               
190                return p;
191        }
192
193        /**
194         * Requests an asynchronous close of the stream, releasing resources
195         * related to it. When the operation is finished @callback will be
196         * called. You can then call g_io_stream_close_finish() to get
197         * the result of the operation.
198         *
199         * For behaviour details see g_io_stream_close().
200         *
201         * The asynchronous methods have a default fallback that uses threads
202         * to implement asynchronicity, so they are optional for inheriting
203         * classes. However, if you override one you must override all.
204         *
205         * Params:
206         *     ioPriority = the io priority of the request
207         *     cancellable = optional cancellable object
208         *     callback = callback to call when the request is satisfied
209         *     userData = the data to pass to callback function
210         *
211         * Since: 2.22
212         */
213        public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
214        {
215                g_io_stream_close_async(gIOStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
216        }
217
218        /**
219         * Closes a stream.
220         *
221         * Params:
222         *     result = a #GAsyncResult
223         *
224         * Returns: %TRUE if stream was successfully closed, %FALSE otherwise.
225         *
226         * Since: 2.22
227         *
228         * Throws: GException on failure.
229         */
230        public bool closeFinish(AsyncResultIF result)
231        {
232                GError* err = null;
233               
234                auto p = g_io_stream_close_finish(gIOStream, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
235               
236                if (err !is null)
237                {
238                        throw new GException( new ErrorG(err) );
239                }
240               
241                return p;
242        }
243
244        /**
245         * Gets the input stream for this object. This is used
246         * for reading.
247         *
248         * Returns: a #GInputStream, owned by the #GIOStream.
249         *     Do not free.
250         *
251         * Since: 2.22
252         */
253        public InputStream getInputStream()
254        {
255                auto p = g_io_stream_get_input_stream(gIOStream);
256               
257                if(p is null)
258                {
259                        return null;
260                }
261               
262                return ObjectG.getDObject!(InputStream)(cast(GInputStream*) p);
263        }
264
265        /**
266         * Gets the output stream for this object. This is used for
267         * writing.
268         *
269         * Returns: a #GOutputStream, owned by the #GIOStream.
270         *     Do not free.
271         *
272         * Since: 2.22
273         */
274        public OutputStream getOutputStream()
275        {
276                auto p = g_io_stream_get_output_stream(gIOStream);
277               
278                if(p is null)
279                {
280                        return null;
281                }
282               
283                return ObjectG.getDObject!(OutputStream)(cast(GOutputStream*) p);
284        }
285
286        /**
287         * Checks if a stream has pending actions.
288         *
289         * Returns: %TRUE if @stream has pending actions.
290         *
291         * Since: 2.22
292         */
293        public bool hasPending()
294        {
295                return g_io_stream_has_pending(gIOStream) != 0;
296        }
297
298        /**
299         * Checks if a stream is closed.
300         *
301         * Returns: %TRUE if the stream is closed.
302         *
303         * Since: 2.22
304         */
305        public bool isClosed()
306        {
307                return g_io_stream_is_closed(gIOStream) != 0;
308        }
309
310        /**
311         * Sets @stream to have actions pending. If the pending flag is
312         * already set or @stream is closed, it will return %FALSE and set
313         * @error.
314         *
315         * Returns: %TRUE if pending was previously unset and is now set.
316         *
317         * Since: 2.22
318         *
319         * Throws: GException on failure.
320         */
321        public bool setPending()
322        {
323                GError* err = null;
324               
325                auto p = g_io_stream_set_pending(gIOStream, &err) != 0;
326               
327                if (err !is null)
328                {
329                        throw new GException( new ErrorG(err) );
330                }
331               
332                return p;
333        }
334
335        /**
336         * Asyncronously splice the output stream of @stream1 to the input stream of
337         * @stream2, and splice the output stream of @stream2 to the input stream of
338         * @stream1.
339         *
340         * When the operation is finished @callback will be called.
341         * You can then call g_io_stream_splice_finish() to get the
342         * result of the operation.
343         *
344         * Params:
345         *     stream2 = a #GIOStream.
346         *     flags = a set of #GIOStreamSpliceFlags.
347         *     ioPriority = the io priority of the request.
348         *     cancellable = optional #GCancellable object, %NULL to ignore.
349         *     callback = a #GAsyncReadyCallback.
350         *     userData = user data passed to @callback.
351         *
352         * Since: 2.28
353         */
354        public void spliceAsync(IOStream stream2, GIOStreamSpliceFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
355        {
356                g_io_stream_splice_async(gIOStream, (stream2 is null) ? null : stream2.getIOStreamStruct(), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
357        }
358}
Note: See TracBrowser for help on using the repository browser.