|
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 <Graphics/WSGRAPHICDRAWERINTERFACE.H> |
|
24 #include "W32STD.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, TInt aIntVal = 0); |
|
97 TBool CheckRoom(); |
|
98 void GetData(); |
|
99 void UpdateLastEvent(const TWsEvent &event); |
|
100 TBool UpdateLastPointerEvent(const TWsEvent &event); |
|
101 void RemoveEvent(TInt index); |
|
102 void PurgePointerEvents(); |
|
103 const TWsEvent* PeekLastEvent(); |
|
104 void WalkEventQueue(EventQueueWalk aFunc, TAny* aFuncParam); |
|
105 void MoveToFront(); |
|
106 static void Wait(); |
|
107 static void Signal(); |
|
108 static void InitStaticsL(); |
|
109 static void DeleteStaticsL(); |
|
110 //void LogUpDownEvents(TChar aChar); |
|
111 public:// from CEventBase |
|
112 void EventReady(const RMessagePtr2& aEventMsg); |
|
113 private: |
|
114 static void EventCopy(TWsEvent* aStart, TWsEvent* aEnd, TInt aNumEvents); |
|
115 static TInt RequiredQueueSize(TInt aNumConnections); |
|
116 void AdjustQueueSizeL(TInt aNewSize); |
|
117 void IncreaseQueueSize(TInt aNumSpaces); |
|
118 TInt FollowingGap() const; |
|
119 void Purge(); |
|
120 TInt PurgeInactiveEvents(const TInt& aSizeRequired); |
|
121 void Compress(TCompressMode aCompressMode); |
|
122 void AddQueueL(); |
|
123 void RemoveQueue(); |
|
124 TBool Expand(TWservEventPriorities aPriority); |
|
125 TBool doExpand(TCompressMode aCompressMode); |
|
126 TInt SqueezeUp(); |
|
127 void SqueezeDown(); |
|
128 void MoveUp(TInt aMove); |
|
129 void MoveDown(TInt aMove); |
|
130 TBool MoveDownAndExpand(TDblQueIter<CEventQueue> &aIter, TInt aExpand); |
|
131 #if defined(_DEBUG) |
|
132 void CheckQueue(); |
|
133 void ZapEvent(TWsEvent* aTarget); |
|
134 void ZapEvents(TWsEvent* aTarget, TInt aLen); |
|
135 #endif |
|
136 private: |
|
137 void QueueActive(); |
|
138 TWsEvent* EventPtr(TInt index); |
|
139 void RemoveEvent(TWsEvent* aEvToRemove); |
|
140 inline void IncEventPointer(TWsEvent*& aEventPtr); |
|
141 inline void DecEventPointer(TWsEvent*& aEventPtr); |
|
142 void PurgeEventPairs(TWsEvent* aEventToPurge, TPointerEvent::TType aMatchingType, TPointerEvent::TType aSearchTerminator); |
|
143 TWsEvent* NextPointerEvent(TWsEvent* aBaseEvent); |
|
144 TBool CheckPurgePointerEvent(TWsEvent* aEventToPurge); |
|
145 private: |
|
146 /** Position of head in local queue relative to iEventPtr. |
|
147 First event to send to the Client. */ |
|
148 TInt iHead; |
|
149 |
|
150 /** Number of events waiting in local queue */ |
|
151 TInt iCount; |
|
152 |
|
153 /** Size of local queue = maximum number of events */ |
|
154 TInt iQueueSize; |
|
155 |
|
156 /** Beginning of local queue */ |
|
157 TWsEvent* iEventPtr; |
|
158 |
|
159 /** Used by iQueueList to link local queues */ |
|
160 TDblQueLink iLink; |
|
161 |
|
162 /** Mutex for operations on global event queue */ |
|
163 static RMutex iMutex; |
|
164 |
|
165 /** Always filled with zeros */ |
|
166 static TWsEvent iNullEvent; |
|
167 |
|
168 /** List of event queues */ |
|
169 static TDblQue<CEventQueue> iQueueList; |
|
170 |
|
171 /** Global queue that keeps all events queues */ |
|
172 static TWsEvent* iGlobalEventQueue; |
|
173 |
|
174 /** Size of global queue */ |
|
175 static TInt iGlobalEventQueueSize; |
|
176 |
|
177 /** Number of event queues */ |
|
178 static TInt iNumConnections; |
|
179 }; |
|
180 |
|
181 class TWsRedrawEvent; |
|
182 |
|
183 class CRedrawQueue : public CEventBase |
|
184 { |
|
185 // Functions |
|
186 public: |
|
187 CRedrawQueue(CWsClient *aOwner); |
|
188 ~CRedrawQueue(); |
|
189 void ConstructL(); |
|
190 TBool TriggerRedraw(); |
|
191 void ReCalcOrder(); |
|
192 void AddInvalid(CWsWindowRedraw *redrawWin); |
|
193 void RemoveInvalid(CWsWindowRedraw *redrawWin); |
|
194 void GetData(); |
|
195 TUint RedrawPriority(CWsWindowRedraw *aRedrawWin); |
|
196 public:// from CEventBase |
|
197 void EventReady(const RMessagePtr2& aEventMsg); |
|
198 private: |
|
199 void DeleteFromQueue(TInt aIndex); |
|
200 void QueueActive(); |
|
201 TBool FindOutstandingRedrawEvent(CWsWindowRedraw& aRedraw, TWsRedrawEvent& aEvent); |
|
202 TBool FindWindowNeedingRedrawEvent(TWsRedrawEvent& aEvent); |
|
203 private: |
|
204 // Data |
|
205 CArrayFixSeg<TRedraw> *iRedraws; // List of windows and their areas that require redraws |
|
206 TBool iAllocError; |
|
207 TBool iRedrawTrigger; |
|
208 TKeyArrayFix *iKeyPriority; |
|
209 TKeyArrayFix *iKeyWindow; |
|
210 static TWsRedrawEvent iNullRedrawEvent; |
|
211 }; |
|
212 |
|
213 class CWsGraphicMessageQueue: public CEventBase |
|
214 { |
|
215 public: |
|
216 class CMessage: public CWsMessageData |
|
217 { |
|
218 public: |
|
219 static CMessage* New(const TDesC8& aData); |
|
220 ~CMessage(); |
|
221 public: // From CWsMessageData |
|
222 TPtrC8 Data() const; |
|
223 void Release(); |
|
224 private: |
|
225 CMessage(const TDesC8& aData); |
|
226 private: |
|
227 TPtr8 iData; |
|
228 }; |
|
229 public: |
|
230 CWsGraphicMessageQueue(CWsClient *aOwner); |
|
231 ~CWsGraphicMessageQueue(); |
|
232 void GetGraphicMessage(); |
|
233 void AbortMessage(TInt aError); |
|
234 void EventReady(const RMessagePtr2& aEventMsg); |
|
235 void Queue(CWsMessageData* aMessage); |
|
236 TInt TopClientHandle() const; |
|
237 private: |
|
238 CWsMessageData* iHead; |
|
239 CWsMessageData* iTail; |
|
240 CWsMessageData* Pop(); |
|
241 void GetDataWithHeader(TUint aHeader, const TDesC8& aData, TInt aDataLen); |
|
242 }; |
|
243 |
|
244 #endif |