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