epoc32/include/stdapis/glib-2.0/glib/giochannel.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 0 061f57f2323e
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
/* GLIB - Library of useful routines for C programming
williamr@2
     2
 * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
williamr@2
     3
 * Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
williamr@2
     4
 *
williamr@2
     5
 * This library is free software; you can redistribute it and/or
williamr@2
     6
 * modify it under the terms of the GNU Lesser General Public
williamr@2
     7
 * License as published by the Free Software Foundation; either
williamr@2
     8
 * version 2 of the License, or (at your option) any later version.
williamr@2
     9
 *
williamr@2
    10
 * This library is distributed in the hope that it will be useful,
williamr@2
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
williamr@2
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
williamr@2
    13
 * Lesser General Public License for more details.
williamr@2
    14
 *
williamr@2
    15
 * You should have received a copy of the GNU Lesser General Public
williamr@2
    16
 * License along with this library; if not, write to the
williamr@2
    17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
williamr@2
    18
 * Boston, MA 02111-1307, USA.
williamr@2
    19
 */
williamr@2
    20
williamr@2
    21
/*
williamr@2
    22
 * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
williamr@2
    23
 * file for a list of people on the GLib Team.  See the ChangeLog
williamr@2
    24
 * files for a list of changes.  These files are distributed with
williamr@2
    25
 * GLib at ftp://ftp.gtk.org/pub/gtk/. 
williamr@2
    26
 */
williamr@2
    27
williamr@2
    28
#ifndef __G_IOCHANNEL_H__
williamr@2
    29
#define __G_IOCHANNEL_H__
williamr@2
    30
williamr@2
    31
#include <_ansi.h>
williamr@2
    32
#include <glib/gconvert.h>
williamr@2
    33
#include <glib/gmain.h>
williamr@2
    34
#include <glib/gstring.h>
williamr@2
    35
williamr@2
    36
G_BEGIN_DECLS
williamr@2
    37
williamr@2
    38
/* GIOChannel
williamr@2
    39
 */
williamr@2
    40
williamr@2
    41
typedef struct _GIOChannel	GIOChannel;
williamr@2
    42
typedef struct _GIOFuncs        GIOFuncs;
williamr@2
    43
williamr@2
    44
typedef enum
williamr@2
    45
{
williamr@2
    46
  G_IO_ERROR_NONE,
williamr@2
    47
  G_IO_ERROR_AGAIN,
williamr@2
    48
  G_IO_ERROR_INVAL,
williamr@2
    49
  G_IO_ERROR_UNKNOWN
williamr@2
    50
} GIOError;
williamr@2
    51
williamr@2
    52
#define G_IO_CHANNEL_ERROR g_io_channel_error_quark()
williamr@2
    53
williamr@2
    54
typedef enum
williamr@2
    55
{
williamr@2
    56
  /* Derived from errno */
williamr@2
    57
  G_IO_CHANNEL_ERROR_FBIG,
williamr@2
    58
  G_IO_CHANNEL_ERROR_INVAL,
williamr@2
    59
  G_IO_CHANNEL_ERROR_IO,
williamr@2
    60
  G_IO_CHANNEL_ERROR_ISDIR,
williamr@2
    61
  G_IO_CHANNEL_ERROR_NOSPC,
williamr@2
    62
  G_IO_CHANNEL_ERROR_NXIO,
williamr@2
    63
  G_IO_CHANNEL_ERROR_OVERFLOW,
williamr@2
    64
  G_IO_CHANNEL_ERROR_PIPE,
williamr@2
    65
  /* Other */
williamr@2
    66
  G_IO_CHANNEL_ERROR_FAILED
williamr@2
    67
} GIOChannelError;
williamr@2
    68
williamr@2
    69
typedef enum
williamr@2
    70
{
williamr@2
    71
  G_IO_STATUS_ERROR,
williamr@2
    72
  G_IO_STATUS_NORMAL,
williamr@2
    73
  G_IO_STATUS_EOF,
williamr@2
    74
  G_IO_STATUS_AGAIN
williamr@2
    75
} GIOStatus;
williamr@2
    76
williamr@2
    77
typedef enum
williamr@2
    78
{
williamr@2
    79
  G_SEEK_CUR,
williamr@2
    80
  G_SEEK_SET,
williamr@2
    81
  G_SEEK_END
williamr@2
    82
} GSeekType;
williamr@2
    83
williamr@2
    84
