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 glib.IOChannel; 26 27 private import glib.ConstructionException; 28 private import glib.ErrorG; 29 private import glib.GException; 30 private import glib.Source; 31 private import glib.Str; 32 private import glib.StringG; 33 private import gtkc.glib; 34 public import gtkc.glibtypes; 35 36 37 /** 38 * A data structure representing an IO Channel. The fields should be 39 * considered private and should only be accessed with the following 40 * functions. 41 */ 42 public class IOChannel 43 { 44 /** the main Gtk struct */ 45 protected GIOChannel* gIOChannel; 46 47 /** Get the main Gtk struct */ 48 public GIOChannel* getIOChannelStruct() 49 { 50 return gIOChannel; 51 } 52 53 /** the main Gtk struct as a void* */ 54 protected void* getStruct() 55 { 56 return cast(void*)gIOChannel; 57 } 58 59 /** 60 * Sets our main struct and passes it to the parent class. 61 */ 62 public this (GIOChannel* gIOChannel) 63 { 64 this.gIOChannel = gIOChannel; 65 } 66 67 68 /** 69 * Open a file @filename as a #GIOChannel using mode @mode. This 70 * channel will be closed when the last reference to it is dropped, 71 * so there is no need to call g_io_channel_close() (though doing 72 * so will not cause problems, as long as no attempt is made to 73 * access the channel after it is closed). 74 * 75 * Params: 76 * filename = A string containing the name of a file 77 * mode = One of "r", "w", "a", "r+", "w+", "a+". These have 78 * the same meaning as in fopen() 79 * 80 * Return: A #GIOChannel on success, %NULL on failure. 81 * 82 * Throws: GException on failure. 83 * Throws: ConstructionException GTK+ fails to create the object. 84 */ 85 public this(string filename, string mode) 86 { 87 GError* err = null; 88 89 auto p = g_io_channel_new_file(Str.toStringz(filename), Str.toStringz(mode), &err); 90 91 if (err !is null) 92 { 93 throw new GException( new ErrorG(err) ); 94 } 95 96 if(p is null) 97 { 98 throw new ConstructionException("null returned by new_file"); 99 } 100 101 this(cast(GIOChannel*) p); 102 } 103 104 /** 105 * Creates a new #GIOChannel given a file descriptor. On UNIX systems 106 * this works for plain files, pipes, and sockets. 107 * 108 * The returned #GIOChannel has a reference count of 1. 109 * 110 * The default encoding for #GIOChannel is UTF-8. If your application 111 * is reading output from a command using via pipe, you may need to set 112 * the encoding to the encoding of the current locale (see 113 * g_get_charset()) with the g_io_channel_set_encoding() function. 114 * 115 * If you want to read raw binary data without interpretation, then 116 * call the g_io_channel_set_encoding() function with %NULL for the 117 * encoding argument. 118 * 119 * This function is available in GLib on Windows, too, but you should 120 * avoid using it on Windows. The domain of file descriptors and 121 * sockets overlap. There is no way for GLib to know which one you mean 122 * in case the argument you pass to this function happens to be both a 123 * valid file descriptor and socket. If that happens a warning is 124 * issued, and GLib assumes that it is the file descriptor you mean. 125 * 126 * Params: 127 * fd = a file descriptor. 128 * 129 * Return: a new #GIOChannel. 130 * 131 * Throws: ConstructionException GTK+ fails to create the object. 132 */ 133 public this(int fd) 134 { 135 auto p = g_io_channel_unix_new(fd); 136 137 if(p is null) 138 { 139 throw new ConstructionException("null returned by unix_new"); 140 } 141 142 this(cast(GIOChannel*) p); 143 } 144 145 /** 146 * Close an IO channel. Any pending data to be written will be 147 * flushed, ignoring errors. The channel will not be freed until the 148 * last reference is dropped using g_io_channel_unref(). 149 * 150 * Deprecated: Use g_io_channel_shutdown() instead. 151 */ 152 public void close() 153 { 154 g_io_channel_close(gIOChannel); 155 } 156 157 /** 158 * Flushes the write buffer for the GIOChannel. 159 * 160 * Return: the status of the operation: One of 161 * #G_IO_STATUS_NORMAL, #G_IO_STATUS_AGAIN, or 162 * #G_IO_STATUS_ERROR. 163 * 164 * Throws: GException on failure. 165 */ 166 public GIOStatus flush() 167 { 168 GError* err = null; 169 170 auto p = g_io_channel_flush(gIOChannel, &err); 171 172 if (err !is null) 173 { 174 throw new GException( new ErrorG(err) ); 175 } 176 177 return p; 178 } 179 180 /** 181 * This function returns a #GIOCondition depending on whether there 182 * is data to be read/space to write data in the internal buffers in 183 * the #GIOChannel. Only the flags %G_IO_IN and %G_IO_OUT may be set. 184 * 185 * Return: A #GIOCondition 186 */ 187 public GIOCondition getBufferCondition() 188 { 189 return g_io_channel_get_buffer_condition(gIOChannel); 190 } 191 192 /** 193 * Gets the buffer size. 194 * 195 * Return: the size of the buffer. 196 */ 197 public size_t getBufferSize() 198 { 199 return g_io_channel_get_buffer_size(gIOChannel); 200 } 201 202 /** 203 * Returns whether @channel is buffered. 204 * 205 * Return: %TRUE if the @channel is buffered. 206 */ 207 public bool getBuffered() 208 { 209 return g_io_channel_get_buffered(gIOChannel) != 0; 210 } 211 212 /** 213 * Returns whether the file/socket/whatever associated with @channel 214 * will be closed when @channel receives its final unref and is 215 * destroyed. The default value of this is %TRUE for channels created 216 * by g_io_channel_new_file (), and %FALSE for all other channels. 217 * 218 * Return: Whether the channel will be closed on the final unref of 219 * the GIOChannel data structure. 220 */ 221 public bool getCloseOnUnref() 222 { 223 return g_io_channel_get_close_on_unref(gIOChannel) != 0; 224 } 225 226 /** 227 * Gets the encoding for the input/output of the channel. 228 * The internal encoding is always UTF-8. The encoding %NULL 229 * makes the channel safe for binary data. 230 * 231 * Return: A string containing the encoding, this string is 232 * owned by GLib and must not be freed. 233 */ 234 public string getEncoding() 235 { 236 return Str.toString(g_io_channel_get_encoding(gIOChannel)); 237 } 238 239 /** 240 * Gets the current flags for a #GIOChannel, including read-only 241 * flags such as %G_IO_FLAG_IS_READABLE. 242 * 243 * The values of the flags %G_IO_FLAG_IS_READABLE and %G_IO_FLAG_IS_WRITABLE 244 * are cached for internal use by the channel when it is created. 245 * If they should change at some later point (e.g. partial shutdown 246 * of a socket with the UNIX shutdown() function), the user 247 * should immediately call g_io_channel_get_flags() to update 248 * the internal values of these flags. 249 * 250 * Return: the flags which are set on the channel 251 */ 252 public GIOFlags getFlags() 253 { 254 return g_io_channel_get_flags(gIOChannel); 255 } 256 257 /** 258 * This returns the string that #GIOChannel uses to determine 259 * where in the file a line break occurs. A value of %NULL 260 * indicates autodetection. 261 * 262 * Params: 263 * length = a location to return the length of the line terminator 264 * 265 * Return: The line termination string. This value 266 * is owned by GLib and must not be freed. 267 */ 268 public string getLineTerm(int* length) 269 { 270 return Str.toString(g_io_channel_get_line_term(gIOChannel, length)); 271 } 272 273 /** 274 * Initializes a #GIOChannel struct. 275 * 276 * This is called by each of the above functions when creating a 277 * #GIOChannel, and so is not often needed by the application 278 * programmer (unless you are creating a new type of #GIOChannel). 279 */ 280 public void init() 281 { 282 g_io_channel_init(gIOChannel); 283 } 284 285 /** 286 * Reads data from a #GIOChannel. 287 * 288 * Deprecated: Use g_io_channel_read_chars() instead. 289 * 290 * Params: 291 * buf = a buffer to read the data into (which should be at least 292 * count bytes long) 293 * count = the number of bytes to read from the #GIOChannel 294 * bytesRead = returns the number of bytes actually read 295 * 296 * Return: %G_IO_ERROR_NONE if the operation was successful. 297 */ 298 public GIOError read(string buf, size_t count, size_t* bytesRead) 299 { 300 return g_io_channel_read(gIOChannel, Str.toStringz(buf), count, bytesRead); 301 } 302 303 /** 304 * Replacement for g_io_channel_read() with the new API. 305 * 306 * Params: 307 * buf = a buffer to read data into 308 * count = the size of the buffer. Note that the buffer may not be 309 * complelely filled even if there is data in the buffer if the 310 * remaining data is not a complete character. 311 * bytesRead = The number of bytes read. This may be 312 * zero even on success if count < 6 and the channel's encoding 313 * is non-%NULL. This indicates that the next UTF-8 character is 314 * too wide for the buffer. 315 * 316 * Return: the status of the operation. 317 * 318 * Throws: GException on failure. 319 */ 320 public GIOStatus readChars(out char[] buf, out size_t bytesRead) 321 { 322 GError* err = null; 323 324 auto p = g_io_channel_read_chars(gIOChannel, buf.ptr, cast(size_t)buf.length, &bytesRead, &err); 325 326 if (err !is null) 327 { 328 throw new GException( new ErrorG(err) ); 329 } 330 331 return p; 332 } 333 334 /** 335 * Reads a line, including the terminating character(s), 336 * from a #GIOChannel into a newly-allocated string. 337 * @str_return will contain allocated memory if the return 338 * is %G_IO_STATUS_NORMAL. 339 * 340 * Params: 341 * strReturn = The line read from the #GIOChannel, including the 342 * line terminator. This data should be freed with g_free() 343 * when no longer needed. This is a nul-terminated string. 344 * If a @length of zero is returned, this will be %NULL instead. 345 * length = location to store length of the read data, or %NULL 346 * terminatorPos = location to store position of line terminator, or %NULL 347 * 348 * Return: the status of the operation. 349 * 350 * Throws: GException on failure. 351 */ 352 public GIOStatus readLine(out string strReturn, out size_t terminatorPos) 353 { 354 char* outstrReturn = null; 355 size_t length; 356 GError* err = null; 357 358 auto p = g_io_channel_read_line(gIOChannel, &outstrReturn, &length, &terminatorPos, &err); 359 360 if (err !is null) 361 { 362 throw new GException( new ErrorG(err) ); 363 } 364 365 strReturn = Str.toString(outstrReturn, length); 366 367 return p; 368 } 369 370 /** 371 * Reads a line from a #GIOChannel, using a #GString as a buffer. 372 * 373 * Params: 374 * buffer = a #GString into which the line will be written. 375 * If @buffer already contains data, the old data will 376 * be overwritten. 377 * terminatorPos = location to store position of line terminator, or %NULL 378 * 379 * Return: the status of the operation. 380 * 381 * Throws: GException on failure. 382 */ 383 public GIOStatus readLineString(StringG buffer, out size_t terminatorPos) 384 { 385 GError* err = null; 386 387 auto p = g_io_channel_read_line_string(gIOChannel, (buffer is null) ? null : buffer.getStringGStruct(), &terminatorPos, &err); 388 389 if (err !is null) 390 { 391 throw new GException( new ErrorG(err) ); 392 } 393 394 return p; 395 } 396 397 /** 398 * Reads all the remaining data from the file. 399 * 400 * Params: 401 * strReturn = Location to 402 * store a pointer to a string holding the remaining data in the 403 * #GIOChannel. This data should be freed with g_free() when no 404 * longer needed. This data is terminated by an extra nul 405 * character, but there may be other nuls in the intervening data. 406 * length = location to store length of the data 407 * 408 * Return: %G_IO_STATUS_NORMAL on success. 409 * This function never returns %G_IO_STATUS_EOF. 410 * 411 * Throws: GException on failure. 412 */ 413 public GIOStatus readToEnd(out string strReturn) 414 { 415 char* outstrReturn = null; 416 size_t length; 417 GError* err = null; 418 419 auto p = g_io_channel_read_to_end(gIOChannel, &outstrReturn, &length, &err); 420 421 if (err !is null) 422 { 423 throw new GException( new ErrorG(err) ); 424 } 425 426 strReturn = Str.toString(outstrReturn, length); 427 428 return p; 429 } 430 431 /** 432 * Reads a Unicode character from @channel. 433 * This function cannot be called on a channel with %NULL encoding. 434 * 435 * Params: 436 * thechar = a location to return a character 437 * 438 * Return: a #GIOStatus 439 * 440 * Throws: GException on failure. 441 */ 442 public GIOStatus readUnichar(out dchar thechar) 443 { 444 GError* err = null; 445 446 auto p = g_io_channel_read_unichar(gIOChannel, &thechar, &err); 447 448 if (err !is null) 449 { 450 throw new GException( new ErrorG(err) ); 451 } 452 453 return p; 454 } 455 456 /** 457 * Increments the reference count of a #GIOChannel. 458 * 459 * Return: the @channel that was passed in (since 2.6) 460 */ 461 public IOChannel doref() 462 { 463 auto p = g_io_channel_ref(gIOChannel); 464 465 if(p is null) 466 { 467 return null; 468 } 469 470 return new IOChannel(cast(GIOChannel*) p); 471 } 472 473 /** 474 * Sets the current position in the #GIOChannel, similar to the standard 475 * library function fseek(). 476 * 477 * Deprecated: Use g_io_channel_seek_position() instead. 478 * 479 * Params: 480 * offset = an offset, in bytes, which is added to the position specified 481 * by @type 482 * type = the position in the file, which can be %G_SEEK_CUR (the current 483 * position), %G_SEEK_SET (the start of the file), or %G_SEEK_END 484 * (the end of the file) 485 * 486 * Return: %G_IO_ERROR_NONE if the operation was successful. 487 */ 488 public GIOError seek(long offset, GSeekType type) 489 { 490 return g_io_channel_seek(gIOChannel, offset, type); 491 } 492 493 /** 494 * Replacement for g_io_channel_seek() with the new API. 495 * 496 * Params: 497 * offset = The offset in bytes from the position specified by @type 498 * type = a #GSeekType. The type %G_SEEK_CUR is only allowed in those 499 * cases where a call to g_io_channel_set_encoding () 500 * is allowed. See the documentation for 501 * g_io_channel_set_encoding () for details. 502 * 503 * Return: the status of the operation. 504 * 505 * Throws: GException on failure. 506 */ 507 public GIOStatus seekPosition(long offset, GSeekType type) 508 { 509 GError* err = null; 510 511 auto p = g_io_channel_seek_position(gIOChannel, offset, type, &err); 512 513 if (err !is null) 514 { 515 throw new GException( new ErrorG(err) ); 516 } 517 518 return p; 519 } 520 521 /** 522 * Sets the buffer size. 523 * 524 * Params: 525 * size = the size of the buffer, or 0 to let GLib pick a good size 526 */ 527 public void setBufferSize(size_t size) 528 { 529 g_io_channel_set_buffer_size(gIOChannel, size); 530 } 531 532 /** 533 * The buffering state can only be set if the channel's encoding 534 * is %NULL. For any other encoding, the channel must be buffered. 535 * 536 * A buffered channel can only be set unbuffered if the channel's 537 * internal buffers have been flushed. Newly created channels or 538 * channels which have returned %G_IO_STATUS_EOF 539 * not require such a flush. For write-only channels, a call to 540 * g_io_channel_flush () is sufficient. For all other channels, 541 * the buffers may be flushed by a call to g_io_channel_seek_position (). 542 * This includes the possibility of seeking with seek type %G_SEEK_CUR 543 * and an offset of zero. Note that this means that socket-based 544 * channels cannot be set unbuffered once they have had data 545 * read from them. 546 * 547 * On unbuffered channels, it is safe to mix read and write 548 * calls from the new and old APIs, if this is necessary for 549 * maintaining old code. 550 * 551 * The default state of the channel is buffered. 552 * 553 * Params: 554 * buffered = whether to set the channel buffered or unbuffered 555 */ 556 public void setBuffered(bool buffered) 557 { 558 g_io_channel_set_buffered(gIOChannel, buffered); 559 } 560 561 /** 562 * Setting this flag to %TRUE for a channel you have already closed 563 * can cause problems. 564 * 565 * Params: 566 * doClose = Whether to close the channel on the final unref of 567 * the GIOChannel data structure. The default value of 568 * this is %TRUE for channels created by g_io_channel_new_file (), 569 * and %FALSE for all other channels. 570 */ 571 public void setCloseOnUnref(bool doClose) 572 { 573 g_io_channel_set_close_on_unref(gIOChannel, doClose); 574 } 575 576 /** 577 * Sets the encoding for the input/output of the channel. 578 * The internal encoding is always UTF-8. The default encoding 579 * for the external file is UTF-8. 580 * 581 * The encoding %NULL is safe to use with binary data. 582 * 583 * The encoding can only be set if one of the following conditions 584 * is true: 585 * 586 * - The channel was just created, and has not been written to or read from yet. 587 * 588 * - The channel is write-only. 589 * 590 * - The channel is a file, and the file pointer was just repositioned 591 * by a call to g_io_channel_seek_position(). (This flushes all the 592 * internal buffers.) 593 * 594 * - The current encoding is %NULL or UTF-8. 595 * 596 * - One of the (new API) read functions has just returned %G_IO_STATUS_EOF 597 * (or, in the case of g_io_channel_read_to_end(), %G_IO_STATUS_NORMAL). 598 * 599 * - One of the functions g_io_channel_read_chars() or 600 * g_io_channel_read_unichar() has returned %G_IO_STATUS_AGAIN or 601 * %G_IO_STATUS_ERROR. This may be useful in the case of 602 * %G_CONVERT_ERROR_ILLEGAL_SEQUENCE. 603 * Returning one of these statuses from g_io_channel_read_line(), 604 * g_io_channel_read_line_string(), or g_io_channel_read_to_end() 605 * does not guarantee that the encoding can be changed. 606 * 607 * Channels which do not meet one of the above conditions cannot call 608 * g_io_channel_seek_position() with an offset of %G_SEEK_CUR, and, if 609 * they are "seekable", cannot call g_io_channel_write_chars() after 610 * calling one of the API "read" functions. 611 * 612 * Params: 613 * encoding = the encoding type 614 * 615 * Return: %G_IO_STATUS_NORMAL if the encoding was successfully set 616 * 617 * Throws: GException on failure. 618 */ 619 public GIOStatus setEncoding(string encoding) 620 { 621 GError* err = null; 622 623 auto p = g_io_channel_set_encoding(gIOChannel, Str.toStringz(encoding), &err); 624 625 if (err !is null) 626 { 627 throw new GException( new ErrorG(err) ); 628 } 629 630 return p; 631 } 632 633 /** 634 * Sets the (writeable) flags in @channel to (@flags & %G_IO_FLAG_SET_MASK). 635 * 636 * Params: 637 * flags = the flags to set on the IO channel 638 * 639 * Return: the status of the operation. 640 * 641 * Throws: GException on failure. 642 */ 643 public GIOStatus setFlags(GIOFlags flags) 644 { 645 GError* err = null; 646 647 auto p = g_io_channel_set_flags(gIOChannel, flags, &err); 648 649 if (err !is null) 650 { 651 throw new GException( new ErrorG(err) ); 652 } 653 654 return p; 655 } 656 657 /** 658 * This sets the string that #GIOChannel uses to determine 659 * where in the file a line break occurs. 660 * 661 * Params: 662 * lineTerm = The line termination string. Use %NULL for 663 * autodetect. Autodetection breaks on "\n", "\r\n", "\r", "\0", 664 * and the Unicode paragraph separator. Autodetection should not be 665 * used for anything other than file-based channels. 666 * length = The length of the termination string. If -1 is passed, the 667 * string is assumed to be nul-terminated. This option allows 668 * termination strings with embedded nuls. 669 */ 670 public void setLineTerm(string lineTerm, int length) 671 { 672 g_io_channel_set_line_term(gIOChannel, Str.toStringz(lineTerm), length); 673 } 674 675 /** 676 * Close an IO channel. Any pending data to be written will be 677 * flushed if @flush is %TRUE. The channel will not be freed until the 678 * last reference is dropped using g_io_channel_unref(). 679 * 680 * Params: 681 * flush = if %TRUE, flush pending 682 * 683 * Return: the status of the operation. 684 * 685 * Throws: GException on failure. 686 */ 687 public GIOStatus shutdown(bool flush) 688 { 689 GError* err = null; 690 691 auto p = g_io_channel_shutdown(gIOChannel, flush, &err); 692 693 if (err !is null) 694 { 695 throw new GException( new ErrorG(err) ); 696 } 697 698 return p; 699 } 700 701 /** 702 * Returns the file descriptor of the #GIOChannel. 703 * 704 * On Windows this function returns the file descriptor or socket of 705 * the #GIOChannel. 706 * 707 * Return: the file descriptor of the #GIOChannel. 708 */ 709 public int unixGetFd() 710 { 711 return g_io_channel_unix_get_fd(gIOChannel); 712 } 713 714 /** 715 * Decrements the reference count of a #GIOChannel. 716 */ 717 public void unref() 718 { 719 g_io_channel_unref(gIOChannel); 720 } 721 722 /** 723 * Writes data to a #GIOChannel. 724 * 725 * Deprecated: Use g_io_channel_write_chars() instead. 726 * 727 * Params: 728 * buf = the buffer containing the data to write 729 * count = the number of bytes to write 730 * bytesWritten = the number of bytes actually written 731 * 732 * Return: %G_IO_ERROR_NONE if the operation was successful. 733 */ 734 public GIOError write(string buf, size_t count, size_t* bytesWritten) 735 { 736 return g_io_channel_write(gIOChannel, Str.toStringz(buf), count, bytesWritten); 737 } 738 739 /** 740 * Replacement for g_io_channel_write() with the new API. 741 * 742 * On seekable channels with encodings other than %NULL or UTF-8, generic 743 * mixing of reading and writing is not allowed. A call to g_io_channel_write_chars () 744 * may only be made on a channel from which data has been read in the 745 * cases described in the documentation for g_io_channel_set_encoding (). 746 * 747 * Params: 748 * buf = a buffer to write data from 749 * count = the size of the buffer. If -1, the buffer 750 * is taken to be a nul-terminated string. 751 * bytesWritten = The number of bytes written. This can be nonzero 752 * even if the return value is not %G_IO_STATUS_NORMAL. 753 * If the return value is %G_IO_STATUS_NORMAL and the 754 * channel is blocking, this will always be equal 755 * to @count if @count >= 0. 756 * 757 * Return: the status of the operation. 758 * 759 * Throws: GException on failure. 760 */ 761 public GIOStatus writeChars(string buf, out size_t bytesWritten) 762 { 763 GError* err = null; 764 765 auto p = g_io_channel_write_chars(gIOChannel, Str.toStringz(buf), cast(ptrdiff_t)buf.length, &bytesWritten, &err); 766 767 if (err !is null) 768 { 769 throw new GException( new ErrorG(err) ); 770 } 771 772 return p; 773 } 774 775 /** 776 * Writes a Unicode character to @channel. 777 * This function cannot be called on a channel with %NULL encoding. 778 * 779 * Params: 780 * thechar = a character 781 * 782 * Return: a #GIOStatus 783 * 784 * Throws: GException on failure. 785 */ 786 public GIOStatus writeUnichar(dchar thechar) 787 { 788 GError* err = null; 789 790 auto p = g_io_channel_write_unichar(gIOChannel, thechar, &err); 791 792 if (err !is null) 793 { 794 throw new GException( new ErrorG(err) ); 795 } 796 797 return p; 798 } 799 800 /** 801 * Converts an `errno` error number to a #GIOChannelError. 802 * 803 * Params: 804 * en = an `errno` error number, e.g. `EINVAL` 805 * 806 * Return: a #GIOChannelError error number, e.g. 807 * %G_IO_CHANNEL_ERROR_INVAL. 808 */ 809 public static GIOChannelError errorFromErrno(int en) 810 { 811 return g_io_channel_error_from_errno(en); 812 } 813 814 /** */ 815 public static GQuark errorQuark() 816 { 817 return g_io_channel_error_quark(); 818 } 819 820 /** 821 * Adds the #GIOChannel into the default main loop context 822 * with the default priority. 823 * 824 * Params: 825 * channel = a #GIOChannel 826 * condition = the condition to watch for 827 * func = the function to call when the condition is satisfied 828 * userData = user data to pass to @func 829 * 830 * Return: the event source id 831 */ 832 public static uint ioAddWatch(IOChannel channel, GIOCondition condition, GIOFunc func, void* userData) 833 { 834 return g_io_add_watch((channel is null) ? null : channel.getIOChannelStruct(), condition, func, userData); 835 } 836 837 /** 838 * Adds the #GIOChannel into the default main loop context 839 * with the given priority. 840 * 841 * This internally creates a main loop source using g_io_create_watch() 842 * and attaches it to the main loop context with g_source_attach(). 843 * You can do these steps manually if you need greater control. 844 * 845 * Params: 846 * channel = a #GIOChannel 847 * priority = the priority of the #GIOChannel source 848 * condition = the condition to watch for 849 * func = the function to call when the condition is satisfied 850 * userData = user data to pass to @func 851 * notify = the function to call when the source is removed 852 * 853 * Return: the event source id 854 */ 855 public static uint ioAddWatchFull(IOChannel channel, int priority, GIOCondition condition, GIOFunc func, void* userData, GDestroyNotify notify) 856 { 857 return g_io_add_watch_full((channel is null) ? null : channel.getIOChannelStruct(), priority, condition, func, userData, notify); 858 } 859 860 /** 861 * Creates a #GSource that's dispatched when @condition is met for the 862 * given @channel. For example, if condition is #G_IO_IN, the source will 863 * be dispatched when there's data available for reading. 864 * 865 * g_io_add_watch() is a simpler interface to this same functionality, for 866 * the case where you want to add the source to the default main loop context 867 * at the default priority. 868 * 869 * On Windows, polling a #GSource created to watch a channel for a socket 870 * puts the socket in non-blocking mode. This is a side-effect of the 871 * implementation and unavoidable. 872 * 873 * Params: 874 * channel = a #GIOChannel to watch 875 * condition = conditions to watch for 876 * 877 * Return: a new #GSource 878 */ 879 public static Source ioCreateWatch(IOChannel channel, GIOCondition condition) 880 { 881 auto p = g_io_create_watch((channel is null) ? null : channel.getIOChannelStruct(), condition); 882 883 if(p is null) 884 { 885 return null; 886 } 887 888 return new Source(cast(GSource*) p); 889 } 890 }