usbclasses/usbphoneasmodem/classimplementation/inc/debug.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 // 
       
    15 // 
       
    16 
       
    17 
       
    18 #ifndef ATPLUGINDEBUG_H
       
    19 #define ATPLUGINDEBUG_H
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <flogger.h>
       
    23 #include <e32svr.h>
       
    24 
       
    25 
       
    26 _LIT(KLogFile,"usbmscfile.txt");
       
    27 _LIT(KLogDir,"usbmscfile");
       
    28 
       
    29 _LIT(KTracePrefix16, "[UsbMscFile] ");
       
    30 _LIT8(KTracePrefix8, "[UsbMscFile] ");
       
    31 _LIT8(KFuncFormat8, ">< %S");
       
    32 _LIT8(KFuncThisFormat8, ">< %S, [0x%08X]");
       
    33 _LIT8(KFuncEntryFormat8, "-> %S");
       
    34 _LIT8(KFuncEntryThisFormat8, "-> %S, [0x%08X]");
       
    35 _LIT8(KFuncExitFormat8, "<- %S");
       
    36 _LIT(KPanicCategory, "UsbMscFile");
       
    37 _LIT8(KPanicPrefix8, "PANIC code ");
       
    38 _LIT8(KLeavePrefix8, "LEAVE code ");
       
    39 
       
    40 #ifdef _DEBUG
       
    41 
       
    42 const TInt KMaxLogLineLength = 512;
       
    43 
       
    44 // Trace options
       
    45 #define KPRINTERROR		0x00000001 // Print error
       
    46 #define KPRINTINFO	    0x00000002 // Print function trace
       
    47 #define KPRINTSTATE		0x00000004 // Print state machine infos
       
    48 #define KPRINTWARNING   0x00000008 // Print warnings
       
    49 
       
    50 const TInt KTraceMask = KPRINTERROR | KPRINTINFO | KPRINTSTATE | KPRINTWARNING;
       
    51 
       
    52 NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow
       
    53 	{
       
    54 public:
       
    55 	void Overflow(TDes16& /*aDes*/) {}
       
    56 	};
       
    57 
       
    58 NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow
       
    59 	{
       
    60 public:
       
    61 	void Overflow(TDes8& /*aDes*/) {}
       
    62 	};
       
    63 
       
    64 inline void Trace(TRefByValue<const TDesC16> aFmt, ...)
       
    65     {
       
    66 	VA_LIST list;
       
    67 	VA_START(list,aFmt);
       
    68 #ifdef __WINS__
       
    69 #ifdef _DEBUG
       
    70     RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
       
    71 #endif
       
    72 #else
       
    73 	TBuf16<KMaxLogLineLength> theFinalString;
       
    74 	theFinalString.Append(KTracePrefix16);
       
    75 	TOverflowTruncate16 overflow;
       
    76 	theFinalString.AppendFormatList(aFmt,list,&overflow);
       
    77 	RDebug::Print(theFinalString);
       
    78 #endif
       
    79     }
       
    80 
       
    81 inline void Trace(TRefByValue<const TDesC8> aFmt, ...)
       
    82     {
       
    83     VA_LIST list;
       
    84     VA_START(list, aFmt);
       
    85 #ifdef __WINS__    
       
    86 #ifdef _DEBUG
       
    87     RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
       
    88 #endif
       
    89 #else
       
    90 	TOverflowTruncate8 overflow;
       
    91     TBuf8<KMaxLogLineLength> buf8;
       
    92     buf8.Append(KTracePrefix8);
       
    93 	buf8.AppendFormatList(aFmt, list, &overflow);
       
    94     TBuf16<KMaxLogLineLength> buf16(buf8.Length());
       
    95     buf16.Copy(buf8);
       
    96     TRefByValue<const TDesC> tmpFmt(_L("%S"));
       
    97     RDebug::Print(tmpFmt, &buf16);
       
    98 #endif
       
    99     }
       
   100 
       
   101 inline void TracePanic(
       
   102 	char* aFile, 
       
   103 	TInt aLine,
       
   104 	TInt aPanicCode,
       
   105 	const TDesC& aPanicCategory)
       
   106     {
       
   107 	TPtrC8 fullFileName((const TUint8*)aFile);
       
   108 	TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1);
       
   109 	TBuf8<KMaxLogLineLength> buf;
       
   110 	buf.Append(KPanicPrefix8);
       
   111 	buf.AppendFormat(_L8("%d at line %d in file %S"), aPanicCode, aLine, &fileName);
       
   112 	Trace(buf);
       
   113 	User::Panic(aPanicCategory, aPanicCode); 
       
   114     }
       
   115 
       
   116 inline void TraceLeave(char* aFile, TInt aLine, TInt aReason)
       
   117 	{
       
   118 	TPtrC8 fullFileName((const TUint8*)aFile);
       
   119 	TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1);
       
   120 	TBuf8<KMaxLogLineLength> buf;
       
   121 	buf.Append(KLeavePrefix8);
       
   122 	buf.AppendFormat(_L8("%d at line %d in file %S"), aReason, aLine, &fileName);
       
   123 	Trace(buf);
       
   124 	User::LeaveIfError(aReason);
       
   125 	}
       
   126 
       
   127 #define TRACE_INFO(p) {if(KTraceMask & KPRINTINFO) Trace p;}
       
   128 
       
   129 #define TRACE_ERROR(p) {if(KTraceMask & KPRINTERROR) Trace p;}
       
   130 
       
   131 #define TRACE_STATE(p) {if(KTraceMask & KPRINTSTATE) Trace p;}
       
   132 
       
   133 #define TRACE_WARNING(p) {if(KTraceMask & KPRINTWARNING) Trace p;}
       
   134 
       
   135 #define TRACE_INFO_SEG(p) {if(KTraceMask & KPRINTINFO) p;}
       
   136 
       
   137 #define TRACE_ASSERT(GUARD, CODE) {if (!(GUARD)) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory);}
       
   138 
       
   139 #define PANIC(CODE) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory)
       
   140 
       
   141 #define LEAVE_IF_ERROR(REASON) {if (REASON) TraceLeave(__FILE__, __LINE__, REASON);}
       
   142 
       
   143 #define LEAVE(REASON) TraceLeave(__FILE__, __LINE__, REASON)
       
   144 
       
   145 #define TRACE_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryFormat8, &ptr8);}}
       
   146 
       
   147 #define TRACE_FUNC_ENTRY_THIS {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryThisFormat8, &ptr8, this);}}
       
   148 
       
   149 #define	 TRACE_FUNC_EXIT {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncExitFormat8, &ptr8);}}
       
   150 
       
   151 #define TRACE_FUNC {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncFormat8, &ptr8);}}
       
   152 
       
   153 #define TRACE_FUNC_THIS {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncThisFormat8, &ptr8, this);}}
       
   154 
       
   155 #define RETURN_IF_ERR(ERR) {if(ERR) {Trace(_L8(" RETURN %d at file %S line %d"), ERR, &(TPtrC8((const TUint8*)__FILE__)), __LINE__); return ERR;}}
       
   156 
       
   157 #else // ! _DEBUG
       
   158 
       
   159 #define TRACE_INFO(p)
       
   160 
       
   161 #define TRACE_ERROR(p)
       
   162 
       
   163 #define TRACE_STATE(p)
       
   164 
       
   165 #define TRACE_WARNING(p)
       
   166 
       
   167 #define TRACE_INFO_SEG(p)
       
   168 
       
   169 #define TRACE_ASSERT(GUARD, CODE)
       
   170 
       
   171 #define PANIC(CODE) {User::Panic(KPanicCategory, CODE);}
       
   172 
       
   173 #define LEAVE_IF_ERROR(REASON) {static_cast<void>(User::LeaveIfError(REASON));}
       
   174 
       
   175 #define LEAVE(REASON) {static_cast<void>(User::Leave(REASON));}
       
   176 
       
   177 #define TRACE_FUNC_ENTRY
       
   178 
       
   179 #define TRACE_FUNC_ENTRY_THIS
       
   180 
       
   181 #define TRACE_FUNC_EXIT
       
   182 
       
   183 #define TRACE_FUNC
       
   184 
       
   185 #define TRACE_FUNC_THIS
       
   186 
       
   187 #define RETURN_IF_ERR(ERR) {if(ERR) return ERR;}
       
   188 #endif // _DEBUG
       
   189 
       
   190 #endif // ATPLUGINDEBUG_H
       
   191 
       
   192 // End of File