usbclasses/usbphoneasmodem/classimplementation/atplugin/inc/pamplugindebug.h
changeset 0 1e05558e2206
child 89 3592750162a5
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // debug API definition for phone as modem at extension plugin
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef PAMPLUGINDEBUG_H
       
    19 #define PAMPLUGINDEBUG_H
       
    20 
       
    21 #include <e32base.h>
       
    22 #include "pamplugindebugconfig.h"
       
    23 
       
    24 #ifdef PRJ_ENABLE_TRACE
       
    25 
       
    26 #ifdef PRJ_FILE_TRACE
       
    27 #include <flogger.h>
       
    28 #else
       
    29 #include <e32debug.h>
       
    30 #endif
       
    31 
       
    32 NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow
       
    33     {
       
    34 public:
       
    35     void Overflow(TDes16& /*aDes*/) {}
       
    36     };
       
    37 
       
    38 NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow
       
    39     {
       
    40 public:
       
    41     void Overflow(TDes8& /*aDes*/) {}
       
    42     };
       
    43 
       
    44 inline void Trace(TRefByValue<const TDesC16> aFmt, ...)
       
    45     {
       
    46     VA_LIST list;
       
    47     VA_START(list,aFmt);
       
    48 #ifdef PRJ_FILE_TRACE
       
    49     RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
       
    50 #else
       
    51     TBuf16<KMaxLogLineLength> theFinalString;
       
    52     theFinalString.Append(KTracePrefix16);
       
    53     TOverflowTruncate16 overflow;
       
    54     theFinalString.AppendFormatList(aFmt,list,&overflow);
       
    55     RDebug::Print(theFinalString);
       
    56 #endif
       
    57     }
       
    58 
       
    59 inline void Trace(TRefByValue<const TDesC8> aFmt, ...)
       
    60     {
       
    61     VA_LIST list;
       
    62     VA_START(list, aFmt);
       
    63 #ifdef PRJ_FILE_TRACE
       
    64     RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
       
    65 #else
       
    66     TOverflowTruncate8 overflow;
       
    67     TBuf8<KMaxLogLineLength> buf8;
       
    68     buf8.Append(KTracePrefix8);
       
    69     buf8.AppendFormatList(aFmt, list, &overflow);
       
    70     TBuf16<KMaxLogLineLength> buf16(buf8.Length());
       
    71     buf16.Copy(buf8);
       
    72     TRefByValue<const TDesC> tmpFmt(_L("%S"));
       
    73     RDebug::Print(tmpFmt, &buf16);
       
    74 #endif
       
    75     }
       
    76 
       
    77 inline void TracePanic(
       
    78     char* aFile, 
       
    79     TInt aLine,
       
    80     TInt aPanicCode,
       
    81     const TDesC& aPanicCategory)
       
    82     {
       
    83     TPtrC8 fullFileName((const TUint8*)aFile);
       
    84     TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1);
       
    85     TBuf8<KMaxLogLineLength> buf;
       
    86     buf.Append(KPanicPrefix8);
       
    87     buf.AppendFormat(_L8("%d at line %d in file %S"), aPanicCode, aLine, &fileName);
       
    88     Trace(buf);
       
    89     User::Panic(aPanicCategory, aPanicCode); 
       
    90     }
       
    91 
       
    92 inline void TraceLeave(char* aFile, TInt aLine, TInt aReason)
       
    93     {
       
    94     TPtrC8 fullFileName((const TUint8*)aFile);
       
    95     TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1);
       
    96     TBuf8<KMaxLogLineLength> buf;
       
    97     buf.Append(KLeavePrefix8);
       
    98     buf.AppendFormat(_L8("%d at line %d in file %S"), aReason, aLine, &fileName);
       
    99     Trace(buf);
       
   100     User::Leave(aReason);
       
   101     }
       
   102 
       
   103 #define TRACE_INFO(p) {if(KTraceMask & KPRINTINFO) Trace p;}
       
   104 
       
   105 #define TRACE_ERROR(p) {if(KTraceMask & KPRINTERROR) Trace p;}
       
   106 
       
   107 #define TRACE_STATE(p) {if(KTraceMask & KPRINTSTATE) Trace p;}
       
   108 
       
   109 #define TRACE_WARNING(p) {if(KTraceMask & KPRINTWARNING) Trace p;}
       
   110 
       
   111 #define TRACE_INFO_SEG(p) {if(KTraceMask & KPRINTINFO) p;}
       
   112 
       
   113 #define TRACE_ASSERT(GUARD, CODE) {if (!(GUARD)) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory);}
       
   114 
       
   115 #define PANIC(CODE) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory)
       
   116 
       
   117 #define LEAVE_IF_ERROR(REASON) {if (REASON) TraceLeave(__FILE__, __LINE__, REASON);}
       
   118 
       
   119 #define LEAVE_IF_NULL(PTR) {if (!PTR) TraceLeave(__FILE__, __LINE__, PTR);}
       
   120 
       
   121 #define LEAVE(REASON) {TraceLeave(__FILE__, __LINE__, REASON);}
       
   122 
       
   123 #define TRACE_STATIC_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryFormat8, &ptr8);}}
       
   124 
       
   125 #define TRACE_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryThisFormat8, &ptr8, this);}}
       
   126 
       
   127 #define TRACE_FUNC_EXIT {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncExitFormat8, &ptr8);}}
       
   128 
       
   129 #define TRACE_STATIC_FUNC {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncFormat8, &ptr8);}}
       
   130 
       
   131 #define TRACE_FUNC {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncThisFormat8, &ptr8, this);}}
       
   132 
       
   133 #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;}}
       
   134 
       
   135 #else // PRJ_ENABLE_TRACE not defined
       
   136 
       
   137 #define TRACE_INFO(p)
       
   138 
       
   139 #define TRACE_ERROR(p)
       
   140 
       
   141 #define TRACE_STATE(p)
       
   142 
       
   143 #define TRACE_WARNING(p)
       
   144 
       
   145 #define TRACE_INFO_SEG(p)
       
   146 
       
   147 #define TRACE_ASSERT(GUARD, CODE)
       
   148 
       
   149 #define PANIC(CODE) {User::Panic(KPanicCategory, CODE);}
       
   150 
       
   151 #define LEAVE_IF_ERROR(REASON) {static_cast<void>(User::LeaveIfError(REASON));}
       
   152 
       
   153 #define LEAVE_IF_NULL(PTR) {static_cast<void>(User::LeaveIfNull(PTR));}
       
   154 
       
   155 #define LEAVE(REASON) {static_cast<void>(User::Leave(REASON));}
       
   156 
       
   157 #define TRACE_STATIC_FUNC_ENTRY
       
   158 
       
   159 #define TRACE_FUNC_ENTRY
       
   160 
       
   161 #define TRACE_FUNC_EXIT
       
   162 
       
   163 #define TRACE_STATIC_FUNC
       
   164 
       
   165 #define TRACE_FUNC
       
   166 
       
   167 #define RETURN_IF_ERR(ERR) {if(ERR) return ERR;}
       
   168 #endif // PRJ_ENABLE_TRACE
       
   169 
       
   170 #endif // PAMPLUGINDEBUG_H