|
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 // General utility functions that don't belong anywhere else |
|
15 // |
|
16 // |
|
17 |
|
18 #include "server.h" |
|
19 #include "rootwin.h" |
|
20 #include "wstop.h" |
|
21 #include "panics.h" |
|
22 |
|
23 GLREF_D CDebugLogBase *wsDebugLog; |
|
24 |
|
25 GLDEF_C RWsRegion *GetRegionFromClientL(CWsClient *aClient, TInt aCount) |
|
26 { |
|
27 TInt bufSize=sizeof(TRect)*aCount; |
|
28 TUint8* rectList=STATIC_CAST(TUint8*,User::Alloc(bufSize)); |
|
29 User::LeaveIfNull(rectList); |
|
30 CleanupStack::PushL(rectList); |
|
31 TPtr8 rectBuf(rectList,bufSize); |
|
32 aClient->RemoteRead(rectBuf,0); |
|
33 RWsRegion* region=new(ELeave) RWsRegion(aCount,REINTERPRET_CAST(TRect*,rectList)); |
|
34 CleanupStack::Pop(rectList); |
|
35 return(region); |
|
36 } |
|
37 |
|
38 GLDEF_C TInt ExternalizeRegionL(RWriteStream& aWriteStream, const RWsRegion& aRegion) |
|
39 { |
|
40 TInt dataLen = sizeof(TRect)*aRegion.Count(); |
|
41 aWriteStream.WriteInt32L(aRegion.Count()); |
|
42 aWriteStream.WriteL(REINTERPRET_CAST(const TUint8*,aRegion.RectangleList()),dataLen); |
|
43 aWriteStream.CommitL(); |
|
44 return sizeof(TInt32)+dataLen; |
|
45 } |
|
46 |
|
47 GLDEF_C RWsRegion* InternalizeRegionL(RReadStream& aReadStream) |
|
48 { |
|
49 TInt numRects = aReadStream.ReadInt32L(); |
|
50 TInt bufSize = sizeof(TRect)*numRects; |
|
51 // Allocate buffer for list of clipping rectangles. We leave if we |
|
52 // cannot create the buffer |
|
53 TUint8* rectList = static_cast<TUint8*>(User::AllocL(bufSize)); |
|
54 CleanupStack::PushL(rectList); |
|
55 // Read the list of rectangles into the buffer |
|
56 aReadStream.ReadL(rectList,bufSize); |
|
57 // Point member pointer to our new rectangle list buffer |
|
58 RWsRegion* region = new(ELeave) RWsRegion(numRects,reinterpret_cast<TRect*>(rectList)); |
|
59 CleanupStack::Pop(rectList); |
|
60 return region; |
|
61 } |
|
62 |
|
63 void Panic(TWservPanic aPanic) |
|
64 { |
|
65 if (wsDebugLog) |
|
66 wsDebugLog->Panic(CDebugLogBase::EDummyConnectionId,aPanic); //Dummy value meaning WSERV |
|
67 _LIT(KWSERVInternalPanicCategory,"WSERV-INTERNAL"); |
|
68 User::Panic(KWSERVInternalPanicCategory,aPanic); |
|
69 } |
|
70 |
|
71 _LIT(KWSERVPanicDesc1,"WServ internal Panic %S, in file %S @ line %i"); |
|
72 _LIT(KWSERVPanicDesc2,"Assert condition = \"%S\""); |
|
73 |
|
74 void PanicWithInfo(TWservPanic aPanic, const TDesC& aFileName, const TDesC& aPanicName, TInt aLine) |
|
75 { |
|
76 TBuf<256> buf; |
|
77 buf.Format(KWSERVPanicDesc1, &aPanicName, &aFileName, aLine); |
|
78 RDebug::Print(buf); |
|
79 if (wsDebugLog) |
|
80 { |
|
81 wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant, buf); |
|
82 } |
|
83 Panic(aPanic); |
|
84 } |
|
85 |
|
86 void PanicWithCondAndInfo(TWservPanic aPanic, const TDesC& aCondition, const TDesC& aFileName, const TDesC& aPanicName, TInt aLine) |
|
87 { |
|
88 TBuf<256> buf; |
|
89 buf.Format(KWSERVPanicDesc1, &aPanicName, &aFileName, aLine); |
|
90 RDebug::Print(buf); |
|
91 if (wsDebugLog) |
|
92 { |
|
93 wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant, buf); |
|
94 } |
|
95 buf.Format(KWSERVPanicDesc2, &aCondition); |
|
96 RDebug::Print(buf); |
|
97 if (wsDebugLog) |
|
98 { |
|
99 wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant, buf); |
|
100 } |
|
101 Panic(aPanic); |
|
102 } |
|
103 |
|
104 |
|
105 GLDEF_C void StateDump() |
|
106 { |
|
107 CWsTop::StateDump(); |
|
108 } |
|
109 |
|
110 GLDEF_C void StateDump(CWsRootWindow* aRootWindow) |
|
111 { |
|
112 TBool enabled=wsDebugLog!=NULL; |
|
113 if (!enabled) |
|
114 { |
|
115 CWsTop::EnableLogging(); |
|
116 if (!wsDebugLog) |
|
117 return; // Failed to enable logging so give up |
|
118 } |
|
119 // |
|
120 _LIT(LogLine,"==========="); |
|
121 _LIT(KWSERVStateLogWindowTree,"Window tree"); |
|
122 TBuf<128> buf; |
|
123 wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,LogLine); |
|
124 wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,KWSERVStateLogWindowTree); |
|
125 wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,LogLine); |
|
126 |
|
127 CWsWindowBase *win=aRootWindow; |
|
128 TInt inset=0; |
|
129 _LIT(KWSERVStateInsetLevelValue,"%*p"); |
|
130 FOREVER |
|
131 { |
|
132 buf.Format(KWSERVStateInsetLevelValue,Min(inset<<1,20)); |
|
133 win->StatusDump(buf); |
|
134 wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,buf); |
|
135 if (win->BaseChild()) |
|
136 { |
|
137 ++inset; |
|
138 win=win->BaseChild(); |
|
139 continue; |
|
140 } |
|
141 while(!win->NextSibling() && win!=aRootWindow) |
|
142 { |
|
143 win=win->BaseParent(); |
|
144 --inset; |
|
145 } |
|
146 if (win==aRootWindow) |
|
147 break; //Will break here if there is only the root window or the tree walk has returned to it |
|
148 win=win->NextSibling(); |
|
149 } |
|
150 wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant,LogLine); |
|
151 // |
|
152 if (!enabled) |
|
153 CWsTop::DisableLogging(); |
|
154 } |
|
155 |
|
156 GLDEF_C void HeapDump() |
|
157 { |
|
158 TBool enabled=(wsDebugLog!=NULL); |
|
159 if (!enabled) |
|
160 CWsTop::EnableLogging(); |
|
161 if (wsDebugLog) // Just in case enable failed |
|
162 wsDebugLog->HeapDump(); |
|
163 if (!enabled) |
|
164 CWsTop::DisableLogging(); |
|
165 } |
|
166 |
|
167 #if defined(_DEBUG) |
|
168 //GLREF_C void ForceLog(TInt aPriority,const TDesC &aText,TInt aParam=0); |
|
169 //ForceLog(CDebugLogBase::ELogImportant,_L("Value=%d"),345); |
|
170 //TLogMessageText buf; |
|
171 //_LIT(KLog,"Count=%d, Object=0x%x"); |
|
172 //buf.Format(KLog,Count(),this); |
|
173 //ForceLog(CDebugLogBase::ELogImportant,buf); |
|
174 GLDEF_C void ForceLog(TInt aPriority,const TDesC &aText,TInt aParam=0) |
|
175 { |
|
176 TBool enabled=(wsDebugLog!=NULL); |
|
177 if (!enabled) |
|
178 CWsTop::EnableLogging(); |
|
179 if (wsDebugLog) // Just in case enable failed |
|
180 { |
|
181 wsDebugLog->MiscMessage(aPriority,aText,aParam); |
|
182 if (!enabled) |
|
183 CWsTop::DisableLogging(); |
|
184 } |
|
185 } |
|
186 #endif |
|
187 |