accessoryservices/pluggeddisplay/edidparser/inc/trace.h
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2  * Copyright (c) 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: Tracing macros, 2nd generation
       
    15  *
       
    16  */
       
    17 
       
    18 #ifndef TRACE_H
       
    19 #define TRACE_H
       
    20 
       
    21 #include "traceconfiguration.hrh"
       
    22 #include "tracedefs.h"
       
    23 #include <e32debug.h> // RDebug
       
    24 #if defined TRACE_INTO_FILE || defined LOG_INTO_FILE
       
    25     #include <flogger.h> // RFileLogger
       
    26 #endif
       
    27 
       
    28 
       
    29 //-----------------------------------------------------------------------------
       
    30 // Constants
       
    31 //-----------------------------------------------------------------------------
       
    32 //
       
    33 
       
    34 /**
       
    35 * Prefix error trace
       
    36 */
       
    37 #define _PREFIX_ERROR( aMsg ) _PREFIX_TRACE( "[ERROR: %d]: " L##aMsg )
       
    38 
       
    39 /**
       
    40 * Prefix info trace.
       
    41 */
       
    42 #define _PREFIX_INFO( aMsg ) _PREFIX_TRACE( "[INFO]: " L##aMsg )
       
    43 
       
    44 /**
       
    45 * Helper for using _LIT with macros.
       
    46 */
       
    47 #define _CREATE_LIT(a,b) _LIT(a,b)
       
    48 
       
    49 /**
       
    50 * Define needed if TRACE_INTO_FILE macro in use
       
    51 */
       
    52 #ifdef TRACE_INTO_FILE
       
    53     _CREATE_LIT( KTraceFile, TRACE_FILE );
       
    54 #endif
       
    55 
       
    56 /**
       
    57 * Define needed directories if LOG_INTO_FILE macro in use
       
    58 */
       
    59 #ifdef LOG_INTO_FILE
       
    60     _CREATE_LIT( KLogFile, LOG_FILE );
       
    61 #endif
       
    62 
       
    63 /**
       
    64 * Helpers for tracing into file.
       
    65 */
       
    66 #if defined TRACE_INTO_FILE || defined LOG_INTO_FILE
       
    67 
       
    68 const TText KBackSlash = '\\';
       
    69 
       
    70 static TPtrC DriveAndPath( const TDesC& aFullPath )
       
    71     {
       
    72     TInt pos( aFullPath.LocateReverse( KBackSlash ) );
       
    73     return ( pos >= 0 && pos < aFullPath.Length() ? aFullPath.Left( pos ) : KNullDesC() );
       
    74     }
       
    75 
       
    76 static TPtrC NameAndExt( const TDesC& aFullPath )
       
    77     {
       
    78     TInt pos( aFullPath.LocateReverse( KBackSlash ) );
       
    79     return ( pos >= 0 && pos < aFullPath.Length() ? aFullPath.Mid( pos + 1 ) : KNullDesC() );
       
    80     }
       
    81 
       
    82 #endif
       
    83 
       
    84 //-----------------------------------------------------------------------------
       
    85 // Error trace macros
       
    86 //-----------------------------------------------------------------------------
       
    87 //
       
    88 #ifdef ERROR_TRACE
       
    89 
       
    90     /**
       
    91     * Error trace definitions.
       
    92     */
       
    93     #ifdef TRACE_INTO_FILE
       
    94 
       
    95         #define ERROR( aErr, aMsg )\
       
    96             {\
       
    97             if( aErr < KErrNone )\
       
    98                 {\
       
    99                 RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   100                     EFileLoggingModeAppend,\
       
   101                     _PREFIX_ERROR( aMsg ), aErr );\
       
   102                 }\
       
   103             }
       
   104         #define ERROR_1( aErr, aMsg, aP1 )\
       
   105             {\
       
   106             if( aErr < KErrNone )\
       
   107                 {\
       
   108                 RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   109                     EFileLoggingModeAppend,\
       
   110                     _PREFIX_ERROR( aMsg ), aErr, aP1 );\
       
   111                 }\
       
   112             }
       
   113         #define ERROR_2( aErr, aMsg, aP1, aP2 )\
       
   114             {\
       
   115             if( aErr < KErrNone )\
       
   116                 {\
       
   117                 RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   118                     EFileLoggingModeAppend,\
       
   119                     _PREFIX_ERROR( aMsg ), aErr, aP1, aP2 );\
       
   120                 }\
       
   121             }
       
   122         #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\
       
   123             {\
       
   124             if( aErr < KErrNone )\
       
   125                 {\
       
   126                 RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   127                     EFileLoggingModeAppend,\
       
   128                     _PREFIX_ERROR( aMsg ), aErr, aP1, aP2, aP3 );\
       
   129                 }\
       
   130             }
       
   131 
       
   132     #else//TRACE_INTO_FILE not defined
       
   133 
       
   134         #define ERROR( aErr, aMsg )\
       
   135             {\
       
   136             if( aErr < KErrNone )\
       
   137                 {\
       
   138                 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr );\
       
   139                 }\
       
   140             }
       
   141         #define ERROR_1( aErr, aMsg, aP1 )\
       
   142             {\
       
   143             if( aErr < KErrNone )\
       
   144                 {\
       
   145                 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1 );\
       
   146                 }\
       
   147             }
       
   148         #define ERROR_2( aErr, aMsg, aP1, aP2 )\
       
   149             {\
       
   150             if( aErr < KErrNone )\
       
   151                 {\
       
   152                 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1, aP2 );\
       
   153                 }\
       
   154             }
       
   155         #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\
       
   156             {\
       
   157             if( aErr < KErrNone )\
       
   158                 {\
       
   159                 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1, aP2, aP3 );\
       
   160                 }\
       
   161             }
       
   162 
       
   163     #endif//TRACE_INTO_FILE
       
   164 
       
   165     #define ERROR_GEN( aMsg ) ERROR( KErrGeneral, aMsg )
       
   166     #define ERROR_GEN_1( aMsg, aP1 ) ERROR_1( KErrGeneral, aMsg, aP1 )
       
   167     #define ERROR_GEN_2( aMsg, aP1, aP2 ) ERROR_2( KErrGeneral, aMsg, aP1, aP2 )
       
   168     #define ERROR_GEN_3( aMsg, aP1, aP2, aP3 ) ERROR_3( KErrGeneral, aMsg, aP1, aP3 )
       
   169 
       
   170     #define ERROR_PARAM(_p) _p
       
   171 
       
   172     #define TRAPD_ERR( aErr, aStmt ) TRAPD( aErr, aStmt )
       
   173     #define TRAP_ERR( aErr, aStmt ) TRAP( aErr, aStmt )
       
   174 
       
   175     #define TRAP_AND_LEAVE(_s,_t) \
       
   176         { TRAPD(_e,_s); ERROR(_e,_t); User::LeaveIfError(_e); }
       
   177 
       
   178 #else//ERROR_TRACE not defined
       
   179 
       
   180     #define ERROR( aErr, aMsg )
       
   181     #define ERROR_1( aErr, aMsg, aP1 )
       
   182     #define ERROR_2( aErr, aMsg, aP1, aP2 )
       
   183     #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )
       
   184     #define ERROR_GEN( aMsg )
       
   185     #define ERROR_GEN_1( aMsg, aP1 )
       
   186     #define ERROR_GEN_2( aMsg, aP1, aP2 )
       
   187     #define ERROR_GEN_3( aMsg, aP1, aP2, aP3 )
       
   188 
       
   189     #define ERROR_PARAM(_p)
       
   190 
       
   191     #define TRAPD_ERR( aErr, aStmt ) TRAP_IGNORE( aStmt )
       
   192     #define TRAP_ERR( aErr, aStmt )  TRAP_IGNORE( aStmt )
       
   193 
       
   194     #define TRAP_AND_LEAVE(_s,_t) { _s; }
       
   195 
       
   196 #endif//ERROR_TRACE
       
   197 
       
   198 //-----------------------------------------------------------------------------
       
   199 // Info trace macros
       
   200 //-----------------------------------------------------------------------------
       
   201 //
       
   202 #ifdef INFO_TRACE
       
   203 
       
   204     /**
       
   205     * Info log message definitions.
       
   206     */
       
   207     #ifdef TRACE_INTO_FILE
       
   208 
       
   209         #define INFO( aMsg )\
       
   210             {\
       
   211             RFileLogger::Write( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   212                 EFileLoggingModeAppend,\
       
   213                 _PREFIX_INFO( aMsg ) );\
       
   214             }
       
   215         #define INFO_1( aMsg, aP1 )\
       
   216             {\
       
   217             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   218                 EFileLoggingModeAppend,\
       
   219                 _PREFIX_INFO( aMsg ), aP1 );\
       
   220             }
       
   221         #define INFO_2( aMsg, aP1, aP2 )\
       
   222             {\
       
   223             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   224                 EFileLoggingModeAppend,\
       
   225                 _PREFIX_INFO( aMsg ), aP1, aP2 );\
       
   226             }
       
   227         #define INFO_3( aMsg, aP1, aP2, aP3 )\
       
   228             {\
       
   229             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   230                 EFileLoggingModeAppend,\
       
   231                 _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\
       
   232             }
       
   233         #define INFO_4( aMsg, aP1, aP2, aP3, aP4 )\
       
   234             {\
       
   235             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   236                 EFileLoggingModeAppend,\
       
   237                 _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4 );\
       
   238             }
       
   239         #define INFO_5( aMsg, aP1, aP2, aP3, aP4, aP5 )\
       
   240             {\
       
   241             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   242                 EFileLoggingModeAppend,\
       
   243                 _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4, aP5 );\
       
   244             }
       
   245 
       
   246     #else//TRACE_INTO_FILE not defined
       
   247 
       
   248         #define INFO( aMsg )\
       
   249             {\
       
   250             RDebug::Print( _PREFIX_INFO( aMsg ) );\
       
   251             }
       
   252         #define INFO_1( aMsg, aP1 )\
       
   253             {\
       
   254             RDebug::Print( _PREFIX_INFO( aMsg ), aP1 );\
       
   255             }
       
   256         #define INFO_2( aMsg, aP1, aP2 )\
       
   257             {\
       
   258             RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2 );\
       
   259             }
       
   260         #define INFO_3( aMsg, aP1, aP2, aP3 )\
       
   261             {\
       
   262             RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\
       
   263             }
       
   264         #define INFO_4( aMsg, aP1, aP2, aP3, aP4 )\
       
   265             {\
       
   266             RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4 );\
       
   267             }
       
   268         #define INFO_5( aMsg, aP1, aP2, aP3, aP4, aP5 )\
       
   269             {\
       
   270             RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4, aP5 );\
       
   271             }
       
   272 
       
   273     #endif//TRACE_INTO_FILE
       
   274 
       
   275     #define INFO_PARAM( aParam ) aParam
       
   276 
       
   277 #else//INFO_TRACE not defined
       
   278 
       
   279     #define INFO( aMsg )
       
   280     #define INFO_1( aMsg, aP1 )
       
   281     #define INFO_2( aMsg, aP1, aP2 )
       
   282     #define INFO_3( aMsg, aP1, aP2, aP3 )
       
   283     #define INFO_4( aMsg, aP1, aP2, aP3, aP4 )
       
   284     #define INFO_5( aMsg, aP1, aP2, aP3, aP4, aP5 )
       
   285     #define INFO_PARAM( aParam )
       
   286 
       
   287 #endif//INFO_TRACE
       
   288 
       
   289 //-----------------------------------------------------------------------------
       
   290 // Trace current client thread name and process id
       
   291 //-----------------------------------------------------------------------------
       
   292 //
       
   293 #ifdef CLIENT_TRACE
       
   294 
       
   295     #define _PREFIX_CLIENT( aMsg ) _PREFIX_TRACE( "[CLIENT: sid [0x%x] thread [%S]] " L##aMsg )
       
   296 
       
   297     #ifdef TRACE_INTO_FILE
       
   298 
       
   299         #define CLIENT_TRACE_2( aMsg, aP1, aP2 )\
       
   300             {\
       
   301             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   302                 EFileLoggingModeAppend, _PREFIX_CLIENT(aMsg), aP1, aP2 );\
       
   303             }
       
   304 
       
   305     #else//TRACE_INTO_FILE not defined
       
   306 
       
   307         #define CLIENT_TRACE_2( aMsg, aP1, aP2 )\
       
   308             {\
       
   309             RDebug::Print( _PREFIX_CLIENT(aMsg), aP1, aP2 );\
       
   310             }
       
   311 
       
   312     #endif//TRACE_INTO_FILE
       
   313 
       
   314     /**
       
   315     * Traces current secure id and thread
       
   316     */
       
   317     #define CURRENT_CLIENT( aMsg )\
       
   318         {\
       
   319         TName name( RThread().Name() );\
       
   320         TSecureId sid( RThread().SecureId() );\
       
   321         CLIENT_TRACE_2( aMsg, sid.iId, &name );\
       
   322         }
       
   323 
       
   324     /**
       
   325     * Traces secure id and thread from RMessage2
       
   326     */
       
   327     #define CLIENT( aRMessage2 )\
       
   328         {\
       
   329         RThread thread;\
       
   330         TInt err = aRMessage2.Client( thread );\
       
   331         if( err == KErrNone )\
       
   332             {\
       
   333             TName name( thread.Name() );\
       
   334             TSecureId sid( thread.SecureId() );\
       
   335             CLIENT_TRACE_2( "", sid.iId, &name );\
       
   336             }\
       
   337         thread.Close();\
       
   338         }
       
   339 
       
   340     /**
       
   341     * Traces secure id and thread from RMessage2
       
   342     */
       
   343     #define CLIENT_1( aRMessage2, aMsg )\
       
   344         {\
       
   345         RThread thread;\
       
   346         TInt err = aRMessage2.Client( thread );\
       
   347         if( err == KErrNone )\
       
   348             {\
       
   349             TName name( thread.Name() );\
       
   350             TSecureId sid( thread.SecureId() );\
       
   351             CLIENT_TRACE_2( aMsg, sid.iId, &name );\
       
   352             }\
       
   353         thread.Close();\
       
   354         }
       
   355 
       
   356 #else
       
   357 
       
   358     #define CURRENT_CLIENT( aMsg )
       
   359     #define CLIENT( aRMessage2 )
       
   360     #define CLIENT_1( aRMessage2, aMsg )
       
   361 
       
   362 #endif
       
   363 
       
   364 //-----------------------------------------------------------------------------
       
   365 // Trace current heap usage
       
   366 //-----------------------------------------------------------------------------
       
   367 //
       
   368 #ifdef HEAP_TRACE
       
   369 
       
   370     #define _PREFIX_HEAP( aMsg ) _PREFIX_TRACE( "[HEAP: %d bytes] " L##aMsg )
       
   371 
       
   372     #ifdef TRACE_INTO_FILE
       
   373 
       
   374         #define HEAP( aMsg )\
       
   375             {\
       
   376             TInt totalAllocSpace = 0;\
       
   377             User::AllocSize( totalAllocSpace );\
       
   378             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   379                 EFileLoggingModeAppend, _PREFIX_HEAP( aMsg ), totalAllocSpace );\
       
   380             }
       
   381         #define HEAP_1( aMsg, aP1 )\
       
   382             {\
       
   383             TInt totalAllocSpace = 0;\
       
   384             User::AllocSize( totalAllocSpace );\
       
   385             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   386                 EFileLoggingModeAppend, _PREFIX_HEAP( aMsg ), totalAllocSpace, aP1 );\
       
   387             }
       
   388         #define HEAP_2( aMsg, aP1, aP2 )\
       
   389             {\
       
   390             TInt totalAllocSpace = 0;\
       
   391             User::AllocSize( totalAllocSpace );\
       
   392             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   393                 EFileLoggingModeAppend, _PREFIX_HEAP( aMsg ), totalAllocSpace, aP1, aP2 );\
       
   394             }
       
   395         #define HEAP_3( aMsg, aP1, aP2, aP3 )\
       
   396             {\
       
   397             TInt totalAllocSpace = 0;\
       
   398             User::AllocSize( totalAllocSpace );\
       
   399             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   400                 EFileLoggingModeAppend, _PREFIX_HEAP( aMsg ), totalAllocSpace, aP1, aP2, aP3 );\
       
   401             }
       
   402         #define HEAP_4( aMsg, aP1, aP2, aP3, aP4 )\
       
   403             {\
       
   404             TInt totalAllocSpace = 0;\
       
   405             User::AllocSize( totalAllocSpace );\
       
   406             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   407                 EFileLoggingModeAppend, _PREFIX_HEAP( aMsg ), totalAllocSpace, aP1, aP2, aP3, aP4 );\
       
   408             }
       
   409 
       
   410     #else//TRACE_INTO_FILE not defined
       
   411 
       
   412         #define HEAP( aMsg )\
       
   413             {\
       
   414             TInt totalAllocSpace = 0;\
       
   415             User::AllocSize( totalAllocSpace );\
       
   416             RDebug::Print( _PREFIX_HEAP( aMsg ), totalAllocSpace );\
       
   417             }
       
   418         #define HEAP_1( aMsg, aP1 )\
       
   419             {\
       
   420             TInt totalAllocSpace = 0;\
       
   421             User::AllocSize( totalAllocSpace );\
       
   422             RDebug::Print( _PREFIX_HEAP( aMsg ), totalAllocSpace, aP1 );\
       
   423             }
       
   424         #define HEAP_2( aMsg, aP1, aP2 )\
       
   425             {\
       
   426             TInt totalAllocSpace = 0;\
       
   427             User::AllocSize( totalAllocSpace );\
       
   428             RDebug::Print( _PREFIX_HEAP( aMsg ), totalAllocSpace, aP1, aP2 );\
       
   429             }
       
   430         #define HEAP_3( aMsg, aP1, aP2, aP3 )\
       
   431             {\
       
   432             TInt totalAllocSpace = 0;\
       
   433             User::AllocSize( totalAllocSpace );\
       
   434             RDebug::Print( _PREFIX_HEAP( aMsg ), totalAllocSpace, aP1, aP2, aP3 );\
       
   435             }
       
   436         #define HEAP_4( aMsg, aP1, aP2, aP3, aP4 )\
       
   437             {\
       
   438             TInt totalAllocSpace = 0;\
       
   439             User::AllocSize( totalAllocSpace );\
       
   440             RDebug::Print( _PREFIX_HEAP( aMsg ), totalAllocSpace, aP1, aP2, aP3, aP4 );\
       
   441             }
       
   442 
       
   443     #endif//TRACE_INTO_FILE
       
   444 
       
   445 #else//HEAP_TRACE not defined
       
   446 
       
   447     #define HEAP( aMsg )
       
   448     #define HEAP_1( aMsg, aP1 )
       
   449     #define HEAP_2( aMsg, aP1, aP2 )
       
   450     #define HEAP_3( aMsg, aP1, aP2, aP3 )
       
   451     #define HEAP_4( aMsg, aP1, aP2, aP3, aP4 )
       
   452 
       
   453 #endif//HEAP_TRACE
       
   454 
       
   455 
       
   456 //-----------------------------------------------------------------------------
       
   457 // Function trace macros
       
   458 //-----------------------------------------------------------------------------
       
   459 //
       
   460 #ifdef FUNC_TRACE
       
   461 
       
   462     #include <e32base.h> // TCleanupItem
       
   463 
       
   464     /**
       
   465     * Function logging definitions.
       
   466     */
       
   467     #ifdef TRACE_INTO_FILE
       
   468 
       
   469         #define FUNC( aMsg, aP1 )\
       
   470             {\
       
   471             TPtrC8 trace( _S8( aMsg ) );\
       
   472             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   473                 EFileLoggingModeAppend, trace, aP1 );\
       
   474             }
       
   475 
       
   476         #define FUNC_2( aMsg, aP1, aP2, aP3 )\
       
   477             {\
       
   478             TPtrC8 trace( _S8( aMsg ) );\
       
   479             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   480                 EFileLoggingModeAppend, trace, aP1, aP2, aP3 );\
       
   481             }
       
   482 
       
   483     #else//TRACE_INTO_FILE not defined
       
   484 
       
   485         #define FUNC( aMsg, aP1 )\
       
   486             {\
       
   487             RDebug::Printf( aMsg, aP1 );\
       
   488             }
       
   489 
       
   490         #define FUNC_2( aMsg, aP1, aP2, aP3 )\
       
   491             {\
       
   492             RDebug::Printf( aMsg, aP1, aP2, aP3 );\
       
   493             }
       
   494 
       
   495     #endif//TRACE_INTO_FILE
       
   496 
       
   497     /**
       
   498     * Function trace helper class.
       
   499     */
       
   500     const TText KFuncNameTerminator = '(';
       
   501     const TText KFuncLeaveIndicator = 'L';
       
   502     const TInt KFuncCanLeave = 0x1;
       
   503     const TInt KFuncLeft = 0x2;
       
   504     const TInt KFuncLogClient = 0x4;
       
   505     
       
   506     class TFuncLog
       
   507         {
       
   508     public:
       
   509         static void Cleanup( TAny* aPtr )
       
   510             {
       
   511             TFuncLog* self = static_cast< TFuncLog* >( aPtr );
       
   512             self->iFlags |= KFuncLeft;
       
   513             self->LogLeave();
       
   514             }
       
   515     
       
   516         inline void LogStart()
       
   517             {
       
   518             if ( iFlags & KFuncLogClient )
       
   519                 {
       
   520                 TBuf8<KMaxName> name8;
       
   521                 name8.Copy( RThread().Name() );
       
   522                 TSecureId sid( RThread().SecureId() );
       
   523                 FUNC_2( _PREFIX_TRACE8("%S-START(sid [0x%x] thread [%S])"),
       
   524                     &iFunc, sid.iId, &name8 );
       
   525                 }
       
   526             else
       
   527                 {
       
   528                 FUNC( _PREFIX_TRACE8("%S-START"), &iFunc );
       
   529                 }
       
   530             }
       
   531 
       
   532         inline void LogLeave()
       
   533             {
       
   534             if ( iFlags & KFuncLogClient )
       
   535                 {
       
   536                 TBuf8<KMaxName> name8;
       
   537                 name8.Copy( RThread().Name() );
       
   538                 TSecureId sid( RThread().SecureId() );
       
   539                 FUNC_2( _PREFIX_TRACE8("%S-LEAVE(sid [0x%x] thread [%S])"),
       
   540                     &iFunc, sid.iId, &name8 );
       
   541                 }
       
   542             else
       
   543                 {
       
   544                 FUNC( _PREFIX_TRACE8("%S-LEAVE"), &iFunc );
       
   545                 }
       
   546             }
       
   547     
       
   548         inline void LogEnd()
       
   549             {
       
   550             if ( iFlags & KFuncLogClient )
       
   551                 {
       
   552                 TBuf8<KMaxName> name8;
       
   553                 name8.Copy( RThread().Name() );
       
   554                 TSecureId sid( RThread().SecureId() );
       
   555                 FUNC_2( _PREFIX_TRACE8("%S-END(sid [0x%x] thread [%S])"),
       
   556                     &iFunc, sid.iId, &name8 );
       
   557                 }
       
   558             else
       
   559                 {
       
   560                 FUNC( _PREFIX_TRACE8("%S-END"), &iFunc );
       
   561                 }
       
   562             }
       
   563     
       
   564         // For non leaving and L methods
       
   565         inline TFuncLog( const char* aFunc, TUint aFlags ) :
       
   566                 iFunc( aFunc ? _S8( aFunc ) : _S8("") ),
       
   567                 iFlags( aFlags ),
       
   568                 iCleanupItem( Cleanup, this ),
       
   569                 iLCPtr( NULL )
       
   570             {
       
   571             TInt pos( iFunc.Locate( KFuncNameTerminator ) );
       
   572             if( pos >= 0 && pos < iFunc.Length() )
       
   573                 {
       
   574                 iFunc.Set( iFunc.Left( pos ) );
       
   575                 TInt len( iFunc.Length() );
       
   576                 if( len > 0 && iFunc[ len - 1 ] == KFuncLeaveIndicator )
       
   577                     {
       
   578                     iFlags |= KFuncCanLeave;
       
   579                     CleanupStack::PushL( iCleanupItem ); // Ignore warnings
       
   580                     }
       
   581                 }
       
   582             LogStart();
       
   583             }
       
   584     
       
   585         // For LC methods only
       
   586         inline TFuncLog( const char* aFunc, TUint aFlags, TAny** aLCPtr ) :
       
   587                 iFunc( aFunc ? _S8( aFunc ) : _S8("") ),
       
   588                 iFlags( aFlags ),
       
   589                 iCleanupItem( Cleanup, this ),
       
   590                 iLCPtr( NULL )
       
   591             {
       
   592             TInt pos( iFunc.Locate( KFuncNameTerminator ) );
       
   593             if( pos >= 0 && pos < iFunc.Length() )
       
   594                 {
       
   595                 iFunc.Set( iFunc.Left( pos ) );
       
   596                 iFlags |= KFuncCanLeave;
       
   597                 iLCPtr = aLCPtr;
       
   598                 CleanupStack::PushL( iCleanupItem ); // Ignore warnings
       
   599                 }
       
   600             LogStart();
       
   601             }
       
   602     
       
   603         inline ~TFuncLog()
       
   604             {
       
   605             if ( !( iFlags & KFuncLeft ) )
       
   606                 {
       
   607                 if ( iFlags & KFuncCanLeave )
       
   608                     {
       
   609                     if ( iLCPtr && *iLCPtr)
       
   610                         {
       
   611                         CleanupStack::Pop(); // Pop LC ptr first
       
   612                         CleanupStack::Pop( this ); // Pop the cleanup item
       
   613                         CleanupStack::PushL( *iLCPtr ); // Push LC ptr back
       
   614                         }
       
   615                     else
       
   616                         {
       
   617                         CleanupStack::Pop( this ); // Pop the cleanup item
       
   618                         }
       
   619                     }
       
   620                 LogEnd(); // Normally finished
       
   621                 }
       
   622             }
       
   623     
       
   624     private: // Data
       
   625         TPtrC8 iFunc;
       
   626         TUint iFlags;
       
   627         TCleanupItem iCleanupItem;
       
   628         TAny** iLCPtr;
       
   629         };
       
   630 
       
   631     /*
       
   632     * Use with non leaving and L methods
       
   633     *
       
   634     * CMyClass* CMyClass::DoL()
       
   635     *   {
       
   636     *   FUNC_LOG;
       
   637     *   CMyClass* ret = new (ELeave) CMyClass();
       
   638     *   ...
       
   639     *   return ret;
       
   640     *   }
       
   641     *
       
   642     * CMyClass* CMyClass::Do()
       
   643     *   {
       
   644     *   FUNC_LOG;
       
   645     *   return iMyClass;
       
   646     *   }
       
   647     *
       
   648     */
       
   649     #define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__, 0 );
       
   650 
       
   651     /*
       
   652     * Use with LC methods
       
   653     *
       
   654     * CMyClass* CMyClass::DoLC()
       
   655     *   {
       
   656     *   CMyClass* ret = NULL;
       
   657     *   FUNC_LOG_LC( ret );
       
   658     *   ...
       
   659     *   return ret;
       
   660     *   }
       
   661     */
       
   662     #define FUNC_LOG_LC( aPtr ) TFuncLog _fl( __PRETTY_FUNCTION__, 0, (TAny**)&aPtr );
       
   663 
       
   664 #ifdef CLIENT_TRACE
       
   665 
       
   666     /*
       
   667     * Used like FUNC_LOG. Prints client info useful for client side executed API methods.
       
   668     */
       
   669     #define FUNC_LOG_WITH_CLIENT TFuncLog _fl( __PRETTY_FUNCTION__, KFuncLogClient );
       
   670 
       
   671     /*
       
   672     * Used like FUNC_LOG_LC. Prints client info useful for client side executed API methods.
       
   673     */ 
       
   674     #define FUNC_LOG_WITH_CLIENT_LC( aPtr )\
       
   675         TFuncLog _fl( __PRETTY_FUNCTION__, KFuncLogClient, (TAny**)&aPtr );
       
   676 
       
   677 #else //CLIENT_TRACE not defined
       
   678 
       
   679     #define FUNC_LOG_WITH_CLIENT FUNC_LOG
       
   680     #define FUNC_LOG_WITH_CLIENT_LC( aPtr ) FUNC_LOG_LC( aPtr )
       
   681 
       
   682 #endif //CLIENT_TRACE
       
   683 
       
   684 #else//FUNC_TRACE not defined
       
   685 
       
   686     #define FUNC_LOG
       
   687     #define FUNC_LOG_LC( ptr )
       
   688     #define FUNC_LOG_WITH_CLIENT
       
   689     #define FUNC_LOG_WITH_CLIENT_LC( ptr )
       
   690 
       
   691 #endif//FUNC_TRACE
       
   692 
       
   693 //-----------------------------------------------------------------------------
       
   694 // Timestamp trace macros
       
   695 //-----------------------------------------------------------------------------
       
   696 //
       
   697 #ifdef TIMESTAMP_TRACE
       
   698 
       
   699     #define PREFIX_TIMESTAMP( aCaption )\
       
   700         _PREFIX_TRACE_2("[TIMESTAMP] (%d:%02d:%02d.%06d us) ",aCaption)
       
   701     #define CURRENT_TIME( aDt ) TDateTime aDt; { TTime t; t.HomeTime(); aDt = t.DateTime(); }
       
   702     #define EXTRACT_TIME( aDt ) aDt.Hour(), aDt.Minute(), aDt.Second(), aDt.MicroSecond()
       
   703 
       
   704     #ifdef TRACE_INTO_FILE
       
   705 
       
   706         #define TIMESTAMP( aCaption )\
       
   707             {\
       
   708             CURRENT_TIME( dt );\
       
   709             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   710                 EFileLoggingModeAppend,\
       
   711                 PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ) );\
       
   712             }
       
   713 
       
   714         #define TIMESTAMP_1( aCaption, aP1 )\
       
   715             {\
       
   716             CURRENT_TIME( dt );\
       
   717             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   718                 EFileLoggingModeAppend,\
       
   719                 PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1 );\
       
   720             }
       
   721 
       
   722         #define TIMESTAMP_2( aCaption, aP1, aP2 )\
       
   723             {\
       
   724             CURRENT_TIME( dt );\
       
   725             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   726                  EFileLoggingModeAppend,\
       
   727                 PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1,aP2 );\
       
   728             }
       
   729 
       
   730         #define TIMESTAMP_3( aCaption, aP1, aP2, aP3 )\
       
   731             {\
       
   732             CURRENT_TIME( dt );\
       
   733             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   734                 EFileLoggingModeAppend,\
       
   735                 PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1,aP2,aP3 );\
       
   736             }
       
   737 
       
   738     #else//TRACE_INTO_FILE not defined
       
   739 
       
   740         #define TIMESTAMP( aCaption )\
       
   741             {\
       
   742             CURRENT_TIME( dt );\
       
   743             RDebug::Print( PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ) );\
       
   744             }
       
   745 
       
   746         #define TIMESTAMP_1( aCaption, aP1 )\
       
   747             {\
       
   748             CURRENT_TIME( dt );\
       
   749             RDebug::Print( PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1 );\
       
   750             }
       
   751 
       
   752         #define TIMESTAMP_2( aCaption, aP1, aP2 )\
       
   753             {\
       
   754             CURRENT_TIME( dt );\
       
   755             RDebug::Print( PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1,aP2 );\
       
   756             }
       
   757 
       
   758         #define TIMESTAMP_3( aCaption, aP1, aP2, aP3 )\
       
   759             {\
       
   760             CURRENT_TIME( dt );\
       
   761             RDebug::Print( PREFIX_TIMESTAMP(aCaption),EXTRACT_TIME( dt ),aP1,aP2,aP3 );\
       
   762             }
       
   763 
       
   764     #endif//TRACE_INTO_FILE
       
   765 
       
   766 #else//TIMESTAMP_TRACE not defined
       
   767 
       
   768     #define TIMESTAMP( aCaption )
       
   769     #define TIMESTAMP_1( aCaption, aP1 )
       
   770     #define TIMESTAMP_2( aCaption, aP1, aP2 )
       
   771     #define TIMESTAMP_3( aCaption, aP1, aP2, aP3 )
       
   772 
       
   773 #endif//TIMESTAMP_TRACE
       
   774 
       
   775 //-----------------------------------------------------------------------------
       
   776 // Trace assert macros
       
   777 //-----------------------------------------------------------------------------
       
   778 //
       
   779 #ifdef _DEBUG
       
   780 
       
   781     #ifdef TRACE_INTO_FILE
       
   782 
       
   783         #define PANIC_TRACE_2( aMsg, aP1, aP2 )\
       
   784             {\
       
   785             TPtrC8 trace( _S8( aMsg ) );\
       
   786             RFileLogger::WriteFormat( DriveAndPath( KTraceFile ), NameAndExt( KTraceFile ),\
       
   787                 EFileLoggingModeAppend, trace, aP1, aP2 );\
       
   788             }
       
   789 
       
   790     #else//TRACE_INTO_FILE not defined
       
   791 
       
   792         #define PANIC_TRACE_2( aMsg, aP1, aP2 )\
       
   793             {\
       
   794             RDebug::Printf( aMsg, aP1, aP2 );\
       
   795             }
       
   796 
       
   797     #endif //TRACE_INTO_FILE not define
       
   798 
       
   799     static void Panic( const TDesC8& aFileName, const TInt aLineNum )
       
   800         {
       
   801         PANIC_TRACE_2( "Assertion failed in file=%S, line=%d", &aFileName, aLineNum );
       
   802         User::Invariant();
       
   803         }
       
   804 
       
   805     #define ASSERT_ALWAYS_TRACE Panic( _L8(__FILE__), __LINE__ );
       
   806     #define ASSERT_TRACE( _s ) if ( !( _s ) ) { ASSERT_ALWAYS_TRACE; }
       
   807 
       
   808 #else // _DEBUG
       
   809 
       
   810     #define ASSERT_ALWAYS_TRACE
       
   811     #define ASSERT_TRACE( _s )
       
   812 
       
   813 #endif // _DEBUG
       
   814 
       
   815 //-----------------------------------------------------------------------------
       
   816 // Event logging macros
       
   817 //-----------------------------------------------------------------------------
       
   818 //
       
   819 #ifdef LOG_INTO_FILE
       
   820 
       
   821     #define _PREFIX_LOG( aMsg ) _PREFIX_TRACE( "[LOG] " L##aMsg )
       
   822 
       
   823     class TLogObjectAppend
       
   824         {
       
   825     public:
       
   826         inline TLogObjectAppend()
       
   827             {
       
   828             if ( iFlogger.Connect() == KErrNone )
       
   829                 {
       
   830                 iFlogger.CreateLog( DriveAndPath(KLogFile), NameAndExt(KLogFile),
       
   831                     EFileLoggingModeAppend );
       
   832                 }
       
   833             }
       
   834         inline ~TLogObjectAppend()
       
   835             {
       
   836             iFlogger.Close();
       
   837             }
       
   838     public:
       
   839         RFileLogger iFlogger;
       
   840         };
       
   841 
       
   842    class TLogObjectNew
       
   843         {
       
   844     public:
       
   845         inline TLogObjectNew()
       
   846             {
       
   847             if ( iFlogger.Connect() == KErrNone )
       
   848                 {
       
   849                 iFlogger.CreateLog( DriveAndPath(KLogFile), NameAndExt(KLogFile),
       
   850                     EFileLoggingModeOverwrite );
       
   851                 }
       
   852             }
       
   853         inline ~TLogObjectNew()
       
   854             {
       
   855             iFlogger.Close();
       
   856             }
       
   857     public:
       
   858         RFileLogger iFlogger;
       
   859         };
       
   860 
       
   861     /*
       
   862     * Use LOG_OBJECT as a member in class declaration or in a method needing logging support
       
   863     * before using any other log macros
       
   864     *
       
   865     * DO NOT enter semicolon after this macro when used in class declaration to avoid compiler
       
   866     * warning.
       
   867     */
       
   868     #define LOG_OBJECT TLogObjectAppend _floggerObject;
       
   869 
       
   870     /*
       
   871     * Use LOG_OBJECT_NEW as a member in class declaration or in a method needing logging support
       
   872     * before using any other log macros. Macro overwrites the existing log file.
       
   873     *
       
   874     * DO NOT enter semicolon after this macro when used in class declaration to avoid compiler
       
   875     * warning.
       
   876     */
       
   877     #define LOG_OBJECT_NEW TLogObjectNew _floggerObject;
       
   878 
       
   879     /*
       
   880     * Use LOG macros to write log file
       
   881     */
       
   882     #define LOG( aMsg ) _floggerObject.iFlogger.WriteFormat( _PREFIX_LOG( aMsg ) );
       
   883 
       
   884     #define LOG_1( aMsg, aP1 ) _floggerObject.iFlogger.WriteFormat( _PREFIX_LOG( aMsg ), aP1 );
       
   885 
       
   886     #define LOG_2( aMsg, aP1, aP2 ) _floggerObject.iFlogger.WriteFormat( _PREFIX_LOG( aMsg ), aP1, aP2 );
       
   887 
       
   888     #define LOG_3( aMsg, aP1, aP2, aP3 ) _floggerObject.iFlogger.WriteFormat( _PREFIX_LOG( aMsg ), aP1, aP2, aP3 );
       
   889 
       
   890     #define LOG_4( aMsg, aP1, aP2, aP3, aP4 )\
       
   891         _floggerObject.iFlogger.WriteFormat( _PREFIX_LOG( aMsg ), aP1, aP2, aP3, aP4 );
       
   892 
       
   893     #define LOG_5( aMsg, aP1, aP2, aP3, aP4, aP5 )\
       
   894         _floggerObject.iFlogger.WriteFormat( _PREFIX_LOG( aMsg ), aP1, aP2, aP3, aP4, aP5 );
       
   895 
       
   896 #else //LOG_INTO_FILE not defined
       
   897 
       
   898     #define LOG_OBJECT
       
   899     #define LOG_OBJECT_NEW
       
   900     #define LOG( aMsg )
       
   901     #define LOG_1( aMsg, aP1 )
       
   902     #define LOG_2( aMsg, aP1, aP2 )
       
   903     #define LOG_3( aMsg, aP1, aP2, aP3 )
       
   904     #define LOG_4( aMsg, aP1, aP2, aP3, aP4 )
       
   905     #define LOG_5( aMsg, aP1, aP2, aP3, aP4, aP5 )
       
   906 
       
   907 #endif //LOG_INTO_FILE
       
   908 
       
   909 #endif // TRACE_H