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