rtxContext.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 _RTXCONTEXT_H_
00029 #define _RTXCONTEXT_H_
00030 
00031 #include "rtxsrc/rtxDList.h"
00032 
00033 #define OSRTENCBUFSIZ 16*1024    /* dynamic encode buffer extent size     */
00034 
00039 /* run-time error info structures */
00040 
00041 #define OSRTERRSTKSIZ   8       /* error stack size                     */
00042 #define OSRTMAXERRPRM   5       /* maximum error parameters             */
00043 
00051 typedef struct {
00052    const OSUTF8CHAR* module;
00053    OSINT32      lineno;
00054 } OSRTErrLocn;
00055 
00066 typedef struct {
00067    OSRTErrLocn  stack[OSRTERRSTKSIZ];
00068    OSINT16      status;
00069    OSUINT8      stkx;
00070    OSUINT8      parmcnt;
00071    OSUTF8CHAR*  parms[OSRTMAXERRPRM];
00072    OSUTF8CHAR*  elemName;
00073 } OSRTErrInfo;
00074 
00075 typedef struct {
00076    OSRTDList list;              /* list of errors */
00077    OSRTErrInfo reserved;        /* error info elem, used if nomem to alloc */
00078    OSRTDListNode reservedNode;  /* node placeholder for errInfo elem       */
00079 } OSRTErrInfoList;
00080 
00089 typedef struct {
00090    OSOCTET*     data;           /* pointer to start of data buffer      */
00091    size_t       byteIndex;      /* byte index                           */
00092    size_t       size;           /* current buffer size                  */
00093    OSINT16      bitOffset;      /* current bit offset (8 - 1)           */
00094    OSBOOL       dynamic;        /* is buffer dynamic?                   */
00095    OSBOOL       aligned;        /* is buffer byte aligned?              */
00096 } OSRTBuffer;
00097 
00098 typedef OSUINT32 OSRTFLAGS;
00099 
00106 typedef struct {
00107    size_t      byteIndex;      /* byte index                           */
00108    OSINT16     bitOffset;      /* current bit offset (8 - 1)           */
00109    OSRTFLAGS   flags;          /* flag bits                            */
00110 } OSRTBufSave;
00111 
00112 /* OSRTCTXT flag mask values : bits 32 - 16 are for common flags, bits  */
00113 /* 15 - 0 are reserved for application specific flags                   */
00114 
00115 #define OSDIAG          0x80000000  /* diagnostic tracing enabled       */
00116 #define OSTRACE         0x40000000  /* tracing enabled                  */
00117 #define OSDISSTRM       0x20000000  /* disable stream encode/decode     */
00118 #define OSNOSTRMBACKOFF 0x8000000   /* stream mark/reset funcs is not used */
00119 
00120 struct OSCTXT;
00127 typedef int (*OSFreeCtxtAppInfoPtr)(struct OSCTXT* pctxt);
00128 
00135 typedef int (*OSResetCtxtAppInfoPtr)(struct OSCTXT* pctxt);
00136 
00144 typedef void (*OSFreeCtxtGlobalPtr)(struct OSCTXT* pctxt);
00145 
00146 /* Alias for __cdecl modifier; if __cdecl keyword is not supported,
00147  * redefine it as empty macro. */
00148 
00149 #if !defined(OSCDECL)
00150 #if defined(_MSC_VER) || defined(__BORLANDC__)
00151 #define OSCDECL __cdecl
00152 #else
00153 #define OSCDECL
00154 #endif
00155 #endif /* OSCDECL */
00156 
00164 typedef struct OSCTXT {          /* run-time context block               */
00165    void*         pMemHeap;       /* internal message memory heap         */
00166    OSRTBuffer    buffer;         /* data buffer                          */
00167    OSRTBufSave   savedInfo;      /* saved buffer info                    */
00168    OSRTErrInfoList errInfo;      /* run-time error info                  */
00169    OSUINT32      initCode;       /* code double word to indicate init    */
00170    OSRTFLAGS     flags;          /* flag bits                            */
00171    OSOCTET       level;          /* nesting level                        */
00172    OSOCTET       state;          /* encode/decode process state          */
00173    OSOCTET       diagLevel;      /* diagnostic trace level               */
00174    OSOCTET       spare[1];       /* word boundary padding                */
00175 #ifndef _NO_STREAM
00176    struct OSRTSTREAM* pStream;   /* Stream                               */
00177    struct OSRTPrintStream *pPrintStrm; /* Print Stream                   */
00178 #endif /* _NO_STREAM */
00179    OSRTDList elemNameStack;      /* element name stack                   */
00180    OSRTDList regExpCache;        /* compiled regular expression cache    */
00181    const OSOCTET* key;           /* pointer to run-time key data         */
00182    size_t        keylen;         /* run-time key length                  */
00183    OSVoidPtr     pXMLInfo;       /* XML specific info                    */
00184    OSVoidPtr     pASN1Info;      /* ASN.1 specific info                  */
00185    OSVoidPtr     pEXIInfo;       /* EXI specific info                    */
00186    OSVoidPtr     pUserData;      /* User defined data                    */
00187    OSVoidPtr     pGlobalData;    /* Global constant data                 */
00188    OSFreeCtxtGlobalPtr gblFreeFunc; /* Global free function              */
00189    OSVoidPtr     ssl;            /* SSL stack endpoint                   */
00190 } OSCTXT;
00191 
00192 #define OSRT_GET_FIRST_ERROR_INFO(pctxt) \
00193 (((pctxt)->errInfo.list.head == 0) ? (OSRTErrInfo*)0 : \
00194 (OSRTErrInfo*)((pctxt)->errInfo.list.head->data))
00195 
00196 #define OSRT_GET_LAST_ERROR_INFO(pctxt) \
00197 (((pctxt)->errInfo.list.tail == 0) ? (OSRTErrInfo*)0 : \
00198 (OSRTErrInfo*)((pctxt)->errInfo.list.tail->data))
00199 
00203 #ifndef _NO_STREAM
00204 
00205 #define OSRTISSTREAM(pctxt) \
00206 ((pctxt)->pStream != 0 && !((pctxt)->flags & OSDISSTRM))
00207 
00208 #else /* _NO_STREAM */
00209 
00210 #define OSRTISSTREAM(pctxt) FALSE
00211 
00212 #endif /* _NO_STREAM */
00213 
00214 #define OSRTBUFSAVE(pctxt) { \
00215 (pctxt)->savedInfo.byteIndex = (pctxt)->buffer.byteIndex; \
00216 (pctxt)->savedInfo.flags = (pctxt)->flags; }
00217 
00218 #define OSRTBUFRESTORE(pctxt) { \
00219 (pctxt)->buffer.byteIndex = (pctxt)->savedInfo.byteIndex; \
00220 (pctxt)->flags = (pctxt)->savedInfo.flags; }
00221 
00222 /* Pointers to C Run-Time memory allocation functions */
00223 
00224 typedef void *(OSCDECL *OSMallocFunc ) (size_t size);
00225 typedef void *(OSCDECL *OSReallocFunc) (void *ptr, size_t size);
00226 typedef void  (OSCDECL *OSFreeFunc   ) (void *ptr);
00227 
00228 #ifdef __cplusplus
00229 extern "C" {
00230 #endif
00231 
00256 #ifndef rtxInitContext
00257 EXTERNRT int rtxInitContext (OSCTXT* pctxt);
00258 #endif
00259 
00274 EXTERNRT int rtxInitContextExt (OSCTXT* pctxt,
00275                                 OSMallocFunc malloc_func,
00276                                 OSReallocFunc realloc_func,
00277                                 OSFreeFunc free_func);
00278 
00299 EXTERNRT int rtxInitThreadContext (OSCTXT* pctxt, const OSCTXT* pSrcCtxt);
00300 
00319 EXTERNRT int rtxInitContextBuffer
00320 (OSCTXT* pctxt, OSOCTET* bufaddr, size_t bufsiz);
00321 
00345 EXTERNRT int rtxCtxtSetBufPtr
00346 (OSCTXT* pctxt, OSOCTET* bufaddr, size_t bufsiz);
00347 
00359 #define rtxCtxtGetMsgPtr(pctxt) (pctxt)->buffer.data
00360 
00370 #define rtxCtxtGetMsgLen(pctxt) (pctxt)->buffer.byteIndex
00371 
00379 EXTERNRT size_t rtxCtxtGetBitOffset (OSCTXT* pctxt);
00380 
00388 EXTERNRT size_t rtxCtxtGetIOByteCount (OSCTXT* pctxt);
00389 
00399 EXTERNRT int rtxCheckContext (OSCTXT* pctxt);
00400 
00408 EXTERNRT void rtxFreeContext (OSCTXT* pctxt);
00409 
00419 EXTERNRT void rtxCopyContext (OSCTXT* pdest, OSCTXT* psrc);
00420 
00427 EXTERNRT void rtxCtxtSetFlag (OSCTXT* pctxt, OSUINT32 mask);
00428 
00436 EXTERNRT void rtxCtxtClearFlag (OSCTXT* pctxt, OSUINT32 mask);
00437 
00444 #define rtxCtxtTestFlag(pctxt,mask) ((pctxt->flags & mask) != 0)
00445 
00458 EXTERNRT int rtxCtxtPushElemName (OSCTXT* pctxt, const OSUTF8CHAR* elemName);
00459 
00467 EXTERNRT const OSUTF8CHAR* rtxCtxtPopElemName (OSCTXT* pctxt);
00468 
00476 #define rtxCtxtPeekElemName(pctxt) \
00477 (((pctxt)->elemNameStack.count > 0) ? \
00478  (const OSUTF8CHAR*)(pctxt)->elemNameStack.tail->data : (const OSUTF8CHAR*)0)
00479 
00480 EXTERNRT int  rtxPreInitContext (OSCTXT* pctxt);
00481 #if 0
00482 EXTERNRT void rtxResetContext (OSCTXT* pctxt);
00483 #endif
00484 EXTERNRT void rtxMemFreeOpenSeqExt
00485 (OSCTXT* pctxt, struct OSRTDList *pElemList);
00486 
00496 EXTERNRT void  rtxMemHeapSetFlags (OSCTXT* pctxt, OSUINT32 flags);
00497 
00506 EXTERNRT void  rtxMemHeapClearFlags (OSCTXT* pctxt, OSUINT32 flags);
00507 
00516 EXTERNRT void  rtxMemHeapSetDefBlkSize (OSCTXT* pctxt, OSUINT32 blkSize);
00517 
00524 EXTERNRT OSUINT32 rtxMemHeapGetDefBlkSize (OSCTXT* pctxt);
00525 
00529 #define rtxByteAlign(pctxt) \
00530 if ((pctxt)->buffer.bitOffset != 8) { \
00531 (pctxt)->buffer.byteIndex++; (pctxt)->buffer.bitOffset = 8; }
00532 
00533 #ifdef __cplusplus
00534 }
00535 #endif
00536 
00539 #endif