localconnectivityservice/headset/hidremconbearer/inc/debug.h
branchRCL_3
changeset 20 4a793f564d72
parent 19 0aa8cc770c8a
child 21 74aa6861c87d
equal deleted inserted replaced
19:0aa8cc770c8a 20:4a793f564d72
     1 /*
       
     2 * Copyright (c) 2006-2009 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 #ifndef DEBUG_H
       
    19 #define DEBUG_H
       
    20 
       
    21 #include "debugconfig.h"
       
    22 
       
    23 #ifdef PRJ_ENABLE_TRACE
       
    24 
       
    25 #ifdef PRJ_FILE_TRACE
       
    26 #include <flogger.h>
       
    27 #else
       
    28 #include <e32debug.h>
       
    29 #endif
       
    30 
       
    31 const TInt KMaxLogLineLength = 512;
       
    32 
       
    33 #define KPRINTERROR        0x00000001 // Tracing level: error
       
    34 #define KPRINTINFO        0x00000002 // Tracing level: function trace
       
    35 #define KPRINTSTATE        0x00000004 // Tracing level: state machine info
       
    36 #define KPRINTWARNING   0x00000008 // Tracing level: warning
       
    37 
       
    38 const TInt KTraceMask = KPRINTERROR | KPRINTINFO | KPRINTSTATE | KPRINTWARNING;
       
    39 
       
    40 NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow
       
    41     {
       
    42 public:
       
    43     void Overflow(TDes16& /*aDes*/) {}
       
    44     };
       
    45 
       
    46 NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow
       
    47     {
       
    48 public:
       
    49     void Overflow(TDes8& /*aDes*/) {}
       
    50     };
       
    51 
       
    52 inline void Trace(TRefByValue<const TDesC16> aFmt, ...)
       
    53     {
       
    54     VA_LIST list;
       
    55     VA_START(list,aFmt);
       
    56 #ifdef PRJ_FILE_TRACE
       
    57     RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
       
    58 #else
       
    59     TBuf16<KMaxLogLineLength> theFinalString;
       
    60     theFinalString.Append(KTracePrefix16);
       
    61     TOverflowTruncate16 overflow;
       
    62     theFinalString.AppendFormatList(aFmt,list,&overflow);
       
    63     RDebug::Print(theFinalString);
       
    64 #endif
       
    65     }
       
    66 
       
    67 inline void Trace(TRefByValue<const TDesC8> aFmt, ...)
       
    68     {
       
    69     VA_LIST list;
       
    70     VA_START(list, aFmt);
       
    71 #ifdef PRJ_FILE_TRACE
       
    72     RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
       
    73 #else
       
    74     TOverflowTruncate8 overflow;
       
    75     TBuf8<KMaxLogLineLength> buf8;
       
    76     buf8.Append(KTracePrefix8);
       
    77     buf8.AppendFormatList(aFmt, list, &overflow);
       
    78     TBuf16<KMaxLogLineLength> buf16(buf8.Length());
       
    79     buf16.Copy(buf8);
       
    80     TRefByValue<const TDesC> tmpFmt(_L("%S"));
       
    81     RDebug::Print(tmpFmt, &buf16);
       
    82 #endif
       
    83     }
       
    84 
       
    85 inline void TracePanic(
       
    86     char* aFile, 
       
    87     TInt aLine,
       
    88     TInt aPanicCode,
       
    89     const TDesC& aPanicCategory)
       
    90     {
       
    91     TPtrC8 fullFileName((const TUint8*)aFile);
       
    92     TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1);
       
    93     TBuf8<KMaxLogLineLength> buf;
       
    94     buf.Append(KPanicPrefix8);
       
    95     buf.AppendFormat(_L8("%d at line %d in file %S"), aPanicCode, aLine, &fileName);
       
    96     Trace(buf);
       
    97     User::Panic(aPanicCategory, aPanicCode); 
       
    98     }
       
    99 
       
   100 inline void TraceLeave(char* aFile, TInt aLine, TInt aReason)
       
   101     {
       
   102     TPtrC8 fullFileName((const TUint8*)aFile);
       
   103     TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1);
       
   104     TBuf8<KMaxLogLineLength> buf;
       
   105     buf.Append(KLeavePrefix8);
       
   106     buf.AppendFormat(_L8("%d at line %d in file %S"), aReason, aLine, &fileName);
       
   107     Trace(buf);
       
   108     User::LeaveIfError(aReason);
       
   109     }
       
   110 
       
   111 #define TRACE_INFO(p) {if(KTraceMask & KPRINTINFO) Trace p;}
       
   112 
       
   113 #define TRACE_ERROR(p) {if(KTraceMask & KPRINTERROR) Trace p;}
       
   114 
       
   115 #define TRACE_STATE(p) {if(KTraceMask & KPRINTSTATE) Trace p;}
       
   116 
       
   117 #define TRACE_WARNING(p) {if(KTraceMask & KPRINTWARNING) Trace p;}
       
   118 
       
   119 #define TRACE_INFO_SEG(p) {if(KTraceMask & KPRINTINFO) p;}
       
   120 
       
   121 #define TRACE_ASSERT(GUARD, CODE) {if (!(GUARD)) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory);}
       
   122 
       
   123 #define PANIC(CODE) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory)
       
   124 
       
   125 #define LEAVE_IF_ERROR(REASON) {if (REASON) TraceLeave(__FILE__, __LINE__, REASON);}
       
   126 
       
   127 #define LEAVE(REASON) {TraceLeave(__FILE__, __LINE__, REASON);}
       
   128 
       
   129 #define TRACE_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryFormat8, &ptr8);}}
       
   130 
       
   131 #define TRACE_FUNC_ENTRY_THIS {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryThisFormat8, &ptr8, this);}}
       
   132 
       
   133 #define TRACE_FUNC_EXIT {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncExitFormat8, &ptr8);}}
       
   134 
       
   135 #define TRACE_FUNC {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncFormat8, &ptr8);}}
       
   136 
       
   137 #define TRACE_FUNC_THIS {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncThisFormat8, &ptr8, this);}}
       
   138 
       
   139 #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;}}
       
   140 
       
   141 #else // PRJ_ENABLE_TRACE not defined
       
   142 
       
   143 #define TRACE_INFO(p)
       
   144 
       
   145 #define TRACE_ERROR(p)
       
   146 
       
   147 #define TRACE_STATE(p)
       
   148 
       
   149 #define TRACE_WARNING(p)
       
   150 
       
   151 #define TRACE_INFO_SEG(p)
       
   152 
       
   153 #define TRACE_ASSERT(GUARD, CODE)
       
   154 
       
   155 #define PANIC(CODE) {User::Panic(KPanicCategory, CODE);}
       
   156 
       
   157 #define LEAVE_IF_ERROR(REASON) {static_cast<void>(User::LeaveIfError(REASON));}
       
   158 
       
   159 #define LEAVE(REASON) {static_cast<void>(User::Leave(REASON));}
       
   160 
       
   161 #define TRACE_FUNC_ENTRY
       
   162 
       
   163 #define TRACE_FUNC_ENTRY_THIS
       
   164 
       
   165 #define TRACE_FUNC_EXIT
       
   166 
       
   167 #define TRACE_FUNC
       
   168 
       
   169 #define TRACE_FUNC_THIS
       
   170 
       
   171 #define RETURN_IF_ERR(ERR) {if(ERR) return ERR;}
       
   172 #endif // PRJ_ENABLE_TRACE
       
   173 
       
   174 #endif // PRJ_LOGGING_H