1.1 --- a/epoc32/include/stdapis/glib-2.0/glib/giochannel.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/stdapis/glib-2.0/glib/giochannel.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,360 @@
1.4 -giochannel.h
1.5 +/* GLIB - Library of useful routines for C programming
1.6 + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
1.7 + * Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
1.8 + *
1.9 + * This library is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU Lesser General Public
1.11 + * License as published by the Free Software Foundation; either
1.12 + * version 2 of the License, or (at your option) any later version.
1.13 + *
1.14 + * This library is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.17 + * Lesser General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU Lesser General Public
1.20 + * License along with this library; if not, write to the
1.21 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1.22 + * Boston, MA 02111-1307, USA.
1.23 + */
1.24 +
1.25 +/*
1.26 + * Modified by the GLib Team and others 1997-2000. See the AUTHORS
1.27 + * file for a list of people on the GLib Team. See the ChangeLog
1.28 + * files for a list of changes. These files are distributed with
1.29 + * GLib at ftp://ftp.gtk.org/pub/gtk/.
1.30 + */
1.31 +
1.32 +#ifndef __G_IOCHANNEL_H__
1.33 +#define __G_IOCHANNEL_H__
1.34 +
1.35 +#include <_ansi.h>
1.36 +#include <glib/gconvert.h>
1.37 +#include <glib/gmain.h>
1.38 +#include <glib/gstring.h>
1.39 +
1.40 +G_BEGIN_DECLS
1.41 +
1.42 +/* GIOChannel
1.43 + */
1.44 +
1.45 +typedef struct _GIOChannel GIOChannel;
1.46 +typedef struct _GIOFuncs GIOFuncs;
1.47 +
1.48 +typedef enum
1.49 +{
1.50 + G_IO_ERROR_NONE,
1.51 + G_IO_ERROR_AGAIN,
1.52 + G_IO_ERROR_INVAL,
1.53 + G_IO_ERROR_UNKNOWN
1.54 +} GIOError;
1.55 +
1.56 +#define G_IO_CHANNEL_ERROR g_io_channel_error_quark()
1.57 +
1.58 +typedef enum
1.59 +{
1.60 + /* Derived from errno */
1.61 + G_IO_CHANNEL_ERROR_FBIG,
1.62 + G_IO_CHANNEL_ERROR_INVAL,
1.63 + G_IO_CHANNEL_ERROR_IO,
1.64 + G_IO_CHANNEL_ERROR_ISDIR,
1.65 + G_IO_CHANNEL_ERROR_NOSPC,
1.66 + G_IO_CHANNEL_ERROR_NXIO,
1.67 + G_IO_CHANNEL_ERROR_OVERFLOW,
1.68 + G_IO_CHANNEL_ERROR_PIPE,
1.69 + /* Other */
1.70 + G_IO_CHANNEL_ERROR_FAILED
1.71 +} GIOChannelError;
1.72 +
1.73 +typedef enum
1.74 +{
1.75 + G_IO_STATUS_ERROR,
1.76 + G_IO_STATUS_NORMAL,
1.77 + G_IO_STATUS_EOF,
1.78 + G_IO_STATUS_AGAIN
1.79 +} GIOStatus;
1.80 +
1.81 +typedef enum
1.82 +{
1.83 + G_SEEK_CUR,
1.84 + G_SEEK_SET,
1.85 + G_SEEK_END
1.86 +} GSeekType;
1.87 +
1.88 +typedef enum
1.89 +{
1.90 + G_IO_IN GLIB_SYSDEF_POLLIN,
1.91 + G_IO_OUT GLIB_SYSDEF_POLLOUT,
1.92 + G_IO_PRI GLIB_SYSDEF_POLLPRI,
1.93 + G_IO_ERR GLIB_SYSDEF_POLLERR,
1.94 + G_IO_HUP GLIB_SYSDEF_POLLHUP,
1.95 + G_IO_NVAL GLIB_SYSDEF_POLLNVAL
1.96 +} GIOCondition;
1.97 +
1.98 +typedef enum
1.99 +{
1.100 + G_IO_FLAG_APPEND = 1 << 0,
1.101 + G_IO_FLAG_NONBLOCK = 1 << 1,
1.102 + G_IO_FLAG_IS_READABLE = 1 << 2, /* Read only flag */
1.103 + G_IO_FLAG_IS_WRITEABLE = 1 << 3, /* Read only flag */
1.104 + G_IO_FLAG_IS_SEEKABLE = 1 << 4, /* Read only flag */
1.105 + G_IO_FLAG_MASK = (1 << 5) - 1,
1.106 + G_IO_FLAG_GET_MASK = G_IO_FLAG_MASK,
1.107 + G_IO_FLAG_SET_MASK = G_IO_FLAG_APPEND | G_IO_FLAG_NONBLOCK
1.108 +} GIOFlags;
1.109 +
1.110 +struct _GIOChannel
1.111 +{
1.112 + /*< private >*/
1.113 + guint ref_count;
1.114 + GIOFuncs *funcs;
1.115 +
1.116 + gchar *encoding;
1.117 + GIConv read_cd;
1.118 + GIConv write_cd;
1.119 + gchar *line_term; /* String which indicates the end of a line of text */
1.120 + guint line_term_len; /* So we can have null in the line term */
1.121 +
1.122 + gsize buf_size;
1.123 + GString *read_buf; /* Raw data from the channel */
1.124 + GString *encoded_read_buf; /* Channel data converted to UTF-8 */
1.125 + GString *write_buf; /* Data ready to be written to the file */
1.126 + gchar partial_write_buf[6]; /* UTF-8 partial characters, null terminated */
1.127 +
1.128 + /* Group the flags together, immediately after partial_write_buf, to save memory */
1.129 +
1.130 + guint use_buffer : 1; /* The encoding uses the buffers */
1.131 + guint do_encode : 1; /* The encoding uses the GIConv coverters */
1.132 + guint close_on_unref : 1; /* Close the channel on final unref */
1.133 + guint is_readable : 1; /* Cached GIOFlag */
1.134 + guint is_writeable : 1; /* ditto */
1.135 + guint is_seekable : 1; /* ditto */
1.136 +
1.137 + gpointer reserved1;
1.138 + gpointer reserved2;
1.139 +};
1.140 +
1.141 +typedef gboolean (*GIOFunc) (GIOChannel *source,
1.142 + GIOCondition condition,
1.143 + gpointer data);
1.144 +struct _GIOFuncs
1.145 +{
1.146 + GIOStatus (*io_read) (GIOChannel *channel,
1.147 + gchar *buf,
1.148 + gsize count,
1.149 + gsize *bytes_read,
1.150 + GError **err);
1.151 + GIOStatus (*io_write) (GIOChannel *channel,
1.152 + const gchar *buf,
1.153 + gsize count,
1.154 + gsize *bytes_written,
1.155 + GError **err);
1.156 + GIOStatus (*io_seek) (GIOChannel *channel,
1.157 + gint64 offset,
1.158 + GSeekType type,
1.159 + GError **err);
1.160 + GIOStatus (*io_close) (GIOChannel *channel,
1.161 + GError **err);
1.162 + GSource* (*io_create_watch) (GIOChannel *channel,
1.163 + GIOCondition condition);
1.164 + void (*io_free) (GIOChannel *channel);
1.165 + GIOStatus (*io_set_flags) (GIOChannel *channel,
1.166 + GIOFlags flags,
1.167 + GError **err);
1.168 + GIOFlags (*io_get_flags) (GIOChannel *channel);
1.169 +};
1.170 +
1.171 +IMPORT_C void g_io_channel_init (GIOChannel *channel);
1.172 +IMPORT_C GIOChannel *g_io_channel_ref (GIOChannel *channel);
1.173 +IMPORT_C void g_io_channel_unref (GIOChannel *channel);
1.174 +
1.175 +#ifndef G_DISABLE_DEPRECATED
1.176 +IMPORT_C GIOError g_io_channel_read (GIOChannel *channel,
1.177 + gchar *buf,
1.178 + gsize count,
1.179 + gsize *bytes_read);
1.180 +IMPORT_C GIOError g_io_channel_write (GIOChannel *channel,
1.181 + const gchar *buf,
1.182 + gsize count,
1.183 + gsize *bytes_written);
1.184 +IMPORT_C GIOError g_io_channel_seek (GIOChannel *channel,
1.185 + gint64 offset,
1.186 + GSeekType type);
1.187 +IMPORT_C void g_io_channel_close (GIOChannel *channel);
1.188 +#endif /* G_DISABLE_DEPRECATED */
1.189 +
1.190 +IMPORT_C GIOStatus g_io_channel_shutdown (GIOChannel *channel,
1.191 + gboolean flush,
1.192 + GError **err);
1.193 +IMPORT_C guint g_io_add_watch_full (GIOChannel *channel,
1.194 + gint priority,
1.195 + GIOCondition condition,
1.196 + GIOFunc func,
1.197 + gpointer user_data,
1.198 + GDestroyNotify notify);
1.199 +IMPORT_C GSource * g_io_create_watch (GIOChannel *channel,
1.200 + GIOCondition condition);
1.201 +IMPORT_C guint g_io_add_watch (GIOChannel *channel,
1.202 + GIOCondition condition,
1.203 + GIOFunc func,
1.204 + gpointer user_data);
1.205 +
1.206 +/* character encoding conversion involved functions.
1.207 + */
1.208 +
1.209 +IMPORT_C void g_io_channel_set_buffer_size (GIOChannel *channel,
1.210 + gsize size);
1.211 +IMPORT_C gsize g_io_channel_get_buffer_size (GIOChannel *channel);
1.212 +IMPORT_C GIOCondition g_io_channel_get_buffer_condition (GIOChannel *channel);
1.213 +IMPORT_C GIOStatus g_io_channel_set_flags (GIOChannel *channel,
1.214 + GIOFlags flags,
1.215 + GError **error);
1.216 +IMPORT_C GIOFlags g_io_channel_get_flags (GIOChannel *channel);
1.217 +IMPORT_C void g_io_channel_set_line_term (GIOChannel *channel,
1.218 + const gchar *line_term,
1.219 + gint length);
1.220 +IMPORT_C G_CONST_RETURN gchar* g_io_channel_get_line_term (GIOChannel *channel,
1.221 + gint *length);
1.222 +IMPORT_C void g_io_channel_set_buffered (GIOChannel *channel,
1.223 + gboolean buffered);
1.224 +IMPORT_C gboolean g_io_channel_get_buffered (GIOChannel *channel);
1.225 +IMPORT_C GIOStatus g_io_channel_set_encoding (GIOChannel *channel,
1.226 + const gchar *encoding,
1.227 + GError **error);
1.228 +IMPORT_C G_CONST_RETURN gchar* g_io_channel_get_encoding (GIOChannel *channel);
1.229 +IMPORT_C void g_io_channel_set_close_on_unref (GIOChannel *channel,
1.230 + gboolean do_close);
1.231 +IMPORT_C gboolean g_io_channel_get_close_on_unref (GIOChannel *channel);
1.232 +
1.233 +
1.234 +IMPORT_C GIOStatus g_io_channel_flush (GIOChannel *channel,
1.235 + GError **error);
1.236 +IMPORT_C GIOStatus g_io_channel_read_line (GIOChannel *channel,
1.237 + gchar **str_return,
1.238 + gsize *length,
1.239 + gsize *terminator_pos,
1.240 + GError **error);
1.241 +IMPORT_C GIOStatus g_io_channel_read_line_string (GIOChannel *channel,
1.242 + GString *buffer,
1.243 + gsize *terminator_pos,
1.244 + GError **error);
1.245 +IMPORT_C GIOStatus g_io_channel_read_to_end (GIOChannel *channel,
1.246 + gchar **str_return,
1.247 + gsize *length,
1.248 + GError **error);
1.249 +IMPORT_C GIOStatus g_io_channel_read_chars (GIOChannel *channel,
1.250 + gchar *buf,
1.251 + gsize count,
1.252 + gsize *bytes_read,
1.253 + GError **error);
1.254 +IMPORT_C GIOStatus g_io_channel_read_unichar (GIOChannel *channel,
1.255 + gunichar *thechar,
1.256 + GError **error);
1.257 +IMPORT_C GIOStatus g_io_channel_write_chars (GIOChannel *channel,
1.258 + const gchar *buf,
1.259 + gssize count,
1.260 + gsize *bytes_written,
1.261 + GError **error);
1.262 +IMPORT_C GIOStatus g_io_channel_write_unichar (GIOChannel *channel,
1.263 + gunichar thechar,
1.264 + GError **error);
1.265 +IMPORT_C GIOStatus g_io_channel_seek_position (GIOChannel *channel,
1.266 + gint64 offset,
1.267 + GSeekType type,
1.268 + GError **error);
1.269 +#ifdef G_OS_WIN32
1.270 +#define g_io_channel_new_file g_io_channel_new_file_utf8
1.271 +#endif
1.272 +
1.273 +IMPORT_C GIOChannel* g_io_channel_new_file (const gchar *filename,
1.274 + const gchar *mode,
1.275 + GError **error);
1.276 +
1.277 +/* Error handling */
1.278 +
1.279 +IMPORT_C GQuark g_io_channel_error_quark (void);
1.280 +IMPORT_C GIOChannelError g_io_channel_error_from_errno (gint en);
1.281 +
1.282 +/* On Unix, IO channels created with this function for any file
1.283 + * descriptor or socket.
1.284 + *
1.285 + * On Win32, this can be used either for files opened with the MSVCRT
1.286 + * (the Microsoft run-time C library) _open() or _pipe, including file
1.287 + * descriptors 0, 1 and 2 (corresponding to stdin, stdout and stderr),
1.288 + * or for Winsock SOCKETs. If the parameter is a legal file
1.289 + * descriptor, it is assumed to be such, otherwise it should be a
1.290 + * SOCKET. This relies on SOCKETs and file descriptors not
1.291 + * overlapping. If you want to be certain, call either
1.292 + * g_io_channel_win32_new_fd() or g_io_channel_win32_new_socket()
1.293 + * instead as appropriate.
1.294 + *
1.295 + * The term file descriptor as used in the context of Win32 refers to
1.296 + * the emulated Unix-like file descriptors MSVCRT provides. The native
1.297 + * corresponding concept is file HANDLE. There isn't as of yet a way to
1.298 + * get GIOChannels for Win32 file HANDLEs.
1.299 + */
1.300 +IMPORT_C GIOChannel* g_io_channel_unix_new (int fd);
1.301 +IMPORT_C gint g_io_channel_unix_get_fd (GIOChannel *channel);
1.302 +
1.303 +
1.304 +/* Hook for GClosure / GSource integration. Don't touch */
1.305 +GLIB_VAR GSourceFuncs g_io_watch_funcs;
1.306 +
1.307 +#ifdef __SYMBIAN32__
1.308 +IMPORT_C GSourceFuncs * _g_io_watch_funcs();
1.309 +#endif /* __SYMBIAN32__ */
1.310 +
1.311 +#ifdef G_OS_WIN32
1.312 +
1.313 +/* You can use this "pseudo file descriptor" in a GPollFD to add
1.314 + * polling for Windows messages. GTK applications should not do that.
1.315 + */
1.316 +
1.317 +#define G_WIN32_MSG_HANDLE 19981206
1.318 +
1.319 +/* Use this to get a GPollFD from a GIOChannel, so that you can call
1.320 + * g_io_channel_win32_poll(). After calling this you should only use
1.321 + * g_io_channel_read() to read from the GIOChannel, i.e. never read()
1.322 + * from the underlying file descriptor. For SOCKETs, it is possible to call
1.323 + * recv().
1.324 + */
1.325 +void g_io_channel_win32_make_pollfd (GIOChannel *channel,
1.326 + GIOCondition condition,
1.327 + GPollFD *fd);
1.328 +
1.329 +/* This can be used to wait a until at least one of the channels is readable.
1.330 + * On Unix you would do a select() on the file descriptors of the channels.
1.331 + */
1.332 +gint g_io_channel_win32_poll (GPollFD *fds,
1.333 + gint n_fds,
1.334 + gint timeout_);
1.335 +
1.336 +/* Create an IO channel for Windows messages for window handle hwnd. */
1.337 +GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
1.338 +
1.339 +/* Create an IO channel for C runtime (emulated Unix-like) file
1.340 + * descriptors. After calling g_io_add_watch() on a IO channel
1.341 + * returned by this function, you shouldn't call read() on the file
1.342 + * descriptor. This is because adding polling for a file descriptor is
1.343 + * implemented on Win32 by starting a thread that sits blocked in a
1.344 + * read() from the file descriptor most of the time. All reads from
1.345 + * the file descriptor should be done by this internal GLib
1.346 + * thread. Your code should call only g_io_channel_read().
1.347 + */
1.348 +GIOChannel* g_io_channel_win32_new_fd (gint fd);
1.349 +
1.350 +/* Get the C runtime file descriptor of a channel. */
1.351 +gint g_io_channel_win32_get_fd (GIOChannel *channel);
1.352 +
1.353 +/* Create an IO channel for a winsock socket. The parameter should be
1.354 + * a SOCKET. Contrary to IO channels for file descriptors (on *Win32),
1.355 + * you can use normal recv() or recvfrom() on sockets even if GLib
1.356 + * is polling them.
1.357 + */
1.358 +GIOChannel *g_io_channel_win32_new_socket (gint socket);
1.359 +
1.360 +#endif
1.361 +
1.362 +G_END_DECLS
1.363 +
1.364 +#endif /* __G_IOCHANNEL_H__ */