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