Home | History | Annotate | Download | only in inc
      1 /*
      2  * Copyright (c) 2010, Texas Instruments Incorporated
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  *
      9  * *  Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  *
     12  * *  Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * *  Neither the name of Texas Instruments Incorporated nor the names of
     17  *    its contributors may be used to endorse or promote products derived
     18  *    from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #ifndef OMX_DEBUG_H
     34 #define OMX_DEBUG_H
     35 
     36 #include "OMX_DebugMem.h"
     37 
     38 #define OMX_NO_MESSAGES    0x00000000
     39 #define OMX_ALL_MESSAGES   0xffff0000
     40 
     41 #define OMX_MASK_FATAL     0x80000000
     42 #define OMX_MASK_ERROR     0x40000000
     43 #define OMX_MASK_WARN      0x20000000
     44 #define OMX_MASK_INFO      0x10000000
     45 #define OMX_MASK_DEBUG     0x08000000
     46 #define OMX_MASK_TRACE     0x04000000
     47 #define OMX_MASK_RESERVE1  0x02000000
     48 #define OMX_MASK_RESERVE2  0x01000000
     49 
     50 #define OMX_MASK_USERMASK  0x00FF0000
     51 
     52 #define OMX_OPTION_FILE    0x00000001
     53 #define OMX_OPTION_FUNC    0x00000002
     54 #define OMX_OPTION_LINE    0x00000004
     55 
     56 #define OMX_MASK_HANDLES   0x0000FFFF
     57 
     58 
     59 
     60 /*
     61  *  ANSI escape sequences for outputing text in various colors
     62  */
     63 #define DBG_TEXT_WHITE   "\x1b[1;37;40m"
     64 #define DBG_TEXT_YELLOW  "\x1b[1;33;40m"
     65 #define DBG_TEXT_MAGENTA "\x1b[1;35;40m"
     66 #define DBG_TEXT_GREEN   "\x1b[1;32;40m"
     67 #define DBG_TEXT_CYAN    "\x1b[1;36;40m"
     68 #define DBG_TEXT_RED     "\x1b[1;31;40m"
     69 
     70 
     71 /* Setup log format (adds newline if no newline provided) */
     72 // do not use this one directly....
     73 #define OMX_LOG_PRINT(HANDLE, STR, ARG...) \
     74     (OMX_Log(HANDLE, __FILE__, __LINE__, __FUNCTION__, STR, ##ARG))
     75 
     76 #ifdef OMX_DEBUG
     77     #define OMX_DPRINT(HANDLE, STR, ARG...) OMX_LOG_PRINT(OMX_MASK_DEBUG | HANDLE, STR, ##ARG)
     78     #define OMX_TPRINT(HANDLE, STR, ARG...) OMX_LOG_PRINT(OMX_MASK_TRACE | HANDLE, STR, ##ARG)
     79 #else
     80     #define OMX_DPRINT(HANDLE, STR, ARG...)
     81     #define OMX_TPRINT(HANDLE, STR, ARG...)
     82 #endif
     83 
     84 /* Later this will be able to be turned on/off separately as a trace */
     85 #define OMX_DENTER(handle) OMX_TPRINT((handle), "+++ENTERING")
     86 #define OMX_DEXIT(handle,retVal) OMX_TPRINT((handle), "---EXITING(0x%x)", (retVal))
     87 
     88 #define OMX_DBG_INT(handle, intVar) OMX_DPRINT(OMX_MASK_DEBUG | (handle), #intVar ": %d", (intVar))
     89 #define OMX_DBG_PTR(handle, ptrVar) OMX_DPRINT(OMX_MASK_DEBUG | (handle), #ptrVar ": 0x%08x", (ptrVar))
     90 #define OMX_DBG_STR(handle, strVar) OMX_DPRINT(OMX_MASK_DEBUG | (handle), #strVar ": %s", (strVar))
     91 
     92 
     93 /* Error/warning printing defines to be used by all sub-components */
     94 #define OMX_INFOPRINT(handle, str,arg...)  (OMX_LOG_PRINT(OMX_MASK_INFO | (handle), "(INFO) "str, ##arg))
     95 #define OMX_WARNPRINT(handle, str,arg...)  (OMX_LOG_PRINT(OMX_MASK_WARN | (handle), "(WARN) "str, ##arg))
     96 #define OMX_ERRPRINT(handle, str,arg...)   (OMX_LOG_PRINT(OMX_MASK_ERROR | (handle), "(ERROR) "str, ##arg))
     97 #define OMX_FATALPRINT(handle, str,arg...)   (OMX_LOG_PRINT(OMX_MASK_FATAL | (handle), "(FATAL) "str, ##arg))
     98 
     99 /* assert macros */
    100 #ifdef OMX_DEBUG
    101     #define OMX_ASSERT(COND) ((!(COND))?OMX_FATALPRINT(0,"OMX_ASSERT("#COND")"),abort():0)
    102 #else
    103     #define OMX_ASSERT(COND)
    104 #endif
    105 
    106 #define OMX_LOG_ADD_MASK(HANDLE,NEW_BITS) (OMX_Log_SetMask((HANDLE), OMX_Log_GetMask(HANDLE) | (NEW_BITS)))
    107 #define OMX_LOG_CLEAR_MASK(HANDLE,NEW_BITS) (OMX_Log_SetMask((HANDLE), OMX_Log_GetMask(HANDLE) & ~(NEW_BITS)))
    108 
    109 #define OMX_LOG_ADD_OPTIONS(HANDLE,NEW_BITS) (OMX_Log_SetOptions((HANDLE), OMX_Log_GetOptions(HANDLE) | (NEW_BITS)))
    110 #define OMX_LOG_CLEAR_OPTIONS(HANDLE,NEW_BITS) (OMX_Log_SetOptions((HANDLE), OMX_Log_GetOptions(HANDLE) & ~(NEW_BITS)))
    111 
    112 typedef unsigned int OMX_DBG_HANDLE;
    113 
    114 OMX_DBG_HANDLE OMX_Log_GetDebugHandle(const char *description);
    115 void           OMX_Log_ReleaseDebugHandle(OMX_DBG_HANDLE hDebug);
    116 unsigned int   OMX_Log_GetMask(OMX_DBG_HANDLE hDebug);
    117 unsigned int   OMX_Log_SetMask(OMX_DBG_HANDLE hDebug, unsigned int uiNewMask);
    118 
    119 unsigned int   OMX_Log_GetOptions(OMX_DBG_HANDLE hDebug);
    120 unsigned int   OMX_Log_SetOptions(OMX_DBG_HANDLE hDebug, unsigned int uiNewOptions);
    121 
    122 void OMX_Log(unsigned int mask, const char *szFileName, int iLineNum,
    123              const char *szFunctionName, const char *strFormat, ...);
    124 
    125 const char *OMX_GetErrorString(OMX_ERRORTYPE error);
    126 
    127 OMX_ERRORTYPE OMX_Log_LoadConfigFile(char* szConfigFile);
    128 
    129 
    130 /*
    131  * The following macros are intended to make accessing a debug handle easier.
    132  *
    133  * For example, for the Util library, you would create a header file called
    134  *   OMX_Util_Private.h.  This file will be included in all source files
    135  *   compiled into the Util library.  The header file uses the 'define' macro
    136  *   to generate a prototype for the getDebugHandle() function:
    137  *
    138  *   DEFINE_DEBUG_HANDLE_FN(UTIL);
    139  *
    140  * Now, in your private header file, define easier macros for printing:
    141  *
    142  *   #define UTIL_DPRINT(str,args...) OMX_DPRINT(ACCESS_DEBUG_HANDLE(UTIL),str,##args)
    143  *   #define UTIL_WARNPRINT(str,args...) OMX_WARNPRINT(ACCESS_DEBUG_HANDLE(UTIL),str,##args)
    144  *   #define UTIL_ERRPRINT(str,args...) OMX_ERRPRINT(ACCESS_DEBUG_HANDLE(UTIL),str,##args)
    145  *
    146  * Finally, in a source file which will be compiled into the lib, for example
    147  *   OMX_Util_Private.c, you implement the function with the 'implement' macro:
    148  *
    149  *   IMPLEMENT_DEBUG_HANDLE_FN(UTIL)
    150  *
    151  */
    152 #define DEFINE_DEBUG_HANDLE_FN(MOD) OMX_DBG_HANDLE getDebugHandle_##MOD(void);
    153 
    154 #define ACCESS_DEBUG_HANDLE(MOD) getDebugHandle_##MOD()
    155 
    156 #define IMPLMENT_DEBUG_HANDLE_FN(MOD) \
    157 OMX_DBG_HANDLE getDebugHandle_##MOD(void)                    \
    158 {                                                            \
    159     static OMX_DBG_HANDLE hDebug = 0;                        \
    160     if(!hDebug) {                                            \
    161         hDebug = OMX_Log_GetDebugHandle(#MOD);               \
    162         OMX_DPRINT(0,"Component "#MOD": hDebug %d",hDebug);  \
    163     }                                                        \
    164     return hDebug;                                           \
    165 }
    166 
    167 
    168 
    169 #endif
    170 
    171