|
1 /* |
|
2 * Copyright (c) 2009 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 "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: CUIEngineEvent: This object executes test cases |
|
15 * from STIF Test Framework. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <e32svr.h> |
|
22 #include <stifinternal/UIEngineContainer.h> |
|
23 #include "UIEngineEvent.h" |
|
24 #include "Logging.h" |
|
25 |
|
26 |
|
27 // EXTERNAL DATA STRUCTURES |
|
28 // None |
|
29 |
|
30 // EXTERNAL FUNCTION PROTOTYPES |
|
31 // None |
|
32 |
|
33 // CONSTANTS |
|
34 // None |
|
35 |
|
36 // MACROS |
|
37 #ifdef LOGGER |
|
38 #undef LOGGER |
|
39 #endif |
|
40 #define LOGGER iUIEngine->iLogger |
|
41 |
|
42 |
|
43 // LOCAL CONSTANTS AND MACROS |
|
44 // None |
|
45 |
|
46 // MODULE DATA STRUCTURES |
|
47 // None |
|
48 |
|
49 // LOCAL FUNCTION PROTOTYPES |
|
50 // None |
|
51 |
|
52 // FORWARD DECLARATIONS |
|
53 // None |
|
54 |
|
55 |
|
56 // ==================== LOCAL FUNCTIONS ======================================= |
|
57 // None |
|
58 |
|
59 // ================= MEMBER FUNCTIONS ========================================= |
|
60 |
|
61 /* |
|
62 ------------------------------------------------------------------------------- |
|
63 |
|
64 Class: CUIEngineEvent |
|
65 |
|
66 Method: CUIEngineEvent |
|
67 |
|
68 Description: Default constructor |
|
69 |
|
70 C++ default constructor can NOT contain any code, that |
|
71 might leave. |
|
72 |
|
73 Parameters: None |
|
74 |
|
75 Return Values: None |
|
76 |
|
77 Errors/Exceptions: None |
|
78 |
|
79 Status: Draft |
|
80 |
|
81 ------------------------------------------------------------------------------- |
|
82 */ |
|
83 CUIEngineEvent::CUIEngineEvent( CUIEngine* aUIEngine) : |
|
84 CActive( CActive::EPriorityStandard ), |
|
85 iState( EEventIdle ), |
|
86 iUIEngine( aUIEngine ), |
|
87 iEventPckg( iEvent ) |
|
88 { |
|
89 __TRACE( KPrint, ( _L( "CUIEngineEvent::CUIEngineEvent") ) ); |
|
90 __ASSERT_ALWAYS( aUIEngine, User::Panic( _L("Null pointer"), KErrGeneral ) ); |
|
91 |
|
92 CActiveScheduler::Add( this ); |
|
93 } |
|
94 |
|
95 |
|
96 /* |
|
97 ------------------------------------------------------------------------------- |
|
98 |
|
99 Class: CUIEngineEvent |
|
100 |
|
101 Method: ConstructL |
|
102 |
|
103 Description: Symbian OS second phase constructor |
|
104 |
|
105 Symbian OS default constructor can leave. |
|
106 |
|
107 Parameters: None |
|
108 |
|
109 Return Values: None |
|
110 |
|
111 Errors/Exceptions: Leaves if called Open method returns error |
|
112 |
|
113 Status: Approved |
|
114 |
|
115 ------------------------------------------------------------------------------- |
|
116 */ |
|
117 void CUIEngineEvent::ConstructL() |
|
118 { |
|
119 |
|
120 } |
|
121 |
|
122 |
|
123 /* |
|
124 ------------------------------------------------------------------------------- |
|
125 |
|
126 Class: CUIEngineEvent |
|
127 |
|
128 Method: NewL |
|
129 |
|
130 Description: Two-phased constructor. |
|
131 |
|
132 Parameters: CUIEngineContainer* CUIEngineContainer: in: Pointer to CUIEngineContainer Interface |
|
133 TTestInfo& aTestInfo: in: Test info |
|
134 |
|
135 Return Values: CUIEngineEvent* : Pointer to created runner object |
|
136 |
|
137 Errors/Exceptions: Leaves if memory allocation for CUIEngineEvent fails |
|
138 Leaves if ConstructL leaves |
|
139 |
|
140 Status: Draft |
|
141 |
|
142 ------------------------------------------------------------------------------- |
|
143 */ |
|
144 CUIEngineEvent* CUIEngineEvent::NewL( CUIEngine* aUIEngine ) |
|
145 { |
|
146 CUIEngineEvent* self = |
|
147 new ( ELeave ) CUIEngineEvent( aUIEngine ); |
|
148 CleanupStack::PushL( self ); |
|
149 self->ConstructL(); |
|
150 CleanupStack::Pop(); |
|
151 return self; |
|
152 } |
|
153 |
|
154 |
|
155 /* |
|
156 ------------------------------------------------------------------------------- |
|
157 |
|
158 Class: CUIEngineEvent |
|
159 |
|
160 Method: ~CUIEngineEvent |
|
161 |
|
162 Description: Destructor |
|
163 |
|
164 Parameters: None |
|
165 |
|
166 Return Values: None |
|
167 |
|
168 Errors/Exceptions: None |
|
169 |
|
170 Status: Draft |
|
171 |
|
172 ------------------------------------------------------------------------------- |
|
173 */ |
|
174 CUIEngineEvent::~CUIEngineEvent() |
|
175 { |
|
176 |
|
177 __TRACE( KPrint, ( _L( "CUIEngineEvent::~CUIEngineEvent()") ) ); |
|
178 Cancel(); |
|
179 |
|
180 if( iState == EEventWaitCompleted ) |
|
181 { |
|
182 // Release event |
|
183 Release(); |
|
184 } |
|
185 |
|
186 } |
|
187 |
|
188 |
|
189 /* |
|
190 ------------------------------------------------------------------------------- |
|
191 |
|
192 Class: CUIEngineEvent |
|
193 |
|
194 Method: Request |
|
195 |
|
196 Description: Request event. |
|
197 |
|
198 Parameters: RTestCase& aTestCase: in: Handle to test case |
|
199 TFullTestResultPckg& aFullTestResultPckg: in: Handle to TFullTestResultPckg |
|
200 |
|
201 Return Values: None |
|
202 |
|
203 Errors/Exceptions: None |
|
204 |
|
205 Status: Draft |
|
206 |
|
207 ------------------------------------------------------------------------------- |
|
208 */ |
|
209 TInt CUIEngineEvent::Request( TDesC& aEventName, |
|
210 TUint32 aMaster, |
|
211 TUint32 aSlave ) |
|
212 { |
|
213 |
|
214 __TRACE( KPrint, ( _L( "CUIEngineEvent::Request %S"), &aEventName ) ); |
|
215 |
|
216 iState = EEventRequested; |
|
217 |
|
218 iMaster = aMaster; |
|
219 iSlave = aSlave; |
|
220 iEvent.SetType( TEventIf::EReqEvent ); |
|
221 iEvent.SetName( aEventName ); |
|
222 |
|
223 TRequestStatus status; |
|
224 iUIEngine->iTestEngine.Event( iEventPckg, status ); |
|
225 User::WaitForRequest( status ); |
|
226 |
|
227 if( status.Int() == KErrNone ) |
|
228 { |
|
229 // Enable event waiting |
|
230 iState = EEventWait; |
|
231 iEvent.SetType( TEventIf::EWaitEvent ); |
|
232 SetActive(); |
|
233 iUIEngine->iTestEngine.Event( iEventPckg, iStatus ); |
|
234 } |
|
235 return status.Int(); |
|
236 |
|
237 } |
|
238 |
|
239 /* |
|
240 ------------------------------------------------------------------------------- |
|
241 |
|
242 Class: CUIEngineEvent |
|
243 |
|
244 Method: Release |
|
245 |
|
246 Description: Release event. |
|
247 |
|
248 Parameters: RTestCase& aTestCase: in: Handle to test case |
|
249 TFullTestResultPckg& aFullTestResultPckg: in: Handle to TFullTestResultPckg |
|
250 |
|
251 Return Values: None |
|
252 |
|
253 Errors/Exceptions: None |
|
254 |
|
255 Status: Draft |
|
256 |
|
257 ------------------------------------------------------------------------------- |
|
258 */ |
|
259 TInt CUIEngineEvent::Release() |
|
260 { |
|
261 |
|
262 __TRACE( KPrint, ( _L( "CUIEngineEvent::Release %S"), &iEvent.Name() ) ); |
|
263 Cancel(); |
|
264 |
|
265 TRequestStatus status; |
|
266 // Release event |
|
267 iState = EEventReleased; |
|
268 iEvent.SetType( TEventIf::ERelEvent ); |
|
269 iUIEngine->iTestEngine.Event( iEventPckg, status ); |
|
270 User::WaitForRequest( status ); |
|
271 |
|
272 return status.Int(); |
|
273 |
|
274 } |
|
275 |
|
276 |
|
277 /* |
|
278 ------------------------------------------------------------------------------- |
|
279 |
|
280 Class: CUIEngineEvent |
|
281 |
|
282 Method: RunL |
|
283 |
|
284 Description: RunL handles completed requests. |
|
285 |
|
286 Parameters: None |
|
287 |
|
288 Return Values: None |
|
289 |
|
290 Errors/Exceptions: Leaves if iStatus is not KErrNone, error is handled in |
|
291 RunError called by CActiveObject |
|
292 |
|
293 Status: Draft |
|
294 |
|
295 ------------------------------------------------------------------------------- |
|
296 */ |
|
297 void CUIEngineEvent::RunL() |
|
298 { |
|
299 |
|
300 __TRACE( KPrint, ( _L( "CUIEngineEvent::RunL") ) ); |
|
301 |
|
302 // Error handled in RunError |
|
303 User::LeaveIfError ( iStatus.Int() ); |
|
304 |
|
305 switch( iState ) |
|
306 { |
|
307 case EEventWait: |
|
308 { |
|
309 // Create response |
|
310 CStifTFwIfProt* resp = CStifTFwIfProt::NewL(); |
|
311 CleanupStack::PushL( resp ); |
|
312 |
|
313 resp->CreateL(); |
|
314 resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgResponse ); |
|
315 resp->AppendId( iSlave ); |
|
316 resp->AppendId( iMaster ); |
|
317 resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote ); |
|
318 resp->Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdRequest ); |
|
319 resp->Append( CStifTFwIfProt::EventStatus, |
|
320 CStifTFwIfProt::EEventSet ); |
|
321 resp->Append( iEvent.Name() ); |
|
322 if( iEvent.EventType() == TEventIf::EState ) |
|
323 { |
|
324 resp->Append( CStifTFwIfProt::EventStatusParams, |
|
325 CStifTFwIfProt::EEventType, |
|
326 CStifTFwIfProt::EventType, |
|
327 TEventIf::EState ); |
|
328 } |
|
329 // Send response |
|
330 iUIEngine->RemoteMsg( NULL, resp->Message() ); |
|
331 CleanupStack::PopAndDestroy( resp ); |
|
332 |
|
333 if( iEvent.EventType() == TEventIf::EIndication ) |
|
334 { |
|
335 // Enable indication event waiting again |
|
336 iEvent.SetType( TEventIf::EWaitEvent ); |
|
337 SetActive(); |
|
338 iUIEngine->iTestEngine.Event( iEventPckg, iStatus ); |
|
339 } |
|
340 else // state event, set only once for one request |
|
341 { |
|
342 iState = EEventWaitCompleted; |
|
343 } |
|
344 } |
|
345 break; |
|
346 case EEventWaitCompleted: |
|
347 case EEventRequested: |
|
348 case EEventReleased: |
|
349 default: |
|
350 __TRACE( KError, ( _L( "CUIEngineEvent::RunL: Illegal state %d"), iState ) ); |
|
351 User::Leave( KErrGeneral ); |
|
352 } |
|
353 } |
|
354 |
|
355 /* |
|
356 ------------------------------------------------------------------------------- |
|
357 |
|
358 Class: CUIEngineEvent |
|
359 |
|
360 Method: DoCancel |
|
361 |
|
362 Description: Cancel active request. |
|
363 |
|
364 Parameters: None |
|
365 |
|
366 Return Values: None |
|
367 |
|
368 Errors/Exceptions: None |
|
369 |
|
370 Status: Draft |
|
371 |
|
372 ------------------------------------------------------------------------------- |
|
373 */ |
|
374 void CUIEngineEvent::DoCancel() |
|
375 { |
|
376 |
|
377 __TRACE( KPrint, ( _L( "CUIEngineEvent::DoCancel") ) ); |
|
378 TRequestStatus status; |
|
379 |
|
380 switch( iState ) |
|
381 { |
|
382 case EEventWait: |
|
383 // First cancel waiting |
|
384 iEvent.SetType( TEventIf::ECancelWait ); |
|
385 iUIEngine->iTestEngine.Event( iEventPckg, status ); |
|
386 User::WaitForRequest( status ); |
|
387 iState = EEventWaitCompleted; |
|
388 break; |
|
389 default: |
|
390 iUIEngine->iTestEngine.CancelAsyncRequest( ETestEngineEvent ); |
|
391 iState = EEventIdle; |
|
392 break; |
|
393 } |
|
394 |
|
395 } |
|
396 |
|
397 |
|
398 /* |
|
399 ------------------------------------------------------------------------------- |
|
400 |
|
401 Class: CUIEngineEvent |
|
402 |
|
403 Method: RunError |
|
404 |
|
405 Description: Handle errors from STIF TestFramework |
|
406 |
|
407 Parameters: TInt aError: in: Symbian OS error: Error code |
|
408 |
|
409 Return Values: TInt KErrNone: Always returned KErrNone |
|
410 |
|
411 Errors/Exceptions: None |
|
412 |
|
413 Status: Draft |
|
414 |
|
415 ------------------------------------------------------------------------------- |
|
416 */ |
|
417 TInt CUIEngineEvent::RunError( TInt aError ) |
|
418 { |
|
419 __TRACE( KPrint, ( _L( "CUIEngineEvent::RunError") ) ); |
|
420 |
|
421 switch( iState ) |
|
422 { |
|
423 case EEventRequested: |
|
424 case EEventWait: |
|
425 case EEventWaitCompleted: |
|
426 case EEventReleased: |
|
427 { |
|
428 // Create response |
|
429 CStifTFwIfProt* resp = NULL; |
|
430 TRAPD( err, resp = CStifTFwIfProt::NewL(); ); |
|
431 if( err != KErrNone ) |
|
432 { |
|
433 return KErrNone; |
|
434 } |
|
435 |
|
436 resp->CreateL(); |
|
437 resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgResponse ); |
|
438 resp->AppendId( iSlave ); |
|
439 resp->AppendId( iMaster ); |
|
440 resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote ); |
|
441 resp->Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdRequest ); |
|
442 resp->Append( CStifTFwIfProt::EventStatus, |
|
443 CStifTFwIfProt::EEventError ); |
|
444 resp->Append( iEvent.Name() ); |
|
445 resp->Append( CStifTFwIfProt::EventStatusParams, |
|
446 CStifTFwIfProt::EEventResult, |
|
447 aError ); |
|
448 |
|
449 // Send response |
|
450 iUIEngine->RemoteMsg( NULL, resp->Message() ); |
|
451 delete resp; |
|
452 } |
|
453 break; |
|
454 default: |
|
455 __TRACE( KError, ( _L( "CUIEngineEvent::RunError: Illegal state %d"), iState ) ); |
|
456 return aError; |
|
457 } |
|
458 |
|
459 return KErrNone; |
|
460 } |
|
461 |
|
462 |
|
463 /* |
|
464 ------------------------------------------------------------------------------- |
|
465 |
|
466 DESCRIPTION |
|
467 |
|
468 CActiveTimer: This object prints running seconds to console screen. |
|
469 |
|
470 ------------------------------------------------------------------------------- |
|
471 */ |
|
472 |
|
473 // ================= MEMBER FUNCTIONS ========================================= |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 // ================= OTHER EXPORTED FUNCTIONS ================================= |
|
479 // None |
|
480 |
|
481 // End of File |