os/mm/mmdevicefw/speechrecogsupport/tsrc/ASR/src/ASRController/CustomMmfASRController.cpp
First public contribution.
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "CustomMmfASRController.h"
18 #include <mmfcontrollerimplementationuids.hrh>
19 #include "customcontrollertestconstants.h"
20 #include "Database/testdatabaseconstants.h"
23 TMmfAsrControllerPanics is an enumeration with the following entries:
25 EBadArgument indicates a bad argument
26 EBadState indicates a state viaolation
27 EBadInvariant indicates an invariant violation
28 EBadReset indicates failed reset
29 EPostConditionViolation indicates a post condition violation
32 enum TMmfAsrControllerPanics
37 EPreConditionViolation,
38 EPostConditionViolation,
44 * This method generates a panic
48 void Panic(TMmfAsrControllerPanics aPanicCode)
50 _LIT(KMMFAsrControllerPanicCategory, "MMFAsrTestController");
51 User::Panic(KMMFAsrControllerPanicCategory, aPanicCode);
60 CMMFController* CCustomMmfASRController::NewL()
62 CCustomMmfASRController* self = new(ELeave) CCustomMmfASRController;
63 CleanupStack::PushL(self);
65 CleanupStack::Pop( self );
66 return STATIC_CAST( CMMFController*, self );
76 void CCustomMmfASRController::SetState( TControllerState aState )
86 void CCustomMmfASRController::ConstructL()
88 //[ Construct custom command parsers]
89 CSpeechRecognitionCustomCommandParser* asrParser = CSpeechRecognitionCustomCommandParser::NewL(*this);
90 CleanupStack::PushL(asrParser);
91 AddCustomCommandParserL(*asrParser);
92 CleanupStack::Pop( asrParser ); //asrParser
94 SetState( ESTraining ); //state of the controller
95 iRecognitionMode = ESdMode; // recognition mode which is nonzero for now
96 iRecordTime = 0; // the duration of the recording for both recognition and trainning
98 iRecognizeComplete = EFalse;
100 iLoadedLexiconID = 0;
101 iLoadedModelBankID = 0;
105 User::LeaveIfError(fsSession.Connect());
106 CleanupClosePushL(fsSession);
107 TInt err = file.Open(fsSession, KFileNameTestDatabase, EFileRead);
111 iDatabase = CSDDatabase::NewL(KFileNameTestDatabase);
113 else if(err == KErrNotFound)
115 iDatabase = CSDDatabase::NewL(KFileNameTestDatabase, EFalse);
117 else if(err == KErrPathNotFound)
120 if(fullFileName.Set(KFileNameTestDatabase, NULL, NULL) == KErrNone)
122 err = fsSession. MkDirAll(fullFileName.DriveAndPath());
125 iDatabase = CSDDatabase::NewL(KFileNameTestDatabase,EFalse);
129 User::LeaveIfError(err);
135 User::LeaveIfError(err);
137 CleanupStack::PopAndDestroy(); //fsSession
144 * ~CCustomMmfAudioController
147 CCustomMmfASRController::~CCustomMmfASRController()
154 * CCustomMmfAudioController
157 CCustomMmfASRController::CCustomMmfASRController()
166 void CCustomMmfASRController::CustomCommand(TMMFMessage& /*aMessage*/)
168 // The custom command is the final stopping off point
169 // in the command processing chain and in this case it does
176 * Adds a data source to the controller
181 * Source does not already exist
183 * iDataSource != NULL
184 * iDataSourceAdded == ETrue
187 void CCustomMmfASRController::AddDataSourceL(MDataSource& /*aSource*/)
189 //[This function is deprecated and should not have been called]
190 Panic(EDeprecatedFunction);
196 * Adds a data sink to the controller
201 void CCustomMmfASRController::AddDataSinkL(MDataSink& )
203 //[This function is deprecated and should not have been called]
204 Panic(EDeprecatedFunction);
210 * If Prime fails the client should reset the controller
211 * because as noted below this code is not transactional.
214 void CCustomMmfASRController::PrimeL()
216 //[This function is deprecated and should not have been called]
217 Panic(EDeprecatedFunction);
222 * This method resets the controller
225 void CCustomMmfASRController::ResetL()
227 //[This function is deprecated and should not have been called]
228 Panic(EDeprecatedFunction);
236 void CCustomMmfASRController::PlayL()
238 //[This function is deprecated and should not have been called]
239 Panic(EDeprecatedFunction);
246 void CCustomMmfASRController::PauseL()
248 //[This function is deprecated and should not have been called]
249 Panic(EDeprecatedFunction);
256 void CCustomMmfASRController::StopL()
258 //[This function is deprecated and should not have been called]
259 Panic(EDeprecatedFunction);
265 * The Controller is in the state EPrimed
266 * @return TTimeIntervalMicroSeconds
269 TTimeIntervalMicroSeconds CCustomMmfASRController::PositionL() const
271 //[This function is deprecated and should not have been called]
272 Panic(EDeprecatedFunction);
273 TTimeIntervalMicroSeconds position(0);
283 void CCustomMmfASRController::SetPositionL(const TTimeIntervalMicroSeconds& )
285 //[This function is deprecated and should not have been called]
286 Panic(EDeprecatedFunction);
291 * MSrAddPronunciationL
294 * @param aPronunciationID
295 * Add pronunciation to the lexicon
296 * @precondition lexicon is loaded
297 * @precondition lexicon has specified id
298 * @post condition lexicon has pronunciation
301 void CCustomMmfASRController::MSrAddPronunciationL( TLexiconID aLexiconID, TModelBankID aModelBankID,
302 TModelID aModelID, TPronunciationID& aPronunciationID )
304 //[ assert the InVariant ]
305 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
307 //[ precondition that are in training mode ]
308 __ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
310 //[ add new pronunciation ]
313 CSDDatabase::TPronunciationData pronunciationData=CSDDatabase::TPronunciationData();
314 pronunciationData.iModelBankID = aModelBankID;
315 pronunciationData.iModelID = aModelID;
317 TRAP(err, aPronunciationID = iDatabase->CreatePronunciationL(aLexiconID, pronunciationData));
319 TMMFEvent addPronunciationComplete( KUidAsrEventAddPronunciation, err );
320 SendEventToClient( addPronunciationComplete );
322 // [ assert the Invariant ]
323 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
329 void CCustomMmfASRController::MSrSetClientUid( TUid aClientUid)
331 //[ assert the InVariant ]
332 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
334 iDatabase->SetClientUid(aClientUid);
344 * @param aPronunciationID
346 * @postcondition grammar has rule
348 void CCustomMmfASRController::MSrAddRuleL(
349 TGrammarID aGrammarID, TLexiconID aLexiconID,
350 TPronunciationID aPronunciationID, TRuleID& aRuleID )
352 //[ assert the InVariant ]
353 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
355 //[ precondition that are in training mode ]
356 __ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
359 //[ if the grammar has the rule ]
361 CSDDatabase::TRuleData ruleData=CSDDatabase::TRuleData();
362 ruleData.iLexiconID = aLexiconID;
363 ruleData.iPronunciationID = aPronunciationID;
365 TRAP( err, aRuleID = iDatabase->CreateRuleL( aGrammarID, ruleData));
368 TMMFEvent event( KUidAsrEventAddRule, err );
369 SendEventToClient( event );
371 // [ assert the Invariant ]
372 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
382 void CCustomMmfASRController::MSrCancel()
384 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
385 // Send back a test event to the client to indicate this has been called, note this is test controller specific event
386 TMMFEvent testCancelEvent( KUidTestASRCancel, KErrNone );
387 SendEventToClient( testCancelEvent );
395 void CCustomMmfASRController::MSrCommitChangesL()
397 //[ assert the Invariant ]
398 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
400 iDatabase->CommitChangesL();
402 // [ assert the invariant ]
403 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
409 * Creates a Grammar and makes it the currently loaded grammar
411 * @precondition State == ESTraining
412 * @postcondition iAsrSchema has grammar with id aGrammarID
415 void CCustomMmfASRController::MSrCreateGrammarL( TGrammarID& aGrammarID )
417 //[ assert the Invariant ]
418 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
420 //[ precondition that we are in trainning state ]
421 __ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
423 aGrammarID = iDatabase->CreateGrammarL();
425 TMMFEvent event( KUidAsrEventCreateGrammar, KErrNone );
426 SendEventToClient( event );
428 //[ assert the invariant ]
429 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
436 * Creates a Lexicon with Id aLexiconId
439 void CCustomMmfASRController::MSrCreateLexiconL( TLexiconID& aLexiconID )
441 //[ assert the Invariant ]
442 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
444 //[ precondition that we are in trainning state ]
445 __ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
447 //[ create the Lexicon ]
448 aLexiconID = iDatabase->CreateLexiconL();
450 TMMFEvent event( KUidAsrEventCreateLexicon, KErrNone );
451 SendEventToClient( event );
453 //[ assert the invariant ]
454 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
460 * MSrCreateModelBankL
461 * @param aModelBankID
462 * @precondition state == ESTraining
463 * @precondition invariant holds
464 * @postcondition currentModelbank id == modelbank id
467 void CCustomMmfASRController::MSrCreateModelBankL( TModelBankID& aModelBankID )
469 //[ assert the Invariant ]
470 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
472 //[ precondition that we are in trainning state ]
473 __ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
475 //[ create the new ModelBank]
476 TRAPD(err, aModelBankID = iDatabase->CreateModelBankL());
478 TMMFEvent event( KUidAsrEventCreateModelBank, err);
479 SendEventToClient( event );
481 //[ assert the invariant ]
482 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
488 * End a recognition session
489 * @precondition State is ESRecognition
490 * @postcondition State is Idle
492 void CCustomMmfASRController::MSrEndRecSessionL()
494 //[ The Invariant must hold ]
495 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
496 //[ precondition that the state is recognise ]
497 __ASSERT_ALWAYS( State() == ESRecognition, Panic(EBadState) );
498 //[ transitionn to Idle state ]
499 SetState( ESTraining );
501 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
507 * Gets all the model ids in a model bank
508 * @precondition iModelBank is loaded
509 * @postcondition model ids are returned
510 * @postcondition invariant holds
512 void CCustomMmfASRController::MSrGetAllModelIDsL( TModelBankID aModelBankID, RArray<TModelID>& aModelIDs )
514 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
516 TRAPD(err, iDatabase->GetAllModelIDsL(aModelBankID, aModelIDs));
518 TMMFEvent event( KUidAsrEventGetAllModelIDs, err );
519 SendEventToClient( event );
521 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
526 * MSrGetAllPronunciationIDsL
527 * @precondition InVariant holds
528 * @postcondition InVariantHolds
530 void CCustomMmfASRController::MSrGetAllPronunciationIDsL( TLexiconID aLexiconID, RArray<TPronunciationID>& aPronunciationIDs )
532 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
534 TRAPD(err, iDatabase->GetAllPronunciationIDsL(aLexiconID, aPronunciationIDs));
536 TMMFEvent event( KUidAsrEventGetAllPronunciationIDs, err );
537 SendEventToClient( event );
539 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
546 * Get all the rule ids contained in the grammar
549 * @precondition Invariant holds
550 * @precondition Lexicon is Loaded
551 * @postcondition Invariant holds
553 void CCustomMmfASRController::MSrGetAllRuleIDsL( TLexiconID aLexiconID, RArray<TRuleID>& aRuleIDs )
555 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
557 TRAPD(err, iDatabase->GetAllRuleIDsL(aLexiconID, aRuleIDs));
559 TMMFEvent event( KUidAsrEventGetAllRuleIDs, err );
560 SendEventToClient( event );
562 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
566 void CCustomMmfASRController::MSrGetAllClientModelBankIDsL(RArray<TModelBankID>& aModelBankIDs )
568 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
570 TRAPD(err, iDatabase->GetAllModelBankIDsL(aModelBankIDs,ETrue));
572 TMMFEvent event( KUidAsrEventGetAllClientModelBankIDs, err );
573 SendEventToClient( event );
575 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
578 void CCustomMmfASRController::MSrGetAllClientLexiconIDsL(RArray<TLexiconID>& aLexiconIDs )
580 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
582 TRAPD(err, iDatabase->GetAllLexiconIDsL(aLexiconIDs, ETrue));
584 TMMFEvent event( KUidAsrEventGetAllClientLexiconIDs, err );
585 SendEventToClient( event );
587 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
591 void CCustomMmfASRController::MSrGetAllClientGrammarIDsL(RArray<TGrammarID>& aGrammarIDs )
593 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
595 TRAPD(err, iDatabase->GetAllGrammarIDsL(aGrammarIDs, ETrue));
597 TMMFEvent event( KUidAsrEventGetAllClientGrammarIDs, err );
598 SendEventToClient( event );
600 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
603 void CCustomMmfASRController::MSrGetAllModelBankIDsL(RArray<TModelBankID>& aModelBankIDs )
605 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
607 TRAPD(err, iDatabase->GetAllModelBankIDsL(aModelBankIDs));
609 TMMFEvent event( KUidAsrEventGetAllModelBankIDs, err );
610 SendEventToClient( event );
612 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
615 void CCustomMmfASRController::MSrGetAllLexiconIDsL(RArray<TLexiconID>& aLexiconIDs )
617 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
619 TRAPD(err, iDatabase->GetAllLexiconIDsL(aLexiconIDs));
621 TMMFEvent event( KUidAsrEventGetAllLexiconIDs, err );
622 SendEventToClient( event );
624 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
628 void CCustomMmfASRController::MSrGetAllGrammarIDsL(RArray<TGrammarID>& aGrammarIDs )
630 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
632 TRAPD(err, iDatabase->GetAllGrammarIDsL(aGrammarIDs));
634 TMMFEvent event( KUidAsrEventGetAllGrammarIDs, err );
635 SendEventToClient( event );
637 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
643 * MSrGetAvailableStorageL
644 * gets the available storage
645 * For this simulation the function always returns zero space available
647 * @precondition Invariant holds
650 void CCustomMmfASRController::MSrGetAvailableStorageL( TInt& aCount )
652 //[ assert the invariant ]
653 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
655 //[ for now we will return no space available ]
658 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
663 * MSrGetEnginePropertiesL
665 * @precondition Invariant holds
668 void CCustomMmfASRController::MSrGetEnginePropertiesL( const RArray<TInt>& aPropertyId,
669 RArray<TInt>& aPropertyValue )
671 //[ assert the invariant ]
672 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
674 //[ empty the src array ]
675 aPropertyValue.Reset();
677 //[ for all the ids specified ]
678 for( TInt count = 0; count < aPropertyId.Count(); count++ )
680 //[ we are just faking this for the moment ]
681 aPropertyValue.Append( count );
684 //[assert there are properties for all the ids]
685 __ASSERT_ALWAYS( aPropertyValue.Count() == aPropertyId.Count(), Panic(EPostConditionViolation) );
686 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
691 * MSrLoadEngineParametersL
694 void CCustomMmfASRController::MSrLoadEngineParametersL( const RArray<TInt>& aParameterId,
695 const RArray<TInt>& aParameterValue )
698 if (aParameterId.Count()!=KNumParameters ||
699 aParameterValue.Count()!=KNumParameters)
704 for (i=0;i<aParameterId.Count() && pass;i++)
705 if (aParameterId[i]!=KParameterIDs[i])
708 for (i=0;i<aParameterValue.Count() && pass;i++)
709 if (aParameterValue[i]!=KParameterValues[i])
716 TMMFEvent event( KUidTestASRLoadParameters, KErrNone );
717 SendEventToClient(event);
721 TMMFEvent event( KUidTestASRLoadParameters, KErrArgument );
722 SendEventToClient(event);
729 * @param aModelBankID
731 * @precondition Invariant holds
732 * @precondition model is loaded
733 * @postcondition Invariant holds
734 * @postcondition modelcount >=0
736 void CCustomMmfASRController::MSrGetModelCountL( TModelBankID aModelBankID, TInt& aCount )
738 //[ assert the invariant ]
739 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
741 RArray<TPronunciationID> ids;
742 CleanupClosePushL(ids);
743 TRAPD(err, iDatabase->GetAllModelIDsL(aModelBankID,ids));
746 aCount = ids.Count();
748 CleanupStack::PopAndDestroy(&ids);
750 TMMFEvent event( KUidAsrEventGetModelCount, err );
751 SendEventToClient( event );
754 //[ assert the invariant ]
755 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
762 * MSrGetRuleValidityL
766 * @precondition InVariantHolds
767 * @precondition state is training or state is recognition
768 * @precondition grammar is loaded
769 * @postcondition InVariantHolds
771 void CCustomMmfASRController::MSrGetRuleValidityL( TGrammarID aGrammarID, TRuleID aRuleID, TBool& aValid )
773 //[ assert the invariant ]
774 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
775 //[ precondition the schema exists ]
777 CSDDatabase::RSDRuleTable ruleTable(*iDatabase);
778 CleanupClosePushL(ruleTable);
779 ruleTable.OpenL(aGrammarID);
780 TRAPD(err, aValid = ruleTable.IsRuleValidL(aRuleID));
781 CleanupStack::PopAndDestroy(&ruleTable);
783 TMMFEvent event( KUidAsrEventGetRuleValidity, err );
784 SendEventToClient( event );
786 //[ assert the invariant ]
787 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
792 * MSrGetUtteranceDurationL
793 * @param aModelBankID
799 void CCustomMmfASRController::MSrGetUtteranceDurationL( TModelBankID aModelBankID, TModelID aModelID,
800 TTimeIntervalMicroSeconds32& aDuration)
802 //[ assert the Invariant ]
803 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
805 CSDDatabase::TModelData modelData = CSDDatabase::TModelData();
808 TRAP(err, iDatabase->GetModelDataL(aModelBankID, aModelID, modelData));
811 aDuration = modelData.iUtteranceDurationMicroSeconds;
814 TMMFEvent event( KUidAsrEventGetUtteranceDuration, err );
815 SendEventToClient( event );
818 //[ assert the Invariant ]
819 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
826 * @precondition aGrammarId is supported by the test controller
827 * @postcondition aGrammarId == id of loaded grammar
829 void CCustomMmfASRController::MSrLoadGrammarL( TGrammarID aGrammarID )
831 //[ assert the Invariant ]
832 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
834 //[ must be in trainning or recognition state ]
835 __ASSERT_ALWAYS( (State() == ESRecognition ) || ( State() == ESTraining ), Panic(EBadState) );
838 if (iDatabase->GrammarExistsL(aGrammarID))
840 iLoadedGrammarID = aGrammarID;
845 TMMFEvent event( KUidAsrEventLoadGrammar, err );
846 SendEventToClient( event );
848 //[ assert the Invariant ]
849 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
856 * @precondition Invariant Holds
857 * @precondition state is Training or Recognition
858 * @precondition controller supports the lexicon
859 * @postcondition iLexicon has id aLexiconId
860 * @psotcondition InVariant holds
862 void CCustomMmfASRController::MSrLoadLexiconL( TLexiconID aLexiconID )
864 //[ assert the Invariant ]
865 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
867 //[ must be in trainning or recognition state ]
868 __ASSERT_ALWAYS( (State() == ESRecognition ) || ( State() == ESTraining ), Panic(EBadState));
871 if (iDatabase->LexiconExistsL(aLexiconID))
873 iLoadedLexiconID = aLexiconID;
878 TMMFEvent event( KUidAsrEventLoadLexicon, err );
879 SendEventToClient( event );
881 //[ assert the Invariant ]
882 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
888 * @param aModelBankID
889 * @precondition InVariant holds
890 * @precondition state is training or recognition
891 * @precondition model bank is is supported by the controller
892 * @postcondition modelbank id is equal to aModelBankId
893 * @postcondition InVariant holds
895 void CCustomMmfASRController::MSrLoadModelsL( TModelBankID aModelBankID )
897 //[ assert the Invariant ]
898 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
900 //[ must be in trainning or recognition state ]
901 __ASSERT_ALWAYS( (State() == ESRecognition ) || ( State() == ESTraining ), Panic(EBadState));
904 if (iDatabase->ModelBankExistsL(aModelBankID))
906 iLoadedModelBankID = aModelBankID;
911 TMMFEvent event( KUidAsrEventLoadModels, err );
912 SendEventToClient( event );
914 //[ assert the Invariant ]
915 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
922 * @param aModelBankID
924 * @param aPlayFromMemory
925 * Always plays froms memory
927 void CCustomMmfASRController::MSrPlayUtteranceL( TModelBankID aModelBankID, TModelID aModelID )
929 //[ assert the InVariant ]
930 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
932 if (!iDatabase->ModelExistsL(aModelBankID, aModelID))
934 User::Leave(KErrNotFound);
938 TMMFEvent aPlayStarted( KUidAsrEventPlayStarted, KErrNone );
939 SendEventToClient( aPlayStarted );
941 TMMFEvent aPlayComplete( KUidAsrEventPlay, KErrNone );
942 SendEventToClient( aPlayComplete );
945 //[ assert the InVariant ]
946 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
955 void CCustomMmfASRController::MSrRecognizeL( CSDClientResultSet& aResultSet )
957 //[ assert the Invariant ]
958 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
960 //[ Precondition that we are in a recognition session ]
961 if( State() != ESRecognition )
963 TMMFEvent recognitionFailed( KUidAsrEventRecognition, KErrNotReady );
964 SendEventToClient( recognitionFailed );
968 TMMFEvent recognitionReady( KUidAsrEventRecognitionReady,KErrNone );
969 SendEventToClient( recognitionReady );
971 //[ return a result set ]
972 iMaxResults = aResultSet.MaxResults();
973 iResultSet = &aResultSet;
975 iRecognizeComplete = ETrue;
977 //[ assert the Invariant ]
978 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
985 * @precondition InVariant holds
988 void CCustomMmfASRController::MSrRecordL( TTimeIntervalMicroSeconds32 aRecordTime )
990 //[ assert the invariant ]
991 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
993 //[ remember the record time
994 // and for the purpose of simulation recording takes zero time ]
995 iRecordTime = aRecordTime ;
997 TMMFEvent aRecordStartedEvent( KUidAsrEventRecordStarted, KErrNone );
998 SendEventToClient( aRecordStartedEvent );
1000 TMMFEvent aEndOfUtteranceEvent( KUidAsrEventEouDetected, KErrNone );
1001 SendEventToClient( aEndOfUtteranceEvent );
1003 if( iRecognizeComplete )
1005 iRecognizeComplete = EFalse;
1007 for (TInt i=0;i<iMaxResults && i<KMaxAvailableResults;i++)
1009 CSDClientResult& result = CONST_CAST(CSDClientResult&, iResultSet->At(i));
1010 result.SetGrammarID(KResultsGrammarID[i]);
1011 result.SetRuleID(KResultsRuleID[i]);
1014 TMMFEvent recognitionComplete( KUidAsrEventRecognition, KErrNone );
1015 SendEventToClient( recognitionComplete );
1018 //[ assert the invaraint ]
1019 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1025 * Interpreted as unload from memory here
1028 void CCustomMmfASRController::MSrRemoveGrammarL( TGrammarID aGrammarID )
1030 //[ assert the invaraint ]
1031 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
1034 if (iLoadedGrammarID == aGrammarID)
1036 TMMFEvent event( KUidAsrEventRemoveGrammar, KErrInUse );
1037 SendEventToClient( event );
1041 TRAPD(err, iDatabase->RemoveGrammarL(aGrammarID));
1042 //[ send message to client of success ]
1043 TMMFEvent event( KUidAsrEventRemoveGrammar, err );
1044 SendEventToClient( event );
1047 //[ assert the invaraint ]
1048 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1055 * slightly different interpretation here
1057 void CCustomMmfASRController::MSrRemoveLexiconL( TLexiconID aLexiconID )
1059 //[ assert the invaraint ]
1060 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1063 if (iLoadedLexiconID == aLexiconID)
1065 TMMFEvent event( KUidAsrEventRemoveLexicon, KErrInUse );
1066 SendEventToClient( event );
1070 TRAPD(err, iDatabase->RemoveLexiconL(aLexiconID));
1071 //[ send message to client of success ]
1072 TMMFEvent event( KUidAsrEventRemoveLexicon, err );
1073 SendEventToClient( event );
1076 //[ assert the invaraint ]
1077 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1084 * MSrRemoveModelBankL
1088 void CCustomMmfASRController::MSrRemoveModelBankL( TModelBankID aModelBankID )
1090 //[ assert the invaraint ]
1091 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1094 if (iLoadedModelBankID == aModelBankID)
1096 TMMFEvent event( KUidAsrEventRemoveModelBank, KErrInUse );
1097 SendEventToClient( event );
1101 TRAPD(err, iDatabase->RemoveModelBankL(aModelBankID));
1102 //[ send message to client of success ]
1103 TMMFEvent event( KUidAsrEventRemoveModelBank, err );
1104 SendEventToClient( event );
1107 //[ assert the invaraint ]
1108 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1115 * @param aModelBankID
1117 * @precondition InVariant holds
1118 * @precondition model bank exists
1119 * @precondition modelbank contains the model
1120 * @postcondition model bank does not contain model
1123 void CCustomMmfASRController::MSrRemoveModelL( TModelBankID aModelBankID, TModelID aModelID )
1125 //[ assert the invariant ]
1126 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1128 if (iLoadedModelBankID == aModelBankID)
1130 TMMFEvent event( KUidAsrEventRemoveModelBank, KErrInUse );
1131 SendEventToClient( event );
1135 TInt err = KErrNone;
1136 if (!iDatabase->ModelBankExistsL(aModelBankID))
1140 CSDDatabase::RSDModelTable view(*iDatabase);
1141 CleanupClosePushL(view);
1142 view.OpenL(aModelBankID);
1143 if (view.FindModelL(aModelID))
1145 view.RemoveModelL(aModelID);
1150 CleanupStack::PopAndDestroy(&view);
1152 //[ send message to client of success ]
1153 TMMFEvent event( KUidAsrEventRemoveModel, err );
1154 SendEventToClient( event );
1157 //[ assert the invaraint ]
1158 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1163 * MSrRemovePronunciationL
1165 * @param aPronunciationID
1166 * @precondition lexicon exists
1167 * @precondition lexicon has id specified
1168 * @postconfition lexicon does not have pronunication
1171 void CCustomMmfASRController::MSrRemovePronunciationL( TLexiconID aLexiconID, TPronunciationID aPronunciationID )
1173 //[ assert the invaraint ]
1174 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1176 if (iLoadedLexiconID == aLexiconID)
1178 TMMFEvent event( KUidAsrEventRemovePronunciation, KErrInUse );
1179 SendEventToClient( event );
1183 TInt err = KErrNone;
1184 if (!iDatabase->LexiconExistsL(aLexiconID))
1188 CSDDatabase::RSDPronunciationTable view(*iDatabase);
1189 CleanupClosePushL(view);
1190 view.OpenL(aLexiconID);
1191 if (view.FindPronunciationL(aPronunciationID))
1193 view.RemovePronunciationL(aPronunciationID);
1198 CleanupStack::PopAndDestroy(&view);
1200 //[ send message to client of success ]
1201 TMMFEvent event( KUidAsrEventRemovePronunciation, err );
1202 SendEventToClient( event );
1205 //[ assert the invaraint ]
1206 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1214 * @precondition InVariant holds
1215 * @precondition grammar is loaded
1216 * @precondition grammar has id specified
1217 * @postcondition grammar does not contain rule
1220 void CCustomMmfASRController::MSrRemoveRuleL( TGrammarID aGrammarID, TRuleID aRuleID )
1222 //[ assert the invaraint ]
1223 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1225 if (iLoadedGrammarID == aGrammarID)
1227 TMMFEvent event( KUidAsrEventRemoveRule, KErrInUse );
1228 SendEventToClient( event );
1232 TInt err = KErrNone;
1233 if (!iDatabase->GrammarExistsL(aGrammarID))
1237 CSDDatabase::RSDRuleTable view(*iDatabase);
1238 CleanupClosePushL(view);
1239 view.OpenL(aGrammarID);
1240 if (view.FindRuleL(aRuleID))
1242 view.RemoveRuleL(aRuleID);
1247 CleanupStack::PopAndDestroy(&view);
1249 //[ send message to client of success ]
1250 TMMFEvent event( KUidAsrEventRemoveRule, err );
1251 SendEventToClient( event );
1254 //[ assert the invaraint ]
1255 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1260 * MSrStartRecSessionL
1262 * @precondition mode is valid
1265 void CCustomMmfASRController::MSrStartRecSessionL( TRecognitionMode aMode )
1267 //[ assert the invariant holds ]
1268 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1270 //[ precondition the mode is valid ]
1271 if( (aMode < ESdMode ) || ( aMode > ESdSiMode) )
1273 User::Leave( KErrArgument );
1276 //[ it does not matter which state we are in we can
1277 // always transition to recognition ]
1278 SetState( ESRecognition );
1280 //[ set the recognition mode ]
1281 iRecognitionMode = aMode ;
1283 //[ assert the Invariant holds ]
1284 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1286 //[ assert the post condition that the mode has been en
1287 __ASSERT_ALWAYS( iRecognitionMode == aMode, Panic(EPostConditionViolation) );
1293 * @param aModelBankID
1297 void CCustomMmfASRController::MSrTrainL( TModelBankID aModelBankID, TModelID& aModelID )
1299 // fixed duration to return for training
1300 const TInt KUtteranceDuration = 2000;
1301 //[ must be in training mode
1302 // must have a lexicon that is not empty
1303 // must have a grammar
1304 // must have a model bank loaded ]
1305 //[ presume train adds a new model id to the bank ]
1306 //[ finally send event to client ]
1307 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1308 TMMFEvent event( KUidAsrEventTrainReady, KErrNone );
1309 SendEventToClient( event );
1311 // [ precondition model bank is loaded ]
1312 if( iLoadedModelBankID != aModelBankID )
1314 TMMFEvent event( KUidAsrEventTrain, KErrNotReady );
1315 SendEventToClient( event );
1319 TInt err = KErrNone;
1321 CSDDatabase::TModelData modelData=CSDDatabase::TModelData();
1322 modelData.iUtteranceDurationMicroSeconds = KUtteranceDuration;
1323 TRAP(err, aModelID = iDatabase->CreateModelL( aModelBankID, modelData));
1325 TMMFEvent trainCompleteEvent( KUidAsrEventTrain, err );
1326 SendEventToClient( trainCompleteEvent );
1327 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1335 * @precondition state == ESTraining
1336 * @postcondition grammar does not contain rule
1339 void CCustomMmfASRController::MSrUnloadRuleL( TGrammarID aGrammarID, TRuleID aRuleID )
1341 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1343 //[ precondition grammar loaded is grammar with id ]
1344 __ASSERT_ALWAYS( iLoadedGrammarID == aGrammarID, Panic(EPreConditionViolation) );
1346 TBool ruleExists = EFalse;
1348 TRAPD(err, ruleExists = iDatabase->RuleExistsL(aGrammarID, aRuleID));
1350 if (err == KErrNone)
1356 //[ send message to client of success ]
1357 TMMFEvent event( KUidAsrEventUnloadRule, err );
1358 SendEventToClient( event );
1360 __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
1368 TInt CCustomMmfASRController::SendEventToClient(const TMMFEvent& aEvent)
1370 //now send event to client...
1371 return DoSendEventToClient(aEvent);
1376 * GetNumberOfMetaDataEntriesL
1381 void CCustomMmfASRController::GetNumberOfMetaDataEntriesL(TInt& /*aNumberOfEntries*/ )
1383 //[This function is deprecated and should not have been called]
1384 Panic(EDeprecatedFunction);
1390 * @returns "CMMFMetaDataEntry*"
1392 CMMFMetaDataEntry* CCustomMmfASRController::GetMetaDataEntryL(TInt /*aIndex*/ )
1394 //[This function is deprecated and should not have been called]
1395 Panic(EDeprecatedFunction);
1401 * @param aDataSource
1404 void CCustomMmfASRController::RemoveDataSourceL(MDataSource& /*aDataSource*/ )
1406 //[This function is deprecated and should not have been called]
1407 Panic(EDeprecatedFunction);
1416 void CCustomMmfASRController::RemoveDataSinkL(MDataSink& /*aDataSink*/ )
1418 //[This function is deprecated and should not have been called]
1419 Panic(EDeprecatedFunction);
1423 * SetPrioritySettings
1425 * @param aPrioritySettings
1427 void CCustomMmfASRController::SetPrioritySettings(const TMMFPrioritySettings& /*aPrioritySettings*/)
1435 * @returns TTimeIntervalMicroSeconds
1438 TTimeIntervalMicroSeconds CCustomMmfASRController::DurationL() const
1440 TTimeIntervalMicroSeconds xx(0);
1450 TBool CCustomMmfASRController::InVariant() const
1452 TBool status = EFalse;
1453 //[ for now the invariant is simply that we have a valid state ]
1454 if( (iState == ESTraining ) || ( iState == ESTraining ) || ( iState == ESRecognition ) )
1465 * @returns TControllerState
1468 CCustomMmfASRController::TControllerState CCustomMmfASRController::State() const