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