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  = GInputStream.html
27  * outPack = gio
28  * outFile = InputStream
29  * strct   = GInputStream
30  * realStrct=
31  * ctorStrct=
32  * clss    = InputStream
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_input_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  * structWrap:
51  * 	- GAsyncResult* -> AsyncResultIF
52  * 	- GCancellable* -> Cancellable
53  * module aliases:
54  * local aliases:
55  * overrides:
56  */
57 
58 module gio.InputStream;
59 
60 public  import gtkc.giotypes;
61 
62 private import gtkc.gio;
63 private import glib.ConstructionException;
64 private import gobject.ObjectG;
65 
66 
67 private import glib.ErrorG;
68 private import glib.GException;
69 private import gio.AsyncResultIF;
70 private import gio.Cancellable;
71 
72 
73 
74 private import gobject.ObjectG;
75 
76 /**
77  * Description
78  * GInputStream has functions to read from a stream (g_input_stream_read()),
79  * to close a stream (g_input_stream_close()) and to skip some content
80  * (g_input_stream_skip()).
81  * To copy the content of an input stream to an output stream without
82  * manually handling the reads and writes, use g_output_stream_splice().
83  * All of these functions have async variants too.
84  */
85 public class InputStream : ObjectG
86 {
87 	
88 	/** the main Gtk struct */
89 	protected GInputStream* gInputStream;
90 	
91 	
92 	public GInputStream* getInputStreamStruct()
93 	{
94 		return gInputStream;
95 	}
96 	
97 	
98 	/** the main Gtk struct as a void* */
99 	protected override void* getStruct()
100 	{
101 		return cast(void*)gInputStream;
102 	}
103 	
104 	/**
105 	 * Sets our main struct and passes it to the parent class
106 	 */
107 	public this (GInputStream* gInputStream)
108 	{
109 		super(cast(GObject*)gInputStream);
110 		this.gInputStream = gInputStream;
111 	}
112 	
113 	protected override void setStruct(GObject* obj)
114 	{
115 		super.setStruct(obj);
116 		gInputStream = cast(GInputStream*)obj;
117 	}
118 	
119 	/**
120 	 */
121 	
122 	/**
123 	 * Tries to read count bytes from the stream into the buffer starting at
124 	 * buffer. Will block during this read.
125 	 * If count is zero returns zero and does nothing. A value of count
126 	 * larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error.
127 	 * On success, the number of bytes read into the buffer is returned.
128 	 * It is not an error if this is not the same as the requested size, as it
129 	 * can happen e.g. near the end of a file. Zero is returned on end of file
130 	 * (or if count is zero), but never otherwise.
131 	 * If cancellable is not NULL, then the operation can be cancelled by
132 	 * triggering the cancellable object from another thread. If the operation
133 	 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an
134 	 * operation was partially finished when the operation was cancelled the
135 	 * partial result will be returned, without an error.
136 	 * On error -1 is returned and error is set accordingly.
137 	 * Params:
138 	 * buffer = a buffer to read data into (which should be at least count bytes long).
139 	 * count = the number of bytes that will be read from the stream
140 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
141 	 * Returns: Number of bytes read, or -1 on error
142 	 * Throws: GException on failure.
143 	 */
144 	public gssize read(void* buffer, gsize count, Cancellable cancellable)
145 	{
146 		// gssize g_input_stream_read (GInputStream *stream,  void *buffer,  gsize count,  GCancellable *cancellable,  GError **error);
147 		GError* err = null;
148 		
149 		auto p = g_input_stream_read(gInputStream, buffer, count, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
150 		
151 		if (err !is null)
152 		{
153 			throw new GException( new ErrorG(err) );
154 		}
155 		
156 		return p;
157 	}
158 	
159 	/**
160 	 * Tries to read count bytes from the stream into the buffer starting at
161 	 * buffer. Will block during this read.
162 	 * This function is similar to g_input_stream_read(), except it tries to
163 	 * read as many bytes as requested, only stopping on an error or end of stream.
164 	 * On a successful read of count bytes, or if we reached the end of the
165 	 * stream, TRUE is returned, and bytes_read is set to the number of bytes
166 	 * read into buffer.
167 	 * If there is an error during the operation FALSE is returned and error
168 	 * is set to indicate the error status, bytes_read is updated to contain
169 	 * the number of bytes read into buffer before the error occurred.
170 	 * Params:
171 	 * buffer = a buffer to read data into (which should be at least count bytes long).
172 	 * count = the number of bytes that will be read from the stream
173 	 * bytesRead = location to store the number of bytes that was read from the stream. [out]
174 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
175 	 * Returns: TRUE on success, FALSE if there was an error
176 	 * Throws: GException on failure.
177 	 */
178 	public int readAll(void* buffer, gsize count, out gsize bytesRead, Cancellable cancellable)
179 	{
180 		// gboolean g_input_stream_read_all (GInputStream *stream,  void *buffer,  gsize count,  gsize *bytes_read,  GCancellable *cancellable,  GError **error);
181 		GError* err = null;
182 		
183 		auto p = g_input_stream_read_all(gInputStream, buffer, count, &bytesRead, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
184 		
185 		if (err !is null)
186 		{
187 			throw new GException( new ErrorG(err) );
188 		}
189 		
190 		return p;
191 	}
192 	
193 	/**
194 	 * Tries to skip count bytes from the stream. Will block during the operation.
195 	 * This is identical to g_input_stream_read(), from a behaviour standpoint,
196 	 * but the bytes that are skipped are not returned to the user. Some
197 	 * streams have an implementation that is more efficient than reading the data.
198 	 * This function is optional for inherited classes, as the default implementation
199 	 * emulates it using read.
200 	 * If cancellable is not NULL, then the operation can be cancelled by
201 	 * triggering the cancellable object from another thread. If the operation
202 	 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an
203 	 * operation was partially finished when the operation was cancelled the
204 	 * partial result will be returned, without an error.
205 	 * Params:
206 	 * count = the number of bytes that will be skipped from the stream
207 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
208 	 * Returns: Number of bytes skipped, or -1 on error
209 	 * Throws: GException on failure.
210 	 */
211 	public gssize skip(gsize count, Cancellable cancellable)
212 	{
213 		// gssize g_input_stream_skip (GInputStream *stream,  gsize count,  GCancellable *cancellable,  GError **error);
214 		GError* err = null;
215 		
216 		auto p = g_input_stream_skip(gInputStream, count, (cancellable is null) ? null : cancellable.getCancellableStruct(), &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.
228 	 * Once the stream is closed, all other operations will return G_IO_ERROR_CLOSED.
229 	 * Closing a stream multiple times will not return an error.
230 	 * Streams will be automatically closed when the last reference
231 	 * is dropped, but you might want to call this function to make sure
232 	 * resources are released as early as possible.
233 	 * Some streams might keep the backing store of the stream (e.g. a file descriptor)
234 	 * open after the stream is closed. See the documentation for the individual
235 	 * stream for details.
236 	 * On failure the first error that happened will be reported, but the close
237 	 * operation will finish as much as possible. A stream that failed to
238 	 * close will still return G_IO_ERROR_CLOSED for all operations. Still, it
239 	 * is important to check and report the error to the user.
240 	 * If cancellable is not NULL, then the operation can be cancelled by
241 	 * triggering the cancellable object from another thread. If the operation
242 	 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned.
243 	 * Cancelling a close will still leave the stream closed, but some streams
244 	 * can use a faster close that doesn't block to e.g. check errors.
245 	 * Params:
246 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
247 	 * Returns: TRUE on success, FALSE on failure
248 	 * Throws: GException on failure.
249 	 */
250 	public int close(Cancellable cancellable)
251 	{
252 		// gboolean g_input_stream_close (GInputStream *stream,  GCancellable *cancellable,  GError **error);
253 		GError* err = null;
254 		
255 		auto p = g_input_stream_close(gInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
256 		
257 		if (err !is null)
258 		{
259 			throw new GException( new ErrorG(err) );
260 		}
261 		
262 		return p;
263 	}
264 	
265 	/**
266 	 * Request an asynchronous read of count bytes from the stream into the buffer
267 	 * starting at buffer. When the operation is finished callback will be called.
268 	 * You can then call g_input_stream_read_finish() to get the result of the
269 	 * operation.
270 	 * During an async request no other sync and async calls are allowed on stream, and will
271 	 * result in G_IO_ERROR_PENDING errors.
272 	 * A value of count larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error.
273 	 * On success, the number of bytes read into the buffer will be passed to the
274 	 * callback. It is not an error if this is not the same as the requested size, as it
275 	 * can happen e.g. near the end of a file, but generally we try to read
276 	 * as many bytes as requested. Zero is returned on end of file
277 	 * (or if count is zero), but never otherwise.
278 	 * Any outstanding i/o request with higher priority (lower numerical value) will
279 	 * be executed before an outstanding request with lower priority. Default
280 	 * priority is G_PRIORITY_DEFAULT.
281 	 * The asyncronous methods have a default fallback that uses threads to implement
282 	 * asynchronicity, so they are optional for inheriting classes. However, if you
283 	 * override one you must override all.
284 	 * Params:
285 	 * buffer = a buffer to read data into (which should be at least count bytes long).
286 	 * count = the number of bytes that will be read from the stream
287 	 * ioPriority = the I/O priority
288 	 * of the request.
289 	 * cancellable = optional GCancellable object, NULL to ignore. [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 readAsync(void* buffer, gsize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
294 	{
295 		// void g_input_stream_read_async (GInputStream *stream,  void *buffer,  gsize count,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
296 		g_input_stream_read_async(gInputStream, buffer, count, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
297 	}
298 	
299 	/**
300 	 * Finishes an asynchronous stream read operation.
301 	 * Params:
302 	 * result = a GAsyncResult.
303 	 * Returns: number of bytes read in, or -1 on error.
304 	 * Throws: GException on failure.
305 	 */
306 	public gssize readFinish(AsyncResultIF result)
307 	{
308 		// gssize g_input_stream_read_finish (GInputStream *stream,  GAsyncResult *result,  GError **error);
309 		GError* err = null;
310 		
311 		auto p = g_input_stream_read_finish(gInputStream, (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 	 * Request an asynchronous skip of count bytes from the stream.
323 	 * When the operation is finished callback will be called.
324 	 * You can then call g_input_stream_skip_finish() to get the result
325 	 * of the operation.
326 	 * During an async request no other sync and async calls are allowed,
327 	 * and will result in G_IO_ERROR_PENDING errors.
328 	 * A value of count larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error.
329 	 * On success, the number of bytes skipped will be passed to the callback.
330 	 * It is not an error if this is not the same as the requested size, as it
331 	 * can happen e.g. near the end of a file, but generally we try to skip
332 	 * as many bytes as requested. Zero is returned on end of file
333 	 * (or if count is zero), but never otherwise.
334 	 * Any outstanding i/o request with higher priority (lower numerical value)
335 	 * will be executed before an outstanding request with lower priority.
336 	 * Default priority is G_PRIORITY_DEFAULT.
337 	 * The asynchronous methods have a default fallback that uses threads to
338 	 * implement asynchronicity, so they are optional for inheriting classes.
339 	 * However, if you override one, you must override all.
340 	 * Params:
341 	 * count = the number of bytes that will be skipped from the stream
342 	 * ioPriority = the I/O priority
343 	 * of the request.
344 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
345 	 * callback = callback to call when the request is satisfied. [scope async]
346 	 * userData = the data to pass to callback function. [closure]
347 	 */
348 	public void skipAsync(gsize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
349 	{
350 		// void g_input_stream_skip_async (GInputStream *stream,  gsize count,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
351 		g_input_stream_skip_async(gInputStream, count, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
352 	}
353 	
354 	/**
355 	 * Finishes a stream skip operation.
356 	 * Params:
357 	 * result = a GAsyncResult.
358 	 * Returns: the size of the bytes skipped, or -1 on error.
359 	 * Throws: GException on failure.
360 	 */
361 	public gssize skipFinish(AsyncResultIF result)
362 	{
363 		// gssize g_input_stream_skip_finish (GInputStream *stream,  GAsyncResult *result,  GError **error);
364 		GError* err = null;
365 		
366 		auto p = g_input_stream_skip_finish(gInputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
367 		
368 		if (err !is null)
369 		{
370 			throw new GException( new ErrorG(err) );
371 		}
372 		
373 		return p;
374 	}
375 	
376 	/**
377 	 * Requests an asynchronous closes of the stream, releasing resources related to it.
378 	 * When the operation is finished callback will be called.
379 	 * You can then call g_input_stream_close_finish() to get the result of the
380 	 * operation.
381 	 * For behaviour details see g_input_stream_close().
382 	 * The asyncronous methods have a default fallback that uses threads to implement
383 	 * asynchronicity, so they are optional for inheriting classes. However, if you
384 	 * override one you must override all.
385 	 * Params:
386 	 * ioPriority = the I/O priority
387 	 * of the request.
388 	 * cancellable = optional cancellable object. [allow-none]
389 	 * callback = callback to call when the request is satisfied. [scope async]
390 	 * userData = the data to pass to callback function. [closure]
391 	 */
392 	public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
393 	{
394 		// void g_input_stream_close_async (GInputStream *stream,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
395 		g_input_stream_close_async(gInputStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
396 	}
397 	
398 	/**
399 	 * Finishes closing a stream asynchronously, started from g_input_stream_close_async().
400 	 * Params:
401 	 * result = a GAsyncResult.
402 	 * Returns: TRUE if the stream was closed successfully.
403 	 * Throws: GException on failure.
404 	 */
405 	public int closeFinish(AsyncResultIF result)
406 	{
407 		// gboolean g_input_stream_close_finish (GInputStream *stream,  GAsyncResult *result,  GError **error);
408 		GError* err = null;
409 		
410 		auto p = g_input_stream_close_finish(gInputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
411 		
412 		if (err !is null)
413 		{
414 			throw new GException( new ErrorG(err) );
415 		}
416 		
417 		return p;
418 	}
419 	
420 	/**
421 	 * Checks if an input stream is closed.
422 	 * Returns: TRUE if the stream is closed.
423 	 */
424 	public int isClosed()
425 	{
426 		// gboolean g_input_stream_is_closed (GInputStream *stream);
427 		return g_input_stream_is_closed(gInputStream);
428 	}
429 	
430 	/**
431 	 * Checks if an input stream has pending actions.
432 	 * Returns: TRUE if stream has pending actions.
433 	 */
434 	public int hasPending()
435 	{
436 		// gboolean g_input_stream_has_pending (GInputStream *stream);
437 		return g_input_stream_has_pending(gInputStream);
438 	}
439 	
440 	/**
441 	 * Sets stream to have actions pending. If the pending flag is
442 	 * already set or stream is closed, it will return FALSE and set
443 	 * error.
444 	 * Returns: TRUE if pending was previously unset and is now set.
445 	 * Throws: GException on failure.
446 	 */
447 	public int setPending()
448 	{
449 		// gboolean g_input_stream_set_pending (GInputStream *stream,  GError **error);
450 		GError* err = null;
451 		
452 		auto p = g_input_stream_set_pending(gInputStream, &err);
453 		
454 		if (err !is null)
455 		{
456 			throw new GException( new ErrorG(err) );
457 		}
458 		
459 		return p;
460 	}
461 	
462 	/**
463 	 * Clears the pending flag on stream.
464 	 */
465 	public void clearPending()
466 	{
467 		// void g_input_stream_clear_pending (GInputStream *stream);
468 		g_input_stream_clear_pending(gInputStream);
469 	}
470 }