Home > Support > Documentation

rtxContext.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 _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       spare[2];       /* word boundary padding                */
00138    struct OSRTSTREAM* pStream;   /* Stream                               */
00139    struct OSRTPrintStream *pPrintStrm; /* Print Stream                   */
00140    OSRTDList elemNameStack;      /* element name stack                   */
00141    OSRTDList regExpCache;        /* compiled regular expression cache    */
00142    const OSOCTET* key;           /* pointer to run-time key data         */
00143    size_t        keylen;         /* run-time key length                  */
00144    OSVoidPtr     pXMLInfo;       /* XML specific info                    */
00145    OSVoidPtr     pASN1Info;      /* ASN.1 specific info                  */
00146    OSVoidPtr     pUserData;      /* User defined data                    */
00147 } OSCTXT;
00148 
00149 #define OSRT_GET_FIRST_ERROR_INFO(pctxt) \
00150 (((pctxt)->errInfo.list.head == 0) ? (OSRTErrInfo*)0 : \
00151 (OSRTErrInfo*)((pctxt)->errInfo.list.head->data))
00152 
00153 #define OSRT_GET_LAST_ERROR_INFO(pctxt) \
00154 (((pctxt)->errInfo.list.tail == 0) ? (OSRTErrInfo*)0 : \
00155 (OSRTErrInfo*)((pctxt)->errInfo.list.tail->data))
00156 
00157 /*
00158  * OSRTFreeCtxtAppInfoPtr is a pointer to pctxt->pAppInfo free function,
00159  * The pctxt->pAppInfo (pXMLInfo and pASN1Info) should contain the pointer 
00160  * to a structure and its first member should be a pointer to an appInfo 
00161  * free function. 
00162  */
00163 typedef int (*OSFreeCtxtAppInfoPtr)(OSCTXT* pctxt);
00164 
00165 /*
00166  * OSRTResetCtxtAppInfoPtr is a pointer to pctxt->pAppInfo reset function,
00167  * The pctxt->pAppInfo (pXMLInfo and pASN1Info) should contain the pointer 
00168  * to a structure and its second member should be a pointer to appInfo reset 
00169  * function.
00170  */
00171 typedef int (*OSResetCtxtAppInfoPtr)(OSCTXT* pctxt);
00172 
00176 #define OSRTISSTREAM(pctxt) \
00177 ((pctxt)->pStream != 0 && !((pctxt)->flags & OSDISSTRM))
00178 
00179 #define OSRTBUFSAVE(pctxt) { \
00180 (pctxt)->savedInfo.byteIndex = (pctxt)->buffer.byteIndex; \
00181 (pctxt)->savedInfo.flags = (pctxt)->flags; }
00182 
00183 #define OSRTBUFRESTORE(pctxt) { \
00184 (pctxt)->buffer.byteIndex = (pctxt)->savedInfo.byteIndex; \
00185 (pctxt)->flags = (pctxt)->savedInfo.flags; }
00186 
00187 #ifdef __cplusplus
00188 extern "C" {
00189 #endif
00190 
00214 EXTERNRTX int rtxInitContext (OSCTXT* pctxt);
00215 
00234 EXTERNRTX int rtxInitContextBuffer (OSCTXT* pctxt, 
00235                                     OSOCTET* bufaddr, 
00236                                     size_t bufsiz);
00237 
00247 EXTERNRTX int rtxCheckContext (OSCTXT* pctxt);
00248 
00256 EXTERNRTX void rtxFreeContext (OSCTXT* pctxt);
00257 
00258 /*
00259  * This function creates a copy of a context structure. The copy is a "shallow
00260  * copy" (i.e. new copies of dynamic memory blocks held within the context are
00261  * not made, only the pointers are transferred to the new context structure).
00262  * This function is mainly for use from within compiler-generated code.
00263  *
00264  * @param pdest        - Context structure to which data is to be copied.
00265  * @param psrc         - Context structure from which data is to be copied.
00266  */
00267 EXTERNRTX void rtxCopyContext (OSCTXT* pdest, OSCTXT* psrc);
00268 
00275 EXTERNRTX void rtxCtxtSetFlag (OSCTXT* pctxt, OSUINT32 mask);
00276 
00284 EXTERNRTX void rtxCtxtClearFlag (OSCTXT* pctxt, OSUINT32 mask);
00285 
00292 #define rtxCtxtTestFlag(pctxt,mask) ((pctxt->flags & mask) != 0)
00293 
00294 EXTERNRTX int  rtxPreInitContext (OSCTXT* pctxt);
00295 EXTERNRTX void rtxResetContext (OSCTXT* pctxt);
00296 
00297 
00298 
00299 EXTERNRTX void rtxMemFreeOpenSeqExt 
00300 (OSCTXT* pctxt, struct OSRTDList *pElemList);
00301 
00302 /*
00303  * This function sets flags to a heap. May be used to control the heap's
00304  * behavior.
00305  *
00306  * @param pctxt        Pointer to a memory block structure that contains the
00307  *                       list of dynamic memory block maintained by these
00308  *                       functions.
00309  * @param flags        The flags.
00310  */
00311 EXTERNRTX void  rtxMemHeapSetFlags (OSCTXT* pctxt, OSUINT32 flags);
00312 
00313 /*
00314  * This function clears memory heap flags.
00315  *
00316  * @param pctxt        Pointer to a memory block structure that contains the
00317  *                       list of dynamic memory block maintained by these
00318  *                       functions.
00319  * @param flags        The flags
00320  */
00321 EXTERNRTX void  rtxMemHeapClearFlags (OSCTXT* pctxt, OSUINT32 flags);
00322 
00323 /*
00324  * This function sets the minimum size and the granularity of memory blocks
00325  * in memory heap for the context.  
00326  *
00327  * @param pctxt        Pointer to a context block.
00328  * @param blkSize      The currently used minimum size and the granularity of
00329  *                       memory blocks.
00330  */
00331 EXTERNRTX void  rtxMemHeapSetDefBlkSize (OSCTXT* pctxt, OSUINT32 blkSize);
00332 
00333 /*
00334  * This function returns the actual granularity of memory blocks in the context.
00335  *
00336  * @param pctxt        Pointer to a context block.
00337  */
00338 EXTERNRTX OSUINT32 rtxMemHeapGetDefBlkSize (OSCTXT* pctxt);
00339 
00340 
00341 #ifdef __cplusplus
00342 }
00343 #endif
00344 
00345 #endif