|         |      1 /* | 
|         |      2 * Copyright (c) 2006-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:  Common debug definitions | 
|         |     15 * | 
|         |     16 */ | 
|         |     17  | 
|         |     18  | 
|         |     19 #ifndef FILEMANAGERDEBUG_H | 
|         |     20 #define FILEMANAGERDEBUG_H | 
|         |     21  | 
|         |     22  | 
|         |     23 //  INCLUDES | 
|         |     24 #include <e32base.h> | 
|         |     25 #include <e32debug.h> | 
|         |     26  | 
|         |     27  | 
|         |     28 //#define FILE_MANAGER_INFO_LOG_ENABLED | 
|         |     29  | 
|         |     30 #ifdef _DEBUG | 
|         |     31  #define FILE_MANAGER_ERROR_LOG_ENABLED | 
|         |     32 #endif // _DEBUG | 
|         |     33  | 
|         |     34  | 
|         |     35 // Info logging | 
|         |     36 #ifdef FILE_MANAGER_INFO_LOG_ENABLED | 
|         |     37  | 
|         |     38  #define INFO_LOG( aMsg ) { _LIT( KMsg, aMsg ); RDebug::Print( KMsg ); } | 
|         |     39  | 
|         |     40  #define INFO_LOG1( aMsg, aArg1 )\ | 
|         |     41     { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1 ); } | 
|         |     42  | 
|         |     43  #define INFO_LOG2( aMsg, aArg1, aArg2 )\ | 
|         |     44     { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2 ); } | 
|         |     45  | 
|         |     46  #define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 )\ | 
|         |     47     { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2, aArg3 ); } | 
|         |     48  | 
|         |     49 // Function log object | 
|         |     50 _LIT8( KFuncNameTerminator, "(" ); | 
|         |     51 _LIT8( KFuncLeavePattern, "L" ); | 
|         |     52  | 
|         |     53 class TFuncLog | 
|         |     54     { | 
|         |     55 public: | 
|         |     56     static void Cleanup( TAny* aPtr ) | 
|         |     57         { | 
|         |     58         TFuncLog* self = static_cast< TFuncLog* >( aPtr ); | 
|         |     59         self->iLeft = ETrue; | 
|         |     60         RDebug::Printf( "%S-LEAVE", &self->iFunc ); // Leave detected | 
|         |     61         } | 
|         |     62  | 
|         |     63     inline TFuncLog( const char* aFunc ) : | 
|         |     64             iFunc( aFunc ? _S8( aFunc ) : _S8("") ), | 
|         |     65             iLeft( EFalse ), | 
|         |     66             iCanLeave( EFalse ) | 
|         |     67         { | 
|         |     68         TInt pos( iFunc.Find( KFuncNameTerminator ) ); | 
|         |     69         if( pos != KErrNotFound ) | 
|         |     70             { | 
|         |     71             iFunc.Set( iFunc.Left( pos ) ); | 
|         |     72             TInt patLen( KFuncLeavePattern().Length() ); | 
|         |     73             iCanLeave = iFunc.Length() > patLen && | 
|         |     74                 !iFunc.Right( patLen ).Compare( KFuncLeavePattern ); | 
|         |     75             } | 
|         |     76         RDebug::Printf( "%S-START", &iFunc ); | 
|         |     77         } | 
|         |     78  | 
|         |     79     inline ~TFuncLog() | 
|         |     80         { | 
|         |     81         if ( !iLeft ) | 
|         |     82             { | 
|         |     83             if ( iCanLeave ) | 
|         |     84                 { | 
|         |     85                 CleanupStack::Pop( this ); // Pop the cleanup item | 
|         |     86                 } | 
|         |     87             RDebug::Printf( "%S-END", &iFunc ); // Normally finished | 
|         |     88             } | 
|         |     89         } | 
|         |     90  | 
|         |     91     TPtrC8 iFunc; | 
|         |     92     TBool iLeft; | 
|         |     93     TBool iCanLeave; | 
|         |     94     }; | 
|         |     95  | 
|         |     96  #define FUNC_LOG\ | 
|         |     97   TFuncLog _fl( __PRETTY_FUNCTION__ );\ | 
|         |     98   TCleanupItem _flCi( TFuncLog::Cleanup, &_fl );\ | 
|         |     99   if ( _fl.iCanLeave ) { CleanupStack::PushL( _flCi ); } | 
|         |    100  | 
|         |    101  #define TIMESTAMP( aCaption )\ | 
|         |    102     {\ | 
|         |    103     TTime t;\ | 
|         |    104     t.HomeTime();\ | 
|         |    105     RDebug::Printf( "%s %d us", aCaption, I64INT( t.Int64() ) );\ | 
|         |    106     } | 
|         |    107  | 
|         |    108 #else // FILE_MANAGER_INFO_LOG_ENABLED | 
|         |    109  | 
|         |    110  #define INFO_LOG( aMsg ) | 
|         |    111  | 
|         |    112  #define INFO_LOG1( aMsg, aArg1 ) | 
|         |    113  | 
|         |    114  #define INFO_LOG2( aMsg, aArg1, aArg2 ) | 
|         |    115  | 
|         |    116  #define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 ) | 
|         |    117  | 
|         |    118  #define FUNC_LOG | 
|         |    119  | 
|         |    120  #define TIMESTAMP( aCaption ) | 
|         |    121  | 
|         |    122 #endif // FILE_MANAGER_INFO_LOG_ENABLED | 
|         |    123  | 
|         |    124  | 
|         |    125 // Error logging | 
|         |    126 #ifdef FILE_MANAGER_ERROR_LOG_ENABLED | 
|         |    127  | 
|         |    128  #define ERROR_LOG( aMsg ) { _LIT( KMsg, aMsg ); RDebug::Print( KMsg ); } | 
|         |    129  | 
|         |    130  #define ERROR_LOG1( aMsg, aArg1 )\ | 
|         |    131     { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1 ); } | 
|         |    132  | 
|         |    133  #define ERROR_LOG2( aMsg, aArg1, aArg2 )\ | 
|         |    134     { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2 ); } | 
|         |    135  | 
|         |    136  #define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 )\ | 
|         |    137     { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2, aArg3 ); } | 
|         |    138  | 
|         |    139  #define LOG_IF_ERROR( aErr, aMsg )\ | 
|         |    140     if ( ( aErr ) != KErrNone )\ | 
|         |    141         { _LIT( KMsg, aMsg ); RDebug::Print( KMsg ); } | 
|         |    142  | 
|         |    143  #define LOG_IF_ERROR1( aErr, aMsg, aArg1 )\ | 
|         |    144     if ( ( aErr ) != KErrNone )\ | 
|         |    145         { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1 ); } | 
|         |    146          | 
|         |    147  #define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 )\ | 
|         |    148     if ( ( aErr ) != KErrNone )\ | 
|         |    149         { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2 ); } | 
|         |    150  | 
|         |    151  #define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 )\ | 
|         |    152     if ( ( aErr ) != KErrNone )\ | 
|         |    153         { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2, aArg3 ); } | 
|         |    154  | 
|         |    155 #else // FILE_MANAGER_ERROR_LOG_ENABLED | 
|         |    156  | 
|         |    157  #define ERROR_LOG( aMsg ) | 
|         |    158  | 
|         |    159  #define ERROR_LOG1( aMsg, aArg1 ) | 
|         |    160  | 
|         |    161  #define ERROR_LOG2( aMsg, aArg1, aArg2 ) | 
|         |    162  | 
|         |    163  #define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 ) | 
|         |    164  | 
|         |    165  // Remove compiler warning | 
|         |    166  #define LOG_IF_ERROR( aErr, aMsg ) ( aErr ) = ( aErr ); | 
|         |    167  | 
|         |    168  #define LOG_IF_ERROR1( aErr, aMsg, aArg1 )  ( aErr ) = ( aErr ); | 
|         |    169  | 
|         |    170  #define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 )  ( aErr ) = ( aErr ); | 
|         |    171  | 
|         |    172  #define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 ) ( aErr ) = ( aErr ); | 
|         |    173  | 
|         |    174 #endif // FILE_MANAGER_ERROR_LOG_ENABLED | 
|         |    175  | 
|         |    176  | 
|         |    177 #endif // FILEMANAGERDEBUG_H | 
|         |    178  | 
|         |    179 // End of File |