alternative to assert
[gtkD.git] / gtkD / src / glib / IOChannel.d
blob8894890f899ccada8fb3a69d7ae52260afe0817b
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-IO-Channels.html
26 * outPack = glib
27 * outFile = IOChannel
28 * strct = GIOChannel
29 * realStrct=
30 * ctorStrct=
31 * clss = IOChannel
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_io_channel_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.ErrorG
45 * - glib.StringG
46 * - glib.Source
47 * - glib.Dataset
48 * - glib.Str
49 * structWrap:
50 * - GIOChannel* -> IOChannel
51 * - GSource* -> Source
52 * - GString* -> StringG
53 * module aliases:
54 * local aliases:
57 module glib.IOChannel;
59 version(noAssert)
61 version(Tango)
63 import tango.io.Stdout; // use the tango loging?
67 private import gtkc.glibtypes;
69 private import gtkc.glib;
72 private import glib.ErrorG;
73 private import glib.StringG;
74 private import glib.Source;
75 private import glib.Dataset;
76 private import glib.Str;
81 /**
82 * Description
83 * The GIOChannel data type aims to provide a portable method for using file
84 * descriptors, pipes, and sockets, and integrating them into the
85 * main event loop.
86 * Currently full support is available on UNIX platforms, support for
87 * Windows is only partially complete.
88 * To create a new GIOChannel on UNIX systems use g_io_channel_unix_new().
89 * This works for plain file descriptors, pipes and sockets.
90 * Alternatively, a channel can be created for a file in a system independent
91 * manner using g_io_channel_new_file().
92 * Once a GIOChannel has been created, it can be used in a generic manner
93 * with the functions g_io_channel_read_chars(), g_io_channel_write_chars(),
94 * g_io_channel_seek_position(), and g_io_channel_shutdown().
95 * To add a GIOChannel to the
96 * main event loop
97 * use g_io_add_watch() or g_io_add_watch_full(). Here you specify which events
98 * you are interested in on the GIOChannel, and provide a function to be
99 * called whenever these events occur.
100 * GIOChannel instances are created with an initial reference count of 1.
101 * g_io_channel_ref() and g_io_channel_unref() can be used to increment or
102 * decrement the reference count respectively. When the reference count falls
103 * to 0, the GIOChannel is freed. (Though it isn't closed automatically,
104 * unless it was created using g_io_channel_new_from_file().)
105 * Using g_io_add_watch() or g_io_add_watch_full() increments a channel's
106 * reference count.
107 * The new functions g_io_channel_read_chars(), g_io_channel_read_line(),
108 * g_io_channel_read_line_string(), g_io_channel_read_to_end(),
109 * g_io_channel_write_chars(), g_io_channel_seek_position(),
110 * and g_io_channel_flush() should not be mixed with the
111 * deprecated functions g_io_channel_read(), g_io_channel_write(),
112 * and g_io_channel_seek() on the same channel.
114 public class IOChannel
117 /** the main Gtk struct */
118 protected GIOChannel* gIOChannel;
121 public GIOChannel* getIOChannelStruct()
123 return gIOChannel;
127 /** the main Gtk struct as a void* */
128 protected void* getStruct()
130 return cast(void*)gIOChannel;
134 * Sets our main struct and passes it to the parent class
136 public this (GIOChannel* gIOChannel)
138 version(noAssert)
140 if ( gIOChannel is null )
142 int zero = 0;
143 version(Tango)
145 Stdout("struct gIOChannel is null on constructor").newline;
147 else
149 printf("struct gIOChannel is null on constructor");
151 zero = zero / zero;
154 else
156 assert(gIOChannel !is null, "struct gIOChannel is null on constructor");
158 this.gIOChannel = gIOChannel;
166 * Creates a new GIOChannel given a file descriptor.
167 * On UNIX systems this works for plain files, pipes, and sockets.
168 * The returned GIOChannel has a reference count of 1.
169 * The default encoding for GIOChannel is UTF-8. If your application
170 * is reading output from a command using via pipe, you may need to
171 * set the encoding to the encoding of the current locale (see
172 * g_get_charset()) with the g_io_channel_set_encoding() function.
173 * If you want to read raw binary data without interpretation, then
174 * call the g_io_channel_set_encoding() function with NULL for the
175 * encoding argument.
176 * This function is available in GLib on Windows, too, but you should
177 * avoid using it on Windows. The domain of file descriptors and sockets
178 * overlap. There is no way for GLib to know which one you mean in case
179 * the argument you pass to this function happens to be both a valid file
180 * descriptor and socket. If that happens a warning is issued, and GLib
181 * assumes that it is the file descriptor you mean.
182 * fd:
183 * a file descriptor.
184 * Returns:
185 * a new GIOChannel.
187 public static IOChannel unixNew(int fd)
189 // GIOChannel* g_io_channel_unix_new (int fd);
190 return new IOChannel( g_io_channel_unix_new(fd) );
194 * Returns the file descriptor of the GIOChannel.
195 * On Windows this function returns the file descriptor or socket of the GIOChannel.
196 * channel:
197 * a GIOChannel, created with g_io_channel_unix_new().
198 * Returns:
199 * the file descriptor of the GIOChannel.
201 public int unixGetFd()
203 // gint g_io_channel_unix_get_fd (GIOChannel *channel);
204 return g_io_channel_unix_get_fd(gIOChannel);
208 * Creates a new GIOChannel given a file descriptor on Windows. This works for
209 * file descriptors from the C runtime.
210 * This function works for file descriptors as returned by the open(),
211 * creat(), pipe() and fileno() calls in the Microsoft C runtime. In
212 * order to meaningfully use this function your code should use the same
213 * C runtime as GLib uses, which is msvcrt.dll. Note that in current
214 * Microsoft compilers it is near impossible to convince it to build code
215 * that would use msvcrt.dll. The last Microsoft compiler version that
216 * supported using msvcrt.dll as the C runtime was version 6. The GNU
217 * compiler and toolchain for Windows, also known as Mingw, fully
218 * supports msvcrt.dll.
219 * If you have created a GIOChannel for a file descriptor and started
220 * watching (polling) it, you shouldn't call read() on the file
221 * descriptor. This is because adding polling for a file descriptor is
222 * implemented in GLib on Windows by starting a thread that sits blocked
223 * in a read() from the file descriptor most of the time. All reads from
224 * the file descriptor should be done by this internal GLib thread. Your
225 * code should call only g_io_channel_read().
226 * This function is available only in GLib on Windows.
227 * fd:
228 * a C library file descriptor.
229 * Returns:
230 * a new GIOChannel.
232 public static IOChannel win32_NewFd(int fd)
234 // GIOChannel* g_io_channel_win32_new_fd (gint fd);
235 return new IOChannel( g_io_channel_win32_new_fd(fd) );
239 * Creates a new GIOChannel given a socket on Windows.
240 * This function works for sockets created by Winsock. It's available
241 * only in GLib on Windows.
242 * Polling a GSource created to watch a channel for a socket puts the
243 * socket in non-blocking mode. This is a side-effect of the
244 * implementation and unavoidable.
245 * socket:
246 * Returns:
247 * a new GIOChannel.
249 public static IOChannel win32_NewSocket(int socket)
251 // GIOChannel* g_io_channel_win32_new_socket (gint socket);
252 return new IOChannel( g_io_channel_win32_new_socket(socket) );
256 * Creates a new GIOChannel given a window handle on Windows.
257 * This function creates a GIOChannel that can be used to poll for
258 * Windows messages for the window in question.
259 * hwnd:
260 * a window handle.
261 * Returns:
262 * a new GIOChannel.
264 public static IOChannel win32_NewMessages(uint hwnd)
266 // GIOChannel* g_io_channel_win32_new_messages (guint hwnd);
267 return new IOChannel( g_io_channel_win32_new_messages(hwnd) );
271 * Initializes a GIOChannel struct. This is called by each of the above functions
272 * when creating a GIOChannel, and so is not often needed by the application
273 * programmer (unless you are creating a new type of GIOChannel).
274 * channel:
275 * a GIOChannel.
277 public void init()
279 // void g_io_channel_init (GIOChannel *channel);
280 g_io_channel_init(gIOChannel);
284 * Open a file filename as a GIOChannel using mode mode. This
285 * channel will be closed when the last reference to it is dropped,
286 * so there is no need to call g_io_channel_close() (though doing
287 * so will not cause problems, as long as no attempt is made to
288 * access the channel after it is closed).
289 * filename:
290 * A string containing the name of a file.
291 * mode:
292 * One of "r", "w", "a", "r+", "w+", "a+". These have
293 * the same meaning as in fopen().
294 * error:
295 * A location to return an error of type G_FILE_ERROR.
296 * Returns:
297 * A GIOChannel on success, NULL on failure.
299 public this (char[] filename, char[] mode, GError** error)
301 // GIOChannel* g_io_channel_new_file (const gchar *filename, const gchar *mode, GError **error);
302 this(cast(GIOChannel*)g_io_channel_new_file(Str.toStringz(filename), Str.toStringz(mode), error) );
306 * Replacement for g_io_channel_read() with the new API.
307 * channel:
308 * a GIOChannel
309 * buf:
310 * a buffer to read data into
311 * count:
312 * the size of the buffer. Note that the buffer may
313 * not be complelely filled even if there is data
314 * in the buffer if the remaining data is not a
315 * complete character.
316 * bytes_read:
317 * The number of bytes read. This may be zero even on
318 * success if count < 6 and the channel's encoding is non-NULL.
319 * This indicates that the next UTF-8 character is too wide for
320 * the buffer.
321 * error:
322 * A location to return an error of type GConvertError
323 * or GIOChannelError.
324 * Returns:
325 * the status of the operation.
327 public GIOStatus readChars(char[] buf, uint count, uint* bytesRead, GError** error)
329 // GIOStatus g_io_channel_read_chars (GIOChannel *channel, gchar *buf, gsize count, gsize *bytes_read, GError **error);
330 return g_io_channel_read_chars(gIOChannel, Str.toStringz(buf), count, bytesRead, error);
334 * This function cannot be called on a channel with NULL encoding.
335 * channel:
336 * a GIOChannel
337 * thechar:
338 * a location to return a character
339 * error:
340 * A location to return an error of type GConvertError
341 * or GIOChannelError
342 * Returns:
343 * a GIOStatus
345 public GIOStatus readUnichar(gunichar* thechar, GError** error)
347 // GIOStatus g_io_channel_read_unichar (GIOChannel *channel, gunichar *thechar, GError **error);
348 return g_io_channel_read_unichar(gIOChannel, thechar, error);
352 * Reads a line, including the terminating character(s),
353 * from a GIOChannel into a newly-allocated string.
354 * str_return will contain allocated memory if the return
355 * is G_IO_STATUS_NORMAL.
356 * channel:
357 * a GIOChannel
358 * str_return:
359 * The line read from the GIOChannel, including the
360 * line terminator. This data should be freed with g_free()
361 * when no longer needed. This is a nul-terminated string.
362 * If a length of zero is returned, this will be NULL instead.
363 * length:
364 * location to store length of the read data, or NULL
365 * terminator_pos:
366 * location to store position of line terminator, or NULL
367 * error:
368 * A location to return an error of type GConvertError
369 * or GIOChannelError
370 * Returns:
371 * the status of the operation.
373 public GIOStatus readLine(char** strReturn, uint* length, uint* terminatorPos, GError** error)
375 // GIOStatus g_io_channel_read_line (GIOChannel *channel, gchar **str_return, gsize *length, gsize *terminator_pos, GError **error);
376 return g_io_channel_read_line(gIOChannel, strReturn, length, terminatorPos, error);
380 * Reads a line from a GIOChannel, using a GString as a buffer.
381 * channel:
382 * a GIOChannel
383 * buffer:
384 * a GString into which the line will be written.
385 * If buffer already contains data, the old data will
386 * be overwritten.
387 * terminator_pos:
388 * location to store position of line terminator, or NULL
389 * error:
390 * a location to store an error of type GConvertError
391 * or GIOChannelError
392 * Returns:
393 * the status of the operation.
395 public GIOStatus readLineString(StringG buffer, uint* terminatorPos, GError** error)
397 // GIOStatus g_io_channel_read_line_string (GIOChannel *channel, GString *buffer, gsize *terminator_pos, GError **error);
398 return g_io_channel_read_line_string(gIOChannel, (buffer is null) ? null : buffer.getStringGStruct(), terminatorPos, error);
402 * Reads all the remaining data from the file.
403 * channel:
404 * a GIOChannel
405 * str_return:
406 * Location to store a pointer to a string holding
407 * the remaining data in the GIOChannel. This data should
408 * be freed with g_free() when no longer needed. This
409 * data is terminated by an extra nul character, but there
410 * may be other nuls in the intervening data.
411 * length:
412 * Location to store length of the data
413 * error:
414 * A location to return an error of type GConvertError
415 * or GIOChannelError
416 * Returns:
417 * G_IO_STATUS_NORMAL on success.
418 * This function never returns G_IO_STATUS_EOF.
420 public GIOStatus readToEnd(char** strReturn, uint* length, GError** error)
422 // GIOStatus g_io_channel_read_to_end (GIOChannel *channel, gchar **str_return, gsize *length, GError **error);
423 return g_io_channel_read_to_end(gIOChannel, strReturn, length, error);
427 * Replacement for g_io_channel_write() with the new API.
428 * On seekable channels with encodings other than NULL or UTF-8, generic
429 * mixing of reading and writing is not allowed. A call to g_io_channel_write_chars()
430 * may only be made on a channel from which data has been read in the
431 * cases described in the documentation for g_io_channel_set_encoding().
432 * channel:
433 * a GIOChannel
434 * buf:
435 * a buffer to write data from
436 * count:
437 * the size of the buffer. If -1, the buffer
438 * is taken to be a nul-terminated string.
439 * bytes_written:
440 * The number of bytes written. This can be nonzero
441 * even if the return value is not G_IO_STATUS_NORMAL.
442 * If the return value is G_IO_STATUS_NORMAL and the
443 * channel is blocking, this will always be equal
444 * to count if count >= 0.
445 * error:
446 * A location to return an error of type GConvertError
447 * or GIOChannelError
448 * Returns:
449 * the status of the operation.
451 public GIOStatus writeChars(char[] buf, int count, uint* bytesWritten, GError** error)
453 // GIOStatus g_io_channel_write_chars (GIOChannel *channel, const gchar *buf, gssize count, gsize *bytes_written, GError **error);
454 return g_io_channel_write_chars(gIOChannel, Str.toStringz(buf), count, bytesWritten, error);
458 * This function cannot be called on a channel with NULL encoding.
459 * channel:
460 * a GIOChannel
461 * thechar:
462 * a character
463 * error:
464 * A location to return an error of type GConvertError
465 * or GIOChannelError
466 * Returns:
467 * a GIOStatus
469 public GIOStatus writeUnichar(gunichar thechar, GError** error)
471 // GIOStatus g_io_channel_write_unichar (GIOChannel *channel, gunichar thechar, GError **error);
472 return g_io_channel_write_unichar(gIOChannel, thechar, error);
476 * Flushes the write buffer for the GIOChannel.
477 * channel:
478 * a GIOChannel
479 * error:
480 * location to store an error of type GIOChannelError
481 * Returns:
482 * the status of the operation: One of
483 * G_IO_CHANNEL_NORMAL, G_IO_CHANNEL_AGAIN, or
484 * G_IO_CHANNEL_ERROR.
486 public GIOStatus flush(GError** error)
488 // GIOStatus g_io_channel_flush (GIOChannel *channel, GError **error);
489 return g_io_channel_flush(gIOChannel, error);
493 * Replacement for g_io_channel_seek() with the new API.
494 * channel:
495 * a GIOChannel
496 * offset:
497 * The offset in bytes from the position specified by type
498 * type:
499 * a GSeekType. The type G_SEEK_CUR is only allowed in those
500 * cases where a call to g_io_channel_set_encoding()
501 * is allowed. See the documentation for
502 * g_io_channel_set_encoding() for details.
503 * error:
504 * A location to return an error of type GIOChannelError
505 * Returns:
506 * the status of the operation.
508 public GIOStatus seekPosition(long offset, GSeekType type, GError** error)
510 // GIOStatus g_io_channel_seek_position (GIOChannel *channel, gint64 offset, GSeekType type, GError **error);
511 return g_io_channel_seek_position(gIOChannel, offset, type, error);
516 * Close an IO channel. Any pending data to be written will be
517 * flushed if flush is TRUE. The channel will not be freed until the
518 * last reference is dropped using g_io_channel_unref().
519 * channel:
520 * a GIOChannel
521 * flush:
522 * if TRUE, flush pending
523 * err:
524 * location to store a GIOChannelError
525 * Returns:
526 * the status of the operation.
528 public GIOStatus shutdown(int flush, GError** err)
530 // GIOStatus g_io_channel_shutdown (GIOChannel *channel, gboolean flush, GError **err);
531 return g_io_channel_shutdown(gIOChannel, flush, err);
538 * Converts an errno error number to a GIOChannelError.
539 * en:
540 * an errno error number, e.g. EINVAL.
541 * Returns:
542 * a GIOChannelError error number, e.g. G_IO_CHANNEL_ERROR_INVAL.
544 public static GIOChannelError errorFromErrno(int en)
546 // GIOChannelError g_io_channel_error_from_errno (gint en);
547 return g_io_channel_error_from_errno(en);
551 * Increments the reference count of a GIOChannel.
552 * channel:
553 * a GIOChannel.
554 * Returns:
555 * the channel that was passed in (since 2.6)
557 public IOChannel doref()
559 // GIOChannel* g_io_channel_ref (GIOChannel *channel);
560 return new IOChannel( g_io_channel_ref(gIOChannel) );
564 * Decrements the reference count of a GIOChannel.
565 * channel:
566 * a GIOChannel.
568 public void unref()
570 // void g_io_channel_unref (GIOChannel *channel);
571 g_io_channel_unref(gIOChannel);
575 * Creates a GSource that's dispatched when condition is met for the given
576 * channel. For example, if condition is G_IO_IN, the source will be dispatched
577 * when there's data available for reading. g_io_add_watch() is a simpler
578 * interface to this same functionality, for the case where you want to add the
579 * source to the default main loop at the default priority.
580 * On Windows, polling a GSource created to watch a channel for a socket
581 * puts the socket in non-blocking mode. This is a side-effect of the
582 * implementation and unavoidable.
583 * channel:
584 * a GIOChannel to watch
585 * condition:
586 * conditions to watch for
587 * Returns:
588 * a new GSource
590 public Source gIoCreateWatch(GIOCondition condition)
592 // GSource* g_io_create_watch (GIOChannel *channel, GIOCondition condition);
593 return new Source( g_io_create_watch(gIOChannel, condition) );
597 * Adds the GIOChannel into the
598 * main event loop
599 * with the default priority.
600 * channel:
601 * a GIOChannel.
602 * condition:
603 * the condition to watch for.
604 * func:
605 * the function to call when the condition is satisfied.
606 * user_data:
607 * user data to pass to func.
608 * Returns:
609 * the event source id.
611 public uint gIoAddWatch(GIOCondition condition, GIOFunc func, void* userData)
613 // guint g_io_add_watch (GIOChannel *channel, GIOCondition condition, GIOFunc func, gpointer user_data);
614 return g_io_add_watch(gIOChannel, condition, func, userData);
618 * Adds the GIOChannel into the
619 * main event loop
620 * with the given priority.
621 * channel:
622 * a GIOChannel.
623 * priority:
624 * the priority of the GIOChannel source.
625 * condition:
626 * the condition to watch for.
627 * func:
628 * the function to call when the condition is satisfied.
629 * user_data:
630 * user data to pass to func.
631 * notify:
632 * the function to call when the source is removed.
633 * Returns:
634 * the event source id.
636 public uint gIoAddWatchFull(int priority, GIOCondition condition, GIOFunc func, void* userData, GDestroyNotify notify)
638 // guint g_io_add_watch_full (GIOChannel *channel, gint priority, GIOCondition condition, GIOFunc func, gpointer user_data, GDestroyNotify notify);
639 return g_io_add_watch_full(gIOChannel, priority, condition, func, userData, notify);
646 * Gets the buffer size.
647 * channel:
648 * a GIOChannel
649 * Returns:
650 * the size of the buffer.
652 public uint getBufferSize()
654 // gsize g_io_channel_get_buffer_size (GIOChannel *channel);
655 return g_io_channel_get_buffer_size(gIOChannel);
659 * Sets the buffer size.
660 * channel:
661 * a GIOChannel
662 * size:
663 * the size of the buffer. 0 == pick a good size
665 public void setBufferSize(uint size)
667 // void g_io_channel_set_buffer_size (GIOChannel *channel, gsize size);
668 g_io_channel_set_buffer_size(gIOChannel, size);
672 * This function returns a GIOCondition depending on whether there
673 * is data to be read/space to write data in the
674 * internal buffers in the GIOChannel. Only the flags G_IO_IN and
675 * G_IO_OUT may be set.
676 * channel:
677 * A GIOChannel
678 * Returns:
679 * A GIOCondition
681 public GIOCondition getBufferCondition()
683 // GIOCondition g_io_channel_get_buffer_condition (GIOChannel *channel);
684 return g_io_channel_get_buffer_condition(gIOChannel);
688 * Gets the current flags for a GIOChannel, including read-only
689 * flags such as G_IO_FLAG_IS_READABLE.
690 * The values of the flags G_IO_FLAG_IS_READABLE and G_IO_FLAG_IS_WRITEABLE
691 * are cached for internal use by the channel when it is created.
692 * If they should change at some later point (e.g. partial shutdown
693 * of a socket with the UNIX shutdown() function), the user
694 * should immediately call g_io_channel_get_flags() to update
695 * the internal values of these flags.
696 * channel:
697 * a GIOChannel
698 * Returns:
699 * the flags which are set on the channel
701 public GIOFlags getFlags()
703 // GIOFlags g_io_channel_get_flags (GIOChannel *channel);
704 return g_io_channel_get_flags(gIOChannel);
708 * Sets the (writeable) flags in channel to (flags G_IO_CHANNEL_SET_MASK).
709 * channel:
710 * a GIOChannel.
711 * flags:
712 * the flags to set on the IO channel.
713 * error:
714 * A location to return an error of type GIOChannelError.
715 * Returns:
716 * the status of the operation.
718 public GIOStatus setFlags(GIOFlags flags, GError** error)
720 // GIOStatus g_io_channel_set_flags (GIOChannel *channel, GIOFlags flags, GError **error);
721 return g_io_channel_set_flags(gIOChannel, flags, error);
726 * This returns the string that GIOChannel uses to determine
727 * where in the file a line break occurs. A value of NULL
728 * indicates auto detection.
729 * channel:
730 * a GIOChannel
731 * length:
732 * a location to return the length of the line terminator
733 * Returns:
734 * The line termination string. This value
735 * is owned by GLib and must not be freed.
737 public char[] getLineTerm(int* length)
739 // const gchar* g_io_channel_get_line_term (GIOChannel *channel, gint *length);
740 return Str.toString(g_io_channel_get_line_term(gIOChannel, length) );
744 * This sets the string that GIOChannel uses to determine
745 * where in the file a line break occurs.
746 * channel:
747 * a GIOChannel
748 * line_term:
749 * The line termination string. Use NULL for auto detect.
750 * Auto detection breaks on "\n", "\r\n", "\r", "\0", and
751 * the Unicode paragraph separator. Auto detection should
752 * not be used for anything other than file-based channels.
753 * length:
754 * The length of the termination string. If -1 is passed, the
755 * string is assumed to be nul-terminated. This option allows
756 * termination strings with embeded nuls.
758 public void setLineTerm(char[] lineTerm, int length)
760 // void g_io_channel_set_line_term (GIOChannel *channel, const gchar *line_term, gint length);
761 g_io_channel_set_line_term(gIOChannel, Str.toStringz(lineTerm), length);
765 * Returns whether channel is buffered.
766 * channel:
767 * a GIOChannel.
768 * Returns:
769 * TRUE if the channel is buffered.
771 public int getBuffered()
773 // gboolean g_io_channel_get_buffered (GIOChannel *channel);
774 return g_io_channel_get_buffered(gIOChannel);
778 * The buffering state can only be set if the channel's encoding
779 * is NULL. For any other encoding, the channel must be buffered.
780 * A buffered channel can only be set unbuffered if the channel's
781 * internal buffers have been flushed. Newly created channels or
782 * channels which have returned G_IO_STATUS_EOF
783 * not require such a flush. For write-only channels, a call to
784 * g_io_channel_flush() is sufficient. For all other channels,
785 * the buffers may be flushed by a call to g_io_channel_seek_position().
786 * This includes the possibility of seeking with seek type G_SEEK_CUR
787 * and an offset of zero. Note that this means that socket-based
788 * channels cannot be set unbuffered once they have had data
789 * read from them.
790 * On unbuffered channels, it is safe to mix read and write
791 * calls from the new and old APIs, if this is necessary for
792 * maintaining old code.
793 * The default state of the channel is buffered.
794 * channel:
795 * a GIOChannel
796 * buffered:
797 * whether to set the channel buffered or unbuffered
799 public void setBuffered(int buffered)
801 // void g_io_channel_set_buffered (GIOChannel *channel, gboolean buffered);
802 g_io_channel_set_buffered(gIOChannel, buffered);
806 * Gets the encoding for the input/output of the channel. The internal
807 * encoding is always UTF-8. The encoding NULL makes the
808 * channel safe for binary data.
809 * channel:
810 * a GIOChannel
811 * Returns:
812 * A string containing the encoding, this string is
813 * owned by GLib and must not be freed.
815 public char[] getEncoding()
817 // const gchar* g_io_channel_get_encoding (GIOChannel *channel);
818 return Str.toString(g_io_channel_get_encoding(gIOChannel) );
822 * Sets the encoding for the input/output of the channel. The internal
823 * encoding is always UTF-8. The default encoding for the
824 * external file is UTF-8.
825 * The encoding NULL is safe to use with binary data.
826 * The encoding can only be set if one of the following conditions
827 * is true:
828 * 1. The channel was just created, and has not been written to
829 * or read from yet.
830 * 2. The channel is write-only.
831 * 3. The channel is a file, and the file pointer was just
832 * repositioned by a call to g_io_channel_seek_position().
833 * (This flushes all the internal buffers.)
834 * 4. The current encoding is NULL or UTF-8.
835 * 5. One of the (new API) read functions has just returned G_IO_STATUS_EOF
836 * (or, in the case of g_io_channel_read_to_end(), G_IO_STATUS_NORMAL).
837 * 6. One of the functions g_io_channel_read_chars() or g_io_channel_read_unichar()
838 * has returned G_IO_STATUS_AGAIN or G_IO_STATUS_ERROR. This may be
839 * useful in the case of G_CONVERT_ERROR_ILLEGAL_SEQUENCE.
840 * Returning one of these statuses from g_io_channel_read_line(),
841 * g_io_channel_read_line_string(), or g_io_channel_read_to_end()
842 * does not guarantee that the encoding can be changed.
843 * Channels which do not meet one of the above conditions cannot call
844 * g_io_channel_seek_position() with an offset of G_SEEK_CUR,
845 * and, if they are "seekable", cannot
846 * call g_io_channel_write_chars() after calling one
847 * of the API "read" functions.
848 * channel:
849 * a GIOChannel
850 * encoding:
851 * the encoding type
852 * error:
853 * location to store an error of type GConvertError.
854 * Returns:
855 * G_IO_STATUS_NORMAL if the encoding was successfully set.
857 public GIOStatus setEncoding(char[] encoding, GError** error)
859 // GIOStatus g_io_channel_set_encoding (GIOChannel *channel, const gchar *encoding, GError **error);
860 return g_io_channel_set_encoding(gIOChannel, Str.toStringz(encoding), error);
864 * Returns whether the file/socket/whatever associated with channel
865 * will be closed when channel receives its final unref and is
866 * destroyed. The default value of this is TRUE for channels created
867 * by g_io_channel_new_file(), and FALSE for all other channels.
868 * channel:
869 * a GIOChannel.
870 * Returns:
871 * Whether the channel will be closed on the final unref of
872 * the GIOChannel data structure.
874 public int getCloseOnUnref()
876 // gboolean g_io_channel_get_close_on_unref (GIOChannel *channel);
877 return g_io_channel_get_close_on_unref(gIOChannel);
881 * Setting this flag to TRUE for a channel you have already closed
882 * can cause problems.
883 * channel:
884 * a GIOChannel
885 * do_close:
886 * Whether to close the channel on the final unref of
887 * the GIOChannel data structure. The default value of
888 * this is TRUE for channels created by g_io_channel_new_file(),
889 * and FALSE for all other channels.
891 public void setCloseOnUnref(int doClose)
893 // void g_io_channel_set_close_on_unref (GIOChannel *channel, gboolean do_close);
894 g_io_channel_set_close_on_unref(gIOChannel, doClose);
898 * Warning
899 * 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.
900 * Reads data from a GIOChannel.
901 * channel:
902 * a GIOChannel.
903 * buf:
904 * a buffer to read the data into (which should be at least count bytes long).
905 * count:
906 * the number of bytes to read from the GIOChannel.
907 * bytes_read:
908 * returns the number of bytes actually read.
909 * Returns:
910 * G_IO_ERROR_NONE if the operation was successful.
912 public GIOError read(char[] buf, uint count, uint* bytesRead)
914 // GIOError g_io_channel_read (GIOChannel *channel, gchar *buf, gsize count, gsize *bytes_read);
915 return g_io_channel_read(gIOChannel, Str.toStringz(buf), count, bytesRead);
920 * Warning
921 * 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.
922 * Writes data to a GIOChannel.
923 * channel:
924 * a GIOChannel.
925 * buf:
926 * the buffer containing the data to write.
927 * count:
928 * the number of bytes to write.
929 * bytes_written:
930 * the number of bytes actually written.
931 * Returns:
932 * G_IO_ERROR_NONE if the operation was successful.
934 public GIOError write(char[] buf, uint count, uint* bytesWritten)
936 // GIOError g_io_channel_write (GIOChannel *channel, const gchar *buf, gsize count, gsize *bytes_written);
937 return g_io_channel_write(gIOChannel, Str.toStringz(buf), count, bytesWritten);
941 * Warning
942 * 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.
943 * Sets the current position in the GIOChannel, similar to the standard library
944 * function fseek().
945 * channel:
946 * a GIOChannel.
947 * offset:
948 * an offset, in bytes, which is added to the position specified by type
949 * type:
950 * the position in the file, which can be G_SEEK_CUR (the current
951 * position), G_SEEK_SET (the start of the file), or G_SEEK_END (the end of the
952 * file).
953 * Returns:
954 * G_IO_ERROR_NONE if the operation was successful.
956 public GIOError seek(long offset, GSeekType type)
958 // GIOError g_io_channel_seek (GIOChannel *channel, gint64 offset, GSeekType type);
959 return g_io_channel_seek(gIOChannel, offset, type);
963 * Warning
964 * 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.
965 * Close an IO channel. Any pending data to be written will be
966 * flushed, ignoring errors. The channel will not be freed until the
967 * last reference is dropped using g_io_channel_unref().
968 * channel:
969 * A GIOChannel
970 * See Also
971 * gtk_input_add_full(), gtk_input_remove(), gdk_input_add(),
972 * gdk_input_add_full(), gdk_input_remove()
973 * Convenience functions for creating GIOChannel instances and adding them to the
974 * main event loop.
976 public void close()
978 // void g_io_channel_close (GIOChannel *channel);
979 g_io_channel_close(gIOChannel);