Home > Support > Documentation

rtxStream.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2003-2007 Objective Systems, Inc.
00003  *
00004  * This software is furnished under a license and may be used and copied
00005  * only in accordance with the terms of such license and with the
00006  * inclusion of the above copyright notice. This software or any other
00007  * copies thereof may not be provided or otherwise made available to any
00008  * other person. No title to and ownership of the software is hereby
00009  * transferred.
00010  *
00011  * The information in this software is subject to change without notice
00012  * and should not be construed as a commitment by Objective Systems, Inc.
00013  *
00014  * PROPRIETARY NOTICE
00015  *
00016  * This software is an unpublished work subject to a confidentiality agreement
00017  * and is protected by copyright and trade secret law.  Unauthorized copying,
00018  * redistribution or other use of this work is prohibited.
00019  *
00020  * The above notice of copyright on this source code product does not indicate
00021  * any actual or intended publication of such source code.
00022  *
00023  *****************************************************************************/
00028 #ifndef _RTXSTREAM_H_
00029 #define _RTXSTREAM_H_
00030 
00031 #include "rtxsrc/rtxContext.h"
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00056 struct OSRTSTREAM;
00057 
00063 typedef long (*OSRTStreamReadProc)
00064    (struct OSRTSTREAM* pStream, OSOCTET* pbuffer, size_t bufSize);
00065 
00071 typedef long (*OSRTStreamBlockingReadProc)
00072    (struct OSRTSTREAM* pStream, OSOCTET* pbuffer, size_t toReadBytes);
00073 
00079 typedef long (*OSRTStreamWriteProc)(struct OSRTSTREAM* pStream, 
00080                                    const OSOCTET* data, size_t numocts);
00081 
00087 typedef int (*OSRTStreamFlushProc)(struct OSRTSTREAM* pStream);
00088 
00094 typedef int (*OSRTStreamCloseProc)(struct OSRTSTREAM* pStream);
00095 
00101 typedef int (*OSRTStreamSkipProc) 
00102    (struct OSRTSTREAM* pStream, size_t skipBytes);
00103 
00109 typedef int (*OSRTStreamMarkProc) 
00110    (struct OSRTSTREAM* pStream, size_t readAheadLimit);
00111 
00117 typedef int (*OSRTStreamResetProc) (struct OSRTSTREAM* pStream);
00118 
00119 #define OSRTSTRMF_INPUT      0x0001
00120 #define OSRTSTRMF_OUTPUT     0x0002
00121 #define OSRTSTRMF_BUFFERED   0x8000 /* direct-buffer stream    */
00122 #define OSRTSTRMF_UNBUFFERED 0x4000 /* force unbuffered stream */
00123 #define OSRTSTRMF_POSMARKED  0x2000 /* stream has marked position */
00124 
00125 #define OSRTSTRMF_BUF_INPUT    (OSRTSTRMF_INPUT|OSRTSTRMF_BUFFERED)
00126 #define OSRTSTRMF_BUF_OUTPUT   (OSRTSTRMF_OUTPUT|OSRTSTRMF_BUFFERED)
00127 
00128 
00129 #define OSRTSTRMID_FILE      1
00130 #define OSRTSTRMID_SOCKET    2
00131 #define OSRTSTRMID_MEMORY    3
00132 #define OSRTSTRMID_BUFFERED  4
00133 #define OSRTSTRMID_DIRECTBUF 5
00134 #define OSRTSTRMID_USER   1000
00135 
00136 #define OSRTSTRM_K_BUFSIZE 1024
00137 
00138 #define OSRTSTRM_K_INVALIDMARK ((size_t)-1)
00139 
00140 #define OSRTSTREAM_BYTEINDEX(pctxt) \
00141 (((pctxt)->pStream->id == OSRTSTRMID_DIRECTBUF) ? \
00142 ((pctxt)->pStream->bytesProcessed + (pctxt)->buffer.byteIndex) : \
00143 ((pctxt)->pStream->ioBytes))
00144 
00145 #define OSRTSTREAM_ID(pctxt) ((pctxt)->pStream->id)
00146 #define OSRTSTREAM_FLAGS(pctxt) ((pctxt)->pStream->flags)
00147 
00153 typedef struct OSRTSTREAM {
00154    OSRTStreamReadProc  read;   /*< pointer to read function  */
00155    OSRTStreamBlockingReadProc blockingRead;/*< pointer to blockingRead function*/
00156    OSRTStreamWriteProc write;  /*< pointer to write function */
00157    OSRTStreamFlushProc flush;  /*< pointer to flush function */
00158    OSRTStreamCloseProc close;  /*< pointer to close function */
00159    OSRTStreamSkipProc  skip;   /*< pointer to skip function  */
00160    OSRTStreamMarkProc  mark;   /*< pointer to mark function  */
00161    OSRTStreamResetProc reset;  /*< pointer to reset function  */
00162 
00163    void*     extra;          /*< pointer to stream-specific data      */
00164 
00165    size_t    bufsize;        /*< physical size of pctxt->buffer.data buf */
00166    size_t    readAheadLimit; /*< read ahead limit (used by ::rtxStreamMark/::rtxStreamReset */
00167    size_t    bytesProcessed; /*< the number of bytes already processed */
00168    size_t    markedBytesProcessed; /*< the marked number of bytes already processed */
00169    size_t    ioBytes;        /*< the actual number of bytes already read/written    */
00170    size_t    nextMarkOffset; /* offset of next appropriate mark position */
00171 
00172    OSUINT32  id;             /*< id of stream (see OSRTSTRMID_* macros  */
00173 
00174    /* this should be included in extra..
00175    OSRTSOCKET socket;         *< socket handle for socket streams     */
00176 
00177    OSUINT16  flags;          /*< flags (see OSRTSTRMF_* macros          */
00178 } OSRTSTREAM;
00179 
00189 EXTERNRTX int rtxStreamClose (OSCTXT* pctxt);
00190 
00201 EXTERNRTX int rtxStreamFlush (OSCTXT* pctxt);
00202 
00212 EXTERNRTX int rtxStreamInit (OSCTXT* pctxt);
00213 
00230 EXTERNRTX long rtxStreamRead 
00231    (OSCTXT* pctxt, OSOCTET* pbuffer, size_t bufSize);
00232 
00249 EXTERNRTX long rtxStreamBlockingRead 
00250    (OSCTXT* pctxt, OSOCTET* pbuffer, size_t readBytes);
00251 
00263 EXTERNRTX int rtxStreamSkip  (OSCTXT* pctxt, size_t skipBytes);
00264 
00277 EXTERNRTX long rtxStreamWrite 
00278    (OSCTXT* pctxt, const OSOCTET* data, size_t numocts);
00279 
00294 EXTERNRTX int rtxStreamGetIOBytes (OSCTXT* pctxt, size_t* pPos);
00295 
00310 EXTERNRTX int rtxStreamMark (OSCTXT* pctxt, size_t readAheadLimit);
00311 
00321 EXTERNRTX int rtxStreamReset (OSCTXT* pctxt);
00322 
00333 EXTERNRTX OSBOOL rtxStreamMarkSupported (OSCTXT* pctxt);
00334 
00343 EXTERNRTX OSBOOL rtxStreamIsOpened (OSCTXT* pctxt);
00344 
00353 EXTERNRTX OSBOOL rtxStreamIsReadable (OSCTXT* pctxt);
00354 
00363 EXTERNRTX OSBOOL rtxStreamIsWritable (OSCTXT* pctxt);
00364 
00374 EXTERNRTX int rtxStreamRelease (OSCTXT* pctxt);
00375 
00378 #ifdef __cplusplus
00379 }
00380 #endif
00381 
00382 #endif /* _RTXSTREAM_H_ */
00383