sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Handles text for the window server debug-logger - platform independent sl@0: // sl@0: // sl@0: sl@0: #include "../SERVER/w32cmd.h" sl@0: #include "DEBUGLOG.H" sl@0: sl@0: void TDebugLogTextHandler::Append(TDes &aBuf1, const TDesC &aBuf2) sl@0: { sl@0: if (aBuf1.Length()+aBuf2.Length()>aBuf1.MaxLength()-1) sl@0: { sl@0: TUint offset=aBuf1.Length(); sl@0: aBuf1.SetLength(aBuf1.MaxLength()-3-1); sl@0: for (TInt i=offset; i<(aBuf1.MaxLength()-3-1); i++) sl@0: aBuf1[i]=aBuf2[i-offset]; sl@0: aBuf1+=_L("..."); sl@0: } sl@0: else sl@0: aBuf1+=aBuf2; sl@0: } sl@0: sl@0: void TDebugLogTextHandler::TestAppend() sl@0: { sl@0: #if defined(_DEBUG) sl@0: TBuf<0x10> buf1=_L("123456789012345"); sl@0: TBuf<0x10> buf2(KNullDesC); sl@0: sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("123456789012345"), panic(1)); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("123456789012345"), panic(2)); sl@0: sl@0: buf1=_L("12345678901234"); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("12345678901234"), panic(3)); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("12345678901234"), panic(4)); sl@0: sl@0: buf1=_L("1234567890123"); sl@0: buf2=_L("**********"); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(5)); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(6)); sl@0: sl@0: buf1=_L("123456789012"); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(7)); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("123456789012..."), panic(8)); sl@0: sl@0: buf1=_L("12345678901"); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("12345678901*..."), panic(9)); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("12345678901*..."), panic(10)); sl@0: sl@0: buf1=_L("1234567890"); sl@0: buf2=_L("*"); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("1234567890*"), panic(11)); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("1234567890**"), panic(12)); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("1234567890***"), panic(12)); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("1234567890****"), panic(12)); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("1234567890*****"), panic(12)); sl@0: TDebugLogTextHandler::Append(buf1, buf2); sl@0: __ASSERT_ALWAYS(buf1==_L("1234567890**..."), panic(12)); sl@0: #endif sl@0: } sl@0: sl@0: TBuf<20> TDebugLogTextHandler::FormatBool(TBool aBool) sl@0: { sl@0: TBuf<6> text; sl@0: if (aBool) sl@0: text.Append(_L("ETrue")); sl@0: else sl@0: text.Append(_L("EFalse")); sl@0: return text; sl@0: } sl@0: sl@0: TBuf<32> TDebugLogTextHandler::FormatPoint(const TPoint &aPoint) sl@0: { sl@0: TBuf<32> text; sl@0: text.Format(_L("{%d,%d}"), aPoint.iX, aPoint.iY); sl@0: return text; sl@0: } sl@0: sl@0: TBuf<32> TDebugLogTextHandler::FormatSize(const TSize &aSize) sl@0: { sl@0: TBuf<32> text; sl@0: text.Format(_L("{%d,%d}"), aSize.iWidth, aSize.iHeight); sl@0: return text; sl@0: } sl@0: sl@0: TBuf<64> TDebugLogTextHandler::FormatRect(const TRect &aRect) sl@0: { sl@0: TBuf<64> text; sl@0: text.Format(_L("{{%d,%d},{%d,%d}}"), aRect.iTl.iX, aRect.iTl.iY, aRect.iBr.iX, aRect.iBr.iY); sl@0: return text; sl@0: } sl@0: sl@0: TBuf<40> TDebugLogTextHandler::FormatRgb(const TRgb &aRgb) sl@0: { sl@0: TBuf<40> text; sl@0: text.Format(_L("{%u,%u,%u}"), (TUint)aRgb.Red(), (TUint)aRgb.Green(), (TUint)aRgb.Blue()); sl@0: return text; sl@0: } sl@0: sl@0: TBuf<20> TDebugLogTextHandler::PointerEventType(TPointerEvent::TType aType) sl@0: { sl@0: TBuf<20> text; sl@0: switch(aType) sl@0: { sl@0: case TPointerEvent::EButton1Down: sl@0: text.Copy(_L("EButton1Down")); sl@0: break; sl@0: case TPointerEvent::EButton1Up: sl@0: text.Copy(_L("EButton1Up")); sl@0: break; sl@0: case TPointerEvent::EButton2Down: sl@0: text.Copy(_L("EButton2Down")); sl@0: break; sl@0: case TPointerEvent::EButton2Up: sl@0: text.Copy(_L("EButton2Up")); sl@0: break; sl@0: case TPointerEvent::EButton3Down: sl@0: text.Copy(_L("EButton3Down")); sl@0: break; sl@0: case TPointerEvent::EButton3Up: sl@0: text.Copy(_L("EButton3Up")); sl@0: break; sl@0: case TPointerEvent::EButtonRepeat: sl@0: text.Copy(_L("EButtonRepeat")); sl@0: break; sl@0: case TPointerEvent::EDrag: sl@0: text.Copy(_L("EDrag")); sl@0: break; sl@0: case TPointerEvent::EMove: sl@0: text.Copy(_L("EMove")); sl@0: break; sl@0: case TPointerEvent::ESwitchOn: sl@0: text.Copy(_L("ESwitchOn")); sl@0: break; sl@0: } sl@0: return text; sl@0: } sl@0: sl@0: TBuf<LogTBufSize> TDebugLogTextHandler::FormatArray(TArrayType aArrayType, const TUint8 *aArrayPtr, TUint aNumElems) sl@0: { sl@0: TBuf<LogTBufSize> text; sl@0: TUint elemSize=0; sl@0: sl@0: switch (aArrayType) sl@0: { sl@0: case EInt: sl@0: elemSize=sizeof(TInt); sl@0: break; sl@0: case ERgb: sl@0: elemSize=sizeof(TRgb); sl@0: break; sl@0: default: sl@0: panic(1); sl@0: } sl@0: sl@0: if (aNumElems>0) sl@0: { sl@0: Append(text, formatArrayElement(aArrayType, aArrayPtr)); sl@0: while (--aNumElems>0) sl@0: { sl@0: Append(text, _L(",")); sl@0: aArrayPtr+=elemSize; sl@0: Append(text, formatArrayElement(aArrayType, aArrayPtr)); sl@0: } sl@0: } sl@0: Append(text, _L("}")); sl@0: return text; sl@0: } sl@0: sl@0: TBuf<0x20> TDebugLogTextHandler::formatArrayElement(TArrayType aArrayType, const TUint8 *aArrayPtr) sl@0: { sl@0: TBuf<0x20> text; sl@0: sl@0: switch (aArrayType) sl@0: { sl@0: case EInt: sl@0: text.Format(_L("%d"), *(TInt *)aArrayPtr); sl@0: break; sl@0: case ERgb: sl@0: { sl@0: TLongBuf buf(FormatRgb(*(TRgb *)aArrayPtr)); sl@0: text.Format(_L("%S"), &buf); sl@0: } sl@0: break; sl@0: default: sl@0: panic(2); sl@0: } sl@0: return text; sl@0: } sl@0: sl@0: void TDebugLogTextHandler::panic(TInt aReason) sl@0: { sl@0: User::Panic(_L("WservDebugLog"), aReason); sl@0: } sl@0: