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