rtxStream.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2003-2010 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 #ifndef _NO_STREAM
00032 
00033 #include "rtxsrc/rtxContext.h"
00034 #include "rtxsrc/rtxMemBuf.h"
00035 
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039 
00059 struct OSRTSTREAM;
00060 
00066 typedef long (*OSRTStreamReadProc)
00067    (struct OSRTSTREAM* pStream, OSOCTET* pbuffer, size_t bufSize);
00068 
00074 typedef long (*OSRTStreamBlockingReadProc)
00075    (struct OSRTSTREAM* pStream, OSOCTET* pbuffer, size_t toReadBytes);
00076 
00082 typedef long (*OSRTStreamWriteProc)(struct OSRTSTREAM* pStream,
00083                                    const OSOCTET* data, size_t numocts);
00084 
00090 typedef int (*OSRTStreamFlushProc)(struct OSRTSTREAM* pStream);
00091 
00097 typedef int (*OSRTStreamCloseProc)(struct OSRTSTREAM* pStream);
00098 
00104 typedef int (*OSRTStreamSkipProc)
00105    (struct OSRTSTREAM* pStream, size_t skipBytes);
00106 
00112 typedef int (*OSRTStreamMarkProc)
00113    (struct OSRTSTREAM* pStream, size_t readAheadLimit);
00114 
00120 typedef int (*OSRTStreamResetProc) (struct OSRTSTREAM* pStream);
00121 
00122 #define OSRTSTRMF_INPUT      0x0001
00123 #define OSRTSTRMF_OUTPUT     0x0002
00124 #define OSRTSTRMF_BUFFERED   0x8000 /* direct-buffer stream    */
00125 #define OSRTSTRMF_UNBUFFERED 0x4000 /* force unbuffered stream */
00126 #define OSRTSTRMF_POSMARKED  0x2000 /* stream has marked position */
00127 #define OSRTSTRMF_FIXINMEM   0x1000 /* disable flushing */
00128 
00129 #define OSRTSTRMF_BUF_INPUT    (OSRTSTRMF_INPUT|OSRTSTRMF_BUFFERED)
00130 #define OSRTSTRMF_BUF_OUTPUT   (OSRTSTRMF_OUTPUT|OSRTSTRMF_BUFFERED)
00131 
00132 
00133 #define OSRTSTRMID_FILE      1
00134 #define OSRTSTRMID_SOCKET    2
00135 #define OSRTSTRMID_MEMORY    3
00136 #define OSRTSTRMID_BUFFERED  4
00137 #define OSRTSTRMID_DIRECTBUF 5
00138 #define OSRTSTRMID_CTXTBUF   6
00139 #define OSRTSTRMID_ZLIB      7
00140 #define OSRTSTRMID_USER   1000
00141 
00142 #define OSRTSTRM_K_BUFSIZE 1024
00143 
00144 #define OSRTSTRM_K_INVALIDMARK ((size_t)-1)
00145 
00146 #define OSRTSTREAM_BYTEINDEX(pctxt) \
00147 (((pctxt)->pStream->id == OSRTSTRMID_DIRECTBUF) ? \
00148 ((pctxt)->pStream->bytesProcessed + (pctxt)->buffer.byteIndex) : \
00149 ((pctxt)->pStream->ioBytes))
00150 
00151 #define OSRTSTREAM_ID(pctxt) ((pctxt)->pStream->id)
00152 #define OSRTSTREAM_FLAGS(pctxt) ((pctxt)->pStream->flags)
00153 
00159 typedef struct OSRTSTREAM {
00160    OSRTStreamReadProc  read;   /*< pointer to read function  */
00161    OSRTStreamBlockingReadProc blockingRead;/*< pointer to blockingRead function*/
00162    OSRTStreamWriteProc write;  /*< pointer to write function */
00163    OSRTStreamFlushProc flush;  /*< pointer to flush function */
00164    OSRTStreamCloseProc close;  /*< pointer to close function */
00165    OSRTStreamSkipProc  skip;   /*< pointer to skip function  */
00166    OSRTStreamMarkProc  mark;   /*< pointer to mark function  */
00167    OSRTStreamResetProc reset;  /*< pointer to reset function  */
00168 
00169    void*     extra;          /*< pointer to stream-specific data      */
00170 
00171    size_t    bufsize;        /*< physical size of pctxt->buffer.data buf */
00172    size_t    readAheadLimit; /*< read ahead limit (used by ::rtxStreamMark/::rtxStreamReset */
00173    size_t    bytesProcessed; /*< the number of bytes already processed */
00174    size_t    markedBytesProcessed; /*< the marked number of bytes already processed */
00175    size_t    ioBytes;        /*< the actual number of bytes already read/written    */
00176    size_t    nextMarkOffset; /* offset of next appropriate mark position */
00177 
00178    OSUINT32  id;             /*< id of stream (see OSRTSTRMID_* macros  */
00179 
00184    OSRTMEMBUF* pCaptureBuf;
00185 
00186    OSUINT16  flags;          /*< flags (see OSRTSTRMF_* macros          */
00187 } OSRTSTREAM;
00188 
00198 EXTERNRT int rtxStreamClose (OSCTXT* pctxt);
00199 
00210 EXTERNRT int rtxStreamFlush (OSCTXT* pctxt);
00211 
00221 EXTERNRT int rtxStreamInit (OSCTXT* pctxt);
00222 
00239 EXTERNRT long rtxStreamRead
00240    (OSCTXT* pctxt, OSOCTET* pbuffer, size_t bufSize);
00241 
00258 EXTERNRT long rtxStreamBlockingRead
00259    (OSCTXT* pctxt, OSOCTET* pbuffer, size_t readBytes);
00260 
00272 EXTERNRT int rtxStreamSkip  (OSCTXT* pctxt, size_t skipBytes);
00273 
00286 EXTERNRT long rtxStreamWrite
00287    (OSCTXT* pctxt, const OSOCTET* data, size_t numocts);
00288 
00303 EXTERNRT int rtxStreamGetIOBytes (OSCTXT* pctxt, size_t* pPos);
00304 
00319 EXTERNRT int rtxStreamMark (OSCTXT* pctxt, size_t readAheadLimit);
00320 
00330 EXTERNRT int rtxStreamReset (OSCTXT* pctxt);
00331 
00342 EXTERNRT OSBOOL rtxStreamMarkSupported (OSCTXT* pctxt);
00343 
00352 EXTERNRT OSBOOL rtxStreamIsOpened (OSCTXT* pctxt);
00353 
00362 EXTERNRT OSBOOL rtxStreamIsReadable (OSCTXT* pctxt);
00363 
00372 EXTERNRT OSBOOL rtxStreamIsWritable (OSCTXT* pctxt);
00373 
00383 EXTERNRT int rtxStreamRelease (OSCTXT* pctxt);
00384 
00395 EXTERNRT void rtxStreamSetCapture (OSCTXT* pctxt, OSRTMEMBUF* pmembuf);
00396 
00406 EXTERNRT OSRTMEMBUF* rtxStreamGetCapture (OSCTXT* pctxt);
00407 
00410 #ifdef __cplusplus
00411 }
00412 #endif
00413 
00414 #endif /* _NO_STREAM */
00415 #endif /* _RTXSTREAM_H_ */
00416