Home | History | Annotate | Download | only in src
      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       M4PSW_DebugTrace.c
     19  * @brief      Default trace function for debugging macros
     20  * @note       This file gives the default implementation of the trace function
     21  *             used in the debug instrumentation macros, based on printf.
     22  *             Application writers are strongly encouraged to implement their
     23  *             own "M4OSA_DebugTrace".
     24  ************************************************************************
     25 */
     26 
     27 
     28 #include <stdio.h> /*for printf */
     29 
     30 #include "M4OSA_Types.h"
     31 #include "M4OSA_Error.h"
     32 
     33 /*#define NO_FILE */ /* suppresses the file name print out */
     34 
     35 
     36 /**
     37  ************************************************************************
     38  * void M4OSA_DebugTrace(M4OSA_Int32 line, char* file, M4OSA_Int32 level,
     39  *                       M4OSA_Char* cond, char* msg, M4OSA_ERR err)
     40  * @brief    This function implements the trace for debug tests
     41  * @note    This function is to be called in the debug macros only.
     42  *            This implementation uses printf.
     43  * @param    line (IN): the line number in the source file
     44  * @param    file (IN): the source file name
     45  * @param    level (IN): the debug level
     46  * @param    msg (IN): the error message
     47  * @param    err (IN): the return value (error code)
     48  * @return    none
     49  ************************************************************************
     50 */
     51 
     52 M4OSAL_TRACE_EXPORT_TYPE void M4OSA_DebugTrace(M4OSA_Int32 line,
     53                                                M4OSA_Char* file,
     54                                                M4OSA_Int32 level,
     55                                                M4OSA_Char* cond,
     56                                                M4OSA_Char* msg,
     57                                                M4OSA_ERR err)
     58 {
     59     M4OSA_Int32 i;
     60 
     61     /* try to "indent" the resulting traces depending on the level */
     62     for (i =0 ; i < level; i ++)
     63     {
     64         printf(" ");
     65     }
     66 
     67 #ifdef NO_FILE
     68     printf("Error: %li, on %s: %s\n",err,cond,msg);
     69 #else /* NO_FILE     */
     70     printf("Error: %li, on %s: %s Line %lu in: %s\n",err,cond,msg,line,file);
     71 #endif /* NO_FILE     */
     72 
     73 }
     74 
     75 M4OSAL_TRACE_EXPORT_TYPE M4OSA_Void M4OSA_DEBUG_traceFunction(M4OSA_UInt32 line,
     76                                                               M4OSA_Char* fileName,
     77                                                               M4OSA_UInt32 level,
     78                                                               M4OSA_Char* stringCondition,
     79                                                               M4OSA_Char* message,
     80                                                               M4OSA_ERR returnedError)
     81 {
     82     M4OSA_DebugTrace(line, fileName, level, stringCondition, message, returnedError);
     83 }
     84 
     85