bluetoothengine/btpbap/inc/debug.h
changeset 0 f63038272f30
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2007-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:  Logging definition
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef PRJ_LOGGING_H
       
    21 #define PRJ_LOGGING_H
       
    22 
       
    23 #include "debugconfig.h"
       
    24 
       
    25 #ifdef PRJ_ENABLE_TRACE
       
    26 
       
    27 #ifdef PRJ_FILE_TRACE
       
    28 #include <flogger.h>
       
    29 #else
       
    30 #include <e32debug.h>
       
    31 #endif
       
    32 
       
    33 const TInt KMaxLogLineLength = 512;
       
    34 
       
    35 #define KPRINTERROR        0x00000001 // Tracing level: error
       
    36 #define KPRINTINFO         0x00000002 // Tracing level: function trace
       
    37 #define KPRINTSTATE        0x00000004 // Tracing level: state machine info
       
    38 #define KPRINTWARNING      0x00000008 // Tracing level: warning
       
    39 
       
    40 const TInt KTraceMask = KPRINTERROR | KPRINTINFO | KPRINTSTATE | KPRINTWARNING;
       
    41 
       
    42 /**
       
    43  *  Owerflow handler for 16 bit descriptor 
       
    44  * 
       
    45  *  @since S60 S60 v3.2
       
    46  */
       
    47 NONSHARABLE_CLASS( TOverflowTruncate16 ) : public TDes16Overflow
       
    48     {
       
    49 public:
       
    50     void Overflow(TDes16& /*aDes*/) {}
       
    51     };
       
    52     
       
    53 /**
       
    54  *  Owerflow handler for 8bit descriptor 
       
    55  * 
       
    56  *  @since S60 S60 v3.2
       
    57  */
       
    58 NONSHARABLE_CLASS( TOverflowTruncate8 ) : public TDes8Overflow
       
    59     {
       
    60 public:
       
    61     void Overflow(TDes8& /*aDes*/) {}
       
    62     };
       
    63 
       
    64 /**
       
    65  * Log requested lines with serial logging or file logging
       
    66  *
       
    67  * @since S60 S60_3.2
       
    68  * @param aFmt a Data to be printed
       
    69  * @return None.
       
    70  */
       
    71 inline void Trace( TRefByValue<const TDesC16> aFmt, ... )
       
    72     {
       
    73     VA_LIST list;
       
    74     VA_START(list,aFmt);
       
    75 #ifdef PRJ_FILE_TRACE
       
    76     RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list );
       
    77 #else
       
    78     TBuf16<KMaxLogLineLength> theFinalString;
       
    79     theFinalString.Append( KTracePrefix16 );
       
    80     TOverflowTruncate16 overflow;
       
    81     theFinalString.AppendFormatList( aFmt, list, &overflow );
       
    82     RDebug::Print( theFinalString );
       
    83 #endif
       
    84     }
       
    85 
       
    86 
       
    87 /**
       
    88  * Log requested lines with serial logging or file logging
       
    89  *
       
    90  * @since S60 S60_3.2
       
    91  * @param aFmt a Data to be printed
       
    92  * @return None.
       
    93  */
       
    94 inline void Trace( TRefByValue<const TDesC8> aFmt, ... )
       
    95     {
       
    96     VA_LIST list;
       
    97     VA_START( list, aFmt );
       
    98 #ifdef PRJ_FILE_TRACE
       
    99     RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list );
       
   100 #else
       
   101     TOverflowTruncate8 overflow;
       
   102     TBuf8<KMaxLogLineLength> buf8;
       
   103     buf8.Append( KTracePrefix8 );
       
   104     buf8.AppendFormatList( aFmt, list, &overflow );
       
   105     TBuf16<KMaxLogLineLength> buf16( buf8.Length() );
       
   106     buf16.Copy(buf8);
       
   107     TRefByValue<const TDesC> tmpFmt( _L("%S") );
       
   108     RDebug::Print( tmpFmt, &buf16 );
       
   109 #endif
       
   110     }
       
   111 
       
   112 /**
       
   113  * Log panics
       
   114  *
       
   115  * @since S60 S60_3.2
       
   116  * @param aFile a File where panic happens
       
   117  * @param aLine a Line where panic happens
       
   118  * @param aPanicCode a Panic code
       
   119  * @param aPanicCategory a Panic category
       
   120  * @return None.
       
   121  */
       
   122 inline void TracePanic(
       
   123     char* aFile, 
       
   124     TInt aLine,
       
   125     TInt aPanicCode,
       
   126     const TDesC& aPanicCategory)
       
   127     {
       
   128     TPtrC8 fullFileName( (const TUint8*)aFile );
       
   129     TPtrC8 fileName( fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1 );
       
   130     TBuf8<KMaxLogLineLength> buf;
       
   131     buf.Append( KPanicPrefix8 );
       
   132     buf.AppendFormat( _L8("%d at line %d in file %S"), aPanicCode, aLine, &fileName );
       
   133     Trace( buf );
       
   134     User::Panic( aPanicCategory, aPanicCode ); 
       
   135     }
       
   136 
       
   137 /**
       
   138  * Log panics
       
   139  *
       
   140  * @since S60 S60_3.2
       
   141  * @param aFile a File where leave happens
       
   142  * @param aLine a Line where leave happens
       
   143  * @param aReason a Reason for leave 
       
   144  * @return None.
       
   145  */
       
   146 inline void TraceLeave( char* aFile, TInt aLine, TInt aReason )
       
   147     {
       
   148     TPtrC8 fullFileName( (const TUint8*)aFile );
       
   149     TPtrC8 fileName( fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1 );
       
   150     TBuf8<KMaxLogLineLength> buf;
       
   151     buf.Append( KLeavePrefix8 );
       
   152     buf.AppendFormat( _L8("%d at line %d in file %S"), aReason, aLine, &fileName );
       
   153     Trace( buf );
       
   154     User::LeaveIfError( aReason );
       
   155     }
       
   156 
       
   157 #define TRACE_INFO(p) {if(KTraceMask & KPRINTINFO) Trace p;}
       
   158 
       
   159 #define TRACE_ERROR(p) {if(KTraceMask & KPRINTERROR) Trace p;}
       
   160 
       
   161 #define TRACE_STATE(p) {if(KTraceMask & KPRINTSTATE) Trace p;}
       
   162 
       
   163 #define TRACE_WARNING(p) {if(KTraceMask & KPRINTWARNING) Trace p;}
       
   164 
       
   165 #define TRACE_INFO_SEG(p) {if(KTraceMask & KPRINTINFO) p;}
       
   166 
       
   167 #define TRACE_ASSERT(GUARD, CODE) {if (!(GUARD)) TracePanic( __FILE__, __LINE__, CODE, KPanicCategory); }
       
   168 
       
   169 #define PANIC(CODE) TracePanic( __FILE__, __LINE__, CODE, KPanicCategory )
       
   170 
       
   171 #define LEAVE_IF_ERROR(REASON) {if ( REASON ) TraceLeave( __FILE__, __LINE__, REASON );}
       
   172 
       
   173 #define LEAVE(REASON) {TraceLeave( __FILE__, __LINE__, REASON );}
       
   174 
       
   175 #define TRACE_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8( (TUint8*)__PRETTY_FUNCTION__ ); Trace( KFuncEntryFormat8, &ptr8 );}}
       
   176 
       
   177 #define TRACE_FUNC_ENTRY_THIS {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace( KFuncEntryThisFormat8, &ptr8, this );}}
       
   178 
       
   179 #define TRACE_FUNC_EXIT {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace( KFuncExitFormat8, &ptr8 );}}
       
   180 
       
   181 #define TRACE_FUNC {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8( (TUint8*)__PRETTY_FUNCTION__ ); Trace( KFuncFormat8, &ptr8 );}}
       
   182 
       
   183 #define TRACE_FUNC_THIS {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8( (TUint8*)__PRETTY_FUNCTION__ ); Trace( KFuncThisFormat8, &ptr8, this );}}
       
   184 
       
   185 #define RETURN_IF_ERR(ERR) {if( ERR ) { TPtrC8 ptr8((TUint8*)__FILE__ ); Trace( _L8(" RETURN %d at file %S line %d"), ERR, &ptr8, __LINE__ ); return ERR;}}
       
   186 
       
   187 #else // PRJ_ENABLE_TRACE not defined
       
   188 
       
   189 #define TRACE_INFO(p)
       
   190 
       
   191 #define TRACE_ERROR(p)
       
   192 
       
   193 #define TRACE_STATE(p)
       
   194 
       
   195 #define TRACE_WARNING(p)
       
   196 
       
   197 #define TRACE_INFO_SEG(p)
       
   198 
       
   199 #define TRACE_ASSERT(GUARD, CODE)
       
   200 
       
   201 #define PANIC(CODE) {User::Panic(KPanicCategory, CODE);}
       
   202 
       
   203 #define LEAVE_IF_ERROR(REASON) {static_cast<void>( User::LeaveIfError( REASON ) );}
       
   204 
       
   205 #define LEAVE(REASON) {static_cast<void>( User::Leave(REASON ) );}
       
   206 
       
   207 #define TRACE_FUNC_ENTRY
       
   208 
       
   209 #define TRACE_FUNC_ENTRY_THIS
       
   210 
       
   211 #define TRACE_FUNC_EXIT
       
   212 
       
   213 #define TRACE_FUNC
       
   214 
       
   215 #define TRACE_FUNC_THIS
       
   216 
       
   217 #define RETURN_IF_ERR( ERR ) {if( ERR ) return ERR;}
       
   218 #endif // PRJ_ENABLE_TRACE
       
   219 
       
   220 #endif // PRJ_LOGGING_H