|
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 related event queues |
|
15 // |
|
16 // |
|
17 |
|
18 #if !defined(__EVQUEUE_H__) |
|
19 #define __EVQUEUE_H__ |
|
20 |
|
21 #include <e32std.h> |
|
22 #include <e32base.h> |
|
23 #include <w32std.h> |
|
24 #include <graphics/wsgraphicdrawerinterface.h> |
|
25 |
|
26 class CWsClient; |
|
27 class CWsWindowRedraw; |
|
28 class CWsGraphicDrawer; |
|
29 |
|
30 enum TEventQueueWalkRet |
|
31 { |
|
32 EEventQueueWalkOk, |
|
33 EEventQueueWalkDeleteEvent, |
|
34 EEventQueueWalkRestart, |
|
35 }; |
|
36 class TWsEvent; |
|
37 |
|
38 typedef TEventQueueWalkRet (*EventQueueWalk)(TAny *aPtr, TWsEvent *aEvent); |
|
39 |
|
40 enum TWservEventPriorities |
|
41 { |
|
42 EEventPriorityHigh, |
|
43 EEventPriorityLow, |
|
44 }; |
|
45 |
|
46 struct TRedraw |
|
47 { |
|
48 CWsWindowRedraw *iRedraw; |
|
49 TUint iPriority; |
|
50 }; |
|
51 |
|
52 class CEventBase : public CBase |
|
53 { |
|
54 private: |
|
55 enum TEventSignalledState |
|
56 { |
|
57 EEventFlagSignalled=0x1, |
|
58 EEventFlagCancelled=0x2 |
|
59 }; |
|
60 public: |
|
61 CEventBase(CWsClient *aOwner); |
|
62 ~CEventBase(); |
|
63 void CancelRead(); |
|
64 void EventReadyCheck(); |
|
65 virtual void EventReady(const RMessagePtr2& aEventMsg); |
|
66 void GetData(TAny *aData, TInt aLen); |
|
67 protected: |
|
68 void SignalEvent(TInt aCode = KErrNone); |
|
69 inline TBool IsEventCancelled(); |
|
70 protected: |
|
71 TInt iEventSignalledState; |
|
72 CWsClient *iWsOwner; |
|
73 RMessagePtr2 iEventMsg; |
|
74 }; |
|
75 |
|
76 class CEventQueue : public CEventBase |
|
77 { |
|
78 private: |
|
79 enum {EExtraQueueSize=16}; |
|
80 enum {EMaxQueueSize=32}; |
|
81 enum {EMinQueueSize=2}; |
|
82 enum {EQueueGranularity=4}; |
|
83 enum TCompressMode |
|
84 { |
|
85 ECompressNoPurge, // Compress only free space |
|
86 ECompressPurge1, // Purge from only non-foreground queues |
|
87 ECompressPurge2, // Purge from all queues |
|
88 }; |
|
89 // Functions |
|
90 public: |
|
91 CEventQueue(CWsClient *aOwner); |
|
92 ~CEventQueue(); |
|
93 void ConstructL(); |
|
94 TBool QueueEvent(const TWsEvent &event); |
|
95 TBool QueueEvent(const TWsEvent &event, TWservEventPriorities aPriority); |
|
96 TBool QueueEvent(TUint32 aTarget, TInt aEvent); |
|
97 TBool CheckRoom(); |
|
98 void GetData(); |
|
99 void UpdateLastEvent(const TWsEvent &event); |
|
100 void RemoveEvent(TInt index); |
|
101 void PurgePointerEvents(); |
|
102 const TWsEvent *PeekLastEvent(); |
|
103 void WalkEventQueue(EventQueueWalk aFunc, TAny *aFuncParam); |
|
104 void MoveToFront(); |
|
105 static void Wait(); |
|
106 static void Signal(); |
|
107 static void InitStaticsL(); |
|
108 static void DeleteStaticsL(); |
|
109 //void LogUpDownEvents(TChar aChar); |
|
110 public:// from CEventBase |
|
111 void EventReady(const RMessagePtr2& aEventMsg); |
|
112 private: |
|
113 static void EventCopy(TWsEvent *aStart, TWsEvent *aEnd, TInt aNumEvents); |
|
114 static TInt RequiredQueueSize(TInt aNumConnections); |
|
115 void AdjustQueueSizeL(TInt aNewSize); |
|
116 void IncreaseQueueSize(TInt aNumSpaces); |
|
117 TInt FollowingGap() const; |
|
118 void Purge(); |
|
119 TInt PurgeInactiveEvents(const TInt& aSizeRequired); |
|
120 void Compress(TCompressMode aCompressMode); |
|
121 void AddQueueL(); |
|
122 void RemoveQueue(); |
|
123 TBool Expand(TWservEventPriorities aPriority); |
|
124 TBool doExpand(TCompressMode aCompressMode); |
|
125 TInt SqueezeUp(); |
|
126 void SqueezeDown(); |
|
127 void MoveUp(TInt aMove); |
|
128 void MoveDown(TInt aMove); |
|
129 TBool MoveDownAndExpand(TDblQueIter<CEventQueue> &aIter, TInt aExpand); |
|
130 #if defined(_DEBUG) |
|
131 void CheckQueue(); |
|
132 void ZapEvent(TWsEvent *aTarget); |
|
133 void ZapEvents(TWsEvent *aTarget, TInt aLen); |
|
134 #endif |
|
135 private: |
|
136 void QueueActive(); |
|
137 TWsEvent *EventPtr(TInt index); |
|
138 // Data |
|
139 TInt iHead; |
|
140 TInt iCount; |
|
141 TInt iQueueSize; |
|
142 TWsEvent *iEventPtr; |
|
143 TDblQueLink iLink; |
|
144 static RMutex iMutex; |
|
145 static TWsEvent iNullEvent; |
|
146 static TDblQue<CEventQueue> iQueueList; |
|
147 static TWsEvent *iGlobalEventQueue; |
|
148 static TInt iGlobalEventQueueSize; |
|
149 static TInt iNumConnections; |
|
150 }; |
|
151 |
|
152 class TWsRedrawEvent; |
|
153 |
|
154 class CRedrawQueue : public CEventBase |
|
155 { |
|
156 // Functions |
|
157 public: |
|
158 CRedrawQueue(CWsClient *aOwner); |
|
159 ~CRedrawQueue(); |
|
160 void ConstructL(); |
|
161 TBool TriggerRedraw(); |
|
162 void ReCalcOrder(); |
|
163 void AddInvalid(CWsWindowRedraw *redrawWin); |
|
164 void RemoveInvalid(CWsWindowRedraw *redrawWin); |
|
165 void GetData(); |
|
166 TUint RedrawPriority(CWsWindowRedraw *aRedrawWin); |
|
167 public:// from CEventBase |
|
168 void EventReady(const RMessagePtr2& aEventMsg); |
|
169 private: |
|
170 void DeleteFromQueue(TInt aIndex); |
|
171 void QueueActive(); |
|
172 TBool FindOutstandingRedrawEvent(CWsWindowRedraw& aRedraw, TWsRedrawEvent& aEvent); |
|
173 TBool FindWindowNeedingRedrawEvent(TWsRedrawEvent& aEvent); |
|
174 private: |
|
175 // Data |
|
176 CArrayFixSeg<TRedraw> *iRedraws; // List of windows and their areas that require redraws |
|
177 TBool iAllocError; |
|
178 TBool iRedrawTrigger; |
|
179 TKeyArrayFix *iKeyPriority; |
|
180 TKeyArrayFix *iKeyWindow; |
|
181 static TWsRedrawEvent iNullRedrawEvent; |
|
182 }; |
|
183 |
|
184 class CWsGraphicMessageQueue: public CEventBase |
|
185 { |
|
186 public: |
|
187 class CMessage: public CWsMessageData |
|
188 { |
|
189 public: |
|
190 static CMessage* New(const TDesC8& aData); |
|
191 ~CMessage(); |
|
192 public: // From CWsMessageData |
|
193 TPtrC8 Data() const; |
|
194 void Release(); |
|
195 private: |
|
196 CMessage(const TDesC8& aData); |
|
197 private: |
|
198 TPtr8 iData; |
|
199 }; |
|
200 public: |
|
201 CWsGraphicMessageQueue(CWsClient *aOwner); |
|
202 ~CWsGraphicMessageQueue(); |
|
203 void GetGraphicMessage(); |
|
204 void AbortMessage(TInt aError); |
|
205 void EventReady(const RMessagePtr2& aEventMsg); |
|
206 void Queue(CWsMessageData* aMessage); |
|
207 TInt TopClientHandle() const; |
|
208 private: |
|
209 CWsMessageData* iHead; |
|
210 CWsMessageData* iTail; |
|
211 CWsMessageData* Pop(); |
|
212 void GetDataWithHeader(TUint aHeader, const TDesC8& aData, TInt aDataLen); |
|
213 }; |
|
214 |
|
215 #endif |