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