typedef enum
williamr@2
    85
{
williamr@2
    86
  G_IO_IN	GLIB_SYSDEF_POLLIN,
williamr@2
    87
  G_IO_OUT	GLIB_SYSDEF_POLLOUT,
williamr@2
    88
  G_IO_PRI	GLIB_SYSDEF_POLLPRI,
williamr@2
    89
  G_IO_ERR	GLIB_SYSDEF_POLLERR,
williamr@2
    90
  G_IO_HUP	GLIB_SYSDEF_POLLHUP,
williamr@2
    91
  G_IO_NVAL	GLIB_SYSDEF_POLLNVAL
williamr@2
    92
} GIOCondition;
williamr@2
    93
williamr@2
    94
typedef enum
williamr@2
    95
{
williamr@2
    96
  G_IO_FLAG_APPEND = 1 << 0,
williamr@2
    97
  G_IO_FLAG_NONBLOCK = 1 << 1,
williamr@2
    98
  G_IO_FLAG_IS_READABLE = 1 << 2,	/* Read only flag */
williamr@2
    99
  G_IO_FLAG_IS_WRITEABLE = 1 << 3,	/* Read only flag */
williamr@2
   100
  G_IO_FLAG_IS_SEEKABLE = 1 << 4,	/* Read only flag */
williamr@2
   101
  G_IO_FLAG_MASK = (1 << 5) - 1,
williamr@2
   102
  G_IO_FLAG_GET_MASK = G_IO_FLAG_MASK,
williamr@2
   103
  G_IO_FLAG_SET_MASK = G_IO_FLAG_APPEND | G_IO_FLAG_NONBLOCK
williamr@2
   104
} GIOFlags;
williamr@2
   105
williamr@2
   106
struct _GIOChannel
williamr@2
   107
{
williamr@2
   108
  /*< private >*/
williamr@2
   109
  guint ref_count;
williamr@2
   110
  GIOFuncs *funcs;
williamr@2
   111
williamr@2
   112
  gchar *encoding;
williamr@2
   113
  GIConv read_cd;
williamr@2
   114
  GIConv write_cd;
williamr@2
   115
  gchar *line_term;		/* String which indicates the end of a line of text */
williamr@2
   116
  guint line_term_len;		/* So we can have null in the line term */
williamr@2
   117
williamr@2
   118
  gsize buf_size;
williamr@2
   119
  GString *read_buf;		/* Raw data from the channel */
williamr@2
   120
  GString *encoded_read_buf;    /* Channel data converted to UTF-8 */
williamr@2
   121
  GString *write_buf;		/* Data ready to be written to the file */
williamr@2
   122
  gchar partial_write_buf[6];	/* UTF-8 partial characters, null terminated */
williamr@2
   123
williamr@2
   124
  /* Group the flags together, immediately after partial_write_buf, to save memory */
williamr@2
   125
williamr@2
   126
  guint use_buffer     : 1;	/* The encoding uses the buffers */
williamr@2
   127
  guint do_encode      : 1;	/* The encoding uses the GIConv coverters */
williamr@2
   128
  guint close_on_unref : 1;	/* Close the channel on final unref */
williamr@2
   129
  guint is_readable    : 1;	/* Cached GIOFlag */
williamr@2
   130
  guint is_writeable   : 1;	/* ditto */
williamr@2
   131
  guint is_seekable    : 1;	/* ditto */
williamr@2
   132
williamr@2
   133
  gpointer reserved1;	
williamr@2
   134
  gpointer reserved2;	
williamr@2
   135
};
williamr@2
   136
williamr@2
   137
typedef gboolean (*GIOFunc) (GIOChannel   *source,
williamr@2
   138
			     GIOCondition  condition,
williamr@2
   139
			     gpointer      data);
williamr@2
   140
struct _GIOFuncs
williamr@2
   141
{
williamr@2
   142
  GIOStatus (*io_read)           (GIOChannel   *channel, 
williamr@2
   143
			          gchar        *buf, 
williamr@2
   144
				  gsize         count,
williamr@2
   145
				  gsize        *bytes_read,
williamr@2
   146
				  GError      **err);
williamr@2
   147
  GIOStatus (*io_write)          (GIOChannel   *channel, 
williamr@2
   148
				  const gchar  *buf, 
williamr@2
   149
				  gsize         count,
williamr@2
   150
				  gsize        *bytes_written,
williamr@2
   151
				  GError      **err);
williamr@2
   152
  GIOStatus (*io_seek)           (GIOChannel   *channel, 
williamr@2
   153
				  gint64        offset, 
williamr@2
   154
				  GSeekType     type,
williamr@2
   155
				  GError      **err);
williamr@2
   156
  GIOStatus  (*io_close)         (GIOChannel   *channel,
williamr@2
   157
				  GError      **err);
williamr@2
   158
  GSource*   (*io_create_watch)  (GIOChannel   *channel,
williamr@2
   159
				  GIOCondition  condition);
williamr@2
   160
  void       (*io_free)          (GIOChannel   *channel);
williamr@2
   161
  GIOStatus  (*io_set_flags)     (GIOChannel   *channel,
williamr@2
   162
                                  GIOFlags      flags,
williamr@2
   163
				  GError      **err);
williamr@2
   164
  GIOFlags   (*io_get_flags)     (GIOChannel   *channel);
williamr@2
   165
};
williamr@2
   166
