2 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #ifndef _GLIBMM_IOCHANNEL_H
4 #define _GLIBMM_IOCHANNEL_H
8 /* $Id: iochannel.hg,v 1.8 2006/05/12 08:08:44 murrayc Exp $ */
10 /* Copyright (C) 2002 The gtkmm Development Team
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with this library; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <glibmm/error.h>
29 #include <glibmm/main.h>
30 #include <glibmm/refptr.h>
31 #include <glibmm/ustring.h>
32 #include <glib/gtypes.h>
35 #include <glibmmconfig.h>
37 GLIBMM_USING_STD(string)
39 #ifndef DOXYGEN_SHOULD_SKIP_THIS
40 extern "C" { typedef struct _GIOChannel GIOChannel; }
50 /** @addtogroup glibmmEnums Enums and Flags */
53 * @ingroup glibmmEnums
64 * @ingroup glibmmEnums
76 * @ingroup glibmmEnums
77 * @par Bitwise operators:
78 * <tt>%IOFlags operator|(IOFlags, IOFlags)</tt><br>
79 * <tt>%IOFlags operator&(IOFlags, IOFlags)</tt><br>
80 * <tt>%IOFlags operator^(IOFlags, IOFlags)</tt><br>
81 * <tt>%IOFlags operator~(IOFlags)</tt><br>
82 * <tt>%IOFlags& operator|=(IOFlags&, IOFlags)</tt><br>
83 * <tt>%IOFlags& operator&=(IOFlags&, IOFlags)</tt><br>
84 * <tt>%IOFlags& operator^=(IOFlags&, IOFlags)</tt><br>
88 IO_FLAG_APPEND = 1 << 0,
89 IO_FLAG_NONBLOCK = 1 << 1,
90 IO_FLAG_IS_READABLE = 1 << 2,
91 IO_FLAG_IS_WRITEABLE = 1 << 3,
92 IO_FLAG_IS_SEEKABLE = 1 << 4,
93 IO_FLAG_GET_MASK = 0x0,
94 IO_FLAG_SET_MASK = 0x1
97 /** @ingroup glibmmEnums */
98 inline IOFlags operator|(IOFlags lhs, IOFlags rhs)
99 { return static_cast<IOFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
101 /** @ingroup glibmmEnums */
102 inline IOFlags operator&(IOFlags lhs, IOFlags rhs)
103 { return static_cast<IOFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
105 /** @ingroup glibmmEnums */
106 inline IOFlags operator^(IOFlags lhs, IOFlags rhs)
107 { return static_cast<IOFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
109 /** @ingroup glibmmEnums */
110 inline IOFlags operator~(IOFlags flags)
111 { return static_cast<IOFlags>(~static_cast<unsigned>(flags)); }
113 /** @ingroup glibmmEnums */
114 inline IOFlags& operator|=(IOFlags& lhs, IOFlags rhs)
115 { return (lhs = static_cast<IOFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
117 /** @ingroup glibmmEnums */
118 inline IOFlags& operator&=(IOFlags& lhs, IOFlags rhs)
119 { return (lhs = static_cast<IOFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
121 /** @ingroup glibmmEnums */
122 inline IOFlags& operator^=(IOFlags& lhs, IOFlags rhs)
123 { return (lhs = static_cast<IOFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
126 /** Exception class for IOChannel errors.
128 class IOChannelError : public Glib::Error
144 IOChannelError(Code error_code, const Glib::ustring& error_message);
145 explicit IOChannelError(GError* gobject);
148 #ifndef DOXYGEN_SHOULD_SKIP_THIS
151 #ifdef GLIBMM_EXCEPTIONS_ENABLED
152 static void throw_func(GError* gobject);
154 //When not using exceptions, we just pass the Exception object around without throwing it:
155 static std::auto_ptr<Glib::Error> throw_func(GError* gobject);
156 #endif //GLIBMM_EXCEPTIONS_ENABLED
158 friend void wrap_init(); // uses throw_func()
163 #ifndef DOXYGEN_SHOULD_SKIP_THIS
164 class GlibmmIOChannel;
167 /** IOChannel aims to provide portable I/O support for files, pipes
168 * and sockets, and to integrate them with the GLib main event loop.
170 * Note that IOChannels implement an automatic implicit character set
171 * conversion to the data stream, and usually will not pass by default
172 * binary data unchanged. To set the encoding of the channel, use e.g.
173 * set_encoding("ISO-8859-15"). To set the channel to no encoding, use
174 * set_encoding() without any arguments.
176 * You can create an IOChannel with one of the static create methods, or
177 * implement one yourself, in which case you have to 1) override all
178 * _vfunc() members. 2) set the GIOChannel flags in your constructor.
180 * @note This feature of being able to implement a custom Glib::IOChannel is
181 * deprecated in glibmm 2.2. The vfunc interface has not yet stabilized
182 * enough to allow that -- the C++ wrapper went in by pure accident. Besides,
183 * it isn't terribly useful either. Thus please refrain from overriding any
186 class IOChannel : public sigc::trackable
189 #ifndef DOXYGEN_SHOULD_SKIP_THIS
190 typedef IOChannel CppObjectType;
191 typedef GIOChannel BaseObjectType;
192 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
198 virtual ~IOChannel();
200 /** Open a file @a filename as an I/O channel using mode @a mode.
201 * This channel will be closed when the last reference to it is dropped,
202 * so there is no need to call close() (though doing so will not cause
203 * problems, as long as no attempt is made to access the channel after
205 * @param filename The name of the file to open.
206 * @param mode One of <tt>"r"</tt>, <tt>"w"</tt>, <tt>"a"</tt>,
207 * <tt>"r+"</tt>, <tt>"w+"</tt>, <tt>"a+"</tt>. These have the
208 * same meaning as in <tt>fopen()</tt>.
209 * @return An IOChannel for the opened file.
210 * @throw Glib::FileError
212 #ifdef GLIBMM_EXCEPTIONS_ENABLED
213 static Glib::RefPtr<IOChannel> create_from_file(const std::string& filename, const std::string& mode);
215 static Glib::RefPtr<IOChannel> create_from_file(const std::string& filename, const std::string& mode, std::auto_ptr<Glib::Error>& error);
216 #endif //GLIBMM_EXCEPTIONS_ENABLED
219 /** Creates an I/O channel from a file descriptor.
220 * On Unix, IOChannels created with this function work for any file
221 * descriptor or socket.
223 * On Win32, this can be used either for files opened with the MSVCRT (the
224 * Microsoft run-time C library) <tt>_open()</tt> or <tt>_pipe()</tt>,
225 * including file descriptors 0, 1 and 2 (corresponding to <tt>stdin</tt>,
226 * <tt>stdout</tt> and <tt>stderr</tt>), or for Winsock <tt>SOCKET</tt>s. If
227 * the parameter is a legal file descriptor, it is assumed to be such,
228 * otherwise it should be a <tt>SOCKET</tt>. This relies on <tt>SOCKET</tt>s
229 * and file descriptors not overlapping. If you want to be certain, call
230 * either create_from_win32_fd() or create_from_win32_socket() instead as
233 * The term file descriptor as used in the context of Win32 refers to the
234 * emulated Unix-like file descriptors MSVCRT provides. The native
235 * corresponding concept is file <tt>HANDLE</tt>. There isn't as of yet
236 * a way to get IOChannels for Win32 file <tt>HANDLE</tt>s.
238 static Glib::RefPtr<IOChannel> create_from_fd(int fd);
241 /* defined(DOXYGEN_SHOULD_SKIP_THIS) actually does the opposite of what it looks like... */
242 #if defined(G_OS_WIN32) || defined(DOXYGEN_SHOULD_SKIP_THIS)
244 /** Create an I/O channel for C runtime (emulated Unix-like) file descriptors.
245 * After calling add_watch() on a I/O channel returned by this function, you
246 * shouldn't call read() on the file descriptor. This is because adding
247 * polling for a file descriptor is implemented on Win32 by starting a thread
248 * that sits blocked in a <tt>%read()</tt> from the file descriptor most of
249 * the time. All reads from the file descriptor should be done by this
250 * internal GLib thread. Your code should call only IOChannel::read().
252 static Glib::RefPtr<IOChannel> create_from_win32_fd(int fd);
255 /** Create an I/O channel for a winsock socket. The parameter should be a
256 * <tt>SOCKET</tt>. Contrary to I/O channels for file descriptors (on Win32),
257 * you can use normal <tt>recv()</tt> or <tt>recvfrom()</tt> on sockets even
258 * if GLib is polling them.
260 static Glib::RefPtr<IOChannel> create_from_win32_socket(int socket);
263 #endif /* defined(G_OS_WIN32) || defined(DOXYGEN_SHOULD_SKIP_THIS) */
265 /** Read a single UCS-4 character.
266 * @retval thechar The Unicode character.
267 * @return The status of the operation.
268 * @throw Glib::IOChannelError
269 * @throw Glib::ConvertError
272 /** This function cannot be called on a channel with <tt>0</tt> encoding.
273 * @param thechar A location to return a character.
274 * @param error A location to return an error of type G::ConvertError
275 * or G::IOChannelError.
276 * @return A G::IOStatus.
278 #ifdef GLIBMM_EXCEPTIONS_ENABLED
279 IOStatus read(gunichar& thechar);
281 IOStatus read(gunichar& thechar, std::auto_ptr<Glib::Error>& error);
282 #endif //GLIBMM_EXCEPTIONS_ENABLED
285 /** Read a character sequence into memory.
286 * @param buf A buffer to read data into.
287 * @param count The size of the buffer in bytes. Note that the buffer may
288 * not be complelely filled even if there is data in the buffer if the
289 * remaining data is not a complete character.
290 * @retval bytes_read The number of bytes read. This may be zero even on
291 * success if @a count < 6 and the channel's encoding is not <tt>""</tt>.
292 * This indicates that the next UTF-8 character is too wide for the buffer.
293 * @return The status of the operation.
294 * @throw Glib::IOChannelError
295 * @throw Glib::ConvertError
298 /** Replacement for g_io_channel_read() with the new API.
299 * @param buf A buffer to read data into.
300 * @param count The size of the buffer. Note that the buffer may
301 * not be complelely filled even if there is data
302 * in the buffer if the remaining data is not a
303 * complete character.
304 * @param bytes_read The number of bytes read. This may be zero even on
305 * success if count < 6 and the channel's encoding is non-<tt>0</tt>.
306 * This indicates that the next UTF-8 character is too wide for
308 * @param error A location to return an error of type G::ConvertError
309 * or G::IOChannelError.
310 * @return The status of the operation.
312 #ifdef GLIBMM_EXCEPTIONS_ENABLED
313 IOStatus read(char* buf, gsize count, gsize& bytes_read);
315 IOStatus read(char* buf, gsize count, gsize& bytes_read, std::auto_ptr<Glib::Error>& error);
316 #endif //GLIBMM_EXCEPTIONS_ENABLED
319 /** Read a maximum of @a count bytes into @a str.
320 * @param count The maximum number of bytes to read.
321 * @retval str The characters that have been read.
322 * @return The status of the operation.
323 * @throw Glib::IOChannelError
324 * @throw Glib::ConvertError
326 #ifdef GLIBMM_EXCEPTIONS_ENABLED
327 IOStatus read(Glib::ustring& str, gsize count);
329 IOStatus read(Glib::ustring& str, gsize count, std::auto_ptr<Glib::Error>& error);
330 #endif //GLIBMM_EXCEPTIONS_ENABLED
332 /** Read a whole line.
333 * Reads until the line separator is found, which is included
334 * in the result string.
335 * @retval line The line that was read.
336 * @return The status of the operation.
337 * @throw Glib::IOChannelError
338 * @throw Glib::ConvertError
340 #ifdef GLIBMM_EXCEPTIONS_ENABLED
341 IOStatus read_line(Glib::ustring& line);
343 IOStatus read_line(Glib::ustring& line, std::auto_ptr<Glib::Error>& error);
344 #endif //GLIBMM_EXCEPTIONS_ENABLED
347 /** Reads all the remaining data from the file.
348 * @retval str The resulting string.
349 * @return Glib::IO_STATUS_NORMAL on success. This function never
350 * returns Glib::IO_STATUS_EOF.
351 * @throw Glib::IOChannelError
352 * @throw Glib::ConvertError
354 #ifdef GLIBMM_EXCEPTIONS_ENABLED
355 IOStatus read_to_end(Glib::ustring& str);
357 IOStatus read_to_end(Glib::ustring& str, std::auto_ptr<Glib::Error>& error);
358 #endif //GLIBMM_EXCEPTIONS_ENABLED
361 /** Write a string to the I/O channel.
362 * Note that this method does not return the number of characters written.
363 * If the channel is blocking and the returned value is
364 * Glib::IO_STATUS_NORMAL, the whole string was written.
365 * @param str the string to write.
366 * @return The status of the operation.
367 * @throw Glib::IOChannelError
368 * @throw Glib::ConvertError
370 #ifdef GLIBMM_EXCEPTIONS_ENABLED
371 IOStatus write(const Glib::ustring& str);
373 IOStatus write(const Glib::ustring& str, std::auto_ptr<Glib::Error>& error);
374 #endif //GLIBMM_EXCEPTIONS_ENABLED
376 /** Write a memory area of @a count bytes to the I/O channel.
377 * @param buf The start of the memory area.
378 * @param count The number of bytes to write.
379 * @retval bytes_written The number of bytes written to the channel.
380 * @return The status of the operation.
381 * @throw Glib::IOChannelError
382 * @throw Glib::ConvertError
385 /** Replacement for g_io_channel_write() with the new API.
387 * On seekable channels with encodings other than <tt>0</tt> or UTF-8, generic
388 * mixing of reading and writing is not allowed. A call to g_io_channel_write_chars()
389 * may only be made on a channel from which data has been read in the
390 * cases described in the documentation for g_io_channel_set_encoding().
391 * @param buf A buffer to write data from.
392 * @param count The size of the buffer. If -1, the buffer
393 * is taken to be a nul-terminated string.
394 * @param bytes_written The number of bytes written. This can be nonzero
395 * even if the return value is not G::IO_STATUS_NORMAL.
396 * If the return value is G::IO_STATUS_NORMAL and the
397 * channel is blocking, this will always be equal
398 * to @a count if @a count >= 0.
399 * @param error A location to return an error of type G::ConvertError
400 * or G::IOChannelError.
401 * @return The status of the operation.
403 #ifdef GLIBMM_EXCEPTIONS_ENABLED
404 IOStatus write(const char* buf, gssize count, gsize& bytes_written);
406 IOStatus write(const char* buf, gssize count, gsize& bytes_written, std::auto_ptr<Glib::Error>& error);
407 #endif //GLIBMM_EXCEPTIONS_ENABLED
410 /** Write a single UCS-4 character to the I/O channel.
411 * @param unichar The character to write.
412 * @return The status of the operation.
413 * @throw Glib::IOChannelError
414 * @throw Glib::ConvertError
417 /** This function cannot be called on a channel with <tt>0</tt> encoding.
418 * @param thechar A character.
419 * @param error A location to return an error of type G::ConvertError
420 * or G::IOChannelError.
421 * @return A G::IOStatus.
423 #ifdef GLIBMM_EXCEPTIONS_ENABLED
424 IOStatus write(gunichar unichar);
426 IOStatus write(gunichar unichar, std::auto_ptr<Glib::Error>& error);
427 #endif //GLIBMM_EXCEPTIONS_ENABLED
430 /** Seek the I/O channel to a specific position.
431 * @param offset The offset in bytes from the position specified by @a type.
432 * @param type A SeekType. The type Glib::SEEK_TYPE_CUR is only allowed in
433 * those cases where a call to set_encoding() is allowed. See the
434 * documentation for set_encoding() for details.
435 * @return The status of the operation.
436 * @throw Glib::IOChannelError
437 * @throw Glib::ConvertError
440 /** Replacement for g_io_channel_seek() with the new API.
441 * @param offset The offset in bytes from the position specified by @a type .
442 * @param type A G::SeekType. The type G::SEEK_CUR is only allowed in those
443 * cases where a call to g_io_channel_set_encoding()
444 * is allowed. See the documentation for
445 * g_io_channel_set_encoding() for details.
446 * @param error A location to return an error of type G::IOChannelError.
447 * @return The status of the operation.
449 #ifdef GLIBMM_EXCEPTIONS_ENABLED
450 IOStatus seek(gint64 offset, SeekType type = SEEK_TYPE_SET);
452 IOStatus seek(gint64 offset, SeekType type, std::auto_ptr<Glib::Error>& error);
453 #endif //GLIBMM_EXCEPTIONS_ENABLED
456 /** Flush the buffers of the I/O channel.
457 * @return The status of the operation.
458 * @throw Glib::IOChannelError
459 * @throw Glib::ConvertError
462 /** Flushes the write buffer for the GIOChannel.
463 * @param error Location to store an error of type G::IOChannelError.
464 * @return The status of the operation: One of
465 * G::IO_CHANNEL_NORMAL, G::IO_CHANNEL_AGAIN, or
466 * G::IO_CHANNEL_ERROR.
468 #ifdef GLIBMM_EXCEPTIONS_ENABLED
471 IOStatus flush(std::auto_ptr<Glib::Error>& error);
472 #endif //GLIBMM_EXCEPTIONS_ENABLED
475 /** Close the I/O channel.
476 * Any pending data to be written will be flushed if @a flush is <tt>true</tt>.
477 * The channel will not be freed until the last reference is dropped.
478 * Accessing the channel after closing it is considered an error.
479 * @param flush Whether to flush() pending data before closing the channel.
480 * @return The status of the operation.
481 * @throw Glib::IOChannelError
484 /** Close an IO channel. Any pending data to be written will be
485 * flushed if @a flush is <tt>true</tt>. The channel will not be freed until the
486 * last reference is dropped using g_io_channel_unref().
487 * @param flush If <tt>true</tt>, flush pending.
488 * @param err Location to store a G::IOChannelError.
489 * @return The status of the operation.
491 #ifdef GLIBMM_EXCEPTIONS_ENABLED
492 IOStatus close(bool flush = true);
494 IOStatus close(bool flush, std::auto_ptr<Glib::Error>& error);
495 #endif //GLIBMM_EXCEPTIONS_ENABLED
498 /** Get the IOChannel internal buffer size.
499 * @return The buffer size.
502 /** Gets the buffer size.
503 * @return The size of the buffer.
505 gsize get_buffer_size() const;
507 /** Set the internal IOChannel buffer size.
508 * @param size The buffer size the IOChannel should use.
511 /** Sets the buffer size.
512 * @param size The size of the buffer. 0 == pick a good size.
514 void set_buffer_size(gsize size);
516 /** Get the current flags for a IOChannel, including read-only
517 * flags such as Glib::IO_FLAG_IS_READABLE.
519 * The values of the flags Glib::IO_FLAG_IS_READABLE and
520 * Glib::IO_FLAG_IS_WRITEABLE are cached for internal use by the channel when
521 * it is created. If they should change at some later point (e.g. partial
522 * shutdown of a socket with the UNIX <tt>shutdown()</tt> function), the user
523 * should immediately call get_flags() to update the internal values of these
525 * @return Bitwise combination of the flags set on the channel.
528 /** Gets the current flags for a G::IOChannel, including read-only
529 * flags such as G::IO_FLAG_IS_READABLE.
531 * The values of the flags G::IO_FLAG_IS_READABLE and G::IO_FLAG_IS_WRITEABLE
532 * are cached for internal use by the channel when it is created.
533 * If they should change at some later point (e.g. partial shutdown
534 * of a socket with the UNIX shutdown() function), the user
535 * should immediately call g_io_channel_get_flags() to update
536 * the internal values of these flags.
537 * @return The flags which are set on the channel.
539 IOFlags get_flags() const;
541 /** Set flags on the IOChannel.
542 * @param flags Bitwise combination of the flags to set.
543 * @return The operation result code.
544 * @throw Glib::IOChannelError
547 /** Sets the (writeable) flags in @a channel to ( @a flags & G::IO_CHANNEL_SET_MASK).
548 * @param flags The flags to set on the IO channel.
549 * @param error A location to return an error of type G::IOChannelError.
550 * @return The status of the operation.
552 #ifdef GLIBMM_EXCEPTIONS_ENABLED
553 IOStatus set_flags(IOFlags flags);
555 IOStatus set_flags(IOFlags flags, std::auto_ptr<Glib::Error>& error);
556 #endif //GLIBMM_EXCEPTIONS_ENABLED
559 /** Set the buffering status of the I/O channel.
560 * The buffering state can only be set if the channel's encoding is
561 * <tt>""</tt>. For any other encoding, the channel must be buffered.
563 * A buffered channel can only be set unbuffered if the channel's internal
564 * buffers have been flushed. Newly created channels or channels which have
565 * returned Glib::IO_STATUS_EOF not require such a flush. For write-only
566 * channels, a call to flush() is sufficient. For all other channels, the
567 * buffers may be flushed by a call to seek(). This includes the possibility
568 * of seeking with seek type Glib::SEEK_TYPE_CUR and an offset of zero. Note
569 * that this means that socket-based channels cannot be set unbuffered once
570 * they have had data read from them.
572 * The default state of the channel is buffered.
574 * @param buffered Whether to set the channel buffered or unbuffered.
577 /** The buffering state can only be set if the channel's encoding
578 * is <tt>0</tt>. For any other encoding, the channel must be buffered.
580 * A buffered channel can only be set unbuffered if the channel's
581 * internal buffers have been flushed. Newly created channels or
582 * channels which have returned G::IO_STATUS_EOF
583 * not require such a flush. For write-only channels, a call to
584 * g_io_channel_flush() is sufficient. For all other channels,
585 * the buffers may be flushed by a call to g_io_channel_seek_position().
586 * This includes the possibility of seeking with seek type G::SEEK_CUR
587 * and an offset of zero. Note that this means that socket-based
588 * channels cannot be set unbuffered once they have had data
591 * On unbuffered channels, it is safe to mix read and write
592 * calls from the new and old APIs, if this is necessary for
593 * maintaining old code.
595 * The default state of the channel is buffered.
596 * @param buffered Whether to set the channel buffered or unbuffered.
598 void set_buffered(bool buffered);
600 /** Get the buffering status of the I/O channel.
601 * @return The buffering status of the channel.
604 /** Return Value: <tt>true</tt> if the @a channel is buffered.
605 * @return <tt>true</tt> if the @a channel is buffered.
607 bool get_buffered() const;
609 /** Returns an IOCondition depending on whether there is data to be
610 * read/space to write data in the internal buffers in the I/O channel.
611 * Only the flags Glib::IO_IN and Glib::IO_OUT may be set.
612 * @return Bitwise combination of Glib::IOCondition flags.
615 /** This function returns a G::IOCondition depending on whether there
616 * is data to be read/space to write data in the
617 * internal buffers in the G::IOChannel. Only the flags G::IO_IN and
618 * G::IO_OUT may be set.
619 * @return A G::IOCondition.
621 IOCondition get_buffer_condition() const;
623 /** Returns whether the file/socket/whatever associated with the I/O channel
624 * will be closed when the channel receives its final unref and is destroyed.
625 * The default value of this is <tt>true</tt> for channels created by
626 * create_from_file(), and <tt>false</tt> for all other channels.
627 * @return Whether the channel will be closed on the final unref of the
631 /** Return value: Whether the channel will be closed on the final unref of
632 * @return Whether the channel will be closed on the final unref of
633 * the GIOChannel data structure.
635 bool get_close_on_unref() const;
637 /** Setting this flag to <tt>true</tt> for a channel you have already closed
638 * can cause problems.
639 * @param do_close Whether to close the channel on the final unref of the
640 * IOChannel object. The default value of this is <tt>true</tt> for channels
641 * created by create_from_file(), and <tt>false</tt> for all other channels.
644 /** Setting this flag to <tt>true</tt> for a channel you have already closed
645 * can cause problems.
646 * @param do_close Whether to close the channel on the final unref of
647 * the GIOChannel data structure. The default value of
648 * this is <tt>true</tt> for channels created by g_io_channel_new_file(),
649 * and <tt>false</tt> for all other channels.
651 void set_close_on_unref(bool do_close);
653 /** Sets the encoding for the input/output of the channel.
654 * The internal encoding is always UTF-8. The default encoding for the
655 * external file is UTF-8. The encoding <tt>""</tt> is safe to use with
658 * The encoding can only be set if one of the following conditions
661 * -# The channel was just created, and has not been written to or read from
663 * -# The channel is write-only.
664 * -# The channel is a file, and the file pointer was just repositioned by a
665 * call to seek_position(). (This flushes all the internal buffers.)
666 * -# The current encoding is <tt>""</tt> or UTF-8.
667 * -# One of the read methods has just returned Glib::IO_STATUS_EOF (or, in
668 * the case of read_to_end(), Glib::IO_STATUS_NORMAL).
669 * -# The read() method has returned Glib::IO_STATUS_AGAIN or thrown
670 * a Glib::Error exception. This may be useful in the case of
671 * ConvertError::ILLEGAL_SEQUENCE. Returning one of these statuses
672 * from read_line() or read_to_end() does <em>not</em> guarantee that
673 * the encoding can be changed.
675 * Channels which do not meet one of the above conditions cannot call
676 * seek_position() with a seek type of Glib::SEEK_TYPE_CUR and, if they
677 * are "seekable", cannot call write() after calling one of the API
680 * @param encoding The encoding name, or <tt>""</tt> for binary.
681 * @return Glib::IO_STATUS_NORMAL if the encoding was successfully set.
682 * @throw Glib::IOChannelError
684 #ifdef GLIBMM_EXCEPTIONS_ENABLED
685 IOStatus set_encoding(const std::string& encoding = std::string());
687 IOStatus set_encoding(const std::string& encoding, std::auto_ptr<Glib::Error>& error);
688 #endif //GLIBMM_EXCEPTIONS_ENABLED
691 /** Get the encoding of the I/O channel.
692 * @return The current encoding of the channel.
694 std::string get_encoding() const;
697 void set_line_term(const std::string& term = std::string());
700 std::string get_line_term() const;
703 /** Creates an IOSource object.
704 * Create a slot from a function to be called when condition is met
705 * for the channel with sigc::ptr_fun() or sigc::mem_fun() and pass
706 * it into the connect() function of the returned IOSource object.
707 * Polling of the channel will start when you attach a MainContext
708 * object to the returned IOSource object using its attach() function.
710 * Glib::signal_io().connect() is a simpler interface to the same
711 * functionality, for the case where you want to add the source to the
712 * default main context.
713 * @param condition The condition to watch for.
714 * @return An IOSource object that can be polled from a MainContext's event loop.
716 Glib::RefPtr<IOSource> create_watch(IOCondition condition);
719 virtual void reference() const;
720 virtual void unreference() const;
723 GIOChannel* gobj() { return gobject_; }
724 const GIOChannel* gobj() const { return gobject_; }
727 GIOChannel* gobject_;
729 /** Constructor that should be used by derived classes.
730 * Use this constructor if you want to inherit from IOChannel.
731 * It will set up a GIOChannel that will call the vfuncs of your
732 * class even if it is being used from C code, and it will keep
733 * a reference to the C++ code while the GIOChannel exists.
738 #ifndef DOXYGEN_SHOULD_SKIP_THIS
739 IOChannel(GIOChannel* gobject, bool take_copy);
742 virtual IOStatus read_vfunc(char* buf, gsize count, gsize& bytes_read);
743 virtual IOStatus write_vfunc(const char* buf, gsize count, gsize& bytes_written);
744 virtual IOStatus seek_vfunc(gint64 offset, SeekType type);
745 virtual IOStatus close_vfunc();
746 virtual IOStatus set_flags_vfunc(IOFlags flags);
747 virtual IOFlags get_flags_vfunc();
748 virtual Glib::RefPtr<Glib::Source> create_watch_vfunc(IOCondition cond);
750 #ifndef DOXYGEN_SHOULD_SKIP_THIS
751 friend class Glib::GlibmmIOChannel;
757 Glib::RefPtr<IOChannel> wrap(GIOChannel* gobject, bool take_copy = false);
762 #endif /* _GLIBMM_IOCHANNEL_H */