coreapplicationuis/powersaveutilities/batindicatorpaneplugin/inc/trace.h
branchRCL_3
changeset 19 924385140d98
parent 18 0818dd463d41
child 20 c2c61fdca848
equal deleted inserted replaced
18:0818dd463d41 19:924385140d98
     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:  Battery Indicator Pane Plug-in trace definitions.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef TRACE_H
       
    20 #define TRACE_H
       
    21 
       
    22 #include "traceconfiguration.hrh"
       
    23 
       
    24 #ifdef TRACE_INTO_FILE
       
    25 #include <flogger.h> // RFileLogger
       
    26 #else
       
    27 #include <e32debug.h> // RDebug
       
    28 #endif
       
    29 
       
    30 //-----------------------------------------------------------------------------
       
    31 // Constants
       
    32 //-----------------------------------------------------------------------------
       
    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_TRACE( aMsg ) TPtrC( (const TText*)L"[BatIndicatorPanePlugin]: " L##aMsg )
       
    40 
       
    41 /**
       
    42 * Prefix error trace
       
    43 */
       
    44 #define _PREFIX_ERROR( aMsg ) _PREFIX_TRACE( "[ERROR: %d]: " L##aMsg )
       
    45 
       
    46 /**
       
    47 * Prefix info trace.
       
    48 */
       
    49 #define _PREFIX_INFO( aMsg ) _PREFIX_TRACE( "[INFO]: " L##aMsg )
       
    50 
       
    51 /**
       
    52 * Prefix macro for strings
       
    53 */
       
    54 #define _PREFIX_CHAR( aMsg ) (const char*)"[BatIndicatorPanePlugin]: " ##aMsg
       
    55 
       
    56 /**
       
    57 * Define needed directories if TRACE_INTO_FILE macro in use
       
    58 */
       
    59 #ifdef TRACE_INTO_FILE
       
    60 
       
    61     _LIT( KDir, "BatIndicatorPanePlugin" );
       
    62     _LIT( KFile, "BatIndicatorPanePlugin_log.txt" );
       
    63     _LIT( KFullPath, "c:\\logs\\BatIndicatorPanePlugin\\" );
       
    64 
       
    65 #endif
       
    66 
       
    67 //-----------------------------------------------------------------------------
       
    68 // Error trace macros
       
    69 //-----------------------------------------------------------------------------
       
    70 //
       
    71 #ifdef ERROR_TRACE
       
    72 
       
    73     /**
       
    74     * Error trace definitions.
       
    75     */
       
    76     #ifdef TRACE_INTO_FILE
       
    77 
       
    78         #define ERROR( aErr, aMsg )\
       
    79             {\
       
    80             if( aErr < KErrNone )\
       
    81                 {\
       
    82                 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_ERROR( aMsg ), aErr );\
       
    83                 }\
       
    84             }
       
    85         #define ERROR_1( aErr, aMsg, aP1 )\
       
    86             {\
       
    87             if( aErr < KErrNone )\
       
    88                 {\
       
    89                 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_ERROR( aMsg ), aErr, aP1 );\
       
    90                 }\
       
    91             }
       
    92         #define ERROR_2( aErr, aMsg, aP1, aP2 )\
       
    93             {\
       
    94             if( aErr < KErrNone )\
       
    95                 {\
       
    96                 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_ERROR( aMsg ), aErr, aP1, aP2 );\
       
    97                 }\
       
    98             }
       
    99         #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\
       
   100             {\
       
   101             if( aErr < KErrNone )\
       
   102                 {\
       
   103                 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_ERROR( aMsg ), aErr, aP1, aP2, aP3 );\
       
   104                 }\
       
   105             }
       
   106             
       
   107     #else//TRACE_INTO_FILE not defined
       
   108     
       
   109         #define ERROR( aErr, aMsg )\
       
   110             {\
       
   111             if( aErr < KErrNone )\
       
   112                 {\
       
   113                 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr );\
       
   114                 }\
       
   115             }
       
   116         #define ERROR_1( aErr, aMsg, aP1 )\
       
   117             {\
       
   118             if( aErr < KErrNone )\
       
   119                 {\
       
   120                 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1 );\
       
   121                 }\
       
   122             }
       
   123         #define ERROR_2( aErr, aMsg, aP1, aP2 )\
       
   124             {\
       
   125             if( aErr < KErrNone )\
       
   126                 {\
       
   127                 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1, aP2 );\
       
   128                 }\
       
   129             }
       
   130         #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\
       
   131             {\
       
   132             if( aErr < KErrNone )\
       
   133                 {\
       
   134                 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1, aP2, aP3 );\
       
   135                 }\
       
   136             }
       
   137     
       
   138     #endif//TRACE_INTO_FILE
       
   139 
       
   140     #define ERROR_GEN( aMsg ) ERROR( KErrGeneral, aMsg )
       
   141     #define ERROR_GEN_1( aMsg, aP1 ) ERROR_1( KErrGeneral, aMsg, aP1 )
       
   142     #define ERROR_GEN_2( aMsg, aP1, aP2 ) ERROR_2( KErrGeneral, aMsg, aP1, aP2 )
       
   143     #define ERROR_GEN_3( aMsg, aP1, aP2, aP3 ) ERROR_3( KErrGeneral, aMsg, aP1, aP3 )
       
   144 
       
   145 #else//ERROR_TRACE not defined
       
   146 
       
   147     #define ERROR( aErr, aMsg )
       
   148     #define ERROR_1( aErr, aMsg, aP1 )
       
   149     #define ERROR_2( aErr, aMsg, aP1, aP2 )
       
   150     #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )
       
   151     #define ERROR_GEN( aMsg )
       
   152     #define ERROR_GEN_1( aMsg, aP1 )
       
   153     #define ERROR_GEN_2( aMsg, aP1, aP2 )
       
   154     #define ERROR_GEN_3( aMsg, aP1, aP2, aP3 )
       
   155 
       
   156 #endif//ERROR_TRACE
       
   157 
       
   158 //-----------------------------------------------------------------------------
       
   159 // Info trace macros
       
   160 //-----------------------------------------------------------------------------
       
   161 //
       
   162 #ifdef INFO_TRACE
       
   163 
       
   164     /**
       
   165     * Info log message definitions.
       
   166     */
       
   167     #ifdef TRACE_INTO_FILE
       
   168     
       
   169         #define INFO( aMsg )\
       
   170             {\
       
   171             RFileLogger::Write( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ) );\
       
   172             }
       
   173         #define INFO_1( aMsg, aP1 )\
       
   174             {\
       
   175             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ), aP1 );\
       
   176             }
       
   177         #define INFO_2( aMsg, aP1, aP2 )\
       
   178             {\
       
   179             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ), aP1, aP2 );\
       
   180             }
       
   181         #define INFO_3( aMsg, aP1, aP2, aP3 )\
       
   182             {\
       
   183             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\
       
   184             }
       
   185 
       
   186     #else//TRACE_INTO_FILE not defined
       
   187 
       
   188         #define INFO( aMsg )\
       
   189             {\
       
   190             RDebug::Print( _PREFIX_INFO( aMsg ) );\
       
   191             }
       
   192         #define INFO_1( aMsg, aP1 )\
       
   193             {\
       
   194             RDebug::Print( _PREFIX_INFO( aMsg ), aP1 );\
       
   195             }
       
   196         #define INFO_2( aMsg, aP1, aP2 )\
       
   197             {\
       
   198             RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2 );\
       
   199             }
       
   200         #define INFO_3( aMsg, aP1, aP2, aP3 )\
       
   201             {\
       
   202             RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\
       
   203             }
       
   204 
       
   205     #endif//TRACE_INTO_FILE
       
   206         
       
   207 #else//INFO_TRACE not defined
       
   208 
       
   209     #define INFO( aMsg )
       
   210     #define INFO_1( aMsg, aP1 )
       
   211     #define INFO_2( aMsg, aP1, aP2 )
       
   212     #define INFO_3( aMsg, aP1, aP2, aP3 )
       
   213 
       
   214 #endif//INFO_TRACE
       
   215 
       
   216 //-----------------------------------------------------------------------------
       
   217 // Trace current client thread name and process id
       
   218 //-----------------------------------------------------------------------------
       
   219 //
       
   220 #ifdef CLIENT_TRACE
       
   221 
       
   222     #define CLIENT( aMessage )\
       
   223         {\
       
   224         RThread thread;\
       
   225         TInt err = aMessage.Client( thread );\
       
   226         if( err == KErrNone )\
       
   227             {\
       
   228             RProcess process;\
       
   229             err = thread.Process( process );\
       
   230             if( err == KErrNone )\
       
   231                 {\
       
   232                 TPtrC thredName( thread.Name() );\
       
   233                 TUid processUid( process.SecureId() );\
       
   234                 INFO_2( "Current client process UID: [%x], thread name: [%S]",\
       
   235                     processUid,\
       
   236                     &thredName );\
       
   237                 }\
       
   238             process.Close();\
       
   239             }\
       
   240         thread.Close();\
       
   241         }
       
   242 
       
   243 #else
       
   244 
       
   245     #define CLIENT( aMessage )
       
   246 
       
   247 #endif
       
   248 
       
   249 //-----------------------------------------------------------------------------
       
   250 // Function trace macros
       
   251 //-----------------------------------------------------------------------------
       
   252 //
       
   253 #ifdef FUNC_TRACE
       
   254 
       
   255     /**
       
   256     * Function logging definitions.
       
   257     */
       
   258     #ifdef TRACE_INTO_FILE
       
   259     
       
   260         #define FUNC( aMsg, aP1 )\
       
   261             {\
       
   262             TPtrC8 trace( _S8( aMsg ) );\
       
   263             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, trace, aP1 );\
       
   264             }\
       
   265     
       
   266     #else//TRACE_INTO_FILE not defined
       
   267     
       
   268         #define FUNC( aMsg, aP1 )\
       
   269             {\
       
   270             RDebug::Printf( aMsg, aP1 );\
       
   271             }\
       
   272     
       
   273     #endif//TRACE_INTO_FILE
       
   274         
       
   275     /**
       
   276     * Function trace helper class.
       
   277     * 
       
   278     * NOTE:
       
   279     * LC -methods cannot be trapped. Therefore if LC -method leaves
       
   280     * END trace is used instead of LEAVE trace.
       
   281     * If you have an idea how to round this problem please tell.
       
   282     */
       
   283     _LIT8( KFuncNameTerminator, "(" );
       
   284     _LIT8( KFuncLeavePatternL, "L" );
       
   285     class TFuncLog
       
   286         {
       
   287         public:
       
   288             static void Cleanup( TAny* aPtr )
       
   289                 {
       
   290                 TFuncLog* self = static_cast< TFuncLog* >( aPtr );
       
   291                 self->iLeft = ETrue;
       
   292                 FUNC( _PREFIX_CHAR("%S-LEAVE"), &self->iFunc ); // Leave detected
       
   293                 }
       
   294             inline TFuncLog( const char* aFunc ) :
       
   295                     iFunc( aFunc ? _S8( aFunc ) : _S8("") ),
       
   296                     iLeft( EFalse ),
       
   297                     iCleanupItem( Cleanup, this ),
       
   298                     iCanLeave( EFalse )
       
   299                 {
       
   300                 TInt pos( iFunc.Find( KFuncNameTerminator ) );
       
   301                 if( pos != KErrNotFound )
       
   302                     {
       
   303                     iFunc.Set( iFunc.Left( pos ) );
       
   304                     iCanLeave = !iFunc.Right( KFuncLeavePatternL().Length() ).Compare( KFuncLeavePatternL );
       
   305                     if ( iCanLeave )
       
   306                         {
       
   307                         CleanupStack::PushL( iCleanupItem ); // Ignore warnings
       
   308                         }
       
   309                     }
       
   310                 FUNC( _PREFIX_CHAR("%S-START"), &iFunc );
       
   311                 }
       
   312 
       
   313             inline ~TFuncLog()
       
   314                 {
       
   315                 if ( !iLeft )
       
   316                     {
       
   317                     if ( iCanLeave )
       
   318                         {
       
   319                         CleanupStack::Pop( this ); // Pop the cleanup item
       
   320                         }
       
   321                     FUNC( _PREFIX_CHAR("%S-END"), &iFunc ); // Normally finished
       
   322                     }
       
   323                 }
       
   324 
       
   325         private: // Data
       
   326             TPtrC8 iFunc;
       
   327             TBool iLeft;
       
   328             TCleanupItem iCleanupItem;
       
   329             TBool iCanLeave;
       
   330         };
       
   331     #define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__ );
       
   332     
       
   333 #else//FUNC_TRACE not defined
       
   334 
       
   335     #define FUNC_LOG
       
   336 
       
   337 #endif//FUNC_TRACE
       
   338 
       
   339 //-----------------------------------------------------------------------------
       
   340 // Timestamp trace macros
       
   341 //-----------------------------------------------------------------------------
       
   342 //
       
   343 #ifdef TIMESTAMP_TRACE
       
   344 
       
   345     #ifdef TRACE_INTO_FILE
       
   346     
       
   347         #define TIMESTAMP( aCaption )\
       
   348             {\
       
   349             TTime t;\
       
   350             t.HomeTime();\
       
   351             TDateTime dt = t.DateTime();\
       
   352             _LIT( KCaption, aCaption );\
       
   353             RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend,\
       
   354                 _PREFIX_TRACE("[TIMESTAMP] %S %d:%02d:%02d.%d us"),\
       
   355                     &KCaption, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\
       
   356             }
       
   357 
       
   358     #else//TRACE_INTO_FILE not defined
       
   359     
       
   360         #define TIMESTAMP( aCaption )\
       
   361             {\
       
   362             TTime t;\
       
   363             t.HomeTime();\
       
   364             TDateTime dt = t.DateTime();\
       
   365             _LIT( KCaption, aCaption );\
       
   366             RDebug::Print( _PREFIX_TRACE("[TIMESTAMP] %S %d:%02d:%02d.%d us"),\
       
   367                 &KCaption, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\
       
   368             }
       
   369 
       
   370     #endif//TRACE_INTO_FILE
       
   371 
       
   372 #else//TIMESTAMP_TRACE not defined
       
   373 
       
   374     #define TIMESTAMP( aCaption )
       
   375 
       
   376 #endif//TIMESTAMP_TRACE
       
   377 
       
   378 #endif