usbengines/usbotgwatcher/inc/debug.h
branchRCL_3
changeset 20 a15c582fbf97
parent 0 1e05558e2206
child 21 ff9df6630274
child 26 0ae0f29418cd
equal deleted inserted replaced
13:7068aba64af5 20:a15c582fbf97
     1 /*
     1 /*
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This material, including documentation and any related computer
     5 * under the terms of "Eclipse Public License v1.0"
     5 * programs, is protected by copyright controlled by Nokia. All
     6 * which accompanies this distribution, and is available
     6 * rights are reserved. Copying, including reproducing, storing
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * adapting or translating, any or all of this material requires the
       
     8 * prior written consent of Nokia. This material also contains
       
     9 * confidential information which may not be disclosed to others
       
    10 * without the prior written consent of Nokia.
     8 *
    11 *
     9 * Initial Contributors:
    12 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    13 * Nokia Corporation - initial contribution.
    11 *
    14 *
    12 * Contributors:
    15 * Contributors:
    13 *
    16 *
    14 * Description:  Central place for debug-type macros & functions
    17 * Description: Debug macros and declarations. 
    15 *
    18 *
    16 */
    19 */
    17 
    20 
       
    21 #ifndef DEBUG_H
       
    22 #define DEBUG_H
    18 
    23 
    19 #ifndef _USBWATCHER_DEBUG_H
    24 //////////////////////////////////////////////////////////////////////////////
    20 #define _USBWATCHER_DEBUG_H
    25 // Here are parameters need to be modified. 
       
    26 // Component name 
       
    27 #define MODULE_NAME "USBOTGWATCHER"
       
    28 //////////////////////////////////////////////////////////////////////////////
       
    29 
       
    30 
       
    31 // For handling unicode strings as L##MACRO is interpreted as LMACRO
       
    32 #define WIDEN2( x ) L##x
       
    33 #define WIDEN( x ) WIDEN2( x )
       
    34 
       
    35 _LIT( KUsbPanicModule, ""WIDEN( MODULE_NAME ) );
    21 
    36 
    22 #ifdef _DEBUG
    37 #ifdef _DEBUG
    23 
    38 
    24 // Enable this to enable memory tracing
    39 // Comment this line out if using real-time debugging
    25 //#define MEMTRACE
    40 //#define LOG_TO_FILE 
       
    41 // ===========================================================================
       
    42 #if defined ( LOG_TO_FILE )
       
    43 // ===========================================================================
       
    44 // Add corresponding libabry in mmp file
       
    45 // LIBRARY    flogger.lib    
       
    46 // The log file is located at  
       
    47 // c:\logs\usb\MODULE_NAME.txt
    26 
    48 
    27 // Following define is to enable OOM
       
    28 // situations in SRCS
       
    29 // SHOULD NEVER BE IN RELEASES.
       
    30 //#define TEST_OOM
       
    31 
       
    32 #ifdef __WINS__
       
    33 
       
    34 // File logging for WINS
       
    35 #define __FLOGGING__
       
    36 
       
    37 #else
       
    38 
       
    39 // Logging with RDebug for target HW
       
    40 #define __CLOGGING__
       
    41 
       
    42 #endif //__WINS__
       
    43 
       
    44 #endif // Debug
       
    45 
       
    46 #if defined ( __FLOGGING__ )
       
    47 
       
    48 _LIT( KLogFile,"UsbWatcher.txt" );
       
    49 _LIT( KLogDir,"usb" );
       
    50 
       
    51 #include <f32file.h>
       
    52 #include <flogger.h>
    49 #include <flogger.h>
    53 
    50 
    54 #define FLOG( a ) { FPrint( a ); }
    51 #define DESC( x ) TPtrC( ( const TText* ) ( x ) )
       
    52 #define DESC8( x ) TPtrC8( ( const TUint8* ) ( x ) )
       
    53 _LIT( KUsbLogDir, "USB" );
       
    54 _LIT( KUsbLogFile, ""WIDEN(MODULE_NAME)L".txt" );
    55 
    55 
    56 #define FLOGHEX( value, len ) { RFileLogger::HexDump( KLogDir, KLogFile, EFileLoggingModeAppend, "", " ",value, len ); }
    56 // s: c string. 
       
    57 #define LOG(s) RFileLogger::WriteFormat( KUsbLogDir, \
       
    58                 KUsbLogFile, EFileLoggingModeAppend, \
       
    59                 DESC8( "["MODULE_NAME"] "##s ) )
    57 
    60 
    58 #define FTRACE( a ) { a; }
    61 // s: c string contains "%x"
       
    62 // v: varaible corresponding to %x
       
    63 #define LOG1(s, v) RFileLogger::WriteFormat( KUsbLogDir, \
       
    64                 KUsbLogFile, EFileLoggingModeAppend, \
       
    65                 DESC8( "["MODULE_NAME"] "##s ), v)
       
    66 // s: c string contains "%x%y"
       
    67 // v1: varaible corresponding to %x
       
    68 // v2: varaible corresponding to %y
       
    69 #define LOG2(s, v1, v2) RFileLogger::WriteFormat( KUsbLogDir, \
       
    70                 KUsbLogFile, EFileLoggingModeAppend, \
       
    71                 DESC8( "["MODULE_NAME"] "##s ), v1, v2)
    59 
    72 
    60 inline void FPrint( const TRefByValue<const TDesC> aFmt, ... )
    73 // s: c string contains "%x%y%z"
    61 {
    74 // v1: varaible corresponding to %x
    62     VA_LIST list;
    75 // v2: varaible corresponding to %y
    63     VA_START( list, aFmt );
    76 // v3: varaible corresponding to %z
    64     RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list );
    77 #define LOG3(s, v1, v2, v3) RFileLogger::WriteFormat( KUsbLogDir, \
       
    78             KUsbLogFile, EFileLoggingModeAppend, \
       
    79             DESC8( "["MODULE_NAME"] "##s ), v1, v2, v3 )
    65 
    80 
    66     // If memory tracing is activated.
    81 class TFuncLogger
    67 #ifdef MEMTRACE
    82     {
    68     TInt size;
    83 public:
    69     User::Heap().AllocSize( size );
    84     TFuncLogger(const TDesC8& aFuncName)
    70     RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, _L( "[USBWATCHER]\tmemory\tMemory usage: %d high: %d" ), size, User::Heap().Size() );
    85         {
    71 #endif
    86         iFuncName.Set( aFuncName );
    72 }
    87         RFileLogger::WriteFormat( KUsbLogDir, KUsbLogFile, EFileLoggingModeAppend, 
       
    88                 DESC8( "["MODULE_NAME"] >>%s" ), iFuncName.Ptr() );
       
    89         }
       
    90     ~TFuncLogger()
       
    91         {
       
    92         RFileLogger::WriteFormat( KUsbLogDir, KUsbLogFile, 
       
    93                 EFileLoggingModeAppend, 
       
    94                 DESC8( "["MODULE_NAME"] <<%s" ), iFuncName.Ptr() );
       
    95         }
       
    96 private:
       
    97     TPtrC8 iFuncName;
       
    98     };
       
    99 // ===========================================================================
       
   100 #else //Real-time logging
       
   101 // ===========================================================================
       
   102 #include <e32debug.h>
    73 
   103 
    74 inline void FHex( const TUint8* aPtr, TInt aLen )
   104 // Paramters same as above.
    75 {
   105 #define LOG( str ) { RDebug::Printf( "["MODULE_NAME"] %s", str  ); }
    76     RFileLogger::HexDump( KLogDir, KLogFile, EFileLoggingModeAppend, 0, 0, aPtr, aLen );
       
    77 }
       
    78 
   106 
    79 inline void FHex( const TDesC8& aDes )
   107 #define LOG1( s, v ) { RDebug::Printf( "["MODULE_NAME"] "##s , v ); }
    80 {
       
    81     FHex( aDes.Ptr(), aDes.Length() );
       
    82 }
       
    83 
   108 
    84 // RDebug logging
   109 #define LOG2( s, v1,v2 ) { RDebug::Printf( "["MODULE_NAME"] "##s , v1, v2 ); }
    85 #elif defined(__CLOGGING__)
       
    86 
   110 
    87 #include <e32svr.h>
   111 #define LOG3( s, v1, v2, v3 ) { RDebug::Printf( "["MODULE_NAME"] "##s , \
       
   112         v1, v2, v3); }
    88 
   113 
    89 #define FLOG( a ) { RDebug::Print( a ); }
   114 class TFuncLogger
       
   115     {
       
   116 public:
       
   117     TFuncLogger(const TPtrC8& aFuncName) : iFuncName( aFuncName )
       
   118         {
       
   119         RDebug::Printf( "["MODULE_NAME"] >>%s", iFuncName.Ptr());
       
   120         }
       
   121     ~TFuncLogger()
       
   122         {
       
   123         RDebug::Printf( "["MODULE_NAME"] <<%s", iFuncName.Ptr());
       
   124         }
       
   125 private:
       
   126     TPtrC8 iFuncName;
       
   127     };
       
   128 #endif // LOG_TO_FILE
    90 
   129 
    91 #define FLOGHEX( a )
   130 #define LEAVE( exp )  {volatile TInt err = exp; \
       
   131             LOG3( "LEAVE(%d) @file: %s, line: %d", err, __FILE__, __LINE__ );\
       
   132             User::Leave( err );}
    92 
   133 
    93 #define FTRACE( a ) { a; }
   134 #define LEAVEIFERROR( exp ) {volatile TInt err = exp; if(err < 0) LEAVE(err);}
    94 
   135 
    95 // Declare the FPrint function
   136 #define PANIC( exp ) {volatile TInt err = exp; \
    96 
   137             LOG3( "PANIC(%d) @file: %s, line: %d", err, __FILE__, __LINE__ );\
    97 inline void FPrint( const TRefByValue<const TDesC> aFmt, ... )
   138             User::Panic( KUsbPanicModule, err );}
    98 {
       
    99     VA_LIST list;
       
   100     VA_START( list,aFmt );
       
   101     TInt tmpInt = VA_ARG( list, TInt );
       
   102     TInt tmpInt2 = VA_ARG( list, TInt );
       
   103     TInt tmpInt3 = VA_ARG( list, TInt );
       
   104     VA_END( list );
       
   105     RDebug::Print( aFmt, tmpInt, tmpInt2, tmpInt3 );
       
   106 }
       
   107 
   139 
   108 
   140 
   109 #else   // No loggings --> reduced code size
   141 #define LOG_FUNC TFuncLogger __instrument(TPtrC8((TUint8*)__PRETTY_FUNCTION__));
   110 
   142 
   111 #define FLOG( a )
   143 #else // _DEBUG   
   112 #define FLOGHEX( a )
   144 // ===========================================================================
   113 #define FTRACE( a )
       
   114 
   145 
   115 #endif //_DEBUG
   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 ) User::Panic( KUsbPanicModule, err );
       
   155 #define LOG_FUNC
       
   156 // ===========================================================================
       
   157 #endif // _DEBUG
       
   158 // ===========================================================================
       
   159 #endif // DEBUG_H
   116 
   160 
   117 #endif // USBDEVCON_DEBUG_H
   161 // End of File
   118