os/graphics/windowing/windowserver/debuglog/DEBUGLOG.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Common code for all debug logging variants
    15 // 
    16 //
    17 
    18 #include "../SERVER/w32cmd.h"
    19 #include "DEBUGLOG.H"
    20 
    21 //#define __LIMIT_LOGGING yes		//These should be turned off for released code
    22 //#define __FORCE_ASCII yes
    23 
    24 #if defined(__LIMIT_LOGGING)
    25 _LIT(limitLogging,"!!");
    26 #endif
    27 
    28 _LIT(KDebugLogFound,"Found");
    29 _LIT(KDebugLogSearchedFor,"Searched for");
    30 
    31 EXPORT_C CDebugLog::CDebugLog(CDebugLogDevice *aDevice) : iDevice(aDevice), iLevel(ELogEverything)
    32 	{
    33 	__DECLARE_NAME(_S("CDebugLog"));
    34 	}
    35 
    36 CDebugLog::~CDebugLog()
    37 	{
    38 	delete iDevice;
    39 	}
    40 
    41 EXPORT_C void CDebugLog::ConstructL(TBool aIsFirst, TDesC &aParams)
    42 	{
    43 	_LIT(LogLine,"=================");
    44 	iDevice->ConstructL(aIsFirst, aParams);
    45 	iPrevTime.HomeTime();
    46 	iExtraLen=0;	// Indicates don't print time part to log
    47 	MiscMessage(LogLine);
    48 	MiscMessage(_L("[Logging Enabled]"));
    49 	TBuf<32> timeBuf;
    50 	iPrevTime.FormatL(timeBuf,_L("[  %:0%H%:1%T%:2%S%.%*C2%:3  ]"));
    51 	MiscMessage(timeBuf);
    52 	MiscMessage(LogLine);
    53 	}
    54 
    55 void CDebugLog::CommandBuf(TInt aApp)
    56 	{
    57 	if (aApp==iLastApp)
    58 		return;
    59 	TPtrC text(iWsDecoder.CommandBuf(aApp));
    60 	WriteToLog(text);
    61 	iLastApp=aApp;
    62 	}
    63 
    64 void CDebugLog::Command(TInt aClass, TInt aOpcode, const TAny *aCmdData, TInt aHandle)
    65 	{
    66 	TPtrC text(iWsDecoder.Command(aClass, aOpcode, aCmdData, aHandle));
    67 	if (text!=KNullDesC)
    68 		WriteToLog(text);
    69 	}
    70 
    71 void CDebugLog::NewClient(TUint aConnectionHandle)
    72 	{
    73 	TPtrC text(iWsDecoder.NewClient(aConnectionHandle));
    74 	WriteToLog(text,ELogImportant);
    75 	}
    76 
    77 void CDebugLog::Reply(TInt aData)
    78 	{
    79 	TPtrC text(iWsDecoder.CommandReply(aData));
    80 	WriteToLog(text);
    81 	}
    82 
    83 void CDebugLog::ReplyBuf(const TDesC8 &aDes)
    84 	{
    85 	TPtrC text(iWsDecoder.CommandReplyBuf(aDes));
    86 	if (text!=KNullDesC)
    87 		WriteToLog(text);
    88 	}
    89 
    90 void CDebugLog::ReplyBuf(const TDesC16 &aDes)
    91 	{
    92 	TPtrC text(iWsDecoder.CommandReplyBuf(aDes));
    93 	if (text!=KNullDesC)
    94 		WriteToLog(text);
    95 	}
    96 
    97 void CDebugLog::SignalEvent(TInt aApp)
    98 	{
    99 	TPtrC text(iWsDecoder.SignalEvent(aApp));
   100 	WriteToLog(text);
   101 	}
   102 
   103 void CDebugLog::Panic(TInt aApp, TInt aReason)
   104 	{
   105 	TPtrC text(iWsDecoder.Panic(aApp, aReason));
   106 	WriteToLog(text,ELogImportant);
   107 	}
   108 
   109 void CDebugLog::MiscMessage(TInt aPriority,const TDesC &aFormat,TInt aParam)
   110 	{
   111 	if (aPriority>=iLevel)
   112 		MiscMessage(aFormat,aParam);
   113 	}
   114 
   115 void CDebugLog::MiscMessage(const TDesC &aFormat,TInt aParam)
   116 	{
   117 	TPtrC text(iWsDecoder.MiscMessage(aFormat,aParam));
   118 	WriteToLog(text,iLevel);
   119 	}
   120 
   121 void CDebugLog::IniFileSettingRead(TInt aScreen, const TDesC& aVarName, TBool aFound, const TDesC& aResult)
   122 	{
   123 	if (!aFound && (iLevel != ELogEverything))
   124 		{ // nothing to print
   125 		return;
   126 		}
   127 		
   128 	TBuf<256> buf;
   129 
   130 	buf.Format(_L("%S .ini setting { "), &(aFound ? KDebugLogFound() : KDebugLogSearchedFor()));   	
   131 
   132 	if (aScreen >= 0)
   133 		{
   134 		buf.AppendFormat(_L("Screen %i, "), aScreen);
   135 		}
   136 	else
   137 		{
   138 		buf.Append(_L("Default, "));
   139 		}
   140 
   141 	if (aFound)
   142 		{
   143 		buf.AppendFormat(_L("\"%S\", \"%S\" }"), &aVarName, &aResult);
   144 		}
   145 	else
   146 		{
   147 		buf.AppendFormat(_L("\"%S\" }"), &aVarName);
   148 		}
   149 
   150 	MiscMessage(buf);
   151 	}
   152 
   153 
   154 void CDebugLog::WriteToLog(const TDesC &aDes,TInt aLevel/*=ELogEverything*/)
   155 	{
   156 	if (aLevel<iLevel)
   157 		return;
   158 #if defined(__LIMIT_LOGGING)
   159 	TBuf<8> start(limitLogging);
   160 	if (start!=aDes.Left(start.Length()))
   161 		return;
   162 #endif
   163 	if (iErr==KErrNone)
   164 		{
   165 		TBuf<80> timeBuf;
   166 		TTime time;
   167 		time.HomeTime();
   168 		TTimeIntervalMicroSeconds diff(time.MicroSecondsFrom(iPrevTime));
   169 		TInt diffi = I64LOW(diff.Int64());
   170 //
   171 		if (iExtraLen>0)
   172 			timeBuf.Format(_L("%+ *p%d.%03d"),iExtraLen,diffi/1000000,(diffi%1000000)/1000);
   173 		iExtraLen=74-aDes.Length();
   174 		if (iExtraLen<1)
   175 			iExtraLen=1;
   176 /* Old version, logs current time
   177 		TBuf<256> buf(aDes);
   178 		time.FormatL(timeBuf,_L("%:0%H%:1%T%:2%S%.%*C2%:3"));
   179 		buf.Format(_L("%+ *p%S"),len,&timeBuf);
   180 */
   181 #if defined(__FORCE_ASCII)
   182 		TBuf8<80> timeBuf8;
   183 		TBuf8<128> des8;
   184 		timeBuf8.Copy(timeBuf);
   185 		des8.Copy(aDes);
   186 		TRAP(iErr,iDevice->WriteToLog8L(timeBuf8, des8));
   187 #else
   188 		TRAP(iErr,iDevice->WriteToLogL(timeBuf, aDes));
   189 #endif
   190 		iPrevTime.HomeTime();
   191 		iLastApp=0;
   192 		}
   193 	}
   194 
   195 
   196 void CDebugLog::HeapDump()
   197 	{
   198 	_LIT(LogLine,"===========");
   199 	MiscMessage(LogLine);
   200 	TBuf<128> buf;
   201 	TInt biggestblock;
   202 	buf.Format(_L("Heap size=%d, available=%d, count=%d"),User::Heap().Size(),User::Heap().Available(biggestblock),User::Heap().Count());
   203 	MiscMessage(buf);
   204 //
   205 	MiscMessage(LogLine);
   206 //
   207 	MiscMessage(LogLine);
   208 //
   209 // Plus profile information for now
   210 //
   211 	LogProfiles();
   212 	}
   213 
   214 void CDebugLog::SetLoggingLevel(TInt aLevel)
   215 	{
   216 	iLevel=aLevel;
   217 	}
   218 
   219 void CDebugLog::AppendProfileNum(TDes &aDes, TInt aNum)
   220 	{
   221 	aDes.AppendFormat(_L("%d.%02d, "),aNum/1000000,(aNum%1000000)/10000);
   222 	}
   223 
   224 void CDebugLog::AppendProfileCount(TDes &aDes, TInt aNum)
   225 	{
   226 	aDes.AppendFormat(_L("[%d], "),aNum);
   227 	}
   228 
   229 void CDebugLog::LogProfiles()
   230 	{
   231 	}