os/graphics/graphicscomposition/openwfcompositionengine/common/src/owfdebug.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/* Copyright (c) 2009 The Khronos Group Inc.
sl@0
     2
 * Portions copyright (c) 2009-2010  Nokia Corporation and/or its subsidiary(-ies)
sl@0
     3
 *
sl@0
     4
 * Permission is hereby granted, free of charge, to any person obtaining a
sl@0
     5
 * copy of this software and/or associated documentation files (the
sl@0
     6
 * "Materials"), to deal in the Materials without restriction, including
sl@0
     7
 * without limitation the rights to use, copy, modify, merge, publish,
sl@0
     8
 * distribute, sublicense, and/or sell copies of the Materials, and to
sl@0
     9
 * permit persons to whom the Materials are furnished to do so, subject to
sl@0
    10
 * the following conditions:
sl@0
    11
 *
sl@0
    12
 * The above copyright notice and this permission notice shall be included
sl@0
    13
 * in all copies or substantial portions of the Materials.
sl@0
    14
 *
sl@0
    15
 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
sl@0
    16
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
sl@0
    17
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
sl@0
    18
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
sl@0
    19
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
sl@0
    20
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
sl@0
    21
 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
sl@0
    22
 */
sl@0
    23
sl@0
    24
sl@0
    25
#include "owfdebug.h"
sl@0
    26
#ifdef DEBUG_LOG
sl@0
    27
sl@0
    28
#include <pthread.h>
sl@0
    29
sl@0
    30
#include "owfdebug.h"
sl@0
    31
#include "owftypes.h"
sl@0
    32
#include "owfdebug.h"
sl@0
    33
sl@0
    34
#ifdef __cplusplus
sl@0
    35
extern "C" {
sl@0
    36
#endif
sl@0
    37
sl@0
    38
sl@0
    39
#ifndef OWF_DEBUG_PREFIX
sl@0
    40
#define OWF_DEBUG_PREFIX "OWF: "
sl@0
    41
#endif
sl@0
    42
int xprintf(const char* aFormat, ...);
sl@0
    43
sl@0
    44
/* This pair of macros are a standard trick 
sl@0
    45
 * to convert the content of a macro into a string after expansion
sl@0
    46
 * TOSTR causes the macro to be expanded, then TOSTR2 applies quotes.
sl@0
    47
 * This is used because .MMP MACRO does not consistantly process macro value quotes.
sl@0
    48
 */
sl@0
    49
#define TOSTR2(x)    #x
sl@0
    50
#define TOSTR(x)    TOSTR2(x)
sl@0
    51
sl@0
    52
sl@0
    53
/* Filters debug messages based on filename or function name.
sl@0
    54
 * @param symbol the file or function name string generated by predefined macros
sl@0
    55
 * @param symlen the length of the string (calculated at compile-time)
sl@0
    56
 * Defining DEBUG_LOG enables all log file output. Do this in the make or .MMP file
sl@0
    57
 * The file output can be filtered by filename or by function name:
sl@0
    58
 * Defining DEBUG_FUNCTION=fnname will filter for all functions STARTING with the name fnname
sl@0
    59
 * Defining DEBUG_FILE=filename will filter for all functions ending with the name filename
sl@0
    60
 * 
sl@0
    61
 * These filters utilise the predefined macros __FILE__ and __FUNCTION__ which are defined in current standards,
sl@0
    62
 * but may contain platform-specific features such as path names, or linkage decoration,
sl@0
    63
 * so the filter-string may require some platform-specific tuning.
sl@0
    64
 * 
sl@0
    65
 * Note that use of #pragma message may also be platform-specific, and is only present in order to 
sl@0
    66
 * print clues about the format of the __FILE__ and __FUNCTION__ macros.
sl@0
    67
 */
sl@0
    68
int  OWF_Debug_DoLog(const char* symbol,int symlen)
sl@0
    69
    {
sl@0
    70
#if defined(DEBUG_LOG_FILE)
sl@0
    71
#pragma message ("DEBUG filter DEBUG_FILE= '" TOSTR(DEBUG_FILE) "' eg= '" __FILE__ "'")
sl@0
    72
    if (symlen>=(sizeof(TOSTR(DEBUG_FILE))-1))
sl@0
    73
        {
sl@0
    74
        return strncmp( symbol+symlen-(sizeof(TOSTR(DEBUG_FILE))-1) , TOSTR(DEBUG_FILE) , sizeof(TOSTR(DEBUG_FILE))-1 )==0;
sl@0
    75
        }
sl@0
    76
    else
sl@0
    77
        return 0;
sl@0
    78
#elif defined(DEBUG_LOG_FUNCTION)
sl@0
    79
#pragma message("DEBUG filter DEBUG_FUNCTION= '" TOSTR(DEBUG_FUNCTION) "' eg= '" __FUNCTION__ "'")
sl@0
    80
    if (symlen>=(sizeof(TOSTR(DEBUG_FILE))-1))
sl@0
    81
        {
sl@0
    82
        return(strncmp(TOSTR(DEBUG_FUNCTION),symbol,sizeof(TOSTR(DEBUG_FUNCTION))-1)==0);
sl@0
    83
        }
sl@0
    84
    else
sl@0
    85
        return 0;
sl@0
    86
#else
sl@0
    87
    (void)symbol;
sl@0
    88
    (void)symlen;
sl@0
    89
    return 1;
sl@0
    90
#endif
sl@0
    91
sl@0
    92
    }
sl@0
    93
sl@0
    94
void OWF_Debug_Print(const char* format, ...)
sl@0
    95
{    
sl@0
    96
    va_list                 ap;
sl@0
    97
    char                    __spager[512];
sl@0
    98
sl@0
    99
    va_start(ap, format);
sl@0
   100
    __spager[0] = 0;
sl@0
   101
    vsnprintf(__spager, 511, format, ap);
sl@0
   102
    xprintf("%s %s\n", OWF_DEBUG_PREFIX, __spager);
sl@0
   103
    va_end(ap);
sl@0
   104
}
sl@0
   105
sl@0
   106
sl@0
   107
void OWF_Debug_Trace(const char* fmt, ...)
sl@0
   108
{
sl@0
   109
    fmt = fmt;
sl@0
   110
}
sl@0
   111
sl@0
   112
sl@0
   113
sl@0
   114
void OWF_Debug_TraceIndent()
sl@0
   115
{
sl@0
   116
}
sl@0
   117
sl@0
   118
void OWF_Debug_TraceUndent()
sl@0
   119
{
sl@0
   120
}
sl@0
   121
sl@0
   122
void OWF_Debug_TraceEnter(const char* func)
sl@0
   123
{
sl@0
   124
    if (func)
sl@0
   125
    {
sl@0
   126
        OWF_Debug_Trace("ENTER %s", func);
sl@0
   127
    }
sl@0
   128
    OWF_Debug_TraceIndent();
sl@0
   129
}
sl@0
   130
sl@0
   131
void OWF_Debug_TraceExit(const char* func)
sl@0
   132
{
sl@0
   133
    OWF_Debug_TraceUndent();
sl@0
   134
    if (func)
sl@0
   135
    {
sl@0
   136
        OWF_Debug_Trace("EXIT %s", func);
sl@0
   137
    }
sl@0
   138
}
sl@0
   139
sl@0
   140
sl@0
   141
#ifdef __cplusplus
sl@0
   142
}
sl@0
   143
#endif
sl@0
   144
sl@0
   145
#else
sl@0
   146
sl@0
   147
sl@0
   148
#endif /* DEBUG */