os/mm/mmdevicefw/speechrecogsupport/tsrc/ASR/src/ASRController/CustomMmfASRController.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "CustomMmfASRController.h"
    17 
    18 #include <mmfcontrollerimplementationuids.hrh>
    19 #include "customcontrollertestconstants.h"
    20 #include "Database/testdatabaseconstants.h"
    21 
    22 /*
    23 	TMmfAsrControllerPanics is an enumeration with the following entries:
    24 	
    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
    30 
    31 */
    32 enum TMmfAsrControllerPanics
    33 	{
    34 	EBadArgument,
    35 	EBadState,
    36 	EBadInvariant,
    37 	EPreConditionViolation,
    38 	EPostConditionViolation,
    39 	EDeprecatedFunction
    40 	};
    41 
    42 /**
    43 * Panic
    44 * This method generates a panic
    45 * @param "TInt"
    46 * @xxxx
    47 */
    48 void Panic(TMmfAsrControllerPanics aPanicCode)
    49 	{
    50 	_LIT(KMMFAsrControllerPanicCategory, "MMFAsrTestController");
    51 	User::Panic(KMMFAsrControllerPanicCategory, aPanicCode);
    52 	}
    53 
    54 
    55 /**
    56 *
    57 * NewL
    58 *
    59 */
    60 CMMFController* CCustomMmfASRController::NewL()
    61 	{
    62     CCustomMmfASRController* self = new(ELeave) CCustomMmfASRController;
    63 	CleanupStack::PushL(self);
    64 	self->ConstructL();
    65 	CleanupStack::Pop( self );	
    66 	return STATIC_CAST( CMMFController*, self );
    67 	}
    68 
    69 
    70 /**
    71 *
    72 * SetState
    73 * @param aState
    74 *
    75 */
    76 void CCustomMmfASRController::SetState( TControllerState aState )
    77 	{
    78 	iState=aState;
    79 	}
    80 
    81 /**
    82 *
    83 * ConstructL
    84 *
    85 */
    86 void CCustomMmfASRController::ConstructL()
    87 	{
    88 	//[ Construct custom command parsers]
    89 	CSpeechRecognitionCustomCommandParser* asrParser = CSpeechRecognitionCustomCommandParser::NewL(*this);
    90 	CleanupStack::PushL(asrParser);
    91 	AddCustomCommandParserL(*asrParser);
    92 	CleanupStack::Pop( asrParser ); //asrParser
    93 
    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
    97 
    98 	iRecognizeComplete = EFalse;
    99 	iLoadedGrammarID = 0;
   100 	iLoadedLexiconID = 0;
   101 	iLoadedModelBankID = 0;
   102 	
   103   	RFs fsSession;
   104   	RFile file;
   105   	User::LeaveIfError(fsSession.Connect());
   106     CleanupClosePushL(fsSession);
   107     TInt err = file.Open(fsSession, KFileNameTestDatabase, EFileRead);
   108   	file.Close();
   109   	if(err == KErrNone)
   110   		{
   111 	    iDatabase = CSDDatabase::NewL(KFileNameTestDatabase);
   112   		}
   113    	else if(err == KErrNotFound)
   114   		{
   115 	    iDatabase = CSDDatabase::NewL(KFileNameTestDatabase, EFalse);		
   116   		}
   117 	else if(err == KErrPathNotFound)
   118   		{
   119   		TParse fullFileName;
   120  		if(fullFileName.Set(KFileNameTestDatabase, NULL, NULL) == KErrNone)
   121 			{
   122 		 	err = fsSession. MkDirAll(fullFileName.DriveAndPath());
   123 		 	if(err == KErrNone)
   124 		 		{
   125 			    iDatabase = CSDDatabase::NewL(KFileNameTestDatabase,EFalse);		
   126 		 		}
   127 		 	else
   128 		 		{
   129 			    User::LeaveIfError(err); 			
   130 		 		}	
   131 	  		}  				
   132  		}
   133   	else
   134   		{
   135 	    User::LeaveIfError(err);
   136   		}
   137   	CleanupStack::PopAndDestroy(); //fsSession 
   138 	}
   139 
   140 
   141 
   142 /**
   143 *
   144 * ~CCustomMmfAudioController
   145 *
   146 */
   147 CCustomMmfASRController::~CCustomMmfASRController()
   148 	{
   149 	delete iDatabase;
   150 	}
   151 
   152 /**
   153 *
   154 * CCustomMmfAudioController
   155 *
   156 */
   157 CCustomMmfASRController::CCustomMmfASRController()
   158 	{	
   159 	}
   160 
   161 /**
   162 *
   163 * CustomCommand
   164 *
   165 */
   166 void CCustomMmfASRController::CustomCommand(TMMFMessage& /*aMessage*/)
   167 	{
   168      // The custom command is the final stopping off point
   169 	 // in the command processing chain and in this case it does
   170 	 // nothing!
   171 	}
   172 
   173 /**
   174  *  AddDataSourceL
   175  *
   176  *	Adds a data source to the controller
   177  *
   178  *	@param aSource
   179  * Preconditions:
   180  * We are stopped
   181  * Source does not already exist
   182  * Postconditions:
   183  * iDataSource != NULL
   184  * iDataSourceAdded == ETrue
   185  *
   186  */
   187 void CCustomMmfASRController::AddDataSourceL(MDataSource& /*aSource*/)
   188 	{
   189 	 //[This function is deprecated and should not have been called]
   190      Panic(EDeprecatedFunction);
   191 	}
   192 
   193 /**
   194  *  AddDataSinkL
   195  *
   196  *	Adds a data sink to the controller
   197  *
   198  *	@param aSink
   199  *
   200  */
   201 void CCustomMmfASRController::AddDataSinkL(MDataSink& )
   202 	{
   203 	 //[This function is deprecated and should not have been called]
   204      Panic(EDeprecatedFunction);
   205 	}
   206 
   207 /**
   208  *  PrimeL
   209  *
   210  *  If Prime fails the client should reset the controller
   211  *  because as noted below this code is not transactional.
   212  *
   213  */
   214 void CCustomMmfASRController::PrimeL()
   215 	{
   216 	//[This function is deprecated and should not have been called]
   217     Panic(EDeprecatedFunction);
   218 	}
   219 
   220 /**
   221  *  ResetL
   222  *  This method resets the controller
   223  *
   224  */
   225 void CCustomMmfASRController::ResetL()
   226 	{
   227 	//[This function is deprecated and should not have been called]
   228     Panic(EDeprecatedFunction);
   229 	}
   230 
   231 /**
   232  *
   233  * PlayL
   234  *
   235  */
   236 void CCustomMmfASRController::PlayL()
   237 	{
   238 	//[This function is deprecated and should not have been called]
   239     Panic(EDeprecatedFunction);
   240 	}
   241 
   242 /**
   243  *  PauseL
   244  *
   245  */
   246 void CCustomMmfASRController::PauseL()
   247 	{
   248 	//[This function is deprecated and should not have been called]
   249     Panic(EDeprecatedFunction);
   250 	}
   251 
   252 /**
   253  *  StopL
   254  *
   255  */
   256 void CCustomMmfASRController::StopL()
   257 	{
   258 	//[This function is deprecated and should not have been called]
   259     Panic(EDeprecatedFunction);
   260 	}
   261 
   262 /**
   263  *  PositionL
   264  * Preconditions:
   265  * The Controller is in the state EPrimed
   266  * @return TTimeIntervalMicroSeconds
   267  *
   268  */
   269 TTimeIntervalMicroSeconds CCustomMmfASRController::PositionL() const
   270 	{
   271 	//[This function is deprecated and should not have been called]
   272     Panic(EDeprecatedFunction);
   273 	TTimeIntervalMicroSeconds position(0);
   274 	return position;
   275 	}
   276 
   277 /**
   278 * SetPositionL
   279 *
   280 * @param aPosition
   281 *
   282 */
   283 void CCustomMmfASRController::SetPositionL(const TTimeIntervalMicroSeconds& )
   284 	{
   285 	//[This function is deprecated and should not have been called]
   286     Panic(EDeprecatedFunction);
   287 	}
   288 
   289 /**
   290 *
   291 * MSrAddPronunciationL
   292 * @param aLexiconID
   293 * @param aModelID
   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
   299 *
   300 */
   301 void CCustomMmfASRController::MSrAddPronunciationL( TLexiconID aLexiconID, TModelBankID aModelBankID,
   302 							  TModelID aModelID, TPronunciationID& aPronunciationID )
   303 	{
   304 	//[ assert the InVariant ]
   305 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));       
   306 
   307 	//[ precondition that are in training mode ]
   308     __ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
   309 
   310 	//[ add new pronunciation ]
   311 	TInt err = KErrNone;
   312 
   313 	CSDDatabase::TPronunciationData pronunciationData=CSDDatabase::TPronunciationData();
   314 	pronunciationData.iModelBankID = aModelBankID;
   315 	pronunciationData.iModelID = aModelID;
   316 	
   317 	TRAP(err, aPronunciationID = iDatabase->CreatePronunciationL(aLexiconID, pronunciationData));
   318 	
   319 	TMMFEvent addPronunciationComplete( KUidAsrEventAddPronunciation, err );
   320 	SendEventToClient( addPronunciationComplete );
   321 
   322 	// [ assert the Invariant  ]
   323 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   324 
   325 	}
   326 	
   327 	
   328 
   329 void CCustomMmfASRController::MSrSetClientUid( TUid aClientUid)
   330 	{
   331 	//[ assert the InVariant ]
   332 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   333 	
   334 	iDatabase->SetClientUid(aClientUid);
   335        
   336 	}
   337 
   338 
   339 /**
   340 *
   341 * MSrAddRule
   342 * @param aGrammarID
   343 * @param aLexiconID
   344 * @param aPronunciationID
   345 * @param aRuleID
   346 * @postcondition grammar has rule
   347 */
   348 void CCustomMmfASRController::MSrAddRuleL( 
   349 				TGrammarID aGrammarID, TLexiconID aLexiconID,
   350 				TPronunciationID aPronunciationID, TRuleID& aRuleID ) 
   351 	{
   352 	//[ assert the InVariant ]
   353 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   354 
   355 	//[ precondition that are in training mode ]
   356     __ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
   357   
   358 
   359 	//[ if the grammar has the rule ]
   360 	TInt err = KErrNone;
   361 	CSDDatabase::TRuleData ruleData=CSDDatabase::TRuleData();
   362 	ruleData.iLexiconID = aLexiconID;
   363 	ruleData.iPronunciationID = aPronunciationID;
   364 
   365 	TRAP( err, aRuleID = iDatabase->CreateRuleL( aGrammarID, ruleData));
   366 
   367 
   368 	TMMFEvent event( KUidAsrEventAddRule, err );
   369 	SendEventToClient( event );
   370 
   371 	// [ assert the Invariant  ]
   372 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   373 
   374 	}
   375 
   376 
   377 /**
   378 *
   379 * MSrCancel
   380 *
   381 */
   382 void CCustomMmfASRController::MSrCancel() 
   383 	{
   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 );
   388 	}
   389 
   390 /**
   391 *
   392 * MSrCommitChangesL
   393 *
   394 */
   395 void CCustomMmfASRController::MSrCommitChangesL() 
   396 	{
   397 	//[ assert the Invariant ]
   398 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   399 
   400 	iDatabase->CommitChangesL();
   401 
   402 	// [ assert the invariant ]
   403 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   404 	}
   405 
   406 /**
   407 *
   408 * MSrCreateGrammarL
   409 * Creates a Grammar and makes it the currently loaded grammar
   410 * @param aGrammarID
   411 * @precondition State == ESTraining
   412 * @postcondition iAsrSchema has grammar with id aGrammarID
   413 *
   414 */
   415 void CCustomMmfASRController::MSrCreateGrammarL( TGrammarID& aGrammarID ) 
   416 	{
   417     //[ assert the Invariant ]
   418 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   419 
   420 	//[ precondition that we are in trainning state ]
   421 	__ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
   422 	
   423 	aGrammarID = iDatabase->CreateGrammarL();
   424 	
   425 	 TMMFEvent event( KUidAsrEventCreateGrammar, KErrNone );
   426 	 SendEventToClient( event );
   427 	
   428 	//[ assert the invariant ]
   429 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   430 	}
   431 
   432 /**
   433 *
   434 * MSrCreateLexiconL
   435 * @param aLexiconID
   436 * Creates a Lexicon with Id aLexiconId
   437 *
   438 */
   439 void CCustomMmfASRController::MSrCreateLexiconL( TLexiconID& aLexiconID ) 
   440 	{
   441 	//[ assert the Invariant ]
   442 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   443 
   444 	//[ precondition that we are in trainning state ]
   445 	__ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
   446 
   447 	//[ create the Lexicon ]
   448 	aLexiconID = iDatabase->CreateLexiconL();
   449 	
   450 	TMMFEvent event( KUidAsrEventCreateLexicon, KErrNone );
   451 	SendEventToClient( event );
   452 
   453 	//[ assert the invariant ]
   454 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   455 
   456 	}
   457 
   458 /**
   459 *
   460 * MSrCreateModelBankL
   461 * @param aModelBankID
   462 * @precondition state == ESTraining
   463 * @precondition invariant holds
   464 * @postcondition currentModelbank id == modelbank id
   465 * 
   466 */
   467 void CCustomMmfASRController::MSrCreateModelBankL( TModelBankID& aModelBankID ) 
   468 	{
   469 	//[ assert the Invariant ]
   470 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   471 
   472 	//[ precondition that we are in trainning state ]
   473 	__ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
   474 
   475 	//[ create the new ModelBank]
   476     TRAPD(err, aModelBankID = iDatabase->CreateModelBankL());
   477     
   478    	TMMFEvent event( KUidAsrEventCreateModelBank, err);
   479 	SendEventToClient( event );
   480 
   481 	//[ assert the invariant ]
   482 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   483 	}
   484 
   485 /**
   486 *
   487 * MSrEndRecSessionL
   488 * End a recognition session
   489 * @precondition State is ESRecognition
   490 * @postcondition State is Idle
   491 */
   492 void CCustomMmfASRController::MSrEndRecSessionL()
   493 	{
   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 );
   500 
   501 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   502 	}
   503 
   504 /**
   505 *
   506 * MSrGetAllModelIDsL
   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
   511 */
   512 void CCustomMmfASRController::MSrGetAllModelIDsL( TModelBankID aModelBankID, RArray<TModelID>& aModelIDs ) 
   513 	{
   514 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   515 
   516 	TRAPD(err, iDatabase->GetAllModelIDsL(aModelBankID, aModelIDs));
   517 
   518 	TMMFEvent event( KUidAsrEventGetAllModelIDs, err );
   519 	SendEventToClient( event );
   520 
   521 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   522 	}
   523 
   524 /**
   525 *
   526 * MSrGetAllPronunciationIDsL
   527 * @precondition InVariant holds
   528 * @postcondition InVariantHolds
   529 */
   530 void CCustomMmfASRController::MSrGetAllPronunciationIDsL( TLexiconID aLexiconID, RArray<TPronunciationID>& aPronunciationIDs ) 
   531 	{
   532 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   533 	
   534 	TRAPD(err, iDatabase->GetAllPronunciationIDsL(aLexiconID, aPronunciationIDs));
   535 	
   536 	TMMFEvent event( KUidAsrEventGetAllPronunciationIDs, err );
   537 	SendEventToClient( event );
   538 
   539 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   540 	
   541 	}
   542 
   543 /**
   544 *
   545 * MSrGetAllRuleIDsL
   546 * Get all the rule ids contained in the grammar
   547 * @param aLexiconID
   548 * @param aRuleIDs
   549 * @precondition Invariant holds
   550 * @precondition Lexicon is Loaded
   551 * @postcondition Invariant holds
   552 */
   553 void CCustomMmfASRController::MSrGetAllRuleIDsL( TLexiconID aLexiconID, RArray<TRuleID>& aRuleIDs ) 
   554 	{
   555 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   556 	
   557 	TRAPD(err, iDatabase->GetAllRuleIDsL(aLexiconID, aRuleIDs));
   558 	
   559 	TMMFEvent event( KUidAsrEventGetAllRuleIDs, err );
   560 	SendEventToClient( event );
   561 	
   562 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   563 	}
   564 	
   565 	
   566 void CCustomMmfASRController::MSrGetAllClientModelBankIDsL(RArray<TModelBankID>& aModelBankIDs ) 
   567 	{
   568      __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   569 
   570 	TRAPD(err, iDatabase->GetAllModelBankIDsL(aModelBankIDs,ETrue));
   571 
   572 	TMMFEvent event( KUidAsrEventGetAllClientModelBankIDs, err );
   573 	SendEventToClient( event );
   574 
   575 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   576 	}
   577 
   578 void CCustomMmfASRController::MSrGetAllClientLexiconIDsL(RArray<TLexiconID>& aLexiconIDs ) 
   579 	{
   580 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   581 	
   582 	TRAPD(err, iDatabase->GetAllLexiconIDsL(aLexiconIDs, ETrue));
   583 
   584 	TMMFEvent event( KUidAsrEventGetAllClientLexiconIDs, err );
   585 	SendEventToClient( event );
   586 
   587 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   588 	
   589 	}
   590 
   591 void CCustomMmfASRController::MSrGetAllClientGrammarIDsL(RArray<TGrammarID>& aGrammarIDs ) 
   592 	{
   593 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   594 	
   595 	TRAPD(err, iDatabase->GetAllGrammarIDsL(aGrammarIDs, ETrue));
   596 
   597 	TMMFEvent event( KUidAsrEventGetAllClientGrammarIDs, err );
   598 	SendEventToClient( event );
   599 	
   600 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   601 	}
   602 	
   603 void CCustomMmfASRController::MSrGetAllModelBankIDsL(RArray<TModelBankID>& aModelBankIDs ) 
   604 	{
   605      __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   606 
   607 	TRAPD(err, iDatabase->GetAllModelBankIDsL(aModelBankIDs));
   608 
   609 	TMMFEvent event( KUidAsrEventGetAllModelBankIDs, err );
   610 	SendEventToClient( event );
   611 
   612 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   613 	}
   614 
   615 void CCustomMmfASRController::MSrGetAllLexiconIDsL(RArray<TLexiconID>& aLexiconIDs ) 
   616 	{
   617 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   618 	
   619 	TRAPD(err, iDatabase->GetAllLexiconIDsL(aLexiconIDs));
   620 
   621 	TMMFEvent event( KUidAsrEventGetAllLexiconIDs, err );
   622 	SendEventToClient( event );
   623 
   624 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   625 	
   626 	}
   627 
   628 void CCustomMmfASRController::MSrGetAllGrammarIDsL(RArray<TGrammarID>& aGrammarIDs ) 
   629 	{
   630 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   631 	
   632 	TRAPD(err, iDatabase->GetAllGrammarIDsL(aGrammarIDs));
   633 
   634 	TMMFEvent event( KUidAsrEventGetAllGrammarIDs, err );
   635 	SendEventToClient( event );
   636 	
   637 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   638 	}
   639 
   640 
   641 /**
   642 *
   643 * MSrGetAvailableStorageL
   644 * gets the available storage
   645 * For this simulation the function always returns zero space available
   646 * @parameter aCount
   647 * @precondition Invariant holds
   648 *
   649 */
   650 void CCustomMmfASRController::MSrGetAvailableStorageL( TInt& aCount ) 
   651 	{
   652 	//[ assert the invariant ]
   653 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   654 	
   655 	//[ for now we will return no space available ]
   656 	aCount = 0;
   657 	
   658 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   659 	}
   660 
   661 /**
   662 *
   663 * MSrGetEnginePropertiesL
   664 * @param aProperties
   665 * @precondition Invariant holds
   666 *
   667 */
   668 void CCustomMmfASRController::MSrGetEnginePropertiesL( const RArray<TInt>& aPropertyId,
   669 						RArray<TInt>& aPropertyValue ) 
   670 	{
   671 	//[ assert the invariant ]
   672 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   673 
   674 	//[ empty the src array ]
   675     aPropertyValue.Reset();
   676 
   677 	//[ for all the ids specified ]
   678     for( TInt count = 0; count < aPropertyId.Count(); count++ )
   679 		{
   680 		//[ we are just faking this for the moment ]
   681 		aPropertyValue.Append( count );
   682 		}
   683 
   684     //[assert there are properties for all the ids]
   685 	__ASSERT_ALWAYS( aPropertyValue.Count() == aPropertyId.Count(), Panic(EPostConditionViolation) );
   686 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   687 	}
   688 
   689 /**
   690 *
   691 * MSrLoadEngineParametersL
   692 *
   693 */
   694 void CCustomMmfASRController::MSrLoadEngineParametersL( const RArray<TInt>& aParameterId, 
   695 						const RArray<TInt>& aParameterValue )
   696 	{
   697 	TBool pass = ETrue;
   698 	if (aParameterId.Count()!=KNumParameters ||
   699 		aParameterValue.Count()!=KNumParameters)
   700 		pass = EFalse;
   701 	else 
   702 		{
   703 		TInt i;
   704 		for (i=0;i<aParameterId.Count() && pass;i++)
   705 			if (aParameterId[i]!=KParameterIDs[i])
   706 				pass = EFalse;
   707 				
   708 		for (i=0;i<aParameterValue.Count() && pass;i++)
   709 			if (aParameterValue[i]!=KParameterValues[i])
   710 				pass = EFalse;
   711 				
   712 	
   713 		}
   714 	if (pass)
   715 		{
   716 		TMMFEvent event( KUidTestASRLoadParameters, KErrNone );
   717 		SendEventToClient(event);					
   718 		}
   719 	else
   720 		{
   721 		TMMFEvent event( KUidTestASRLoadParameters, KErrArgument );
   722 		SendEventToClient(event);					
   723 		}
   724 	}
   725 
   726 /**
   727 *
   728 * MSrGetModelCountL
   729 * @param aModelBankID
   730 * @param aCount
   731 * @precondition Invariant holds
   732 * @precondition model is loaded
   733 * @postcondition Invariant holds
   734 * @postcondition modelcount >=0
   735 */
   736 void CCustomMmfASRController::MSrGetModelCountL( TModelBankID aModelBankID, TInt& aCount ) 
   737 	{
   738 	//[ assert the invariant ]
   739 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   740 
   741 	RArray<TPronunciationID> ids;
   742 	CleanupClosePushL(ids);
   743 	TRAPD(err, iDatabase->GetAllModelIDsL(aModelBankID,ids));
   744 	
   745 	if (err==KErrNone)
   746 		aCount = ids.Count();
   747 		
   748 	CleanupStack::PopAndDestroy(&ids);
   749 	
   750 	TMMFEvent event( KUidAsrEventGetModelCount, err );
   751 	SendEventToClient( event );
   752 
   753 
   754 	//[ assert the invariant ]
   755 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   756 	}
   757 
   758 
   759 
   760 /**
   761 *
   762 * MSrGetRuleValidityL
   763 * @param aGrammarID
   764 * @param aRuleID
   765 * @param aValid
   766 * @precondition InVariantHolds
   767 * @precondition state is training or state is recognition
   768 * @precondition grammar is loaded
   769 * @postcondition InVariantHolds
   770 */
   771 void CCustomMmfASRController::MSrGetRuleValidityL( TGrammarID aGrammarID, TRuleID aRuleID, TBool& aValid ) 
   772 	{
   773 	//[ assert the invariant ]
   774 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   775 	//[ precondition the schema exists ]
   776 
   777 	CSDDatabase::RSDRuleTable ruleTable(*iDatabase);
   778 	CleanupClosePushL(ruleTable);
   779 	ruleTable.OpenL(aGrammarID);
   780 	TRAPD(err, aValid = ruleTable.IsRuleValidL(aRuleID));
   781 	CleanupStack::PopAndDestroy(&ruleTable);
   782 
   783    	TMMFEvent event( KUidAsrEventGetRuleValidity, err );
   784 	SendEventToClient( event );
   785 
   786 	//[ assert the invariant ]
   787 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   788 	}
   789 
   790 /**
   791 *
   792 * MSrGetUtteranceDurationL
   793 * @param aModelBankID
   794 * @param aModelID
   795 * @param aDuration
   796 * @param aFromMemory
   797 * 
   798 */
   799 void CCustomMmfASRController::MSrGetUtteranceDurationL( TModelBankID aModelBankID, TModelID aModelID,
   800 								   TTimeIntervalMicroSeconds32& aDuration) 
   801 	{
   802     //[ assert the Invariant ]
   803 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   804 
   805 	CSDDatabase::TModelData modelData = CSDDatabase::TModelData();
   806 
   807 	TInt err;
   808 	TRAP(err, iDatabase->GetModelDataL(aModelBankID, aModelID, modelData));
   809 	if (err==KErrNone)
   810 		{
   811 		aDuration = modelData.iUtteranceDurationMicroSeconds;
   812 		}
   813 
   814 	TMMFEvent event( KUidAsrEventGetUtteranceDuration, err );
   815 	SendEventToClient( event );
   816 
   817 
   818 	//[ assert the Invariant ]
   819 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   820 	}
   821 
   822 /**
   823 *
   824 * MSrLoadGrammarL
   825 * @param aGrammarID
   826 * @precondition aGrammarId is supported by the test controller
   827 * @postcondition aGrammarId == id of loaded grammar
   828 */
   829 void CCustomMmfASRController::MSrLoadGrammarL( TGrammarID aGrammarID ) 
   830 	{
   831 	//[ assert the Invariant ]
   832 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   833 
   834 	//[ must be in trainning or recognition state ]
   835 	__ASSERT_ALWAYS( (State() == ESRecognition ) || ( State() == ESTraining ), Panic(EBadState) );
   836 
   837 	TInt err = KErrNone;	
   838 	if (iDatabase->GrammarExistsL(aGrammarID))
   839 		{
   840 		iLoadedGrammarID = aGrammarID;
   841 		}
   842 	else
   843 		err = KErrNotFound;
   844 		
   845 	TMMFEvent event( KUidAsrEventLoadGrammar, err );
   846 	SendEventToClient( event );
   847 
   848 	//[ assert the Invariant ]
   849 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   850 	}
   851 
   852 /**
   853 *
   854 * MSrLoadLexiconL
   855 * @param aLexiconID
   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
   861 */
   862 void CCustomMmfASRController::MSrLoadLexiconL( TLexiconID aLexiconID ) 
   863 	{
   864 	//[ assert the Invariant ]
   865 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   866 
   867 	//[ must be in trainning or recognition state ]
   868 	__ASSERT_ALWAYS( (State() == ESRecognition ) || ( State() == ESTraining ), Panic(EBadState));
   869 
   870 	TInt err = KErrNone;
   871 	if (iDatabase->LexiconExistsL(aLexiconID))
   872 		{
   873 		iLoadedLexiconID = aLexiconID;
   874 		}
   875 	else
   876 		err = KErrNotFound;
   877 
   878 	TMMFEvent event( KUidAsrEventLoadLexicon, err );
   879 	SendEventToClient( event );
   880 
   881 	//[ assert the Invariant ]
   882 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   883 	}
   884 
   885 /**
   886 *
   887 * MSrLoadModelsL
   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
   894 */
   895 void CCustomMmfASRController::MSrLoadModelsL( TModelBankID aModelBankID ) 
   896 	{
   897 	//[ assert the Invariant ]
   898 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   899 
   900 	//[ must be in trainning or recognition state ]
   901 	__ASSERT_ALWAYS( (State() == ESRecognition ) || ( State() == ESTraining ), Panic(EBadState));
   902 
   903 	TInt err = KErrNone;
   904 	if (iDatabase->ModelBankExistsL(aModelBankID))
   905 		{
   906 		iLoadedModelBankID = aModelBankID;
   907 		}
   908 	else
   909 		err = KErrNotFound;
   910 
   911 	TMMFEvent event( KUidAsrEventLoadModels, err );
   912 	SendEventToClient( event );
   913 
   914 	//[ assert the Invariant ]
   915 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   916 
   917 	}
   918 
   919 /**
   920 *
   921 * MSrPlayUtteranceL
   922 * @param aModelBankID 
   923 * @param aModelID
   924 * @param aPlayFromMemory
   925 * Always plays froms memory
   926 */
   927 void CCustomMmfASRController::MSrPlayUtteranceL( TModelBankID aModelBankID, TModelID aModelID ) 
   928 	{
   929 	//[ assert the InVariant ]
   930 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   931 
   932 	if (!iDatabase->ModelExistsL(aModelBankID, aModelID))
   933 		{
   934 		User::Leave(KErrNotFound);
   935 		}
   936 	else
   937 		{
   938 		TMMFEvent aPlayStarted( KUidAsrEventPlayStarted, KErrNone );
   939 		SendEventToClient( aPlayStarted );
   940 		
   941 		TMMFEvent aPlayComplete( KUidAsrEventPlay, KErrNone );
   942 		SendEventToClient( aPlayComplete );
   943 		}
   944 
   945 	//[ assert the InVariant ]
   946 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   947 	}
   948 
   949 /**
   950 *
   951 * MSrRecognizeL
   952 * @param aResultSet
   953 *
   954 */
   955 void CCustomMmfASRController::MSrRecognizeL( CSDClientResultSet& aResultSet ) 
   956 	{
   957 	//[ assert the Invariant ]
   958 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   959 
   960 	//[ Precondition that we are in a recognition session ]
   961 	if( State() != ESRecognition )
   962 		{
   963 		TMMFEvent recognitionFailed( KUidAsrEventRecognition, KErrNotReady );
   964 		SendEventToClient( recognitionFailed );
   965 		return;
   966 		}
   967 
   968 	TMMFEvent recognitionReady( KUidAsrEventRecognitionReady,KErrNone );
   969 	SendEventToClient( recognitionReady );
   970 
   971 	//[ return a result set ]
   972 	iMaxResults = aResultSet.MaxResults();
   973     iResultSet = &aResultSet;
   974 
   975     iRecognizeComplete = ETrue;
   976 	
   977 	//[ assert the Invariant ]
   978 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   979 	}
   980 
   981 /*
   982 *
   983 * MSrRecordL
   984 * @param aRecordTime
   985 * @precondition InVariant holds
   986 * @postcondition 
   987 */
   988 void CCustomMmfASRController::MSrRecordL( TTimeIntervalMicroSeconds32 aRecordTime ) 
   989 	{
   990 	//[ assert the invariant ]
   991 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   992 	
   993 	//[ remember the record time 
   994 	// and for the purpose of simulation recording takes zero time ]
   995 	iRecordTime = aRecordTime ;
   996 
   997 	TMMFEvent aRecordStartedEvent( KUidAsrEventRecordStarted, KErrNone );
   998 	SendEventToClient( aRecordStartedEvent );
   999 
  1000 	TMMFEvent aEndOfUtteranceEvent( KUidAsrEventEouDetected, KErrNone );
  1001 	SendEventToClient( aEndOfUtteranceEvent );
  1002 
  1003 	if( iRecognizeComplete )
  1004 		{
  1005 		iRecognizeComplete = EFalse;
  1006 		
  1007 		for (TInt i=0;i<iMaxResults && i<KMaxAvailableResults;i++)
  1008 		{
  1009 			CSDClientResult& result = CONST_CAST(CSDClientResult&, iResultSet->At(i));
  1010 			result.SetGrammarID(KResultsGrammarID[i]);
  1011 			result.SetRuleID(KResultsRuleID[i]);
  1012 		}
  1013 		
  1014 		TMMFEvent recognitionComplete( KUidAsrEventRecognition, KErrNone );
  1015 		SendEventToClient( recognitionComplete );
  1016 		}
  1017 
  1018  	//[ assert the invaraint ]
  1019 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1020 	}
  1021 
  1022 /**
  1023 *
  1024 * MSrRemoveGrammarL
  1025 * Interpreted as unload from memory here 
  1026 *
  1027 */
  1028 void CCustomMmfASRController::MSrRemoveGrammarL( TGrammarID aGrammarID ) 
  1029 	{
  1030 	//[ assert the invaraint ]
  1031 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
  1032     
  1033 
  1034 	if (iLoadedGrammarID == aGrammarID)
  1035 		{
  1036 		TMMFEvent event( KUidAsrEventRemoveGrammar, KErrInUse );
  1037 		SendEventToClient( event );
  1038 		}		
  1039 	else
  1040 		{		
  1041 		TRAPD(err, iDatabase->RemoveGrammarL(aGrammarID));
  1042 		//[ send message to client of success ]
  1043 		TMMFEvent event( KUidAsrEventRemoveGrammar, err );
  1044 		SendEventToClient( event );
  1045 		}
  1046 
  1047 	//[ assert the invaraint ]
  1048 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1049 	}
  1050 
  1051 /**
  1052 *
  1053 * MSrRemoveLexiconL
  1054 * @param aLexiconID
  1055 * slightly different interpretation here 
  1056 */
  1057 void CCustomMmfASRController::MSrRemoveLexiconL( TLexiconID aLexiconID ) 
  1058 	{
  1059     //[ assert the invaraint ]
  1060 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1061 
  1062 
  1063 	if (iLoadedLexiconID == aLexiconID)
  1064 		{
  1065 		TMMFEvent event( KUidAsrEventRemoveLexicon, KErrInUse );
  1066 		SendEventToClient( event );
  1067 		}		
  1068 	else
  1069 		{		
  1070 		TRAPD(err, iDatabase->RemoveLexiconL(aLexiconID));
  1071 		//[ send message to client of success ]
  1072 		TMMFEvent event( KUidAsrEventRemoveLexicon, err );
  1073 		SendEventToClient( event );
  1074 		}
  1075 	
  1076 	//[ assert the invaraint ]
  1077 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1078 	
  1079 
  1080 	}
  1081 
  1082 /**
  1083 *
  1084 * MSrRemoveModelBankL
  1085 *
  1086 *
  1087 */
  1088 void CCustomMmfASRController::MSrRemoveModelBankL( TModelBankID aModelBankID )
  1089 	{
  1090     //[ assert the invaraint ]
  1091 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1092 
  1093 
  1094 	if (iLoadedModelBankID == aModelBankID)
  1095 		{
  1096 		TMMFEvent event( KUidAsrEventRemoveModelBank, KErrInUse );
  1097 		SendEventToClient( event );
  1098 		}		
  1099 	else
  1100 		{		
  1101 		TRAPD(err, iDatabase->RemoveModelBankL(aModelBankID));
  1102 		//[ send message to client of success ]
  1103 		TMMFEvent event( KUidAsrEventRemoveModelBank, err );
  1104 		SendEventToClient( event );
  1105 		}
  1106 	
  1107 	//[ assert the invaraint ]
  1108 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1109 
  1110 	}
  1111 
  1112 /**
  1113 *
  1114 * MSrRemoveModelL
  1115 * @param aModelBankID
  1116 * @param aModeID
  1117 * @precondition InVariant holds
  1118 * @precondition model bank exists
  1119 * @precondition modelbank contains the model
  1120 * @postcondition model bank does not contain model
  1121 *
  1122 */
  1123 void CCustomMmfASRController::MSrRemoveModelL( TModelBankID aModelBankID, TModelID aModelID )
  1124 	{
  1125 	//[ assert the invariant ]
  1126 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1127 	
  1128 	if (iLoadedModelBankID == aModelBankID)
  1129 		{
  1130 		TMMFEvent event( KUidAsrEventRemoveModelBank, KErrInUse );
  1131 		SendEventToClient( event );
  1132 		}		
  1133 	else
  1134 		{	
  1135 		TInt err = KErrNone;
  1136 		if (!iDatabase->ModelBankExistsL(aModelBankID))
  1137 			err = KErrNotFound;
  1138 		else 
  1139 			{
  1140 			CSDDatabase::RSDModelTable view(*iDatabase);
  1141 			CleanupClosePushL(view);
  1142 			view.OpenL(aModelBankID);
  1143 			if (view.FindModelL(aModelID))
  1144 				{
  1145 				view.RemoveModelL(aModelID);
  1146 				}
  1147 			else
  1148 				err = KErrNotFound;
  1149 				
  1150 			CleanupStack::PopAndDestroy(&view);
  1151 			}
  1152 		//[ send message to client of success ]
  1153 		TMMFEvent event( KUidAsrEventRemoveModel, err );
  1154 		SendEventToClient( event );
  1155 		}
  1156 	
  1157 	//[ assert the invaraint ]
  1158 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1159 	}
  1160 
  1161 /**
  1162 *
  1163 * MSrRemovePronunciationL
  1164 * @param aLexiconID
  1165 * @param aPronunciationID
  1166 * @precondition lexicon exists
  1167 * @precondition lexicon has id specified
  1168 * @postconfition lexicon does not have pronunication
  1169 *
  1170 */
  1171 void CCustomMmfASRController::MSrRemovePronunciationL( TLexiconID aLexiconID, TPronunciationID aPronunciationID )
  1172 	{
  1173    	//[ assert the invaraint ]
  1174 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1175 	
  1176 	if (iLoadedLexiconID == aLexiconID)
  1177 		{
  1178 		TMMFEvent event( KUidAsrEventRemovePronunciation, KErrInUse );
  1179 		SendEventToClient( event );
  1180 		}		
  1181 	else
  1182 		{	
  1183 		TInt err = KErrNone;
  1184 		if (!iDatabase->LexiconExistsL(aLexiconID))
  1185 			err = KErrNotFound;
  1186 		else 
  1187 			{
  1188 			CSDDatabase::RSDPronunciationTable view(*iDatabase);
  1189 			CleanupClosePushL(view);
  1190 			view.OpenL(aLexiconID);
  1191 			if (view.FindPronunciationL(aPronunciationID))
  1192 				{
  1193 				view.RemovePronunciationL(aPronunciationID);
  1194 				}
  1195 			else
  1196 				err = KErrNotFound;
  1197 				
  1198 			CleanupStack::PopAndDestroy(&view);
  1199 			}
  1200 		//[ send message to client of success ]
  1201 		TMMFEvent event( KUidAsrEventRemovePronunciation, err );
  1202 		SendEventToClient( event );
  1203 		}
  1204 	
  1205 	//[ assert the invaraint ]
  1206 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1207 	}
  1208 
  1209 /**
  1210 *
  1211 * MSrRemoveRuleL
  1212 * @param aLexiconID
  1213 * @param aRuleID
  1214 * @precondition InVariant holds
  1215 * @precondition grammar is loaded
  1216 * @precondition grammar has id specified
  1217 * @postcondition grammar does not contain rule
  1218 *
  1219 */
  1220 void CCustomMmfASRController::MSrRemoveRuleL( TGrammarID aGrammarID, TRuleID aRuleID )
  1221 	{
  1222 	//[ assert the invaraint ]
  1223 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1224 	
  1225 	if (iLoadedGrammarID == aGrammarID)
  1226 		{
  1227 		TMMFEvent event( KUidAsrEventRemoveRule, KErrInUse );
  1228 		SendEventToClient( event );
  1229 		}		
  1230 	else
  1231 		{		
  1232 		TInt err = KErrNone;
  1233 		if (!iDatabase->GrammarExistsL(aGrammarID))
  1234 			err = KErrNotFound;
  1235 		else 
  1236 			{
  1237 			CSDDatabase::RSDRuleTable view(*iDatabase);
  1238 			CleanupClosePushL(view);
  1239 			view.OpenL(aGrammarID);
  1240 			if (view.FindRuleL(aRuleID))
  1241 				{
  1242 				view.RemoveRuleL(aRuleID);
  1243 				}
  1244 			else
  1245 				err = KErrNotFound;
  1246 				
  1247 			CleanupStack::PopAndDestroy(&view);
  1248 			}
  1249 		//[ send message to client of success ]
  1250 		TMMFEvent event( KUidAsrEventRemoveRule, err );
  1251 		SendEventToClient( event );
  1252 		}
  1253 	
  1254 	//[ assert the invaraint ]
  1255 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1256 	}
  1257 
  1258 /**
  1259 *
  1260 * MSrStartRecSessionL
  1261 * @param aMode
  1262 * @precondition mode is valid
  1263 *
  1264 */
  1265 void CCustomMmfASRController::MSrStartRecSessionL( TRecognitionMode aMode )
  1266 	{
  1267 	//[ assert the invariant holds ]
  1268 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1269 
  1270 	//[ precondition the mode is valid ]
  1271 	if( (aMode < ESdMode ) || ( aMode > ESdSiMode) )
  1272 		{
  1273 		User::Leave( KErrArgument );
  1274 		}
  1275 
  1276 	//[ it does not matter which state we are in we can
  1277 	// always transition to recognition ]
  1278 	SetState( ESRecognition );
  1279 
  1280 	//[ set the recognition mode ]
  1281 	iRecognitionMode = aMode ;
  1282 
  1283 	//[ assert the Invariant holds ]
  1284 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1285 
  1286 	//[ assert the post condition that the mode has been en
  1287 	__ASSERT_ALWAYS( iRecognitionMode == aMode, Panic(EPostConditionViolation) );
  1288 	}
  1289 
  1290 /**
  1291 *
  1292 * MSrTrainL
  1293 * @param aModelBankID
  1294 * @param aModelID
  1295 *
  1296 */
  1297 void CCustomMmfASRController::MSrTrainL( TModelBankID aModelBankID, TModelID& aModelID )
  1298 	{
  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 );
  1310 
  1311 	// [ precondition model bank is loaded ]
  1312 	if( iLoadedModelBankID != aModelBankID )
  1313 		 {
  1314 	 	 TMMFEvent event( KUidAsrEventTrain, KErrNotReady );
  1315 		 SendEventToClient( event );
  1316 		 return;
  1317 		 }
  1318 
  1319 	TInt err = KErrNone;
  1320 	
  1321 	CSDDatabase::TModelData modelData=CSDDatabase::TModelData();
  1322 	modelData.iUtteranceDurationMicroSeconds = KUtteranceDuration;
  1323 	TRAP(err, aModelID = iDatabase->CreateModelL( aModelBankID, modelData));
  1324 
  1325 	TMMFEvent trainCompleteEvent( KUidAsrEventTrain, err );
  1326 	SendEventToClient( trainCompleteEvent );
  1327 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1328 	}
  1329 
  1330 /**
  1331 *
  1332 * MSrUnloadRuleL
  1333 * @param aGrammarID
  1334 * @param aRuleID
  1335 * @precondition state == ESTraining
  1336 * @postcondition grammar does not contain rule
  1337 *
  1338 */
  1339 void CCustomMmfASRController::MSrUnloadRuleL( TGrammarID aGrammarID, TRuleID aRuleID )
  1340 	{
  1341 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1342 
  1343 	//[ precondition grammar loaded is grammar with id ]
  1344 	__ASSERT_ALWAYS( iLoadedGrammarID == aGrammarID, Panic(EPreConditionViolation) );
  1345 
  1346 	TBool ruleExists = EFalse;
  1347 
  1348 	TRAPD(err, ruleExists = iDatabase->RuleExistsL(aGrammarID, aRuleID));
  1349 
  1350 	if (err == KErrNone)
  1351 		{
  1352 		if (!ruleExists)
  1353 			err = KErrNotFound;
  1354 		}
  1355 
  1356 	//[ send message to client of success ]
  1357 	TMMFEvent event( KUidAsrEventUnloadRule, err );
  1358 	SendEventToClient( event );
  1359 
  1360 	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1361 	}
  1362 	
  1363 /**
  1364  *  SendEventToClient
  1365  *
  1366  *	@param aEvent
  1367  */
  1368 TInt CCustomMmfASRController::SendEventToClient(const TMMFEvent& aEvent)
  1369 	{
  1370 	//now send event to client...
  1371 	return DoSendEventToClient(aEvent);
  1372 	}
  1373 
  1374 /**
  1375 *
  1376 * GetNumberOfMetaDataEntriesL
  1377 *
  1378 * @param "TInt"
  1379 *
  1380 */
  1381 void CCustomMmfASRController::GetNumberOfMetaDataEntriesL(TInt& /*aNumberOfEntries*/ ) 
  1382 	{
  1383 	 //[This function is deprecated and should not have been called]
  1384      Panic(EDeprecatedFunction);
  1385 	}
  1386 
  1387 /**
  1388 * GetMetaDataEntryL
  1389 * @param aIndex
  1390 * @returns "CMMFMetaDataEntry*"
  1391 */
  1392 CMMFMetaDataEntry* CCustomMmfASRController::GetMetaDataEntryL(TInt /*aIndex*/ ) 
  1393 	{
  1394 	//[This function is deprecated and should not have been called]
  1395     Panic(EDeprecatedFunction);
  1396 	return NULL;
  1397 	}
  1398 
  1399 /**
  1400 * RemoveDataSourceL
  1401 * @param aDataSource
  1402 * 
  1403 */
  1404 void CCustomMmfASRController::RemoveDataSourceL(MDataSource& /*aDataSource*/ )
  1405 	{
  1406 	//[This function is deprecated and should not have been called]
  1407     Panic(EDeprecatedFunction);
  1408 	}
  1409 
  1410 /**
  1411 * RemoveDataSinkL
  1412 * 
  1413 * @param aDataSink
  1414 *
  1415 */
  1416 void CCustomMmfASRController::RemoveDataSinkL(MDataSink& /*aDataSink*/ )
  1417 	{
  1418 	 //[This function is deprecated and should not have been called]
  1419      Panic(EDeprecatedFunction);
  1420 	}
  1421 
  1422 /**
  1423  *  SetPrioritySettings
  1424  *
  1425  *	@param aPrioritySettings
  1426  */
  1427 void CCustomMmfASRController::SetPrioritySettings(const TMMFPrioritySettings& /*aPrioritySettings*/)
  1428 	{
  1429 	}
  1430 
  1431 /**
  1432 *
  1433 * DurationL
  1434 *
  1435 * @returns TTimeIntervalMicroSeconds 
  1436 *
  1437 */
  1438 TTimeIntervalMicroSeconds CCustomMmfASRController::DurationL() const
  1439 	{
  1440 	TTimeIntervalMicroSeconds xx(0);
  1441 	return xx; 
  1442 	}
  1443 
  1444 /**
  1445 *
  1446 * InVariant
  1447 * @returns TBool
  1448 *
  1449 */
  1450 TBool CCustomMmfASRController::InVariant() const
  1451 	{
  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 ) )
  1455 		 {
  1456 		 status = ETrue;
  1457 		 }
  1458 	 
  1459 	 return status;
  1460 	}
  1461 
  1462 /**
  1463 *
  1464 * State
  1465 * @returns TControllerState
  1466 *
  1467 */
  1468 CCustomMmfASRController::TControllerState CCustomMmfASRController::State() const
  1469 	{
  1470 	return iState;	
  1471 	}