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