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