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