|
1 /* |
|
2 * Copyright (c) 2007 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: This is the model class for the Browser Test Plugin, which |
|
15 * tests HTTP functionality. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // System Include Files |
|
21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
22 #include <logfilterandeventconstants.hrh> |
|
23 #endif |
|
24 #include <centralrepository.h> // CRepository |
|
25 #include <cmmanager.h> // RCmManager |
|
26 #include <cmdestination.h> // RCmDestination |
|
27 #include <cmconnectionmethod.h> // RCmConnectionMethod |
|
28 #include <cmpluginpacketdatadef.h> // Connection Manager Defs |
|
29 #include <cmconnectionmethoddef.h> // Connection Manager Defs |
|
30 #include <es_sock.h> // RSocketServ, RConnection |
|
31 #include <stringpool.h> // RStringPool |
|
32 #include <httpstringconstants.h> // HTTP Strings |
|
33 #include <http/rhttpconnectioninfo.h> // RHTTPConnectionInfo |
|
34 #include <http/rhttpsession.h> // RHTTPSession |
|
35 #include <http/rhttptransaction.h> // RHTTPTransaction |
|
36 #include <http/thttpevent.h> // THTTPEvent |
|
37 #include <uri8.h> // TUriParser8 |
|
38 #include <logwrap.h> // CLogEvent |
|
39 #include <logcli.h> // CLogFilter |
|
40 #include <DiagResultsDatabaseItem.h> // CDiagResultsDatabaseItem |
|
41 #include <DiagFrameworkDebug.h> // Debugging Macros |
|
42 #include <diaglogeventeraser.h> // CDiagLogEventEraser |
|
43 #include <commdb.h> |
|
44 // User Include Files |
|
45 #include "diagbrowserpluginmodel.h" // CDiagBrowserPluginModel |
|
46 #include "diagbrowserpluginmodelobserver.h" // CDiagBrowserPluginModelObserver |
|
47 #include "diagbrowserpluginprivatecrkeys.h" // CenRep keys |
|
48 #include "diagbrowserplugin.pan" // Panic |
|
49 #include "diagbrowserplugin.hrh" |
|
50 |
|
51 #include <devdiagbrowserpluginrsc.rsg> |
|
52 // Local Constants |
|
53 const TInt KConnArrayGranularity = ( 3 ); |
|
54 const TInt KMicroSecondsInMilliseconds = ( 1000 ); |
|
55 const TInt KHttpResponseCodeOk = ( 200 ); |
|
56 #ifdef __WINS__ |
|
57 const TInt KEmulatorDynamicIpApId = ( 11 ); |
|
58 #endif // __WINS__ |
|
59 |
|
60 |
|
61 // ============================ GLOBAL FUNCTIONS ============================= |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // Static two-phase constructor. |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CDiagBrowserPluginModel* CDiagBrowserPluginModel::NewL( |
|
68 MDiagBrowserPluginModelObserver& aObserver ) |
|
69 { |
|
70 LOGSTRING( "CDiagBrowserPluginModel::NewL()" ) |
|
71 |
|
72 CDiagBrowserPluginModel* self = new( ELeave ) CDiagBrowserPluginModel( |
|
73 aObserver ); |
|
74 CleanupStack::PushL( self ); |
|
75 self->ConstructL(); |
|
76 CleanupStack::Pop( self ); |
|
77 return self; |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // Destructor. |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 CDiagBrowserPluginModel::~CDiagBrowserPluginModel() |
|
85 { |
|
86 LOGSTRING( "CDiagBrowserPluginModel::~CDiagBrowserPluginModel()" ) |
|
87 |
|
88 // Stop any outstanding requests. |
|
89 Cancel(); |
|
90 |
|
91 // Free memory reserved by the model. |
|
92 delete iTimer; |
|
93 delete iLogEraser; |
|
94 delete iWaitDialog; |
|
95 // Close any open sessions. |
|
96 iHttpTransaction.Close(); |
|
97 iHttpSession.Close(); |
|
98 iConnection.Close(); |
|
99 iSocketServ.Close(); |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // Initiates the browser test. |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 void CDiagBrowserPluginModel::RunBrowserTestL() |
|
107 { |
|
108 LOGSTRING( "CDiagBrowserPluginModel::RunBrowserTestL()" ) |
|
109 |
|
110 // Mark the start time for removing the logs. |
|
111 iStartTime.UniversalTime(); |
|
112 iRetryCount = 0; |
|
113 iTimerCalled = 0; |
|
114 // Read Central Repository keys. |
|
115 if ( !ReadCenRepKeysL() ) |
|
116 { |
|
117 HandleTestEndL( CDiagResultsDatabaseItem::EFailed ); |
|
118 return; |
|
119 } |
|
120 |
|
121 /* Read APN data. |
|
122 GetConnectionMethodL( iPrimaryConnection ); |
|
123 GetConnectionMethodL( iSecondaryConnection );*/ |
|
124 //iTimeoutValue = 30000; |
|
125 // Open the connection. |
|
126 if ( !OpenAndStartConnectionL() ) |
|
127 { |
|
128 HandleTestEndL( CDiagResultsDatabaseItem::EFailed ); |
|
129 return; |
|
130 } |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // Returns the total number of execution steps. |
|
135 // --------------------------------------------------------------------------- |
|
136 TUint CDiagBrowserPluginModel::TotalSteps() |
|
137 { |
|
138 LOGSTRING( "CDiagBrowserPluginModel::TotalSteps()" ) |
|
139 return EDiagBrowserStateMax; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // The default constructor. |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 CDiagBrowserPluginModel::CDiagBrowserPluginModel( |
|
147 MDiagBrowserPluginModelObserver& aObserver ) |
|
148 : CActive( EPriorityStandard ), |
|
149 iObserver( aObserver ) |
|
150 { |
|
151 LOGSTRING( "CDiagBrowserPluginModel::CDiagBrowserPluginModel()" ) |
|
152 CActiveScheduler::Add( this ); |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // The second phase constructor. |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CDiagBrowserPluginModel::ConstructL() |
|
160 { |
|
161 LOGSTRING( "CDiagBrowserPluginModel::ConstructL()" ) |
|
162 |
|
163 // Open the connection to the Socket Server. |
|
164 User::LeaveIfError( iSocketServ.Connect() ); |
|
165 User::LeaveIfError( iConnection.Open( iSocketServ ) ); |
|
166 idialogOn = EFalse; idialogDismissed = EFalse; |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // Reads and stores the browser test's Central Repository Keys. |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 TBool CDiagBrowserPluginModel::ReadCenRepKeysL() |
|
174 { |
|
175 LOGSTRING( "CDiagBrowserPluginModel::ReadCenRepKeysL()" ) |
|
176 |
|
177 // Create a Central Repository object. |
|
178 CRepository* repository = CRepository::NewLC( |
|
179 KCRUidDiagBrowserTestPlugin ); |
|
180 |
|
181 // Get the data. |
|
182 /* if ( repository->Get( KDiagBrowserApnPrimary, |
|
183 iPrimaryConnection.iApn ) != KErrNone || |
|
184 repository->Get( KDiagBrowserApnSecondary, |
|
185 iSecondaryConnection.iApn ) != KErrNone || |
|
186 repository->Get( KDiagBrowserProxyAddress, |
|
187 iProxyAddress ) != KErrNone || |
|
188 repository->Get( KDiagBrowserProxyPort, |
|
189 iProxyPort ) != KErrNone ||*/ |
|
190 if( repository->Get( KDiagBrowserResponseTimeout, |
|
191 iTimeoutValue ) != KErrNone || |
|
192 repository->Get( KDiagBrowserUri, |
|
193 iUri ) != KErrNone ) |
|
194 { |
|
195 LOGSTRING( "CDiagBrowserPluginModel::ReadCenRepKeysL() - CenRep read" |
|
196 L" failed." ) |
|
197 |
|
198 CleanupStack::PopAndDestroy( repository ); |
|
199 return EFalse; |
|
200 } |
|
201 |
|
202 /* LOGSTRING3( |
|
203 "CDiagBrowserPluginModel::ReadCenRepKeysL() - Primary APN '%S'" |
|
204 L" Secondary APN '%S'", |
|
205 &iPrimaryConnection.iApn, |
|
206 &iSecondaryConnection.iApn ) |
|
207 |
|
208 LOGSTRING3( |
|
209 "CDiagBrowserPluginModel::ReadCenRepKeysL() - Proxy '%S:%d'", |
|
210 &iProxyAddress, |
|
211 iProxyPort )*/ |
|
212 |
|
213 LOGSTRING3( |
|
214 "CDiagBrowserPluginModel::ReadCenRepKeysL() - Timeout %d, Uri '%S'", |
|
215 iTimeoutValue, |
|
216 &iUri ) |
|
217 |
|
218 CleanupStack::PopAndDestroy( repository ); |
|
219 return ETrue; |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // Finds the connection method that corresponds to the data supplied in the |
|
224 // argument. |
|
225 // --------------------------------------------------------------------------- |
|
226 // |
|
227 void CDiagBrowserPluginModel::GetConnectionMethodL( |
|
228 TBrowserConnectionMethodData& aData ) |
|
229 { |
|
230 LOGSTRING( "CDiagBrowserPluginModel::GetConnectionMethodL()" ) |
|
231 |
|
232 // Look for matching connection methods. |
|
233 RCmManager connManager; |
|
234 connManager.OpenLC(); |
|
235 |
|
236 // Get a list of all the destinations. |
|
237 RArray< TUint32 > connArray = RArray< TUint32 >( KConnArrayGranularity ); |
|
238 CleanupClosePushL( connArray ); |
|
239 connManager.AllDestinationsL( connArray ); |
|
240 |
|
241 // Look through all the destinations' connection methods and see if any of |
|
242 // them match the CenRep data. |
|
243 for ( TInt i = 0; i < connArray.Count() && !aData.iIsValid ; i++ ) |
|
244 { |
|
245 RCmDestination destination = connManager.DestinationL( |
|
246 connArray[ i ] ); |
|
247 CleanupClosePushL( destination ); |
|
248 |
|
249 LOGSTRING4( "CDiagBrowserPluginModel::GetConnectionMethodL() -" |
|
250 L" Destination %d / %d, %d method(s)", |
|
251 i + 1, |
|
252 connArray.Count(), |
|
253 destination.ConnectionMethodCount() ) |
|
254 |
|
255 // Don't use any hidden destinations, because they are not visible to |
|
256 // the user. |
|
257 if ( destination.IsHidden() ) |
|
258 { |
|
259 LOGSTRING( "CDiagBrowserPluginModel::GetConnectionMethodL() -" |
|
260 L" Skipping hidden destination" ) |
|
261 CleanupStack::PopAndDestroy(); // destination |
|
262 continue; |
|
263 } |
|
264 for ( TInt j = 0; |
|
265 j < destination.ConnectionMethodCount() && !aData.iIsValid; |
|
266 j++ ) |
|
267 { |
|
268 RCmConnectionMethod method = destination.ConnectionMethodL( j ); |
|
269 CleanupClosePushL( method ); |
|
270 |
|
271 // This call is trapped because not all connection methods support |
|
272 // the data we're querying, and the leave should not be propagated |
|
273 // up because that would not be a reason for test failure. |
|
274 TRAP_IGNORE( CheckConnectionMatchL( method, aData ) ) |
|
275 CleanupStack::PopAndDestroy(); // method |
|
276 } |
|
277 |
|
278 CleanupStack::PopAndDestroy(); // destination |
|
279 } |
|
280 |
|
281 // Get a list of all the uncategorized connection methods. |
|
282 connArray.Reset(); |
|
283 connManager.ConnectionMethodL( connArray ); |
|
284 LOGSTRING2( "CDiagBrowserPluginModel::GetConnectionMethodL() -" |
|
285 L" Checking %d uncategorized method(s)", |
|
286 connArray.Count() ) |
|
287 |
|
288 // Look through all the uncategorized connection methods and see if any |
|
289 // of them match match the CenRep data. |
|
290 for ( TInt i = 0; i < connArray.Count() && !aData.iIsValid; i++ ) |
|
291 { |
|
292 RCmConnectionMethod method = connManager.ConnectionMethodL( |
|
293 connArray[ i ] ); |
|
294 CleanupClosePushL( method ); |
|
295 |
|
296 // This call is trapped because not all connection methods support |
|
297 // the data we're querying, and the leave should not be propagated |
|
298 // up because that would not be a reason for test failure. |
|
299 TRAP_IGNORE( CheckConnectionMatchL( method, aData ) ) |
|
300 CleanupStack::PopAndDestroy(); // method |
|
301 } |
|
302 |
|
303 CleanupStack::PopAndDestroy(); // connArray |
|
304 CleanupStack::PopAndDestroy(); // connManager |
|
305 } |
|
306 |
|
307 // --------------------------------------------------------------------------- |
|
308 // Checks if the connection method matches the data supplied in the argument. |
|
309 // --------------------------------------------------------------------------- |
|
310 // |
|
311 void CDiagBrowserPluginModel::CheckConnectionMatchL( |
|
312 const RCmConnectionMethod& aMethod, |
|
313 TBrowserConnectionMethodData& aData ) const |
|
314 { |
|
315 LOGSTRING( "CDiagBrowserPluginModel::CheckConnectionMatchL()" ) |
|
316 |
|
317 HBufC* name = aMethod.GetStringAttributeL( |
|
318 CMManager::ECmName ); |
|
319 CleanupStack::PushL( name ); |
|
320 |
|
321 #ifdef __WINS__ |
|
322 HBufC* apn = HBufC::NewL( 1 ); |
|
323 #else |
|
324 HBufC* apn = aMethod.GetStringAttributeL( |
|
325 CMManager::EPacketDataAPName ); |
|
326 #endif // __WINS__ |
|
327 CleanupStack::PushL( apn ); |
|
328 |
|
329 TInt type = aMethod.GetIntAttributeL( |
|
330 CMManager::ECmBearerType ); |
|
331 |
|
332 TBool hidden = aMethod.GetBoolAttributeL( |
|
333 CMManager::ECmHidden ); |
|
334 |
|
335 HBufC* proxy = aMethod.GetStringAttributeL( |
|
336 CMManager::ECmProxyServerName ); |
|
337 CleanupStack::PushL( proxy ); |
|
338 |
|
339 TInt port = aMethod.GetIntAttributeL( |
|
340 CMManager::ECmProxyPortNumber ); |
|
341 |
|
342 TUint apId = aMethod.GetIntAttributeL( |
|
343 CMManager::ECmIapId ); |
|
344 |
|
345 LOGSTRING4( |
|
346 "CDiagBrowserPluginModel::CheckConnectionMatchL() - CM" |
|
347 L" Name '%S', Type '0x%08x', Hidden '%d'", name, type, hidden ) |
|
348 |
|
349 LOGSTRING5( "CDiagBrowserPluginModel::CheckConnectionMatchL() - CM" |
|
350 L" APN '%S', Proxy '%S:%d', Id %d", apn, proxy, port, apId ) |
|
351 |
|
352 #ifdef __WINS__ |
|
353 if ( apId == KEmulatorDynamicIpApId ) |
|
354 #else |
|
355 if ( apn->Compare( aData.iApn ) == 0 && |
|
356 proxy->Compare( iProxyAddress ) == 0 && |
|
357 port == iProxyPort && |
|
358 type == KUidPacketDataBearerType && |
|
359 !hidden ) |
|
360 #endif // __WINS__ |
|
361 { |
|
362 aData.iApId = apId; |
|
363 aData.iMethodName.Copy( *name ); |
|
364 aData.iIsValid = ETrue; |
|
365 |
|
366 LOGSTRING2( "CDiagBrowserPluginModel::CheckConnectionMatchL() - Found" |
|
367 L" AP with id %d.", aData.iApId ) |
|
368 } |
|
369 |
|
370 CleanupStack::PopAndDestroy( proxy ); |
|
371 CleanupStack::PopAndDestroy( apn ); |
|
372 CleanupStack::PopAndDestroy( name ); |
|
373 } |
|
374 |
|
375 // --------------------------------------------------------------------------- |
|
376 // Starts or resets the connection timeout timer. |
|
377 // --------------------------------------------------------------------------- |
|
378 // |
|
379 void CDiagBrowserPluginModel::StartConnectionTimerL() |
|
380 { |
|
381 LOGSTRING( "CDiagBrowserPluginModel::StartConnectionTimerL()" ) |
|
382 |
|
383 // Create the timer, or cancel an existing timer. |
|
384 if ( !iTimer ) |
|
385 { |
|
386 iTimer = CPeriodic::NewL( EPriorityHigh ); |
|
387 } |
|
388 else |
|
389 { |
|
390 iTimer->Cancel(); |
|
391 } |
|
392 |
|
393 // Start the timer. |
|
394 iTimer->Start( |
|
395 TTimeIntervalMicroSeconds32( |
|
396 iTimeoutValue * KMicroSecondsInMilliseconds ), |
|
397 TTimeIntervalMicroSeconds32( 0 ), |
|
398 TCallBack( TimerExpired, this ) ); |
|
399 iTimerCalled++; |
|
400 } |
|
401 |
|
402 // --------------------------------------------------------------------------- |
|
403 // Updates the plugin's state and reports progress to the observer. |
|
404 // --------------------------------------------------------------------------- |
|
405 // |
|
406 void CDiagBrowserPluginModel::SetStateL( TDiagBrowserState aTargetState ) |
|
407 { |
|
408 LOGSTRING3( "CDiagBrowserPluginModel::SetStateL( %d ) - iState %d", |
|
409 aTargetState, |
|
410 iState ) |
|
411 |
|
412 // Check for bad state transitions. |
|
413 switch ( aTargetState ) |
|
414 { |
|
415 case EDiagBrowserStateConnectingBearer: |
|
416 __ASSERT_ALWAYS( iState == EDiagBrowserStateInitial, |
|
417 Panic( EDiagBrowserPluginBadState ) ); |
|
418 break; |
|
419 |
|
420 case EDiagBrowserStateConnectingServer: |
|
421 __ASSERT_ALWAYS( iState == EDiagBrowserStateConnectingBearer, |
|
422 Panic( EDiagBrowserPluginBadState ) ); |
|
423 break; |
|
424 |
|
425 case EDiagBrowserStateErasingLog: |
|
426 __ASSERT_ALWAYS( iState != EDiagBrowserStateInitial, |
|
427 Panic( EDiagBrowserPluginBadState ) ); |
|
428 break; |
|
429 |
|
430 default: |
|
431 Panic( EDiagBrowserPluginBadState ); |
|
432 } |
|
433 |
|
434 // Update the state. Send progress to the observer. |
|
435 iState = aTargetState; |
|
436 iObserver.TestProgressL( aTargetState ); |
|
437 } |
|
438 |
|
439 // --------------------------------------------------------------------------- |
|
440 // Callback function for handling timer events. |
|
441 // --------------------------------------------------------------------------- |
|
442 // |
|
443 TInt CDiagBrowserPluginModel::TimerExpired( TAny* aPtr ) |
|
444 { |
|
445 LOGSTRING2( "CDiagBrowserPluginModel::TimerExpired( 0x%x )", aPtr ) |
|
446 |
|
447 __ASSERT_ALWAYS( aPtr, Panic( EDiagBrowserPluginInternal ) ); |
|
448 |
|
449 CDiagBrowserPluginModel* myThis = |
|
450 static_cast< CDiagBrowserPluginModel* >( aPtr ); |
|
451 |
|
452 // Stop the timer to prevent further undesired callbacks. |
|
453 myThis->iTimer->Cancel(); |
|
454 myThis->TimerCleanUp(); |
|
455 // Try to continue test execution by retrying the secondary connection. |
|
456 //TRAPD( error, myThis->RetryConnectionL() ); |
|
457 return KErrNone; |
|
458 } |
|
459 void CDiagBrowserPluginModel::TimerCleanUp() |
|
460 { |
|
461 |
|
462 if (iState == EDiagBrowserStateConnectingBearer) |
|
463 { |
|
464 if(iTimerCalled<=1) |
|
465 StartConnectionTimerL(); |
|
466 else |
|
467 iConnection.Stop( RConnection::EStopAuthoritative ); |
|
468 } |
|
469 else if (iState == EDiagBrowserStateConnectingServer) |
|
470 iHttpTransaction.Cancel(); |
|
471 |
|
472 } |
|
473 // --------------------------------------------------------------------------- |
|
474 // Opens the network connection. This may be called multiple times if a |
|
475 // retry is necessary. |
|
476 // --------------------------------------------------------------------------- |
|
477 TBool CDiagBrowserPluginModel::OpenAndStartConnectionL() |
|
478 { |
|
479 LOGSTRING( "CDiagBrowserPluginModel::OpenAndStartConnectionL()" ) |
|
480 |
|
481 // Check if there is a valid connection to use. |
|
482 /*if ( !iPrimaryConnection.iIsValid && !iSecondaryConnection.iIsValid ) |
|
483 { |
|
484 LOGSTRING( "CDiagBrowserPluginModel::OpenAndStartConnectionL() - No" |
|
485 L" valid connections." ) |
|
486 return EFalse; |
|
487 } |
|
488 */ |
|
489 |
|
490 // Reset the connection. |
|
491 iHttpTransaction.Close(); |
|
492 iHttpSession.Close(); |
|
493 iConnection.Stop(); |
|
494 iState = EDiagBrowserStateInitial; |
|
495 |
|
496 iConnectionPrefs.SetDialogPreference(ECommDbDialogPrefPrompt);//ECommDbDialogPrefDoNotPrompt ECommDbDialogPrefPrompt |
|
497 LOGSTRING("SetDialogPreference( ECommDbDialogPrefPrompt)"); |
|
498 iConnectionPrefs.SetDirection( ECommDbConnectionDirectionOutgoing ); |
|
499 //iConnectionPrefs.SetIapId( iapID ); |
|
500 //iConnectionPrefs.SetBearerSet(ECommDbBearerGPRS); |
|
501 iConnection.Start( iConnectionPrefs, iStatus ); |
|
502 SetActive(); |
|
503 ShowProgressNoteL(); |
|
504 // Start the timer and set the state to notify progress. |
|
505 StartConnectionTimerL(); |
|
506 SetStateL( EDiagBrowserStateConnectingBearer ); |
|
507 return ETrue; |
|
508 } |
|
509 |
|
510 // --------------------------------------------------------------------------- |
|
511 // Handles ending the test by deleting the logs, if necessary, and informing |
|
512 // the observer. |
|
513 // --------------------------------------------------------------------------- |
|
514 void CDiagBrowserPluginModel::HandleTestEndL( |
|
515 CDiagResultsDatabaseItem::TResult aResult ) |
|
516 { |
|
517 LOGSTRING2( "CDiagBrowserPluginModel::HandleTestEndL( %d )", aResult ) |
|
518 |
|
519 // Store the result, to return when log deletion completes. |
|
520 iResult = aResult; |
|
521 |
|
522 // Delete the logs, if necessary. |
|
523 if ( iState != EDiagBrowserStateInitial ) |
|
524 { |
|
525 if ( !iLogEraser ) |
|
526 { |
|
527 iLogEraser = CDiagLogEventEraser::NewL( *this ); |
|
528 } |
|
529 |
|
530 // Set the filter for log erasing. |
|
531 TUid eventType; |
|
532 TTime now; |
|
533 eventType.iUid = KLogPacketDataEventType; |
|
534 now.UniversalTime(); |
|
535 |
|
536 CLogFilter& filter = iLogEraser->Filter(); |
|
537 filter.SetEventType( eventType ); |
|
538 filter.SetStartTime( iStartTime ); |
|
539 filter.SetEndTime( now ); |
|
540 |
|
541 // Erase the logs from the test, asynchronously. |
|
542 SetStateL( EDiagBrowserStateErasingLog ); |
|
543 iLogEraser->StartAsyncEraseLogsL(); |
|
544 } |
|
545 else |
|
546 { |
|
547 iObserver.TestEndL( iResult ); |
|
548 } |
|
549 |
|
550 |
|
551 // clear the dialogue only if dialog is running. |
|
552 if(idialogOn) |
|
553 iWaitDialog->ProcessFinishedL(); |
|
554 } |
|
555 // ---------------------------------------------------------------------------- |
|
556 // CDiagDataNetworkTestPDPEngine::ShowVibrationNoteL |
|
557 // |
|
558 // Progress Note |
|
559 // ---------------------------------------------------------------------------- |
|
560 |
|
561 void CDiagBrowserPluginModel::ShowProgressNoteL() |
|
562 { |
|
563 if ( iWaitDialog ) |
|
564 { |
|
565 delete iWaitDialog; |
|
566 iWaitDialog = NULL; |
|
567 } |
|
568 |
|
569 |
|
570 // WAIT NOTE DIALOG |
|
571 iWaitDialog = new (ELeave) CAknWaitDialog( |
|
572 (REINTERPRET_CAST(CEikDialog**, &iWaitDialog)), |
|
573 ETrue); |
|
574 |
|
575 iWaitDialog->PrepareLC(R_BROWSER_PLUGIN_WAIT_NOTE); |
|
576 iWaitDialog->SetCallback(this); |
|
577 iWaitDialog->RunLD(); |
|
578 idialogOn = ETrue; |
|
579 LOGSTRING("CDiagBrowserPluginModel::ShowProgressNoteL()"); |
|
580 |
|
581 } |
|
582 |
|
583 //********************************************************* |
|
584 // CallBack from AKnWaitDialog when Cancel is pressed |
|
585 //********************************************************* |
|
586 |
|
587 void CDiagBrowserPluginModel::DialogDismissedL( TInt aButtonId ) |
|
588 { |
|
589 LOGSTRING2("CDiagBrowserPluginModel::DialogDismissedL() = %d",aButtonId); |
|
590 |
|
591 if (aButtonId == EBrowserTestCancel && idialogOn) |
|
592 { |
|
593 // cancel the tests based on which point the dialog is dismissed |
|
594 LOGSTRING2("CDiagBrowserPluginModel::DialogDismissed @ iState= %d",iState); |
|
595 if (iState == EDiagBrowserStateConnectingBearer) |
|
596 iConnection.Stop( RConnection::EStopAuthoritative ); |
|
597 else if (iState == EDiagBrowserStateConnectingServer) |
|
598 iHttpTransaction.Cancel(); |
|
599 iWaitDialog = NULL; |
|
600 idialogOn = EFalse; |
|
601 idialogDismissed = ETrue; |
|
602 } |
|
603 } |
|
604 // --------------------------------------------------------------------------- |
|
605 // Attempts to continue test execution by retrying with the secondary |
|
606 // connection. |
|
607 // --------------------------------------------------------------------------- |
|
608 void CDiagBrowserPluginModel::RetryConnectionL() |
|
609 { |
|
610 LOGSTRING( "CDiagBrowserPluginModel::RetryConnectionL()" ); |
|
611 |
|
612 if (iRetryCount < 1 && !idialogDismissed) |
|
613 { |
|
614 if ( OpenAndStartConnectionL() ) |
|
615 { |
|
616 iRetryCount++; |
|
617 return; |
|
618 } |
|
619 } |
|
620 HandleTestEndL( CDiagResultsDatabaseItem::EFailed ); |
|
621 } |
|
622 |
|
623 // --------------------------------------------------------------------------- |
|
624 // From class CActive. |
|
625 // Active object run handler. |
|
626 // --------------------------------------------------------------------------- |
|
627 void CDiagBrowserPluginModel::RunL() |
|
628 { |
|
629 LOGSTRING( "CDiagBrowserPluginModel::RunL()" ) |
|
630 |
|
631 __ASSERT_ALWAYS( iState == EDiagBrowserStateConnectingBearer, |
|
632 Panic( EDiagBrowserPluginBadState ) ); |
|
633 |
|
634 // Stop the timer. |
|
635 if ( iTimer ) |
|
636 { |
|
637 iTimer->Cancel(); |
|
638 } |
|
639 |
|
640 if (iStatus == KErrConnectionTerminated ) |
|
641 { |
|
642 HandleTestEndL( CDiagResultsDatabaseItem::ESkipped ); |
|
643 return; |
|
644 } |
|
645 // Check if the connection succeeded. |
|
646 if ( iStatus != KErrNone ) |
|
647 { |
|
648 LOGSTRING2( |
|
649 "CDiagBrowserPluginModel::RunL() - connection failed. Error %d", |
|
650 iStatus.Int() ) |
|
651 LOGSTRING( "retry if possible()" ); |
|
652 // Retry, if possible. |
|
653 //RetryConnectionL(); |
|
654 HandleTestEndL( CDiagResultsDatabaseItem::EFailed ); |
|
655 return; |
|
656 } |
|
657 |
|
658 // Open the HTTP Session. |
|
659 iHttpSession.OpenL(); |
|
660 |
|
661 // Associate the HTTP session with the open connection. |
|
662 RStringPool pool = iHttpSession.StringPool(); |
|
663 RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo(); |
|
664 connInfo.SetPropertyL( pool.StringF( HTTP::EHttpSocketServ, |
|
665 RHTTPSession::GetTable() ), |
|
666 THTTPHdrVal( iSocketServ.Handle() ) ); |
|
667 TInt connectionPtr = reinterpret_cast< TInt >( &iConnection ); |
|
668 connInfo.SetPropertyL( pool.StringF( HTTP::EHttpSocketConnection, |
|
669 RHTTPSession::GetTable() ), |
|
670 THTTPHdrVal( connectionPtr ) ); |
|
671 |
|
672 // Copy the URI to an 8-bit descriptor. Directly getting an 8-bit |
|
673 // descriptor from Central Repository does not seem to work properly. |
|
674 TBuf8< KMaxStringLength > uri8; |
|
675 uri8.Copy( iUri ); |
|
676 |
|
677 TUriParser8 uriParser; |
|
678 if ( uriParser.Parse( uri8 ) != KErrNone ) |
|
679 { |
|
680 LOGSTRING2( |
|
681 "CDiagBrowserPluginModel::RunL() - parsing the uri '%S' failed.", |
|
682 &iUri ) |
|
683 HandleTestEndL( CDiagResultsDatabaseItem::EFailed ); |
|
684 return; |
|
685 } |
|
686 |
|
687 // Create an HTTP transaction, setting the model as the callback object. |
|
688 iHttpTransaction = iHttpSession.OpenTransactionL( uriParser, *this ); |
|
689 iHttpTransaction.SubmitL(); |
|
690 LOGSTRING2( "CDiagBrowserPluginModel::RunL() - HTTP transaction submitted" |
|
691 L" for '%S'", |
|
692 &iUri ) |
|
693 |
|
694 // Start the timer and set the state to notify progress. |
|
695 StartConnectionTimerL(); |
|
696 SetStateL( EDiagBrowserStateConnectingServer ); |
|
697 } |
|
698 |
|
699 // --------------------------------------------------------------------------- |
|
700 // From class CActive. |
|
701 // Handles leaves in the active object's RunL function. |
|
702 // --------------------------------------------------------------------------- |
|
703 TInt CDiagBrowserPluginModel::RunError( TInt aError ) |
|
704 { |
|
705 LOGSTRING2( "CDiagBrowserPluginModel::RunError( %d )", aError ) |
|
706 |
|
707 // Try to continue test execution by retrying the secondary connection. |
|
708 //TRAPD( error, RetryConnectionL() ); |
|
709 //return error; |
|
710 HandleTestEndL( CDiagResultsDatabaseItem::EFailed ); |
|
711 return KErrNone; |
|
712 } |
|
713 |
|
714 // --------------------------------------------------------------------------- |
|
715 // From class CActive. |
|
716 // Active object cancel. |
|
717 // --------------------------------------------------------------------------- |
|
718 void CDiagBrowserPluginModel::DoCancel() |
|
719 { |
|
720 LOGSTRING( "CDiagBrowserPluginModel::DoCancel()" ) |
|
721 |
|
722 // Does not have an asynchronous cancel, but this functions as Cancel. |
|
723 iConnection.Stop( RConnection::EStopAuthoritative ); |
|
724 } |
|
725 |
|
726 // --------------------------------------------------------------------------- |
|
727 // From class MHTTPTransactionCallback. |
|
728 // Called when an event occurs on an HTTP transaction. |
|
729 // --------------------------------------------------------------------------- |
|
730 void CDiagBrowserPluginModel::MHFRunL( RHTTPTransaction aTransaction, |
|
731 const THTTPEvent& aEvent ) |
|
732 { |
|
733 LOGSTRING2( "CDiagBrowserPluginModel::MHFRunL() - aEvent.iStatus %d", |
|
734 aEvent.iStatus ) |
|
735 |
|
736 __ASSERT_ALWAYS( iState == EDiagBrowserStateConnectingServer, |
|
737 Panic( EDiagBrowserPluginBadState ) ); |
|
738 __ASSERT_ALWAYS( aTransaction.Id() == iHttpTransaction.Id(), |
|
739 Panic( EDiagBrowserPluginTransaction ) ); |
|
740 |
|
741 // Failed status. |
|
742 if ( aEvent == THTTPEvent::EFailed ) |
|
743 { |
|
744 LOGSTRING( "CDiagBrowserPluginModel::MHFRunL() - Response failed." ) |
|
745 //RetryConnectionL(); |
|
746 //return; |
|
747 HandleTestEndL( CDiagResultsDatabaseItem::EFailed ); |
|
748 } |
|
749 |
|
750 // Skip non-success / non-failure statuses. |
|
751 if ( aEvent != THTTPEvent::EGotResponseHeaders && |
|
752 aEvent != THTTPEvent::EGotResponseBodyData && |
|
753 aEvent != THTTPEvent::EResponseComplete && |
|
754 aEvent != THTTPEvent::ESucceeded && |
|
755 aEvent != THTTPEvent::ERequestComplete ) |
|
756 { |
|
757 LOGSTRING( "CDiagBrowserPluginModel::MHFRunL() - Unused event." ) |
|
758 return; |
|
759 } |
|
760 |
|
761 // Stop the request, so we don't get any further callbacks. |
|
762 iHttpTransaction.Cancel(); |
|
763 |
|
764 // Get the HTTP response code and check it. |
|
765 RHTTPResponse response = aTransaction.Response(); |
|
766 if ( response.StatusCode() != KHttpResponseCodeOk ) |
|
767 { |
|
768 LOGSTRING2( "CDiagBrowserPluginModel::MHFRunL() - status code is %d", |
|
769 response.StatusCode() ) |
|
770 HandleTestEndL( CDiagResultsDatabaseItem::EFailed ); |
|
771 } |
|
772 else |
|
773 { |
|
774 LOGSTRING( |
|
775 "CDiagBrowserPluginModel::MHFRunL() - connection succeeded" ) |
|
776 HandleTestEndL( CDiagResultsDatabaseItem::ESuccess ); |
|
777 } |
|
778 } |
|
779 |
|
780 // --------------------------------------------------------------------------- |
|
781 // From class MHTTPTransactionCallback. |
|
782 // Called when an error occurs on an HTTP transaction. |
|
783 // --------------------------------------------------------------------------- |
|
784 TInt CDiagBrowserPluginModel::MHFRunError( TInt aError, |
|
785 RHTTPTransaction aTransaction, |
|
786 const THTTPEvent& /* aEvent */ ) |
|
787 { |
|
788 LOGSTRING2( "CDiagBrowserPluginModel::MHFRunError( %d )", aError ) |
|
789 |
|
790 __ASSERT_ALWAYS( iState == EDiagBrowserStateConnectingServer, |
|
791 Panic( EDiagBrowserPluginBadState ) ); |
|
792 __ASSERT_ALWAYS( aTransaction.Id() == iHttpTransaction.Id(), |
|
793 Panic( EDiagBrowserPluginTransaction ) ); |
|
794 |
|
795 // Try to continue test execution by retrying the secondary connection. |
|
796 TRAPD( error, RetryConnectionL() ); |
|
797 return error; |
|
798 } |
|
799 |
|
800 // --------------------------------------------------------------------------- |
|
801 // From class MDiagLogEventEraserObserver. |
|
802 // This function checks if the log event needs to be deleted. |
|
803 // --------------------------------------------------------------------------- |
|
804 TBool CDiagBrowserPluginModel::IsEventToBeDeleted( const CLogEvent& aEvent ) |
|
805 { |
|
806 LOGSTRING( "CDiagBrowserPluginModel::IsEventToBeDeleted()" ) |
|
807 |
|
808 if ( ( iPrimaryConnection.iUsed && aEvent.RemoteParty().Compare( |
|
809 iPrimaryConnection.iMethodName ) == 0 ) || |
|
810 ( iSecondaryConnection.iUsed && aEvent.RemoteParty().Compare( |
|
811 iSecondaryConnection.iMethodName ) == 0 ) ) |
|
812 { |
|
813 // The name matches, so delete the log entry. |
|
814 return ETrue; |
|
815 } |
|
816 |
|
817 return EFalse; |
|
818 } |
|
819 |
|
820 // --------------------------------------------------------------------------- |
|
821 // From class MDiagLogEventEraserObserver. |
|
822 // This function notifies that the erase operation is complete. |
|
823 // --------------------------------------------------------------------------- |
|
824 void CDiagBrowserPluginModel::CompleteEventEraseL( TInt aError ) |
|
825 { |
|
826 LOGSTRING2( |
|
827 "CDiagBrowserPluginModel::CompleteEventEraseL( %d )", aError ) |
|
828 |
|
829 __ASSERT_ALWAYS( iState == EDiagBrowserStateErasingLog, |
|
830 Panic( EDiagBrowserPluginBadState ) ); |
|
831 |
|
832 // The error code is ignored, because it's not part of the criteria for |
|
833 // the test to pass. We are deleting logs asynchronously, so the browser |
|
834 // portion of the test has already stored a result in iResult. |
|
835 iState = EDiagBrowserStateInitial; |
|
836 |
|
837 // dialog dismissed with Cancel |
|
838 |
|
839 if (idialogDismissed) |
|
840 iResult = CDiagResultsDatabaseItem::ESkipped; |
|
841 |
|
842 LOGSTRING2( "CDiagBrowserPluginModel::dialogDismissed = %d)", idialogDismissed) |
|
843 iObserver.TestEndL( iResult ); |
|
844 } |
|
845 |
|
846 // End of File |