148 // CApSettingsDeleteOperation::RunL |
107 // CApSettingsDeleteOperation::RunL |
149 // --------------------------------------------------------- |
108 // --------------------------------------------------------- |
150 // |
109 // |
151 void CApSettingsDeleteOperation::RunL() |
110 void CApSettingsDeleteOperation::RunL() |
152 { |
111 { |
153 APSETUILOGGER_ENTERFN( EDelete,"DeleteOp::RunL") |
|
154 |
|
155 switch ( iState ) |
|
156 { |
|
157 case EProcOnDialogOn: |
|
158 { // two chances : |
|
159 // 1. Process finished normally |
|
160 // 2. Process leaved with error |
|
161 iState = EProcOffDialogOn; |
|
162 if ( iWaitDialog ) |
|
163 { |
|
164 iWaitDialog->ProcessFinishedL(); |
|
165 } |
|
166 if ( iStatus.Int() != KErrNone ) |
|
167 { |
|
168 // some error has occured |
|
169 iErr = iStatus.Int(); |
|
170 } |
|
171 Next(); |
|
172 break; |
|
173 } |
|
174 case EProcOffDialogOn: |
|
175 { |
|
176 // now we wait for the dialog to be dismissed |
|
177 // just to be able to delete it |
|
178 // stays in this state as long as DialogDismissedL() |
|
179 // is not called, it will move it out into |
|
180 // EProcOffDialogOff and it also deletes |
|
181 Next(); |
|
182 break; |
|
183 } |
|
184 case EProcOnDialogOff: |
|
185 { // this can't be, as dialog MUST stay as long as operation... |
|
186 iState = EProcOffDialogOff; |
|
187 Next(); |
|
188 break; |
|
189 } |
|
190 case EProcOffDialogOff: |
|
191 { // now we can safely delete the dialog |
|
192 if ( iWaitDialog ) |
|
193 { |
|
194 delete iWaitDialog; |
|
195 } |
|
196 if ( iErr != KErrNone ) |
|
197 { |
|
198 // some error has occured |
|
199 iErrorUi->ShowGlobalErrorNoteL( iErr ); |
|
200 } |
|
201 iDeleteOperation.Kill( iErr ); |
|
202 iDeleteOperation.Close(); |
|
203 // delete this; |
|
204 break; |
|
205 } |
|
206 default: |
|
207 { |
|
208 __ASSERT_DEBUG( EFalse, Panic( EInvalidState ) ); |
|
209 break; |
|
210 } |
|
211 } |
|
212 |
|
213 APSETUILOGGER_LEAVEFN( EDelete,"DeleteOp::RunL") |
|
214 } |
112 } |
215 |
113 |
216 |
114 |
217 // --------------------------------------------------------- |
115 // --------------------------------------------------------- |
218 // CApSettingsDeleteOperation::DoCancel |
116 // CApSettingsDeleteOperation::DoCancel |
219 // --------------------------------------------------------- |
117 // --------------------------------------------------------- |
220 // |
118 // |
221 void CApSettingsDeleteOperation::DoCancel() |
119 void CApSettingsDeleteOperation::DoCancel() |
222 { // must be here as it is pure virtual in base... |
120 { // must be here as it is pure virtual in base... |
223 APSETUILOGGER_ENTERFN( EDelete,"DeleteOp::DoCancel") |
|
224 |
|
225 if (iDeleteOperation.Handle() != 0 && iStatus == KRequestPending) |
|
226 { |
|
227 iDeleteOperation.LogonCancel(iStatus); |
|
228 } |
|
229 |
|
230 APSETUILOGGER_LEAVEFN( EDelete,"DeleteOp::DoCancel") |
|
231 } |
121 } |
232 |
122 |
233 |
123 |
234 |
124 |
235 // --------------------------------------------------------- |
125 // --------------------------------------------------------- |
236 // CApSettingsDeleteOperation::DialogDismissedL |
126 // CApSettingsDeleteOperation::DialogDismissedL |
237 // --------------------------------------------------------- |
127 // --------------------------------------------------------- |
238 // |
128 // |
239 void CApSettingsDeleteOperation::DialogDismissedL( TInt /*aButtonId*/ ) |
129 void CApSettingsDeleteOperation::DialogDismissedL( TInt /*aButtonId*/ ) |
240 { |
130 { |
241 APSETUILOGGER_ENTERFN( EDelete,"DeleteOp::DialogDismissedL") |
|
242 |
|
243 switch ( iState ) |
|
244 { |
|
245 case EProcOnDialogOn: |
|
246 { // can't be, it means that dialog is dismissed by user |
|
247 // but process is still runing... |
|
248 iState = EProcOnDialogOff; |
|
249 break; |
|
250 } |
|
251 case EProcOffDialogOn: |
|
252 { |
|
253 // set dialog off |
|
254 iState = EProcOffDialogOff; |
|
255 // as proc is already off, it circles in RunL, |
|
256 break; |
|
257 } |
|
258 case EProcOnDialogOff: |
|
259 { // can't be, it is already off... |
|
260 iState = EProcOnDialogOff; |
|
261 Next(); |
|
262 break; |
|
263 } |
|
264 case EProcOffDialogOff: |
|
265 {// can't be, it is already off... |
|
266 iState = EProcOffDialogOff; |
|
267 Next(); |
|
268 break; |
|
269 } |
|
270 default: |
|
271 { |
|
272 __ASSERT_DEBUG( EFalse, Panic( EInvalidState ) ); |
|
273 break; |
|
274 } |
|
275 } |
|
276 |
|
277 APSETUILOGGER_LEAVEFN( EDelete,"DeleteOp::DialogDismissedL") |
|
278 } |
131 } |
279 |
132 |
280 |
133 |
281 // --------------------------------------------------------- |
134 // --------------------------------------------------------- |
282 // CApSettingsDeleteOperation::StartL |
135 // CApSettingsDeleteOperation::StartL |
283 // --------------------------------------------------------- |
136 // --------------------------------------------------------- |
284 // |
137 // |
285 void CApSettingsDeleteOperation::StartL() |
138 void CApSettingsDeleteOperation::StartL() |
286 { |
139 { |
287 APSETUILOGGER_ENTERFN( EDelete,"DeleteOp::StartL") |
|
288 |
|
289 iStatus = KRequestPending; |
|
290 // set the internal state as both is running |
|
291 iState = EProcOnDialogOn; |
|
292 |
|
293 // now we can start wait note... |
|
294 StartWaitNoteL(); |
|
295 |
|
296 // now start new thread with operation |
|
297 StartDeleteOperationThreadL(); |
|
298 |
|
299 SetActive(); |
|
300 // now we can wait on it... |
|
301 // wait until the started thread completes (delete operation completes) |
|
302 // and it will enter RunL. RunL will notify the wait dialog about the |
|
303 // completion of the process. |
|
304 // As the dialog shall wait ~0.5 sec till display AND must be visible |
|
305 // for ~1.5 sec. as a minimum, but must stay up as long as the 'process' |
|
306 // on it is waiting for does not completes, we have the following chances: |
|
307 // if the process is shorter than 0.5, |
|
308 // after operation completes, state moves to EProcOffDialogOn, |
|
309 // dialog will be notified about completion by RunL, and RunL starts |
|
310 // circle and wait for the dialog to finish, multiply re-entering |
|
311 // and leaving RunL, as long as the state is EProcOffDialogOn. |
|
312 // As time was shorter than 0.5, thus dialog will not show itself |
|
313 // and will call DialogDismissedL, which will change the |
|
314 // state to EProcOffDialogOff, which, on entering |
|
315 // RunL again, will delete the dialog and kill the thread. |
|
316 // if the process was longer than 0.5 but shorter than 0.5+1.5sec, |
|
317 // after operation completes, state moves to EProcOffDialogOn, |
|
318 // dialog will be notified about completion by RunL, and RunL starts |
|
319 // circle and wait for the dialog to finish, multiply re-entering |
|
320 // and leaving RunL, as long as the state is EProcOffDialogOn. |
|
321 // As time was longer than 0.5, thus dialog will show itself |
|
322 // and will stay up for 1.5 sec, as process ended between |
|
323 // 0.5 and (0.5+1.5). After it dialog will call DialogDismissedL, |
|
324 // which will change the state to EProcOffDialogOff, which, on |
|
325 // entering RunL again, will delete the dialog and kill the thread. |
|
326 // if the process was longer than 0.5+1.5 |
|
327 // after operation completes, state moves to EProcOffDialogOn, |
|
328 // dialog will be notified about completion by RunL, and RunL starts |
|
329 // circle and wait for the dialog to finish, multiply re-entering |
|
330 // and leaving RunL, as long as the state is EProcOffDialogOn. |
|
331 // As time was longer than 0.5+1.5, thus dialog will show itself |
|
332 // and will stay up for as long as 'process/operation' is not finished. |
|
333 // As thread completes, notifies dialog, after it dialog will |
|
334 // call back DialogDismissedL, which will change the state |
|
335 // to EProcOffDialogOff, which, on entering RunL again, |
|
336 // will delete the dialog and kill the thread. |
|
337 |
|
338 APSETUILOGGER_LEAVEFN( EDelete,"DeleteOp::StartL") |
|
339 } |
140 } |
340 |
141 |
341 |
142 |
342 |
143 |
343 // --------------------------------------------------------- |
144 // --------------------------------------------------------- |
344 // CApSettingsDeleteOperation::Next |
145 // CApSettingsDeleteOperation::Next |
345 // --------------------------------------------------------- |
146 // --------------------------------------------------------- |
346 // |
147 // |
347 void CApSettingsDeleteOperation::Next() |
148 void CApSettingsDeleteOperation::Next() |
348 { |
149 { |
349 APSETUILOGGER_ENTERFN( EDelete,"DeleteOp::Next") |
|
350 |
|
351 iStatus = KRequestPending; |
|
352 SetActive(); |
|
353 TRequestStatus *status = &iStatus; |
|
354 User::RequestComplete( status, KErrNone ); // Invoke RunL() |
|
355 |
|
356 APSETUILOGGER_LEAVEFN( EDelete,"DeleteOp::Next") |
|
357 } |
150 } |
358 |
151 |
359 |
152 |
360 |
153 |
361 |
154 |
390 // --------------------------------------------------------- |
168 // --------------------------------------------------------- |
391 // |
169 // |
392 TInt CApSettingsDeleteOperation::DoRunDeleteThreadL( |
170 TInt CApSettingsDeleteOperation::DoRunDeleteThreadL( |
393 CApSettingsDeleteOperation* aop ) |
171 CApSettingsDeleteOperation* aop ) |
394 { |
172 { |
395 APSETUILOGGER_ENTERFN( EDelete,"DeleteOp::DoRunDeleteThreadL") |
173 return KErrNotSupported; |
396 |
|
397 CCommsDatabase* db = CCommsDatabase::NewL( EDatabaseTypeIAP ); |
|
398 CleanupStack::PushL( db ); |
|
399 |
|
400 APSETUILOGGER_WRITE( EDelete,"Commsdb created"); |
|
401 |
|
402 CApDataHandler* handler = CApDataHandler::NewLC( *db ); |
|
403 |
|
404 APSETUILOGGER_WRITE( EDelete,"CApDataHandler created"); |
|
405 |
|
406 CVpnApEngine* vpnengine = CVpnApEngine::NewLC( db ); |
|
407 |
|
408 APSETUILOGGER_WRITE( EDelete,"CVpnApEngine created"); |
|
409 |
|
410 TBool ownTransaction = StartTransactionLC( db, |
|
411 /*aWrite*/ETrue, |
|
412 /*aRetry*/ETrue ); |
|
413 |
|
414 APSETUILOGGER_WRITE( EDelete,"Tr.started"); |
|
415 |
|
416 // NORMAL OPERATION STARTS |
|
417 TBool isvpn = vpnengine->IsVpnApL( aop->iUid ); |
|
418 |
|
419 APSETUILOGGER_WRITE( EDelete,"IsVpnApL returned"); |
|
420 |
|
421 // if linked to a VPN, the VPN also must be deleted |
|
422 // deleting the VPN part is the delete operation's responsibility... |
|
423 if ( isvpn ) |
|
424 { |
|
425 vpnengine->DeleteVpnL( aop->iUid ); |
|
426 } |
|
427 else |
|
428 { |
|
429 handler->RemoveAPL( aop->iUid ); |
|
430 } |
|
431 |
|
432 APSETUILOGGER_WRITE( EDelete,"RemoveAPL returned"); |
|
433 |
|
434 |
|
435 if ( ownTransaction ) |
|
436 { |
|
437 TInt err = db->CommitTransaction(); |
|
438 User::LeaveIfError( err ); |
|
439 CleanupStack::Pop(); // RollbackTransactionOnLeave |
|
440 } |
|
441 |
|
442 APSETUILOGGER_WRITE( EDelete," delete finished"); |
|
443 |
|
444 CleanupStack::PopAndDestroy( 3, db ); //db,handler,vpnengine |
|
445 |
|
446 // NORMAL OPERATION ENDS |
|
447 |
|
448 |
|
449 APSETUILOGGER_LEAVEFN( EDelete,"DeleteOp::DoRunDeleteThreadL") |
|
450 return KErrNone; |
|
451 } |
174 } |
452 |
175 |
453 |
176 |
454 |
177 |
455 // --------------------------------------------------------- |
178 // --------------------------------------------------------- |
456 // CApSettingsDeleteOperation::StartWaitNoteL |
179 // CApSettingsDeleteOperation::StartWaitNoteL |
457 // --------------------------------------------------------- |
180 // --------------------------------------------------------- |
458 // |
181 // |
459 void CApSettingsDeleteOperation::StartWaitNoteL() |
182 void CApSettingsDeleteOperation::StartWaitNoteL() |
460 { |
183 { |
461 APSETUILOGGER_ENTERFN( EDelete,"DeleteOp::StartWaitNoteL") |
|
462 |
|
463 if ( iWaitDialog ) |
|
464 { |
|
465 delete iWaitDialog; |
|
466 iWaitDialog = NULL; |
|
467 } |
|
468 iWaitDialog = |
|
469 new ( ELeave ) CAknWaitDialog |
|
470 ( REINTERPRET_CAST(CEikDialog**,&iWaitDialog) ); |
|
471 iWaitDialog->PrepareLC( iResourceID ); |
|
472 iWaitDialog->SetTone( CAknNoteDialog::ENoTone ); |
|
473 iWaitDialog->SetTextL( *iNoteText ); |
|
474 iWaitDialog->SetCallback( this ); |
|
475 iWaitDialog->RunLD(); |
|
476 |
|
477 APSETUILOGGER_LEAVEFN( EDelete,"DeleteOp::StartWaitNoteL") |
|
478 } |
184 } |
479 |
185 |
480 |
186 |
481 |
187 |
482 // --------------------------------------------------------- |
188 // --------------------------------------------------------- |
483 // CApSettingsDeleteOperation::StartDeleteOperationThreadL |
189 // CApSettingsDeleteOperation::StartDeleteOperationThreadL |
484 // --------------------------------------------------------- |
190 // --------------------------------------------------------- |
485 // |
191 // |
486 void CApSettingsDeleteOperation::StartDeleteOperationThreadL() |
192 void CApSettingsDeleteOperation::StartDeleteOperationThreadL() |
487 { |
193 { |
488 APSETUILOGGER_ENTERFN( EDelete,"DeleteOp::StartDeleteOperationThreadL") |
|
489 |
|
490 TInt err = iDeleteOperation.Create |
|
491 ( |
|
492 KDeleteThreadName, // aName |
|
493 RunDeleteThread, // aFunction |
|
494 KDeleteThreadStackSize, // aStackSize |
|
495 NULL, // Use this heap. |
|
496 this // aPtr |
|
497 ); |
|
498 APSETUILOGGER_WRITE_FORMAT( EDelete, "iDeleteOperation create returned, code:%d", err); |
|
499 |
|
500 User::LeaveIfError( err ); |
|
501 // on termination/death of this thread, it will call RunL |
|
502 iDeleteOperation.Logon( iStatus ); |
|
503 // let's start the thread |
|
504 iDeleteOperation.Resume(); |
|
505 // set the internal state as both is running |
|
506 iState = EProcOnDialogOn; |
|
507 |
|
508 APSETUILOGGER_LEAVEFN( EDelete,"DeleteOp::StartDeleteOperationThreadL") |
|
509 } |
194 } |
510 |
195 |
511 |
196 |
512 |
197 |
513 |
198 |
518 // |
203 // |
519 TBool CApSettingsDeleteOperation::StartTransactionLC( CCommsDatabase* aDb, |
204 TBool CApSettingsDeleteOperation::StartTransactionLC( CCommsDatabase* aDb, |
520 TBool aWrite, |
205 TBool aWrite, |
521 TBool aRetry /*ETrue*/ ) |
206 TBool aRetry /*ETrue*/ ) |
522 { |
207 { |
523 APSETUILOGGER_ENTERFN( EDelete,"DeleteOp::StartTransactionLC") |
208 return EFalse; |
524 |
|
525 TBool retval( EFalse ); |
|
526 if ( !aDb->InTransaction() ) |
|
527 { |
|
528 TInt retriesLeft( aRetry ? KRetryCount : 1 ); |
|
529 TInt err = aDb->BeginTransaction(); |
|
530 while ( ( err == KErrLocked ) && --retriesLeft ) |
|
531 { |
|
532 User::After( KRetryWait ); |
|
533 err = aDb->BeginTransaction(); |
|
534 if (aWrite ) |
|
535 { |
|
536 TRAP_IGNORE( GetWriteLockL( aDb ) ); |
|
537 } |
|
538 } |
|
539 if ( err ) |
|
540 { |
|
541 ShowNoteL( R_APUI_VIEW_TEXT_CANNOT_ACCESS_DB ); |
|
542 } |
|
543 User::LeaveIfError( err ); |
|
544 CleanupStack::PushL( TCleanupItem( RollbackTransactionOnLeave, aDb ) ); |
|
545 retval = ETrue; |
|
546 } |
|
547 else |
|
548 { |
|
549 retval = EFalse; |
|
550 } |
|
551 |
|
552 APSETUILOGGER_LEAVEFN( EDelete,"DeleteOp::StartTransactionLC") |
|
553 return retval; |
|
554 } |
209 } |
555 |
210 |
556 |
211 |
557 // --------------------------------------------------------- |
212 // --------------------------------------------------------- |
558 // CApSettingsDeleteOperation::GetWriteLockL |
213 // CApSettingsDeleteOperation::GetWriteLockL |
559 // --------------------------------------------------------- |
214 // --------------------------------------------------------- |
560 // |
215 // |
561 void CApSettingsDeleteOperation::GetWriteLockL( CCommsDatabase* aDb ) |
216 void CApSettingsDeleteOperation::GetWriteLockL( CCommsDatabase* aDb ) |
562 { |
217 { |
563 APSETUILOGGER_ENTERFN( EDelete,"DeleteOp::GetWriteLockL") |
|
564 |
|
565 CCommsDbTableView* v = aDb->OpenTableLC( TPtrC(WAP_ACCESS_POINT ) ); |
|
566 TUint32 aDummyUid( KApNoneUID ); |
|
567 TInt err = v->InsertRecord( aDummyUid ); |
|
568 User::LeaveIfError( err ); |
|
569 v->CancelRecordChanges(); |
|
570 User::LeaveIfError( err ); |
|
571 CleanupStack::PopAndDestroy(); // v |
|
572 |
|
573 APSETUILOGGER_LEAVEFN( EDelete,"DeleteOp::GetWriteLockL") |
|
574 } |
218 } |
575 |
219 |
576 // --------------------------------------------------------- |
220 // --------------------------------------------------------- |
577 // CApSettingsDeleteOperation::RollbackTransactionOnLeave |
221 // CApSettingsDeleteOperation::RollbackTransactionOnLeave |
578 // --------------------------------------------------------- |
222 // --------------------------------------------------------- |
579 // |
223 // |
580 void CApSettingsDeleteOperation::RollbackTransactionOnLeave( TAny* aDb ) |
224 void CApSettingsDeleteOperation::RollbackTransactionOnLeave( TAny* aDb ) |
581 { |
225 { |
582 APSETUILOGGER_ENTERFN( EDelete,"DeleteOp::RollbackTransactionOnLeave") |
|
583 |
|
584 CCommsDatabase* db = STATIC_CAST( CCommsDatabase*, aDb ); |
|
585 db->RollbackTransaction(); |
|
586 |
|
587 APSETUILOGGER_LEAVEFN( EDelete,"DeleteOp::RollbackTransactionOnLeave") |
|
588 } |
226 } |
589 |
227 |
590 |
228 |
591 // --------------------------------------------------------- |
229 // --------------------------------------------------------- |
592 // CApSettingsDeleteOperation::ReadUintL |
230 // CApSettingsDeleteOperation::ReadUintL |