rtxMemBuf.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  *****************************************************************************/
00024 
00041 /* memory buffer */
00042 
00043 #ifndef _RTXMEMBUF_H_
00044 #define _RTXMEMBUF_H_
00045 
00046 #include "rtxsrc/rtxContext.h"
00047 
00048 typedef struct OSRTMEMBUF {
00049    OSCTXT*      pctxt;
00050    OSUINT32     segsize;        /* segment size                     */
00051    OSUINT32     startidx;       /* start index of useful info       */
00052    OSUINT32     usedcnt;        /* used byte count                  */
00053    OSUINT32     bufsize;        /* buffer size                      */
00054    OSUINT32     bitOffset;      /* bit offset                       */
00055    OSUINT32     userState;      /* user state - any value, 0 is initial */
00056    OSOCTET*     buffer;         /* memory buffer                    */
00057    OSBOOL       isDynamic;      /* is buffer allocated dynamically? */
00058    OSBOOL       isExpandable;   /* is buffer expandable?            */
00059    OSBOOL       useSysMem;      /* use system memory management     */
00060 } OSRTMEMBUF;
00061 
00062 #define OSMBDFLTSEGSIZE 1024
00063 
00064 #define OSMEMBUFPTR(pmb)    ((pmb)->buffer + (pmb)->startidx)
00065 #define OSMEMBUFENDPTR(pmb) ((pmb)->buffer + (pmb)->startidx + (pmb)->usedcnt)
00066 #define OSMEMBUFUSEDSIZE(pmb) ((size_t)(pmb)->usedcnt)
00067 
00068 #define OSMBAPPENDSTR(pmb,str) \
00069 rtxMemBufAppend(pmb,(OSOCTET*)str,OSCRTLSTRLEN(str))
00070 
00071 #define OSMBAPPENDUTF8(pmb,str) \
00072 rtxMemBufAppend(pmb,(OSOCTET*)str,rtxUTF8LenBytes(str))
00073 
00074 #ifdef __cplusplus
00075 extern "C" {
00076 #endif
00077 
00078 /* Memory buffer functions */
00079 
00094 EXTERNRT int rtxMemBufAppend
00095 (OSRTMEMBUF* pMemBuf, const OSOCTET* pdata, size_t nbytes);
00096 
00111 EXTERNRT int rtxMemBufCut
00112 (OSRTMEMBUF* pMemBuf, size_t fromOffset, size_t nbytes);
00113 
00121 EXTERNRT void rtxMemBufFree (OSRTMEMBUF* pMemBuf);
00122 
00131 EXTERNRT OSOCTET* rtxMemBufGetData (OSRTMEMBUF* pMemBuf, int* length);
00132 
00139 EXTERNRT int rtxMemBufGetDataLen (OSRTMEMBUF* pMemBuf);
00140 
00153 EXTERNRT void rtxMemBufInit
00154 (OSCTXT* pCtxt, OSRTMEMBUF* pMemBuf, size_t segsize);
00155 
00173 EXTERNRT void rtxMemBufInitBuffer (OSCTXT* pCtxt, OSRTMEMBUF* pMemBuf,
00174                                     OSOCTET* buf, size_t bufsize,
00175                                     size_t segsize);
00176 
00186 EXTERNRT int rtxMemBufPreAllocate (OSRTMEMBUF* pMemBuf, size_t nbytes);
00187 
00194 EXTERNRT void rtxMemBufReset (OSRTMEMBUF* pMemBuf);
00195 
00211 EXTERNRT int rtxMemBufSet (OSRTMEMBUF* pMemBuf, OSOCTET value, size_t nbytes);
00212 
00224 EXTERNRT OSBOOL rtxMemBufSetExpandable
00225 (OSRTMEMBUF* pMemBuf, OSBOOL isExpandable);
00226 
00237 EXTERNRT OSBOOL rtxMemBufSetUseSysMem (OSRTMEMBUF* pMemBuf, OSBOOL value);
00238 
00247 EXTERNRT int rtxMemBufTrimW (OSRTMEMBUF* pMemBuf);
00248 
00252 #ifdef __cplusplus
00253 }
00254 #endif
00255 
00256 #endif