rollback to 3428, before the mysterious removal of libs/* at 3431/3432
[ardour.git] / libs / glibmm2 / glib / glibmm / iochannel.cc
1 // Generated by gtkmmproc -- DO NOT MODIFY!
2
3
4 #include <glibmm/iochannel.h>
5 #include <glibmm/private/iochannel_p.h>
6
7 // -*- c++ -*-
8 /* $Id: iochannel.ccg,v 1.6 2006/10/04 12:04:09 murrayc Exp $ */
9
10 /* Copyright (C) 2002 The gtkmm Development Team
11  *
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.
16  *
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.
21  *
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.
25  */
26
27 #include <glibmm/exceptionhandler.h>
28 #include <glibmm/iochannel.h>
29 #include <glibmm/utility.h>
30 #include <glibmm/main.h>
31 #include <glib.h>
32
33
34 namespace
35 {
36
37 // Glib::IOChannel reference counting issues:
38 //
39 // Normally, you'd expect that the C++ object stays around as long as the
40 // C instance does.  Also Glib::wrap() usually returns always the same C++
41 // wrapper object for a single C instance.
42 //
43 // Unfortunately it isn't possible to implement these features if we didn't
44 // create the underlying GIOChannel.  That is, when wrapping existing
45 // GIOChannel instances such as returned by e.g. g_io_channel_unix_new() or
46 // g_io_channel_new_file().  Neither is there a way to hook up a wrapper
47 // object in an existing GIOChannel, nor exists any destroy notification.
48 //
49 // So that means:  If the IOChannel is implemented in C++ -- that is, our
50 // GlibmmIOChannel backend is used -- we use the GIOChannel reference
51 // counting mechanism.  If the IOChannel backend is unknown, then the
52 // wrapper instance holds always exactly one reference to the GIOChannel.
53 // The wrapper object itself is then managed via our own refcounting
54 // mechanism.  To do that a utility class ForeignIOChannel is introduced to
55 // override reference() and unreference().
56
57 class ForeignIOChannel : public Glib::IOChannel
58 {
59 public:
60   ForeignIOChannel(GIOChannel* gobject, bool take_copy)
61     : Glib::IOChannel(gobject, take_copy), ref_count_(0) {}
62
63   virtual void reference()   const;
64   virtual void unreference() const;
65
66 private:
67   mutable int ref_count_;
68 };
69
70 void ForeignIOChannel::reference() const
71 {
72   ++ref_count_;
73 }
74
75 void ForeignIOChannel::unreference() const
76 {
77   if (!(--ref_count_)) delete this;
78 }
79
80 } // anonymous namespace
81
82
83 namespace Glib
84 {
85
86 class GlibmmIOChannel
87 {
88 public:
89   GIOChannel        base;
90   Glib::IOChannel*  wrapper;
91
92   static const GIOFuncs vfunc_table;
93
94   static GIOStatus io_read(GIOChannel* channel, char* buf, gsize count,
95                            gsize* bytes_read, GError** err);
96
97   static GIOStatus io_write(GIOChannel* channel, const char* buf, gsize count,
98                             gsize* bytes_written, GError** err);
99
100   static GIOStatus io_seek (GIOChannel* channel, gint64 offset, GSeekType type, GError** err);
101   static GIOStatus io_close(GIOChannel* channel, GError** err);
102
103   static GSource*  io_create_watch(GIOChannel* channel, GIOCondition condition);
104   static void      io_free(GIOChannel* channel);
105
106   static GIOStatus io_set_flags(GIOChannel* channel, GIOFlags flags, GError** err);
107   static GIOFlags  io_get_flags(GIOChannel* channel);
108 };
109
110 // static
111 const GIOFuncs GlibmmIOChannel::vfunc_table =
112 {
113   &GlibmmIOChannel::io_read,
114   &GlibmmIOChannel::io_write,
115   &GlibmmIOChannel::io_seek,
116   &GlibmmIOChannel::io_close,
117   &GlibmmIOChannel::io_create_watch,
118   &GlibmmIOChannel::io_free,
119   &GlibmmIOChannel::io_set_flags,
120   &GlibmmIOChannel::io_get_flags,
121 };
122
123
124 /**** GLib::IOChannel ******************************************************/
125
126 /* Construct a custom C++-implemented IOChannel.  GlibmmIOChannel is an
127  * extended GIOChannel struct which allows us to hook up a pointer to this
128  * persistent wrapper instance.
129  */
130 IOChannel::IOChannel()
131 :
132   gobject_ (static_cast<GIOChannel*>(g_malloc(sizeof(GlibmmIOChannel))))
133 {
134   g_io_channel_init(gobject_);
135   gobject_->funcs = const_cast<GIOFuncs*>(&GlibmmIOChannel::vfunc_table);
136
137   reinterpret_cast<GlibmmIOChannel*>(gobject_)->wrapper = this;
138 }
139
140 /* Construct an IOChannel wrapper for an already created GIOChannel.
141  * See the comment at the top of this file for an explanation of the
142  * problems with this approach.
143  */
144 IOChannel::IOChannel(GIOChannel* gobject, bool take_copy)
145 :
146   gobject_ (gobject)
147 {
148   // This ctor should never be called for GlibmmIOChannel instances.
149   g_assert(gobject != 0);
150   g_assert(gobject->funcs != &GlibmmIOChannel::vfunc_table);
151
152   if(take_copy)
153     g_io_channel_ref(gobject_);
154 }
155
156 IOChannel::~IOChannel()
157 {
158   if(gobject_)
159   {
160     // Check whether this IOChannel is implemented in C++, i.e. whether it
161     // uses our GlibmmIOChannel forwarding backend.  Normally, this will never
162     // be true because the wrapper should only be deleted in the io_free()
163     // callback, which clears gobject_ before deleting.  But in case the ctor
164     // of a derived class threw an exception the GIOChannel must be destroyed
165     // prematurely.
166     //
167     if(gobject_->funcs == &GlibmmIOChannel::vfunc_table)
168     {
169       // Disconnect the wrapper object so that it won't be deleted twice.
170       reinterpret_cast<GlibmmIOChannel*>(gobject_)->wrapper = 0;
171     }
172
173     GIOChannel *const tmp_gobject = gobject_;
174     gobject_ = 0;
175
176     g_io_channel_unref(tmp_gobject);
177   }
178 }
179
180 #ifdef GLIBMM_EXCEPTIONS_ENABLED
181 Glib::RefPtr<IOChannel> IOChannel::create_from_file(const std::string& filename, const std::string& mode)
182 #else
183 Glib::RefPtr<IOChannel> IOChannel::create_from_file(const std::string& filename, const std::string& mode, std::auto_ptr<Glib::Error>& error)
184 #endif //GLIBMM_EXCEPTIONS_ENABLED
185 {
186   GError* gerror = 0;
187   GIOChannel *const channel = g_io_channel_new_file(filename.c_str(), mode.c_str(), &gerror);
188
189   if(gerror)
190   {
191     #ifdef GLIBMM_EXCEPTIONS_ENABLED
192     Glib::Error::throw_exception(gerror);
193     #else
194     error = Glib::Error::throw_exception(gerror);
195     #endif //GLIBMM_EXCEPTIONS_ENABLED
196   }
197
198   return Glib::wrap(channel, false);
199 }
200
201 Glib::RefPtr<IOChannel> IOChannel::create_from_fd(int fd)
202 {
203   return Glib::wrap(g_io_channel_unix_new(fd), false);
204 }
205
206 #ifdef G_OS_WIN32
207
208 Glib::RefPtr<IOChannel> IOChannel::create_from_win32_fd(int fd)
209 {
210   return Glib::wrap(g_io_channel_win32_new_fd(fd), false);
211 }
212
213 Glib::RefPtr<IOChannel> IOChannel::create_from_win32_socket(int socket)
214 {
215   return Glib::wrap(g_io_channel_win32_new_socket(socket), false);
216 }
217
218 #endif /* G_OS_WIN32 */
219
220 #ifdef GLIBMM_EXCEPTIONS_ENABLED
221 IOStatus IOChannel::write(const Glib::ustring& str)
222 #else
223 IOStatus IOChannel::write(const Glib::ustring& str, std::auto_ptr<Glib::Error>& error)
224 #endif //GLIBMM_EXCEPTIONS_ENABLED
225 {
226   gsize bytes_written = 0;
227 #ifdef GLIBMM_EXCEPTIONS_ENABLED
228   return write(str.data(), str.bytes(), bytes_written);
229 #else
230   return write(str.data(), str.bytes(), bytes_written, error);
231 #endif //GLIBMM_EXCEPTIONS_ENABLED
232 }
233
234 #ifdef GLIBMM_EXCEPTIONS_ENABLED
235 IOStatus IOChannel::read_line(Glib::ustring& line)
236 #else
237 IOStatus IOChannel::read_line(Glib::ustring& line, std::auto_ptr<Glib::Error>& error)
238 #endif //GLIBMM_EXCEPTIONS_ENABLED
239 {
240   Glib::ScopedPtr<char> buf;
241   GError* gerror = 0;
242   gsize   bytes = 0;
243
244   const GIOStatus status = g_io_channel_read_line(gobj(), buf.addr(), &bytes, 0, &gerror);
245
246   if(gerror)
247   {
248     #ifdef GLIBMM_EXCEPTIONS_ENABLED
249     Glib::Error::throw_exception(gerror);
250     #else
251     error = Glib::Error::throw_exception(gerror);
252     #endif //GLIBMM_EXCEPTIONS_ENABLED
253   }
254
255   if(buf.get())
256     line.assign(buf.get(), buf.get() + bytes);
257   else
258     line.erase();
259
260   return (IOStatus) status;
261 }
262
263 #ifdef GLIBMM_EXCEPTIONS_ENABLED
264 IOStatus IOChannel::read_to_end(Glib::ustring& str)
265 #else
266 IOStatus IOChannel::read_to_end(Glib::ustring& str, std::auto_ptr<Glib::Error>& error)
267 #endif //GLIBMM_EXCEPTIONS_ENABLED
268 {
269   Glib::ScopedPtr<char> buf;
270   GError* gerror = 0;
271   gsize   bytes = 0;
272
273   const GIOStatus status = g_io_channel_read_to_end(gobj(), buf.addr(), &bytes, &gerror);
274
275   if(gerror)
276   {
277     #ifdef GLIBMM_EXCEPTIONS_ENABLED
278     Glib::Error::throw_exception(gerror);
279     #else
280     error = Glib::Error::throw_exception(gerror);
281     #endif //GLIBMM_EXCEPTIONS_ENABLED
282   }
283
284   if(buf.get())
285     str.assign(buf.get(), buf.get() + bytes);
286   else
287     str.erase();
288
289   return (IOStatus) status;
290 }
291
292 #ifdef GLIBMM_EXCEPTIONS_ENABLED
293 IOStatus IOChannel::read(Glib::ustring& str, gsize count)
294 #else
295 IOStatus IOChannel::read(Glib::ustring& str, gsize count, std::auto_ptr<Glib::Error>& error)
296 #endif //GLIBMM_EXCEPTIONS_ENABLED
297 {
298   Glib::ScopedPtr<char> buf (g_new(char, count));
299   GError* gerror = 0;
300   gsize   bytes = 0;
301
302   const GIOStatus status = g_io_channel_read_chars(gobj(), buf.get(), count, &bytes, &gerror);
303
304  if(gerror)
305   {
306     #ifdef GLIBMM_EXCEPTIONS_ENABLED
307     Glib::Error::throw_exception(gerror);
308     #else
309     error = Glib::Error::throw_exception(gerror);
310     #endif //GLIBMM_EXCEPTIONS_ENABLED
311   }
312
313   if(buf.get())
314     str.assign(buf.get(), buf.get() + bytes);
315   else
316     str.erase();
317
318   return (IOStatus) status;
319 }
320
321 #ifdef GLIBMM_EXCEPTIONS_ENABLED
322 IOStatus IOChannel::set_encoding(const std::string& encoding)
323 #else
324 IOStatus IOChannel::set_encoding(const std::string& encoding, std::auto_ptr<Glib::Error>& error)
325 #endif //GLIBMM_EXCEPTIONS_ENABLED
326 {
327   GError* gerror = 0;
328
329   const GIOStatus status = g_io_channel_set_encoding(
330       gobj(), (encoding.empty()) ? 0 : encoding.c_str(), &gerror);
331
332   if(gerror)
333   {
334     #ifdef GLIBMM_EXCEPTIONS_ENABLED
335     Glib::Error::throw_exception(gerror);
336     #else
337     error = Glib::Error::throw_exception(gerror);
338     #endif //GLIBMM_EXCEPTIONS_ENABLED
339   }
340
341   return (IOStatus) status;
342 }
343
344 std::string IOChannel::get_encoding() const
345 {
346   const char *const encoding = g_io_channel_get_encoding(gobject_);
347   return (encoding) ? std::string(encoding) : std::string();
348 }
349
350 void IOChannel::set_line_term(const std::string& term)
351 {
352   if(term.empty())
353     g_io_channel_set_line_term(gobj(), 0, 0);
354   else
355     g_io_channel_set_line_term(gobj(), term.data(), term.size());
356 }
357
358 std::string IOChannel::get_line_term() const
359 {
360   int len = 0;
361   const char *const term = g_io_channel_get_line_term(gobject_, &len);
362
363   return (term) ? std::string(term, len) : std::string();
364 }
365
366 Glib::RefPtr<IOSource> IOChannel::create_watch(IOCondition condition)
367 {
368   // The corresponding unreference() takes place in the dtor
369   // of the Glib::RefPtr<IOChannel> object below.
370   reference();
371   return IOSource::create(Glib::RefPtr<IOChannel>(this), condition);
372 }
373
374 IOStatus IOChannel::read_vfunc(char*, gsize, gsize&)
375 {
376   g_assert_not_reached();
377   return IO_STATUS_ERROR;
378 }
379
380 IOStatus IOChannel::write_vfunc(const char*, gsize, gsize&)
381 {
382   g_assert_not_reached();
383   return IO_STATUS_ERROR;
384 }
385
386 IOStatus IOChannel::seek_vfunc(gint64, SeekType)
387 {
388   g_assert_not_reached();
389   return IO_STATUS_ERROR;
390 }
391
392 IOStatus IOChannel::close_vfunc()
393 {
394   g_assert_not_reached();
395   return IO_STATUS_ERROR;
396 }
397
398 Glib::RefPtr<Glib::Source> IOChannel::create_watch_vfunc(IOCondition)
399 {
400   g_assert_not_reached();
401   return Glib::RefPtr<Glib::Source>();
402 }
403
404 IOStatus IOChannel::set_flags_vfunc(IOFlags)
405 {
406   g_assert_not_reached();
407   return IO_STATUS_ERROR;
408 }
409
410 IOFlags IOChannel::get_flags_vfunc()
411 {
412   g_assert_not_reached();
413   return IOFlags(0);
414 }
415
416 void IOChannel::reference() const
417 {
418   g_io_channel_ref(gobject_);
419 }
420
421 void IOChannel::unreference() const
422 {
423   g_io_channel_unref(gobject_);
424 }
425
426 Glib::RefPtr<IOChannel> wrap(GIOChannel* gobject, bool take_copy)
427 {
428   IOChannel* cpp_object = 0;
429
430   if(gobject)
431   {
432     if(gobject->funcs == &GlibmmIOChannel::vfunc_table)
433     {
434       cpp_object = reinterpret_cast<GlibmmIOChannel*>(gobject)->wrapper;
435
436       if(take_copy && cpp_object)
437         cpp_object->reference();
438     }
439     else
440     {
441       cpp_object = new ForeignIOChannel(gobject, take_copy);
442       cpp_object->reference(); // the refcount is initially 0
443     }
444   }
445
446   return Glib::RefPtr<IOChannel>(cpp_object);
447 }
448
449
450 /**** Glib::GlibmmIOChannel ************************************************/
451
452 // static
453 GIOStatus GlibmmIOChannel::io_read(GIOChannel* channel, char* buf, gsize count,
454                                    gsize* bytes_read, GError** err)
455 {
456   if(!&err) err = err; //Avoid an unused parameter warning when GLIBMM_EXCEPTIONS_ENABLED is used.
457
458   IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
459
460   #ifdef GLIBMM_EXCEPTIONS_ENABLED
461   try
462   {
463   #endif //GLIBMM_EXCEPTIONS_ENABLED
464     return (GIOStatus) wrapper->read_vfunc(buf, count, *bytes_read);
465   #ifdef GLIBMM_EXCEPTIONS_ENABLED
466   }
467   catch(Glib::Error& error)
468   {
469     error.propagate(err);
470   }
471   catch(...)
472   {
473     Glib::exception_handlers_invoke();
474   }
475   #endif //GLIBMM_EXCEPTIONS_ENABLED
476
477   return G_IO_STATUS_ERROR;
478 }
479
480 // static
481 GIOStatus GlibmmIOChannel::io_write(GIOChannel* channel, const char* buf, gsize count,
482                                     gsize* bytes_written, GError** err)
483 {
484   if(!&err) err = err; //Avoid an unused parameter warning when GLIBMM_EXCEPTIONS_ENABLED is used.
485
486   IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
487
488   #ifdef GLIBMM_EXCEPTIONS_ENABLED
489   try
490   {
491   #endif //GLIBMM_EXCEPTIONS_ENABLED
492     return (GIOStatus) wrapper->write_vfunc(buf, count, *bytes_written);
493   #ifdef GLIBMM_EXCEPTIONS_ENABLED
494   }
495   catch(Glib::Error& error)
496   {
497     error.propagate(err);
498   }
499   catch(...)
500   {
501     Glib::exception_handlers_invoke();
502   }
503   #endif //GLIBMM_EXCEPTIONS_ENABLED
504
505   return G_IO_STATUS_ERROR;
506 }
507
508 // static
509 GIOStatus GlibmmIOChannel::io_seek(GIOChannel* channel, gint64 offset, GSeekType type, GError** err)
510 {
511   if(!&err) err = err; //Avoid an unused parameter warning when GLIBMM_EXCEPTIONS_ENABLED is used.
512
513   IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
514
515   #ifdef GLIBMM_EXCEPTIONS_ENABLED
516   try
517   {
518   #endif //GLIBMM_EXCEPTIONS_ENABLED
519     return (GIOStatus) wrapper->seek_vfunc(offset, (SeekType) type);
520   #ifdef GLIBMM_EXCEPTIONS_ENABLED
521   }
522   catch(Glib::Error& error)
523   {
524     error.propagate(err);
525   }
526   catch(...)
527   {
528     Glib::exception_handlers_invoke();
529   }
530   #endif //GLIBMM_EXCEPTIONS_ENABLED
531
532   return G_IO_STATUS_ERROR;
533 }
534
535 // static
536 GIOStatus GlibmmIOChannel::io_close(GIOChannel* channel, GError** err)
537 {
538   if(!&err) err = err; //Avoid an unused parameter warning when GLIBMM_EXCEPTIONS_ENABLED is used.
539
540   IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
541
542   #ifdef GLIBMM_EXCEPTIONS_ENABLED
543   try
544   {
545   #endif //GLIBMM_EXCEPTIONS_ENABLED
546     return (GIOStatus) wrapper->close_vfunc();
547   #ifdef GLIBMM_EXCEPTIONS_ENABLED
548   }
549   catch(Glib::Error& error)
550   {
551     error.propagate(err);
552   }
553   catch(...)
554   {
555     Glib::exception_handlers_invoke();
556   }
557   #endif //GLIBMM_EXCEPTIONS_ENABLED
558  
559
560   return G_IO_STATUS_ERROR;
561 }
562
563 // static
564 GSource* GlibmmIOChannel::io_create_watch(GIOChannel* channel, GIOCondition condition)
565 {
566   IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
567
568   #ifdef GLIBMM_EXCEPTIONS_ENABLED
569   try
570   {
571   #endif //GLIBMM_EXCEPTIONS_ENABLED
572     const Glib::RefPtr<Source> source = wrapper->create_watch_vfunc((IOCondition) condition);
573     return (source) ? source->gobj_copy() : 0;
574   #ifdef GLIBMM_EXCEPTIONS_ENABLED
575   }
576   catch(...)
577   {
578     Glib::exception_handlers_invoke();
579   }
580   #endif //GLIBMM_EXCEPTIONS_ENABLED
581
582   return 0;
583 }
584
585 // static
586 void GlibmmIOChannel::io_free(GIOChannel* channel)
587 {
588   if(IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper)
589   {
590     wrapper->gobject_ = 0;
591     delete wrapper;
592   }
593
594   g_free(channel);
595 }
596
597 // static
598 GIOStatus GlibmmIOChannel::io_set_flags(GIOChannel* channel, GIOFlags flags, GError** err)
599 {
600   if(!&err) err = err; //Avoid an unused parameter warning when GLIBMM_EXCEPTIONS_ENABLED is used.
601
602   IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
603
604   #ifdef GLIBMM_EXCEPTIONS_ENABLED
605   try
606   {
607   #endif //GLIBMM_EXCEPTIONS_ENABLED
608     return (GIOStatus) wrapper->set_flags_vfunc((IOFlags) flags);
609   #ifdef GLIBMM_EXCEPTIONS_ENABLED
610   }
611   catch(Glib::Error& error)
612   {
613     error.propagate(err);
614   }
615   catch(...)
616   {
617     Glib::exception_handlers_invoke();
618   }
619   #endif //GLIBMM_EXCEPTIONS_ENABLED
620
621   return G_IO_STATUS_ERROR;
622 }
623
624 // static
625 GIOFlags GlibmmIOChannel::io_get_flags(GIOChannel* channel)
626 {
627   IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper;
628
629   #ifdef GLIBMM_EXCEPTIONS_ENABLED
630   try
631   {
632   #endif //GLIBMM_EXCEPTIONS_ENABLED
633     return (GIOFlags) wrapper->get_flags_vfunc();
634   #ifdef GLIBMM_EXCEPTIONS_ENABLED
635   }
636   catch(...)
637   {
638     Glib::exception_handlers_invoke();
639   }
640   #endif //GLIBMM_EXCEPTIONS_ENABLED
641
642   return GIOFlags(0);
643 }
644
645 } // namespace Glib
646
647
648 namespace
649 {
650 } // anonymous namespace
651
652
653 Glib::IOChannelError::IOChannelError(Glib::IOChannelError::Code error_code, const Glib::ustring& error_message)
654 :
655   Glib::Error (G_IO_CHANNEL_ERROR, error_code, error_message)
656 {}
657
658 Glib::IOChannelError::IOChannelError(GError* gobject)
659 :
660   Glib::Error (gobject)
661 {}
662
663 Glib::IOChannelError::Code Glib::IOChannelError::code() const
664 {
665   return static_cast<Code>(Glib::Error::code());
666 }
667
668 #ifdef GLIBMM_EXCEPTIONS_ENABLED
669 void Glib::IOChannelError::throw_func(GError* gobject)
670 {
671   throw Glib::IOChannelError(gobject);
672 }
673 #else
674 //When not using exceptions, we just pass the Exception object around without throwing it:
675 std::auto_ptr<Glib::Error> Glib::IOChannelError::throw_func(GError* gobject)
676 {
677   return std::auto_ptr<Glib::Error>(new Glib::IOChannelError(gobject));
678 }
679 #endif //GLIBMM_EXCEPTIONS_ENABLED
680
681
682 namespace Glib
683 {
684
685
686 #ifdef GLIBMM_EXCEPTIONS_ENABLED
687 IOStatus IOChannel::read(gunichar& thechar)
688 #else
689 IOStatus IOChannel::read(gunichar& thechar, std::auto_ptr<Glib::Error>& error)
690 #endif //GLIBMM_EXCEPTIONS_ENABLED
691 {
692   GError* gerror = 0;
693   IOStatus retvalue = ((IOStatus)(g_io_channel_read_unichar(gobj(), &(thechar), &(gerror))));
694 #ifdef GLIBMM_EXCEPTIONS_ENABLED
695   if(gerror)
696     ::Glib::Error::throw_exception(gerror);
697 #else
698   if(gerror)
699     error = ::Glib::Error::throw_exception(gerror);
700 #endif //GLIBMM_EXCEPTIONS_ENABLED
701
702   return retvalue;
703
704 }
705
706 #ifdef GLIBMM_EXCEPTIONS_ENABLED
707 IOStatus IOChannel::read(char* buf, gsize count, gsize& bytes_read)
708 #else
709 IOStatus IOChannel::read(char* buf, gsize count, gsize& bytes_read, std::auto_ptr<Glib::Error>& error)
710 #endif //GLIBMM_EXCEPTIONS_ENABLED
711 {
712   GError* gerror = 0;
713   IOStatus retvalue = ((IOStatus)(g_io_channel_read_chars(gobj(), buf, count, &(bytes_read), &(gerror))));
714 #ifdef GLIBMM_EXCEPTIONS_ENABLED
715   if(gerror)
716     ::Glib::Error::throw_exception(gerror);
717 #else
718   if(gerror)
719     error = ::Glib::Error::throw_exception(gerror);
720 #endif //GLIBMM_EXCEPTIONS_ENABLED
721
722   return retvalue;
723
724 }
725
726 #ifdef GLIBMM_EXCEPTIONS_ENABLED
727 IOStatus IOChannel::write(const char* buf, gssize count, gsize& bytes_written)
728 #else
729 IOStatus IOChannel::write(const char* buf, gssize count, gsize& bytes_written, std::auto_ptr<Glib::Error>& error)
730 #endif //GLIBMM_EXCEPTIONS_ENABLED
731 {
732   GError* gerror = 0;
733   IOStatus retvalue = ((IOStatus)(g_io_channel_write_chars(gobj(), buf, count, &(bytes_written), &(gerror))));
734 #ifdef GLIBMM_EXCEPTIONS_ENABLED
735   if(gerror)
736     ::Glib::Error::throw_exception(gerror);
737 #else
738   if(gerror)
739     error = ::Glib::Error::throw_exception(gerror);
740 #endif //GLIBMM_EXCEPTIONS_ENABLED
741
742   return retvalue;
743
744 }
745
746 #ifdef GLIBMM_EXCEPTIONS_ENABLED
747 IOStatus IOChannel::write(gunichar unichar)
748 #else
749 IOStatus IOChannel::write(gunichar unichar, std::auto_ptr<Glib::Error>& error)
750 #endif //GLIBMM_EXCEPTIONS_ENABLED
751 {
752   GError* gerror = 0;
753   IOStatus retvalue = ((IOStatus)(g_io_channel_write_unichar(gobj(), unichar, &(gerror))));
754 #ifdef GLIBMM_EXCEPTIONS_ENABLED
755   if(gerror)
756     ::Glib::Error::throw_exception(gerror);
757 #else
758   if(gerror)
759     error = ::Glib::Error::throw_exception(gerror);
760 #endif //GLIBMM_EXCEPTIONS_ENABLED
761
762   return retvalue;
763
764 }
765
766 #ifdef GLIBMM_EXCEPTIONS_ENABLED
767 IOStatus IOChannel::seek(gint64 offset, SeekType type)
768 #else
769 IOStatus IOChannel::seek(gint64 offset, SeekType type, std::auto_ptr<Glib::Error>& error)
770 #endif //GLIBMM_EXCEPTIONS_ENABLED
771 {
772   GError* gerror = 0;
773   IOStatus retvalue = ((IOStatus)(g_io_channel_seek_position(gobj(), offset, ((GSeekType)(type)), &(gerror))));
774 #ifdef GLIBMM_EXCEPTIONS_ENABLED
775   if(gerror)
776     ::Glib::Error::throw_exception(gerror);
777 #else
778   if(gerror)
779     error = ::Glib::Error::throw_exception(gerror);
780 #endif //GLIBMM_EXCEPTIONS_ENABLED
781
782   return retvalue;
783
784 }
785
786 #ifdef GLIBMM_EXCEPTIONS_ENABLED
787 IOStatus IOChannel::flush()
788 #else
789 IOStatus IOChannel::flush(std::auto_ptr<Glib::Error>& error)
790 #endif //GLIBMM_EXCEPTIONS_ENABLED
791 {
792   GError* gerror = 0;
793   IOStatus retvalue = ((IOStatus)(g_io_channel_flush(gobj(), &(gerror))));
794 #ifdef GLIBMM_EXCEPTIONS_ENABLED
795   if(gerror)
796     ::Glib::Error::throw_exception(gerror);
797 #else
798   if(gerror)
799     error = ::Glib::Error::throw_exception(gerror);
800 #endif //GLIBMM_EXCEPTIONS_ENABLED
801
802   return retvalue;
803
804 }
805
806 #ifdef GLIBMM_EXCEPTIONS_ENABLED
807 IOStatus IOChannel::close(bool flush)
808 #else
809 IOStatus IOChannel::close(bool flush, std::auto_ptr<Glib::Error>& error)
810 #endif //GLIBMM_EXCEPTIONS_ENABLED
811 {
812   GError* gerror = 0;
813   IOStatus retvalue = ((IOStatus)(g_io_channel_shutdown(gobj(), static_cast<int>(flush), &(gerror))));
814 #ifdef GLIBMM_EXCEPTIONS_ENABLED
815   if(gerror)
816     ::Glib::Error::throw_exception(gerror);
817 #else
818   if(gerror)
819     error = ::Glib::Error::throw_exception(gerror);
820 #endif //GLIBMM_EXCEPTIONS_ENABLED
821
822   return retvalue;
823
824 }
825
826 gsize IOChannel::get_buffer_size() const
827 {
828   return g_io_channel_get_buffer_size(const_cast<GIOChannel*>(gobj()));
829 }
830
831 void IOChannel::set_buffer_size(gsize size)
832 {
833 g_io_channel_set_buffer_size(gobj(), size); 
834 }
835
836 IOFlags IOChannel::get_flags() const
837 {
838   return ((IOFlags)(g_io_channel_get_flags(const_cast<GIOChannel*>(gobj()))));
839 }
840
841 #ifdef GLIBMM_EXCEPTIONS_ENABLED
842 IOStatus IOChannel::set_flags(IOFlags flags)
843 #else
844 IOStatus IOChannel::set_flags(IOFlags flags, std::auto_ptr<Glib::Error>& error)
845 #endif //GLIBMM_EXCEPTIONS_ENABLED
846 {
847   GError* gerror = 0;
848   IOStatus retvalue = ((IOStatus)(g_io_channel_set_flags(gobj(), ((GIOFlags)(flags)), &(gerror))));
849 #ifdef GLIBMM_EXCEPTIONS_ENABLED
850   if(gerror)
851     ::Glib::Error::throw_exception(gerror);
852 #else
853   if(gerror)
854     error = ::Glib::Error::throw_exception(gerror);
855 #endif //GLIBMM_EXCEPTIONS_ENABLED
856
857   return retvalue;
858
859 }
860
861 void IOChannel::set_buffered(bool buffered)
862 {
863 g_io_channel_set_buffered(gobj(), static_cast<int>(buffered)); 
864 }
865
866 bool IOChannel::get_buffered() const
867 {
868   return g_io_channel_get_buffered(const_cast<GIOChannel*>(gobj()));
869 }
870
871 IOCondition IOChannel::get_buffer_condition() const
872 {
873   return ((IOCondition)(g_io_channel_get_buffer_condition(const_cast<GIOChannel*>(gobj()))));
874 }
875
876 bool IOChannel::get_close_on_unref() const
877 {
878   return g_io_channel_get_close_on_unref(const_cast<GIOChannel*>(gobj()));
879 }
880
881 void IOChannel::set_close_on_unref(bool do_close)
882 {
883 g_io_channel_set_close_on_unref(gobj(), static_cast<int>(do_close)); 
884 }
885
886
887 } // namespace Glib
888
889