First public contribution.
1 // Copyright (c) 2008-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 #include "wsgcedebugsession.h"
22 RWsDebugSession::RWsDebugSession(TInt aScreenNo /*= -1*/):
24 iSurfaceUpdateSerial(-1)
26 iSurfaceListBuffer.CreateMax(48);
29 RWsDebugSession::~RWsDebugSession()
31 iSurfaceListBuffer.Close();
35 TBool RWsDebugSession::ResetUpdated()
37 TInt surfaceUpdateSerial=DebugInfo(EWsDebugSerialSurfacesUpdated,iScreenNo);
38 TBool retVal=(iSurfaceUpdateSerial!=surfaceUpdateSerial);
39 iSurfaceUpdateSerial=surfaceUpdateSerial;
43 TInt RWsDebugSession::ResetUpdatedAndGetSurfaceWindowList(const TWsDebugWindowId * & aWinList)
45 iSurfaceUpdateSerial=DebugInfo(EWsDebugSerialSurfacesUpdated,iScreenNo);
46 TInt reqSize=DebugInfo(EWsDebugSurfaceWindowList,iSurfaceListBuffer,iScreenNo);
47 while (reqSize>iSurfaceListBuffer.MaxLength())
49 iSurfaceListBuffer.Close();
50 iSurfaceListBuffer.CreateMax(reqSize);
51 iSurfaceUpdateSerial=DebugInfo(EWsDebugSerialSurfacesUpdated,iScreenNo);
52 reqSize=DebugInfo(EWsDebugSurfaceWindowList,iSurfaceListBuffer,iScreenNo);
54 if (reqSize==KErrCancel)
61 aWinList=(TWsDebugWindowId*)iSurfaceListBuffer.Ptr();
62 return reqSize/sizeof(TWsDebugWindowId);
66 * Stream data into the provided buffer and point the return object pointer to it.
67 * The pointer is left null if the method returns an error code or the buffer is too small.
68 * The ret5urn code reports
71 TInt RWsDebugSession::DebugInfo(TWsDebugInfoFunc aFunction, TInt aParam, TDes8& aHostBuffer,const void*&aReturnedObject,TInt aObjectSize)const
74 TInt reqSize=DebugInfo(aFunction,aHostBuffer,aParam);
78 return reqSize; //Error code is transmitted unmolested
80 if (reqSize==0) //Size 0 is transformed to max
81 reqSize=aHostBuffer.MaxLength();
82 if ((reqSize%aObjectSize)!=0)
83 { //Size not multiple of object --> error
86 if (reqSize<=aHostBuffer.MaxLength())
87 { //Pointer is only set if data fits buffer
88 aReturnedObject=(const void*)aHostBuffer.Ptr();
90 reqSize/=aObjectSize; //Return the exact number of objects filled
94 * Stream the reply data via the buffer associated with the region.
95 * Some protected accessor optimisation used to manage the reported size of the region after streaming.
98 TInt RWsDebugSession::DebugInfo(TWsDebugInfoFunc aFunction, TInt aParam, TRegion& aPreAllocatedReturnedRegion)const
100 //Attempt to fit the received data in the preexisting region buffer...
101 class XRegion:public TRegion
104 using TRegion::AppendRect;
105 // using TRegion::SetListSize;
106 using TRegion::RectangleListW;
108 { return iAllocedRects; }
109 void SetListSize(TInt aNewSize) //DANGER no error checking!!!
111 }& preAllocatedReturnedRegion=(XRegion&)aPreAllocatedReturnedRegion;
113 TInt reqSize=preAllocatedReturnedRegion.MaxSize();
114 const TElt* elements=preAllocatedReturnedRegion.RectangleListW();
115 TInt lenBytes=reqSize*sizeof(TElt);
116 TPtr8 pBuff((TUint8*)elements,lenBytes,lenBytes);
117 reqSize=DebugInfo(aFunction,aParam,pBuff,elements);
123 reqSize=preAllocatedReturnedRegion.MaxSize();
125 preAllocatedReturnedRegion.SetListSize(reqSize);
128 //If data does not fit in preexisting buffer
129 //Use a temp array instead
130 //Still try to block copy into the existing capacity
131 //I think this use of region copy is more efficient than appending,
132 //and definitely better than unioning the elements.
137 TElt* tempbuff=new TElt[reqSize];
140 reqSize=KErrNoMemory;
144 TInt lenBytes=reqSize*sizeof(TElt);
145 TPtr8 pBuff((TUint8*)elements,lenBytes,lenBytes);
146 TInt reqSize2=DebugInfo(aFunction,aParam,pBuff,elements);
151 RRegion r(reqSize,tempbuff); //note this region does not own its memory so should not be closed!
152 aPreAllocatedReturnedRegion.Copy(r);
153 if (aPreAllocatedReturnedRegion.CheckError())
154 reqSize=KErrNoMemory;
157 }while (reqSize>0 && elements==NULL && --breakLoop);
159 if (reqSize>=0 && elements==NULL)
161 preAllocatedReturnedRegion.ForceError();
162 reqSize=KErrTimedOut;
166 if (reqSize==KErrCancel)
168 preAllocatedReturnedRegion.Clear();
172 preAllocatedReturnedRegion.ForceError();