Main Page | Class List | Directories | File List | Class Members | File Members

giochannel.c

Go to the documentation of this file.
00001 /* GLIB - Library of useful routines for C programming
00002  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
00003  *
00004  * giochannel.c: IO Channel abstraction
00005  * Copyright 1998 Owen Taylor
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Library General Public
00018  * License along with this library; if not, write to the
00019  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020  * Boston, MA 02111-1307, USA.
00021  */
00022 
00023 /*
00024  * Modified by the GLib Team and others 1997-1999.  See the AUTHORS
00025  * file for a list of people on the GLib Team.  See the ChangeLog
00026  * files for a list of changes.  These files are distributed with
00027  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
00028  */
00029 
00030 /* 
00031  * MT safe
00032  */
00033 
00034 #include "config.h"
00035 
00036 #include "glib.h"
00037 #ifdef HAVE_UNISTD_H
00038 #include <unistd.h>
00039 #endif
00040 
00041 void
00042 g_io_channel_init (GIOChannel *channel)
00043 {
00044   channel->channel_flags = 0;
00045   channel->ref_count = 1;
00046 }
00047 
00048 
00049 void 
00050 g_io_channel_ref (GIOChannel *channel)
00051 {
00052   g_return_if_fail (channel != NULL);
00053 
00054   channel->ref_count++;
00055 }
00056 
00057 void 
00058 g_io_channel_unref (GIOChannel *channel)
00059 {
00060   g_return_if_fail (channel != NULL);
00061 
00062   channel->ref_count--;
00063   if (channel->ref_count == 0)
00064     channel->funcs->io_free (channel);
00065 }
00066 
00067 GIOError 
00068 g_io_channel_read (GIOChannel *channel, 
00069                    gchar      *buf, 
00070                    guint       count,
00071                    guint      *bytes_read)
00072 {
00073   g_return_val_if_fail (channel != NULL, G_IO_ERROR_UNKNOWN);
00074 
00075   return channel->funcs->io_read (channel, buf, count, bytes_read);
00076 }
00077 
00078 GIOError 
00079 g_io_channel_write (GIOChannel *channel, 
00080                     gchar      *buf, 
00081                     guint       count,
00082                     guint      *bytes_written)
00083 {
00084   g_return_val_if_fail (channel != NULL, G_IO_ERROR_UNKNOWN);
00085 
00086   return channel->funcs->io_write (channel, buf, count, bytes_written);
00087 }
00088 
00089 GIOError 
00090 g_io_channel_seek  (GIOChannel   *channel,
00091                     gint        offset, 
00092                     GSeekType   type)
00093 {
00094   g_return_val_if_fail (channel != NULL, G_IO_ERROR_UNKNOWN);
00095 
00096   return channel->funcs->io_seek (channel, offset, type);
00097 }
00098      
00099 void
00100 g_io_channel_close (GIOChannel *channel)
00101 {
00102   g_return_if_fail (channel != NULL);
00103 
00104   channel->funcs->io_close (channel);
00105 }
00106 
00107 guint 
00108 g_io_add_watch_full (GIOChannel    *channel,
00109                      gint           priority,
00110                      GIOCondition   condition,
00111                      GIOFunc        func,
00112                      gpointer       user_data,
00113                      GDestroyNotify notify)
00114 {
00115   g_return_val_if_fail (channel != NULL, 0);
00116 
00117   return channel->funcs->io_add_watch (channel, priority, condition,
00118                                        func, user_data, notify);
00119 }
00120 
00121 guint 
00122 g_io_add_watch (GIOChannel    *channel,
00123                 GIOCondition   condition,
00124                 GIOFunc        func,
00125                 gpointer       user_data)
00126 {
00127   return g_io_add_watch_full (channel, 0, condition, func, user_data, NULL);
00128 }

© sourcejam.com 2005-2008