phonecmdhandler/phonecmdhnlr/inc/PhoneHandlerDebug.h
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  Macro definitions for tracing and debugging purposes.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef PHONECMDHANDLER_DEBUG_H
       
    20 #define PHONECMDHANDLER_DEBUG_H
       
    21 
       
    22 #ifdef _DEBUG
       
    23 
       
    24 // INCLUDES
       
    25 #include <e32svr.h>
       
    26 
       
    27 // CONSTANTS
       
    28 _LIT( KComponent, "[PHONECMDHANDLER]" );
       
    29 _LIT( KThisFile,  "[PHONECMDHANDLER] - Trace this file: %s, line: %d, compiled: %s %s" );
       
    30 _LIT( KAssertion, "[PHONECMDHANDLER] - Assertion failed: File: %s, line: %d, compiled: %s %s" );
       
    31 _LIT( KPanic,     "[PHONECMDHANDLER] - Panic occurred: File: %s, line: %d, compiled: %s %s" );
       
    32 _LIT( KMystic,    "[PHONECMDHANDLER] - Mystic failure: File: %s, line: %d, compiled: %s %s" );
       
    33 _LIT8( KDATE, __DATE__ );
       
    34 _LIT8( KTIME, __TIME__ );
       
    35 
       
    36 const TInt KTraceMaxSize = 256;
       
    37 
       
    38 // DATA TYPES
       
    39 enum TTraceType
       
    40     {
       
    41     ETraceInit,
       
    42     ETraceAssert,
       
    43     ETracePanic
       
    44     };
       
    45 
       
    46 // INLINE FUNCTIONS
       
    47 
       
    48     // -----------------------------------------------------------------------------
       
    49     // ThisFileFunc
       
    50     // -----------------------------------------------------------------------------
       
    51     inline void ThisFileFunc( const TDesC8& aFile,
       
    52                               TInt aLine,
       
    53                               TTraceType aType = ETraceInit )
       
    54         {
       
    55         HBufC* fileBuf = HBufC::New( aFile.Length() + 1 );
       
    56         HBufC* dateBuf = HBufC::New( 32 );
       
    57         HBufC* timeBuf = HBufC::New( 32 );
       
    58 
       
    59         if ( fileBuf != NULL && dateBuf != NULL && timeBuf != NULL )
       
    60             {
       
    61             fileBuf->Des().Copy( aFile );
       
    62             timeBuf->Des().Copy( KTIME );
       
    63             dateBuf->Des().Copy( KDATE );
       
    64 
       
    65             if ( aType == ETraceInit )
       
    66                 {
       
    67                 RDebug::Print( KThisFile,
       
    68                                fileBuf->Des().PtrZ(),
       
    69                                aLine,
       
    70                                dateBuf->Des().PtrZ(),
       
    71                                timeBuf->Des().PtrZ() );
       
    72                 }
       
    73 
       
    74             else if ( aType == ETraceAssert )
       
    75                 {
       
    76                 RDebug::Print( KAssertion,
       
    77                                fileBuf->Des().PtrZ(),
       
    78                                aLine,
       
    79                                dateBuf->Des().PtrZ(),
       
    80                                timeBuf->Des().PtrZ() );
       
    81                 }
       
    82 
       
    83             else if ( aType == ETracePanic )
       
    84                 {
       
    85                 RDebug::Print( KPanic,
       
    86                                fileBuf->Des().PtrZ(),
       
    87                                aLine,
       
    88                                dateBuf->Des().PtrZ(),
       
    89                                timeBuf->Des().PtrZ() );
       
    90                 }
       
    91 
       
    92             else
       
    93                 {
       
    94                 RDebug::Print( KMystic,
       
    95                                fileBuf->Des().PtrZ(),
       
    96                                aLine,
       
    97                                dateBuf->Des().PtrZ(),
       
    98                                timeBuf->Des().PtrZ() );
       
    99                 }
       
   100             }
       
   101 
       
   102         else
       
   103             {
       
   104             RDebug::Print( _L( "Assertion and memory allocation failed!" ) );
       
   105             }
       
   106 
       
   107         delete fileBuf;
       
   108         delete dateBuf;
       
   109         delete timeBuf;
       
   110         }
       
   111 
       
   112     // -----------------------------------------------------------------------------
       
   113     // TraceAssertFunc
       
   114     // -----------------------------------------------------------------------------
       
   115     inline void TraceAssertFunc( const TDesC8& aFile, TInt aLine )
       
   116         {
       
   117         ThisFileFunc( aFile, aLine, ETraceAssert );
       
   118         }
       
   119 
       
   120     // -----------------------------------------------------------------------------
       
   121     // TracePanicFunc
       
   122     // -----------------------------------------------------------------------------
       
   123     inline void TracePanicFunc( const TDesC8& aFile, TInt aLine )
       
   124         {
       
   125         ThisFileFunc( aFile, aLine, ETracePanic );
       
   126         User::Panic( KComponent, KErrGeneral );
       
   127         }
       
   128 
       
   129 // MACROS
       
   130     #define PANIC_IF_FALSE( a ) if ( !( a ) )\
       
   131             TracePanicFunc( TPtrC8( ( TText8* ) __FILE__), __LINE__ )
       
   132 
       
   133     #define PANIC_IF_TRUE( a ) if ( ( a ) )\
       
   134             TracePanicFunc( TPtrC8( ( TText8* ) __FILE__), __LINE__ )
       
   135 
       
   136     #define PANIC_ALWAYS\
       
   137             TracePanicFunc( TPtrC8( ( TText8* ) __FILE__), __LINE__ )
       
   138 
       
   139     // -----------------------------------------------------------------------------
       
   140     // COMPONENT_TRACE_FLAG
       
   141     // -----------------------------------------------------------------------------
       
   142     #ifdef COMPONENT_TRACE_FLAG
       
   143 
       
   144         #define COMPONENT_TRACE_THIS_FILE\
       
   145             ThisFileFunc( TPtrC8( ( TText8* ) __FILE__), __LINE__ )
       
   146 
       
   147         #define COM_TRACE_( AAA ) do\
       
   148             { _LIT( logStr, AAA ); RDebug::Print( logStr ); } while ( 0 )
       
   149 
       
   150         #define COM_TRACE_1( AAA, BBB ) do\
       
   151              { _LIT( logStr, AAA ); RDebug::Print( logStr, BBB ); } while ( 0 )
       
   152 
       
   153         #define COM_TRACE_2( AAA, BBB, CCC ) do\
       
   154              { _LIT( logStr, AAA ); RDebug::Print( logStr, BBB, CCC ); } while ( 0 )
       
   155 
       
   156         #define COM_TRACE_3( AAA, BBB, CCC, DDD ) do\
       
   157              { _LIT( logStr, AAA ); RDebug::Print( logStr, BBB, CCC, DDD ); } while ( 0 )
       
   158 
       
   159         #define COM_TRACE_4( AAA, BBB, CCC, DDD, EEE ) do\
       
   160              { _LIT( logStr, AAA ); RDebug::Print( logStr, BBB, CCC, DDD, EEE ); } while ( 0 )
       
   161 
       
   162         #define COM_TRACE_RAW_( AAA ) do\
       
   163             { RDebug::RawPrint( AAA ); } while ( 0 )
       
   164             
       
   165         #define COM_TRACE_RAW_1( AAA, BBB ) do\
       
   166              { _LIT( logStr, AAA ); TBuf<KTraceMaxSize> buffer; buffer.Append( logStr ); buffer.Append( BBB );\
       
   167              RDebug::RawPrint( buffer ); } while ( 0 )
       
   168         
       
   169     #else
       
   170 
       
   171         #define COMPONENT_TRACE_THIS_FILE
       
   172 
       
   173         #define COM_TRACE_( AAA )
       
   174         #define COM_TRACE_1( AAA, BBB )
       
   175         #define COM_TRACE_2( AAA, BBB, CCC )
       
   176         #define COM_TRACE_3( AAA, BBB, CCC, DDD )
       
   177         #define COM_TRACE_4( AAA, BBB, CCC, DDD, EEE )
       
   178         #define COM_TRACE_RAW_( AAA )
       
   179         #define COM_TRACE_RAW_1( AAA, BBB )
       
   180 
       
   181     #endif // COMPONENT_TRACE_FLAG
       
   182 
       
   183     #define TRACE_ASSERT( a ) if ( !( a ) )\
       
   184             TraceAssertFunc( TPtrC8( ( TText8* ) __FILE__), __LINE__ )
       
   185 
       
   186     #define TRACE_ASSERT_RETURN( a ) if ( !( ( a ) == KErrNone ) )\
       
   187             TraceAssertFunc( TPtrC8( ( TText8* ) __FILE__), __LINE__ )
       
   188 
       
   189     #define TRACE_ASSERT_ALWAYS\
       
   190             TraceAssertFunc( TPtrC8( ( TText8* ) __FILE__ ), __LINE__ )
       
   191 
       
   192     // -----------------------------------------------------------------------------
       
   193     // API_TRACE_FLAG
       
   194     // -----------------------------------------------------------------------------
       
   195     #ifdef API_TRACE_FLAG
       
   196 
       
   197         #define API_TRACE_( AAA ) do\
       
   198             { _LIT( logStr, AAA ); RDebug::Print( logStr ); } while ( 0 )
       
   199 
       
   200         #define API_TRACE_1( AAA, BBB ) do\
       
   201              { _LIT( logStr, AAA ); RDebug::Print( logStr, BBB ); } while ( 0 )
       
   202 
       
   203         #define API_TRACE_2( AAA, BBB, CCC ) do\
       
   204              { _LIT( logStr, AAA ); RDebug::Print( logStr, BBB, CCC ); } while ( 0 )
       
   205 
       
   206         #define API_TRACE_3( AAA, BBB, CCC, DDD ) do\
       
   207              { _LIT( logStr, AAA ); RDebug::Print( logStr, BBB, CCC, DDD ); } while ( 0 )
       
   208 
       
   209         #define API_TRACE_4( AAA, BBB, CCC, DDD, EEE ) do\
       
   210              { _LIT( logStr, AAA ); RDebug::Print( logStr, BBB, CCC, DDD, EEE ); } while ( 0 )
       
   211              
       
   212         #define API_TRACE_RAW_1( AAA, BBB ) do\
       
   213              { _LIT( logStr, AAA ); TBuf<KTraceMaxSize> buffer; buffer.Append( logStr ); buffer.Append( BBB );\
       
   214              RDebug::RawPrint( buffer ); } while ( 0 )
       
   215 
       
   216     #else
       
   217 
       
   218         #define API_TRACE_( AAA )
       
   219         #define API_TRACE_1( AAA, BBB )
       
   220         #define API_TRACE_2( AAA, BBB, CCC )
       
   221         #define API_TRACE_3( AAA, BBB, CCC, DDD )
       
   222         #define API_TRACE_4( AAA, BBB, CCC, DDD, EEE )
       
   223         #define API_TRACE_RAW_1( AAA, BBB )
       
   224 
       
   225     #endif // API_TRACE_FLAG
       
   226 
       
   227 #else // _DEBUG
       
   228 
       
   229     #define TRACE_ASSERT( a )
       
   230     #define TRACE_ASSERT_RETURN( a ) a
       
   231     #define TRACE_ASSERT_ALWAYS
       
   232 
       
   233     #define COM_TRACE_( AAA )
       
   234     #define COM_TRACE_1( AAA, BBB )
       
   235     #define COM_TRACE_2( AAA, BBB, CCC )
       
   236     #define COM_TRACE_3( AAA, BBB, CCC, DDD )
       
   237     #define COM_TRACE_4( AAA, BBB, CCC, DDD, EEE )
       
   238     #define COM_TRACE_RAW_( AAA )
       
   239     #define COM_TRACE_RAW_1( AAA, BBB )
       
   240 
       
   241     #define API_TRACE_( AAA )
       
   242     #define API_TRACE_1( AAA, BBB )
       
   243     #define API_TRACE_2( AAA, BBB, CCC )
       
   244     #define API_TRACE_3( AAA, BBB, CCC, DDD )
       
   245     #define API_TRACE_4( AAA, BBB, CCC, DDD, EEE )
       
   246     #define API_TRACE_RAW_1( AAA, BBB )
       
   247 
       
   248     #define COMPONENT_TRACE_THIS_FILE
       
   249 
       
   250     #define PANIC_IF_FALSE( a )
       
   251     #define PANIC_IF_TRUE( a )
       
   252     #define PANIC_ALWAYS
       
   253 
       
   254 #endif // _DEBUG
       
   255 
       
   256 #endif // PHONECMDHANDLER_DEBUG_H
       
   257 
       
   258 // End of File