sl@0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
/**
|
sl@0
|
17 |
@file
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "wsgcedebugsession.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
RWsDebugSession::RWsDebugSession(TInt aScreenNo /*= -1*/):
|
sl@0
|
23 |
iScreenNo(aScreenNo),
|
sl@0
|
24 |
iSurfaceUpdateSerial(-1)
|
sl@0
|
25 |
{
|
sl@0
|
26 |
iSurfaceListBuffer.CreateMax(48);
|
sl@0
|
27 |
}
|
sl@0
|
28 |
|
sl@0
|
29 |
RWsDebugSession::~RWsDebugSession()
|
sl@0
|
30 |
{
|
sl@0
|
31 |
iSurfaceListBuffer.Close();
|
sl@0
|
32 |
|
sl@0
|
33 |
}
|
sl@0
|
34 |
|
sl@0
|
35 |
TBool RWsDebugSession::ResetUpdated()
|
sl@0
|
36 |
{
|
sl@0
|
37 |
TInt surfaceUpdateSerial=DebugInfo(EWsDebugSerialSurfacesUpdated,iScreenNo);
|
sl@0
|
38 |
TBool retVal=(iSurfaceUpdateSerial!=surfaceUpdateSerial);
|
sl@0
|
39 |
iSurfaceUpdateSerial=surfaceUpdateSerial;
|
sl@0
|
40 |
return retVal;
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
TInt RWsDebugSession::ResetUpdatedAndGetSurfaceWindowList(const TWsDebugWindowId * & aWinList)
|
sl@0
|
44 |
{
|
sl@0
|
45 |
iSurfaceUpdateSerial=DebugInfo(EWsDebugSerialSurfacesUpdated,iScreenNo);
|
sl@0
|
46 |
TInt reqSize=DebugInfo(EWsDebugSurfaceWindowList,iSurfaceListBuffer,iScreenNo);
|
sl@0
|
47 |
while (reqSize>iSurfaceListBuffer.MaxLength())
|
sl@0
|
48 |
{
|
sl@0
|
49 |
iSurfaceListBuffer.Close();
|
sl@0
|
50 |
iSurfaceListBuffer.CreateMax(reqSize);
|
sl@0
|
51 |
iSurfaceUpdateSerial=DebugInfo(EWsDebugSerialSurfacesUpdated,iScreenNo);
|
sl@0
|
52 |
reqSize=DebugInfo(EWsDebugSurfaceWindowList,iSurfaceListBuffer,iScreenNo);
|
sl@0
|
53 |
}
|
sl@0
|
54 |
if (reqSize==KErrCancel)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
aWinList=NULL;
|
sl@0
|
57 |
return 0;
|
sl@0
|
58 |
}
|
sl@0
|
59 |
else
|
sl@0
|
60 |
{
|
sl@0
|
61 |
aWinList=(TWsDebugWindowId*)iSurfaceListBuffer.Ptr();
|
sl@0
|
62 |
return reqSize/sizeof(TWsDebugWindowId);
|
sl@0
|
63 |
}
|
sl@0
|
64 |
}
|
sl@0
|
65 |
/**
|
sl@0
|
66 |
* Stream data into the provided buffer and point the return object pointer to it.
|
sl@0
|
67 |
* The pointer is left null if the method returns an error code or the buffer is too small.
|
sl@0
|
68 |
* The ret5urn code reports
|
sl@0
|
69 |
*
|
sl@0
|
70 |
**/
|
sl@0
|
71 |
TInt RWsDebugSession::DebugInfo(TWsDebugInfoFunc aFunction, TInt aParam, TDes8& aHostBuffer,const void*&aReturnedObject,TInt aObjectSize)const
|
sl@0
|
72 |
{
|
sl@0
|
73 |
aHostBuffer.SetMax();
|
sl@0
|
74 |
TInt reqSize=DebugInfo(aFunction,aHostBuffer,aParam);
|
sl@0
|
75 |
aReturnedObject=NULL;
|
sl@0
|
76 |
if (reqSize<0)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
return reqSize; //Error code is transmitted unmolested
|
sl@0
|
79 |
}
|
sl@0
|
80 |
if (reqSize==0) //Size 0 is transformed to max
|
sl@0
|
81 |
reqSize=aHostBuffer.MaxLength();
|
sl@0
|
82 |
if ((reqSize%aObjectSize)!=0)
|
sl@0
|
83 |
{ //Size not multiple of object --> error
|
sl@0
|
84 |
return KErrCorrupt;
|
sl@0
|
85 |
}
|
sl@0
|
86 |
if (reqSize<=aHostBuffer.MaxLength())
|
sl@0
|
87 |
{ //Pointer is only set if data fits buffer
|
sl@0
|
88 |
aReturnedObject=(const void*)aHostBuffer.Ptr();
|
sl@0
|
89 |
}
|
sl@0
|
90 |
reqSize/=aObjectSize; //Return the exact number of objects filled
|
sl@0
|
91 |
return reqSize;
|
sl@0
|
92 |
}
|
sl@0
|
93 |
/**
|
sl@0
|
94 |
* Stream the reply data via the buffer associated with the region.
|
sl@0
|
95 |
* Some protected accessor optimisation used to manage the reported size of the region after streaming.
|
sl@0
|
96 |
*
|
sl@0
|
97 |
**/
|
sl@0
|
98 |
TInt RWsDebugSession::DebugInfo(TWsDebugInfoFunc aFunction, TInt aParam, TRegion& aPreAllocatedReturnedRegion)const
|
sl@0
|
99 |
{
|
sl@0
|
100 |
//Attempt to fit the received data in the preexisting region buffer...
|
sl@0
|
101 |
class XRegion:public TRegion
|
sl@0
|
102 |
{
|
sl@0
|
103 |
public:
|
sl@0
|
104 |
using TRegion::AppendRect;
|
sl@0
|
105 |
// using TRegion::SetListSize;
|
sl@0
|
106 |
using TRegion::RectangleListW;
|
sl@0
|
107 |
TInt MaxSize()
|
sl@0
|
108 |
{ return iAllocedRects; }
|
sl@0
|
109 |
void SetListSize(TInt aNewSize) //DANGER no error checking!!!
|
sl@0
|
110 |
{ iCount=aNewSize; }
|
sl@0
|
111 |
}& preAllocatedReturnedRegion=(XRegion&)aPreAllocatedReturnedRegion;
|
sl@0
|
112 |
typedef TRect TElt;
|
sl@0
|
113 |
TInt reqSize=preAllocatedReturnedRegion.MaxSize();
|
sl@0
|
114 |
const TElt* elements=preAllocatedReturnedRegion.RectangleListW();
|
sl@0
|
115 |
TInt lenBytes=reqSize*sizeof(TElt);
|
sl@0
|
116 |
TPtr8 pBuff((TUint8*)elements,lenBytes,lenBytes);
|
sl@0
|
117 |
reqSize=DebugInfo(aFunction,aParam,pBuff,elements);
|
sl@0
|
118 |
|
sl@0
|
119 |
if (elements)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
if (reqSize==0)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
reqSize=preAllocatedReturnedRegion.MaxSize();
|
sl@0
|
124 |
}
|
sl@0
|
125 |
preAllocatedReturnedRegion.SetListSize(reqSize);
|
sl@0
|
126 |
return reqSize;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
//If data does not fit in preexisting buffer
|
sl@0
|
129 |
//Use a temp array instead
|
sl@0
|
130 |
//Still try to block copy into the existing capacity
|
sl@0
|
131 |
//I think this use of region copy is more efficient than appending,
|
sl@0
|
132 |
//and definitely better than unioning the elements.
|
sl@0
|
133 |
if (reqSize>=0)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
TInt breakLoop=10;
|
sl@0
|
136 |
do {
|
sl@0
|
137 |
TElt* tempbuff=new TElt[reqSize];
|
sl@0
|
138 |
if (tempbuff==NULL)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
reqSize=KErrNoMemory;
|
sl@0
|
141 |
break;
|
sl@0
|
142 |
}
|
sl@0
|
143 |
elements=tempbuff;
|
sl@0
|
144 |
TInt lenBytes=reqSize*sizeof(TElt);
|
sl@0
|
145 |
TPtr8 pBuff((TUint8*)elements,lenBytes,lenBytes);
|
sl@0
|
146 |
TInt reqSize2=DebugInfo(aFunction,aParam,pBuff,elements);
|
sl@0
|
147 |
if (reqSize2!=0)
|
sl@0
|
148 |
reqSize=reqSize2;
|
sl@0
|
149 |
if (elements)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
RRegion r(reqSize,tempbuff); //note this region does not own its memory so should not be closed!
|
sl@0
|
152 |
aPreAllocatedReturnedRegion.Copy(r);
|
sl@0
|
153 |
if (aPreAllocatedReturnedRegion.CheckError())
|
sl@0
|
154 |
reqSize=KErrNoMemory;
|
sl@0
|
155 |
}
|
sl@0
|
156 |
delete[] tempbuff;
|
sl@0
|
157 |
}while (reqSize>0 && elements==NULL && --breakLoop);
|
sl@0
|
158 |
}
|
sl@0
|
159 |
if (reqSize>=0 && elements==NULL)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
preAllocatedReturnedRegion.ForceError();
|
sl@0
|
162 |
reqSize=KErrTimedOut;
|
sl@0
|
163 |
}
|
sl@0
|
164 |
if (reqSize<0)
|
sl@0
|
165 |
{
|
sl@0
|
166 |
if (reqSize==KErrCancel)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
preAllocatedReturnedRegion.Clear();
|
sl@0
|
169 |
}
|
sl@0
|
170 |
else
|
sl@0
|
171 |
{
|
sl@0
|
172 |
preAllocatedReturnedRegion.ForceError();
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
}
|
sl@0
|
176 |
return reqSize;
|
sl@0
|
177 |
}
|