# bufferedio.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  $RCSfile: bufferedio.h,v $
    00003  -------------------
    00004  cvs         : $Id: bufferedio.h,v 1.23 2005/03/07 10:35:49 cstim Exp $
    00005  begin       : Fri Feb 07 2003
    00006  copyright   : (C) 2003 by Martin Preuss
    00007  email       : martin@libchipcard.de
    00008
    00009  ***************************************************************************
    00010  *                                                                         *
    00011  *   This library is free software; you can redistribute it and/or         *
    00012  *   modify it under the terms of the GNU Lesser General Public            *
    00013  *   License as published by the Free Software Foundation; either          *
    00014  *   version 2.1 of the License, or (at your option) any later version.    *
    00015  *                                                                         *
    00016  *   This library is distributed in the hope that it will be useful,       *
    00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
    00019  *   Lesser General Public License for more details.                       *
    00020  *                                                                         *
    00021  *   You should have received a copy of the GNU Lesser General Public      *
    00022  *   License along with this library; if not, write to the Free Software   *
    00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
    00024  *   MA  02111-1307  USA                                                   *
    00025  *                                                                         *
    00026  ***************************************************************************/
    00027
    00028
    00029 #ifndef GWENHYWFAR_BUFFEREDIO_H
    00030 #define GWENHYWFAR_BUFFEREDIO_H "$Id: bufferedio.h,v 1.23 2005/03/07 10:35:49 cstim Exp $"
    00031
    00032 #include <gwenhywfar/gwenhywfarapi.h>
    00033 #include <gwenhywfar/inherit.h>
    00034
    00035 #ifdef __cplusplus
    00036 extern "C" {
    00037 #endif
    00038   typedef struct GWEN_BUFFEREDIOSTRUCT GWEN_BUFFEREDIO;
    00039   GWEN_INHERIT_FUNCTION_LIB_DEFS(GWEN_BUFFEREDIO, GWENHYWFAR_API)
    00040   /* No trailing semicolon because this is a macro call */
    00041 #ifdef __cplusplus
    00042 }
    00043 #endif
    00044
    00045 #include <gwenhywfar/error.h>
    00046
    00047 /* for compatibility only */
    00048 #include <gwenhywfar/bio_file.h>
    00049 #include <gwenhywfar/bio_socket.h>
    00050 #include <gwenhywfar/bio_buffer.h>
    00051 #include <gwenhywfar/buffer.h>
    00052
    00053
    00054
    00055 #ifdef __cplusplus
    00056 extern "C" {
    00057 #endif
    00058
    00059 #define GWEN_BUFFEREDIO_ERROR_TYPE    "BufferedIO"
    00060 #define GWEN_BUFFEREDIO_ERROR_READ    1
    00061 #define GWEN_BUFFEREDIO_ERROR_WRITE   2
    00062 #define GWEN_BUFFEREDIO_ERROR_CLOSE   3
    00063 #define GWEN_BUFFEREDIO_ERROR_TIMEOUT 4
    00064 #define GWEN_BUFFEREDIO_ERROR_PARTIAL 5
    00065 #define GWEN_BUFFEREDIO_ERROR_EOF     6
    00066 #define GWEN_BUFFEREDIO_ERROR_NO_DATA 7
    00067
    00068
    00069 #define GWEN_BUFFEREDIO_CHAR_ERROR   (-1)
    00070 #define GWEN_BUFFEREDIO_CHAR_EOF     (-2)
    00071 #define GWEN_BUFFEREDIO_CHAR_NO_DATA (-3)
    00072
    00073
    00075 #define GWEN_BUFFEREDIO_FLAGS_CLOSE   0x00000001
    00076
    00077 #define GWEN_BUFFEREDIO_FLAGS_DEFAULT \
    00078   (\
    00079   GWEN_BUFFEREDIO_FLAGS_CLOSE\
    00080   )
    00081
    00082
    00083 #define GWEN_BUFFEREDIO_CBID_IO "GWEN_BUFFEREDIO_CBID_IO"
    00084
    00085
    00086 typedef enum {
    00087   GWEN_LineModeUnix=0,
    00088   GWEN_LineModeDOS
    00089 } GWEN_BUFFEREDIOLINEMODE;
    00090
    00091 typedef GWEN_ERRORCODE (*GWEN_BUFFEREDIOREADFN)(GWEN_BUFFEREDIO *dm,
    00092                                                  char *buffer,
    00093                                                   int *size,
    00094                                                   int timeout);
    00095 typedef GWEN_ERRORCODE (*GWEN_BUFFEREDIOWRITEFN)(GWEN_BUFFEREDIO *dm,
    00096                                                    const char *buffer,
    00097                                                    int *size,
    00098                                                    int timeout);
    00099 typedef GWEN_ERRORCODE (*GWEN_BUFFEREDIOCLOSEFN)(GWEN_BUFFEREDIO *dm);
    00100
    00101
    00102
    00108 GWENHYWFAR_API GWEN_BUFFEREDIO *GWEN_BufferedIO_new();
    00109
    00114 GWENHYWFAR_API void GWEN_BufferedIO_free(GWEN_BUFFEREDIO *dm);
    00115
    00126 GWENHYWFAR_API void GWEN_BufferedIO_SetReadBuffer(GWEN_BUFFEREDIO *bt,
    00127                                                   char *buffer,
    00128                                                   int len);
    00129
    00139 GWENHYWFAR_API void GWEN_BufferedIO_SetWriteBuffer(GWEN_BUFFEREDIO *bt,
    00140                                                    char *buffer,
    00141                                                    int len);
    00142
    00148 GWENHYWFAR_API int GWEN_BufferedIO_CheckEOF(GWEN_BUFFEREDIO *dm);
    00149
    00157 GWENHYWFAR_API int GWEN_BufferedIO_PeekChar(GWEN_BUFFEREDIO *dm);
    00158
    00170 GWENHYWFAR_API int GWEN_BufferedIO_ReadChar(GWEN_BUFFEREDIO *bio);
    00171
    00177 GWENHYWFAR_API GWEN_ERRORCODE GWEN_BufferedIO_Flush(GWEN_BUFFEREDIO *bt);
    00178
    00189 GWENHYWFAR_API GWEN_ERRORCODE GWEN_BufferedIO_ShortFlush(GWEN_BUFFEREDIO *bt);
    00190
    00191 /*
    00192  * Returns !=0 if the read buffer is empty, 0 if it is not.
    00193  */
    00194 GWENHYWFAR_API int GWEN_BufferedIO_ReadBufferEmpty(GWEN_BUFFEREDIO *bt);
    00195
    00196
    00197 /*
    00198  * Returns !=0 if the write buffer is empty, 0 if it is not.
    00199  */
    00200 GWENHYWFAR_API int GWEN_BufferedIO_WriteBufferEmpty(GWEN_BUFFEREDIO *bt);
    00201
    00208 GWENHYWFAR_API GWEN_ERRORCODE GWEN_BufferedIO_ReadLine(GWEN_BUFFEREDIO *bt,
    00209                                                        char *buffer,
    00210                                                        unsigned int s);
    00211
    00218 GWENHYWFAR_API
    00219 GWEN_ERRORCODE GWEN_BufferedIO_ReadLine2Buffer(GWEN_BUFFEREDIO *bt,
    00220                                                GWEN_BUFFER *buffer);
    00221
    00226 GWENHYWFAR_API GWEN_ERRORCODE GWEN_BufferedIO_WriteChar(GWEN_BUFFEREDIO *dm,
    00227                                                         char c);
    00228
    00234 GWENHYWFAR_API GWEN_ERRORCODE GWEN_BufferedIO_Write(GWEN_BUFFEREDIO *bt,
    00235                                                     const char *buffer);
    00236
    00243 GWENHYWFAR_API GWEN_ERRORCODE GWEN_BufferedIO_WriteLine(GWEN_BUFFEREDIO *bt,
    00244                                                         const char *buffer);
    00245
    00250 GWENHYWFAR_API GWEN_ERRORCODE GWEN_BufferedIO_Close(GWEN_BUFFEREDIO *dm);
    00251
    00252
    00261 GWENHYWFAR_API
    00262 void GWEN_BufferedIO_SetLineMode(GWEN_BUFFEREDIO *dm,
    00263                                  GWEN_BUFFEREDIOLINEMODE lm);
    00264
    00269 GWENHYWFAR_API
    00270 GWEN_TYPE_UINT32 GWEN_BufferedIO_GetFlags(const GWEN_BUFFEREDIO *bt);
    00271
    00276 GWENHYWFAR_API
    00277 void GWEN_BufferedIO_SetFlags(GWEN_BUFFEREDIO *bt, GWEN_TYPE_UINT32 f);
    00278
    00283 GWENHYWFAR_API
    00284 void GWEN_BufferedIO_AddFlags(GWEN_BUFFEREDIO *bt, GWEN_TYPE_UINT32 f);
    00285
    00290 GWENHYWFAR_API
    00291 void GWEN_BufferedIO_SubFlags(GWEN_BUFFEREDIO *bt, GWEN_TYPE_UINT32 f);
    00292
    00293
    00298 GWENHYWFAR_API
    00299 GWEN_BUFFEREDIOLINEMODE GWEN_BufferedIO_GetLineMode(GWEN_BUFFEREDIO *dm);
    00300
    00301
    00311 GWENHYWFAR_API
    00312 void GWEN_BufferedIO_SetTimeout(GWEN_BUFFEREDIO *dm, int timeout);
    00313
    00314
    00318 GWENHYWFAR_API
    00319 int GWEN_BufferedIO_GetTimeout(GWEN_BUFFEREDIO *dm);
    00320
    00321
    00322 GWENHYWFAR_API
    00323 int GWEN_BufferedIO_GetLines(const GWEN_BUFFEREDIO *dm);
    00324
    00325
    00326 GWENHYWFAR_API
    00327 int GWEN_BufferedIO_GetLinePos(const GWEN_BUFFEREDIO *dm);
    00328
    00329
    00330 GWENHYWFAR_API
    00331 int GWEN_BufferedIO_GetBytesRead(const GWEN_BUFFEREDIO *dm);
    00332
    00333 GWENHYWFAR_API
    00334 int GWEN_BufferedIO_GetBytesWritten(const GWEN_BUFFEREDIO *dm);
    00335
    00336
    00337 GWENHYWFAR_API
    00338 void GWEN_BufferedIO_SetReadFn(GWEN_BUFFEREDIO *dm,
    00339                                GWEN_BUFFEREDIOREADFN fn);
    00340 GWENHYWFAR_API
    00341 void GWEN_BufferedIO_SetWriteFn(GWEN_BUFFEREDIO *dm,
    00342                                 GWEN_BUFFEREDIOWRITEFN fn);
    00343 GWENHYWFAR_API
    00344 void GWEN_BufferedIO_SetCloseFn(GWEN_BUFFEREDIO *dm,
    00345                                 GWEN_BUFFEREDIOCLOSEFN fn);
    00346
    00347
    00352 GWENHYWFAR_API
    00353 GWEN_ERRORCODE GWEN_BufferedIO_Abandon(GWEN_BUFFEREDIO *dm);
    00354
    00355
    00368 GWENHYWFAR_API
    00369   GWEN_ERRORCODE GWEN_BufferedIO_WriteRaw(GWEN_BUFFEREDIO *bt,
    00370                                           const char *buffer,
    00371                                           unsigned int *bsize);
    00372
    00373
    00382 GWENHYWFAR_API
    00383   GWEN_ERRORCODE GWEN_BufferedIO_ReadRaw(GWEN_BUFFEREDIO *bt,
    00384                                          char *buffer,
    00385                                          unsigned int *bsize);
    00386
    00390 GWENHYWFAR_API
    00391   GWEN_ERRORCODE GWEN_BufferedIO_ReadRawForced(GWEN_BUFFEREDIO *bt,
    00392                                                char *buffer,
    00393                                                unsigned int *bsize);
    00394
    00398 GWENHYWFAR_API
    00399   GWEN_ERRORCODE GWEN_BufferedIO_WriteRawForced(GWEN_BUFFEREDIO *bt,
    00400                                                 char *buffer,
    00401                                                 unsigned int *bsize);
    00402
    00403
    00404
    00405 #ifdef __cplusplus
    00406 }
    00407 #endif
    00408
    00409
    00410 #endif /* GWENHYWFAR_BUFFEREDIO_H */
    00411
    00412
    00413
    00414
    00415