|
1 /* |
|
2 * Copyright (c) 2003-2005 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: CNssVasDatabase is responsible for the issuing of requests to |
|
15 * to the VasDb server and returning the results to the VasDb Managers. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "srsfbldvariant.hrh" |
|
21 #include <e32base.h> |
|
22 #include <e32test.h> |
|
23 #include "nssvascvasdatabase.h" |
|
24 #include "nssvascspeechitem.h" |
|
25 #include "nssvascvasdbsrvdef.h" |
|
26 #include "nssvastspeechitemconstant.h" |
|
27 #include <f32file.h> |
|
28 #include "rubydebug.h" |
|
29 |
|
30 // Complementary macro for TRAPD: |
|
31 // TRAPD( err, doSomething() ); |
|
32 // REACT( err, return( err ) ); |
|
33 #define REACT(a,b) if ( a < 0 ) {b;} |
|
34 |
|
35 const TInt KTagRefListGranularity = 2; |
|
36 |
|
37 const TInt KFetchedTagRefListGranularity = 50; |
|
38 |
|
39 #ifdef _DEBUG |
|
40 // used in UDEB macros only |
|
41 _LIT( KVasDatabasePanic, "CNssVasDatabase.cpp" ); |
|
42 #endif // _DEBUG |
|
43 |
|
44 // ============================ Methods =============================== |
|
45 |
|
46 //-------------------------------------------------------- |
|
47 //C++ default constructor can NOT contain any code that |
|
48 // might leave. |
|
49 //-------------------------------------------------------- |
|
50 CNssVASDatabase::CNssVASDatabase( TInt /*aPriority*/ ) |
|
51 : iIsLocked( EFalse ) |
|
52 { |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CNssVasDatabase::NewLC |
|
57 // Two-phased constructor. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CNssVASDatabase* CNssVASDatabase::NewLC( TInt aPriority ) |
|
61 { |
|
62 CNssVASDatabase* self = new(ELeave)CNssVASDatabase( aPriority ); |
|
63 CleanupStack::PushL( self ); |
|
64 self->ConstructL(); |
|
65 return self; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CNssVasDatabase::NewL |
|
70 // Two-phased constructor. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CNssVASDatabase* CNssVASDatabase::NewL( TInt aPriority ) |
|
74 { |
|
75 CNssVASDatabase* self = NewLC( aPriority ); |
|
76 CleanupStack::Pop( self ); |
|
77 return self; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CNssVasDatabase::ConstructL |
|
82 // Symbian 2nd phase constructor can leave. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 void CNssVASDatabase::ConstructL() |
|
86 { |
|
87 iContextBuilder = CNssContextBuilder::NewL(); |
|
88 iSpeechItemBuilder = CNssSpeechItemBuilder::NewL( this ); |
|
89 iVasDb = CNssVasDb::NewL( *iContextBuilder, |
|
90 *iSpeechItemBuilder); |
|
91 iTNssTagRefList = new(ELeave) TNssTagReferenceListArray( KTagRefListGranularity ); |
|
92 } |
|
93 |
|
94 //------------------------------------------ |
|
95 // CNssVASDatabase::~CNssVASDatabase |
|
96 // Destructor |
|
97 //------------------------------------------ |
|
98 CNssVASDatabase::~CNssVASDatabase() |
|
99 { |
|
100 RUBY_DEBUG0( "CNssVASDatabase::~CNssVASDatabase" ); |
|
101 |
|
102 if ( iGrammarIdRuleIdPackage ) |
|
103 { |
|
104 delete iGrammarIdRuleIdPackage; |
|
105 } |
|
106 |
|
107 if ( iSpeechItemBuilder ) |
|
108 { |
|
109 delete iSpeechItemBuilder; |
|
110 } |
|
111 |
|
112 if ( iVASDBEventMonitor ) |
|
113 { |
|
114 delete iVASDBEventMonitor; |
|
115 } |
|
116 |
|
117 if ( iTNssTagRefList ) |
|
118 { |
|
119 iTNssTagRefList->Reset(); |
|
120 delete iTNssTagRefList; |
|
121 } |
|
122 |
|
123 if ( iVasDb ) |
|
124 { |
|
125 delete iVasDb; |
|
126 } |
|
127 if ( iContextBuilder ) |
|
128 { |
|
129 delete iContextBuilder; |
|
130 } |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // RNssVasDbSession::OpenDatabase |
|
135 // Method to open the database. |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 TInt CNssVASDatabase::OpenDatabase() |
|
139 { |
|
140 if ( iConnected ) |
|
141 { |
|
142 iConnected++; |
|
143 return KErrDbAlreadyOpen; |
|
144 } |
|
145 |
|
146 TRAPD( error, iVasDb->OpenDatabaseL() ); |
|
147 |
|
148 if ( error == KErrNone ) |
|
149 { |
|
150 iConnected++; |
|
151 } |
|
152 |
|
153 return error; |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // RNssVasDbSession::CloseDatabase |
|
158 // Method to close the database. |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void CNssVASDatabase::CloseDatabase() |
|
162 { |
|
163 // Check if already closed (or never opened) |
|
164 if ( iConnected > 0 ) |
|
165 { |
|
166 // Some other VAS instance in the same thread may be using the database. |
|
167 iConnected--; |
|
168 |
|
169 // If not, close it. |
|
170 if ( iConnected <= 0 ) |
|
171 { |
|
172 iVasDb->CloseDatabase(); |
|
173 } |
|
174 } |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CNssVasDatabase::CreateDb |
|
179 // Method to create vas database |
|
180 // ----------------------------------------------------------------------------- |
|
181 TInt CNssVASDatabase::CreateDb() |
|
182 { |
|
183 TRAPD( error, iVasDb->CreateDatabaseL() ); |
|
184 |
|
185 return error; |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CNssVasDatabase::StartMonitoringDatabaseL |
|
190 // Method to start monitoring changes to vas database |
|
191 // ----------------------------------------------------------------------------- |
|
192 void CNssVASDatabase::StartMonitoringDatabaseL() |
|
193 { |
|
194 //iVASDBEventMonitor = CNssVASDBEventMonitor::NewL(); |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CNssVasDatabase::AddObserverL |
|
199 // Method to add an observer of the vas database |
|
200 // ----------------------------------------------------------------------------- |
|
201 void CNssVASDatabase::AddObserverL( MNssVASDatabaseObserver* /*aObserver*/ ) |
|
202 { |
|
203 User::Leave( KErrNotSupported ); |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CNssVasDatabase::RemoveObserverL |
|
208 // Method to remove an observer of the vas database |
|
209 // ----------------------------------------------------------------------------- |
|
210 TInt CNssVASDatabase::RemoveObserver( MNssVASDatabaseObserver* /*aObserver*/ ) |
|
211 { |
|
212 return KErrNotFound; |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CNssVasDatabase::ModelBankAndLexiconExist |
|
217 // Method to determine if modelbank and lexicon ids exist. |
|
218 // ----------------------------------------------------------------------------- |
|
219 TBool CNssVASDatabase::ModelBankAndLexiconExist( TUint32 &aModelBankId, TUint32 &aLexiconId ) |
|
220 { |
|
221 TBool ret = EFalse; |
|
222 |
|
223 TRAPD( err, ret = iVasDb->GetModelBankIdLexiconIdL( aModelBankId, aLexiconId ) ); |
|
224 |
|
225 // To remove warning |
|
226 if ( err != KErrNone ) |
|
227 { |
|
228 } |
|
229 |
|
230 return ret; |
|
231 } |
|
232 |
|
233 //----------------------------------------------------------------------------- |
|
234 //CNssVasDatabase::TagExist |
|
235 //Method to determine if tags exist for a context. |
|
236 //----------------------------------------------------------------------------- |
|
237 TBool CNssVASDatabase::TagExist( CNssContext* aContext ) |
|
238 { |
|
239 TBool ret( EFalse ); |
|
240 |
|
241 if ( aContext->ContextId() != KNssVASDbDefaultValue ) |
|
242 { |
|
243 TRAPD( error, ret = iVasDb->TagExistL( aContext->ContextId() ) ); |
|
244 REACT( error, ret = EFalse ); |
|
245 } |
|
246 else |
|
247 { |
|
248 RUBY_DEBUG0( "CNssVASDatabase::TagExist ERROR:Unsaved context" ); |
|
249 } |
|
250 |
|
251 return ret; |
|
252 } |
|
253 //----------------------------------------------------------------------------- |
|
254 //CNssVasDatabase::TagCount |
|
255 //Method to get the number of tags for a context. |
|
256 //----------------------------------------------------------------------------- |
|
257 TInt CNssVASDatabase::TagCount( CNssContext* aContext ) |
|
258 { |
|
259 TInt ret( KErrNotFound ); |
|
260 |
|
261 if ( aContext->ContextId() != KNssVASDbDefaultValue ) |
|
262 { |
|
263 TRAPD( error, ret = iVasDb->TagCountL( aContext->ContextId() ) ); |
|
264 |
|
265 // To remove warning |
|
266 if ( error != KErrNone ) |
|
267 { |
|
268 } |
|
269 } |
|
270 |
|
271 return ret; |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // CNssVasDatabase::SaveContext |
|
276 // Method to save a context |
|
277 // ----------------------------------------------------------------------------- |
|
278 TInt CNssVASDatabase::SaveContext( CNssContext* aContext, TInt& aContextId ) |
|
279 { |
|
280 TInt ret = KErrNone; |
|
281 |
|
282 aContextId = aContext->ContextId(); |
|
283 |
|
284 if ( aContext->ContextId() == KNssVASDbDefaultValue ) |
|
285 { |
|
286 TRAP( ret, iVasDb->SaveContextL( *aContext, aContextId ) ); |
|
287 } |
|
288 else |
|
289 { |
|
290 TRAP( ret, iVasDb->UpdateContextL( *aContext ) ); |
|
291 } |
|
292 |
|
293 return ret; |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CNssVasDatabase::SaveContextClientData |
|
298 // Method to save the clientdata of a context |
|
299 // ----------------------------------------------------------------------------- |
|
300 TInt CNssVASDatabase::SaveContextClientData( CNssContext* aContext ) |
|
301 { |
|
302 TRAPD( error, iVasDb->UpdateContextClientDataL( *aContext ) ); |
|
303 return error; |
|
304 } |
|
305 |
|
306 // ----------------------------------------------------------------------------- |
|
307 // CNssVasDatabase::GetContext |
|
308 // Method to get a context by name |
|
309 // ----------------------------------------------------------------------------- |
|
310 CArrayPtrFlat<CNssContext>* CNssVASDatabase::GetContext( const TDesC& aName ) |
|
311 { |
|
312 CArrayPtrFlat<CNssContext>* result = NULL; |
|
313 |
|
314 TRAPD( error, result = iVasDb->GetContextByNameL( aName ) ); |
|
315 |
|
316 // To remove warning |
|
317 if ( error != KErrNone ) |
|
318 { |
|
319 } |
|
320 |
|
321 return result; |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CNssVasDatabase::GetGlobalContexts |
|
326 // Method to get all global contexts |
|
327 // ----------------------------------------------------------------------------- |
|
328 CArrayPtrFlat<CNssContext>* CNssVASDatabase::GetGlobalContexts() |
|
329 { |
|
330 CArrayPtrFlat<CNssContext>* result = NULL; |
|
331 |
|
332 TRAPD( error, result = iVasDb->GetGlobalContexts() ); |
|
333 |
|
334 // To remove warning |
|
335 if ( error != KErrNone ) |
|
336 { |
|
337 } |
|
338 |
|
339 return( result ); |
|
340 } |
|
341 |
|
342 // ----------------------------------------------------------------------------- |
|
343 // CNssVasDatabase::GetAllContexts |
|
344 // Method to get all contexts |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 CArrayPtrFlat<CNssContext>* CNssVASDatabase::GetAllContexts() |
|
348 { |
|
349 CArrayPtrFlat<CNssContext>* result = NULL; |
|
350 |
|
351 TRAPD( error, result = iVasDb->GetAllContexts() ); |
|
352 |
|
353 // To remove warning |
|
354 if ( error != KErrNone ) |
|
355 { |
|
356 } |
|
357 |
|
358 return result; |
|
359 } |
|
360 |
|
361 // ----------------------------------------------------------------------------- |
|
362 // CNssVasDatabase::SaveTag |
|
363 // Method to save a tag |
|
364 // ----------------------------------------------------------------------------- |
|
365 TInt CNssVASDatabase::SaveTag( CNssTag* aTag, TInt& aNewId ) |
|
366 { |
|
367 TInt ret = KErrNone; |
|
368 |
|
369 if ( aTag->TagId() == KNssVASDbDefaultValue ) |
|
370 { |
|
371 TRAP( ret, iVasDb->SaveTagL( *aTag, aNewId ) ); |
|
372 } |
|
373 else |
|
374 { |
|
375 // Used to call RNssVasDbSession::UpdateTag |
|
376 // which returned KErrNotSupported |
|
377 ret = KErrNotSupported; |
|
378 } |
|
379 |
|
380 return ret; |
|
381 } |
|
382 |
|
383 // ----------------------------------------------------------------------------- |
|
384 // CNssVasDatabase::DeleteTag |
|
385 // Method to delete several tags |
|
386 // ----------------------------------------------------------------------------- |
|
387 // |
|
388 TInt CNssVASDatabase::DeleteTags( const RArray<TUint32>& aTagIdArray ) |
|
389 { |
|
390 TRAPD( error, iVasDb->DeleteTagsL( aTagIdArray ) ); |
|
391 |
|
392 return error; |
|
393 } |
|
394 |
|
395 // ----------------------------------------------------------------------------- |
|
396 // CNssVasDatabase::SaveTag |
|
397 // Method to save several tags |
|
398 // ----------------------------------------------------------------------------- |
|
399 // |
|
400 TInt CNssVASDatabase::SaveTags( RPointerArray<CNssTag>* aTagArray ) |
|
401 { |
|
402 RUBY_DEBUG0("CNssVASDatabase::SaveTags"); |
|
403 |
|
404 RArray<TInt> tagIdArray; |
|
405 |
|
406 ASSERT( aTagArray ); |
|
407 |
|
408 TInt arrayCount = aTagArray ? aTagArray->Count() : 0; |
|
409 if( arrayCount == 0 ) |
|
410 { |
|
411 arrayCount++; |
|
412 } |
|
413 |
|
414 CArrayPtrFlat<CNssTag>* ctagArray = new CArrayPtrFlat<CNssTag>( arrayCount ); |
|
415 |
|
416 for( TInt i( 0 ); i < aTagArray->Count(); i++ ) |
|
417 { |
|
418 TRAPD( error, ctagArray->AppendL( (*aTagArray)[i] ) ); |
|
419 if( error != KErrNone ) |
|
420 { |
|
421 delete ctagArray; |
|
422 return error; |
|
423 } |
|
424 } |
|
425 |
|
426 TRAPD( error, iVasDb->SaveTagsL( ctagArray, tagIdArray ) ); |
|
427 |
|
428 if( error == KErrNone ) |
|
429 { |
|
430 RUBY_ASSERT_DEBUG( ctagArray->Count() == tagIdArray.Count(), |
|
431 User::Panic( KVasDatabasePanic, __LINE__ ) ); |
|
432 |
|
433 for ( TInt k( 0 ); k < ctagArray->Count(); k++ ) |
|
434 { |
|
435 (*aTagArray)[k]->SetTagId( tagIdArray[k] ); |
|
436 } |
|
437 } |
|
438 else |
|
439 { |
|
440 // iSess->SaveTags failed |
|
441 /** @todo Higher level handler should display some "No memory" label if possible |
|
442 Or should we do it here? */ |
|
443 } |
|
444 |
|
445 delete ctagArray; |
|
446 |
|
447 tagIdArray.Close(); |
|
448 |
|
449 return error; |
|
450 } |
|
451 |
|
452 // ----------------------------------------------------------------------------- |
|
453 // CNssVasDatabase::GetTag |
|
454 // Method to get a tag by name |
|
455 // ----------------------------------------------------------------------------- |
|
456 MNssTagListArray* CNssVASDatabase::GetTag( const TDesC& aName ) |
|
457 { |
|
458 CArrayPtrFlat<CNssTag>* result = NULL; |
|
459 |
|
460 TRAPD( error, result = iVasDb->GetTagL( aName ) ); |
|
461 |
|
462 // To remove warning |
|
463 if ( error != KErrNone ) |
|
464 { |
|
465 } |
|
466 |
|
467 CArrayPtrFlat<MNssTag>* array = NULL; |
|
468 |
|
469 TInt arrayCount = result ? result->Count() : 0; |
|
470 if( arrayCount == 0 ) |
|
471 { |
|
472 arrayCount++; |
|
473 } |
|
474 |
|
475 array = new CArrayPtrFlat<MNssTag>( arrayCount ); |
|
476 if( !array ) |
|
477 { |
|
478 return NULL; |
|
479 } |
|
480 |
|
481 if( result ) |
|
482 { |
|
483 for( TInt i( 0 ); i < result->Count(); i++ ) |
|
484 { |
|
485 TRAP( error, array->AppendL( result->At( i ) ) ); |
|
486 if( error != KErrNone ) |
|
487 { |
|
488 return NULL; |
|
489 } |
|
490 } |
|
491 |
|
492 result->Reset(); |
|
493 delete result; |
|
494 } |
|
495 |
|
496 return array; |
|
497 } |
|
498 |
|
499 // ----------------------------------------------------------------------------- |
|
500 // CNssVasDatabase::GetTag |
|
501 // Method to get a tag by context and name |
|
502 // Not fully implemented. |
|
503 // ----------------------------------------------------------------------------- |
|
504 |
|
505 MNssTagListArray* CNssVASDatabase::GetTag(CNssContext* /*aContext*/,const TDesC& aName) |
|
506 { |
|
507 return GetTag(aName); |
|
508 } |
|
509 |
|
510 // ----------------------------------------------------------------------------- |
|
511 // CNssVasDatabase::GetTag |
|
512 // Method to get a tag by context. |
|
513 // ----------------------------------------------------------------------------- |
|
514 // |
|
515 CArrayPtrFlat<MNssTag>* CNssVASDatabase::GetTag( CNssContext* aContext ) |
|
516 { |
|
517 CArrayPtrFlat<CNssTag>* result = NULL; |
|
518 |
|
519 TRAPD( error, result = iVasDb->GetTagL( *aContext ) ); |
|
520 |
|
521 // To remove warning |
|
522 if ( error != KErrNone ) |
|
523 { |
|
524 } |
|
525 |
|
526 CArrayPtrFlat<MNssTag>* array = NULL; |
|
527 |
|
528 if( result ) |
|
529 { |
|
530 array = new CArrayPtrFlat<MNssTag>( result->Count() ); |
|
531 if( !array ) |
|
532 { |
|
533 return NULL; |
|
534 } |
|
535 |
|
536 for( TInt i( 0 ); i < result->Count(); i++ ) |
|
537 { |
|
538 CNssTag* tag = result->At( i ); |
|
539 TRAP( error, array->AppendL( result->At( i ) ) ); |
|
540 if( error != KErrNone ) |
|
541 { |
|
542 return NULL; |
|
543 } |
|
544 } |
|
545 |
|
546 result->Reset(); |
|
547 delete result; |
|
548 } |
|
549 |
|
550 return array; |
|
551 } |
|
552 |
|
553 // ----------------------------------------------------------------------------- |
|
554 // CNssVasDatabase::GetTag |
|
555 // Method to get a tag by grammarid and ruleid. |
|
556 // ----------------------------------------------------------------------------- |
|
557 // |
|
558 MNssTagListArray* CNssVASDatabase::GetTag( const TInt aGrammarID, const TInt aRuleID ) |
|
559 { |
|
560 iTNssGrammarIdRuleId.iGrammarId = aGrammarID; |
|
561 iTNssGrammarIdRuleId.iRuleId = aRuleID; |
|
562 |
|
563 CArrayPtrFlat<CNssTag>* result = NULL; |
|
564 |
|
565 TRAPD( error, result = iVasDb->GetTagL( iTNssGrammarIdRuleId ) ); |
|
566 |
|
567 // To remove warning |
|
568 if ( error != KErrNone ) |
|
569 { |
|
570 } |
|
571 |
|
572 CArrayPtrFlat<MNssTag>* array = NULL; |
|
573 |
|
574 TInt arrayCount = result ? result->Count() : 0; |
|
575 if( arrayCount == 0 ) |
|
576 { |
|
577 arrayCount++; |
|
578 } |
|
579 |
|
580 array = new CArrayPtrFlat<MNssTag>( arrayCount ); |
|
581 if( !array ) |
|
582 { |
|
583 return NULL; |
|
584 } |
|
585 |
|
586 if( result ) |
|
587 { |
|
588 for( TInt i( 0 ); i < result->Count(); i++ ) |
|
589 { |
|
590 TRAP( error, array->AppendL( result->At( i ) ) ); |
|
591 if( error != KErrNone ) |
|
592 { |
|
593 return NULL; |
|
594 } |
|
595 } |
|
596 |
|
597 result->Reset(); |
|
598 delete result; |
|
599 } |
|
600 |
|
601 return array; |
|
602 } |
|
603 |
|
604 // ----------------------------------------------------------------------------- |
|
605 // CNssVasDatabase::GetTags |
|
606 // Method to get tags by their grammarid and ruleid. |
|
607 // ----------------------------------------------------------------------------- |
|
608 // |
|
609 MNssTagListArray* CNssVASDatabase::GetTags( TNssGrammarIdRuleIdListArray& aGrammarIdRuleIds) |
|
610 { |
|
611 CArrayPtrFlat<CNssTag>* result = NULL; |
|
612 |
|
613 TRAPD( error, result = iVasDb->GetTagsL( aGrammarIdRuleIds ) ); |
|
614 |
|
615 // To remove warning |
|
616 if ( error != KErrNone ) |
|
617 { |
|
618 } |
|
619 |
|
620 CArrayPtrFlat<MNssTag>* array = NULL; |
|
621 |
|
622 TInt arrayCount = result ? result->Count() : 0; |
|
623 if( arrayCount == 0 ) |
|
624 { |
|
625 arrayCount++; |
|
626 } |
|
627 |
|
628 array = new CArrayPtrFlat<MNssTag>( arrayCount ); |
|
629 if( !array ) |
|
630 { |
|
631 return NULL; |
|
632 } |
|
633 |
|
634 if( result ) |
|
635 { |
|
636 for( TInt i( 0 ); i < result->Count(); i++ ) |
|
637 { |
|
638 TRAP( error, array->AppendL( result->At( i ) ) ); |
|
639 if( error != KErrNone ) |
|
640 { |
|
641 return NULL; |
|
642 } |
|
643 } |
|
644 |
|
645 result->Reset(); |
|
646 delete result; |
|
647 } |
|
648 |
|
649 return array; |
|
650 } |
|
651 |
|
652 // ----------------------------------------------------------------------------- |
|
653 // CNssVasDatabase::GetTag |
|
654 // Method to get a tag by tagid |
|
655 // ----------------------------------------------------------------------------- |
|
656 MNssTagListArray* CNssVASDatabase::GetTag( const TUint32 aTagId ) |
|
657 { |
|
658 CArrayPtrFlat<CNssTag>* result = NULL; |
|
659 |
|
660 TRAPD( error, result = iVasDb->GetTagL( aTagId ) ); |
|
661 |
|
662 // To remove warning |
|
663 if ( error != KErrNone ) |
|
664 { |
|
665 } |
|
666 |
|
667 CArrayPtrFlat<MNssTag>* array = NULL; |
|
668 |
|
669 TInt arrayCount = result ? result->Count() : 0; |
|
670 if( arrayCount == 0 ) |
|
671 { |
|
672 arrayCount++; |
|
673 } |
|
674 |
|
675 array = new CArrayPtrFlat<MNssTag>( arrayCount ); |
|
676 if( !array ) |
|
677 { |
|
678 return NULL; |
|
679 } |
|
680 |
|
681 if( result ) |
|
682 { |
|
683 for( TInt i( 0 ); i < result->Count(); i++ ) |
|
684 { |
|
685 TRAP( error, array->AppendL( result->At( i ) ) ); |
|
686 if( error != KErrNone ) |
|
687 { |
|
688 return NULL; |
|
689 } |
|
690 } |
|
691 |
|
692 result->Reset(); |
|
693 delete result; |
|
694 } |
|
695 |
|
696 return array; |
|
697 } |
|
698 |
|
699 // ----------------------------------------------------------------------------- |
|
700 // CNssVasDatabase::GetTagList |
|
701 // Method to get tags by rrd int position. |
|
702 // ----------------------------------------------------------------------------- |
|
703 MNssTagListArray* CNssVASDatabase::GetTagList( CNssContext* aContext, TInt aNum, TInt aPosition ) |
|
704 { |
|
705 CArrayPtrFlat<CNssTag>* result = NULL; |
|
706 |
|
707 TRAPD( error, result = iVasDb->GetTagL( aContext->ContextId(), |
|
708 aNum, aPosition ) ); |
|
709 |
|
710 // To remove warning |
|
711 if ( error != KErrNone ) |
|
712 { |
|
713 } |
|
714 |
|
715 CArrayPtrFlat<MNssTag>* array = NULL; |
|
716 |
|
717 TInt arrayCount = result ? result->Count() : 0; |
|
718 if( arrayCount == 0 ) |
|
719 { |
|
720 arrayCount++; |
|
721 } |
|
722 |
|
723 array = new CArrayPtrFlat<MNssTag>( arrayCount ); |
|
724 if( !array ) |
|
725 { |
|
726 return NULL; |
|
727 } |
|
728 |
|
729 if( result ) |
|
730 { |
|
731 for( TInt i( 0 ); i < result->Count(); i++ ) |
|
732 { |
|
733 TRAP( error, array->AppendL( result->At( i ) ) ); |
|
734 if( error != KErrNone ) |
|
735 { |
|
736 return NULL; |
|
737 } |
|
738 } |
|
739 |
|
740 result->Reset(); |
|
741 delete result; |
|
742 } |
|
743 |
|
744 return array; |
|
745 } |
|
746 |
|
747 // ----------------------------------------------------------------------------- |
|
748 // CNssVasDatabase::GetTagList |
|
749 // Method to get tags by rrd text value and position. |
|
750 // ----------------------------------------------------------------------------- |
|
751 MNssTagListArray* CNssVASDatabase::GetTagList( CNssContext* aContext, |
|
752 TDesC& aText, TInt aPosition ) |
|
753 { |
|
754 CArrayPtrFlat<CNssTag>* result = NULL; |
|
755 |
|
756 TRAPD( error, result = iVasDb->GetTagL( aContext->ContextId(), |
|
757 aText, aPosition ) ); |
|
758 |
|
759 // To remove warning |
|
760 if ( error != KErrNone ) |
|
761 { |
|
762 } |
|
763 |
|
764 CArrayPtrFlat<MNssTag>* array = NULL; |
|
765 |
|
766 TInt arrayCount = result ? result->Count() : 0; |
|
767 if( arrayCount == 0 ) |
|
768 { |
|
769 arrayCount++; |
|
770 } |
|
771 |
|
772 array = new CArrayPtrFlat<MNssTag>( arrayCount ); |
|
773 if( !array ) |
|
774 { |
|
775 return NULL; |
|
776 } |
|
777 |
|
778 if( result ) |
|
779 { |
|
780 for( TInt i( 0 ); i < result->Count(); i++ ) |
|
781 { |
|
782 TRAP( error, array->AppendL( result->At( i ) ) ); |
|
783 if( error != KErrNone ) |
|
784 { |
|
785 return NULL; |
|
786 } |
|
787 } |
|
788 |
|
789 result->Reset(); |
|
790 delete result; |
|
791 } |
|
792 |
|
793 return array; |
|
794 } |
|
795 |
|
796 // ----------------------------------------------------------------------------- |
|
797 // CNssVasDatabase::DeleteTag |
|
798 // Method to delete a tag. |
|
799 // ----------------------------------------------------------------------------- |
|
800 TInt CNssVASDatabase::DeleteTag( CNssTag *aTag ) |
|
801 { |
|
802 TInt ret( KErrNotFound ); |
|
803 |
|
804 if ( aTag->TagId() != KNssVASDbDefaultValue ) |
|
805 { |
|
806 ret = DeleteTag( aTag->TagId() ); |
|
807 } |
|
808 |
|
809 return ret; |
|
810 } |
|
811 |
|
812 // ----------------------------------------------------------------------------- |
|
813 // CNssVasDatabase::DeleteTag |
|
814 // Method to delete a tag by name. |
|
815 // ----------------------------------------------------------------------------- |
|
816 TInt CNssVASDatabase::DeleteTag( const TDesC& aName ) |
|
817 { |
|
818 TRAPD( error, iVasDb->DeleteTagL( aName ) ); |
|
819 |
|
820 return( error ); |
|
821 } |
|
822 |
|
823 // ----------------------------------------------------------------------------- |
|
824 // CNssVasDatabase::DeleteTag |
|
825 // Method to delete a tag by key/id. |
|
826 // ----------------------------------------------------------------------------- |
|
827 TInt CNssVASDatabase::DeleteTag( const TUint32 aTagId ) |
|
828 { |
|
829 TRAPD( error, iVasDb->DeleteTagL( aTagId ) ); |
|
830 |
|
831 return( error ); |
|
832 } |
|
833 |
|
834 // ----------------------------------------------------------------------------- |
|
835 // CNssVasDatabase::DeleteContext |
|
836 // Method to delete context. |
|
837 // ----------------------------------------------------------------------------- |
|
838 TInt CNssVASDatabase::DeleteContext( CNssContext* aContext ) |
|
839 { |
|
840 return( DeleteContext( aContext->ContextName() ) ); |
|
841 } |
|
842 |
|
843 // ----------------------------------------------------------------------------- |
|
844 // CNssVasDatabase::DeleteContext |
|
845 // Method to delete context by name. |
|
846 // ----------------------------------------------------------------------------- |
|
847 TInt CNssVASDatabase::DeleteContext( const TDesC& aName ) |
|
848 { |
|
849 TRAPD( error, iVasDb->DeleteContextL( aName ) ); |
|
850 |
|
851 return( error ); |
|
852 } |
|
853 |
|
854 // ----------------------------------------------------------------------------- |
|
855 // CNssVasDatabase::DeleteContext |
|
856 // Method to all tag references of a context. |
|
857 // ----------------------------------------------------------------------------- |
|
858 // |
|
859 CArrayPtrFlat<MNssTagReference>* CNssVASDatabase::GetTagReferenceList( CNssContext* aContext ) |
|
860 { |
|
861 TNssTagReferenceListArray* ttagRefArray = NULL; |
|
862 |
|
863 TRAPD( error, |
|
864 ttagRefArray = iVasDb->GetTagReferenceListL( aContext->ContextId() ) ); |
|
865 |
|
866 // To remove warning |
|
867 if ( error != KErrNone ) |
|
868 { |
|
869 } |
|
870 |
|
871 if ( !ttagRefArray ) |
|
872 { |
|
873 return( NULL ); |
|
874 } |
|
875 |
|
876 // Convert TNssTagReferences to CNssTagReferences |
|
877 CArrayPtrFlat<MNssTagReference>* result = |
|
878 new CArrayPtrFlat<MNssTagReference>( KFetchedTagRefListGranularity ); |
|
879 |
|
880 if ( !result ) |
|
881 { |
|
882 delete ttagRefArray; |
|
883 ttagRefArray = 0; |
|
884 return( NULL ); |
|
885 } |
|
886 |
|
887 TRAPD( err, ConvertTNssTagRefToMNssTagRefL( ttagRefArray, result ) ); |
|
888 |
|
889 delete ttagRefArray; |
|
890 ttagRefArray = 0; |
|
891 |
|
892 if ( err != KErrNone ) |
|
893 { |
|
894 result->ResetAndDestroy(); |
|
895 delete result; |
|
896 result = 0; |
|
897 } |
|
898 |
|
899 return( result ); |
|
900 } |
|
901 |
|
902 |
|
903 // ------------------------ |
|
904 // Private Utility Methods |
|
905 // ----------------------- |
|
906 |
|
907 // ----------------------------------------------------------------------------- |
|
908 // CNssVASDatabase::ConvertTNssTagRefToMNssTagRefL |
|
909 // |
|
910 // ----------------------------------------------------------------------------- |
|
911 // |
|
912 void CNssVASDatabase::ConvertTNssTagRefToMNssTagRefL( |
|
913 TNssTagReferenceListArray* aTNssTagRef, |
|
914 CArrayPtrFlat<MNssTagReference>* aCNssTagRef ) |
|
915 { |
|
916 CNssTagReference* tagRefPtr=NULL; |
|
917 |
|
918 for ( TInt i( 0 ); i < aTNssTagRef->Count(); i++ ) |
|
919 { |
|
920 tagRefPtr = new(ELeave)CNssTagReference(); |
|
921 CleanupStack::PushL( tagRefPtr ); |
|
922 tagRefPtr->SetTagNameL( (*aTNssTagRef)[i].iTagName ); |
|
923 tagRefPtr->SetTagId( (*aTNssTagRef)[i].iTagId ); |
|
924 aCNssTagRef->AppendL( tagRefPtr ); |
|
925 CleanupStack::Pop( tagRefPtr ); |
|
926 } |
|
927 } |
|
928 |
|
929 // ----------------------------------------------------------------------------- |
|
930 // CNssVASDatabase::ConvertDBError |
|
931 // |
|
932 // ----------------------------------------------------------------------------- |
|
933 // |
|
934 MNssVASDatabaseClient::TNssVASDBClientReturnCode CNssVASDatabase::ConvertDBError( TInt aError ) |
|
935 { |
|
936 MNssVASDatabaseClient::TNssVASDBClientReturnCode failcode = |
|
937 MNssVASDatabaseClient::EVASDBFailure; |
|
938 |
|
939 switch ( aError ) |
|
940 { |
|
941 case KErrNone: |
|
942 failcode = MNssVASDatabaseClient::EVASDBSuccess; |
|
943 break; |
|
944 case KErrNotFound: |
|
945 failcode = MNssVASDatabaseClient::EVASDBItemNotFound; |
|
946 break; |
|
947 case KErrNoMemory: |
|
948 failcode = MNssVASDatabaseClient::EVASDBNoMemory; |
|
949 break; |
|
950 case KErrDiskFull: |
|
951 failcode = MNssVASDatabaseClient::EVASDBDiskFull; |
|
952 break; |
|
953 default: |
|
954 failcode = MNssVASDatabaseClient::EVASDBFailure;//just in case |
|
955 break; |
|
956 } |
|
957 |
|
958 return failcode; |
|
959 } |
|
960 |
|
961 // ----------------------------------------------------------------------------- |
|
962 // CNssVASDatabase::GetDefaultModelBankId |
|
963 // |
|
964 // ----------------------------------------------------------------------------- |
|
965 // |
|
966 TInt CNssVASDatabase::GetDefaultModelBankId( TUint32& aId ) |
|
967 { |
|
968 TRAPD( error, iVasDb->GetDefaultModelBankIdL( aId ) ); |
|
969 |
|
970 return error; |
|
971 } |
|
972 |
|
973 // ----------------------------------------------------------------------------- |
|
974 // CNssVASDatabase::ResetModelBank |
|
975 // |
|
976 // ----------------------------------------------------------------------------- |
|
977 // |
|
978 TInt CNssVASDatabase::ResetModelBank( TUint32 aNewId ) |
|
979 { |
|
980 TRAPD( error, iVasDb->ResetModelBankL( aNewId ) ); |
|
981 |
|
982 return error; |
|
983 } |
|
984 |
|
985 // ----------------------------------------------------------------------------- |
|
986 // CNssVASDatabase::UpdateTagRuleIDs |
|
987 // |
|
988 // ----------------------------------------------------------------------------- |
|
989 // |
|
990 TInt CNssVASDatabase::UpdateTagRuleIDs( |
|
991 const RArray<TNssSpeechItem>& aRetrainedTags ) |
|
992 { |
|
993 TRAPD( error, iVasDb->UpdateTagRuleIDsL( aRetrainedTags ) ); |
|
994 |
|
995 return( error ); |
|
996 } |