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