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