|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Handles text for the window server debug-logger - platform independent |
|
15 // |
|
16 // |
|
17 |
|
18 #include "../SERVER/w32cmd.h" |
|
19 #include "DEBUGLOG.H" |
|
20 |
|
21 void TDebugLogTextHandler::Append(TDes &aBuf1, const TDesC &aBuf2) |
|
22 { |
|
23 if (aBuf1.Length()+aBuf2.Length()>aBuf1.MaxLength()-1) |
|
24 { |
|
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]; |
|
29 aBuf1+=_L("..."); |
|
30 } |
|
31 else |
|
32 aBuf1+=aBuf2; |
|
33 } |
|
34 |
|
35 void TDebugLogTextHandler::TestAppend() |
|
36 { |
|
37 #if defined(_DEBUG) |
|
38 TBuf<0x10> buf1=_L("123456789012345"); |
|
39 TBuf<0x10> buf2(KNullDesC); |
|
40 |
|
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)); |
|
45 |
|
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)); |
|
51 |
|
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)); |
|
58 |
|
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)); |
|
64 |
|
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)); |
|
70 |
|
71 buf1=_L("1234567890"); |
|
72 buf2=_L("*"); |
|
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)); |
|
85 #endif |
|
86 } |
|
87 |
|
88 TBuf<20> TDebugLogTextHandler::FormatBool(TBool aBool) |
|
89 { |
|
90 TBuf<6> text; |
|
91 if (aBool) |
|
92 text.Append(_L("ETrue")); |
|
93 else |
|
94 text.Append(_L("EFalse")); |
|
95 return text; |
|
96 } |
|
97 |
|
98 TBuf<32> TDebugLogTextHandler::FormatPoint(const TPoint &aPoint) |
|
99 { |
|
100 TBuf<32> text; |
|
101 text.Format(_L("{%d,%d}"), aPoint.iX, aPoint.iY); |
|
102 return text; |
|
103 } |
|
104 |
|
105 TBuf<32> TDebugLogTextHandler::FormatSize(const TSize &aSize) |
|
106 { |
|
107 TBuf<32> text; |
|
108 text.Format(_L("{%d,%d}"), aSize.iWidth, aSize.iHeight); |
|
109 return text; |
|
110 } |
|
111 |
|
112 TBuf<64> TDebugLogTextHandler::FormatRect(const TRect &aRect) |
|
113 { |
|
114 TBuf<64> text; |
|
115 text.Format(_L("{{%d,%d},{%d,%d}}"), aRect.iTl.iX, aRect.iTl.iY, aRect.iBr.iX, aRect.iBr.iY); |
|
116 return text; |
|
117 } |
|
118 |
|
119 TBuf<40> TDebugLogTextHandler::FormatRgb(const TRgb &aRgb) |
|
120 { |
|
121 TBuf<40> text; |
|
122 text.Format(_L("{%u,%u,%u}"), (TUint)aRgb.Red(), (TUint)aRgb.Green(), (TUint)aRgb.Blue()); |
|
123 return text; |
|
124 } |
|
125 |
|
126 TBuf<20> TDebugLogTextHandler::PointerEventType(TPointerEvent::TType aType) |
|
127 { |
|
128 TBuf<20> text; |
|
129 switch(aType) |
|
130 { |
|
131 case TPointerEvent::EButton1Down: |
|
132 text.Copy(_L("EButton1Down")); |
|
133 break; |
|
134 case TPointerEvent::EButton1Up: |
|
135 text.Copy(_L("EButton1Up")); |
|
136 break; |
|
137 case TPointerEvent::EButton2Down: |
|
138 text.Copy(_L("EButton2Down")); |
|
139 break; |
|
140 case TPointerEvent::EButton2Up: |
|
141 text.Copy(_L("EButton2Up")); |
|
142 break; |
|
143 case TPointerEvent::EButton3Down: |
|
144 text.Copy(_L("EButton3Down")); |
|
145 break; |
|
146 case TPointerEvent::EButton3Up: |
|
147 text.Copy(_L("EButton3Up")); |
|
148 break; |
|
149 case TPointerEvent::EButtonRepeat: |
|
150 text.Copy(_L("EButtonRepeat")); |
|
151 break; |
|
152 case TPointerEvent::EDrag: |
|
153 text.Copy(_L("EDrag")); |
|
154 break; |
|
155 case TPointerEvent::EMove: |
|
156 text.Copy(_L("EMove")); |
|
157 break; |
|
158 case TPointerEvent::ESwitchOn: |
|
159 text.Copy(_L("ESwitchOn")); |
|
160 break; |
|
161 } |
|
162 return text; |
|
163 } |
|
164 |
|
165 TBuf<LogTBufSize> TDebugLogTextHandler::FormatArray(TArrayType aArrayType, const TUint8 *aArrayPtr, TUint aNumElems) |
|
166 { |
|
167 TBuf<LogTBufSize> text; |
|
168 TUint elemSize=0; |
|
169 |
|
170 switch (aArrayType) |
|
171 { |
|
172 case EInt: |
|
173 elemSize=sizeof(TInt); |
|
174 break; |
|
175 case ERgb: |
|
176 elemSize=sizeof(TRgb); |
|
177 break; |
|
178 default: |
|
179 panic(1); |
|
180 } |
|
181 |
|
182 if (aNumElems>0) |
|
183 { |
|
184 Append(text, formatArrayElement(aArrayType, aArrayPtr)); |
|
185 while (--aNumElems>0) |
|
186 { |
|
187 Append(text, _L(",")); |
|
188 aArrayPtr+=elemSize; |
|
189 Append(text, formatArrayElement(aArrayType, aArrayPtr)); |
|
190 } |
|
191 } |
|
192 Append(text, _L("}")); |
|
193 return text; |
|
194 } |
|
195 |
|
196 TBuf<0x20> TDebugLogTextHandler::formatArrayElement(TArrayType aArrayType, const TUint8 *aArrayPtr) |
|
197 { |
|
198 TBuf<0x20> text; |
|
199 |
|
200 switch (aArrayType) |
|
201 { |
|
202 case EInt: |
|
203 text.Format(_L("%d"), *(TInt *)aArrayPtr); |
|
204 break; |
|
205 case ERgb: |
|
206 { |
|
207 TLongBuf buf(FormatRgb(*(TRgb *)aArrayPtr)); |
|
208 text.Format(_L("%S"), &buf); |
|
209 } |
|
210 break; |
|
211 default: |
|
212 panic(2); |
|
213 } |
|
214 return text; |
|
215 } |
|
216 |
|
217 void TDebugLogTextHandler::panic(TInt aReason) |
|
218 { |
|
219 User::Panic(_L("WservDebugLog"), aReason); |
|
220 } |
|
221 |