windowing/windowserver/nonnga/SERVER/CLIENT.H
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1999-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 // Definition of classes for the class that deals with client communication
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef __CLIENT_H__
       
    19 #define __CLIENT_H__
       
    20 
       
    21 #include <graphics/wsgraphicdrawerinterface.h>
       
    22 #include "WSGRAPHICDRAWERARRAY.H"
       
    23 
       
    24 #include <e32std.h>
       
    25 #include <e32base.h>
       
    26 #include <w32std.h>
       
    27 #include "w32cmd.h"
       
    28 #include "WSOBJIX.H"
       
    29 #include "EVQUEUE.H"
       
    30 #include "PRIKEY.H"
       
    31 #include "wstypes.h"
       
    32 
       
    33 class CWsWindowBase;
       
    34 class CWsClientWindow;
       
    35 class CWsPointerCursor;
       
    36 class CWsCustomTextCursor;
       
    37 class CWsSpriteBase;
       
    38 class DWsScreenDevice;
       
    39 class CScreen;
       
    40 class RHandleBase;
       
    41 class CWindowServer;
       
    42 class CWsGraphicDrawerObject;
       
    43 class CWsGraphicDrawer;
       
    44 
       
    45 class TWsCursorArrayItem
       
    46 	{
       
    47 public:
       
    48 	CWsSpriteBase *iCursor;
       
    49 	TInt iIndex;
       
    50 	};
       
    51 
       
    52 /** Server-side object for a client session.
       
    53 
       
    54 @internalComponent
       
    55 @released
       
    56 */
       
    57 class CWsClient : public CSession2, public MWsClient
       
    58 	{
       
    59 private:
       
    60 	enum{EObjectGranularity=5};
       
    61 	enum{ENoDefaultSystemPointerCursor=-1};
       
    62 public:
       
    63 	enum{EPanicLeave=1};
       
    64 public:
       
    65 	CWsClient(RThread aClient);
       
    66 	~CWsClient();
       
    67 	inline const RThread& Client() const;
       
    68 	inline CWindowServer& WindowServer();
       
    69 	void CommandL(TInt aOpcode, const TAny *aCmdData);
       
    70 	void StartInitializationL(TUint aConnectionHandle);
       
    71 	static const TUint8 *EndOfCommandBuffer();
       
    72 	static const TPtrC BufferTPtr(TText *aStart,TInt aLen);
       
    73 	static TBool BufferTPtrGc(TText* aStart,TInt aLen,TPtrC& aPtr);
       
    74 	static const TPtrC8 BufferTPtr8(TUint8* aStart,TInt aLen);
       
    75 	void CommandBufL();
       
    76 	static void ReplyBuf(const TAny *aSource, TInt aLength);
       
    77 	static void ReplyBuf(const TDesC8 &aDes);
       
    78 	static void ReplyBuf(const TDesC16 &aDes);
       
    79 	static void ReplySize(const TSize &aSize);
       
    80 	static void ReplyPoint(const TPoint &aPoint);
       
    81 	static void ReplyRect(const TRect &aRect);
       
    82 	static void SetReply(TInt reply);
       
    83 	static void PanicCurrentClient(TClientPanic aPanic);
       
    84 	void PPanic(TClientPanic aPanic) const;
       
    85 	void HandleToWindow(TInt handle,CWsWindowBase **pWin);
       
    86 	void HandleToClientWindow(TInt handle,CWsClientWindow **pWin);
       
    87 	inline CEventQueue *EventQueue() const;
       
    88 	inline CRedrawQueue *RedrawQueue() const;
       
    89 	inline CWsObjectIx *ObjectIndex();
       
    90 	CWsObject *HandleToObjUntyped(TInt aHandle);
       
    91 	CWsObject *HandleToObj(TInt aHandle, WH_HANDLES aType);
       
    92 	void RequestComplete(TRequestStatus * &aStatus, TInt aErr);
       
    93 //
       
    94 	inline void EventReady(const RMessagePtr2& aEventMsg);
       
    95 	inline void GetEventData();
       
    96 	inline void CancelEvent();
       
    97 	inline void PurgePointerEvents();
       
    98 
       
    99 	inline void RedrawEventReady(const RMessagePtr2& aEventMsg);
       
   100 	inline void CancelRedrawEvent();
       
   101 	inline void GetRedrawData();
       
   102 
       
   103 	inline void PriorityKeyEventReady(const RMessagePtr2& aEventMsg);
       
   104 	inline void CancelPriorityKeyEvent();
       
   105 	inline void GetPriorityKeyData();
       
   106 	inline void PriorityKeyPressed(TInt aHandle, const TKeyData &aKey, TInt aScanCode);
       
   107 
       
   108 	void TriggerRedraw();
       
   109 	void SessionPanic(TClientPanic aReason) const;
       
   110 	void SessionTerminate();
       
   111 	void UpdateWindowOrdinalPrioritys();
       
   112 	void CreateNewWindowGroupL(const TWsClCmdCreateWindowGroup &aCmd);
       
   113 	void CreateNewWindowL(const TWsClCmdCreateWindow &aCmd);
       
   114 	void CreateNewAnimDllL(const TWsClCmdUnion &aParams);
       
   115 //
       
   116 	void CreateNewSpriteL(const TWsClCmdCreateSprite &aCmd);
       
   117 	void CreateNewPointerCursorL(const TWsClCmdCreatePointerCursor &aCmd);
       
   118 	void StartSetCustomTextCursorL(const TWsClCmdCustomTextCursorData& aCmd);
       
   119 	void CompleteSetCustomTextCursorL(TInt aErr);
       
   120 	static CWsCustomTextCursor* FindCustomTextCursor(TInt aIdentifier);
       
   121 
       
   122 	void CreateNewScreenDeviceL( TInt aDefaultScreenNumber, TUint aClientScreenDevicePointer);
       
   123 	void CreateNewBitmapL(const TWsClCmdCreateBitmap &aCmd);
       
   124 	void CreateNewClickL(const TUid& aUid);
       
   125 //
       
   126 	void ReplyGroupName(HBufC *aName, TInt aMaxLength) const;
       
   127 	inline TInt ObjectHandle(const CWsObject *aThis);
       
   128 	void SetSystemPointerCursorL(TInt aIndex, CWsPointerCursor *aCursor);
       
   129 	void ClearSystemPointerCursor(TInt aIndex);
       
   130 	void ClaimSystemPointerCursorListL();
       
   131 	void FreeSystemPointerCursorList();
       
   132 	static CWsPointerCursor *SystemPointerCursor(TInt aIndex);
       
   133 	static inline CWsPointerCursor *DefaultSystemPointerCursor();
       
   134 	void SetDefaultSystemPointerCursor(TInt aIndex);
       
   135 	void SetComputeMode(RWsSession::TComputeMode aComputeMode);
       
   136 	void SetClientPriority();
       
   137 	inline TInt ConnectionHandle() const;
       
   138 	inline DWsScreenDevice *PrimaryScreenDevice() const;
       
   139  	inline void NotifyScreenDeviceDeleted(DWsScreenDevice* aDeletedScreenDevice);
       
   140 	inline CScreen* Screen() const;
       
   141 	inline TBool NotClosing() const;
       
   142 	inline const RMessage2& ClientMessage() const;
       
   143 	void RemoteRead(TDes16& aDes, TInt aOffset);
       
   144 	void RemoteRead(TDes8& aDes, TInt aOffset);
       
   145 	void RemoteReadL(TDes16& aDes, TInt aOffset);
       
   146 	void RemoteReadL(TDes8& aDes, TInt aOffset);
       
   147 	static void DeleteStatics();
       
   148 	void SetResponseHandle(RHandleBase* aHandle);
       
   149 
       
   150 	// from MWsClient
       
   151 	TBool HasCapability(TCapability aCapability) const;
       
   152 	TSecureId SecureId() const;
       
   153 	TVendorId VendorId() const;
       
   154 	TInt SendMessage(const CWsGraphicDrawer* aOnBehalfOf,const TDesC8& aData);
       
   155 	TInt SendMessage(const CWsGraphicDrawer* aOnBehalfOf,CWsMessageData& aData);
       
   156 
       
   157 	CWsGraphicDrawerObject* DrawerObject(const CWsGraphicDrawer* aDrawer);
       
   158 	const CWsGraphicDrawerObject* DrawerObject(const CWsGraphicDrawer* aDrawer) const;
       
   159 	static inline CWsClient* CurrentClient();
       
   160 	static inline TBool CheckBuffer(TInt aLength, TInt aMaxLength);
       
   161  	static TBool DebugEnforceRedrawCallingConvention();
       
   162 private: // from CSession2
       
   163 	void ServiceL(const RMessage2 &aMessage);
       
   164 	void ServiceError(const RMessage2& aMessage,TInt aError);
       
   165 private:
       
   166 	void CompleteInitializationL();
       
   167 	static void DeleteSystemPointerListEntry(TInt aIndex);
       
   168 	static TBool FindCursorArrayItem (CArrayFixFlat<TWsCursorArrayItem>* aCursorArray,
       
   169 									  TInt aIndex, TInt& aPosition);
       
   170 	static inline CWsPointerCursor*& PointerCursor (TInt aPosition);
       
   171 	static inline CWsCustomTextCursor*& TextCursor (TInt aPosition);
       
   172 	void CommandL(TInt aOpcode, const RMessage2& aMessage);
       
   173 	void DoServiceL(const RMessage2& aMessage, TBool& aCompleteRequest);
       
   174 	void CompleteMessage(const RMessage2& aMessage,TInt aReason);
       
   175 	void InitialiseScreenDevices();
       
   176 	inline TBool IsInitialised();
       
   177 	void DebugInfoL(TInt aFunction, TInt aParam, TBool aHasReplyBuf) const;
       
   178 public:
       
   179 	static TWsCmdHeaderBase iCurrentCommand;
       
   180 private:
       
   181 	enum TInternalFlags
       
   182 		{
       
   183 		EPanicClientAsSoonAsPossible	=0x01,		//The client should be panicked, but we have no way to panic him now
       
   184 		EClientIsClosing		=0x02,		//The client is closing down, so the screen device may no longer be valid
       
   185 		};
       
   186 private:	// Private data
       
   187 	RThread iClient;
       
   188 	TUint iConnectionHandle; // Connection ID, only needed for logging, could bin this
       
   189 	CEventQueue *iEventQueue;
       
   190 	CRedrawQueue *iRedrawQueue;
       
   191 	CPriorityKey *iPriorityKeyEvent;
       
   192 	CWsGraphicMessageQueue iGraphicMessageQueue;
       
   193 	RWsSession::TComputeMode iComputeMode;
       
   194 	CWsObjectIx *iObjectIndex;
       
   195 	DWsScreenDevice *iPrimaryScreenDevice;
       
   196 	TWsCursorArrayItem iTempCustomTextCursor;
       
   197 	CScreen* iScreen;		//## This needs updating
       
   198 	mutable TInt iPanicReason;
       
   199 	mutable TInt iInternalFlags;
       
   200 	RMessage2 iClientMessage;
       
   201 	RHandleBase* iResponseHandle;
       
   202 	TInt iMessageIdSeq;
       
   203 	TBool iIsInitialised;
       
   204 #if defined(_DEBUG)
       
   205 	TBool iLastCommand;
       
   206 #endif
       
   207 	static CWsClient *iCurrentClient;	// Client who's buffer is currently being processed
       
   208 	static TInt iReply;					// Value to reply
       
   209 	static TInt iReplyOffset;			// Offset into reply to write next block of data
       
   210 	static TInt iDefaultSystemPointerCursorIndex;		//Negative when there isn't one
       
   211 	static CWsPointerCursor *iDefaultSystemPointerCursor;
       
   212 	static CArrayFixFlat<TWsCursorArrayItem> *iSystemPointerCursors;
       
   213 	static CWsClient *iSystemPointerCursorListOwner;
       
   214 	static CArrayFixFlat<TWsCursorArrayItem> *iTextCursorArray;
       
   215 	static TBuf8<EClientBufferMaxSize> iCmdBuf;
       
   216 	static TUint iConnectionId;
       
   217  	static TBool iDebug_EnforceRedrawCallingConvention;
       
   218 #if defined(__WINS__)
       
   219 	TBool iRemoveKeyCode;
       
   220 public:
       
   221 	inline TBool RemoveKeyCode();
       
   222 #endif
       
   223 	};
       
   224 
       
   225 
       
   226 //
       
   227 // inlines			//
       
   228 //
       
   229 
       
   230 //
       
   231 inline const RThread& CWsClient::Client() const
       
   232 	{return iClient;}
       
   233 inline CWindowServer& CWsClient::WindowServer()
       
   234 	{return *reinterpret_cast<CWindowServer*>(const_cast<CServer2*>(Server()));}
       
   235 inline void CWsClient::EventReady(const RMessagePtr2& aEventMsg)
       
   236 	{iEventQueue->EventReady(aEventMsg);}
       
   237 inline void CWsClient::GetEventData()
       
   238     {iEventQueue->GetData();}
       
   239 inline void CWsClient::PurgePointerEvents()
       
   240 	{iEventQueue->PurgePointerEvents();}
       
   241 inline void CWsClient::CancelEvent()
       
   242 	{iEventQueue->CancelRead();}
       
   243 inline void CWsClient::RedrawEventReady(const RMessagePtr2& aEventMsg)
       
   244     {iRedrawQueue->EventReady(aEventMsg);}
       
   245 inline void CWsClient::GetRedrawData()
       
   246     {iRedrawQueue->GetData();}
       
   247 inline void CWsClient::CancelRedrawEvent()
       
   248 	{iRedrawQueue->CancelRead();}
       
   249 inline void CWsClient::PriorityKeyEventReady(const RMessagePtr2& aEventMsg)
       
   250     {iPriorityKeyEvent->EventReady(aEventMsg);}
       
   251 inline void CWsClient::CancelPriorityKeyEvent()
       
   252 	{iPriorityKeyEvent->CancelRead();}
       
   253 inline void CWsClient::GetPriorityKeyData()
       
   254 	{iPriorityKeyEvent->GetData();}
       
   255 inline void CWsClient::PriorityKeyPressed(TInt aHandle, const TKeyData &aKey, TInt aScanCode)
       
   256 	{iPriorityKeyEvent->PriorityKey(aHandle,aKey,aScanCode);}
       
   257 inline TInt CWsClient::ObjectHandle(const CWsObject *aThis)
       
   258 	{return(iObjectIndex->At(aThis));}
       
   259 #if defined(__WINS__)
       
   260 inline TBool CWsClient::RemoveKeyCode()
       
   261 	{return iRemoveKeyCode;}
       
   262 #endif
       
   263 //
       
   264 inline CEventQueue *CWsClient::EventQueue() const
       
   265 	{return(iEventQueue);}
       
   266 inline CRedrawQueue *CWsClient::RedrawQueue() const
       
   267 	{return(iRedrawQueue);}
       
   268 inline CWsObjectIx *CWsClient::ObjectIndex()
       
   269 	{return(iObjectIndex);}
       
   270 inline TInt CWsClient::ConnectionHandle() const
       
   271 	{return(iConnectionHandle);}
       
   272 inline DWsScreenDevice *CWsClient::PrimaryScreenDevice() const
       
   273 	{return(iPrimaryScreenDevice);}
       
   274 inline void CWsClient::NotifyScreenDeviceDeleted(DWsScreenDevice* aDeletedScreenDevice)
       
   275 	{
       
   276 	if (iPrimaryScreenDevice == aDeletedScreenDevice)
       
   277 		iPrimaryScreenDevice = NULL;
       
   278 	}
       
   279 inline CWsPointerCursor*& CWsClient::PointerCursor(TInt aIndex)
       
   280 	{return (CWsPointerCursor*&)(*iSystemPointerCursors)[aIndex].iCursor;}
       
   281 inline CWsCustomTextCursor*& CWsClient::TextCursor(TInt aIndex)
       
   282 	{return (CWsCustomTextCursor*&)(*iTextCursorArray)[aIndex].iCursor;}
       
   283 inline const RMessage2& CWsClient::ClientMessage() const
       
   284 	{return iClientMessage;}
       
   285 inline CScreen* CWsClient::Screen() const
       
   286 	{return iScreen;}
       
   287 inline TBool CWsClient::NotClosing() const
       
   288 	{return !(iInternalFlags&EClientIsClosing);}
       
   289 inline CWsClient* CWsClient::CurrentClient()
       
   290 	{return iCurrentClient;}
       
   291 inline TBool CWsClient::CheckBuffer(TInt aLength, TInt aMaxLength)
       
   292 	{return TBool((aLength>=0) && (aLength<=aMaxLength));}
       
   293 inline TBool CWsClient::IsInitialised()
       
   294 	{return iIsInitialised;}
       
   295 #endif