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