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  = GPollableInputStream.html
27  * outPack = gio
28  * outFile = PollableInputStreamT
29  * strct   = GPollableInputStream
30  * realStrct=
31  * ctorStrct=
32  * clss    = PollableInputStreamT
33  * interf  = PollableInputStreamIF
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * 	- TStruct
38  * extend  = 
39  * implements:
40  * prefixes:
41  * 	- g_pollable_input_stream_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- gobject.ObjectG
48  * 	- glib.ErrorG
49  * 	- glib.GException
50  * 	- glib.Source
51  * 	- gio.Cancellable
52  * structWrap:
53  * 	- GCancellable* -> Cancellable
54  * 	- GObject* -> ObjectG
55  * 	- GSource* -> Source
56  * module aliases:
57  * local aliases:
58  * overrides:
59  */
60 
61 module gio.PollableInputStreamT;
62 
63 public  import gtkc.giotypes;
64 
65 public import gtkc.gio;
66 public import glib.ConstructionException;
67 public import gobject.ObjectG;
68 
69 
70 public import gobject.ObjectG;
71 public import glib.ErrorG;
72 public import glib.GException;
73 public import glib.Source;
74 public import gio.Cancellable;
75 
76 
77 
78 
79 /**
80  * GPollableInputStream is implemented by GInputStreams that
81  * can be polled for readiness to read. This can be used when
82  * interfacing with a non-GIO API that expects
83  * UNIX-file-descriptor-style asynchronous I/O rather than GIO-style.
84  */
85 public template PollableInputStreamT(TStruct)
86 {
87 	
88 	/** the main Gtk struct */
89 	protected GPollableInputStream* gPollableInputStream;
90 	
91 	
92 	public GPollableInputStream* getPollableInputStreamTStruct()
93 	{
94 		return cast(GPollableInputStream*)getStruct();
95 	}
96 	
97 	
98 	/**
99 	 */
100 	
101 	/**
102 	 * Checks if stream is actually pollable. Some classes may implement
103 	 * GPollableInputStream but have only certain instances of that class
104 	 * be pollable. If this method returns FALSE, then the behavior of
105 	 * other GPollableInputStream methods is undefined.
106 	 * For any given stream, the value returned by this method is constant;
107 	 * a stream cannot switch from pollable to non-pollable or vice versa.
108 	 * Since 2.28
109 	 * Returns: TRUE if stream is pollable, FALSE if not.
110 	 */
111 	public int canPoll()
112 	{
113 		// gboolean g_pollable_input_stream_can_poll (GPollableInputStream *stream);
114 		return g_pollable_input_stream_can_poll(getPollableInputStreamTStruct());
115 	}
116 	
117 	/**
118 	 * Checks if stream can be read.
119 	 * Note that some stream types may not be able to implement this 100%
120 	 * reliably, and it is possible that a call to g_input_stream_read()
121 	 * after this returns TRUE would still block. To guarantee
122 	 * non-blocking behavior, you should always use
123 	 * g_pollable_input_stream_read_nonblocking(), which will return a
124 	 * G_IO_ERROR_WOULD_BLOCK error rather than blocking.
125 	 * Since 2.28
126 	 * Returns: TRUE if stream is readable, FALSE if not. If an error has occurred on stream, this will result in g_pollable_input_stream_is_readable() returning TRUE, and the next attempt to read will return the error.
127 	 */
128 	public int isReadable()
129 	{
130 		// gboolean g_pollable_input_stream_is_readable (GPollableInputStream *stream);
131 		return g_pollable_input_stream_is_readable(getPollableInputStreamTStruct());
132 	}
133 	
134 	/**
135 	 * Creates a GSource that triggers when stream can be read, or
136 	 * cancellable is triggered or an error occurs. The callback on the
137 	 * source is of the GPollableSourceFunc type.
138 	 * As with g_pollable_input_stream_is_readable(), it is possible that
139 	 * the stream may not actually be readable even after the source
140 	 * triggers, so you should use g_pollable_input_stream_read_nonblocking()
141 	 * rather than g_input_stream_read() from the callback.
142 	 * Since 2.28
143 	 * Params:
144 	 * cancellable = a GCancellable, or NULL. [allow-none]
145 	 * Returns: a new GSource. [transfer full]
146 	 */
147 	public Source createSource(Cancellable cancellable)
148 	{
149 		// GSource * g_pollable_input_stream_create_source  (GPollableInputStream *stream,  GCancellable *cancellable);
150 		auto p = g_pollable_input_stream_create_source(getPollableInputStreamTStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct());
151 		
152 		if(p is null)
153 		{
154 			return null;
155 		}
156 		
157 		return ObjectG.getDObject!(Source)(cast(GSource*) p);
158 	}
159 	
160 	/**
161 	 * Attempts to read up to count bytes from stream into buffer, as
162 	 * with g_input_stream_read(). If stream is not currently readable,
163 	 * this will immediately return G_IO_ERROR_WOULD_BLOCK, and you can
164 	 * use g_pollable_input_stream_create_source() to create a GSource
165 	 * that will be triggered when stream is readable.
166 	 * Note that since this method never blocks, you cannot actually
167 	 * use cancellable to cancel it. However, it will return an error
168 	 * if cancellable has already been cancelled when you call, which
169 	 * may happen if you call this method after a source triggers due
170 	 * to having been cancelled.
171 	 * Virtual: read_nonblocking
172 	 * Params:
173 	 * buffer = a buffer to read data into (which should be at least count
174 	 * bytes long).
175 	 * count = the number of bytes you want to read
176 	 * cancellable = a GCancellable, or NULL. [allow-none]
177 	 * Returns: the number of bytes read, or -1 on error (including G_IO_ERROR_WOULD_BLOCK).
178 	 * Throws: GException on failure.
179 	 */
180 	public gssize readNonblocking(void[] buffer, gsize count, Cancellable cancellable)
181 	{
182 		// gssize g_pollable_input_stream_read_nonblocking  (GPollableInputStream *stream,  void *buffer,  gsize count,  GCancellable *cancellable,  GError **error);
183 		GError* err = null;
184 		
185 		auto p = g_pollable_input_stream_read_nonblocking(getPollableInputStreamTStruct(), buffer.ptr, count, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
186 		
187 		if (err !is null)
188 		{
189 			throw new GException( new ErrorG(err) );
190 		}
191 		
192 		return p;
193 	}
194 }