usbengines/usbotgwatcher/inc/debug.h
changeset 34 7858bc6ead78
parent 31 dfdd8240f7c8
child 35 9d8b04ca6939
equal deleted inserted replaced
31:dfdd8240f7c8 34:7858bc6ead78
     1 /*
       
     2 * Copyright (c) 2007 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:  Debug macros and declarations. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef DEBUG_H
       
    20 #define DEBUG_H
       
    21 
       
    22 //////////////////////////////////////////////////////////////////////////////
       
    23 // Here are parameters need to be modified. 
       
    24 // Component name 
       
    25 #define MODULE_NAME "USBOTGWATCHER"
       
    26 //////////////////////////////////////////////////////////////////////////////
       
    27 
       
    28 
       
    29 // For handling unicode strings as L##MACRO is interpreted as LMACRO
       
    30 #define WIDEN2( x ) L##x
       
    31 #define WIDEN( x ) WIDEN2( x )
       
    32 
       
    33 _LIT( KUsbPanicModule, ""WIDEN( MODULE_NAME ) );
       
    34 
       
    35 #ifdef _DEBUG
       
    36 
       
    37 // Comment this line out if using real-time debugging
       
    38 //#define LOG_TO_FILE 
       
    39 // ===========================================================================
       
    40 #if defined ( LOG_TO_FILE )
       
    41 // ===========================================================================
       
    42 // Add corresponding libabry in mmp file
       
    43 // LIBRARY    flogger.lib    
       
    44 // The log file is located at  
       
    45 // c:\logs\usb\MODULE_NAME.txt
       
    46 
       
    47 #include <flogger.h>
       
    48 
       
    49 #define DESC( x ) TPtrC( ( const TText* ) ( x ) )
       
    50 #define DESC8( x ) TPtrC8( ( const TUint8* ) ( x ) )
       
    51 _LIT( KUsbLogDir, "USB" );
       
    52 _LIT( KUsbLogFile, ""WIDEN(MODULE_NAME)L".txt" );
       
    53 
       
    54 // s: c string. 
       
    55 #define LOG(s) RFileLogger::WriteFormat( KUsbLogDir, \
       
    56                 KUsbLogFile, EFileLoggingModeAppend, \
       
    57                 DESC8( "["MODULE_NAME"] "##s ) )
       
    58 
       
    59 // s: c string contains "%x"
       
    60 // v: varaible corresponding to %x
       
    61 #define LOG1(s, v) RFileLogger::WriteFormat( KUsbLogDir, \
       
    62                 KUsbLogFile, EFileLoggingModeAppend, \
       
    63                 DESC8( "["MODULE_NAME"] "##s ), v)
       
    64 // s: c string contains "%x%y"
       
    65 // v1: varaible corresponding to %x
       
    66 // v2: varaible corresponding to %y
       
    67 #define LOG2(s, v1, v2) RFileLogger::WriteFormat( KUsbLogDir, \
       
    68                 KUsbLogFile, EFileLoggingModeAppend, \
       
    69                 DESC8( "["MODULE_NAME"] "##s ), v1, v2)
       
    70 
       
    71 // s: c string contains "%x%y%z"
       
    72 // v1: varaible corresponding to %x
       
    73 // v2: varaible corresponding to %y
       
    74 // v3: varaible corresponding to %z
       
    75 #define LOG3(s, v1, v2, v3) RFileLogger::WriteFormat( KUsbLogDir, \
       
    76             KUsbLogFile, EFileLoggingModeAppend, \
       
    77             DESC8( "["MODULE_NAME"] "##s ), v1, v2, v3 )
       
    78 
       
    79 class TFuncLogger
       
    80     {
       
    81 public:
       
    82     TFuncLogger(const TDesC8& aFuncName)
       
    83         {
       
    84         iFuncName.Set( aFuncName );
       
    85         RFileLogger::WriteFormat( KUsbLogDir, KUsbLogFile, EFileLoggingModeAppend, 
       
    86                 DESC8( "["MODULE_NAME"] >>%s" ), iFuncName.Ptr() );
       
    87         }
       
    88     ~TFuncLogger()
       
    89         {
       
    90         RFileLogger::WriteFormat( KUsbLogDir, KUsbLogFile, 
       
    91                 EFileLoggingModeAppend, 
       
    92                 DESC8( "["MODULE_NAME"] <<%s" ), iFuncName.Ptr() );
       
    93         }
       
    94 private:
       
    95     TPtrC8 iFuncName;
       
    96     };
       
    97 // ===========================================================================
       
    98 #else //LOG_TO_FILE not defined
       
    99 // ===========================================================================
       
   100 #include <e32debug.h>
       
   101 
       
   102 // Paramters same as above.
       
   103 #define LOG( str ) { RDebug::Printf( "["MODULE_NAME"] %s", str  ); }
       
   104 
       
   105 #define LOG1( s, v ) { RDebug::Printf( "["MODULE_NAME"] "##s , v ); }
       
   106 
       
   107 #define LOG2( s, v1,v2 ) { RDebug::Printf( "["MODULE_NAME"] "##s , v1, v2 ); }
       
   108 
       
   109 #define LOG3( s, v1, v2, v3 ) { RDebug::Printf( "["MODULE_NAME"] "##s , \
       
   110         v1, v2, v3); }
       
   111 
       
   112 class TFuncLogger
       
   113     {
       
   114 public:
       
   115     TFuncLogger(const TPtrC8& aFuncName) : iFuncName( aFuncName )
       
   116         {
       
   117         RDebug::Printf( "["MODULE_NAME"] >>%s", iFuncName.Ptr());
       
   118         }
       
   119     ~TFuncLogger()
       
   120         {
       
   121         RDebug::Printf( "["MODULE_NAME"] <<%s", iFuncName.Ptr());
       
   122         }
       
   123 private:
       
   124     TPtrC8 iFuncName;
       
   125     };
       
   126 #endif // LOG_TO_FILE
       
   127 
       
   128 #define LEAVE( exp )  {volatile TInt err_ = exp; \
       
   129         LOG3( "LEAVE(%d) @file: %s, line: %d", err_, __FILE__, __LINE__ );\
       
   130         User::Leave( err_ );}
       
   131 
       
   132 #define LEAVEIFERROR( exp ) {volatile TInt err__ = exp; \
       
   133         if(err__ < 0) LEAVE(err__);}
       
   134 
       
   135 #define PANIC( exp ) {volatile TInt err_ = exp; \
       
   136         LOG3( "PANIC(%d) @file: %s, line: %d", err_, __FILE__, __LINE__ );\
       
   137         User::Panic( KUsbPanicModule, err_ );} 
       
   138 
       
   139 #define LOG_FUNC TFuncLogger __instrument(TPtrC8((TUint8*)__PRETTY_FUNCTION__));
       
   140 
       
   141 #define ASSERT_PANIC( exp, code ) {if(!(exp)) PANIC(code)}
       
   142 
       
   143 #else // _DEBUG not defined 
       
   144 // ===========================================================================
       
   145 
       
   146 #define LOG( s )
       
   147 #define LOG1( s, v ) 
       
   148 #define LOG2( s, v1, v2 )
       
   149 #define LOG3( s, v1, v2, v3 )
       
   150 #define LOG_FUNC_ENTRY 
       
   151 #define LOG_FUNC_EXIT 
       
   152 #define LEAVE( exp ) User::Leave( exp );
       
   153 #define LEAVEIFERROR( exp ) User::LeaveIfError( exp );
       
   154 #define PANIC( err ) // in non-debug builds PANICs are silent
       
   155 #define LOG_FUNC
       
   156 #define ASSERT_PANIC( exp, code )
       
   157 // ===========================================================================
       
   158 #endif // _DEBUG
       
   159 // ===========================================================================
       
   160 #endif // DEBUG_H
       
   161 
       
   162 // End of File