os/persistentdata/featuremgmt/featuremgr/src/inc/featmgrdebug.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 FEATMGRDEBUG_H
    21 #define FEATMGRDEBUG_H
    22 
    23 
    24 //  INCLUDES
    25 #include <e32debug.h>
    26 
    27 // Enable macros to support error and/or info logging
    28 #ifdef _DEBUG
    29     //#define FEATMGR_INFO_LOG_ENABLED
    30     //#define FEATMGR_ERROR_LOG_ENABLED
    31     #define FEATMGR_TIMESTAMP_ENABLED
    32 #endif // _DEBUG
    33 
    34 
    35 /**
    36 * Prefix trace macro to complete tracing with component name.
    37 * Returns TDesC which can be used directly with RDebug or RFileLogger.
    38 */
    39  #define PREFIX( aMsg ) TPtrC( (const TText*)L"[EFM]: " L##aMsg )
    40 
    41 /**
    42 * Prefix error trace
    43 */
    44  #define ERROR_PREFIX( aMsg ) PREFIX( "[ERROR]: " L##aMsg )
    45 
    46 /**
    47 * Prefix macro for strings
    48 */
    49 #define _PREFIX_CHAR( aMsg ) (const char*)"[EFM]: " ##aMsg
    50 
    51 // Info logging
    52 #ifdef FEATMGR_INFO_LOG_ENABLED
    53 
    54  #define INFO_LOG( aMsg ) { RDebug::Print( PREFIX( aMsg ) ); }
    55 
    56  #define INFO_LOG1( aMsg, aArg1 )\
    57     { RDebug::Print( PREFIX( aMsg ), aArg1 ); }
    58 
    59  #define INFO_LOG2( aMsg, aArg1, aArg2 )\
    60     { RDebug::Print( PREFIX( aMsg ), aArg1, aArg2 ); }
    61 
    62  #define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 )\
    63     { RDebug::Print( PREFIX( aMsg ), aArg1, aArg2, aArg3 ); }
    64 
    65  #define FUNC( aMsg, aP1 )\
    66     {\
    67     RDebug::Printf( aMsg, aP1 );\
    68     }\
    69 // Function log object
    70 _LIT8( KFuncNameTerminator, "(" );
    71 _LIT8( KFuncLeavePattern, "L" );
    72 
    73 class TFuncLog
    74     {
    75     public:
    76     
    77     static void Cleanup( TAny* aPtr )
    78         {
    79         TFuncLog* self = static_cast< TFuncLog* >( aPtr );
    80         self->iLeft = ETrue;
    81         FUNC( _PREFIX_CHAR("%S-LEAVE"), &self->iFunc ); // Leave detected
    82         }
    83 
    84     inline TFuncLog( const char* aFunc ) :
    85             iFunc( aFunc ? _S8( aFunc ) : _S8("") ),
    86             iLeft( EFalse ),
    87             iCleanupItem( Cleanup, this ),
    88             iCanLeave( EFalse )
    89         {
    90         TInt pos( iFunc.Find( KFuncNameTerminator ) );
    91         if( pos != KErrNotFound )
    92             {
    93             iFunc.Set( iFunc.Left( pos ) );
    94             iCanLeave = !iFunc.Right( KFuncLeavePattern().Length() ).Compare( KFuncLeavePattern );
    95             if ( iCanLeave )
    96                 {
    97                 CleanupStack::PushL( iCleanupItem ); // Ignore warnings
    98                 }
    99             }
   100         FUNC( _PREFIX_CHAR("%S-START"), &iFunc );
   101         }
   102 
   103     inline ~TFuncLog()
   104         {
   105         if ( !iLeft )
   106             {
   107             if ( iCanLeave )
   108                 {
   109                 CleanupStack::Pop( this ); // Pop the cleanup item
   110                 }
   111             FUNC( _PREFIX_CHAR("%S-END"), &iFunc ); // Normally finished
   112             }
   113         }
   114 
   115     private: // Data
   116     
   117     TPtrC8 iFunc;
   118     TBool iLeft;
   119     TCleanupItem iCleanupItem;
   120     TBool iCanLeave;
   121     };
   122 
   123  #define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__ );
   124 
   125 #else // FEATMGR_INFO_LOG_ENABLED
   126 
   127  #define INFO_LOG( aMsg )
   128 
   129  #define INFO_LOG1( aMsg, aArg1 )
   130 
   131  #define INFO_LOG2( aMsg, aArg1, aArg2 )
   132 
   133  #define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 )
   134 
   135  #define FUNC_LOG
   136 
   137 #endif // FEATMGR_INFO_LOG_ENABLED
   138 
   139 // Timestamp logging
   140 #ifdef FEATMGR_TIMESTAMP_ENABLED
   141 
   142  #define TIMESTAMP( aCaption )\
   143     {\
   144     TTime t;\
   145     t.HomeTime();\
   146     TDateTime dt = t.DateTime();\
   147     _LIT( KCaption, aCaption );\
   148     RDebug::Print( PREFIX("[TIMESTAMP] %S %d:%02d:%02d.%d us"),\
   149         &KCaption, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\
   150     }
   151 
   152 #else
   153 
   154  #define TIMESTAMP( aCaption )
   155 
   156 #endif // FEATMGR_TIMESTAMP_ENABLED
   157 
   158 // Error logging
   159 #ifdef FEATMGR_ERROR_LOG_ENABLED
   160 
   161  #define ERROR_LOG( aMsg )\
   162     {RDebug::Print( ERROR_PREFIX( aMsg ) ); }
   163 
   164  #define ERROR_LOG1( aMsg, aArg1 )\
   165     {RDebug::Print( ERROR_PREFIX( aMsg ), aArg1 ); }
   166 
   167  #define ERROR_LOG2( aMsg, aArg1, aArg2 )\
   168     { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2 ); }
   169 
   170  #define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 )\
   171     { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2, aArg3 ); }
   172 
   173  #define LOG_IF_ERROR( aErr, aMsg )\
   174     if ( ( aErr ) != KErrNone )\
   175         { RDebug::Print( ERROR_PREFIX( aMsg )); }
   176 
   177  #define LOG_IF_ERROR1( aErr, aMsg, aArg1 )\
   178     if ( ( aErr ) != KErrNone )\
   179         { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1 ); }
   180         
   181  #define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 )\
   182     if ( ( aErr ) != KErrNone )\
   183         { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2 ); }
   184 
   185  #define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 )\
   186     if ( ( aErr ) != KErrNone )\
   187         { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2, aArg3 ); }
   188 
   189 #else // FEATMGR_ERROR_LOG_ENABLED
   190 
   191  #define ERROR_LOG( aMsg )
   192 
   193  #define ERROR_LOG1( aMsg, aArg1 )
   194 
   195  #define ERROR_LOG2( aMsg, aArg1, aArg2 )
   196 
   197  #define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 )
   198 
   199  // Remove compiler warning
   200  #define LOG_IF_ERROR( aErr, aMsg ) ( aErr ) = ( aErr );
   201 
   202  #define LOG_IF_ERROR1( aErr, aMsg, aArg1 )  ( aErr ) = ( aErr );
   203 
   204  #define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 )  ( aErr ) = ( aErr );
   205 
   206  #define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 ) ( aErr ) = ( aErr );
   207 
   208 #endif // FEATMGR_ERROR_LOG_ENABLED
   209 
   210 
   211 #endif // FEATMGRDEBUG_H
   212 
   213 // End of File