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  = gstreamer-GstPoll.html
27  * outPack = gstreamer
28  * outFile = Poll
29  * strct   = GstPoll
30  * realStrct=
31  * ctorStrct=
32  * clss    = Poll
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gst_poll_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * structWrap:
47  * module aliases:
48  * local aliases:
49  * overrides:
50  */
51 
52 module gstreamer.Poll;
53 
54 public  import gstreamerc.gstreamertypes;
55 
56 private import gstreamerc.gstreamer;
57 private import glib.ConstructionException;
58 private import gobject.ObjectG;
59 
60 
61 
62 
63 /**
64  * A GstPoll keeps track of file descriptors much like fd_set (used with
65  * select()) or a struct pollfd array (used with poll()). Once created with
66  * gst_poll_new(), the set can be used to wait for file descriptors to be
67  * readable and/or writable. It is possible to make this wait be controlled
68  * by specifying TRUE for the controllable flag when creating the set (or
69  * later calling gst_poll_set_controllable()).
70  *
71  * New file descriptors are added to the set using gst_poll_add_fd(), and
72  * removed using gst_poll_remove_fd(). Controlling which file descriptors
73  * should be waited for to become readable and/or writable are done using
74  * gst_poll_fd_ctl_read() and gst_poll_fd_ctl_write().
75  *
76  * Use gst_poll_wait() to wait for the file descriptors to actually become
77  * readable and/or writable, or to timeout if no file descriptor is available
78  * in time. The wait can be controlled by calling gst_poll_restart() and
79  * gst_poll_set_flushing().
80  *
81  * Once the file descriptor set has been waited for, one can use
82  * gst_poll_fd_has_closed() to see if the file descriptor has been closed,
83  * gst_poll_fd_has_error() to see if it has generated an error,
84  * gst_poll_fd_can_read() to see if it is possible to read from the file
85  * descriptor, and gst_poll_fd_can_write() to see if it is possible to
86  * write to it.
87  */
88 public class Poll
89 {
90 	
91 	/** the main Gtk struct */
92 	protected GstPoll* gstPoll;
93 	
94 	
95 	/** Get the main Gtk struct */
96 	public GstPoll* getPollStruct()
97 	{
98 		return gstPoll;
99 	}
100 	
101 	
102 	/** the main Gtk struct as a void* */
103 	protected void* getStruct()
104 	{
105 		return cast(void*)gstPoll;
106 	}
107 	
108 	/**
109 	 * Sets our main struct and passes it to the parent class
110 	 */
111 	public this (GstPoll* gstPoll)
112 	{
113 		this.gstPoll = gstPoll;
114 	}
115 	
116 	/**
117 	 */
118 	
119 	/**
120 	 * Add a file descriptor to the file descriptor set.
121 	 * Params:
122 	 * fd = a file descriptor.
123 	 * Returns: TRUE if the file descriptor was successfully added to the set.
124 	 */
125 	public int addFd(GstPollFD* fd)
126 	{
127 		// gboolean gst_poll_add_fd (GstPoll *set,  GstPollFD *fd);
128 		return gst_poll_add_fd(gstPoll, fd);
129 	}
130 	
131 	/**
132 	 * Check if fd in set has data to be read.
133 	 * Params:
134 	 * fd = a file descriptor.
135 	 * Returns: TRUE if the descriptor has data to be read.
136 	 */
137 	public int fdCanRead(GstPollFD* fd)
138 	{
139 		// gboolean gst_poll_fd_can_read (const GstPoll *set,  GstPollFD *fd);
140 		return gst_poll_fd_can_read(gstPoll, fd);
141 	}
142 	
143 	/**
144 	 * Check if fd in set can be used for writing.
145 	 * Params:
146 	 * fd = a file descriptor.
147 	 * Returns: TRUE if the descriptor can be used for writing.
148 	 */
149 	public int fdCanWrite(GstPollFD* fd)
150 	{
151 		// gboolean gst_poll_fd_can_write (const GstPoll *set,  GstPollFD *fd);
152 		return gst_poll_fd_can_write(gstPoll, fd);
153 	}
154 	
155 	/**
156 	 * Control whether the descriptor fd in set will be monitored for
157 	 * readability.
158 	 * Params:
159 	 * fd = a file descriptor.
160 	 * active = a new status.
161 	 * Returns: TRUE if the descriptor was successfully updated.
162 	 */
163 	public int fdCtlRead(GstPollFD* fd, int active)
164 	{
165 		// gboolean gst_poll_fd_ctl_read (GstPoll *set,  GstPollFD *fd,  gboolean active);
166 		return gst_poll_fd_ctl_read(gstPoll, fd, active);
167 	}
168 	
169 	/**
170 	 * Control whether the descriptor fd in set will be monitored for
171 	 * writability.
172 	 * Params:
173 	 * fd = a file descriptor.
174 	 * active = a new status.
175 	 * Returns: TRUE if the descriptor was successfully updated.
176 	 */
177 	public int fdCtlWrite(GstPollFD* fd, int active)
178 	{
179 		// gboolean gst_poll_fd_ctl_write (GstPoll *set,  GstPollFD *fd,  gboolean active);
180 		return gst_poll_fd_ctl_write(gstPoll, fd, active);
181 	}
182 	
183 	/**
184 	 * Check if fd in set has closed the connection.
185 	 * Params:
186 	 * fd = a file descriptor.
187 	 * Returns: TRUE if the connection was closed.
188 	 */
189 	public int fdHasClosed(GstPollFD* fd)
190 	{
191 		// gboolean gst_poll_fd_has_closed (const GstPoll *set,  GstPollFD *fd);
192 		return gst_poll_fd_has_closed(gstPoll, fd);
193 	}
194 	
195 	/**
196 	 * Check if fd in set has an error.
197 	 * Params:
198 	 * fd = a file descriptor.
199 	 * Returns: TRUE if the descriptor has an error.
200 	 */
201 	public int fdHasError(GstPollFD* fd)
202 	{
203 		// gboolean gst_poll_fd_has_error (const GstPoll *set,  GstPollFD *fd);
204 		return gst_poll_fd_has_error(gstPoll, fd);
205 	}
206 	
207 	/**
208 	 * Mark fd as ignored so that the next call to gst_poll_wait() will yield
209 	 * the same result for fd as last time. This function must be called if no
210 	 * operation (read/write/recv/send/etc.) will be performed on fd before
211 	 * the next call to gst_poll_wait().
212 	 * The reason why this is needed is because the underlying implementation
213 	 * might not allow querying the fd more than once between calls to one of
214 	 * the re-enabling operations.
215 	 * Params:
216 	 * fd = a file descriptor.
217 	 */
218 	public void fdIgnored(GstPollFD* fd)
219 	{
220 		// void gst_poll_fd_ignored (GstPoll *set,  GstPollFD *fd);
221 		gst_poll_fd_ignored(gstPoll, fd);
222 	}
223 	
224 	/**
225 	 * Initializes fd. Alternatively you can initialize it with
226 	 * GST_POLL_FD_INIT.
227 	 * Params:
228 	 * fd = a GstPollFD
229 	 */
230 	public static void fdInit(GstPollFD* fd)
231 	{
232 		// void gst_poll_fd_init (GstPollFD *fd);
233 		gst_poll_fd_init(fd);
234 	}
235 	
236 	/**
237 	 * Free a file descriptor set.
238 	 */
239 	public void free()
240 	{
241 		// void gst_poll_free (GstPoll *set);
242 		gst_poll_free(gstPoll);
243 	}
244 	
245 	/**
246 	 * Create a new file descriptor set. If controllable, it
247 	 * is possible to restart or flush a call to gst_poll_wait() with
248 	 * gst_poll_restart() and gst_poll_set_flushing() respectively.
249 	 * Free-function: gst_poll_free
250 	 * Params:
251 	 * controllable = whether it should be possible to control a wait.
252 	 * Throws: ConstructionException GTK+ fails to create the object.
253 	 */
254 	public this (int controllable)
255 	{
256 		// GstPoll * gst_poll_new (gboolean controllable);
257 		auto p = gst_poll_new(controllable);
258 		if(p is null)
259 		{
260 			throw new ConstructionException("null returned by gst_poll_new(controllable)");
261 		}
262 		this(cast(GstPoll*) p);
263 	}
264 	
265 	/**
266 	 * Create a new poll object that can be used for scheduling cancellable
267 	 * timeouts.
268 	 * A timeout is performed with gst_poll_wait(). Multiple timeouts can be
269 	 * performed from different threads.
270 	 * Free-function: gst_poll_free
271 	 * Throws: ConstructionException GTK+ fails to create the object.
272 	 */
273 	public this ()
274 	{
275 		// GstPoll * gst_poll_new_timer (void);
276 		auto p = gst_poll_new_timer();
277 		if(p is null)
278 		{
279 			throw new ConstructionException("null returned by gst_poll_new_timer()");
280 		}
281 		this(cast(GstPoll*) p);
282 	}
283 	
284 	/**
285 	 * Get a GPollFD for the reading part of the control socket. This is useful when
286 	 * integrating with a GSource and GMainLoop.
287 	 * Params:
288 	 * fd = a GPollFD
289 	 */
290 	public void getReadGpollfd(GPollFD* fd)
291 	{
292 		// void gst_poll_get_read_gpollfd (GstPoll *set,  GPollFD *fd);
293 		gst_poll_get_read_gpollfd(gstPoll, fd);
294 	}
295 	
296 	/**
297 	 * Remove a file descriptor from the file descriptor set.
298 	 * Params:
299 	 * fd = a file descriptor.
300 	 * Returns: TRUE if the file descriptor was successfully removed from the set.
301 	 */
302 	public int removeFd(GstPollFD* fd)
303 	{
304 		// gboolean gst_poll_remove_fd (GstPoll *set,  GstPollFD *fd);
305 		return gst_poll_remove_fd(gstPoll, fd);
306 	}
307 	
308 	/**
309 	 * Restart any gst_poll_wait() that is in progress. This function is typically
310 	 * used after adding or removing descriptors to set.
311 	 * If set is not controllable, then this call will have no effect.
312 	 */
313 	public void restart()
314 	{
315 		// void gst_poll_restart (GstPoll *set);
316 		gst_poll_restart(gstPoll);
317 	}
318 	
319 	/**
320 	 * When controllable is TRUE, this function ensures that future calls to
321 	 * gst_poll_wait() will be affected by gst_poll_restart() and
322 	 * gst_poll_set_flushing().
323 	 * Params:
324 	 * set = a GstPoll.
325 	 * controllable = new controllable state.
326 	 * Returns: TRUE if the controllability of set could be updated.
327 	 */
328 	public int setControllable(int controllable)
329 	{
330 		// gboolean gst_poll_set_controllable (GstPoll *set,  gboolean controllable);
331 		return gst_poll_set_controllable(gstPoll, controllable);
332 	}
333 	
334 	/**
335 	 * When flushing is TRUE, this function ensures that current and future calls
336 	 * to gst_poll_wait() will return -1, with errno set to EBUSY.
337 	 * Unsetting the flushing state will restore normal operation of set.
338 	 * Params:
339 	 * set = a GstPoll.
340 	 * flushing = new flushing state.
341 	 */
342 	public void setFlushing(int flushing)
343 	{
344 		// void gst_poll_set_flushing (GstPoll *set,  gboolean flushing);
345 		gst_poll_set_flushing(gstPoll, flushing);
346 	}
347 	
348 	/**
349 	 * Wait for activity on the file descriptors in set. This function waits up to
350 	 * the specified timeout. A timeout of GST_CLOCK_TIME_NONE waits forever.
351 	 * For GstPoll objects created with gst_poll_new(), this function can only be
352 	 * called from a single thread at a time. If called from multiple threads,
353 	 * -1 will be returned with errno set to EPERM.
354 	 * This is not true for timer GstPoll objects created with
355 	 * gst_poll_new_timer(), where it is allowed to have multiple threads waiting
356 	 * simultaneously.
357 	 * Params:
358 	 * timeout = a timeout in nanoseconds.
359 	 * Returns: The number of GstPollFD in set that have activity or 0 when no activity was detected after timeout. If an error occurs, -1 is returned and errno is set.
360 	 */
361 	public int wait(GstClockTime timeout)
362 	{
363 		// gint gst_poll_wait (GstPoll *set,  GstClockTime timeout);
364 		return gst_poll_wait(gstPoll, timeout);
365 	}
366 	
367 	/**
368 	 * Read a byte from the control socket of the controllable set.
369 	 * This function is mostly useful for timer GstPoll objects created with
370 	 * gst_poll_new_timer().
371 	 * Returns: TRUE on success. FALSE when set is not controllable or when there was no byte to read.
372 	 */
373 	public int readControl()
374 	{
375 		// gboolean gst_poll_read_control (GstPoll *set);
376 		return gst_poll_read_control(gstPoll);
377 	}
378 	
379 	/**
380 	 * Write a byte to the control socket of the controllable set.
381 	 * This function is mostly useful for timer GstPoll objects created with
382 	 * gst_poll_new_timer().
383 	 * It will make any current and future gst_poll_wait() function return with
384 	 * 1, meaning the control socket is set. After an equal amount of calls to
385 	 * gst_poll_read_control() have been performed, calls to gst_poll_wait() will
386 	 * block again until their timeout expired.
387 	 * Returns: TRUE on success. FALSE when set is not controllable or when the byte could not be written.
388 	 */
389 	public int writeControl()
390 	{
391 		// gboolean gst_poll_write_control (GstPoll *set);
392 		return gst_poll_write_control(gstPoll);
393 	}
394 }