|
1 /* |
|
2 * Copyright (c) 2004-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: CNssContextManager provides context processing for the client. CNssContextManager |
|
15 * implements the MNssContextMgr interface, and also provides additional methods for |
|
16 * use by internal VAS components. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // include files |
|
22 #include "nssvasccontextmgr.h" |
|
23 #include "nssvascvasdatabase.h" |
|
24 #include "nssvasccontextbuilder.h" |
|
25 #include "nssvasmresetfactorymodelsclient.h" |
|
26 #include "rubydebug.h" |
|
27 |
|
28 const TInt KContextArrayGranularity = 5; |
|
29 |
|
30 _LIT( KContextMgrPanic, "contextmgr.cpp"); |
|
31 |
|
32 // --------------------------------------------------------- |
|
33 // CNssContextMgr::CNssContextMgr |
|
34 // C++ constructor |
|
35 // --------------------------------------------------------- |
|
36 // |
|
37 CNssContextMgr::CNssContextMgr() |
|
38 : CActive( EPriorityStandard ) |
|
39 { |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------- |
|
43 // CNssContextMgr::CNssContextMgr |
|
44 // overloaded C++ constructor |
|
45 // --------------------------------------------------------- |
|
46 // |
|
47 CNssContextMgr::CNssContextMgr( CNssVASDatabase* aVASDatabase ) |
|
48 : CActive( EPriorityStandard ) |
|
49 { |
|
50 iVasDatabase = aVASDatabase; |
|
51 iState = ENone; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------- |
|
55 // CNssContextMgr::~CNssContextMgr |
|
56 // destructor |
|
57 // --------------------------------------------------------- |
|
58 // |
|
59 CNssContextMgr::~CNssContextMgr() |
|
60 { |
|
61 if ( iContextBuilder ) |
|
62 { |
|
63 delete iContextBuilder; |
|
64 iContextBuilder = NULL; |
|
65 } |
|
66 |
|
67 // Cancel any oustanding requests before destroying self. |
|
68 if( IsActive() ) |
|
69 { |
|
70 Cancel(); // -> in base class -> goes on to call DoCancel in this class... |
|
71 } |
|
72 |
|
73 // Delete context list if it has not been delivered to the client yet |
|
74 if ( iContextList ) |
|
75 { |
|
76 iContextList->ResetAndDestroy(); |
|
77 delete iContextList; |
|
78 } |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // CNssContextMgr::NewL |
|
83 // Two-phased constructor. |
|
84 // --------------------------------------------------------- |
|
85 // |
|
86 CNssContextMgr* CNssContextMgr::NewL( CNssVASDatabase* aVASDatabase ) |
|
87 { |
|
88 CNssContextMgr* self = NewLC( aVASDatabase ); |
|
89 CleanupStack::Pop( self ); |
|
90 return self; |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------- |
|
94 // CNssContextMgr::NewLC |
|
95 // Two-phased constructor. |
|
96 // --------------------------------------------------------- |
|
97 // |
|
98 CNssContextMgr* CNssContextMgr::NewLC( CNssVASDatabase* aVASDatabase ) |
|
99 { |
|
100 CNssContextMgr* self = new (ELeave) CNssContextMgr( aVASDatabase ); |
|
101 CleanupStack::PushL( self ); |
|
102 self->ConstructL(); |
|
103 return self; |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------- |
|
107 // CNssContextMgr::ConstructL |
|
108 // EPOC constructor can leave. |
|
109 // --------------------------------------------------------- |
|
110 // |
|
111 void CNssContextMgr::ConstructL() |
|
112 { |
|
113 iContextBuilder = CNssContextBuilder::NewL(); |
|
114 |
|
115 CActiveScheduler::Add( this ); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------- |
|
119 // CNssContextMgr::CreateContextL |
|
120 // creates an empty context object |
|
121 // --------------------------------------------------------- |
|
122 // |
|
123 MNssContext* CNssContextMgr::CreateContextL() |
|
124 { |
|
125 return iContextBuilder->CreateContextL(); |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------- |
|
129 // CNssContextMgr::GetContext |
|
130 // retrives a context fromt he VAS DB based on the name of the context |
|
131 // --------------------------------------------------------- |
|
132 // |
|
133 TInt CNssContextMgr::GetContext( MNssGetContextClient* aContextClient, const TDesC& aName ) |
|
134 { |
|
135 if ( IsActive() || !aContextClient || aName.Length() == 0 ) |
|
136 { |
|
137 return KErrGeneral; |
|
138 } |
|
139 |
|
140 if ( iContextList ) |
|
141 { |
|
142 iContextList->ResetAndDestroy(); |
|
143 delete iContextList; |
|
144 iContextList = NULL; |
|
145 } |
|
146 |
|
147 TInt ret( KErrNone ); |
|
148 |
|
149 iContextList = iVasDatabase->GetContext( aName ); |
|
150 |
|
151 if ( !iContextList ) |
|
152 { |
|
153 ret = KErrGeneral; |
|
154 } |
|
155 |
|
156 else if ( iContextList->Count() == 0 ) |
|
157 { |
|
158 delete iContextList; |
|
159 iContextList = NULL; |
|
160 ret = KErrGeneral; |
|
161 } |
|
162 |
|
163 else |
|
164 { |
|
165 iState = EGetContextClientGetContext; |
|
166 iGetContextClient = aContextClient; |
|
167 |
|
168 TRequestStatus* pRS = &iStatus; |
|
169 User::RequestComplete( pRS, KErrNone ); |
|
170 SetActive(); |
|
171 } |
|
172 |
|
173 return ret; |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------- |
|
177 // CNssContextMgr::GetContextList |
|
178 // retreives a list of contexts from the VAS DB |
|
179 // --------------------------------------------------------- |
|
180 // |
|
181 TInt CNssContextMgr::GetContextList( MNssGetContextClient* aContextClient ) |
|
182 { |
|
183 if ( IsActive() || !aContextClient ) |
|
184 { |
|
185 return KErrGeneral; |
|
186 } |
|
187 |
|
188 if ( iContextList ) |
|
189 { |
|
190 iContextList->ResetAndDestroy(); |
|
191 delete iContextList; |
|
192 iContextList = 0; |
|
193 } |
|
194 |
|
195 TInt ret( KErrNone ); |
|
196 |
|
197 iContextList = iVasDatabase->GetAllContexts(); |
|
198 |
|
199 if ( !iContextList ) |
|
200 { |
|
201 ret = KErrGeneral; |
|
202 } |
|
203 |
|
204 else if ( iContextList->Count() == 0 ) |
|
205 { |
|
206 delete iContextList; |
|
207 iContextList = NULL; |
|
208 ret = KErrGeneral; |
|
209 } |
|
210 |
|
211 else |
|
212 { |
|
213 iState = EGetContextClientGetContextList; |
|
214 iGetContextClient = aContextClient; |
|
215 |
|
216 TRequestStatus* pRS = &iStatus; |
|
217 User::RequestComplete( pRS, KErrNone ); |
|
218 SetActive(); |
|
219 } |
|
220 |
|
221 return ret; |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------- |
|
225 // CNssContextMgr::DeleteContext |
|
226 // deletes a context from VAS DB |
|
227 // --------------------------------------------------------- |
|
228 // |
|
229 TInt CNssContextMgr::DeleteContext( MNssDeleteContextClient* aContextClient, |
|
230 MNssContext* aContext ) |
|
231 { |
|
232 iState = EDeleteContextClient; |
|
233 iDeleteContextClient = aContextClient; |
|
234 iLocalContext = (CNssContext*)(aContext); |
|
235 |
|
236 // will fail if 2 requests come in together |
|
237 TRAPD( error, iLocalContext->BeginDeleteFromSrsL(this) ); |
|
238 |
|
239 return error; |
|
240 } |
|
241 |
|
242 // --------------------------------------------------------- |
|
243 // CNssContextMgr::SaveContext |
|
244 // saves a context in the vas db |
|
245 // --------------------------------------------------------- |
|
246 // |
|
247 TInt CNssContextMgr::SaveContext( MNssSaveContextClient* aContextClient,MNssContext* aContext ) |
|
248 { |
|
249 if ( IsActive() || !aContextClient || !aContext ) |
|
250 { |
|
251 return KErrGeneral; |
|
252 } |
|
253 |
|
254 if ( !( &aContext->ContextName() ) ) |
|
255 { |
|
256 return KErrGeneral; |
|
257 } |
|
258 |
|
259 iState = ESaveContextClient; |
|
260 iSaveContextClient = aContextClient; |
|
261 iLocalContext = (CNssContext*)(aContext); |
|
262 |
|
263 TUint32 modelBankId; |
|
264 TUint32 lexiconId; |
|
265 if ( iVasDatabase->ModelBankAndLexiconExist( modelBankId, lexiconId ) ) |
|
266 { |
|
267 iLocalContext->SetModelBankId( modelBankId ); |
|
268 iLocalContext->SetLexiconId( lexiconId ); |
|
269 iLocalContext->SetModelBankAndLexiconExist( ETrue ); |
|
270 } |
|
271 |
|
272 // will fail if 2 requests come in together |
|
273 TRAPD( err, iLocalContext->BeginSaveToSrsL(this) ); |
|
274 |
|
275 return err; |
|
276 } |
|
277 |
|
278 // --------------------------------------------------------- |
|
279 // CNssContextMgr::SaveClientData |
|
280 // Saves to the VAS DB the client data associated with a context |
|
281 // --------------------------------------------------------- |
|
282 // |
|
283 TInt CNssContextMgr::SaveClientData( |
|
284 MNssContext* aContext ) |
|
285 { |
|
286 if ( !aContext || !( &aContext->ContextName() ) ) |
|
287 { |
|
288 return KErrArgument; |
|
289 } |
|
290 |
|
291 return iVasDatabase->SaveContextClientData( (CNssContext*)aContext ); |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------- |
|
295 // CNssContextMgr::GetGlobalContexts |
|
296 // retrives a list of context from the VAS DB, that have |
|
297 // their global flag ETrue |
|
298 // --------------------------------------------------------- |
|
299 // |
|
300 TMNssContextList* CNssContextMgr::GetGlobalContexts() |
|
301 { |
|
302 return iVasDatabase->GetGlobalContexts(); |
|
303 } |
|
304 |
|
305 // --------------------------------------------------------- |
|
306 // CNssContextMgr::VASDatabaseComplete |
|
307 // call back implementation from interface MNssVASDatabaseClient |
|
308 // --------------------------------------------------------- |
|
309 // |
|
310 void CNssContextMgr::VASDatabaseComplete(CArrayPtrFlat<CNssContext> *aContextList, |
|
311 CArrayPtrFlat<CNssTag>* /*aTagList*/ , |
|
312 CArrayPtrFlat<CNssTagReference>* /*aTagRefList*/, |
|
313 TNssVASDBClientReturnCode aCode) |
|
314 { |
|
315 switch(iState) |
|
316 { |
|
317 case EGetContextClientGetContext: |
|
318 iState = ENone; |
|
319 if ( aCode == EVASDBSuccess ) |
|
320 { |
|
321 |
|
322 if ( iGetContextClient ) |
|
323 { |
|
324 // make a copy of the context to return, this copy needs to |
|
325 // be deleted by the client. |
|
326 MNssContext *context = NULL; |
|
327 TRAPD( err, (context = ((*aContextList)[0])->CopyL()) ); |
|
328 aContextList->ResetAndDestroy(); |
|
329 delete aContextList; |
|
330 if( err == KErrNone ) |
|
331 { |
|
332 // call back to client with copied context. |
|
333 iGetContextClient->GetContextCompleted( context, KErrNone ); |
|
334 #ifndef __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
335 iGetContextClient->GetContextCompleted( context ); |
|
336 #endif // __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
337 } |
|
338 else |
|
339 { |
|
340 // call back to client with error code. |
|
341 iGetContextClient->GetContextCompleted( NULL, KErrGeneral ); |
|
342 #ifndef __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
343 iGetContextClient->GetContextFailed( MNssGetContextClient::EVASDBFailure ); |
|
344 #endif // __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
345 } |
|
346 |
|
347 } |
|
348 else |
|
349 { |
|
350 aContextList->ResetAndDestroy(); |
|
351 delete aContextList; |
|
352 } |
|
353 } |
|
354 else |
|
355 { |
|
356 // if get context list from VAS DB failed, there is no list returned back, |
|
357 // thus no need to delete any list. |
|
358 if ( iGetContextClient ) |
|
359 { |
|
360 iGetContextClient->GetContextCompleted( NULL, KErrGeneral ); |
|
361 #ifndef __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
362 iGetContextClient->GetContextFailed( MNssGetContextClient::EVASDBFailure ); |
|
363 #endif // __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
364 } |
|
365 } |
|
366 break; |
|
367 |
|
368 case EGetContextClientGetContextList: |
|
369 iState = ENone; |
|
370 if ( aCode == EVASDBSuccess ) |
|
371 { |
|
372 TRAPD( err, CNssContextListToMNssContextListConvertorL( aContextList ) ); |
|
373 if ( err != KErrNone && iGetContextClient ) |
|
374 { |
|
375 iGetContextClient->GetContextCompleted( NULL, err ); |
|
376 #ifndef __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
377 iGetContextClient->GetContextFailed( MNssGetContextClient::EVASDBFailure ); |
|
378 #endif // __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
379 |
|
380 } |
|
381 } |
|
382 else |
|
383 { |
|
384 if ( iGetContextClient ) |
|
385 { |
|
386 iGetContextClient->GetContextCompleted( NULL, KErrGeneral ); |
|
387 #ifndef __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
388 iGetContextClient->GetContextFailed( MNssGetContextClient::EVASDBFailure ); |
|
389 #endif // __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
390 } |
|
391 } |
|
392 break; |
|
393 |
|
394 case EDeleteContextClient: |
|
395 iState = ENone; |
|
396 if ( aCode == EVASDBSuccess ) |
|
397 { |
|
398 if ( iDeleteContextClient ) |
|
399 { |
|
400 if ( iLocalContext->CommitSrsChanges() == KErrNone ) |
|
401 { |
|
402 iDeleteContextClient->DeleteContextCompleted( KErrNone ); |
|
403 } |
|
404 else |
|
405 { |
|
406 iDeleteContextClient->DeleteContextCompleted( KErrGeneral ); |
|
407 } |
|
408 } |
|
409 } |
|
410 else |
|
411 { |
|
412 iLocalContext->CommitSrsChanges(); |
|
413 |
|
414 iDeleteContextClient->DeleteContextCompleted( KErrGeneral ); |
|
415 } |
|
416 break; |
|
417 |
|
418 case ESaveContextClient: |
|
419 iState = ENone; |
|
420 |
|
421 if ( aCode == EVASDBSuccess ) |
|
422 { |
|
423 // context has been saved in VAS DB and SRS DB. |
|
424 // model bank and lexicon have been created or existed from before |
|
425 iLocalContext->SetModelBankAndLexiconExist( ETrue ); |
|
426 |
|
427 if ( iSaveContextClient ) |
|
428 { |
|
429 if ( iLocalContext->CommitSrsChanges() == KErrNone ) |
|
430 { |
|
431 iSaveContextClient->SaveContextCompleted( KErrNone ); |
|
432 } |
|
433 else |
|
434 { |
|
435 iSaveContextClient->SaveContextCompleted( KErrGeneral ); |
|
436 } |
|
437 } |
|
438 } |
|
439 else // failed to save context in vas db |
|
440 { |
|
441 iLocalContext->RollbackSrsChanges(); |
|
442 iSaveContextClient->SaveContextCompleted( KErrGeneral ); |
|
443 } |
|
444 break; |
|
445 |
|
446 case ESaveClientDataClient: |
|
447 iState = ENone; |
|
448 if ( aCode == EVASDBSuccess ) |
|
449 { |
|
450 iSaveContextClient->SaveContextCompleted( KErrNone ); |
|
451 } |
|
452 else{ |
|
453 iSaveContextClient->SaveContextCompleted( KErrGeneral ); |
|
454 } |
|
455 break; |
|
456 |
|
457 case EInterCompContextMgrClientGetContext: |
|
458 iState = ENone; |
|
459 if ( aCode == EVASDBSuccess ) |
|
460 { |
|
461 if ( iInterCompContextMgrClient ) |
|
462 { |
|
463 // make a copy of the context to return, this copy needs to |
|
464 // be deleted by the client. |
|
465 CNssContext *context = NULL; |
|
466 TRAPD( err, (context = ((*aContextList)[0])->CopyL()) ); |
|
467 // delete the context list got from VAS DB. |
|
468 aContextList->ResetAndDestroy(); |
|
469 delete aContextList; |
|
470 if ( err == KErrNone ) |
|
471 { |
|
472 // call back to client with copied context. |
|
473 iInterCompContextMgrClient->GetContextCompleted( context, KErrNone ); |
|
474 } |
|
475 else |
|
476 { |
|
477 // call back to client with error code. |
|
478 iInterCompContextMgrClient->GetContextCompleted( |
|
479 NULL, err ); |
|
480 } |
|
481 } |
|
482 else |
|
483 { |
|
484 aContextList->ResetAndDestroy(); |
|
485 delete aContextList; |
|
486 } |
|
487 } |
|
488 else |
|
489 { |
|
490 if ( iInterCompContextMgrClient) |
|
491 { |
|
492 iInterCompContextMgrClient->GetContextCompleted( NULL, KErrGeneral ); |
|
493 } |
|
494 } |
|
495 break; |
|
496 |
|
497 case EInterCompContextMgrClientGetGlobalContexts: |
|
498 iState = ENone; |
|
499 if ( aCode == EVASDBSuccess ) |
|
500 { |
|
501 if ( iInterCompContextMgrClient ) |
|
502 { |
|
503 iInterCompContextMgrClient->GetGlobalContextsCompleted( |
|
504 aContextList, KErrNone ); |
|
505 } |
|
506 else |
|
507 { |
|
508 aContextList->ResetAndDestroy(); |
|
509 delete aContextList; |
|
510 } |
|
511 } |
|
512 else |
|
513 { |
|
514 if ( iInterCompContextMgrClient ) |
|
515 { |
|
516 iInterCompContextMgrClient->GetContextCompleted( |
|
517 NULL, KErrGeneral ); |
|
518 } |
|
519 } |
|
520 break; |
|
521 |
|
522 case EInterCompContextMgrClientGetContextList: |
|
523 iState = ENone; |
|
524 if ( aCode == EVASDBSuccess ) |
|
525 { |
|
526 if ( iInterCompContextMgrClient ) |
|
527 { |
|
528 iInterCompContextMgrClient->GetContextListCompleted( |
|
529 aContextList, NULL ); |
|
530 } |
|
531 else |
|
532 { |
|
533 aContextList->ResetAndDestroy(); |
|
534 delete aContextList; |
|
535 } |
|
536 } |
|
537 else |
|
538 { |
|
539 if ( iInterCompContextMgrClient ) |
|
540 { |
|
541 iInterCompContextMgrClient->GetContextCompleted( |
|
542 NULL, KErrNone ); |
|
543 } |
|
544 } |
|
545 break; |
|
546 |
|
547 default: |
|
548 break; |
|
549 } |
|
550 } |
|
551 |
|
552 // --------------------------------------------------------- |
|
553 // CNssContextMgr::HandleSaveSrsDBCompleted |
|
554 // call back implementation from MNssCoreSrsDBEventHandler |
|
555 // --------------------------------------------------------- |
|
556 // |
|
557 void CNssContextMgr::HandleSaveSrsDBCompleted() |
|
558 { |
|
559 TInt contextId = KNssVASDbDefaultValue; |
|
560 |
|
561 // Save context to VAS DB |
|
562 TInt ret = iVasDatabase->SaveContext( iLocalContext, contextId ); |
|
563 |
|
564 // Commit SRS DB |
|
565 if ( ret == KErrNone ) |
|
566 { |
|
567 iLocalContext->CommitSrsChanges(); |
|
568 } |
|
569 else |
|
570 { |
|
571 iLocalContext->RollbackSrsChanges(); |
|
572 } |
|
573 |
|
574 // When a context is saved for the first time, |
|
575 // a Context ID is assigned for it. |
|
576 if ( iLocalContext->ContextId() == KNssVASDbDefaultValue ) |
|
577 { |
|
578 iLocalContext->SetContextId( contextId ); |
|
579 } |
|
580 |
|
581 // Send callback |
|
582 if ( iSaveContextClient ) |
|
583 { |
|
584 if ( ret == KErrNone ) |
|
585 { |
|
586 iSaveContextClient->SaveContextCompleted( KErrNone ); |
|
587 } |
|
588 else |
|
589 { |
|
590 iSaveContextClient->SaveContextCompleted( KErrGeneral ); |
|
591 } |
|
592 } |
|
593 } |
|
594 |
|
595 // --------------------------------------------------------- |
|
596 // CNssContextMgr::HandleDeleteSrsDBCompleted |
|
597 // call back implementation from MNssCoreSrsDBEventHandler |
|
598 // NO LONGER USED AFTER SERIALIZATION OF DELETETAG. |
|
599 // CNssSpeechItemTrainer TAKES CARE OF DELETING NOW. |
|
600 // --------------------------------------------------------- |
|
601 // |
|
602 void CNssContextMgr::HandleDeleteSrsDBCompleted() |
|
603 { |
|
604 TInt ret = iVasDatabase->DeleteContext( iLocalContext->ContextName() ); |
|
605 |
|
606 // If VAS DB removal failed, roll back Plugin delete. |
|
607 if ( ret != KErrNone ) |
|
608 { |
|
609 iLocalContext->RollbackSrsChanges(); |
|
610 |
|
611 iDeleteContextClient->DeleteContextCompleted( KErrGeneral ); |
|
612 return; |
|
613 } |
|
614 |
|
615 // If VAS DB removal was successful, commit the Plugin removal. |
|
616 TInt commitErr; |
|
617 commitErr = iLocalContext->CommitSrsChanges(); |
|
618 |
|
619 // DB becomes corrupted: VAS DB removal was successful, SRS DB wasn't. |
|
620 if ( commitErr != KErrNone ) |
|
621 { |
|
622 iDeleteContextClient->DeleteContextCompleted( KErrGeneral ); |
|
623 return; |
|
624 } |
|
625 |
|
626 // Both removals were successful. |
|
627 iDeleteContextClient->DeleteContextCompleted( KErrNone ); |
|
628 } |
|
629 |
|
630 // ----------------------------------------------------------------------------- |
|
631 // CNssContextMgr::HandleResetSrsDBCompleted |
|
632 // call back from SRS DB |
|
633 // ----------------------------------------------------------------------------- |
|
634 // |
|
635 void CNssContextMgr::HandleResetSrsDBCompleted() |
|
636 { |
|
637 if ( iVasDatabase->ResetModelBank( iModelBankId ) == KErrNone ) |
|
638 { |
|
639 iContextBuilder->GetContextPortal()->CommitSaveContext(); |
|
640 iResetClient->HandleResetComplete( KErrNone ); |
|
641 } |
|
642 else{ |
|
643 iContextBuilder->GetContextPortal()->RollbackSaveContext(); |
|
644 iResetClient->HandleResetComplete( KErrGeneral ); |
|
645 } |
|
646 } |
|
647 |
|
648 // --------------------------------------------------------- |
|
649 // CNssContextMgr::HandleSrsDBError |
|
650 // call back implementation from MNssCoreSrsDBEventHandler |
|
651 // --------------------------------------------------------- |
|
652 // |
|
653 void CNssContextMgr::HandleSrsDBError( MNssCoreSrsDBEventHandler::TNssSrsDBResult /*aResult*/) |
|
654 { |
|
655 switch(iState) |
|
656 { |
|
657 case ESaveContextClient: |
|
658 iState = ENone; |
|
659 if ( iSaveContextClient ) |
|
660 { |
|
661 iSaveContextClient->SaveContextCompleted( KErrGeneral ); |
|
662 } |
|
663 break; |
|
664 |
|
665 case EDeleteContextClient: |
|
666 iState = ENone; |
|
667 if ( iDeleteContextClient) |
|
668 { |
|
669 iDeleteContextClient->DeleteContextCompleted( KErrGeneral ); |
|
670 } |
|
671 break; |
|
672 |
|
673 default: |
|
674 break; |
|
675 } |
|
676 } |
|
677 |
|
678 // --------------------------------------------------------- |
|
679 // CNssContextMgr::CNssContextListToMNssContextListConvertorL |
|
680 // private method to convert CNssTag list to MNssTag list |
|
681 // --------------------------------------------------------- |
|
682 // |
|
683 void CNssContextMgr::CNssContextListToMNssContextListConvertorL( |
|
684 CArrayPtrFlat<CNssContext>* aSourceList ) |
|
685 { |
|
686 CArrayPtrFlat<MNssContext>* destinationList = new (ELeave) CArrayPtrFlat<MNssContext>(1); |
|
687 CleanupStack::PushL( destinationList ); |
|
688 CleanupResetAndDestroyPushL( *destinationList ); |
|
689 for ( TInt i( 0 ); i < aSourceList->Count(); i++ ) |
|
690 { |
|
691 destinationList->AppendL((MNssContext*) (*aSourceList)[i]); |
|
692 } |
|
693 aSourceList->Reset(); |
|
694 delete aSourceList; |
|
695 CleanupStack::Pop( destinationList ); // ResetAndDestroy |
|
696 CleanupStack::Pop( destinationList ); // list itself |
|
697 iGetContextClient->GetContextListCompleted( destinationList, KErrNone ); |
|
698 } |
|
699 |
|
700 // --------------------------------------------------------- |
|
701 // CNssContextMgr::TagExist |
|
702 // determine if a tags exists for a context in the VAS Database. |
|
703 // --------------------------------------------------------- |
|
704 // |
|
705 TBool CNssContextMgr::TagExist( CNssContext* aContext ) |
|
706 { |
|
707 return iVasDatabase->TagExist( aContext ); |
|
708 } |
|
709 |
|
710 // --------------------------------------------------------- |
|
711 // CNssContextMgr::CancelGetContext |
|
712 // cancel get context /get context list / get global contexts |
|
713 // --------------------------------------------------------- |
|
714 // |
|
715 void CNssContextMgr::CancelGetContext() |
|
716 { |
|
717 iInterCompContextMgrClient = NULL; |
|
718 |
|
719 iGetContextClient = NULL; |
|
720 } |
|
721 |
|
722 // --------------------------------------------------------- |
|
723 // CNssContextMgr::DoCancel |
|
724 // A function required by CActive |
|
725 // --------------------------------------------------------- |
|
726 // |
|
727 void CNssContextMgr::DoCancel() |
|
728 { |
|
729 CancelGetContext(); |
|
730 } |
|
731 |
|
732 // --------------------------------------------------------- |
|
733 // CNssContextMgr::RunL |
|
734 // CActive calls this function when higher-priority tasks |
|
735 // have been finished. |
|
736 // --------------------------------------------------------- |
|
737 // |
|
738 void CNssContextMgr::RunL() |
|
739 { |
|
740 TInt err( iStatus.Int() ); |
|
741 |
|
742 RUBY_DEBUG1( "CNssContextMgr::RunL, iStatus = %d", err ); |
|
743 |
|
744 switch( iState ) |
|
745 { |
|
746 case EGetContextClientGetContext: |
|
747 { |
|
748 iState = ENone; |
|
749 |
|
750 MNssContext* context = 0; |
|
751 |
|
752 TRAP( err, (context = ((*iContextList)[0])->CopyL()) ); |
|
753 iContextList->ResetAndDestroy(); |
|
754 |
|
755 delete iContextList; |
|
756 iContextList = 0; |
|
757 |
|
758 if ( iGetContextClient ) |
|
759 { |
|
760 if ( context ) |
|
761 { |
|
762 iGetContextClient->GetContextCompleted( context, KErrNone ); |
|
763 #ifndef __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
764 iGetContextClient->GetContextCompleted( context ); |
|
765 #endif // __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
766 } |
|
767 else |
|
768 { |
|
769 iGetContextClient->GetContextCompleted( NULL, KErrGeneral ); |
|
770 #ifndef __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
771 iGetContextClient->GetContextFailed( MNssGetContextClient::EVASDBFailure ); |
|
772 #endif // __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
773 } |
|
774 } |
|
775 else |
|
776 { |
|
777 delete context; |
|
778 } |
|
779 } |
|
780 break; |
|
781 |
|
782 case EGetContextClientGetContextList: |
|
783 { |
|
784 CArrayPtrFlat<MNssContext>* contextList = |
|
785 new CArrayPtrFlat<MNssContext>( KContextArrayGranularity ); |
|
786 |
|
787 if ( contextList ) |
|
788 { |
|
789 err = KErrNone; |
|
790 for( TInt k = 0; k < iContextList->Count(); k++ ) |
|
791 { |
|
792 TRAP( err, contextList->AppendL( (*iContextList)[k] ) ); |
|
793 } |
|
794 |
|
795 delete iContextList; |
|
796 iContextList = 0; |
|
797 |
|
798 if ( err != KErrNone ) |
|
799 { |
|
800 contextList->ResetAndDestroy(); |
|
801 delete contextList; |
|
802 contextList = 0; |
|
803 } |
|
804 } |
|
805 |
|
806 if ( iGetContextClient ) |
|
807 { |
|
808 if ( contextList ) |
|
809 { |
|
810 iGetContextClient->GetContextListCompleted( contextList, KErrNone ); |
|
811 } |
|
812 else{ |
|
813 iGetContextClient->GetContextCompleted( NULL, KErrGeneral ); |
|
814 #ifndef __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
815 iGetContextClient->GetContextFailed( MNssGetContextClient::EVASDBFailure ); |
|
816 #endif // __SIND_RD_BREAK_PHONEBOOK_COMPATIBILITY |
|
817 } |
|
818 } |
|
819 else |
|
820 { |
|
821 contextList->ResetAndDestroy(); |
|
822 delete contextList; |
|
823 contextList = NULL; |
|
824 } |
|
825 } |
|
826 break; |
|
827 |
|
828 case EInterCompContextMgrClientGetContext: |
|
829 { |
|
830 CArrayPtrFlat<CNssContext>* contextList = iContextList; |
|
831 iContextList = 0; |
|
832 |
|
833 if ( contextList ) |
|
834 { |
|
835 iInterCompContextMgrClient->GetContextListCompleted( |
|
836 contextList, NULL ); |
|
837 } |
|
838 else{ |
|
839 iInterCompContextMgrClient->GetContextCompleted( |
|
840 NULL, KErrGeneral ); |
|
841 } |
|
842 } |
|
843 break; |
|
844 |
|
845 default: |
|
846 { |
|
847 User::Panic( KContextMgrPanic, __LINE__ ); |
|
848 } |
|
849 break; |
|
850 } |
|
851 } |
|
852 |
|
853 // --------------------------------------------------------- |
|
854 // CNssContextMgr::RunError |
|
855 // Cleanup function required by CActive |
|
856 // --------------------------------------------------------- |
|
857 // |
|
858 TInt CNssContextMgr::RunError(TInt /*aError*/) |
|
859 { |
|
860 if ( iContextList ) |
|
861 { |
|
862 iContextList->ResetAndDestroy(); |
|
863 delete iContextList; |
|
864 iContextList = 0; |
|
865 } |
|
866 |
|
867 Cancel(); |
|
868 |
|
869 return KErrNone; |
|
870 } |
|
871 |
|
872 // --------------------------------------------------------- |
|
873 // CNssContextMgr::ResetFactoryModels |
|
874 // Resets factory models |
|
875 // --------------------------------------------------------- |
|
876 // |
|
877 TInt CNssContextMgr::ResetFactoryModels( MNssResetFactoryModelsClient* aClient ) |
|
878 { |
|
879 if ( !aClient ) |
|
880 { |
|
881 return KErrArgument; |
|
882 } |
|
883 |
|
884 if ( IsActive() ) |
|
885 { |
|
886 return KErrNotReady; |
|
887 } |
|
888 |
|
889 iResetClient = aClient; |
|
890 |
|
891 // Old ID: We destroy the old (speaker adapted) model bank with this ID. |
|
892 TUint32 oldId; |
|
893 |
|
894 // New ID: When we create a new (speaker independent) model bank, |
|
895 // we save the ID here. |
|
896 iModelBankId = KInvalidModelBankID; |
|
897 |
|
898 TInt err = iVasDatabase->GetDefaultModelBankId( oldId ); |
|
899 |
|
900 if ( err != KErrNone ) |
|
901 { |
|
902 return( err ); |
|
903 } |
|
904 |
|
905 TRAP( err, iContextBuilder->GetContextPortal()->BeginResetModelsL( |
|
906 (TSIModelBankID)oldId, iModelBankId, this ) ); |
|
907 |
|
908 if ( err != KErrNone ) |
|
909 { |
|
910 return( err ); |
|
911 } |
|
912 |
|
913 return( KErrNone ); |
|
914 } |