1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicscomposition/openwfcompositionengine/common/src/owfdebug.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,148 @@
1.4 +/* Copyright (c) 2009 The Khronos Group Inc.
1.5 + * Portions copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies)
1.6 + *
1.7 + * Permission is hereby granted, free of charge, to any person obtaining a
1.8 + * copy of this software and/or associated documentation files (the
1.9 + * "Materials"), to deal in the Materials without restriction, including
1.10 + * without limitation the rights to use, copy, modify, merge, publish,
1.11 + * distribute, sublicense, and/or sell copies of the Materials, and to
1.12 + * permit persons to whom the Materials are furnished to do so, subject to
1.13 + * the following conditions:
1.14 + *
1.15 + * The above copyright notice and this permission notice shall be included
1.16 + * in all copies or substantial portions of the Materials.
1.17 + *
1.18 + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1.19 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1.20 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1.21 + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
1.22 + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
1.23 + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1.24 + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
1.25 + */
1.26 +
1.27 +
1.28 +#include "owfdebug.h"
1.29 +#ifdef DEBUG_LOG
1.30 +
1.31 +#include <pthread.h>
1.32 +
1.33 +#include "owfdebug.h"
1.34 +#include "owftypes.h"
1.35 +#include "owfdebug.h"
1.36 +
1.37 +#ifdef __cplusplus
1.38 +extern "C" {
1.39 +#endif
1.40 +
1.41 +
1.42 +#ifndef OWF_DEBUG_PREFIX
1.43 +#define OWF_DEBUG_PREFIX "OWF: "
1.44 +#endif
1.45 +int xprintf(const char* aFormat, ...);
1.46 +
1.47 +/* This pair of macros are a standard trick
1.48 + * to convert the content of a macro into a string after expansion
1.49 + * TOSTR causes the macro to be expanded, then TOSTR2 applies quotes.
1.50 + * This is used because .MMP MACRO does not consistantly process macro value quotes.
1.51 + */
1.52 +#define TOSTR2(x) #x
1.53 +#define TOSTR(x) TOSTR2(x)
1.54 +
1.55 +
1.56 +/* Filters debug messages based on filename or function name.
1.57 + * @param symbol the file or function name string generated by predefined macros
1.58 + * @param symlen the length of the string (calculated at compile-time)
1.59 + * Defining DEBUG_LOG enables all log file output. Do this in the make or .MMP file
1.60 + * The file output can be filtered by filename or by function name:
1.61 + * Defining DEBUG_FUNCTION=fnname will filter for all functions STARTING with the name fnname
1.62 + * Defining DEBUG_FILE=filename will filter for all functions ending with the name filename
1.63 + *
1.64 + * These filters utilise the predefined macros __FILE__ and __FUNCTION__ which are defined in current standards,
1.65 + * but may contain platform-specific features such as path names, or linkage decoration,
1.66 + * so the filter-string may require some platform-specific tuning.
1.67 + *
1.68 + * Note that use of #pragma message may also be platform-specific, and is only present in order to
1.69 + * print clues about the format of the __FILE__ and __FUNCTION__ macros.
1.70 + */
1.71 +int OWF_Debug_DoLog(const char* symbol,int symlen)
1.72 + {
1.73 +#if defined(DEBUG_LOG_FILE)
1.74 +#pragma message ("DEBUG filter DEBUG_FILE= '" TOSTR(DEBUG_FILE) "' eg= '" __FILE__ "'")
1.75 + if (symlen>=(sizeof(TOSTR(DEBUG_FILE))-1))
1.76 + {
1.77 + return strncmp( symbol+symlen-(sizeof(TOSTR(DEBUG_FILE))-1) , TOSTR(DEBUG_FILE) , sizeof(TOSTR(DEBUG_FILE))-1 )==0;
1.78 + }
1.79 + else
1.80 + return 0;
1.81 +#elif defined(DEBUG_LOG_FUNCTION)
1.82 +#pragma message("DEBUG filter DEBUG_FUNCTION= '" TOSTR(DEBUG_FUNCTION) "' eg= '" __FUNCTION__ "'")
1.83 + if (symlen>=(sizeof(TOSTR(DEBUG_FILE))-1))
1.84 + {
1.85 + return(strncmp(TOSTR(DEBUG_FUNCTION),symbol,sizeof(TOSTR(DEBUG_FUNCTION))-1)==0);
1.86 + }
1.87 + else
1.88 + return 0;
1.89 +#else
1.90 + (void)symbol;
1.91 + (void)symlen;
1.92 + return 1;
1.93 +#endif
1.94 +
1.95 + }
1.96 +
1.97 +void OWF_Debug_Print(const char* format, ...)
1.98 +{
1.99 + va_list ap;
1.100 + char __spager[512];
1.101 +
1.102 + va_start(ap, format);
1.103 + __spager[0] = 0;
1.104 + vsnprintf(__spager, 511, format, ap);
1.105 + xprintf("%s %s\n", OWF_DEBUG_PREFIX, __spager);
1.106 + va_end(ap);
1.107 +}
1.108 +
1.109 +
1.110 +void OWF_Debug_Trace(const char* fmt, ...)
1.111 +{
1.112 + fmt = fmt;
1.113 +}
1.114 +
1.115 +
1.116 +
1.117 +void OWF_Debug_TraceIndent()
1.118 +{
1.119 +}
1.120 +
1.121 +void OWF_Debug_TraceUndent()
1.122 +{
1.123 +}
1.124 +
1.125 +void OWF_Debug_TraceEnter(const char* func)
1.126 +{
1.127 + if (func)
1.128 + {
1.129 + OWF_Debug_Trace("ENTER %s", func);
1.130 + }
1.131 + OWF_Debug_TraceIndent();
1.132 +}
1.133 +
1.134 +void OWF_Debug_TraceExit(const char* func)
1.135 +{
1.136 + OWF_Debug_TraceUndent();
1.137 + if (func)
1.138 + {
1.139 + OWF_Debug_Trace("EXIT %s", func);
1.140 + }
1.141 +}
1.142 +
1.143 +
1.144 +#ifdef __cplusplus
1.145 +}
1.146 +#endif
1.147 +
1.148 +#else
1.149 +
1.150 +
1.151 +#endif /* DEBUG */