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