Home | History | Annotate | Download | only in inc
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 /**
     17  ************************************************************************
     18  * @file         M4OSA_Debug.h
     19  * @brief        Debug and Trace Macro
     20  ************************************************************************
     21 */
     22 
     23 
     24 #ifndef _M4OSA_DEBUG_H_
     25 #define _M4OSA_DEBUG_H_
     26 
     27 #include "M4OSA_Error.h"
     28 #include "M4OSA_Types.h"
     29 
     30 
     31 /* defaut value, defined only if not defined already. */
     32 #ifndef M4TRACE_ID
     33 #define M4TRACE_ID M4UNKNOWN_COREID
     34 #endif /* M4TRACE_ID undefined */
     35 
     36 
     37 #define M4OSA_SUPER_DEBUG_LEVEL 0
     38 
     39 #ifndef M4OSA_DEBUG_LEVEL
     40 #define M4OSA_DEBUG_LEVEL       0
     41 #endif
     42 
     43 
     44 #define M4OSA_SUPER_TRACE_LEVEL 0
     45 
     46 #ifndef M4OSA_TRACE_LEVEL
     47 #define M4OSA_TRACE_LEVEL       0
     48 #endif
     49 
     50 #ifdef __cplusplus
     51 extern "C"
     52 {
     53 #endif
     54 
     55 
     56 #if (M4OSA_DEBUG_LEVEL >= 1) || (M4OSA_SUPER_DEBUG_LEVEL >= 1)
     57 
     58 /* Debug macros */
     59 extern M4OSA_Void M4OSA_DEBUG_traceFunction(M4OSA_UInt32 line,
     60                                             M4OSA_Char* fileName,
     61                                             M4OSA_UInt32 level,
     62                                             M4OSA_Char* stringCondition,
     63                                             M4OSA_Char* message,
     64                                             M4OSA_ERR returnedError);
     65 
     66 
     67 #define M4OSA_DEBUG_IFx(cond, errorCode, msg, level)\
     68       if(cond)\
     69       {\
     70          M4OSA_DEBUG_traceFunction(__LINE__, (M4OSA_Char*)__FILE__, level,\
     71                                    (M4OSA_Char*)#cond, (M4OSA_Char*)msg,\
     72                                    (errorCode));\
     73          return(errorCode);\
     74       }
     75 
     76 #define M4OSA_DEBUG(errorCode, msg)\
     77          M4OSA_DEBUG_traceFunction(__LINE__, (M4OSA_Char*)__FILE__, 1,\
     78                                    (M4OSA_Char*)#errorCode, (M4OSA_Char*)msg,\
     79                                    (errorCode));
     80 
     81 #else /*(M4OSA_DEBUG_LEVEL >= 1) || (M4OSA_SUPER_DEBUG_LEVEL >= 1)*/
     82 
     83 
     84 #define M4OSA_DEBUG(errorCode, msg)
     85 
     86 #endif /*(M4OSA_DEBUG_LEVEL >= 1) || (M4OSA_SUPER_DEBUG_LEVEL >= 1)*/
     87 
     88 
     89 
     90 #if (M4OSA_DEBUG_LEVEL >= 1) || (M4OSA_SUPER_DEBUG_LEVEL >= 1)
     91  #define M4OSA_DEBUG_IF1(cond, errorCode, msg)\
     92          M4OSA_DEBUG_IFx(cond, errorCode, msg, 1)
     93 #else
     94  #define M4OSA_DEBUG_IF1(cond, errorCode, msg)
     95 #endif /*(M4OSA_DEBUG_LEVEL >= 1) || (M4OSA_SUPER_DEBUG_LEVEL >= 1)*/
     96 
     97 
     98 #if (M4OSA_DEBUG_LEVEL >= 2) || (M4OSA_SUPER_DEBUG_LEVEL >= 2)
     99  #define M4OSA_DEBUG_IF2(cond, errorCode, msg)\
    100          M4OSA_DEBUG_IFx(cond, errorCode, msg, 2)
    101 #else
    102  #define M4OSA_DEBUG_IF2(cond, errorCode, msg)
    103 #endif /*(M4OSA_DEBUG_LEVEL >= 2) || (M4OSA_SUPER_DEBUG_LEVEL >= 2)*/
    104 
    105 
    106 #if (M4OSA_DEBUG_LEVEL >= 3) || (M4OSA_SUPER_DEBUG_LEVEL >= 3)
    107  #define M4OSA_DEBUG_IF3(cond, errorCode, msg)\
    108          M4OSA_DEBUG_IFx(cond, errorCode, msg, 3)
    109 #else
    110  #define M4OSA_DEBUG_IF3(cond, errorCode, msg)
    111 #endif /*(M4OSA_DEBUG_LEVEL >= 3) || (M4OSA_SUPER_DEBUG_LEVEL >= 3)*/
    112 
    113 
    114 
    115 /* Trace macros */
    116 
    117 #if (M4OSA_TRACE_LEVEL >= 1) || (M4OSA_SUPER_TRACE_LEVEL >= 1)
    118 
    119 extern M4OSA_Void M4OSA_TRACE_traceFunction(M4OSA_UInt32 line,
    120                                             M4OSA_Char* fileName,
    121                                             M4OSA_CoreID coreID,
    122                                             M4OSA_UInt32 level,
    123                                             M4OSA_Char* stringMsg,
    124                                             ... );
    125 
    126 
    127 
    128 #define M4OSA_TRACEx_0(msg, level)\
    129       M4OSA_TRACE_traceFunction(__LINE__, (M4OSA_Char*)__FILE__,\
    130                              (M4OSA_CoreID)M4TRACE_ID, level, (M4OSA_Char*)msg);
    131 
    132 
    133 #define M4OSA_TRACEx_1(msg, param1, level)\
    134       M4OSA_TRACE_traceFunction(__LINE__, (M4OSA_Char*)__FILE__,\
    135                      (M4OSA_CoreID)M4TRACE_ID, level, (M4OSA_Char*)msg, param1);
    136 
    137 
    138 #define M4OSA_TRACEx_2(msg, param1, param2, level)\
    139       M4OSA_TRACE_traceFunction(__LINE__, (M4OSA_Char*)__FILE__,\
    140                                 (M4OSA_CoreID)M4TRACE_ID, level,\
    141                                 (M4OSA_Char*)msg, param1,\
    142                                 param2);
    143 
    144 
    145 #define M4OSA_TRACEx_3(msg, param1, param2, param3, level)\
    146       M4OSA_TRACE_traceFunction(__LINE__, (M4OSA_Char*)__FILE__,\
    147                                 (M4OSA_CoreID)M4TRACE_ID, level, (M4OSA_Char*)msg,\
    148                                 param1,param2, param3);
    149 
    150 
    151 #define M4OSA_TRACEx_4(msg, param1, param2, param3, param4, level)\
    152       M4OSA_TRACE_traceFunction(__LINE__, (M4OSA_Char*)__FILE__,\
    153                                 (M4OSA_CoreID)M4TRACE_ID, level,\
    154                                 (M4OSA_Char*)msg, param1,\
    155                                 param2, param3, param4);
    156 
    157 
    158 #define M4OSA_TRACEx_5(msg, param1, param2, param3, param4, param5, level)\
    159       M4OSA_TRACE_traceFunction(__LINE__, (M4OSA_Char*)__FILE__,\
    160                                 (M4OSA_CoreID)M4TRACE_ID, level,\
    161                                 (M4OSA_Char*)msg, param1,\
    162                                 param2, param3, param4, param5);
    163 
    164 #endif /*(M4OSA_TRACE_LEVEL >= 1) || (M4OSA_SUPER_TRACE_LEVEL >= 1)*/
    165 
    166 
    167 
    168 #if (M4OSA_TRACE_LEVEL >= 1) || (M4OSA_SUPER_TRACE_LEVEL >= 1)
    169 #define M4OSA_TRACE1_0(msg)\
    170         M4OSA_TRACEx_0(msg, 1)
    171 
    172 #define M4OSA_TRACE1_1(msg, param1)\
    173         M4OSA_TRACEx_1(msg, param1, 1)
    174 
    175 #define M4OSA_TRACE1_2(msg, param1, param2)\
    176         M4OSA_TRACEx_2(msg, param1, param2, 1)
    177 
    178 #define M4OSA_TRACE1_3(msg, param1, param2, param3)\
    179         M4OSA_TRACEx_3(msg, param1, param2, param3, 1)
    180 
    181 #define M4OSA_TRACE1_4(msg, param1, param2, param3, param4)\
    182         M4OSA_TRACEx_4(msg, param1, param2, param3, param4, 1)
    183 
    184 #define M4OSA_TRACE1_5(msg, param1, param2, param3, param4, param5)\
    185         M4OSA_TRACEx_5(msg, param1, param2, param3, param4, param5, 1)
    186 
    187 #else /*(M4OSA_TRACE_LEVEL >= 1) || (M4OSA_SUPER_TRACE_LEVEL >= 1)*/
    188 
    189 #define M4OSA_TRACE1_0(msg)
    190 #define M4OSA_TRACE1_1(msg, param1)
    191 #define M4OSA_TRACE1_2(msg, param1, param2)
    192 #define M4OSA_TRACE1_3(msg, param1, param2, param3)
    193 #define M4OSA_TRACE1_4(msg, param1, param2, param3, param4)
    194 #define M4OSA_TRACE1_5(msg, param1, param2, param3, param4, param5)
    195 
    196 #endif /*(M4OSA_TRACE_LEVEL >= 1) || (M4OSA_SUPER_TRACE_LEVEL >= 1)*/
    197 
    198 
    199 #if (M4OSA_TRACE_LEVEL >= 2) || (M4OSA_SUPER_TRACE_LEVEL >= 2)
    200 #define M4OSA_TRACE2_0(msg)\
    201         M4OSA_TRACEx_0(msg, 2)
    202 
    203 #define M4OSA_TRACE2_1(msg, param1)\
    204         M4OSA_TRACEx_1(msg, param1, 2)
    205 
    206 #define M4OSA_TRACE2_2(msg, param1, param2)\
    207         M4OSA_TRACEx_2(msg, param1, param2, 2)
    208 
    209 #define M4OSA_TRACE2_3(msg, param1, param2, param3)\
    210         M4OSA_TRACEx_3(msg, param1, param2, param3, 2)
    211 
    212 #define M4OSA_TRACE2_4(msg, param1, param2, param3, param4)\
    213         M4OSA_TRACEx_4(msg, param1, param2, param3, param4, 2)
    214 
    215 #define M4OSA_TRACE2_5(msg, param1, param2, param3, param4, param5)\
    216         M4OSA_TRACEx_5(msg, param1, param2, param3, param4, param5, 2)
    217 
    218 #else /*(M4OSA_TRACE_LEVEL >= 2) || (M4OSA_SUPER_TRACE_LEVEL >= 2)*/
    219 
    220 #define M4OSA_TRACE2_0(msg)
    221 #define M4OSA_TRACE2_1(msg, param1)
    222 #define M4OSA_TRACE2_2(msg, param1, param2)
    223 #define M4OSA_TRACE2_3(msg, param1, param2, param3)
    224 #define M4OSA_TRACE2_4(msg, param1, param2, param3, param4)
    225 #define M4OSA_TRACE2_5(msg, param1, param2, param3, param4, param5)
    226 #endif /*(M4OSA_TRACE_LEVEL >= 2) || (M4OSA_SUPER_TRACE_LEVEL >= 2)*/
    227 
    228 
    229 #if (M4OSA_TRACE_LEVEL >= 3) || (M4OSA_SUPER_TRACE_LEVEL >= 3)
    230 #define M4OSA_TRACE3_0(msg)\
    231         M4OSA_TRACEx_0(msg, 3)
    232 
    233 #define M4OSA_TRACE3_1(msg, param1)\
    234         M4OSA_TRACEx_1(msg, param1, 3)
    235 
    236 #define M4OSA_TRACE3_2(msg, param1, param2)\
    237         M4OSA_TRACEx_2(msg, param1, param2, 3)
    238 
    239 #define M4OSA_TRACE3_3(msg, param1, param2, param3)\
    240         M4OSA_TRACEx_3(msg, param1, param2, param3, 3)
    241 
    242 #define M4OSA_TRACE3_4(msg, param1, param2, param3, param4)\
    243         M4OSA_TRACEx_4(msg, param1, param2, param3, param4, 3)
    244 
    245 #define M4OSA_TRACE3_5(msg, param1, param2, param3, param4, param5)\
    246         M4OSA_TRACEx_5(msg, param1, param2, param3, param4, param5, 3)
    247 
    248 #else /*(M4OSA_TRACE_LEVEL >= 3) || (M4OSA_SUPER_TRACE_LEVEL >= 3)*/
    249 
    250 #define M4OSA_TRACE3_0(msg)
    251 #define M4OSA_TRACE3_1(msg, param1)
    252 #define M4OSA_TRACE3_2(msg, param1, param2)
    253 #define M4OSA_TRACE3_3(msg, param1, param2, param3)
    254 #define M4OSA_TRACE3_4(msg, param1, param2, param3, param4)
    255 #define M4OSA_TRACE3_5(msg, param1, param2, param3, param4, param5)
    256 
    257 #endif /*(M4OSA_TRACE_LEVEL >= 3) || (M4OSA_SUPER_TRACE_LEVEL >= 3)*/
    258 
    259 
    260 
    261 #ifdef __cplusplus
    262 }
    263 #endif
    264 
    265 #endif /* _M4OSA_DEBUG_H_ */
    266 
    267