williamr@2
   167
IMPORT_C void        g_io_channel_init   (GIOChannel    *channel);
williamr@2
   168
IMPORT_C GIOChannel *g_io_channel_ref    (GIOChannel    *channel);
williamr@2
   169
IMPORT_C void        g_io_channel_unref  (GIOChannel    *channel);
williamr@2
   170
williamr@2
   171
#ifndef G_DISABLE_DEPRECATED
williamr@2
   172
IMPORT_C GIOError    g_io_channel_read   (GIOChannel    *channel, 
williamr@2
   173
			         gchar         *buf, 
williamr@2
   174
			         gsize          count,
williamr@2
   175
			         gsize         *bytes_read);
williamr@2
   176
IMPORT_C GIOError  g_io_channel_write    (GIOChannel    *channel, 
williamr@2
   177
			         const gchar   *buf, 
williamr@2
   178
			         gsize          count,
williamr@2
   179
			         gsize         *bytes_written);
williamr@2
   180
IMPORT_C GIOError  g_io_channel_seek     (GIOChannel    *channel,
williamr@2
   181
			         gint64         offset, 
williamr@2
   182
			         GSeekType      type);
williamr@2
   183
IMPORT_C void      g_io_channel_close    (GIOChannel    *channel);
williamr@2
   184
#endif /* G_DISABLE_DEPRECATED */
williamr@2
   185
williamr@2
   186
IMPORT_C GIOStatus g_io_channel_shutdown (GIOChannel      *channel,
williamr@2
   187
				 gboolean         flush,
williamr@2
   188
				 GError         **err);
williamr@2
   189
IMPORT_C guint     g_io_add_watch_full   (GIOChannel      *channel,
williamr@2
   190
				 gint             priority,
williamr@2
   191
				 GIOCondition     condition,
williamr@2
   192
				 GIOFunc          func,
williamr@2
   193
				 gpointer         user_data,
williamr@2
   194
				 GDestroyNotify   notify);
williamr@2
   195
IMPORT_C GSource * g_io_create_watch     (GIOChannel      *channel,
williamr@2
   196
				 GIOCondition     condition);
williamr@2
   197
IMPORT_C guint     g_io_add_watch        (GIOChannel      *channel,
williamr@2
   198
				 GIOCondition     condition,
williamr@2
   199
				 GIOFunc          func,
williamr@2
   200
				 gpointer         user_data);
williamr@2
   201
williamr@2
   202
/* character encoding conversion involved functions.
williamr@2
   203
 */
williamr@2
   204
williamr@2
   205
IMPORT_C void                  g_io_channel_set_buffer_size      (GIOChannel   *channel,
williamr@2
   206
							 gsize         size);
williamr@2
   207
IMPORT_C gsize                 g_io_channel_get_buffer_size      (GIOChannel   *channel);
williamr@2
   208
IMPORT_C GIOCondition          g_io_channel_get_buffer_condition (GIOChannel   *channel);
williamr@2
   209
IMPORT_C GIOStatus             g_io_channel_set_flags            (GIOChannel   *channel,
williamr@2
   210
							 GIOFlags      flags,
williamr@2
   211
							 GError      **error);
williamr@2
   212
IMPORT_C GIOFlags              g_io_channel_get_flags            (GIOChannel   *channel);
williamr@2
   213
IMPORT_C void                  g_io_channel_set_line_term        (GIOChannel   *channel,
williamr@2
   214
							 const gchar  *line_term,
williamr@2
   215
							 gint          length);
williamr@2
   216
IMPORT_C G_CONST_RETURN gchar* g_io_channel_get_line_term        (GIOChannel   *channel,
williamr@2
   217
							 gint         *length);
williamr@2
   218
IMPORT_C void		      g_io_channel_set_buffered		(GIOChannel   *channel,
williamr@2
   219
							 gboolean      buffered);
williamr@2
   220
IMPORT_C gboolean	      g_io_channel_get_buffered		(GIOChannel   *channel);
williamr@2
   221
