First public contribution.
1 // Copyright (c) 1995-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.
14 // Handles text for the window server debug-logger - platform independent
18 #include "../SERVER/w32cmd.h"
21 void TDebugLogTextHandler::Append(TDes &aBuf1, const TDesC &aBuf2)
23 if (aBuf1.Length()+aBuf2.Length()>aBuf1.MaxLength()-1)
25 TUint offset=aBuf1.Length();
26 aBuf1.SetLength(aBuf1.MaxLength()-3-1);
27 for (TInt i=offset; i<(aBuf1.MaxLength()-3-1); i++)
28 aBuf1[i]=aBuf2[i-offset];
35 void TDebugLogTextHandler::TestAppend()
38 TBuf<0x10> buf1=_L("123456789012345");
39 TBuf<0x10> buf2(KNullDesC);
41 TDebugLogTextHandler::Append(buf1, buf2);
42 __ASSERT_ALWAYS(buf1==_L("123456789012345"), panic(1));
43 TDebugLogTextHandler::Append(buf1, buf2);
44 __ASSERT_ALWAYS(buf1==_L("123456789012345"), panic(2));
46 buf1=_L("12345678901234");
47 TDebugLogTextHandler::Append(buf1, buf2);
48 __ASSERT_ALWAYS(buf1==_L("12345678901234"), panic(3));
49 TDebugLogTextHandler::Append(buf1, buf2);
50 __ASSERT_ALWAYS(buf1==_L("12345678901234"), panic(4));
52 buf1=_L("1234567890123");
53 buf2=_L("**********");
54 TDebugLogTextHandler::Append(buf1, buf2);
55 __ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(5));
56 TDebugLogTextHandler::Append(buf1, buf2);
57 __ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(6));
59 buf1=_L("123456789012");
60 TDebugLogTextHandler::Append(buf1, buf2);
61 __ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(7));
62 TDebugLogTextHandler::Append(buf1, buf2);
63 __ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(8));
65 buf1=_L("12345678901");
66 TDebugLogTextHandler::Append(buf1, buf2);
67 __ASSERT_ALWAYS(buf1==_L("12345678901*..."), panic(9));
68 TDebugLogTextHandler::Append(buf1, buf2);
69 __ASSERT_ALWAYS(buf1==_L("12345678901*..."), panic(10));
71 buf1=_L("1234567890");
73 TDebugLogTextHandler::Append(buf1, buf2);
74 __ASSERT_ALWAYS(buf1==_L("1234567890*"), panic(11));
75 TDebugLogTextHandler::Append(buf1, buf2);
76 __ASSERT_ALWAYS(buf1==_L("1234567890**"), panic(12));
77 TDebugLogTextHandler::Append(buf1, buf2);
78 __ASSERT_ALWAYS(buf1==_L("1234567890***"), panic(12));
79 TDebugLogTextHandler::Append(buf1, buf2);
80 __ASSERT_ALWAYS(buf1==_L("1234567890****"), panic(12));
81 TDebugLogTextHandler::Append(buf1, buf2);
82 __ASSERT_ALWAYS(buf1==_L("1234567890*****"), panic(12));
83 TDebugLogTextHandler::Append(buf1, buf2);
84 __ASSERT_ALWAYS(buf1==_L("1234567890**..."), panic(12));
88 TBuf<20> TDebugLogTextHandler::FormatBool(TBool aBool)
92 text.Append(_L("ETrue"));
94 text.Append(_L("EFalse"));
98 TBuf<32> TDebugLogTextHandler::FormatPoint(const TPoint &aPoint)
101 text.Format(_L("{%d,%d}"), aPoint.iX, aPoint.iY);
105 TBuf<32> TDebugLogTextHandler::FormatSize(const TSize &aSize)
108 text.Format(_L("{%d,%d}"), aSize.iWidth, aSize.iHeight);
112 TBuf<64> TDebugLogTextHandler::FormatRect(const TRect &aRect)
115 text.Format(_L("{{%d,%d},{%d,%d}}"), aRect.iTl.iX, aRect.iTl.iY, aRect.iBr.iX, aRect.iBr.iY);
119 TBuf<40> TDebugLogTextHandler::FormatRgb(const TRgb &aRgb)
122 text.Format(_L("{%u,%u,%u}"), (TUint)aRgb.Red(), (TUint)aRgb.Green(), (TUint)aRgb.Blue());
126 TBuf<20> TDebugLogTextHandler::PointerEventType(TPointerEvent::TType aType)
131 case TPointerEvent::EButton1Down:
132 text.Copy(_L("EButton1Down"));
134 case TPointerEvent::EButton1Up:
135 text.Copy(_L("EButton1Up"));
137 case TPointerEvent::EButton2Down:
138 text.Copy(_L("EButton2Down"));
140 case TPointerEvent::EButton2Up:
141 text.Copy(_L("EButton2Up"));
143 case TPointerEvent::EButton3Down:
144 text.Copy(_L("EButton3Down"));
146 case TPointerEvent::EButton3Up:
147 text.Copy(_L("EButton3Up"));
149 case TPointerEvent::EButtonRepeat:
150 text.Copy(_L("EButtonRepeat"));
152 case TPointerEvent::EDrag:
153 text.Copy(_L("EDrag"));
155 case TPointerEvent::EMove:
156 text.Copy(_L("EMove"));
158 case TPointerEvent::ESwitchOn:
159 text.Copy(_L("ESwitchOn"));
165 TBuf<LogTBufSize> TDebugLogTextHandler::FormatArray(TArrayType aArrayType, const TUint8 *aArrayPtr, TUint aNumElems)
167 TBuf<LogTBufSize> text;
173 elemSize=sizeof(TInt);
176 elemSize=sizeof(TRgb);
184 Append(text, formatArrayElement(aArrayType, aArrayPtr));
185 while (--aNumElems>0)
187 Append(text, _L(","));
189 Append(text, formatArrayElement(aArrayType, aArrayPtr));
192 Append(text, _L("}"));
196 TBuf<0x20> TDebugLogTextHandler::formatArrayElement(TArrayType aArrayType, const TUint8 *aArrayPtr)
203 text.Format(_L("%d"), *(TInt *)aArrayPtr);
207 TLongBuf buf(FormatRgb(*(TRgb *)aArrayPtr));
208 text.Format(_L("%S"), &buf);
217 void TDebugLogTextHandler::panic(TInt aReason)
219 User::Panic(_L("WservDebugLog"), aReason);