bluetoothengine/bteng/inc/debug.h
changeset 0 f63038272f30
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2006 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:  This file defines logging macros for bteng
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef BTENG_DEBUG_H
       
    21 #define BTENG_DEBUG_H
       
    22 
       
    23 
       
    24 #include "prjconfig.h"
       
    25 #include <bttypes.h>
       
    26 #ifdef PRJ_ENABLE_TRACE
       
    27 
       
    28 #ifdef PRJ_FILE_TRACE
       
    29 #include <flogger.h>
       
    30 #else   //PRJ_FILE_TRACE
       
    31 #include <e32debug.h>
       
    32 #endif  PRJ_FILE_TRACE
       
    33 
       
    34 
       
    35 /**
       
    36  * Tracing levels definitions.
       
    37  * This enables tracing of different levels of information.
       
    38  */
       
    39 _LIT( KBTEngLogFile, "btenglog.txt" );  // Log file
       
    40 _LIT( KBTEngLogDir, "bt" );             // Log file location
       
    41 
       
    42 
       
    43 // Print options:
       
    44 #define KPRINTERROR	 0x00000001         // Print error
       
    45 #define KPRINTFTRACE 0x00000002         // Print function trace
       
    46 const TInt KBTEngDebugMask = 0x00000001 | 0x00000002;
       
    47 
       
    48 
       
    49 /**
       
    50  * Handlers below are used for formatting debug prints,
       
    51  * to trucate rather than panic the caller.
       
    52  */
       
    53 NONSHARABLE_CLASS( TBTEngOverflowTruncate8 ) : public TDes8Overflow
       
    54     {
       
    55 public:
       
    56     void Overflow( TDes8& /*aDes*/ ) {}
       
    57     };
       
    58 
       
    59 
       
    60 NONSHARABLE_CLASS( TBTEngOverflowTruncate16 ) : public TDes16Overflow
       
    61     {
       
    62 public:
       
    63     void Overflow( TDes16& /*aDes*/ ) {}
       
    64     };
       
    65 
       
    66 
       
    67 inline void DebugPrint( TRefByValue<const TDesC8> aFmt, ... )
       
    68     {
       
    69     VA_LIST list;
       
    70     VA_START( list, aFmt );
       
    71 #ifdef PRJ_FILE_TRACE
       
    72     RFileLogger::WriteFormat( KBTEngLogDir, KBTEngLogFile, EFileLoggingModeAppend, aFmt, list);
       
    73 #ifdef MEMTRACE
       
    74     TInt size;
       
    75     User::Heap().AllocSize( size );
       
    76     RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, _L( "[BTEng]\t Memory usage: %d; high: %d" ), size, User::Heap().Size() );
       
    77 #endif  // MEMTRACE
       
    78 #else   // PRJ_FILE_TRACE
       
    79     TBuf8<0x100> logString;
       
    80     TBTEngOverflowTruncate8 overflow;
       
    81     logString.AppendFormatList( aFmt, list, &overflow );
       
    82     TBuf16<0x100> buf16;
       
    83     buf16.Copy( logString );
       
    84     TRefByValue<const TDesC16> tmpFmt( _L( "%S" ) );
       
    85     RDebug::Print( tmpFmt, &buf16 );
       
    86 #endif  // PRJ_FILE_TRACE
       
    87     }
       
    88 
       
    89 
       
    90 inline void DebugPrint( TRefByValue<const TDesC16> aFmt, ... )
       
    91     {
       
    92     VA_LIST list;
       
    93     VA_START( list, aFmt );
       
    94 #ifdef PRJ_FILE_TRACE
       
    95     RFileLogger::WriteFormat( KBTEngLogDir, KBTEngLogFile, EFileLoggingModeAppend, aFmt, list );
       
    96 #ifdef MEMTRACE
       
    97     TInt size;
       
    98     User::Heap().AllocSize( size );
       
    99     RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, _L( "[BTEng]\t Memory usage: %d; high: %d" ), size, User::Heap().Size() );
       
   100 #endif  // MEMTRACE
       
   101 #else   // PRJ_FILE_TRACE
       
   102     TBuf16<0x100> logString;
       
   103     TBTEngOverflowTruncate16 overflow;
       
   104     logString.AppendFormatList( aFmt, list, &overflow );
       
   105     RDebug::Print( logString );
       
   106 #endif   // PRJ_FILE_TRACE
       
   107     }
       
   108 
       
   109 
       
   110 inline TBuf8<0x100> DebugFormat( TRefByValue<const TDesC16> aFmt, ... )
       
   111     {
       
   112     VA_LIST list;
       
   113     VA_START( list, aFmt );
       
   114     TBuf<0x100> buf;
       
   115     TBTEngOverflowTruncate16 overflow;
       
   116     buf.AppendFormatList( aFmt, list, &overflow );
       
   117     TBuf8<0x100> buf8;
       
   118     buf8.Copy( buf );
       
   119     return buf8;
       
   120     }
       
   121 
       
   122 
       
   123 inline void DebugPrintToHex( const TDesC8& aDes )
       
   124     {
       
   125     for( TInt i = 0; i < aDes.Length(); ++i )
       
   126         {
       
   127         DebugPrint( _L( "[BTENG]\t %02x" ), aDes[i] );
       
   128         }
       
   129     }
       
   130 
       
   131 inline void DebugPrintBDAddr(const TBTDevAddr& aAddr)
       
   132     {
       
   133     TBuf<16> addrdes;
       
   134     aAddr.GetReadable(addrdes);
       
   135     DebugPrint(_L("[BTENG]\t BD addr %S") , &addrdes);   
       
   136     }
       
   137 
       
   138 _LIT( KTracePrefix, "[BTENG]\t " );
       
   139 _LIT8( KFuncEntryFormat8, "[BTENG]\t %S >>" );
       
   140 _LIT8( KFuncEntryArgFormat8, "[BTENG]\t %S >> %S" );
       
   141 _LIT8( KFuncExitFormat8, "[BTENG]\t %S <<" );
       
   142 _LIT8( KFuncExitResFormat8, "[BTENG]\t %S << %S" );
       
   143 
       
   144 
       
   145 #define TRACE_INFO( a ) { if( KBTEngDebugMask & KPRINTFTRACE ) DebugPrint a; }
       
   146 
       
   147 #define TRACE_ERROR( a ) { if( KBTEngDebugMask & KPRINTERROR ) DebugPrint a; }
       
   148 
       
   149 #define TRACE_FUNC_ENTRY { if( KBTEngDebugMask & KPRINTFTRACE ) { \
       
   150                                 TPtrC8 ptr( (TUint8*) __PRETTY_FUNCTION__ ); \
       
   151                                 DebugPrint( KFuncEntryFormat8, &ptr ); } }
       
   152 
       
   153 
       
   154 #define TRACE_FUNC_EXIT { if( KBTEngDebugMask & KPRINTFTRACE ) { \
       
   155                                 TPtrC8 ptr( (TUint8*) __PRETTY_FUNCTION__ ); \
       
   156                                 DebugPrint( KFuncExitFormat8, &ptr ); } }
       
   157 
       
   158 
       
   159 #define TRACE_FUNC_ARG( a ) { if( KBTEngDebugMask & KPRINTFTRACE ) { \
       
   160                                 TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \
       
   161                                 TPtrC8 arg( DebugFormat a ); \
       
   162                                 DebugPrint( KFuncEntryArgFormat8, &func, &arg ); } }
       
   163 
       
   164 
       
   165 #define TRACE_FUNC_RES( a ) { if( KBTEngDebugMask & KPRINTFTRACE ) { \
       
   166                                 TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \
       
   167                                 TPtrC8 res( DebugFormat a ); \
       
   168                                 DebugPrint( KFuncExitResFormat8, &func, &res ); } }
       
   169 
       
   170 #define TRACE_BDADDR( a ) { if( KBTEngDebugMask & KPRINTFTRACE ) DebugPrintBDAddr(a); }
       
   171 
       
   172 #else // PRJ_ENABLE_TRACE
       
   173 
       
   174 #define TRACE_INFO( a )
       
   175 
       
   176 #define TRACE_ERROR( a )
       
   177 
       
   178 #define TRACE_FUNC_ENTRY
       
   179 
       
   180 #define TRACE_FUNC_EXIT
       
   181 
       
   182 #define TRACE_FUNC_ARG( a )
       
   183 
       
   184 #define TRACE_FUNC_RES( a )
       
   185 
       
   186 #define TRACE_BDADDR( a )
       
   187 
       
   188 #endif // PRJ_ENABLE_TRACE
       
   189 
       
   190 #endif // BTENG_DEBUG_H