IMPORT_C GIOStatus             g_io_channel_set_encoding         (GIOChannel   *channel,
williamr@2
   222
							 const gchar  *encoding,
williamr@2
   223
							 GError      **error);
williamr@2
   224
IMPORT_C G_CONST_RETURN gchar* g_io_channel_get_encoding         (GIOChannel   *channel);
williamr@2
   225
IMPORT_C void                  g_io_channel_set_close_on_unref	(GIOChannel   *channel,
williamr@2
   226
							 gboolean      do_close);
williamr@2
   227
IMPORT_C gboolean              g_io_channel_get_close_on_unref	(GIOChannel   *channel);
williamr@2
   228
williamr@2
   229
williamr@2
   230
IMPORT_C GIOStatus   g_io_channel_flush            (GIOChannel   *channel,
williamr@2
   231
					   GError      **error);
williamr@2
   232
IMPORT_C GIOStatus   g_io_channel_read_line        (GIOChannel   *channel,
williamr@2
   233
					   gchar       **str_return,
williamr@2
   234
					   gsize        *length,
williamr@2
   235
					   gsize        *terminator_pos,
williamr@2
   236
					   GError      **error);
williamr@2
   237
IMPORT_C GIOStatus   g_io_channel_read_line_string (GIOChannel   *channel,
williamr@2
   238
					   GString      *buffer,
williamr@2
   239
					   gsize        *terminator_pos,
williamr@2
   240
					   GError      **error);
williamr@2
   241
IMPORT_C GIOStatus   g_io_channel_read_to_end      (GIOChannel   *channel,
williamr@2
   242
					   gchar       **str_return,
williamr@2
   243
					   gsize        *length,
williamr@2
   244
					   GError      **error);
williamr@2
   245
IMPORT_C GIOStatus   g_io_channel_read_chars       (GIOChannel   *channel,
williamr@2
   246
					   gchar        *buf,
williamr@2
   247
					   gsize         count,
williamr@2
   248
					   gsize        *bytes_read,
williamr@2
   249
					   GError      **error);
williamr@2
   250
IMPORT_C GIOStatus   g_io_channel_read_unichar     (GIOChannel   *channel,
williamr@2
   251
					   gunichar     *thechar,
williamr@2
   252
					   GError      **error);
williamr@2
   253
IMPORT_C GIOStatus   g_io_channel_write_chars      (GIOChannel   *channel,
williamr@2
   254
					   const gchar  *buf,
williamr@2
   255
					   gssize        count,
williamr@2
   256
					   gsize        *bytes_written,
williamr@2
   257
					   GError      **error);
williamr@2
   258
IMPORT_C GIOStatus   g_io_channel_write_unichar    (GIOChannel   *channel,
williamr@2
   259
					   gunichar      thechar,
williamr@2
   260
					   GError      **error);
williamr@2
   261
IMPORT_C GIOStatus   g_io_channel_seek_position    (GIOChannel   *channel,
williamr@2
   262
					   gint64        offset,
williamr@2
   263
					   GSeekType     type,
williamr@2
   264
					   GError      **error);
williamr@2
   265
#ifdef G_OS_WIN32
williamr@2
   266
#define g_io_channel_new_file g_io_channel_new_file_utf8
williamr@2
   267
#endif
williamr@2
   268
williamr@2
   269
IMPORT_C GIOChannel* g_io_channel_new_file         (const gchar  *filename,
williamr@2
   270
					   const gchar  *mode,
williamr@2
   271
					   GError      **error);
williamr@2
   272
williamr@2
   273
/* Error handling */
williamr@2
   274
williamr@2
   275
IMPORT_C GQuark          g_io_channel_error_quark      (void);
williamr@2
   276
IMPORT_C GIOChannelError g_io_channel_error_from_errno (gint en);
williamr@2
   277
williamr@2
   278
/* On Unix, IO channels created with this function for any file
williamr@2
   279
 * descriptor or socket.
williamr@2
   280
 *
williamr@2
   281
 * On Win32, this can be used either for files opened with the MSVCRT
williamr@2
   282
 * (the Microsoft run-time C library) _open() or _pipe, including file
williamr@2
   283
 * descriptors 0, 1 and 2 (corresponding to stdin, stdout and stderr),
williamr@2
   284
 * or for Winsock SOCKETs. If the parameter is a legal file
williamr@2
   285
 * descriptor, it is assumed to be such, otherwise it should be a
williamr@2
   286
 * SOCKET. This relies on SOCKETs and file descriptors not
williamr@2
   287
 * overlapping. If you want to be certain, call either
williamr@2
   288
 * g_io_channel_win32_new_fd() or g_io_channel_win32_new_socket()
williamr@2
   289
 * instead as appropriate.
williamr@2
   290
 *
williamr@2
   291
 * The term file descriptor as used in the context of Win32 refers to
williamr@2
   292
 * the emulated Unix-like file descriptors MSVCRT provides. The native
williamr@2
   293
 * corresponding concept is file HANDLE. There isn't as of yet a way to
williamr@2
   294
 * get GIOChannels for Win32 file HANDLEs.
williamr@2
   295
 */
