source: appstream-generator/build/girepo/glib/IOChannel.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

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