Home > Support > Documentation

rtxContext.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2003-2008 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 OSSAVEBUF       0x10000000  /* do not free dynamic encode buffer */
00119 #define OSNOSTRMBACKOFF 0x8000000   /* stream mark/reset funcs is not used */
00120 
00128 typedef struct OSCTXT {          /* run-time context block               */
00129    void*         pMemHeap;       /* internal message memory heap         */
00130    OSRTBuffer    buffer;         /* data buffer                          */
00131    OSRTBufSave   savedInfo;      /* saved buffer info                    */
00132    OSRTErrInfoList errInfo;      /* run-time error info                  */
00133    OSUINT32      initCode;       /* code double word to indicate init    */
00134    OSRTFLAGS     flags;          /* flag bits                            */
00135    OSOCTET       level;          /* nesting level                        */
00136    OSOCTET       state;          /* encode/decode process state          */
00137    OSOCTET       diagLevel;      /* diagnostic trace level               */
00138    OSOCTET       spare[1];       /* word boundary padding                */
00139    struct OSRTSTREAM* pStream;   /* Stream                               */
00140    struct OSRTPrintStream *pPrintStrm; /* Print Stream                   */
00141    OSRTDList elemNameStack;      /* element name stack                   */
00142    OSRTDList regExpCache;        /* compiled regular expression cache    */
00143    const OSOCTET* key;           /* pointer to run-time key data         */
00144    size_t        keylen;         /* run-time key length                  */
00145    OSVoidPtr     pXMLInfo;       /* XML specific info                    */
00146    OSVoidPtr     pASN1Info;      /* ASN.1 specific info                  */
00147    OSVoidPtr     pEXIInfo;       /* EXI specific info                    */
00148    OSVoidPtr     pUserData;      /* User defined data                    */
00149 } OSCTXT;
00150 
00151 #define OSRT_GET_FIRST_ERROR_INFO(pctxt) \
00152 (((pctxt)->errInfo.list.head == 0) ? (OSRTErrInfo*)0 : \
00153 (OSRTErrInfo*)((pctxt)->errInfo.list.head->data))
00154 
00155 #define OSRT_GET_LAST_ERROR_INFO(pctxt) \
00156 (((pctxt)->errInfo.list.tail == 0) ? (OSRTErrInfo*)0 : \
00157 (OSRTErrInfo*)((pctxt)->errInfo.list.tail->data))
00158 
00159 /*
00160  * OSRTFreeCtxtAppInfoPtr is a pointer to pctxt->pAppInfo free function,
00161  * The pctxt->pAppInfo (pXMLInfo and pASN1Info) should contain the pointer 
00162  * to a structure and its first member should be a pointer to an appInfo 
00163  * free function. 
00164  */
00165 typedef int (*OSFreeCtxtAppInfoPtr)(OSCTXT* pctxt);
00166 
00167 /*
00168  * OSRTResetCtxtAppInfoPtr is a pointer to pctxt->pAppInfo reset function,
00169  * The pctxt->pAppInfo (pXMLInfo and pASN1Info) should contain the pointer 
00170  * to a structure and its second member should be a pointer to appInfo reset 
00171  * function.
00172  */
00173 typedef int (*OSResetCtxtAppInfoPtr)(OSCTXT* pctxt);
00174 
00178 #define OSRTISSTREAM(pctxt) \
00179 ((pctxt)->pStream != 0 && !((pctxt)->flags & OSDISSTRM))
00180 
00181 #define OSRTBUFSAVE(pctxt) { \
00182 (pctxt)->savedInfo.byteIndex = (pctxt)->buffer.byteIndex; \
00183 (pctxt)->savedInfo.flags = (pctxt)->flags; }
00184 
00185 #define OSRTBUFRESTORE(pctxt) { \
00186 (pctxt)->buffer.byteIndex = (pctxt)->savedInfo.byteIndex; \
00187 (pctxt)->flags = (pctxt)->savedInfo.flags; }
00188 
00189 #ifdef __cplusplus
00190 extern "C" {
00191 #endif
00192 
00216 EXTERNRT int rtxInitContext (OSCTXT* pctxt);
00217 
00236 EXTERNRT int rtxInitContextBuffer (OSCTXT* pctxt, 
00237                                     OSOCTET* bufaddr, 
00238                                     size_t bufsiz);
00239 
00249 EXTERNRT int rtxCheckContext (OSCTXT* pctxt);
00250 
00258 EXTERNRT void rtxFreeContext (OSCTXT* pctxt);
00259 
00260 /*
00261  * This function creates a copy of a context structure. The copy is a "shallow
00262  * copy" (i.e. new copies of dynamic memory blocks held within the context are
00263  * not made, only the pointers are transferred to the new context structure).
00264  * This function is mainly for use from within compiler-generated code.
00265  *
00266  * @param pdest        - Context structure to which data is to be copied.
00267  * @param psrc         - Context structure from which data is to be copied.
00268  */
00269 EXTERNRT void rtxCopyContext (OSCTXT* pdest, OSCTXT* psrc);
00270 
00277 EXTERNRT void rtxCtxtSetFlag (OSCTXT* pctxt, OSUINT32 mask);
00278 
00286 EXTERNRT void rtxCtxtClearFlag (OSCTXT* pctxt, OSUINT32 mask);
00287 
00294 #define rtxCtxtTestFlag(pctxt,mask) ((pctxt->flags & mask) != 0)
00295 
00296 EXTERNRT int  rtxPreInitContext (OSCTXT* pctxt);
00297 #if 0
00298 EXTERNRT void rtxResetContext (OSCTXT* pctxt);
00299 #endif
00300 EXTERNRT void rtxMemFreeOpenSeqExt 
00301 (OSCTXT* pctxt, struct OSRTDList *pElemList);
00302 
00303 /*
00304  * This function sets flags to a heap. May be used to control the heap's
00305  * behavior.
00306  *
00307  * @param pctxt        Pointer to a memory block structure that contains the
00308  *                       list of dynamic memory block maintained by these
00309  *                       functions.
00310  * @param flags        The flags.
00311  */
00312 EXTERNRT void  rtxMemHeapSetFlags (OSCTXT* pctxt, OSUINT32 flags);
00313 
00314 /*
00315  * This function clears memory heap flags.
00316  *
00317  * @param pctxt        Pointer to a memory block structure that contains the
00318  *                       list of dynamic memory block maintained by these
00319  *                       functions.
00320  * @param flags        The flags
00321  */
00322 EXTERNRT void  rtxMemHeapClearFlags (OSCTXT* pctxt, OSUINT32 flags);
00323 
00324 /*
00325  * This function sets the minimum size and the granularity of memory blocks
00326  * in memory heap for the context.  
00327  *
00328  * @param pctxt        Pointer to a context block.
00329  * @param blkSize      The currently used minimum size and the granularity of
00330  *                       memory blocks.
00331  */
00332 EXTERNRT void  rtxMemHeapSetDefBlkSize (OSCTXT* pctxt, OSUINT32 blkSize);
00333 
00334 /*
00335  * This function returns the actual granularity of memory blocks in the context.
00336  *
00337  * @param pctxt        Pointer to a context block.
00338  */
00339 EXTERNRT OSUINT32 rtxMemHeapGetDefBlkSize (OSCTXT* pctxt);
00340 
00341 
00342 #ifdef __cplusplus
00343 }
00344 #endif
00345 
00348 #endif