First public contribution.
1 // Copyright (c) 1997-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __DEBUGLOG_H__
17 #define __DEBUGLOG_H__
19 #pragma warning( disable : 4710 ) //function abc not expanded
21 #include "../SERVER/w32cmd.h"
23 typedef TBuf<32> TShortBuf;
24 typedef TBuf<64> TLongBuf;
26 enum {LogTBufSize=0xA0};
29 class TDebugLogOverflow : public TDes16Overflow
32 inline TDebugLogOverflow();
34 inline TBool IsError();
35 //Pure virtual function from TDesNnOverflow
36 void Overflow(TDes &aDes);
44 enum {ENewClientClass=0x9999};
49 TWsWinCmdUnion window;
52 TWsAnimDllCmdUnion anim;
54 TDesC &CommandBuf(TInt aApp);
55 TDesC &Command(TInt aClass, TInt aOpcode, const TAny *aCmdData, TInt aHandle);
56 TDesC &CommandReply(TInt aData);
57 TDesC &CommandReplyBuf(const TDesC8 &aDes);
58 TDesC &CommandReplyBuf(const TDesC16 &aDes);
59 TDesC &NewClient(TUint aConnectionHandle);
60 TDesC &SignalEvent(TInt aApp);
61 TDesC &Panic(TInt aApp, TInt aReason);
62 TDesC &MiscMessage(const TDesC &aFormat,TInt aParam);
67 void UnKnownOpcode(TBuf<LogTBufSize> &aText, TInt aOpcode);
68 void UnKnownReplyBuf(TBuf<LogTBufSize> &aText, TInt aOpcode);
69 void AppendPoint(TBuf<LogTBufSize> &aText, const TDesC8 *aReplyDes8);
70 void AppendRect(TBuf<LogTBufSize> &aText, const TDesC8 *aReplyDes8);
71 void AppendDesc(TBuf<LogTBufSize> &aText, const TDesC8 *aReplyDes8);
72 void AppendDesc(TBuf<LogTBufSize> &aText, const TDesC16 *aReplyDes16);
73 void decodeWindow(TBuf<LogTBufSize> &aText,TInt aOpcode,const TAny *aCmdData);
74 void DecodeWindowGroup(TBuf<LogTBufSize> &aText, TInt aOpcode, const TAny *aCmdData, TInt aHandle);
75 void DecodeClient(TBuf<LogTBufSize> &aText, TInt aOpcode, const TAny *aCmdData, TInt aHandle);
76 void DecodeWindow(TBuf<LogTBufSize> &aText, TInt aOpcode, const TAny *aCmdData, TInt aHandle);
77 void DecodeGc(TBuf<LogTBufSize> &aText, TInt aOpcode, const TAny *aCmdData, TInt aHandle);
78 void DecodeGc1(TBuf<LogTBufSize> &aText, TInt aOpcode, const TAny *aCmdData);
79 void DecodeGc2(TBuf<LogTBufSize> &aText, TInt aOpcode, const TAny *aCmdData);
80 void DecodeGc3(TBuf<LogTBufSize> &aText, TInt aOpcode, const TAny *aCmdData);
81 void DecodeScreenDevice(TBuf<LogTBufSize> &aText, TInt aOpcode, const TAny *aCmdData, TInt aHandle);
82 void DecodeAnimDll(TBuf<LogTBufSize> &aText, TInt aOpcode, const TAny *aCmdData, TInt aHandle);
83 void DecodeSpriteBase(TBuf<LogTBufSize> &aText, TInt aOpcode, const TAny *aCmdData, TInt aHandle);
84 void DecodeBitmap(TBuf<LogTBufSize> &aText, TInt aOpcode, const TAny *aCmdData, TInt aHandle);
85 void DecodeDirect(TBuf<LogTBufSize> &aText, TInt aOpcode, const TAny *aCmdData, TInt aHandle);
86 void DecodeClick(TBuf<LogTBufSize> &aText, TInt aOpcode, const TAny *aCmdData, TInt aHandle);
87 void ReplyBufWindowGroup(TBuf<LogTBufSize> &aText, TInt aOpcode, const TDesC8 *aReplyDes8, const TDesC *aReplyDesText);
88 void ReplyBufWindow(TBuf<LogTBufSize> &aText, TInt aOpcode, const TDesC8 *aReplyDes8, const TDesC *aReplyDesText);
89 void ReplyBufClient(TBuf<LogTBufSize> &aText, TInt aOpcode, const TDesC8 *aReplyDes8, const TDesC *aReplyDesText);
90 void ReplyBufScreenDevice(TBuf<LogTBufSize> &aText, TInt aOpcode, const TDesC8 *aReplyDes8, const TDesC *aReplyDesText);
91 TDesC &commandDetails(TInt aClass, TInt aOpcode, const TAny *aCmdData, TInt aHandle);
92 TDesC &eventDetails(const TWsEvent *aWsEvent);
93 TDesC &eventDetails(const TRawEvent *aEvent);
94 TDesC &replyBufDetails(TInt aClass, TInt aOpcode, const TDesC8 *aReplyDes8, const TDesC *aReplyDesText);
96 TBuf<LogTBufSize> iEventDetailsText;
97 TBuf<LogTBufSize> iCommandDetailsText;
98 TBuf<LogTBufSize> iText;
101 TInt iRequestFuncClass;
104 TDebugLogOverflow iOverflowHandler;
107 class TDebugLogTextHandler
115 static void Append(TDes &aBuf1, const TDesC &aBuf2);
116 static void TestAppend();
117 static TBuf<20> FormatBool(TBool aBool);
118 static TBuf<32> FormatPoint(const TPoint &aPoint);
119 static TBuf<32> FormatSize(const TSize &aSize);
120 static TBuf<64> FormatRect(const TRect &aRect);
121 static TBuf<40> FormatRgb(const TRgb &aRgb);
122 static TBuf<20> PointerEventType(TPointerEvent::TType aType);
123 static TBuf<LogTBufSize> FormatArray(TArrayType aArrayType, const TUint8 *aArrayPtr, TUint aNumElems);
125 static TBuf<0x20> formatArrayElement(TArrayType aArrayType, const TUint8 *aArrayPtr);
126 static void panic(TInt aReason);
129 class CDebugLogDevice : public CBase
132 virtual void ConstructL(TBool aIsFirst, TDesC &aParams)=0;
133 virtual void WriteToLogL(const TDesC &aDes, const TDesC &aDes2)=0;
134 virtual void WriteToLog8L(const TDesC8 &aDes, const TDesC8 &aDes2)=0;
137 class CDebugLog: public CDebugLogBase
140 enum {KNumProfiles=10};
142 IMPORT_C CDebugLog(CDebugLogDevice *aDevice);
144 IMPORT_C void ConstructL(TBool aIsFirst, TDesC &aParams);
145 //Pure virtual functions from CDebugLogBase
146 void CommandBuf(TInt aApp);
147 void Command(TInt aClass, TInt aOpcode, const TAny *aCmdData, TInt aHandle);
148 void NewClient(TUint aConnectionHandle);
149 void Reply(TInt aData);
150 void ReplyBuf(const TDesC8 &aDes);
151 void ReplyBuf(const TDesC16 &aDes);
152 void SignalEvent(TInt aApp);
153 void Panic(TInt aApp, TInt aReason);
154 void MiscMessage(TInt aPriority,const TDesC &aFmt,TInt aParam=0);
156 void SetLoggingLevel(TInt aLevel);
157 void IniFileSettingRead(TInt aScreen, const TDesC& aVarName, TBool aFound, const TDesC& aResult);
160 void AppendProfileNum(TDes &aDes, TInt aNum);
161 void AppendProfileCount(TDes &aDes, TInt aNum);
163 void WriteToLog(const TDesC &aDes,TInt aLevel=ELogEverything);
164 void MiscMessage(const TDesC &aFmt,TInt aParam=0);
167 CDebugLogDevice *iDevice;
168 TWsDecoder iWsDecoder;
173 TInt iLevel; //The current logging level
177 GLREF_C TInt hHandleToValue(TUint32 handle);
181 /*TDebugLogOverflow*/
182 inline TDebugLogOverflow::TDebugLogOverflow() :iError(EFalse)
184 inline void TDebugLogOverflow::Reset()
186 inline TBool TDebugLogOverflow::IsError()