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