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  = gio-gpollableutils.html
27  * outPack = gio
28  * outFile = PollableUtils
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = 
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- gobject.ObjectG
47  * 	- glib.ErrorG
48  * 	- glib.GException
49  * 	- glib.Source
50  * 	- gio.Cancellable
51  * 	- gio.InputStream
52  * 	- gio.OutputStream
53  * structWrap:
54  * 	- GCancellable* -> Cancellable
55  * 	- GInputStream* -> InputStream
56  * 	- GObject* -> ObjectG
57  * 	- GOutputStream* -> OutputStream
58  * 	- GSource* -> Source
59  * module aliases:
60  * local aliases:
61  * overrides:
62  */
63 
64 module gio.PollableUtils;
65 
66 public  import gtkc.giotypes;
67 
68 private import gtkc.gio;
69 private import glib.ConstructionException;
70 private import gobject.ObjectG;
71 
72 private import gobject.ObjectG;
73 private import glib.ErrorG;
74 private import glib.GException;
75 private import glib.Source;
76 private import gio.Cancellable;
77 private import gio.InputStream;
78 private import gio.OutputStream;
79 
80 
81 
82 /**
83  */
84 
85 /**
86  * Utility method for GPollableInputStream and GPollableOutputStream
87  * implementations. Creates a new GSource that expects a callback of
88  * type GPollableSourceFunc. The new source does not actually do
89  * anything on its own; use g_source_add_child_source() to add other
90  * sources to it to cause it to trigger.
91  * Since 2.28
92  * Params:
93  * pollableStream = the stream associated with the new source
94  * Returns: the new GSource. [transfer full]
95  */
96 public static Source pollableSourceNew(ObjectG pollableStream)
97 {
98 	// GSource * g_pollable_source_new (GObject *pollable_stream);
99 	auto p = g_pollable_source_new((pollableStream is null) ? null : pollableStream.getObjectGStruct());
100 	
101 	if(p is null)
102 	{
103 		return null;
104 	}
105 	
106 	return ObjectG.getDObject!(Source)(cast(GSource*) p);
107 }
108 
109 /**
110  * Utility method for GPollableInputStream and GPollableOutputStream
111  * implementations. Creates a new GSource, as with
112  * g_pollable_source_new(), but also attaching child_source (with a
113  * dummy callback), and cancellable, if they are non-NULL.
114  * Since 2.34
115  * Params:
116  * pollableStream = the stream associated with the
117  * new source. [type GObject]
118  * childSource = optional child source to attach. [allow-none]
119  * cancellable = optional GCancellable to attach. [allow-none]
120  * Returns: the new GSource. [transfer full]
121  */
122 public static Source pollableSourceNewFull(void* pollableStream, Source childSource, Cancellable cancellable)
123 {
124 	// GSource * g_pollable_source_new_full (gpointer pollable_stream,  GSource *child_source,  GCancellable *cancellable);
125 	auto p = g_pollable_source_new_full(pollableStream, (childSource is null) ? null : childSource.getSourceStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct());
126 	
127 	if(p is null)
128 	{
129 		return null;
130 	}
131 	
132 	return ObjectG.getDObject!(Source)(cast(GSource*) p);
133 }
134 
135 /**
136  * Tries to read from stream, as with g_input_stream_read() (if
137  * blocking is TRUE) or g_pollable_input_stream_read_nonblocking()
138  * (if blocking is FALSE). This can be used to more easily share
139  * code between blocking and non-blocking implementations of a method.
140  * If blocking is FALSE, then stream must be a
141  * GPollableInputStream for which g_pollable_input_stream_can_poll()
142  * returns TRUE, or else the behavior is undefined. If blocking is
143  * TRUE, then stream does not need to be a GPollableInputStream.
144  * Since 2.34
145  * Params:
146  * stream = a GInputStream
147  * buffer = a buffer to read data into
148  * blocking = whether to do blocking I/O
149  * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
150  * Returns: the number of bytes read, or -1 on error.
151  * Throws: GException on failure.
152  */
153 public static gssize pollableStreamRead(InputStream stream, void[] buffer, int blocking, Cancellable cancellable)
154 {
155 	// gssize g_pollable_stream_read (GInputStream *stream,  void *buffer,  gsize count,  gboolean blocking,  GCancellable *cancellable,  GError **error);
156 	GError* err = null;
157 	
158 	auto p = g_pollable_stream_read((stream is null) ? null : stream.getInputStreamStruct(), buffer.ptr, cast(int) buffer.length, blocking, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
159 	
160 	if (err !is null)
161 	{
162 		throw new GException( new ErrorG(err) );
163 	}
164 	
165 	return p;
166 }
167 
168 /**
169  * Tries to write to stream, as with g_output_stream_write() (if
170  * blocking is TRUE) or g_pollable_output_stream_write_nonblocking()
171  * (if blocking is FALSE). This can be used to more easily share
172  * code between blocking and non-blocking implementations of a method.
173  * If blocking is FALSE, then stream must be a
174  * GPollableOutputStream for which
175  * g_pollable_output_stream_can_poll() returns TRUE or else the
176  * behavior is undefined. If blocking is TRUE, then stream does not
177  * need to be a GPollableOutputStream.
178  * Since 2.34
179  * Params:
180  * stream = a GOutputStream.
181  * buffer = the buffer
182  * containing the data to write. [array length=count][element-type guint8]
183  * blocking = whether to do blocking I/O
184  * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
185  * Returns: the number of bytes written, or -1 on error.
186  * Throws: GException on failure.
187  */
188 public static gssize pollableStreamWrite(OutputStream stream, void[] buffer, int blocking, Cancellable cancellable)
189 {
190 	// gssize g_pollable_stream_write (GOutputStream *stream,  const void *buffer,  gsize count,  gboolean blocking,  GCancellable *cancellable,  GError **error);
191 	GError* err = null;
192 	
193 	auto p = g_pollable_stream_write((stream is null) ? null : stream.getOutputStreamStruct(), buffer.ptr, cast(int) buffer.length, blocking, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
194 	
195 	if (err !is null)
196 	{
197 		throw new GException( new ErrorG(err) );
198 	}
199 	
200 	return p;
201 }
202 
203 /**
204  * Tries to write count bytes to stream, as with
205  * g_output_stream_write_all(), but using g_pollable_stream_write()
206  * rather than g_output_stream_write().
207  * On a successful write of count bytes, TRUE is returned, and
208  * bytes_written is set to count.
209  * If there is an error during the operation (including
210  * G_IO_ERROR_WOULD_BLOCK in the non-blocking case), FALSE is
211  * returned and error is set to indicate the error status,
212  * bytes_written is updated to contain the number of bytes written
213  * into the stream before the error occurred.
214  * As with g_pollable_stream_write(), if blocking is FALSE, then
215  * stream must be a GPollableOutputStream for which
216  * g_pollable_output_stream_can_poll() returns TRUE or else the
217  * behavior is undefined. If blocking is TRUE, then stream does not
218  * need to be a GPollableOutputStream.
219  * Since 2.34
220  * Params:
221  * stream = a GOutputStream.
222  * buffer = the buffer
223  * containing the data to write. [array length=count][element-type guint8]
224  * blocking = whether to do blocking I/O
225  * bytesWritten = location to store the number of bytes that was
226  * written to the stream. [out]
227  * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
228  * Returns: TRUE on success, FALSE if there was an error
229  * Throws: GException on failure.
230  */
231 public static int pollableStreamWriteAll(OutputStream stream, void[] buffer, int blocking, out gsize bytesWritten, Cancellable cancellable)
232 {
233 	// gboolean g_pollable_stream_write_all (GOutputStream *stream,  const void *buffer,  gsize count,  gboolean blocking,  gsize *bytes_written,  GCancellable *cancellable,  GError **error);
234 	GError* err = null;
235 	
236 	auto p = g_pollable_stream_write_all((stream is null) ? null : stream.getOutputStreamStruct(), buffer.ptr, cast(int) buffer.length, blocking, &bytesWritten, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
237 	
238 	if (err !is null)
239 	{
240 		throw new GException( new ErrorG(err) );
241 	}
242 	
243 	return p;
244 }
245