I've no idea here...
[gtkD.git] / src / glib / IOChannel.d
blobdcc68b11c5cfa170f5e6e8c325c55eb4c15d9612
1 /*
2 * This file is part of duit.
4 * duit 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 * duit 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 duit; 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 * local aliases:
56 module glib.IOChannel;
58 private import glib.glibtypes;
60 private import lib.glib;
62 private import glib.ErrorG;
63 private import glib.StringG;
64 private import glib.Source;
65 private import glib.Dataset;
66 private import glib.Str;
68 /**
69 * Description
70 * The GIOChannel data type aims to provide a portable method for using file
71 * descriptors, pipes, and sockets, and integrating them into the
72 * main event loop.
73 * Currently full support is available on UNIX platforms, support for
74 * Windows is only partially complete.
75 * To create a new GIOChannel on UNIX systems use g_io_channel_unix_new().
76 * This works for plain file descriptors, pipes and sockets.
77 * Alternatively, a channel can be created for a file in a system independent
78 * manner using g_io_channel_new_file().
79 * Once a GIOChannel has been created, it can be used in a generic manner
80 * with the functions g_io_channel_read_chars(), g_io_channel_write_chars(),
81 * g_io_channel_seek_position(), and g_io_channel_shutdown().
82 * To add a GIOChannel to the
83 * main event loop
84 * use g_io_add_watch() or g_io_add_watch_full(). Here you specify which events
85 * you are interested in on the GIOChannel, and provide a function to be
86 * called whenever these events occur.
87 * GIOChannel instances are created with an initial reference count of 1.
88 * g_io_channel_ref() and g_io_channel_unref() can be used to increment or
89 * decrement the reference count respectively. When the reference count falls
90 * to 0, the GIOChannel is freed. (Though it isn't closed automatically,
91 * unless it was created using g_io_channel_new_from_file().)
92 * Using g_io_add_watch() or g_io_add_watch_full() increments a channel's
93 * reference count.
94 * The new functions g_io_channel_read_chars(), g_io_channel_read_line(),
95 * g_io_channel_read_line_string(), g_io_channel_read_to_end(),
96 * g_io_channel_write_chars(), g_io_channel_seek_position(),
97 * and g_io_channel_flush() should not be mixed with the
98 * deprecated functions g_io_channel_read(), g_io_channel_write(),
99 * and g_io_channel_seek() on the same channel.
101 public class IOChannel
104 /** the main Gtk struct */
105 protected GIOChannel* gIOChannel;
108 public GIOChannel* getIOChannelStruct()
110 return gIOChannel;
114 /** the main Gtk struct as a void* */
115 protected void* getStruct()
117 return cast(void*)gIOChannel;
121 * Sets our main struct and passes it to the parent class
123 public this (GIOChannel* gIOChannel)
125 this.gIOChannel = gIOChannel;
133 * Creates a new GIOChannel given a file descriptor.
134 * On UNIX systems this works for plain files, pipes, and sockets.
135 * The returned GIOChannel has a reference count of 1.
136 * The default encoding for GIOChannel is UTF-8. If your application
137 * is reading output from a command using via pipe, you may need to
138 * set the encoding to the encoding of the current locale (see
139 * g_get_charset()) with the g_io_channel_set_encoding() function.
140 * If you want to read raw binary data without interpretation, then
141 * call the g_io_channel_set_encoding() function with NULL for the
142 * encoding argument.
143 * This function is available in GLib on Windows, too, but you should
144 * avoid using it on Windows. The domain of file descriptors and sockets
145 * overlap. There is no way for GLib to know which one you mean in case
146 * the argument you pass to this function happens to be both a valid file
147 * descriptor and socket. If that happens a warning is issued, and GLib
148 * assumes that it is the file descriptor you mean.
149 * fd:
150 * a file descriptor.
151 * Returns:
152 * a new GIOChannel.
154 public static IOChannel unixNew(int fd)
156 // GIOChannel* g_io_channel_unix_new (int fd);
157 return new IOChannel( g_io_channel_unix_new(fd) );
161 * Returns the file descriptor of the GIOChannel.
162 * On Windows this function returns the file descriptor or socket of the GIOChannel.
163 * channel:
164 * a GIOChannel, created with g_io_channel_unix_new().
165 * Returns:
166 * the file descriptor of the GIOChannel.
168 public int unixGetFd()
170 // gint g_io_channel_unix_get_fd (GIOChannel *channel);
171 return g_io_channel_unix_get_fd(gIOChannel);
175 * Creates a new GIOChannel given a file descriptor on Windows. This works for
176 * file descriptors from the C runtime.
177 * This function works for file descriptors as returned by the open(),
178 * creat(), pipe() and fileno() calls in the Microsoft C runtime. In
179 * order to meaningfully use this function your code should use the same
180 * C runtime as GLib uses, which is msvcrt.dll. Note that in current
181 * Microsoft compilers it is near impossible to convince it to build code
182 * that would use msvcrt.dll. The last Microsoft compiler version that
183 * supported using msvcrt.dll as the C runtime was version 6. The GNU
184 * compiler and toolchain for Windows, also known as Mingw, fully
185 * supports msvcrt.dll.
186 * If you have created a GIOChannel for a file descriptor and started
187 * watching (polling) it, you shouldn't call read() on the file
188 * descriptor. This is because adding polling for a file descriptor is
189 * implemented in GLib on Windows by starting a thread that sits blocked
190 * in a read() from the file descriptor most of the time. All reads from
191 * the file descriptor should be done by this internal GLib thread. Your
192 * code should call only g_io_channel_read().
193 * This function is available only in GLib on Windows.
194 * fd:
195 * a C library file descriptor.
196 * Returns:
197 * a new GIOChannel.
199 public static IOChannel win32_NewFd(int fd)
201 // GIOChannel* g_io_channel_win32_new_fd (gint fd);
202 return new IOChannel( g_io_channel_win32_new_fd(fd) );
206 * Creates a new GIOChannel given a socket on Windows.
207 * This function works for sockets created by Winsock. It's available
208 * only in GLib on Windows.
209 * Polling a GSource created to watch a channel for a socket puts the
210 * socket in non-blocking mode. This is a side-effect of the
211 * implementation and unavoidable.
212 * socket:
213 * Returns:
214 * a new GIOChannel.
216 public static IOChannel win32_NewSocket(int socket)
218 // GIOChannel* g_io_channel_win32_new_socket (gint socket);
219 return new IOChannel( g_io_channel_win32_new_socket(socket) );
223 * Creates a new GIOChannel given a window handle on Windows.
224 * This function creates a GIOChannel that can be used to poll for
225 * Windows messages for the window in question.
226 * hwnd:
227 * a window handle.
228 * Returns:
229 * a new GIOChannel.
231 public static IOChannel win32_NewMessages(uint hwnd)
233 // GIOChannel* g_io_channel_win32_new_messages (guint hwnd);
234 return new IOChannel( g_io_channel_win32_new_messages(hwnd) );
238 * Initializes a GIOChannel struct. This is called by each of the above functions
239 * when creating a GIOChannel, and so is not often needed by the application
240 * programmer (unless you are creating a new type of GIOChannel).
241 * channel:
242 * a GIOChannel.
244 public void init()
246 // void g_io_channel_init (GIOChannel *channel);
247 g_io_channel_init(gIOChannel);
251 * Open a file filename as a GIOChannel using mode mode. This
252 * channel will be closed when the last reference to it is dropped,
253 * so there is no need to call g_io_channel_close() (though doing
254 * so will not cause problems, as long as no attempt is made to
255 * access the channel after it is closed).
256 * filename:
257 * A string containing the name of a file.
258 * mode:
259 * One of "r", "w", "a", "r+", "w+", "a+". These have
260 * the same meaning as in fopen().
261 * error:
262 * A location to return an error of type G_FILE_ERROR.
263 * Returns:
264 * A GIOChannel on success, NULL on failure.
266 public this (char[] filename, char[] mode, GError** error)
268 // GIOChannel* g_io_channel_new_file (const gchar *filename, const gchar *mode, GError **error);
269 this(cast(GIOChannel*)g_io_channel_new_file(Str.toStringz(filename), Str.toStringz(mode), error) );
273 * Replacement for g_io_channel_read() with the new API.
274 * channel:
275 * a GIOChannel
276 * buf:
277 * a buffer to read data into
278 * count:
279 * the size of the buffer. Note that the buffer may
280 * not be complelely filled even if there is data
281 * in the buffer if the remaining data is not a
282 * complete character.
283 * bytes_read:
284 * The number of bytes read. This may be zero even on
285 * success if count < 6 and the channel's encoding is non-NULL.
286 * This indicates that the next UTF-8 character is too wide for
287 * the buffer.
288 * error:
289 * A location to return an error of type GConvertError
290 * or GIOChannelError.
291 * Returns:
292 * the status of the operation.
294 public GIOStatus readChars(char[] buf, uint count, uint* bytesRead, GError** error)
296 // GIOStatus g_io_channel_read_chars (GIOChannel *channel, gchar *buf, gsize count, gsize *bytes_read, GError **error);
297 return g_io_channel_read_chars(gIOChannel, Str.toStringz(buf), count, bytesRead, error);
301 * This function cannot be called on a channel with NULL encoding.
302 * channel:
303 * a GIOChannel
304 * thechar:
305 * a location to return a character
306 * error:
307 * A location to return an error of type GConvertError
308 * or GIOChannelError
309 * Returns:
310 * a GIOStatus
312 public GIOStatus readUnichar(gunichar* thechar, GError** error)
314 // GIOStatus g_io_channel_read_unichar (GIOChannel *channel, gunichar *thechar, GError **error);
315 return g_io_channel_read_unichar(gIOChannel, thechar, error);
319 * Reads a line, including the terminating character(s),
320 * from a GIOChannel into a newly-allocated string.
321 * str_return will contain allocated memory if the return
322 * is G_IO_STATUS_NORMAL.
323 * channel:
324 * a GIOChannel
325 * str_return:
326 * The line read from the GIOChannel, including the
327 * line terminator. This data should be freed with g_free()
328 * when no longer needed. This is a nul-terminated string.
329 * If a length of zero is returned, this will be NULL instead.
330 * length:
331 * location to store length of the read data, or NULL
332 * terminator_pos:
333 * location to store position of line terminator, or NULL
334 * error:
335 * A location to return an error of type GConvertError
336 * or GIOChannelError
337 * Returns:
338 * the status of the operation.
340 public GIOStatus readLine(char** strReturn, uint* length, uint* terminatorPos, GError** error)
342 // GIOStatus g_io_channel_read_line (GIOChannel *channel, gchar **str_return, gsize *length, gsize *terminator_pos, GError **error);
343 return g_io_channel_read_line(gIOChannel, strReturn, length, terminatorPos, error);
347 * Reads a line from a GIOChannel, using a GString as a buffer.
348 * channel:
349 * a GIOChannel
350 * buffer:
351 * a GString into which the line will be written.
352 * If buffer already contains data, the old data will
353 * be overwritten.
354 * terminator_pos:
355 * location to store position of line terminator, or NULL
356 * error:
357 * a location to store an error of type GConvertError
358 * or GIOChannelError
359 * Returns:
360 * the status of the operation.
362 public GIOStatus readLineString(StringG buffer, uint* terminatorPos, GError** error)
364 // GIOStatus g_io_channel_read_line_string (GIOChannel *channel, GString *buffer, gsize *terminator_pos, GError **error);
365 return g_io_channel_read_line_string(gIOChannel, (buffer is null) ? null : buffer.getStringGStruct(), terminatorPos, error);
369 * Reads all the remaining data from the file.
370 * channel:
371 * a GIOChannel
372 * str_return:
373 * Location to store a pointer to a string holding
374 * the remaining data in the GIOChannel. This data should
375 * be freed with g_free() when no longer needed. This
376 * data is terminated by an extra nul character, but there
377 * may be other nuls in the intervening data.
378 * length:
379 * Location to store length of the data
380 * error:
381 * A location to return an error of type GConvertError
382 * or GIOChannelError
383 * Returns:
384 * G_IO_STATUS_NORMAL on success.
385 * This function never returns G_IO_STATUS_EOF.
387 public GIOStatus readToEnd(char** strReturn, uint* length, GError** error)
389 // GIOStatus g_io_channel_read_to_end (GIOChannel *channel, gchar **str_return, gsize *length, GError **error);
390 return g_io_channel_read_to_end(gIOChannel, strReturn, length, error);
394 * Replacement for g_io_channel_write() with the new API.
395 * On seekable channels with encodings other than NULL or UTF-8, generic
396 * mixing of reading and writing is not allowed. A call to g_io_channel_write_chars()
397 * may only be made on a channel from which data has been read in the
398 * cases described in the documentation for g_io_channel_set_encoding().
399 * channel:
400 * a GIOChannel
401 * buf:
402 * a buffer to write data from
403 * count:
404 * the size of the buffer. If -1, the buffer
405 * is taken to be a nul-terminated string.
406 * bytes_written:
407 * The number of bytes written. This can be nonzero
408 * even if the return value is not G_IO_STATUS_NORMAL.
409 * If the return value is G_IO_STATUS_NORMAL and the
410 * channel is blocking, this will always be equal
411 * to count if count >= 0.
412 * error:
413 * A location to return an error of type GConvertError
414 * or GIOChannelError
415 * Returns:
416 * the status of the operation.
418 public GIOStatus writeChars(char[] buf, int count, uint* bytesWritten, GError** error)
420 // GIOStatus g_io_channel_write_chars (GIOChannel *channel, const gchar *buf, gssize count, gsize *bytes_written, GError **error);
421 return g_io_channel_write_chars(gIOChannel, Str.toStringz(buf), count, bytesWritten, error);
425 * This function cannot be called on a channel with NULL encoding.
426 * channel:
427 * a GIOChannel
428 * thechar:
429 * a character
430 * error:
431 * A location to return an error of type GConvertError
432 * or GIOChannelError
433 * Returns:
434 * a GIOStatus
436 public GIOStatus writeUnichar(gunichar thechar, GError** error)
438 // GIOStatus g_io_channel_write_unichar (GIOChannel *channel, gunichar thechar, GError **error);
439 return g_io_channel_write_unichar(gIOChannel, thechar, error);
443 * Flushes the write buffer for the GIOChannel.
444 * channel:
445 * a GIOChannel
446 * error:
447 * location to store an error of type GIOChannelError
448 * Returns:
449 * the status of the operation: One of
450 * G_IO_CHANNEL_NORMAL, G_IO_CHANNEL_AGAIN, or
451 * G_IO_CHANNEL_ERROR.
453 public GIOStatus flush(GError** error)
455 // GIOStatus g_io_channel_flush (GIOChannel *channel, GError **error);
456 return g_io_channel_flush(gIOChannel, error);
460 * Replacement for g_io_channel_seek() with the new API.
461 * channel:
462 * a GIOChannel
463 * offset:
464 * The offset in bytes from the position specified by type
465 * type:
466 * a GSeekType. The type G_SEEK_CUR is only allowed in those
467 * cases where a call to g_io_channel_set_encoding()
468 * is allowed. See the documentation for
469 * g_io_channel_set_encoding() for details.
470 * error:
471 * A location to return an error of type GIOChannelError
472 * Returns:
473 * the status of the operation.
475 public GIOStatus seekPosition(long offset, GSeekType type, GError** error)
477 // GIOStatus g_io_channel_seek_position (GIOChannel *channel, gint64 offset, GSeekType type, GError **error);
478 return g_io_channel_seek_position(gIOChannel, offset, type, error);
483 * Close an IO channel. Any pending data to be written will be
484 * flushed if flush is TRUE. The channel will not be freed until the
485 * last reference is dropped using g_io_channel_unref().
486 * channel:
487 * a GIOChannel
488 * flush:
489 * if TRUE, flush pending
490 * err:
491 * location to store a GIOChannelError
492 * Returns:
493 * the status of the operation.
495 public GIOStatus shutdown(int flush, GError** err)
497 // GIOStatus g_io_channel_shutdown (GIOChannel *channel, gboolean flush, GError **err);
498 return g_io_channel_shutdown(gIOChannel, flush, err);
505 * Converts an errno error number to a GIOChannelError.
506 * en:
507 * an errno error number, e.g. EINVAL.
508 * Returns:
509 * a GIOChannelError error number, e.g. G_IO_CHANNEL_ERROR_INVAL.
511 public static GIOChannelError errorFromErrno(int en)
513 // GIOChannelError g_io_channel_error_from_errno (gint en);
514 return g_io_channel_error_from_errno(en);
518 * Increments the reference count of a GIOChannel.
519 * channel:
520 * a GIOChannel.
521 * Returns:
522 * the channel that was passed in (since 2.6)
524 public IOChannel ref()
526 // GIOChannel* g_io_channel_ref (GIOChannel *channel);
527 return new IOChannel( g_io_channel_ref(gIOChannel) );
531 * Decrements the reference count of a GIOChannel.
532 * channel:
533 * a GIOChannel.
535 public void unref()
537 // void g_io_channel_unref (GIOChannel *channel);
538 g_io_channel_unref(gIOChannel);
542 * Creates a GSource that's dispatched when condition is met for the given
543 * channel. For example, if condition is G_IO_IN, the source will be dispatched
544 * when there's data available for reading. g_io_add_watch() is a simpler
545 * interface to this same functionality, for the case where you want to add the
546 * source to the default main loop at the default priority.
547 * On Windows, polling a GSource created to watch a channel for a socket
548 * puts the socket in non-blocking mode. This is a side-effect of the
549 * implementation and unavoidable.
550 * channel:
551 * a GIOChannel to watch
552 * condition:
553 * conditions to watch for
554 * Returns:
555 * a new GSource
557 public Source gIoCreateWatch(GIOCondition condition)
559 // GSource* g_io_create_watch (GIOChannel *channel, GIOCondition condition);
560 return new Source( g_io_create_watch(gIOChannel, condition) );
564 * Adds the GIOChannel into the
565 * main event loop
566 * with the default priority.
567 * channel:
568 * a GIOChannel.
569 * condition:
570 * the condition to watch for.
571 * func:
572 * the function to call when the condition is satisfied.
573 * user_data:
574 * user data to pass to func.
575 * Returns:
576 * the event source id.
578 public uint gIoAddWatch(GIOCondition condition, GIOFunc func, void* userData)
580 // guint g_io_add_watch (GIOChannel *channel, GIOCondition condition, GIOFunc func, gpointer user_data);
581 return g_io_add_watch(gIOChannel, condition, func, userData);
585 * Adds the GIOChannel into the
586 * main event loop
587 * with the given priority.
588 * channel:
589 * a GIOChannel.
590 * priority:
591 * the priority of the GIOChannel source.
592 * condition:
593 * the condition to watch for.
594 * func:
595 * the function to call when the condition is satisfied.
596 * user_data:
597 * user data to pass to func.
598 * notify:
599 * the function to call when the source is removed.
600 * Returns:
601 * the event source id.
603 public uint gIoAddWatchFull(int priority, GIOCondition condition, GIOFunc func, void* userData, GDestroyNotify notify)
605 // guint g_io_add_watch_full (GIOChannel *channel, gint priority, GIOCondition condition, GIOFunc func, gpointer user_data, GDestroyNotify notify);
606 return g_io_add_watch_full(gIOChannel, priority, condition, func, userData, notify);
613 * Gets the buffer size.
614 * channel:
615 * a GIOChannel
616 * Returns:
617 * the size of the buffer.
619 public uint getBufferSize()
621 // gsize g_io_channel_get_buffer_size (GIOChannel *channel);
622 return g_io_channel_get_buffer_size(gIOChannel);
626 * Sets the buffer size.
627 * channel:
628 * a GIOChannel
629 * size:
630 * the size of the buffer. 0 == pick a good size
632 public void setBufferSize(uint size)
634 // void g_io_channel_set_buffer_size (GIOChannel *channel, gsize size);
635 g_io_channel_set_buffer_size(gIOChannel, size);
639 * This function returns a GIOCondition depending on whether there
640 * is data to be read/space to write data in the
641 * internal buffers in the GIOChannel. Only the flags G_IO_IN and
642 * G_IO_OUT may be set.
643 * channel:
644 * A GIOChannel
645 * Returns:
646 * A GIOCondition
648 public GIOCondition getBufferCondition()
650 // GIOCondition g_io_channel_get_buffer_condition (GIOChannel *channel);
651 return g_io_channel_get_buffer_condition(gIOChannel);
655 * Gets the current flags for a GIOChannel, including read-only
656 * flags such as G_IO_FLAG_IS_READABLE.
657 * The values of the flags G_IO_FLAG_IS_READABLE and G_IO_FLAG_IS_WRITEABLE
658 * are cached for internal use by the channel when it is created.
659 * If they should change at some later point (e.g. partial shutdown
660 * of a socket with the UNIX shutdown() function), the user
661 * should immediately call g_io_channel_get_flags() to update
662 * the internal values of these flags.
663 * channel:
664 * a GIOChannel
665 * Returns:
666 * the flags which are set on the channel
668 public GIOFlags getFlags()
670 // GIOFlags g_io_channel_get_flags (GIOChannel *channel);
671 return g_io_channel_get_flags(gIOChannel);
675 * Sets the (writeable) flags in channel to (flags G_IO_CHANNEL_SET_MASK).
676 * channel:
677 * a GIOChannel.
678 * flags:
679 * the flags to set on the IO channel.
680 * error:
681 * A location to return an error of type GIOChannelError.
682 * Returns:
683 * the status of the operation.
685 public GIOStatus setFlags(GIOFlags flags, GError** error)
687 // GIOStatus g_io_channel_set_flags (GIOChannel *channel, GIOFlags flags, GError **error);
688 return g_io_channel_set_flags(gIOChannel, flags, error);
693 * This returns the string that GIOChannel uses to determine
694 * where in the file a line break occurs. A value of NULL
695 * indicates auto detection.
696 * channel:
697 * a GIOChannel
698 * length:
699 * a location to return the length of the line terminator
700 * Returns:
701 * The line termination string. This value
702 * is owned by GLib and must not be freed.
704 public char[] getLineTerm(int* length)
706 // const gchar* g_io_channel_get_line_term (GIOChannel *channel, gint *length);
707 return Str.toString(g_io_channel_get_line_term(gIOChannel, length) );
711 * This sets the string that GIOChannel uses to determine
712 * where in the file a line break occurs.
713 * channel:
714 * a GIOChannel
715 * line_term:
716 * The line termination string. Use NULL for auto detect.
717 * Auto detection breaks on "\n", "\r\n", "\r", "\0", and
718 * the Unicode paragraph separator. Auto detection should
719 * not be used for anything other than file-based channels.
720 * length:
721 * The length of the termination string. If -1 is passed, the
722 * string is assumed to be nul-terminated. This option allows
723 * termination strings with embeded nuls.
725 public void setLineTerm(char[] lineTerm, int length)
727 // void g_io_channel_set_line_term (GIOChannel *channel, const gchar *line_term, gint length);
728 g_io_channel_set_line_term(gIOChannel, Str.toStringz(lineTerm), length);
732 * Returns whether channel is buffered.
733 * channel:
734 * a GIOChannel.
735 * Returns:
736 * TRUE if the channel is buffered.
738 public int getBuffered()
740 // gboolean g_io_channel_get_buffered (GIOChannel *channel);
741 return g_io_channel_get_buffered(gIOChannel);
745 * The buffering state can only be set if the channel's encoding
746 * is NULL. For any other encoding, the channel must be buffered.
747 * A buffered channel can only be set unbuffered if the channel's
748 * internal buffers have been flushed. Newly created channels or
749 * channels which have returned G_IO_STATUS_EOF
750 * not require such a flush. For write-only channels, a call to
751 * g_io_channel_flush() is sufficient. For all other channels,
752 * the buffers may be flushed by a call to g_io_channel_seek_position().
753 * This includes the possibility of seeking with seek type G_SEEK_CUR
754 * and an offset of zero. Note that this means that socket-based
755 * channels cannot be set unbuffered once they have had data
756 * read from them.
757 * On unbuffered channels, it is safe to mix read and write
758 * calls from the new and old APIs, if this is necessary for
759 * maintaining old code.
760 * The default state of the channel is buffered.
761 * channel:
762 * a GIOChannel
763 * buffered:
764 * whether to set the channel buffered or unbuffered
766 public void setBuffered(int buffered)
768 // void g_io_channel_set_buffered (GIOChannel *channel, gboolean buffered);
769 g_io_channel_set_buffered(gIOChannel, buffered);
773 * Gets the encoding for the input/output of the channel. The internal
774 * encoding is always UTF-8. The encoding NULL makes the
775 * channel safe for binary data.
776 * channel:
777 * a GIOChannel
778 * Returns:
779 * A string containing the encoding, this string is
780 * owned by GLib and must not be freed.
782 public char[] getEncoding()
784 // const gchar* g_io_channel_get_encoding (GIOChannel *channel);
785 return Str.toString(g_io_channel_get_encoding(gIOChannel) );
789 * Sets the encoding for the input/output of the channel. The internal
790 * encoding is always UTF-8. The default encoding for the
791 * external file is UTF-8.
792 * The encoding NULL is safe to use with binary data.
793 * The encoding can only be set if one of the following conditions
794 * is true:
795 * 1. The channel was just created, and has not been written to
796 * or read from yet.
797 * 2. The channel is write-only.
798 * 3. The channel is a file, and the file pointer was just
799 * repositioned by a call to g_io_channel_seek_position().
800 * (This flushes all the internal buffers.)
801 * 4. The current encoding is NULL or UTF-8.
802 * 5. One of the (new API) read functions has just returned G_IO_STATUS_EOF
803 * (or, in the case of g_io_channel_read_to_end(), G_IO_STATUS_NORMAL).
804 * 6. One of the functions g_io_channel_read_chars() or g_io_channel_read_unichar()
805 * has returned G_IO_STATUS_AGAIN or G_IO_STATUS_ERROR. This may be
806 * useful in the case of G_CONVERT_ERROR_ILLEGAL_SEQUENCE.
807 * Returning one of these statuses from g_io_channel_read_line(),
808 * g_io_channel_read_line_string(), or g_io_channel_read_to_end()
809 * does not guarantee that the encoding can be changed.
810 * Channels which do not meet one of the above conditions cannot call
811 * g_io_channel_seek_position() with an offset of G_SEEK_CUR,
812 * and, if they are "seekable", cannot
813 * call g_io_channel_write_chars() after calling one
814 * of the API "read" functions.
815 * channel:
816 * a GIOChannel
817 * encoding:
818 * the encoding type
819 * error:
820 * location to store an error of type GConvertError.
821 * Returns:
822 * G_IO_STATUS_NORMAL if the encoding was successfully set.
824 public GIOStatus setEncoding(char[] encoding, GError** error)
826 // GIOStatus g_io_channel_set_encoding (GIOChannel *channel, const gchar *encoding, GError **error);
827 return g_io_channel_set_encoding(gIOChannel, Str.toStringz(encoding), error);
831 * Returns whether the file/socket/whatever associated with channel
832 * will be closed when channel receives its final unref and is
833 * destroyed. The default value of this is TRUE for channels created
834 * by g_io_channel_new_file(), and FALSE for all other channels.
835 * channel:
836 * a GIOChannel.
837 * Returns:
838 * Whether the channel will be closed on the final unref of
839 * the GIOChannel data structure.
841 public int getCloseOnUnref()
843 // gboolean g_io_channel_get_close_on_unref (GIOChannel *channel);
844 return g_io_channel_get_close_on_unref(gIOChannel);
848 * Setting this flag to TRUE for a channel you have already closed
849 * can cause problems.
850 * channel:
851 * a GIOChannel
852 * do_close:
853 * Whether to close the channel on the final unref of
854 * the GIOChannel data structure. The default value of
855 * this is TRUE for channels created by g_io_channel_new_file(),
856 * and FALSE for all other channels.
858 public void setCloseOnUnref(int doClose)
860 // void g_io_channel_set_close_on_unref (GIOChannel *channel, gboolean do_close);
861 g_io_channel_set_close_on_unref(gIOChannel, doClose);
865 * Warning
866 * 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.
867 * Reads data from a GIOChannel.
868 * channel:
869 * a GIOChannel.
870 * buf:
871 * a buffer to read the data into (which should be at least count bytes long).
872 * count:
873 * the number of bytes to read from the GIOChannel.
874 * bytes_read:
875 * returns the number of bytes actually read.
876 * Returns:
877 * G_IO_ERROR_NONE if the operation was successful.
879 public GIOError read(char[] buf, uint count, uint* bytesRead)
881 // GIOError g_io_channel_read (GIOChannel *channel, gchar *buf, gsize count, gsize *bytes_read);
882 return g_io_channel_read(gIOChannel, Str.toStringz(buf), count, bytesRead);
887 * Warning
888 * 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.
889 * Writes data to a GIOChannel.
890 * channel:
891 * a GIOChannel.
892 * buf:
893 * the buffer containing the data to write.
894 * count:
895 * the number of bytes to write.
896 * bytes_written:
897 * the number of bytes actually written.
898 * Returns:
899 * G_IO_ERROR_NONE if the operation was successful.
901 public GIOError write(char[] buf, uint count, uint* bytesWritten)
903 // GIOError g_io_channel_write (GIOChannel *channel, const gchar *buf, gsize count, gsize *bytes_written);
904 return g_io_channel_write(gIOChannel, Str.toStringz(buf), count, bytesWritten);
908 * Warning
909 * 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.
910 * Sets the current position in the GIOChannel, similar to the standard library
911 * function fseek().
912 * channel:
913 * a GIOChannel.
914 * offset:
915 * an offset, in bytes, which is added to the position specified by type
916 * type:
917 * the position in the file, which can be G_SEEK_CUR (the current
918 * position), G_SEEK_SET (the start of the file), or G_SEEK_END (the end of the
919 * file).
920 * Returns:
921 * G_IO_ERROR_NONE if the operation was successful.
923 public GIOError seek(long offset, GSeekType type)
925 // GIOError g_io_channel_seek (GIOChannel *channel, gint64 offset, GSeekType type);
926 return g_io_channel_seek(gIOChannel, offset, type);
930 * Warning
931 * 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.
932 * Close an IO channel. Any pending data to be written will be
933 * flushed, ignoring errors. The channel will not be freed until the
934 * last reference is dropped using g_io_channel_unref().
935 * channel:
936 * A GIOChannel
937 * See Also
938 * gtk_input_add_full(), gtk_input_remove(), gdk_input_add(),
939 * gdk_input_add_full(), gdk_input_remove()
940 * Convenience functions for creating GIOChannel instances and adding them to the
941 * main event loop.
943 public void close()
945 // void g_io_channel_close (GIOChannel *channel);
946 g_io_channel_close(gIOChannel);