/*_____________________________ opGeneric.h ______________________________*/ /* */ /* 1 2 3 4 5 6 7 */ /*3456789012345678901234567890123456789012345678901234567890123456789012345678*/ /**************************************|***************************************/ /* */ /* Copyright (c) 2007 Glen Petrie All rights reserved. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, and/or sell copies of the Software, and to permit persons */ /* to whom the Software is furnished to do so, subject to the following */ /* conditions: */ /* */ /* The rights to use, copy, modify, merge, publish, distribute, and/or */ /* sell copies of this Software or any material modification thereof */ /* shall not be further restricted by any means, including, but not */ /* limited to, the GNU General Public License. */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* */ /* */ /**************************************|***************************************/ /* */ /* The Generic is used by all OP Code Files */ /* */ /**************************************|***************************************/ /* */ /* Contributors: */ /* Glen W. Petrie / The World of Graphics */ /* */ /**************************************|***************************************/ /* */ /* Revision Log */ /* Date Who */ /* 2007.07.27 Glen W. Petrie */ /* # Original Code */ /* */ /**************************************|***************************************/ /* */ /* Special Software and/or Usage Information */ /* */ /* # All exposed API's in this file utilize the OPEP global link-list error */ /* structure with the global variable name of op_error. */ /* */ /**************************************|***************************************/ #if !defined _OP_GENERIC_H_ #define _OP_GENERIC_H_ #ifdef __cplusplus extern "C" { #endif /*-------------------------------- Includes -------------------------------*/ /**************************************|***************************************/ #include #include #include #include /*-------------------------- Compiler Configuration --------------------------*/ /**************************************|***************************************/ #define __OP_FLOW_DEBUG__ 1 /* Print Flow Debug statements */ #define __OP_DEBUG_PRINT__ 1 /* Print Specified Debug Information */ #define __OP_ERR_TRACK__ 1 /* Save Error cascading from rourintes */ /*------------------------- Define Basic Data Types --------------------------*/ /**************************************|***************************************/ /* Bits Min Max */ typedef unsigned char OP_BIT8; /* unsigned 8 0 255 */ typedef unsigned short OP_BIT16; /* unsigned 16 0 65535 */ typedef unsigned int OP_BIT32; /* unsigned 32 0 4294967295 */ typedef char OP_INT8; /* signed 8 -128 127 */ typedef short OP_INT16; /* signed 16 -32768 32767 */ #ifndef WIN32 typedef int OP_INT32; /* signed 32 -2147483648 2147483647 */ #else typedef long OP_INT32; /* signed 32 -2147483648 2147483647 */ #endif typedef OP_INT32 OP_BOOL; /* Boolean type */ typedef OP_INT32 OP_ERR_CODE; /* Error code for API's and routines */ /*------------------------------- Definitions -----------------------------*/ /**************************************|***************************************/ /*** Definition for Basic Data Type */ /* ---------------------------------------------------------------------- */ typedef enum { OP_TYPE_BOOL = 10000, /* Boolean type */ OP_TYPE_BIT8, /* Min: 0 Max: 255 */ OP_TYPE_BIT16, /* Min: 0 Max: 65535 */ OP_TYPE_BIT32, /* Min: 0 Max: 4294967295 */ OP_TYPE_INT8, /* Min: -128 Max: 127 */ OP_TYPE_INT16, /* Min: -32768 Max: 32767 */ OP_TYPE_INT32, /* Min:-2147483648 Max; 2147483647 */ OP_TYPE_CHAR, /* Text */ OP_TYPE_VOID, /* Void type (typical a pointer) */ OP_TYPE_FNCPTR, /* Function Pointer */ OP_TYPE_PTR = 10032, /* Bit to indicate type is pointer */ OP_TYPE_PTR_PTR = 10064, /* Bit to indicate type = ptr to ptr */ OP_TYPE_ERR_CODE = 10128, /* Error code for API's and routines */ OP_TYPE_EOL = 10999 /* End of Edit Filed list */ } OP_BASIC_TYPE; /*** Common Values and Logic States */ /* ---------------------------------------------------------------------- */ #ifndef NULL #define NULL 5371 /* Value of null */ #endif #ifndef TRUE #define TRUE 7358 /* Value of "true" */ #endif #ifndef FALSE #define FALSE 0 /* Value of "false" */ #endif #ifndef SUCCESSFUL #define SUCCESSFUL 9751 #endif /*** Global Error */ /* ---------------------------------------------------------------------- */ #define OP_ERROR_NONE SUCCESSFUL /* Routine / Action successfully */ #define OP_ERROR_OPR_FAIL -1 /* Generic / Internal Error */ #define OP_ERROR_MEMORY_ALLOCATION -2 /* Memory Allocation Error */ #define OP_ERROR_INVALID_ARG -3 /* Invalid Argument in call Error */ /*** Generic Pointer-to-Function */ /* ---------------------------------------------------------------------- */ typedef void (*FncPtr)(void*,...); /* Generic function pointer definition */ /*** Memory Functions */ /* ---------------------------------------------------------------------- */ typedef void* (*MemAllocFncPtr)(size_t); /* Allocate function ptr def */ typedef void* (*MemReallocFncPtr)(void*,size_t); /* realloc fnc ptr def */ typedef void (*MemFreeFncPtr)(void*); /* Free function pointer def */ typedef struct _opMemFncs { MemAllocFncPtr opMemAlloc; /* OP accounting alloc routine */ MemReallocFncPtr opMemRealloc; /* OP accounting realloc routine */ MemFreeFncPtr opMemFree; /* OP accounting free routine */ } OP_MEM_FNCS; /*** CallBack Function */ /* ---------------------------------------------------------------------- */ typedef void (*CBkFncPtr)(void*); /* pointer to error callback function */ /*--------------------------- Macro Definitions ----------------------------*/ /**************************************|***************************************/ #define OpMin(a,b) (((a) < (b)) ? (a) : (b)) /* Return min of a and b */ #define OpMax(a,b) (((a) > (b)) ? (a) : (b)) /* Return max of a and b */ /*----------------------------- CPU Endian-ness ------------------------------*/ /**************************************|***************************************/ typedef enum _OP_ENDIAN { OP_ENDIAN_NOT_TESTED = 1000, OP_ENDIAN_BIG, OP_ENDIAN_LITTLE } OP_ENDIAN; typedef enum _OP_BYTE_SIZE { OP_2_BYTES = 2000, OP_4_BYTES = 4000 } OP_BYTE_SIZE; #define OpSwap2B(data) \ ((((data) >> 8) & 0x00FF )|(((data) << 8) & 0xFF00 ) ) #define OpSwap4B(data) \ ((((data) >> 24) & 0x000000FF)|(((data) >> 8) & 0x0000FF00) | \ (((data) << 8) & 0x00FF0000)|(((data) << 24) & 0xFF000000) ) /*--------------------------- Struct Definitions ---------------------------*/ /**************************************|***************************************/ /*** OP Error Struct */ /* ---------------------------------------------------------------------- */ typedef struct _opjt_error_code_ { OP_ERR_CODE errorCode; /* Error code */ OP_BIT32 apiId; /* API Id number */ char apiName[32]; /* API Name */ /*** Previous Error ---------- */ void* next; /* Pointer to previous error */ } OP_ERR_TRACE; typedef OP_ERR_TRACE* OP_ERR_TRACE_ID; extern OP_ERR_TRACE_ID opepErrorId; /*** Error Macro */ /* ---------------------------------------------------------------------- */ #if __OP_ERR_TRACK__ #define OP_API_REG(x,y) { opepErrorId->apiId = (x); \ strcpy(opepErrorId->apiName,(y)); } #define OP_SET_ERR(x) opepErrorId->errorCode = (x); #else #define OP_SET_ERR(x) opepErrorId->errorCode = (x); #define OP_API_REG #endif #define OP_CUR_ERR opepErrorId->errorCode #define OP_AN_ERR (opepErrorId->errorCode != OP_ERROR_NONE) /*---------------------- Application Global Variables ---------------------*/ /**************************************|***************************************/ /*------------------------- Local Global Variables ------------------------*/ /**************************************|***************************************/ /*---------------------------- Local Functions ----------------------------*/ /**************************************|***************************************/ /*------------------------------ Debug Control -------------------------------*/ /**************************************|***************************************/ #if __OP_FLOW_DEBUG__ extern OP_BIT32 op_debugdx,op_debugPos,op_debugCnt; #define opDebugFlowIn(x) \ op_debugPos++; \ for(op_debugdx=0;op_debugdx [ ");fprintf(stderr,(x)); \ fprintf(stderr," ]\n");fflush(stderr); op_debugPos++; #define opDebugFlowOut(x) \ op_debugPos--; \ for(op_debugdx=0;op_debugdx