1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/debuglog/TXTHNDLR.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,221 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Handles text for the window server debug-logger - platform independent
1.18 +//
1.19 +//
1.20 +
1.21 +#include "../SERVER/w32cmd.h"
1.22 +#include "DEBUGLOG.H"
1.23 +
1.24 +void TDebugLogTextHandler::Append(TDes &aBuf1, const TDesC &aBuf2)
1.25 + {
1.26 + if (aBuf1.Length()+aBuf2.Length()>aBuf1.MaxLength()-1)
1.27 + {
1.28 + TUint offset=aBuf1.Length();
1.29 + aBuf1.SetLength(aBuf1.MaxLength()-3-1);
1.30 + for (TInt i=offset; i<(aBuf1.MaxLength()-3-1); i++)
1.31 + aBuf1[i]=aBuf2[i-offset];
1.32 + aBuf1+=_L("...");
1.33 + }
1.34 + else
1.35 + aBuf1+=aBuf2;
1.36 + }
1.37 +
1.38 +void TDebugLogTextHandler::TestAppend()
1.39 + {
1.40 +#if defined(_DEBUG)
1.41 + TBuf<0x10> buf1=_L("123456789012345");
1.42 + TBuf<0x10> buf2(KNullDesC);
1.43 +
1.44 + TDebugLogTextHandler::Append(buf1, buf2);
1.45 + __ASSERT_ALWAYS(buf1==_L("123456789012345"), panic(1));
1.46 + TDebugLogTextHandler::Append(buf1, buf2);
1.47 + __ASSERT_ALWAYS(buf1==_L("123456789012345"), panic(2));
1.48 +
1.49 + buf1=_L("12345678901234");
1.50 + TDebugLogTextHandler::Append(buf1, buf2);
1.51 + __ASSERT_ALWAYS(buf1==_L("12345678901234"), panic(3));
1.52 + TDebugLogTextHandler::Append(buf1, buf2);
1.53 + __ASSERT_ALWAYS(buf1==_L("12345678901234"), panic(4));
1.54 +
1.55 + buf1=_L("1234567890123");
1.56 + buf2=_L("**********");
1.57 + TDebugLogTextHandler::Append(buf1, buf2);
1.58 + __ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(5));
1.59 + TDebugLogTextHandler::Append(buf1, buf2);
1.60 + __ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(6));
1.61 +
1.62 + buf1=_L("123456789012");
1.63 + TDebugLogTextHandler::Append(buf1, buf2);
1.64 + __ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(7));
1.65 + TDebugLogTextHandler::Append(buf1, buf2);
1.66 + __ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(8));
1.67 +
1.68 + buf1=_L("12345678901");
1.69 + TDebugLogTextHandler::Append(buf1, buf2);
1.70 + __ASSERT_ALWAYS(buf1==_L("12345678901*..."), panic(9));
1.71 + TDebugLogTextHandler::Append(buf1, buf2);
1.72 + __ASSERT_ALWAYS(buf1==_L("12345678901*..."), panic(10));
1.73 +
1.74 + buf1=_L("1234567890");
1.75 + buf2=_L("*");
1.76 + TDebugLogTextHandler::Append(buf1, buf2);
1.77 + __ASSERT_ALWAYS(buf1==_L("1234567890*"), panic(11));
1.78 + TDebugLogTextHandler::Append(buf1, buf2);
1.79 + __ASSERT_ALWAYS(buf1==_L("1234567890**"), panic(12));
1.80 + TDebugLogTextHandler::Append(buf1, buf2);
1.81 + __ASSERT_ALWAYS(buf1==_L("1234567890***"), panic(12));
1.82 + TDebugLogTextHandler::Append(buf1, buf2);
1.83 + __ASSERT_ALWAYS(buf1==_L("1234567890****"), panic(12));
1.84 + TDebugLogTextHandler::Append(buf1, buf2);
1.85 + __ASSERT_ALWAYS(buf1==_L("1234567890*****"), panic(12));
1.86 + TDebugLogTextHandler::Append(buf1, buf2);
1.87 + __ASSERT_ALWAYS(buf1==_L("1234567890**..."), panic(12));
1.88 +#endif
1.89 + }
1.90 +
1.91 +TBuf<20> TDebugLogTextHandler::FormatBool(TBool aBool)
1.92 + {
1.93 + TBuf<6> text;
1.94 + if (aBool)
1.95 + text.Append(_L("ETrue"));
1.96 + else
1.97 + text.Append(_L("EFalse"));
1.98 + return text;
1.99 + }
1.100 +
1.101 +TBuf<32> TDebugLogTextHandler::FormatPoint(const TPoint &aPoint)
1.102 + {
1.103 + TBuf<32> text;
1.104 + text.Format(_L("{%d,%d}"), aPoint.iX, aPoint.iY);
1.105 + return text;
1.106 + }
1.107 +
1.108 +TBuf<32> TDebugLogTextHandler::FormatSize(const TSize &aSize)
1.109 + {
1.110 + TBuf<32> text;
1.111 + text.Format(_L("{%d,%d}"), aSize.iWidth, aSize.iHeight);
1.112 + return text;
1.113 + }
1.114 +
1.115 +TBuf<64> TDebugLogTextHandler::FormatRect(const TRect &aRect)
1.116 + {
1.117 + TBuf<64> text;
1.118 + text.Format(_L("{{%d,%d},{%d,%d}}"), aRect.iTl.iX, aRect.iTl.iY, aRect.iBr.iX, aRect.iBr.iY);
1.119 + return text;
1.120 + }
1.121 +
1.122 +TBuf<40> TDebugLogTextHandler::FormatRgb(const TRgb &aRgb)
1.123 + {
1.124 + TBuf<40> text;
1.125 + text.Format(_L("{%u,%u,%u}"), (TUint)aRgb.Red(), (TUint)aRgb.Green(), (TUint)aRgb.Blue());
1.126 + return text;
1.127 + }
1.128 +
1.129 +TBuf<20> TDebugLogTextHandler::PointerEventType(TPointerEvent::TType aType)
1.130 + {
1.131 + TBuf<20> text;
1.132 + switch(aType)
1.133 + {
1.134 + case TPointerEvent::EButton1Down:
1.135 + text.Copy(_L("EButton1Down"));
1.136 + break;
1.137 + case TPointerEvent::EButton1Up:
1.138 + text.Copy(_L("EButton1Up"));
1.139 + break;
1.140 + case TPointerEvent::EButton2Down:
1.141 + text.Copy(_L("EButton2Down"));
1.142 + break;
1.143 + case TPointerEvent::EButton2Up:
1.144 + text.Copy(_L("EButton2Up"));
1.145 + break;
1.146 + case TPointerEvent::EButton3Down:
1.147 + text.Copy(_L("EButton3Down"));
1.148 + break;
1.149 + case TPointerEvent::EButton3Up:
1.150 + text.Copy(_L("EButton3Up"));
1.151 + break;
1.152 + case TPointerEvent::EButtonRepeat:
1.153 + text.Copy(_L("EButtonRepeat"));
1.154 + break;
1.155 + case TPointerEvent::EDrag:
1.156 + text.Copy(_L("EDrag"));
1.157 + break;
1.158 + case TPointerEvent::EMove:
1.159 + text.Copy(_L("EMove"));
1.160 + break;
1.161 + case TPointerEvent::ESwitchOn:
1.162 + text.Copy(_L("ESwitchOn"));
1.163 + break;
1.164 + }
1.165 + return text;
1.166 + }
1.167 +
1.168 +TBuf<LogTBufSize> TDebugLogTextHandler::FormatArray(TArrayType aArrayType, const TUint8 *aArrayPtr, TUint aNumElems)
1.169 + {
1.170 + TBuf<LogTBufSize> text;
1.171 + TUint elemSize=0;
1.172 +
1.173 + switch (aArrayType)
1.174 + {
1.175 + case EInt:
1.176 + elemSize=sizeof(TInt);
1.177 + break;
1.178 + case ERgb:
1.179 + elemSize=sizeof(TRgb);
1.180 + break;
1.181 + default:
1.182 + panic(1);
1.183 + }
1.184 +
1.185 + if (aNumElems>0)
1.186 + {
1.187 + Append(text, formatArrayElement(aArrayType, aArrayPtr));
1.188 + while (--aNumElems>0)
1.189 + {
1.190 + Append(text, _L(","));
1.191 + aArrayPtr+=elemSize;
1.192 + Append(text, formatArrayElement(aArrayType, aArrayPtr));
1.193 + }
1.194 + }
1.195 + Append(text, _L("}"));
1.196 + return text;
1.197 + }
1.198 +
1.199 +TBuf<0x20> TDebugLogTextHandler::formatArrayElement(TArrayType aArrayType, const TUint8 *aArrayPtr)
1.200 + {
1.201 + TBuf<0x20> text;
1.202 +
1.203 + switch (aArrayType)
1.204 + {
1.205 + case EInt:
1.206 + text.Format(_L("%d"), *(TInt *)aArrayPtr);
1.207 + break;
1.208 + case ERgb:
1.209 + {
1.210 + TLongBuf buf(FormatRgb(*(TRgb *)aArrayPtr));
1.211 + text.Format(_L("%S"), &buf);
1.212 + }
1.213 + break;
1.214 + default:
1.215 + panic(2);
1.216 + }
1.217 + return text;
1.218 + }
1.219 +
1.220 +void TDebugLogTextHandler::panic(TInt aReason)
1.221 + {
1.222 + User::Panic(_L("WservDebugLog"), aReason);
1.223 + }
1.224 +