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