williamr@2
   296
IMPORT_C GIOChannel* g_io_channel_unix_new    (int         fd);
williamr@2
   297
IMPORT_C gint        g_io_channel_unix_get_fd (GIOChannel *channel);
williamr@2
   298
williamr@2
   299
williamr@2
   300
/* Hook for GClosure / GSource integration. Don't touch */
williamr@2
   301
GLIB_VAR GSourceFuncs g_io_watch_funcs;
williamr@2
   302
williamr@2
   303
#ifdef __SYMBIAN32__
williamr@2
   304
IMPORT_C GSourceFuncs * _g_io_watch_funcs();
williamr@2
   305
#endif /* __SYMBIAN32__ */
williamr@2
   306
williamr@2
   307
#ifdef G_OS_WIN32
williamr@2
   308
williamr@2
   309
/* You can use this "pseudo file descriptor" in a GPollFD to add
williamr@2
   310
 * polling for Windows messages. GTK applications should not do that.
williamr@2
   311
 */
williamr@2
   312
williamr@2
   313
#define G_WIN32_MSG_HANDLE 19981206
williamr@2
   314
williamr@2
   315
/* Use this to get a GPollFD from a GIOChannel, so that you can call
williamr@2
   316
 * g_io_channel_win32_poll(). After calling this you should only use
williamr@2
   317
 * g_io_channel_read() to read from the GIOChannel, i.e. never read()
williamr@2
   318
 * from the underlying file descriptor. For SOCKETs, it is possible to call
williamr@2
   319
 * recv().
williamr@2
   320
 */
williamr@2
   321
void        g_io_channel_win32_make_pollfd (GIOChannel   *channel,
williamr@2
   322
					    GIOCondition  condition,
williamr@2
   323
					    GPollFD      *fd);
williamr@2
   324
williamr@2
   325
/* This can be used to wait a until at least one of the channels is readable.
williamr@2
   326
 * On Unix you would do a select() on the file descriptors of the channels.
williamr@2
   327
 */
williamr@2
   328
gint        g_io_channel_win32_poll   (GPollFD    *fds,
williamr@2
   329
				       gint        n_fds,
williamr@2
   330
				       gint        timeout_);
williamr@2
   331
williamr@2
   332
/* Create an IO channel for Windows messages for window handle hwnd. */
williamr@2
   333
GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
williamr@2
   334
williamr@2
   335
/* Create an IO channel for C runtime (emulated Unix-like) file
williamr@2
   336
 * descriptors. After calling g_io_add_watch() on a IO channel
williamr@2
   337
 * returned by this function, you shouldn't call read() on the file
williamr@2
   338
 * descriptor. This is because adding polling for a file descriptor is
williamr@2
   339
 * implemented on Win32 by starting a thread that sits blocked in a
williamr@2
   340
 * read() from the file descriptor most of the time. All reads from
williamr@2
   341
 * the file descriptor should be done by this internal GLib
williamr@2
   342
 * thread. Your code should call only g_io_channel_read().
williamr@2
   343
 */
williamr@2
   344
GIOChannel* g_io_channel_win32_new_fd (gint         fd);
williamr@2
   345
williamr@2
   346
/* Get the C runtime file descriptor of a channel. */
williamr@2
   347
gint        g_io_channel_win32_get_fd (GIOChannel *channel);
williamr@2
   348
williamr@2
   349
/* Create an IO channel for a winsock socket. The parameter should be
williamr@2
   350
 * a SOCKET. Contrary to IO channels for file descriptors (on *Win32),
williamr@2
   351
 * you can use normal recv() or recvfrom() on sockets even if GLib
williamr@2
   352
 * is polling them.
williamr@2
   353
 */
williamr@2
   354
GIOChannel *g_io_channel_win32_new_socket (gint socket);
williamr@2
   355
williamr@2
   356
#endif
williamr@2
   357
williamr@2
   358
G_END_DECLS
williamr@2
   359
williamr@2
   360
#endif /* __G_IOCHANNEL_H__ */