Home | History | Annotate | Download | only in src
      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 /*
     34 *   @file  timm_osal_trace.c
     35 *   This file contains methods that provides the functionality
     36 *   for logging errors/warings/information/etc.
     37 *
     38 *  @path \
     39 *
     40 */
     41 /* -------------------------------------------------------------------------- */
     42 /* =========================================================================
     43  *!
     44  *! Revision History
     45  *! ===================================
     46  *!
     47  * ========================================================================= */
     48 
     49 /******************************************************************************
     50 * Includes
     51 ******************************************************************************/
     52 
     53 /*#include "typedefs.h"*/
     54 #include <stdarg.h>
     55 #include <stdio.h>
     56 #include <stdlib.h>
     57 #include "timm_osal_trace.h"
     58 
     59 #ifdef _Android
     60 #define LOG_TAG "DOMX"
     61 #include <utils/Log.h>
     62 #endif
     63 
     64 /**
     65 * The OSAL debug trace detail can be set at compile time by defining the flag
     66 * TIMM_OSAL_DEBUG_TRACE_DETAIL=<Details>
     67 * detail - 0 - no detail
     68 *          1 - function name
     69 *          2 - function name, line number
     70 * Prefix is added to every debug trace message
     71 */
     72 #ifndef TIMM_OSAL_DEBUG_TRACE_DETAIL
     73 #define TIMM_OSAL_DEBUG_TRACE_DETAIL 2
     74 #endif
     75 
     76 #define DEFAULT_TRACE_LEVEL 1
     77 
     78 static int trace_level = -1;
     79 
     80 /* strip out leading ../ stuff that happens to __FILE__ for out-of-tree builds */
     81 static const char *simplify_path(const char *file)
     82 {
     83 	while (file)
     84 	{
     85 		char c = file[0];
     86 		if ((c != '.') && (c != '/') && (c != '\\'))
     87 			break;
     88 		file++;
     89 	}
     90 	return file;
     91 }
     92 
     93 void __TIMM_OSAL_TraceFunction(const __TIMM_OSAL_TRACE_LOCATION * loc,
     94     const char *fmt, ...)
     95 {
     96 	if (trace_level == -1)
     97 	{
     98 		char *val = getenv("TIMM_OSAL_DEBUG_TRACE_LEVEL");
     99 		trace_level =
    100 		    val ? strtol(val, NULL, 0) : DEFAULT_TRACE_LEVEL;
    101 	}
    102 
    103 	if (trace_level >= loc->level)
    104 	{
    105 		va_list ap;
    106 
    107 		va_start(ap, fmt);	/* make ap point to first arg after 'fmt' */
    108 
    109 #ifdef _Android
    110 
    111 #if ( TIMM_OSAL_DEBUG_TRACE_DETAIL > 1 )
    112 		ALOGD("%s:%d\t%s()\t", simplify_path(loc->file), loc->line,
    113 		    loc->function);
    114 #endif
    115 		char string[1000];
    116 		vsprintf(string, fmt, ap);
    117 		ALOGD("%s",string);
    118 
    119 #else
    120 
    121 #if ( TIMM_OSAL_DEBUG_TRACE_DETAIL > 1 )
    122 		printf("%s:%d\t%s()\t", simplify_path(loc->file), loc->line,
    123 		    loc->function);
    124 #endif
    125 		vprintf(fmt, ap);
    126 
    127 #endif
    128 		va_end(ap);
    129 	}
    130 }
    131