sl@0
|
1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Handles text for the window server debug-logger - platform independent
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "../SERVER/w32cmd.h"
|
sl@0
|
19 |
#include "DEBUGLOG.H"
|
sl@0
|
20 |
|
sl@0
|
21 |
void TDebugLogTextHandler::Append(TDes &aBuf1, const TDesC &aBuf2)
|
sl@0
|
22 |
{
|
sl@0
|
23 |
if (aBuf1.Length()+aBuf2.Length()>aBuf1.MaxLength()-1)
|
sl@0
|
24 |
{
|
sl@0
|
25 |
TUint offset=aBuf1.Length();
|
sl@0
|
26 |
aBuf1.SetLength(aBuf1.MaxLength()-3-1);
|
sl@0
|
27 |
for (TInt i=offset; i<(aBuf1.MaxLength()-3-1); i++)
|
sl@0
|
28 |
aBuf1[i]=aBuf2[i-offset];
|
sl@0
|
29 |
aBuf1+=_L("...");
|
sl@0
|
30 |
}
|
sl@0
|
31 |
else
|
sl@0
|
32 |
aBuf1+=aBuf2;
|
sl@0
|
33 |
}
|
sl@0
|
34 |
|
sl@0
|
35 |
void TDebugLogTextHandler::TestAppend()
|
sl@0
|
36 |
{
|
sl@0
|
37 |
#if defined(_DEBUG)
|
sl@0
|
38 |
TBuf<0x10> buf1=_L("123456789012345");
|
sl@0
|
39 |
TBuf<0x10> buf2(KNullDesC);
|
sl@0
|
40 |
|
sl@0
|
41 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
42 |
__ASSERT_ALWAYS(buf1==_L("123456789012345"), panic(1));
|
sl@0
|
43 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
44 |
__ASSERT_ALWAYS(buf1==_L("123456789012345"), panic(2));
|
sl@0
|
45 |
|
sl@0
|
46 |
buf1=_L("12345678901234");
|
sl@0
|
47 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
48 |
__ASSERT_ALWAYS(buf1==_L("12345678901234"), panic(3));
|
sl@0
|
49 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
50 |
__ASSERT_ALWAYS(buf1==_L("12345678901234"), panic(4));
|
sl@0
|
51 |
|
sl@0
|
52 |
buf1=_L("1234567890123");
|
sl@0
|
53 |
buf2=_L("**********");
|
sl@0
|
54 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
55 |
__ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(5));
|
sl@0
|
56 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
57 |
__ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(6));
|
sl@0
|
58 |
|
sl@0
|
59 |
buf1=_L("123456789012");
|
sl@0
|
60 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
61 |
__ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(7));
|
sl@0
|
62 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
63 |
__ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(8));
|
sl@0
|
64 |
|
sl@0
|
65 |
buf1=_L("12345678901");
|
sl@0
|
66 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
67 |
__ASSERT_ALWAYS(buf1==_L("12345678901*..."), panic(9));
|
sl@0
|
68 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
69 |
__ASSERT_ALWAYS(buf1==_L("12345678901*..."), panic(10));
|
sl@0
|
70 |
|
sl@0
|
71 |
buf1=_L("1234567890");
|
sl@0
|
72 |
buf2=_L("*");
|
sl@0
|
73 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
74 |
__ASSERT_ALWAYS(buf1==_L("1234567890*"), panic(11));
|
sl@0
|
75 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
76 |
__ASSERT_ALWAYS(buf1==_L("1234567890**"), panic(12));
|
sl@0
|
77 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
78 |
__ASSERT_ALWAYS(buf1==_L("1234567890***"), panic(12));
|
sl@0
|
79 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
80 |
__ASSERT_ALWAYS(buf1==_L("1234567890****"), panic(12));
|
sl@0
|
81 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
82 |
__ASSERT_ALWAYS(buf1==_L("1234567890*****"), panic(12));
|
sl@0
|
83 |
TDebugLogTextHandler::Append(buf1, buf2);
|
sl@0
|
84 |
__ASSERT_ALWAYS(buf1==_L("1234567890**..."), panic(12));
|
sl@0
|
85 |
#endif
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
TBuf<20> TDebugLogTextHandler::FormatBool(TBool aBool)
|
sl@0
|
89 |
{
|
sl@0
|
90 |
TBuf<6> text;
|
sl@0
|
91 |
if (aBool)
|
sl@0
|
92 |
text.Append(_L("ETrue"));
|
sl@0
|
93 |
else
|
sl@0
|
94 |
text.Append(_L("EFalse"));
|
sl@0
|
95 |
return text;
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
TBuf<32> TDebugLogTextHandler::FormatPoint(const TPoint &aPoint)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
TBuf<32> text;
|
sl@0
|
101 |
text.Format(_L("{%d,%d}"), aPoint.iX, aPoint.iY);
|
sl@0
|
102 |
return text;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
TBuf<32> TDebugLogTextHandler::FormatSize(const TSize &aSize)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
TBuf<32> text;
|
sl@0
|
108 |
text.Format(_L("{%d,%d}"), aSize.iWidth, aSize.iHeight);
|
sl@0
|
109 |
return text;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
TBuf<64> TDebugLogTextHandler::FormatRect(const TRect &aRect)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
TBuf<64> text;
|
sl@0
|
115 |
text.Format(_L("{{%d,%d},{%d,%d}}"), aRect.iTl.iX, aRect.iTl.iY, aRect.iBr.iX, aRect.iBr.iY);
|
sl@0
|
116 |
return text;
|
sl@0
|
117 |
}
|
sl@0
|
118 |
|
sl@0
|
119 |
TBuf<40> TDebugLogTextHandler::FormatRgb(const TRgb &aRgb)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
TBuf<40> text;
|
sl@0
|
122 |
text.Format(_L("{%u,%u,%u}"), (TUint)aRgb.Red(), (TUint)aRgb.Green(), (TUint)aRgb.Blue());
|
sl@0
|
123 |
return text;
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
TBuf<20> TDebugLogTextHandler::PointerEventType(TPointerEvent::TType aType)
|
sl@0
|
127 |
{
|
sl@0
|
128 |
TBuf<20> text;
|
sl@0
|
129 |
switch(aType)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
case TPointerEvent::EButton1Down:
|
sl@0
|
132 |
text.Copy(_L("EButton1Down"));
|
sl@0
|
133 |
break;
|
sl@0
|
134 |
case TPointerEvent::EButton1Up:
|
sl@0
|
135 |
text.Copy(_L("EButton1Up"));
|
sl@0
|
136 |
break;
|
sl@0
|
137 |
case TPointerEvent::EButton2Down:
|
sl@0
|
138 |
text.Copy(_L("EButton2Down"));
|
sl@0
|
139 |
break;
|
sl@0
|
140 |
case TPointerEvent::EButton2Up:
|
sl@0
|
141 |
text.Copy(_L("EButton2Up"));
|
sl@0
|
142 |
break;
|
sl@0
|
143 |
case TPointerEvent::EButton3Down:
|
sl@0
|
144 |
text.Copy(_L("EButton3Down"));
|
sl@0
|
145 |
break;
|
sl@0
|
146 |
case TPointerEvent::EButton3Up:
|
sl@0
|
147 |
text.Copy(_L("EButton3Up"));
|
sl@0
|
148 |
break;
|
sl@0
|
149 |
case TPointerEvent::EButtonRepeat:
|
sl@0
|
150 |
text.Copy(_L("EButtonRepeat"));
|
sl@0
|
151 |
break;
|
sl@0
|
152 |
case TPointerEvent::EDrag:
|
sl@0
|
153 |
text.Copy(_L("EDrag"));
|
sl@0
|
154 |
break;
|
sl@0
|
155 |
case TPointerEvent::EMove:
|
sl@0
|
156 |
text.Copy(_L("EMove"));
|
sl@0
|
157 |
break;
|
sl@0
|
158 |
case TPointerEvent::ESwitchOn:
|
sl@0
|
159 |
text.Copy(_L("ESwitchOn"));
|
sl@0
|
160 |
break;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
return text;
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
TBuf<LogTBufSize> TDebugLogTextHandler::FormatArray(TArrayType aArrayType, const TUint8 *aArrayPtr, TUint aNumElems)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
TBuf<LogTBufSize> text;
|
sl@0
|
168 |
TUint elemSize=0;
|
sl@0
|
169 |
|
sl@0
|
170 |
switch (aArrayType)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
case EInt:
|
sl@0
|
173 |
elemSize=sizeof(TInt);
|
sl@0
|
174 |
break;
|
sl@0
|
175 |
case ERgb:
|
sl@0
|
176 |
elemSize=sizeof(TRgb);
|
sl@0
|
177 |
break;
|
sl@0
|
178 |
default:
|
sl@0
|
179 |
panic(1);
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
if (aNumElems>0)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
Append(text, formatArrayElement(aArrayType, aArrayPtr));
|
sl@0
|
185 |
while (--aNumElems>0)
|
sl@0
|
186 |
{
|
sl@0
|
187 |
Append(text, _L(","));
|
sl@0
|
188 |
aArrayPtr+=elemSize;
|
sl@0
|
189 |
Append(text, formatArrayElement(aArrayType, aArrayPtr));
|
sl@0
|
190 |
}
|
sl@0
|
191 |
}
|
sl@0
|
192 |
Append(text, _L("}"));
|
sl@0
|
193 |
return text;
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
TBuf<0x20> TDebugLogTextHandler::formatArrayElement(TArrayType aArrayType, const TUint8 *aArrayPtr)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
TBuf<0x20> text;
|
sl@0
|
199 |
|
sl@0
|
200 |
switch (aArrayType)
|
sl@0
|
201 |
{
|
sl@0
|
202 |
case EInt:
|
sl@0
|
203 |
text.Format(_L("%d"), *(TInt *)aArrayPtr);
|
sl@0
|
204 |
break;
|
sl@0
|
205 |
case ERgb:
|
sl@0
|
206 |
{
|
sl@0
|
207 |
TLongBuf buf(FormatRgb(*(TRgb *)aArrayPtr));
|
sl@0
|
208 |
text.Format(_L("%S"), &buf);
|
sl@0
|
209 |
}
|
sl@0
|
210 |
break;
|
sl@0
|
211 |
default:
|
sl@0
|
212 |
panic(2);
|
sl@0
|
213 |
}
|
sl@0
|
214 |
return text;
|
sl@0
|
215 |
}
|
sl@0
|
216 |
|
sl@0
|
217 |
void TDebugLogTextHandler::panic(TInt aReason)
|
sl@0
|
218 |
{
|
sl@0
|
219 |
User::Panic(_L("WservDebugLog"), aReason);
|
sl@0
|
220 |
}
|
sl@0
|
221 |
|