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  = GOutputStream.html
27  * outPack = gio
28  * outFile = OutputStream
29  * strct   = GOutputStream
30  * realStrct=
31  * ctorStrct=
32  * clss    = OutputStream
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = GObject
38  * implements:
39  * prefixes:
40  * 	- g_output_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  * structWrap:
52  * 	- GAsyncResult* -> AsyncResultIF
53  * 	- GCancellable* -> Cancellable
54  * 	- GInputStream* -> InputStream
55  * module aliases:
56  * local aliases:
57  * overrides:
58  */
59 
60 module gio.OutputStream;
61 
62 public  import gtkc.giotypes;
63 
64 private import gtkc.gio;
65 private import glib.ConstructionException;
66 private import gobject.ObjectG;
67 
68 
69 private import glib.ErrorG;
70 private import glib.GException;
71 private import gio.AsyncResultIF;
72 private import gio.Cancellable;
73 private import gio.InputStream;
74 
75 
76 
77 private import gobject.ObjectG;
78 
79 /**
80  * Description
81  * GOutputStream has functions to write to a stream (g_output_stream_write()),
82  * to close a stream (g_output_stream_close()) and to flush pending writes
83  * (g_output_stream_flush()).
84  * To copy the content of an input stream to an output stream without
85  * manually handling the reads and writes, use g_output_stream_splice().
86  * All of these functions have async variants too.
87  */
88 public class OutputStream : ObjectG
89 {
90 	
91 	/** the main Gtk struct */
92 	protected GOutputStream* gOutputStream;
93 	
94 	
95 	public GOutputStream* getOutputStreamStruct()
96 	{
97 		return gOutputStream;
98 	}
99 	
100 	
101 	/** the main Gtk struct as a void* */
102 	protected override void* getStruct()
103 	{
104 		return cast(void*)gOutputStream;
105 	}
106 	
107 	/**
108 	 * Sets our main struct and passes it to the parent class
109 	 */
110 	public this (GOutputStream* gOutputStream)
111 	{
112 		super(cast(GObject*)gOutputStream);
113 		this.gOutputStream = gOutputStream;
114 	}
115 	
116 	protected override void setStruct(GObject* obj)
117 	{
118 		super.setStruct(obj);
119 		gOutputStream = cast(GOutputStream*)obj;
120 	}
121 	
122 	/**
123 	 */
124 	
125 	/**
126 	 * Tries to write count bytes from buffer into the stream. Will block
127 	 * during the operation.
128 	 * If count is 0, returns 0 and does nothing. A value of count
129 	 * larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error.
130 	 * On success, the number of bytes written to the stream is returned.
131 	 * It is not an error if this is not the same as the requested size, as it
132 	 * can happen e.g. on a partial I/O error, or if there is not enough
133 	 * storage in the stream. All writes block until at least one byte
134 	 * is written or an error occurs; 0 is never returned (unless
135 	 * count is 0).
136 	 * If cancellable is not NULL, then the operation can be cancelled by
137 	 * triggering the cancellable object from another thread. If the operation
138 	 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an
139 	 * operation was partially finished when the operation was cancelled the
140 	 * partial result will be returned, without an error.
141 	 * On error -1 is returned and error is set accordingly.
142 	 * Params:
143 	 * buffer = the buffer containing the data to write. [array length=count][element-type guint8]
144 	 * count = the number of bytes to write
145 	 * cancellable = optional cancellable object. [allow-none]
146 	 * Returns: Number of bytes written, or -1 on error
147 	 * Throws: GException on failure.
148 	 */
149 	public gssize write(void* buffer, gsize count, Cancellable cancellable)
150 	{
151 		// gssize g_output_stream_write (GOutputStream *stream,  const void *buffer,  gsize count,  GCancellable *cancellable,  GError **error);
152 		GError* err = null;
153 		
154 		auto p = g_output_stream_write(gOutputStream, buffer, count, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
155 		
156 		if (err !is null)
157 		{
158 			throw new GException( new ErrorG(err) );
159 		}
160 		
161 		return p;
162 	}
163 	
164 	/**
165 	 * Tries to write count bytes from buffer into the stream. Will block
166 	 * during the operation.
167 	 * This function is similar to g_output_stream_write(), except it tries to
168 	 * write as many bytes as requested, only stopping on an error.
169 	 * On a successful write of count bytes, TRUE is returned, and bytes_written
170 	 * is set to count.
171 	 * If there is an error during the operation FALSE is returned and error
172 	 * is set to indicate the error status, bytes_written is updated to contain
173 	 * the number of bytes written into the stream before the error occurred.
174 	 * Params:
175 	 * buffer = the buffer containing the data to write. [array length=count][element-type guint8]
176 	 * count = the number of bytes to write
177 	 * bytesWritten = location to store the number of bytes that was
178 	 * written to the stream. [out]
179 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
180 	 * Returns: TRUE on success, FALSE if there was an error
181 	 * Throws: GException on failure.
182 	 */
183 	public int writeAll(void* buffer, gsize count, gsize* bytesWritten, Cancellable cancellable)
184 	{
185 		// gboolean g_output_stream_write_all (GOutputStream *stream,  const void *buffer,  gsize count,  gsize *bytes_written,  GCancellable *cancellable,  GError **error);
186 		GError* err = null;
187 		
188 		auto p = g_output_stream_write_all(gOutputStream, buffer, count, bytesWritten, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
189 		
190 		if (err !is null)
191 		{
192 			throw new GException( new ErrorG(err) );
193 		}
194 		
195 		return p;
196 	}
197 	
198 	/**
199 	 * Splices an input stream into an output stream.
200 	 * Params:
201 	 * source = a GInputStream.
202 	 * flags = a set of GOutputStreamSpliceFlags.
203 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
204 	 * Returns: a gssize containing the size of the data spliced, or -1 if an error occurred.
205 	 * Throws: GException on failure.
206 	 */
207 	public gssize splice(InputStream source, GOutputStreamSpliceFlags flags, Cancellable cancellable)
208 	{
209 		// gssize g_output_stream_splice (GOutputStream *stream,  GInputStream *source,  GOutputStreamSpliceFlags flags,  GCancellable *cancellable,  GError **error);
210 		GError* err = null;
211 		
212 		auto p = g_output_stream_splice(gOutputStream, (source is null) ? null : source.getInputStreamStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
213 		
214 		if (err !is null)
215 		{
216 			throw new GException( new ErrorG(err) );
217 		}
218 		
219 		return p;
220 	}
221 	
222 	/**
223 	 * Flushed any outstanding buffers in the stream. Will block during
224 	 * the operation. Closing the stream will implicitly cause a flush.
225 	 * This function is optional for inherited classes.
226 	 * If cancellable is not NULL, then the operation can be cancelled by
227 	 * triggering the cancellable object from another thread. If the operation
228 	 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned.
229 	 * Params:
230 	 * cancellable = optional cancellable object. [allow-none]
231 	 * Returns: TRUE on success, FALSE on error
232 	 * Throws: GException on failure.
233 	 */
234 	public int flush(Cancellable cancellable)
235 	{
236 		// gboolean g_output_stream_flush (GOutputStream *stream,  GCancellable *cancellable,  GError **error);
237 		GError* err = null;
238 		
239 		auto p = g_output_stream_flush(gOutputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
240 		
241 		if (err !is null)
242 		{
243 			throw new GException( new ErrorG(err) );
244 		}
245 		
246 		return p;
247 	}
248 	
249 	/**
250 	 * Closes the stream, releasing resources related to it.
251 	 * Once the stream is closed, all other operations will return G_IO_ERROR_CLOSED.
252 	 * Closing a stream multiple times will not return an error.
253 	 * Closing a stream will automatically flush any outstanding buffers in the
254 	 * stream.
255 	 * Streams will be automatically closed when the last reference
256 	 * is dropped, but you might want to call this function to make sure
257 	 * resources are released as early as possible.
258 	 * Some streams might keep the backing store of the stream (e.g. a file descriptor)
259 	 * open after the stream is closed. See the documentation for the individual
260 	 * stream for details.
261 	 * On failure the first error that happened will be reported, but the close
262 	 * operation will finish as much as possible. A stream that failed to
263 	 * close will still return G_IO_ERROR_CLOSED for all operations. Still, it
264 	 * is important to check and report the error to the user, otherwise
265 	 * there might be a loss of data as all data might not be written.
266 	 * If cancellable is not NULL, then the operation can be cancelled by
267 	 * triggering the cancellable object from another thread. If the operation
268 	 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned.
269 	 * Cancelling a close will still leave the stream closed, but there some streams
270 	 * can use a faster close that doesn't block to e.g. check errors. On
271 	 * cancellation (as with any error) there is no guarantee that all written
272 	 * data will reach the target.
273 	 * Params:
274 	 * cancellable = optional cancellable object. [allow-none]
275 	 * Returns: TRUE on success, FALSE on failure
276 	 * Throws: GException on failure.
277 	 */
278 	public int close(Cancellable cancellable)
279 	{
280 		// gboolean g_output_stream_close (GOutputStream *stream,  GCancellable *cancellable,  GError **error);
281 		GError* err = null;
282 		
283 		auto p = g_output_stream_close(gOutputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
284 		
285 		if (err !is null)
286 		{
287 			throw new GException( new ErrorG(err) );
288 		}
289 		
290 		return p;
291 	}
292 	
293 	/**
294 	 * Request an asynchronous write of count bytes from buffer into
295 	 * the stream. When the operation is finished callback will be called.
296 	 * You can then call g_output_stream_write_finish() to get the result of the
297 	 * operation.
298 	 * During an async request no other sync and async calls are allowed,
299 	 * and will result in G_IO_ERROR_PENDING errors.
300 	 * A value of count larger than G_MAXSSIZE will cause a
301 	 * G_IO_ERROR_INVALID_ARGUMENT error.
302 	 * On success, the number of bytes written will be passed to the
303 	 * callback. It is not an error if this is not the same as the
304 	 * requested size, as it can happen e.g. on a partial I/O error,
305 	 * but generally we try to write as many bytes as requested.
306 	 * You are guaranteed that this method will never fail with
307 	 * G_IO_ERROR_WOULD_BLOCK - if stream can't accept more data, the
308 	 * method will just wait until this changes.
309 	 * Any outstanding I/O request with higher priority (lower numerical
310 	 * value) will be executed before an outstanding request with lower
311 	 * priority. Default priority is G_PRIORITY_DEFAULT.
312 	 * The asyncronous methods have a default fallback that uses threads
313 	 * to implement asynchronicity, so they are optional for inheriting
314 	 * classes. However, if you override one you must override all.
315 	 * For the synchronous, blocking version of this function, see
316 	 * g_output_stream_write().
317 	 * Params:
318 	 * buffer = the buffer containing the data to write. [array length=count][element-type guint8]
319 	 * count = the number of bytes to write
320 	 * ioPriority = the io priority of the request.
321 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
322 	 * callback = callback to call when the request is satisfied. [scope async]
323 	 * userData = the data to pass to callback function. [closure]
324 	 */
325 	public void writeAsync(void* buffer, gsize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
326 	{
327 		// void g_output_stream_write_async (GOutputStream *stream,  const void *buffer,  gsize count,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
328 		g_output_stream_write_async(gOutputStream, buffer, count, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
329 	}
330 	
331 	/**
332 	 * Finishes a stream write operation.
333 	 * Params:
334 	 * result = a GAsyncResult.
335 	 * Returns: a gssize containing the number of bytes written to the stream.
336 	 * Throws: GException on failure.
337 	 */
338 	public gssize writeFinish(AsyncResultIF result)
339 	{
340 		// gssize g_output_stream_write_finish (GOutputStream *stream,  GAsyncResult *result,  GError **error);
341 		GError* err = null;
342 		
343 		auto p = g_output_stream_write_finish(gOutputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
344 		
345 		if (err !is null)
346 		{
347 			throw new GException( new ErrorG(err) );
348 		}
349 		
350 		return p;
351 	}
352 	
353 	/**
354 	 * Splices a stream asynchronously.
355 	 * When the operation is finished callback will be called.
356 	 * You can then call g_output_stream_splice_finish() to get the
357 	 * result of the operation.
358 	 * For the synchronous, blocking version of this function, see
359 	 * g_output_stream_splice().
360 	 * Params:
361 	 * source = a GInputStream.
362 	 * flags = a set of GOutputStreamSpliceFlags.
363 	 * ioPriority = the io priority of the request.
364 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
365 	 * callback = a GAsyncReadyCallback. [scope async]
366 	 * userData = user data passed to callback. [closure]
367 	 */
368 	public void spliceAsync(InputStream source, GOutputStreamSpliceFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
369 	{
370 		// void g_output_stream_splice_async (GOutputStream *stream,  GInputStream *source,  GOutputStreamSpliceFlags flags,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
371 		g_output_stream_splice_async(gOutputStream, (source is null) ? null : source.getInputStreamStruct(), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
372 	}
373 	
374 	/**
375 	 * Finishes an asynchronous stream splice operation.
376 	 * Params:
377 	 * result = a GAsyncResult.
378 	 * Returns: a gssize of the number of bytes spliced.
379 	 * Throws: GException on failure.
380 	 */
381 	public gssize spliceFinish(AsyncResultIF result)
382 	{
383 		// gssize g_output_stream_splice_finish (GOutputStream *stream,  GAsyncResult *result,  GError **error);
384 		GError* err = null;
385 		
386 		auto p = g_output_stream_splice_finish(gOutputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
387 		
388 		if (err !is null)
389 		{
390 			throw new GException( new ErrorG(err) );
391 		}
392 		
393 		return p;
394 	}
395 	
396 	/**
397 	 * Flushes a stream asynchronously.
398 	 * For behaviour details see g_output_stream_flush().
399 	 * When the operation is finished callback will be
400 	 * called. You can then call g_output_stream_flush_finish() to get the
401 	 * result of the operation.
402 	 * Params:
403 	 * ioPriority = the io priority of the request.
404 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
405 	 * callback = a GAsyncReadyCallback to call when the request is satisfied. [scope async]
406 	 * userData = the data to pass to callback function. [closure]
407 	 */
408 	public void flushAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
409 	{
410 		// void g_output_stream_flush_async (GOutputStream *stream,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
411 		g_output_stream_flush_async(gOutputStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
412 	}
413 	
414 	/**
415 	 * Finishes flushing an output stream.
416 	 * Params:
417 	 * result = a GAsyncResult.
418 	 * Returns: TRUE if flush operation suceeded, FALSE otherwise.
419 	 * Throws: GException on failure.
420 	 */
421 	public int flushFinish(AsyncResultIF result)
422 	{
423 		// gboolean g_output_stream_flush_finish (GOutputStream *stream,  GAsyncResult *result,  GError **error);
424 		GError* err = null;
425 		
426 		auto p = g_output_stream_flush_finish(gOutputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
427 		
428 		if (err !is null)
429 		{
430 			throw new GException( new ErrorG(err) );
431 		}
432 		
433 		return p;
434 	}
435 	
436 	/**
437 	 * Requests an asynchronous close of the stream, releasing resources
438 	 * related to it. When the operation is finished callback will be
439 	 * called. You can then call g_output_stream_close_finish() to get
440 	 * the result of the operation.
441 	 * For behaviour details see g_output_stream_close().
442 	 * The asyncronous methods have a default fallback that uses threads
443 	 * to implement asynchronicity, so they are optional for inheriting
444 	 * classes. However, if you override one you must override all.
445 	 * Params:
446 	 * ioPriority = the io priority of the request.
447 	 * cancellable = optional cancellable object. [allow-none]
448 	 * callback = callback to call when the request is satisfied. [scope async]
449 	 * userData = the data to pass to callback function. [closure]
450 	 */
451 	public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
452 	{
453 		// void g_output_stream_close_async (GOutputStream *stream,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
454 		g_output_stream_close_async(gOutputStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
455 	}
456 	
457 	/**
458 	 * Closes an output stream.
459 	 * Params:
460 	 * result = a GAsyncResult.
461 	 * Returns: TRUE if stream was successfully closed, FALSE otherwise.
462 	 * Throws: GException on failure.
463 	 */
464 	public int closeFinish(AsyncResultIF result)
465 	{
466 		// gboolean g_output_stream_close_finish (GOutputStream *stream,  GAsyncResult *result,  GError **error);
467 		GError* err = null;
468 		
469 		auto p = g_output_stream_close_finish(gOutputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
470 		
471 		if (err !is null)
472 		{
473 			throw new GException( new ErrorG(err) );
474 		}
475 		
476 		return p;
477 	}
478 	
479 	/**
480 	 * Checks if an output stream is being closed. This can be
481 	 * used inside e.g. a flush implementation to see if the
482 	 * flush (or other i/o operation) is called from within
483 	 * the closing operation.
484 	 * Since 2.24
485 	 * Returns: TRUE if stream is being closed. FALSE otherwise.
486 	 */
487 	public int isClosing()
488 	{
489 		// gboolean g_output_stream_is_closing (GOutputStream *stream);
490 		return g_output_stream_is_closing(gOutputStream);
491 	}
492 	
493 	/**
494 	 * Checks if an output stream has already been closed.
495 	 * Returns: TRUE if stream is closed. FALSE otherwise.
496 	 */
497 	public int isClosed()
498 	{
499 		// gboolean g_output_stream_is_closed (GOutputStream *stream);
500 		return g_output_stream_is_closed(gOutputStream);
501 	}
502 	
503 	/**
504 	 * Checks if an ouput stream has pending actions.
505 	 * Returns: TRUE if stream has pending actions.
506 	 */
507 	public int hasPending()
508 	{
509 		// gboolean g_output_stream_has_pending (GOutputStream *stream);
510 		return g_output_stream_has_pending(gOutputStream);
511 	}
512 	
513 	/**
514 	 * Sets stream to have actions pending. If the pending flag is
515 	 * already set or stream is closed, it will return FALSE and set
516 	 * error.
517 	 * Returns: TRUE if pending was previously unset and is now set.
518 	 * Throws: GException on failure.
519 	 */
520 	public int setPending()
521 	{
522 		// gboolean g_output_stream_set_pending (GOutputStream *stream,  GError **error);
523 		GError* err = null;
524 		
525 		auto p = g_output_stream_set_pending(gOutputStream, &err);
526 		
527 		if (err !is null)
528 		{
529 			throw new GException( new ErrorG(err) );
530 		}
531 		
532 		return p;
533 	}
534 	
535 	/**
536 	 * Clears the pending flag on stream.
537 	 */
538 	public void clearPending()
539 	{
540 		// void g_output_stream_clear_pending (GOutputStream *stream);
541 		g_output_stream_clear_pending(gOutputStream);
542 	}
543 }