hti/HtiServicePlugins/HtiIpProxyServicePlugin/IPProxyEngine/Src/DebugPrint.h
branchRCL_3
changeset 59 8ad140f3dd41
parent 0 a03f92240627
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Debugging support
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /*
       
    20 Idea:
       
    21 
       
    22     Logging tool for developers, uniform style to write debug log to RDebug or to a File
       
    23 
       
    24 Usage:
       
    25 
       
    26     Configuring:
       
    27      - add to .mmp file
       
    28         // define logging on and logging into file, file must be defined in code
       
    29         // the macros can also be in a header file
       
    30         // and inside ifdef if printing wanted in debug builds
       
    31         MACRO ENABLE_DEBUG_PRINT
       
    32         MACRO DEBUG_OUTPUT_TO_FILE
       
    33         // this library is needed for the file logging, remove if/when not using
       
    34         LIBRARY flogger.lib
       
    35 
       
    36         Alternatively you may enable debug print in a header with:
       
    37         #ifdef _DEBUG // comment this if you want logging in release build
       
    38         #define ENABLE_DEBUG_PRINT
       
    39         #define DEBUG_OUTPUT_TO_FILE
       
    40         #endif // _DEBUG
       
    41 
       
    42      - make a directory: Epoc32\Wins\c\logs\hti\
       
    43 
       
    44     Enabling:
       
    45      - in some source header
       
    46         // log file name if using file logging
       
    47         #define DEBUG_FILENAME "Example.log"
       
    48         // include the printing macros
       
    49         #include "DebugPrint.h"
       
    50 
       
    51     Printing:
       
    52 
       
    53         // normal string
       
    54         DEBUG_PRINT( DEBUG_STRING( "Debug Print" ) );
       
    55         // string with variables
       
    56         DEBUG_PRINT( DEBUG_LINE( "Debug Print %d" ), 100 );
       
    57         TInt index( 100 );
       
    58         DEBUG_PRINT( DEBUG_STRING( "Debug Print %d" ), index );
       
    59 
       
    60         // DEBUG_LINE automatically adds filename and linenumber to output
       
    61         _LIT( KDebugPrintExample, "Example" );
       
    62         DEBUG_PRINT( DEBUG_LINE( "Debug Print %S" ), &KDebugPrintExample );
       
    63 
       
    64 Known issues:
       
    65 
       
    66     - If you use macros from .mmp file remember to abld makefile <target> to change flags from project
       
    67     - Using lots of DEBUG_LINE macros slows down compiling due to excessive preprocessing
       
    68 
       
    69 Ideas & further development:
       
    70 
       
    71     - make rdebug and file logging work simultaneously, currently not possible
       
    72     - enable optional run-time configuring of debug info writing
       
    73 
       
    74 */
       
    75 
       
    76 #ifndef __DEBUGPRINT_H__
       
    77 #define __DEBUGPRINT_H__
       
    78 
       
    79 // Debug logging is enabled, you may enable debug printing in release builds also
       
    80 #ifdef ENABLE_DEBUG_PRINT
       
    81 
       
    82     // warn if this is a release build!!
       
    83     #ifndef _DEBUG
       
    84         #if defined(__VC32__)
       
    85             #pragma message( "Warning: debug printing is on in release build!" )
       
    86         #else // __GCC32__
       
    87             #warning "debug printing is on in release build!"
       
    88         #endif // __VC32__
       
    89     #endif
       
    90 
       
    91 // no include files if no debug printing --> faster compile time
       
    92 // INCLUDES
       
    93 #include <e32std.h>
       
    94 #include <e32svr.h>
       
    95 #include <flogger.h>
       
    96 
       
    97     /**
       
    98      * Depending if the build is UNICODE or not, define the
       
    99      * helper macros that display the source code filename and
       
   100      * linenumber as a part of the debug message.
       
   101      */
       
   102     #ifdef _UNICODE
       
   103         #define STRINGIZE(l) L#l
       
   104         #define TO_NUMBER(l) STRINGIZE(l)
       
   105         #define TOKEN_PASTING(s) L##s
       
   106         #define TO_UNICODE(s) TOKEN_PASTING(s)
       
   107         #define DEBUG_STR(m) TO_UNICODE(__FILE__) L"(" TO_NUMBER(__LINE__) L") : " L##m
       
   108     #else
       
   109         #define STRINGIZE(l) #l
       
   110         #define TO_NUMBER(l) STRINGIZE(l)
       
   111         #define DEBUG_STR __FILE__ "(" TO_NUMBER(__LINE__) ") : "
       
   112     #endif // _UNICODE
       
   113 
       
   114     /**
       
   115      * Helper macro for defining debug strings with just the debug text.
       
   116      */
       
   117     #define DEBUG_STRING(s) _L(s)
       
   118 
       
   119     /**
       
   120      * Helper macro for defining debug string with filename and linenumber.
       
   121      */
       
   122     #define DEBUG_LINE(s) TPtrC((const TText *) DEBUG_STR(s))
       
   123 
       
   124     #ifdef DEBUG_OUTPUT_TO_FILE
       
   125 
       
   126         /**
       
   127          * Method to handle file writing
       
   128          */
       
   129         inline void DebugWriteFormat(TRefByValue<const TDesC> aFmt,...)
       
   130             {
       
   131             _LIT(KDir, "hti");
       
   132             #ifdef DEBUG_FILENAME
       
   133                 const static TLitC<sizeof(DEBUG_FILENAME)> KName={sizeof(DEBUG_FILENAME)-1, TO_UNICODE( DEBUG_FILENAME ) };
       
   134             #else
       
   135                 _LIT(KName, "DebugOutput.log" );
       
   136             #endif // DEBUG_FILENAME
       
   137 
       
   138             // take the ellipsis parameters
       
   139             VA_LIST args;
       
   140             VA_START(args,aFmt);
       
   141             RFileLogger::WriteFormat( KDir, KName, EFileLoggingModeAppend, aFmt, args );
       
   142             VA_END(args);
       
   143             }
       
   144 
       
   145         /**
       
   146          * Output to log file
       
   147          */
       
   148         #define DEBUG_PRINT DebugWriteFormat
       
   149 
       
   150     #else
       
   151         /**
       
   152          * Output to debugger output
       
   153          */
       
   154         #define DEBUG_PRINT RDebug::Print
       
   155     #endif
       
   156 
       
   157 #else   // ENABLE_DEBUG_PRINT
       
   158 
       
   159     /**
       
   160      * Dummy struct for checking that all DEBUG_PRINT's define string
       
   161      * literals using space-saving DEBUG_STRING.
       
   162      */
       
   163     struct TEmptyDebugString { };
       
   164 
       
   165     /**
       
   166      * Macro for defining debug-only literal strings (empty release version)
       
   167      */
       
   168     #define DEBUG_STRING(s) TEmptyDebugString()
       
   169 
       
   170     /**
       
   171      * Macro for defining debug-only literal strings (empty release version)
       
   172      */
       
   173     #define DEBUG_LINE(s) TEmptyDebugString()
       
   174 
       
   175     /// Empty debug print function for release builds.
       
   176     inline void DEBUG_PRINT(TEmptyDebugString)
       
   177         {
       
   178         }
       
   179 
       
   180     /// Empty debug print function for release builds.
       
   181     template<class T1>
       
   182     inline void DEBUG_PRINT(TEmptyDebugString,T1)
       
   183         {
       
   184         }
       
   185 
       
   186     /// Empty debug print function for release builds.
       
   187     template<class T1,class T2>
       
   188     inline void DEBUG_PRINT(TEmptyDebugString,T1,T2)
       
   189         {
       
   190         }
       
   191 
       
   192     /// Empty debug print function for release builds.
       
   193     template<class T1,class T2,class T3>
       
   194     inline void DEBUG_PRINT(TEmptyDebugString,T1,T2,T3)
       
   195         {
       
   196         }
       
   197 
       
   198     /// Empty debug print function for release builds.
       
   199     template<class T1,class T2,class T3,class T4>
       
   200     inline void DEBUG_PRINT(TEmptyDebugString,T1,T2,T3,T4)
       
   201         {
       
   202         }
       
   203 
       
   204     /// Empty debug print function for release builds.
       
   205     template<class T1,class T2,class T3,class T4,class T5>
       
   206     inline void DEBUG_PRINT(TEmptyDebugString,T1,T2,T3,T4,T5)
       
   207         {
       
   208         }
       
   209 
       
   210     /// Empty debug print function for release builds.
       
   211     template<class T1,class T2,class T3,class T4,class T5,class T6>
       
   212     inline void DEBUG_PRINT(TEmptyDebugString,T1,T2,T3,T4,T5,T6)
       
   213         {
       
   214         }
       
   215 
       
   216     /// Empty debug print function for release builds.
       
   217     template<class T1,class T2,class T3,class T4,class T5,class T6,class T7>
       
   218     inline void DEBUG_PRINT(TEmptyDebugString,T1,T2,T3,T4,T5,T6,T7)
       
   219         {
       
   220         }
       
   221 
       
   222     /// Empty debug print function for release builds.
       
   223     template<class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8>
       
   224     inline void DEBUG_PRINT(TEmptyDebugString,T1,T2,T3,T4,T5,T6,T7,T8)
       
   225         {
       
   226         }
       
   227 
       
   228 #endif  // ENABLE_DEBUG_PRINT
       
   229 
       
   230 #endif //  __DEBUGPRINT_H__