windowing/windowserver/nga/SERVER/openwfc/CLIENT.H
changeset 0 5d03bc08d59c
child 33 25f95128741d
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 #include <e32hashtab.h>  //RHashMap
       
    33 
       
    34 class CWsWindowBase;
       
    35 class CWsClientWindow;
       
    36 class CWsPointerCursor;
       
    37 class CWsCustomTextCursor;
       
    38 class CWsSpriteBase;
       
    39 class DWsScreenDevice;
       
    40 class CScreen;
       
    41 class RHandleBase;
       
    42 class CWsGraphicDrawerObject;
       
    43 class CWsGraphicDrawer;
       
    44 class MWsElement;
       
    45 class TSurfaceConfiguration;
       
    46 class CWsRedrawMsgWindow;
       
    47 
       
    48 /** Server-side object for a client session.
       
    49 
       
    50 @internalComponent
       
    51 @released
       
    52 */
       
    53 class CWsClient : public CSession2, public MWsClient
       
    54 	{
       
    55 private:
       
    56 	friend class CWsRedrawMsgWindow;
       
    57 private:
       
    58 	class TWsCursorArrayItem;
       
    59 	enum{EObjectGranularity=5};
       
    60 	enum{ENoDefaultSystemPointerCursor=-1};
       
    61 public:
       
    62 	enum{EPanicLeave=1};
       
    63 public: // from MWsClient
       
    64 	TBool HasCapability(TCapability aCapability) const;
       
    65 	TSecureId SecureId() const;
       
    66 	TVendorId VendorId() const;
       
    67 public:
       
    68 	CWsClient(RThread aClient);
       
    69 	~CWsClient();
       
    70 	static void InitStaticsL();
       
    71 	static void DeleteStatics();
       
    72 	inline TBool NotClosing() const;
       
    73 	inline CWsObjectIx* ObjectIndex();
       
    74 
       
    75 	inline const RMessage2& ClientMessage() const;
       
    76 	
       
    77 	inline const RThread& Client() const;
       
    78 	static inline CWsClient* CurrentClient();
       
    79 	inline TInt ConnectionHandle() const;
       
    80 	inline DWsScreenDevice* PrimaryScreenDevice();
       
    81 	inline const DWsScreenDevice* PrimaryScreenDevice() const;
       
    82 	inline CScreen* Screen();
       
    83 	inline const CScreen* Screen() const;
       
    84 	static CWsPointerCursor* SystemPointerCursor(TInt aIndex);
       
    85 	static inline CWsPointerCursor* DefaultSystemPointerCursor();
       
    86 	static CWsCustomTextCursor* FindCustomTextCursor(TInt aIdentifier);
       
    87 	void SessionPanic(TClientPanic aReason) const;
       
    88 	
       
    89 	// Window object access from handle
       
    90 	void HandleToWindow(TInt aHandle, CWsWindowBase** pWin);
       
    91 	void HandleToClientWindow(TInt aHandle, CWsClientWindow** pWin);
       
    92 	
       
    93 	// Generic WsObject access from handle
       
    94 	CWsObject* HandleToObj(TInt aHandle, WH_HANDLES aType);
       
    95 	const CWsObject* HandleToObj(TInt aHandle, WH_HANDLES aType) const;
       
    96 	CWsObject* HandleToObjUntyped(TInt aHandle);
       
    97 	const CWsObject* HandleToObjUntyped(TInt aHandle) const;
       
    98 	
       
    99 	CWsGraphicDrawerObject* DrawerObject(const CWsGraphicDrawer* aDrawer);
       
   100 	const CWsGraphicDrawerObject* DrawerObject(const CWsGraphicDrawer* aDrawer) const;
       
   101 	
       
   102 	// Handle from object
       
   103 	inline TInt ObjectHandle(const CWsObject* aThis) const;
       
   104 	
       
   105 	// Queue access
       
   106 	inline CEventQueue* EventQueue();
       
   107 	inline const CEventQueue* EventQueue() const;
       
   108 	inline CRedrawQueue* RedrawQueue();
       
   109 	inline const CRedrawQueue* RedrawQueue() const;	
       
   110 	
       
   111 	// Execute client command from buffer
       
   112 	void ExecuteCommandL(TInt aOpcode, const TAny* aCmdData);
       
   113 	static const TUint8* EndOfCommandBuffer();
       
   114 	static const TPtrC BufferTPtr(TText* aStart,TInt aLen);
       
   115 	static TBool BufferTPtrGc(TText* aStart,TInt aLen,TPtrC& aPtr);
       
   116 	static const TPtrC8 BufferTPtr8(TUint8* aStart,TInt aLen);
       
   117 	
       
   118 	// Remote read data from client
       
   119 	void RemoteRead(TDes16& aDes, TInt aOffset);
       
   120 	void RemoteRead(TDes8& aDes, TInt aOffset);
       
   121 	void RemoteReadL(TDes16& aDes, TInt aOffset);
       
   122 	void RemoteReadL(TDes8& aDes, TInt aOffset);
       
   123 
       
   124 	// Send the reply to the client's request
       
   125 	void SetResponseHandle(RHandleBase* aHandle);
       
   126 	static void ReplyBuf(const TAny* aSource, TInt aLength);
       
   127 	static void ReplyBuf(const TDesC8 &aDes);
       
   128 	static void ReplyBuf(const TDesC16 &aDes);
       
   129 	static void ReplySize(const TSize &aSize);
       
   130 	static void ReplyPoint(const TPoint &aPoint);
       
   131 	static void ReplyRect(const TRect &aRect);
       
   132 	static void ReplyGroupName(HBufC* aName, TInt aMaxLength);
       
   133 	static void SetReply(TInt reply);
       
   134 	void RequestComplete(TRequestStatus*& aStatus, TInt aErr);
       
   135 	
       
   136 	// Panic or terminate the client
       
   137 	static void PanicCurrentClient(TClientPanic aPanic);
       
   138 	static TInt ReplyBufSpace()  ;
       
   139 	void PPanic(TClientPanic aPanic) const;
       
   140 	void SessionTerminate();
       
   141 	
       
   142 	// All events
       
   143 	inline void EventReady(const RMessagePtr2& aEventMsg);
       
   144 	
       
   145 	// Pointer events
       
   146 	inline void PurgePointerEvents();
       
   147 
       
   148 	// Key events
       
   149 	inline void PriorityKeyPressed(TInt aHandle, const TKeyData &aKey, TInt aScanCode);
       
   150 
       
   151 	// Notification of misc events
       
   152 	void AddNotificationL(TInt aKey, const RMessage2& aClientMsg);
       
   153 	void CompleteNotification(TInt aKey, TInt aReason);
       
   154 	inline void NotifyScreenDeviceDeleted(DWsScreenDevice* aDeletedScreenDevice);
       
   155 	
       
   156 	// Redraw
       
   157 	void TriggerRedraw();
       
   158 
       
   159 	// Misc
       
   160 	void UpdateWindowOrdinalPrioritys();
       
   161 	void SetClientPriority();	// boost when in foreground
       
   162 
       
   163 	void CreateDrawableSourceL(const TWsClCmdCreateDrawableSource& aDrawableSourceData);
       
   164 
       
   165 	//retry putting events on event queue
       
   166 	void SetRetryFlag(TEventCode aEventCode);
       
   167 	void RemoveRetryFlag(TEventCode aEventCode);
       
   168 	TBool RetryEvent(TEventCode aEventCode);
       
   169 
       
   170     inline void WgMsgQueueOverflow();// Set flag  window group message queue is overflow and has pending messages
       
   171 
       
   172 private: // from MWsClient
       
   173 	TInt SendMessage(const CWsGraphicDrawer* aOnBehalfOf, const TDesC8& aData);
       
   174 	TInt SendMessage(const CWsGraphicDrawer* aOnBehalfOf, CWsMessageData& aData);
       
   175 
       
   176 private: // from CSession2
       
   177 	void ServiceL(const RMessage2 &aMessage);
       
   178 	void ServiceError(const RMessage2& aMessage,TInt aError);
       
   179 private:
       
   180 	// Construction and destruction
       
   181 	inline TBool IsInitialised();
       
   182 	void StartInitializationL(TUint aConnectionHandle);
       
   183 	void CompleteInitializationL();
       
   184 	void InitialiseScreenDevices();
       
   185 	
       
   186 	// Service client commands by dispatching them to the object associated with the op code
       
   187 	void DoServiceL(const RMessage2& aMessage, TBool& aCompleteRequest);
       
   188 	void DoServiceCommandBuf();
       
   189 	static TInt DoContinueDeferredServiceOfCommandBuf(TAny* aClient);
       
   190 	void DispatchCommandsInBufL();
       
   191 	void CompleteMessage(const RMessage2& aMessage,TInt aReason);
       
   192 	
       
   193 	// Execute async client commands
       
   194 	void ExecuteAsyncClientCommandL(TInt aOpcode, const RMessage2& aMessage);
       
   195 	static inline TBool CheckBuffer(TInt aLength, TInt aMaxLength);
       
   196 	static TBool DebugEnforceRedrawCallingConvention();
       
   197 	
       
   198 	// Create new objects
       
   199 	void CreateNewWindowGroupL(const TWsClCmdCreateWindowGroup &aCmd);
       
   200 	void CreateNewWindowL(const TWsClCmdCreateWindow &aCmd);
       
   201 	void CreateNewAnimDllL(const TWsClCmdUnion &aParams);
       
   202 	void CreateNewSpriteL(const TWsClCmdCreateSprite &aCmd);
       
   203 	void CreateNewPointerCursorL(const TWsClCmdCreatePointerCursor &aCmd);
       
   204 	void CreateNewBitmapL(const TWsClCmdCreateBitmap &aCmd);
       
   205 	void CreateNewClickHandlerL(const TUid& aUid);
       
   206 	void CreateNewScreenDeviceL( TInt aDefaultScreenNumber, TUint aClientScreenDevicePointer);
       
   207 	
       
   208 	// Surface management
       
   209 	TInt RegisterSurface(const TWsClCmdUnion& pData);
       
   210 	void UnregisterSurface(const TWsClCmdUnion& pData);
       
   211 	
       
   212 	// Text cursor
       
   213 	static inline CWsCustomTextCursor*& TextCursor (TInt aPosition);
       
   214 	void StartSetCustomTextCursorL(const TWsClCmdCustomTextCursorData& aCmd);
       
   215 	void CompleteSetCustomTextCursorL(TInt aErr);
       
   216 	
       
   217 	// Pointer cursor
       
   218 	static inline CWsPointerCursor*& PointerCursor (TInt aPosition);
       
   219 	void SetSystemPointerCursorL(TInt aIndex, CWsPointerCursor* aCursor);
       
   220 	void ClearSystemPointerCursor(TInt aIndex);
       
   221 	void ClaimSystemPointerCursorListL();
       
   222 	void FreeSystemPointerCursorList();
       
   223 	void SetDefaultSystemPointerCursor(TInt aIndex);
       
   224 	static void DeleteSystemPointerListEntry(TInt aIndex);
       
   225 	
       
   226 	static TBool FindCursorArrayItem(CArrayFixFlat<TWsCursorArrayItem>* aCursorArray,
       
   227 									  TInt aIndex, TInt& aPosition);
       
   228 	
       
   229 	// Key events
       
   230 	inline void CancelClientRequestForPriorityKeyEvent();
       
   231 	inline void HandleClientRequestForPriorityKeyData();
       
   232 	inline void PriorityKeyEventReady(const RMessagePtr2& aEventMsg);
       
   233 	
       
   234 	// Redraw events
       
   235 	inline void CancelClientRequestForRedrawEvent();
       
   236 	inline void HandleClientRequestForRedrawData();
       
   237 	inline void RedrawEventReady(const RMessagePtr2& aEventMsg);
       
   238 	inline TBool ClientProcessingRedrawEvent();
       
   239 	
       
   240 	// Client event requests
       
   241 	inline void HandleClientRequestForEventData();
       
   242 	inline void CancelClientRequestForEventData();
       
   243 
       
   244 	// Debugging
       
   245 	void DebugInfoL(TInt aFunction, TInt aParam, TBool aHasReplyBuf) const;
       
   246 	void DebugInfoUnclassifiedL(TInt aFunction, TInt aParam, TBool aHasReplyBuf) const;
       
   247 	TInt DebugInfoClassifiedL(TInt aFunction, TInt aParam, TBool aHasReplyBuf) const;
       
   248 	TInt DebugInfoScreenUiL(TInt aFunction, TInt aParam, TInt aReplyBufSize, CScreen& aScreen) const;
       
   249 	TInt DebugInfoScreenElementSetL(TInt aFunction, TInt aParam, TInt aReplyBufSize,const CScreen& aScreen) const;
       
   250 	TInt DebugInfoElementSetWindowL(TInt aFunction, TInt aParam, TInt aReplyBufSize,const CScreen& aScreen) const;
       
   251 	TInt DebugInfoElementSetElementL(TInt aFunction, TInt aParam, TInt aReplyBufSize,const CScreen& aScreen) const;
       
   252 	TInt DebugReturnConfig(TInt aReplyBufSize, MWsElement* aElement, TInt aFlags=0)const;
       
   253 	TInt DebugReturnBase(TInt aReplyBufSize, const MWsElement* aElement) const;
       
   254 	TInt DebugReturnFlags(TInt aReplyBufSize, const MWsElement* aElement, TInt aFlags=0) const;
       
   255 	TInt DebugReturnRegion(TInt aReplyBufSize, const TRegion* aRegion, TInt aErrCodeIfEmpty) const;	
       
   256 	
       
   257 	// Misc
       
   258 	void SetComputeMode(RWsSession::TComputeMode aComputeMode);
       
   259 public:
       
   260 	static TWsCmdHeaderBase iCurrentCommand;
       
   261 private:
       
   262 	class TWsCursorArrayItem
       
   263 		{
       
   264 	public:
       
   265 		CWsSpriteBase* iCursor;
       
   266 		TInt iIndex;
       
   267 		};
       
   268 
       
   269 	enum TInternalFlags
       
   270 		{
       
   271 		EIsInitialised = 0x01,
       
   272 		EPanicClientAsSoonAsPossible = 0x02,		//The client should be panicked, but we have no way to panic him now
       
   273 		EClientIsClosing = 0x04,		//The client is closing down, so the screen device may no longer be valid
       
   274 		EFinishedProcessingCommands=0x08,	//Reached last command in command buffer or otherwised finihsed processing it
       
   275 		ERemoveKeyCode=0x10,		//Remove the Win32 keycode emulator only
       
   276 		ERetryDisplayEvent=0x20,
       
   277 		EIsPerformingRedrawEvent=0x40,         //The client is performing a RedrawEvent
       
   278 		EWgMsgQueueOverflow =0x80,
       
   279 		};
       
   280 private:
       
   281 	RThread iClient;
       
   282 	CScreen* iScreen;		//## This needs updating
       
   283 	TUint iConnectionHandle; // Connection ID, only needed for logging, could bin this
       
   284 	CEventQueue* iEventQueue;
       
   285 	CRedrawQueue* iRedrawQueue;
       
   286 	CPriorityKey* iPriorityKeyEvent;
       
   287 	CWsGraphicMessageQueue iGraphicMessageQueue;
       
   288 	RWsSession::TComputeMode iComputeMode;
       
   289 	CWsObjectIx* iObjectIndex;
       
   290 	DWsScreenDevice* iPrimaryScreenDevice;
       
   291 	TWsCursorArrayItem iTempCustomTextCursor;
       
   292 	mutable TInt iPanicReason;
       
   293 	mutable TUint iInternalFlags;
       
   294 	RMessage2 iClientMessage;
       
   295 	RHandleBase* iResponseHandle;
       
   296 	TInt iMessageIdSeq;
       
   297 
       
   298 	//Members for procerssing command buffer
       
   299 	static CWsClient* iCurrentClient;	// Client who's buffer is currently being processed
       
   300 	static TInt iReply;					// Value to reply
       
   301 	static TInt iReplyOffset;			// Offset into reply to write next block of data
       
   302 	static TBuf8<EClientBufferMaxSize> iCmdBuf; // Buffer contain a block of client commands
       
   303 	static CWsObject* iDestObj;			// Current object client command is for
       
   304 	static const TUint8* iNextCmd;		// Pointer in buffer to the next command to be processed
       
   305 	static CIdle* iMoreCommands;		// Active object responsible for executing more client commands
       
   306 
       
   307 	static TInt iDefaultSystemPointerCursorIndex;		// Negative when there isn't one
       
   308 	static CWsPointerCursor* iDefaultSystemPointerCursor;
       
   309 	static CArrayFixFlat<TWsCursorArrayItem>* iSystemPointerCursors;
       
   310 	static CWsClient* iSystemPointerCursorListOwner;
       
   311 	static CArrayFixFlat<TWsCursorArrayItem>* iTextCursorArray;
       
   312 	static TUint iConnectionId;
       
   313 	static TKeyArrayFix iCursorKey;
       
   314  	static TBool iDebug_EnforceRedrawCallingConvention;
       
   315 #if defined(__WINS__)
       
   316 public:
       
   317 	inline TBool RemoveKeyCode();
       
   318 #endif
       
   319 	};
       
   320 
       
   321 
       
   322 //
       
   323 // inlines			//
       
   324 //
       
   325 
       
   326 inline const RThread& CWsClient::Client() const
       
   327 	{return iClient;}
       
   328 
       
   329 inline void CWsClient::EventReady(const RMessagePtr2& aEventMsg)
       
   330 	{iEventQueue->EventReady(aEventMsg);}
       
   331 
       
   332 inline void CWsClient::HandleClientRequestForEventData()
       
   333     {iEventQueue->GetData();}
       
   334 
       
   335 inline void CWsClient::CancelClientRequestForEventData()
       
   336 	{iEventQueue->CancelRead();}
       
   337 
       
   338 inline void CWsClient::PurgePointerEvents()
       
   339 	{iEventQueue->PurgePointerEvents();}
       
   340 
       
   341 inline void CWsClient::RedrawEventReady(const RMessagePtr2& aEventMsg)
       
   342     {
       
   343     iInternalFlags&=~EIsPerformingRedrawEvent;
       
   344     iRedrawQueue->EventReady(aEventMsg);
       
   345     }
       
   346 
       
   347 inline TBool CWsClient::ClientProcessingRedrawEvent()
       
   348 	{return !!(iInternalFlags&EIsPerformingRedrawEvent);}
       
   349 
       
   350 inline void CWsClient::HandleClientRequestForRedrawData()
       
   351     {
       
   352     iInternalFlags|=EIsPerformingRedrawEvent;
       
   353     iRedrawQueue->GetData();
       
   354     }
       
   355 
       
   356 inline void CWsClient::CancelClientRequestForRedrawEvent()
       
   357 	{iRedrawQueue->CancelRead();}
       
   358 
       
   359 inline void CWsClient::PriorityKeyEventReady(const RMessagePtr2& aEventMsg)
       
   360     {iPriorityKeyEvent->EventReady(aEventMsg);}
       
   361 
       
   362 inline void CWsClient::CancelClientRequestForPriorityKeyEvent()
       
   363 	{iPriorityKeyEvent->CancelRead();}
       
   364 
       
   365 inline void CWsClient::HandleClientRequestForPriorityKeyData()
       
   366 	{iPriorityKeyEvent->GetData();}
       
   367 
       
   368 inline void CWsClient::PriorityKeyPressed(TInt aHandle, const TKeyData &aKey, TInt aScanCode)
       
   369 	{iPriorityKeyEvent->PriorityKey(aHandle,aKey,aScanCode);}
       
   370 
       
   371 inline TInt CWsClient::ObjectHandle(const CWsObject* aThis) const
       
   372 	{return(iObjectIndex->At(aThis));}
       
   373 
       
   374 #if defined(__WINS__)
       
   375 inline TBool CWsClient::RemoveKeyCode()
       
   376 	{return iInternalFlags&ERemoveKeyCode;}
       
   377 #endif
       
   378 
       
   379 inline CEventQueue* CWsClient::EventQueue()
       
   380 	{return(iEventQueue);}
       
   381 
       
   382 inline const CEventQueue* CWsClient::EventQueue() const
       
   383 	{return(iEventQueue);}
       
   384 
       
   385 inline CRedrawQueue* CWsClient::RedrawQueue()
       
   386 	{return(iRedrawQueue);}
       
   387 
       
   388 inline const CRedrawQueue* CWsClient::RedrawQueue() const
       
   389 	{return(iRedrawQueue);}
       
   390 
       
   391 inline CWsObjectIx* CWsClient::ObjectIndex()
       
   392 	{return(iObjectIndex);}
       
   393 
       
   394 inline TInt CWsClient::ConnectionHandle() const
       
   395 	{return(iConnectionHandle);}
       
   396 
       
   397 inline DWsScreenDevice* CWsClient::PrimaryScreenDevice()
       
   398 	{return(iPrimaryScreenDevice);}
       
   399 
       
   400 inline const DWsScreenDevice* CWsClient::PrimaryScreenDevice() const
       
   401 	{return(iPrimaryScreenDevice);}
       
   402 
       
   403 inline void CWsClient::NotifyScreenDeviceDeleted(DWsScreenDevice* aDeletedScreenDevice)
       
   404 	{
       
   405 	if (iPrimaryScreenDevice == aDeletedScreenDevice)
       
   406 		iPrimaryScreenDevice = NULL;
       
   407 	}
       
   408 
       
   409 inline CWsPointerCursor*& CWsClient::PointerCursor(TInt aIndex)
       
   410 	{return (CWsPointerCursor*&)(*iSystemPointerCursors)[aIndex].iCursor;}
       
   411 
       
   412 inline CWsCustomTextCursor*& CWsClient::TextCursor(TInt aIndex)
       
   413 	{return (CWsCustomTextCursor*&)(*iTextCursorArray)[aIndex].iCursor;}
       
   414 
       
   415 inline const RMessage2& CWsClient::ClientMessage() const
       
   416 	{return iClientMessage;}
       
   417 
       
   418 inline CScreen* CWsClient::Screen()
       
   419 	{return iScreen;}
       
   420 
       
   421 inline const CScreen* CWsClient::Screen() const
       
   422 	{return iScreen;}
       
   423 
       
   424 inline TBool CWsClient::NotClosing() const
       
   425 	{return !(iInternalFlags&EClientIsClosing);}
       
   426 
       
   427 inline CWsClient* CWsClient::CurrentClient()
       
   428 	{return iCurrentClient;}
       
   429 
       
   430 inline TBool CWsClient::CheckBuffer(TInt aLength, TInt aMaxLength)
       
   431 	{return TBool((aLength>=0) && (aLength<=aMaxLength));}
       
   432 
       
   433 inline TBool CWsClient::IsInitialised()
       
   434 	{return iInternalFlags&EIsInitialised; }
       
   435 
       
   436 inline void CWsClient::WgMsgQueueOverflow()
       
   437     {iInternalFlags |= EWgMsgQueueOverflow;}
       
   438 
       
   439 #endif