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