bluetoothengine/btaudioman/inc/debug.h
changeset 0 f63038272f30
child 6 6a29d5ad0713
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:  Logging definition
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef PRJ_LOGGING_H
       
    20 #define PRJ_LOGGING_H
       
    21 
       
    22 #include <e32base.h>
       
    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 NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow
       
    34     {
       
    35 public:
       
    36     void Overflow(TDes16& /*aDes*/) {}
       
    37     };
       
    38 
       
    39 NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow
       
    40     {
       
    41 public:
       
    42     void Overflow(TDes8& /*aDes*/) {}
       
    43     };
       
    44 
       
    45 inline void Trace(TRefByValue<const TDesC16> aFmt, ...)
       
    46     {
       
    47     VA_LIST list;
       
    48     VA_START(list,aFmt);
       
    49 #ifdef PRJ_FILE_TRACE
       
    50     RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
       
    51 #else
       
    52     RBuf16 theFinalString;
       
    53     theFinalString.Create(KMaxLogLineLength);
       
    54     theFinalString.Append(KTracePrefix16);
       
    55     TOverflowTruncate16 overflow;
       
    56     theFinalString.AppendFormatList(aFmt,list,&overflow);
       
    57     RDebug::Print(theFinalString);
       
    58     theFinalString.Close();
       
    59 #endif
       
    60     }
       
    61 
       
    62 inline void Trace(TRefByValue<const TDesC8> aFmt, ...)
       
    63     {
       
    64     VA_LIST list;
       
    65     VA_START(list, aFmt);
       
    66 #ifdef PRJ_FILE_TRACE
       
    67     RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
       
    68 #else
       
    69     TOverflowTruncate8 overflow; 
       
    70     RBuf8 buf8;
       
    71     buf8.Create(KMaxLogLineLength);
       
    72     buf8.Append(KTracePrefix8);
       
    73     buf8.AppendFormatList(aFmt, list, &overflow);
       
    74 
       
    75     RBuf16 buf16;
       
    76     buf16.Create(KMaxLogLineLength);
       
    77     buf16.Copy(buf8);
       
    78     TRefByValue<const TDesC> tmpFmt(_L("%S"));
       
    79     RDebug::Print(tmpFmt, &buf16);
       
    80     buf8.Close();         
       
    81     buf16.Close();
       
    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     RBuf8 buf;
       
    94     buf.Create(KMaxLogLineLength);
       
    95     buf.Append(KPanicPrefix8);
       
    96     buf.AppendFormat(_L8("%d at line %d in file %S"), aPanicCode, aLine, &fileName);
       
    97     Trace(buf);
       
    98     buf.Close(); 
       
    99     User::Panic(aPanicCategory, aPanicCode); 
       
   100     }
       
   101 
       
   102 inline void TraceLeave(char* aFile, TInt aLine, TInt aReason)
       
   103     {
       
   104     TPtrC8 fullFileName((const TUint8*)aFile);
       
   105     TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1);
       
   106     RBuf8 buf;
       
   107     buf.Create(KMaxLogLineLength);
       
   108     buf.Append(KLeavePrefix8);
       
   109     buf.AppendFormat(_L8("%d at line %d in file %S"), aReason, aLine, &fileName);
       
   110     Trace(buf);    
       
   111     buf.Close();
       
   112     User::Leave(aReason);
       
   113     }
       
   114 
       
   115 #define TRACE_INFO(p) {if(KTraceMask & KPRINTINFO) Trace p;}
       
   116 
       
   117 #define TRACE_ERROR(p) {if(KTraceMask & KPRINTERROR) Trace p;}
       
   118 
       
   119 #define TRACE_STATE(p) {if(KTraceMask & KPRINTSTATE) Trace p;}
       
   120 
       
   121 #define TRACE_WARNING(p) {if(KTraceMask & KPRINTWARNING) Trace p;}
       
   122 
       
   123 #define TRACE_INFO_SEG(p) {if(KTraceMask & KPRINTINFO) p;}
       
   124 
       
   125 #define TRACE_ASSERT(GUARD, CODE) {if (!(GUARD)) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory);}
       
   126 
       
   127 #define PANIC(CODE) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory)
       
   128 
       
   129 #define LEAVE_IF_ERROR(REASON) {if (REASON) TraceLeave(__FILE__, __LINE__, REASON);}
       
   130 
       
   131 #define LEAVE_IF_NULL(PTR) {if (!PTR) TraceLeave(__FILE__, __LINE__, KErrGeneral);}
       
   132 
       
   133 #define LEAVE(REASON) {TraceLeave(__FILE__, __LINE__, REASON);}
       
   134 
       
   135 #define TRACE_STATIC_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryFormat8, &ptr8);}}
       
   136 
       
   137 #define TRACE_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryThisFormat8, &ptr8, this);}}
       
   138 
       
   139 #define TRACE_FUNC_EXIT {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncExitFormat8, &ptr8);}}
       
   140 
       
   141 #define TRACE_STATIC_FUNC {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncFormat8, &ptr8);}}
       
   142 
       
   143 #define TRACE_FUNC {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncThisFormat8, &ptr8, this);}}
       
   144 
       
   145 #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;}}
       
   146 
       
   147 #else // PRJ_ENABLE_TRACE not defined
       
   148 
       
   149 #define TRACE_INFO(p)
       
   150 
       
   151 #define TRACE_ERROR(p)
       
   152 
       
   153 #define TRACE_STATE(p)
       
   154 
       
   155 #define TRACE_WARNING(p)
       
   156 
       
   157 #define TRACE_INFO_SEG(p)
       
   158 
       
   159 #define TRACE_ASSERT(GUARD, CODE)
       
   160 
       
   161 #define PANIC(CODE) {User::Panic(KPanicCategory, CODE);}
       
   162 
       
   163 #define LEAVE_IF_ERROR(REASON) {static_cast<void>(User::LeaveIfError(REASON));}
       
   164 
       
   165 #define LEAVE_IF_NULL(PTR) {static_cast<void>(User::LeaveIfNull(PTR));}
       
   166 
       
   167 #define LEAVE(REASON) {static_cast<void>(User::Leave(REASON));}
       
   168 
       
   169 #define TRACE_STATIC_FUNC_ENTRY
       
   170 
       
   171 #define TRACE_FUNC_ENTRY
       
   172 
       
   173 #define TRACE_FUNC_EXIT
       
   174 
       
   175 #define TRACE_STATIC_FUNC
       
   176 
       
   177 #define TRACE_FUNC
       
   178 
       
   179 #define RETURN_IF_ERR(ERR) {if(ERR) return ERR;}
       
   180 #endif // PRJ_ENABLE_TRACE
       
   181 
       
   182 #endif // PRJ_LOGGING_H