sl@0: // Copyright (c) 1999-2010 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: // Window server client side local header file sl@0: // sl@0: // sl@0: sl@0: #ifndef __CLIENT_H__ sl@0: #define __CLIENT_H__ sl@0: sl@0: #include sl@0: sl@0: #if defined(_DEBUG) && defined(__WINS__) sl@0: //#define __AUTO_FLUSH //Define this for test purposes only, it hard codes auto flushing sl@0: #endif sl@0: sl@0: /** Panics the client. This will result in the client thread being destroyed. */ sl@0: GLREF_C void Panic(TW32Panic aPanic); sl@0: GLREF_C void Assert(TW32Assert aPanic); sl@0: sl@0: class TReadDescriptorType; sl@0: class TWriteDescriptorType; sl@0: sl@0: class RWsBuffer sl@0: { sl@0: friend class RWsSession; sl@0: public: sl@0: enum bufferSizes sl@0: { sl@0: EDefBufferSize=EClientBufferSize, sl@0: EMinBufferSize=EClientBufferSize, sl@0: EMaxBufferSize=EClientBufferMaxSize sl@0: }; sl@0: public: sl@0: RWsBuffer(RWsSession *aSession); sl@0: void Close(); sl@0: void Destroy(); sl@0: TInt Open(); sl@0: TInt Connect(TUint32 handle); sl@0: TInt WriteReplyWs(TUint opcode); sl@0: TInt WriteReplyWs(const TAny *pData, TInt length,TUint opcode); sl@0: TInt WriteReplyWs(const TAny *pData, TInt length, const TAny *pData2, TInt length2, TUint opcode); sl@0: void SetBufferSizeL(TInt aBufSize); sl@0: void SetMaxBufferSizeL(TInt aMaxBufSize); sl@0: TInt Flush(const TIpcArgs* aIpcArgs=NULL,TBool aRequestFinish=EFalse); sl@0: TBool SetAutoFlush(TBool aState); sl@0: void Write(TInt aHandle, TUint aOpcode, const TAny *aData, TInt aLength, const TAny *aData2, TInt aLength2, const TIpcArgs* aIpcArgs=NULL); sl@0: void Write(TInt aHandle, TUint aOpcode, const TAny *aData, TInt aLength, const TIpcArgs* aIpcArgs=NULL); sl@0: void Write(TInt handle,TUint opcode); sl@0: void AppendData(const TAny *aData, TInt aLength, TBool aFinished); sl@0: TInt WriteReply(TInt handle,TUint opcode, const TIpcArgs* aIpcArgs=NULL); sl@0: TInt WriteReply(TInt handle,TUint opcode,const TAny *buf, TInt bufLen, const TIpcArgs* aIpcArgs=NULL); sl@0: TInt WriteReply(TInt handle,TUint opcode,const TAny *buf, TInt bufLen,const TAny *buf2, TInt buflen2, const TIpcArgs* aIpcArgs=NULL); sl@0: TInt WriteReplyP(TInt aHandle,TUint aOpcode,const TWriteDescriptorType& aReplyBuffer); sl@0: TInt WriteReplyP(TInt aHandle,TUint aOpcode,const TAny *aData,TInt aLength,const TWriteDescriptorType& aReplyBuffer); sl@0: TInt WriteReplyP(TInt aHandle,TUint aOpcode,const TAny *aData1,TInt aLengthData1,const TAny *aData2,TInt aLengthData2,const TWriteDescriptorType& aReplyBuffer); sl@0: TInt WriteReplyByProvidingRemoteReadAccess(TInt aHandle,TUint aOpcode,const TAny *aData, TInt aLength,const TReadDescriptorType& aRemoteReadBuffer); sl@0: sl@0: inline TInt BufferSize() const; sl@0: inline TBool IsEmpty() const; sl@0: inline RWsSession* Session() {return iSession;} sl@0: static void FlushAllBuffers(TInt aBitmapHandle); sl@0: void SetCallBack(); sl@0: void CancelCallBack(); sl@0: void AddToBitmapArray(TInt aBitmapHandle); sl@0: sl@0: void SetWsGraphicManager(CWsGraphic::CManager* aManager); sl@0: static CWsGraphic::CManager* WsGraphicManager(); sl@0: sl@0: void AsyncRequest(TInt aHandle, TUint aOpcode, TRequestStatus& aStatus); sl@0: sl@0: void EnableWindowSizeCacheL(); sl@0: inline TBool WindowSizeCacheEnabled() const; sl@0: inline void MarkWindowSizeCacheDirty(TInt aHandle); sl@0: inline void RefreshWindowSizeCache(TInt aHandle, const TSize& aNewSize); sl@0: inline TInt CachedWindowSize(TInt aHandle, TSize& aSize); sl@0: inline void DestroyWindowSizeCacheEntry(TInt aHandle); sl@0: sl@0: private: sl@0: TInt DoWrite(TInt aHandle, TUint aOpcode, TBool aFlush, const TIpcArgs* aIpcArgs, const TAny* aData1=NULL, TInt aLength1=0, const TAny* aData2=NULL, TInt aLength2=0); sl@0: inline void SetAndLimitMaxBufSize(TInt aMaxBufSize); sl@0: void ReAllocBufferL(TInt aNewSize); sl@0: TBool ReAllocBuffer(TInt aNewSize); sl@0: void GrowBuffer(TInt aRequiredSpace, TInt aMsgSize); sl@0: sl@0: private: sl@0: RWsSession *iSession; sl@0: CWsGraphic::CManager* iManager; sl@0: TBool iAutoFlush; sl@0: TPtr8 iBuf; sl@0: RWsBuffer *iNext; sl@0: TInt iPreviousHandle; sl@0: TInt iBufSize; // current buffer size, DoWrite can expand this up to iMaxBufize sl@0: TInt iMaxBufSize; // maximum buffer size, set by SetBufferSizeL or SetMaxBufferSizeL sl@0: #if defined(_DEBUG) sl@0: TInt iAppendDataLength; sl@0: #endif sl@0: private: //Added here as adding it to RWsSession breaks BC. sl@0: TInt iDirectAcessCount; sl@0: RArray iBitmapArray; sl@0: TBool iInvalidBitmapArray; sl@0: sl@0: class TWindowSizeCacheEntry sl@0: { sl@0: public: sl@0: inline TWindowSizeCacheEntry(const TSize& aSize); sl@0: public: sl@0: TSize iSize; sl@0: TBool iDirty; sl@0: }; sl@0: sl@0: RHashMap* iWindowSizeCache; sl@0: }; sl@0: sl@0: sl@0: inline TInt RWsBuffer::BufferSize() const sl@0: {return(iBuf.MaxLength());} sl@0: sl@0: inline TBool RWsBuffer::IsEmpty() const sl@0: {return iBuf.Length()==0;} sl@0: sl@0: inline RWsBuffer::TWindowSizeCacheEntry::TWindowSizeCacheEntry(const TSize& aSize) sl@0: : iSize(aSize), iDirty(EFalse) sl@0: { sl@0: } sl@0: sl@0: inline TBool RWsBuffer::WindowSizeCacheEnabled() const sl@0: { sl@0: return iWindowSizeCache ? ETrue : EFalse; sl@0: } sl@0: sl@0: inline void RWsBuffer::MarkWindowSizeCacheDirty(TInt aHandle) sl@0: { sl@0: __ASSERT_ALWAYS(iWindowSizeCache != NULL, Assert(EW32AssertWindowSizeCacheFailure)); sl@0: RWsBuffer::TWindowSizeCacheEntry* entry = iWindowSizeCache->Find(aHandle); sl@0: if (entry != NULL) sl@0: { sl@0: entry->iDirty = ETrue; sl@0: } sl@0: } sl@0: sl@0: inline void RWsBuffer::RefreshWindowSizeCache(TInt aHandle, const TSize& aNewSize) sl@0: { sl@0: __ASSERT_ALWAYS(iWindowSizeCache != NULL, Assert(EW32AssertWindowSizeCacheFailure)); sl@0: RWsBuffer::TWindowSizeCacheEntry* entry = iWindowSizeCache->Find(aHandle); sl@0: if (entry == NULL) sl@0: { sl@0: iWindowSizeCache->Insert(aHandle, RWsBuffer::TWindowSizeCacheEntry(aNewSize)); sl@0: } sl@0: else sl@0: { sl@0: entry->iSize = aNewSize; sl@0: entry->iDirty = EFalse; sl@0: } sl@0: } sl@0: sl@0: inline TInt RWsBuffer::CachedWindowSize(TInt aHandle, TSize& aSize) sl@0: { sl@0: __ASSERT_ALWAYS(iWindowSizeCache != NULL, Assert(EW32AssertWindowSizeCacheFailure)); sl@0: RWsBuffer::TWindowSizeCacheEntry* entry = iWindowSizeCache->Find(aHandle); sl@0: if ( entry && !(entry->iDirty) ) sl@0: { sl@0: aSize = entry->iSize; sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: // return KErrNotFound when either entry not found for aHandle, or entry is dirty sl@0: return KErrNotFound; sl@0: } sl@0: } sl@0: sl@0: inline void RWsBuffer::DestroyWindowSizeCacheEntry(TInt aHandle) sl@0: { sl@0: __ASSERT_ALWAYS(iWindowSizeCache != NULL, Assert(EW32AssertWindowSizeCacheFailure)); sl@0: TInt err = iWindowSizeCache->Remove(aHandle); sl@0: // If there is a window size cache entry, then err == KErrNone. sl@0: // Otherwise, there isn't a size cache entry, and err == KErrNotFound. sl@0: __ASSERT_DEBUG(err == KErrNone || err == KErrNotFound, Assert(EW32AssertWindowSizeCacheFailure)); sl@0: } sl@0: sl@0: sl@0: #endif