|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include "CIptvTestEventWaiter.h" |
|
21 #include "MIptvTestEventWaiterObserver.h" |
|
22 #include "CIptvTestEvent.h" |
|
23 #include "VCXTestLog.h" |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CIptvTestEventWaiter::NewL |
|
27 // ----------------------------------------------------------------------------- |
|
28 // |
|
29 EXPORT_C CIptvTestEventWaiter* CIptvTestEventWaiter::NewL(MIptvTestEventWaiterObserver& aObserver) |
|
30 { |
|
31 VCXLOGLO1(">>>CIptvTestEventWaiter::NewL"); |
|
32 CIptvTestEventWaiter* self = new (ELeave) CIptvTestEventWaiter(aObserver); |
|
33 |
|
34 CleanupStack::PushL( self ); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop( self ); |
|
37 VCXLOGLO1("<<<CIptvTestEventWaiter::NewL"); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CIptvTestEventWaiter::~CIptvTestEventWaiter |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 EXPORT_C CIptvTestEventWaiter::~CIptvTestEventWaiter() |
|
46 { |
|
47 VCXLOGLO1(">>>CIptvTestEventWaiter::~CIptvTestEventWaiter"); |
|
48 if( IsAdded() ) |
|
49 { |
|
50 Deque(); // calls also Cancel() |
|
51 } |
|
52 |
|
53 iTimer.Close(); |
|
54 |
|
55 Reset(); |
|
56 VCXLOGLO1("<<<CIptvTestEventWaiter::~CIptvTestEventWaiter"); |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CIptvTestEventWaiter::CheckTimeouts |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 EXPORT_C TInt CIptvTestEventWaiter::CheckTimeouts() |
|
64 { |
|
65 VCXLOGLO1(">>>CIptvTestEventWaiter::CheckTimeouts"); |
|
66 TTime now; |
|
67 now.UniversalTime(); |
|
68 |
|
69 TInt i; |
|
70 for(i=0; i<iEventQueue.Count();i++) |
|
71 { |
|
72 CIptvTestEvent* event = iEventQueue[i]; |
|
73 if( event->HasTimeouted( now ) ) |
|
74 { |
|
75 VCXLOGLO1("CIptvTestEventWaiter:: event timedout"); |
|
76 iObserver.EventWaiterErrorL( KErrTimedOut, *event ); |
|
77 VCXLOGLO1("<<<CIptvTestEventWaiter::CheckTimeouts"); |
|
78 return KErrTimedOut; |
|
79 } |
|
80 } |
|
81 |
|
82 for(i=0; i<iEventDump.Count();i++) |
|
83 { |
|
84 CIptvTestEvent* event = iEventDump[i]; |
|
85 if( event->HasTimeouted( now ) ) |
|
86 { |
|
87 VCXLOGLO1("CIptvTestEventWaiter:: event timedout"); |
|
88 iObserver.EventWaiterErrorL( KErrTimedOut, *event ); |
|
89 VCXLOGLO1("<<<CIptvTestEventWaiter::CheckTimeouts"); |
|
90 return KErrTimedOut; |
|
91 } |
|
92 } |
|
93 |
|
94 VCXLOGLO1("<<<CIptvTestEventWaiter::CheckTimeouts"); |
|
95 |
|
96 return KErrNone; |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CIptvTestEventWaiter::AddEvent |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C TInt CIptvTestEventWaiter::AddEvent(CIptvTestEvent* aEvent, TBool aSequential) |
|
104 { |
|
105 VCXLOGLO1(">>>CIptvTestEventWaiter::AddEvent"); |
|
106 |
|
107 if(aSequential) |
|
108 { |
|
109 // First event in queue, activate it |
|
110 if(iEventQueue.Count() <= 0) |
|
111 { |
|
112 aEvent->Activate(); |
|
113 } |
|
114 // Add event |
|
115 iEventQueue.Append( aEvent ); |
|
116 } |
|
117 else |
|
118 { |
|
119 // All events in dump are active |
|
120 iEventDump.Append( aEvent ); |
|
121 aEvent->Activate(); |
|
122 } |
|
123 |
|
124 if( !IsActive() ) |
|
125 { |
|
126 iTimer.After(iStatus, 1000000); // once in second |
|
127 SetActive(); |
|
128 } |
|
129 |
|
130 VCXLOGLO1("<<<CIptvTestEventWaiter::AddEvent"); |
|
131 return KErrNone; |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CIptvTestEventWaiter::EventHappened |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 EXPORT_C TInt CIptvTestEventWaiter::EventHappened(CIptvTestEvent* aEvent, CIptvTestEvent** aQueuedEvent) |
|
139 { |
|
140 VCXLOGLO1(">>>CIptvTestEventWaiter::EventHappened"); |
|
141 TBool eventFound = EFalse; |
|
142 |
|
143 // Check first from the queue. |
|
144 |
|
145 VCXLOGLO1("Event queue:"); |
|
146 |
|
147 for(TInt i=0; i<iEventQueue.Count();i++) |
|
148 { |
|
149 CIptvTestEvent* event = iEventQueue[i]; |
|
150 TBuf<32> name; |
|
151 event->GetName(name); |
|
152 VCXLOGLO3(" queue %d: %S, %d", i, &name); |
|
153 } |
|
154 |
|
155 //CheckTimeouts(); |
|
156 |
|
157 if(iEventQueue.Count() > 0) |
|
158 { |
|
159 CIptvTestEvent* event = iEventQueue[0]; |
|
160 TBuf<32> name; |
|
161 event->GetName(name); |
|
162 VCXLOGLO2(" - %S", &name); |
|
163 |
|
164 if( !eventFound && event->Compare( *aEvent ) ) |
|
165 { |
|
166 iEventQueue.Remove( 0 ); |
|
167 if(iEventQueue.Count() > 0) |
|
168 { |
|
169 iEventQueue[0]->Activate(); |
|
170 } |
|
171 iPastEvents.Append( event ); |
|
172 eventFound = ETrue; |
|
173 |
|
174 *aQueuedEvent = event; |
|
175 |
|
176 VCXLOGLO1("*Match*"); |
|
177 } |
|
178 } |
|
179 |
|
180 // Check if the event is in the dump, meaning it can happen any time. |
|
181 |
|
182 VCXLOGLO1("Event dump:"); |
|
183 |
|
184 if(!eventFound) |
|
185 { |
|
186 for(TInt i=0; i<iEventDump.Count();i++) |
|
187 { |
|
188 CIptvTestEvent* event = iEventDump[i]; |
|
189 |
|
190 TBuf<32> name; |
|
191 event->GetName(name); |
|
192 VCXLOGLO2(" - %S", &name); |
|
193 |
|
194 if( !eventFound && event->Compare( *aEvent ) ) |
|
195 { |
|
196 iEventDump.Remove( i ); |
|
197 iPastEvents.Append( event ); |
|
198 eventFound = ETrue; |
|
199 *aQueuedEvent = event; |
|
200 VCXLOGLO1("*Match*"); |
|
201 } |
|
202 } |
|
203 } |
|
204 |
|
205 // Event was found and there's no more events in queues. Message observer that all events are validated. |
|
206 |
|
207 if( eventFound && iEventQueue.Count() == 0 && iEventDump.Count() == 0 ) |
|
208 { |
|
209 iObserver.EventWaiterAllEventsValidated(); |
|
210 } |
|
211 |
|
212 if( !eventFound ) |
|
213 { |
|
214 VCXLOGLO1("CIptvTestEventWaiter:: Event not found from queues."); |
|
215 |
|
216 if(iEventQueue.Count() > 0) |
|
217 { |
|
218 CIptvTestEvent* event = iEventQueue[0]; |
|
219 *aQueuedEvent = event; |
|
220 } |
|
221 |
|
222 VCXLOGLO1("<<<CIptvTestEventWaiter::EventHappened"); |
|
223 return KErrNotFound; |
|
224 } |
|
225 |
|
226 VCXLOGLO1("<<<CIptvTestEventWaiter::EventHappened"); |
|
227 return KErrNone; |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CIptvTestEventWaiter::Reset |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 EXPORT_C TInt CIptvTestEventWaiter::Reset() |
|
235 { |
|
236 VCXLOGLO1(">>>CIptvTestEventWaiter::Reset"); |
|
237 iEventQueue.ResetAndDestroy(); |
|
238 iEventDump.ResetAndDestroy(); |
|
239 iPastEvents.ResetAndDestroy(); |
|
240 VCXLOGLO1("<<<CIptvTestEventWaiter::Reset"); |
|
241 return KErrNone; |
|
242 } |
|
243 |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CIptvTestEventWaiter::GetEventCount |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 EXPORT_C TInt CIptvTestEventWaiter::GetEventCount() |
|
250 { |
|
251 VCXLOGLO1(">>>CIptvTestEventWaiter::GetEventCount"); |
|
252 TInt count = 0; |
|
253 count += iEventQueue.Count(); |
|
254 count += iEventDump.Count(); |
|
255 VCXLOGLO2("<<<CIptvTestEventWaiter:: events in queue: %d", count); |
|
256 |
|
257 VCXLOGLO1("<<<CIptvTestEventWaiter::GetEventCount"); |
|
258 return count; |
|
259 } |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // CIptvTestEventWaiter::CIptvTestEventWaiter |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 CIptvTestEventWaiter::CIptvTestEventWaiter(MIptvTestEventWaiterObserver& aObserver) |
|
266 : CActive(CActive::EPriorityStandard), iObserver(aObserver) |
|
267 { |
|
268 |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CIptvTestEventWaiter::ConstructL |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 void CIptvTestEventWaiter::ConstructL() |
|
276 { |
|
277 VCXLOGLO1(">>>CIptvTestEventWaiter::ConstructL"); |
|
278 User::LeaveIfError(iTimer.CreateLocal()); |
|
279 CActiveScheduler::Add(this); |
|
280 VCXLOGLO1("<<<CIptvTestEventWaiter::ConstructL"); |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // CTestUtilConnectionWaiter::RunL() |
|
285 // |
|
286 // Handle request completion events |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 void CIptvTestEventWaiter::RunL() |
|
290 { |
|
291 //VCXLOGLO1(">>>CIptvTestEventWaiter::RunL"); |
|
292 |
|
293 // TInt statusCode = iStatus.Int(); |
|
294 |
|
295 CheckTimeouts(); |
|
296 |
|
297 // Start timer again if waiting for events |
|
298 |
|
299 if(iEventQueue.Count() > 0 || iEventDump.Count() > 0) |
|
300 { |
|
301 |
|
302 if( !IsActive() ) |
|
303 { |
|
304 iTimer.After(iStatus, 1000000); // once in second |
|
305 SetActive(); |
|
306 } |
|
307 } |
|
308 |
|
309 |
|
310 //VCXLOGLO1("<<<CIptvTestEventWaiter::RunL"); |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // CIptvTestEventWaiter::DoCancel() |
|
315 // |
|
316 // Cancels ongoing requests |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 void CIptvTestEventWaiter::DoCancel() |
|
320 { |
|
321 VCXLOGLO1(">>>CIptvTestEventWaiter::DoCancel"); |
|
322 iTimer.Cancel(); |
|
323 VCXLOGLO1("<<<CIptvTestEventWaiter::DoCancel"); |
|
324 } |
|
325 |
|
326 |
|
327 // End of File |