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