os/mm/mmdevicefw/speechrecogsupport/tsrc/ASR/src/ASRController/CustomMmfASRController.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmdevicefw/speechrecogsupport/tsrc/ASR/src/ASRController/CustomMmfASRController.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1471 @@
     1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "CustomMmfASRController.h"
    1.20 +
    1.21 +#include <mmfcontrollerimplementationuids.hrh>
    1.22 +#include "customcontrollertestconstants.h"
    1.23 +#include "Database/testdatabaseconstants.h"
    1.24 +
    1.25 +/*
    1.26 +	TMmfAsrControllerPanics is an enumeration with the following entries:
    1.27 +	
    1.28 +	EBadArgument indicates a bad argument
    1.29 +	EBadState indicates a state viaolation
    1.30 +	EBadInvariant indicates an invariant violation
    1.31 +	EBadReset indicates failed reset
    1.32 +	EPostConditionViolation indicates a post condition violation
    1.33 +
    1.34 +*/
    1.35 +enum TMmfAsrControllerPanics
    1.36 +	{
    1.37 +	EBadArgument,
    1.38 +	EBadState,
    1.39 +	EBadInvariant,
    1.40 +	EPreConditionViolation,
    1.41 +	EPostConditionViolation,
    1.42 +	EDeprecatedFunction
    1.43 +	};
    1.44 +
    1.45 +/**
    1.46 +* Panic
    1.47 +* This method generates a panic
    1.48 +* @param "TInt"
    1.49 +* @xxxx
    1.50 +*/
    1.51 +void Panic(TMmfAsrControllerPanics aPanicCode)
    1.52 +	{
    1.53 +	_LIT(KMMFAsrControllerPanicCategory, "MMFAsrTestController");
    1.54 +	User::Panic(KMMFAsrControllerPanicCategory, aPanicCode);
    1.55 +	}
    1.56 +
    1.57 +
    1.58 +/**
    1.59 +*
    1.60 +* NewL
    1.61 +*
    1.62 +*/
    1.63 +CMMFController* CCustomMmfASRController::NewL()
    1.64 +	{
    1.65 +    CCustomMmfASRController* self = new(ELeave) CCustomMmfASRController;
    1.66 +	CleanupStack::PushL(self);
    1.67 +	self->ConstructL();
    1.68 +	CleanupStack::Pop( self );	
    1.69 +	return STATIC_CAST( CMMFController*, self );
    1.70 +	}
    1.71 +
    1.72 +
    1.73 +/**
    1.74 +*
    1.75 +* SetState
    1.76 +* @param aState
    1.77 +*
    1.78 +*/
    1.79 +void CCustomMmfASRController::SetState( TControllerState aState )
    1.80 +	{
    1.81 +	iState=aState;
    1.82 +	}
    1.83 +
    1.84 +/**
    1.85 +*
    1.86 +* ConstructL
    1.87 +*
    1.88 +*/
    1.89 +void CCustomMmfASRController::ConstructL()
    1.90 +	{
    1.91 +	//[ Construct custom command parsers]
    1.92 +	CSpeechRecognitionCustomCommandParser* asrParser = CSpeechRecognitionCustomCommandParser::NewL(*this);
    1.93 +	CleanupStack::PushL(asrParser);
    1.94 +	AddCustomCommandParserL(*asrParser);
    1.95 +	CleanupStack::Pop( asrParser ); //asrParser
    1.96 +
    1.97 +	SetState( ESTraining );  //state of the controller
    1.98 +	iRecognitionMode =	ESdMode; // recognition mode which is nonzero for now
    1.99 +	iRecordTime = 0; // the duration of the recording for both recognition and trainning
   1.100 +
   1.101 +	iRecognizeComplete = EFalse;
   1.102 +	iLoadedGrammarID = 0;
   1.103 +	iLoadedLexiconID = 0;
   1.104 +	iLoadedModelBankID = 0;
   1.105 +	
   1.106 +  	RFs fsSession;
   1.107 +  	RFile file;
   1.108 +  	User::LeaveIfError(fsSession.Connect());
   1.109 +    CleanupClosePushL(fsSession);
   1.110 +    TInt err = file.Open(fsSession, KFileNameTestDatabase, EFileRead);
   1.111 +  	file.Close();
   1.112 +  	if(err == KErrNone)
   1.113 +  		{
   1.114 +	    iDatabase = CSDDatabase::NewL(KFileNameTestDatabase);
   1.115 +  		}
   1.116 +   	else if(err == KErrNotFound)
   1.117 +  		{
   1.118 +	    iDatabase = CSDDatabase::NewL(KFileNameTestDatabase, EFalse);		
   1.119 +  		}
   1.120 +	else if(err == KErrPathNotFound)
   1.121 +  		{
   1.122 +  		TParse fullFileName;
   1.123 + 		if(fullFileName.Set(KFileNameTestDatabase, NULL, NULL) == KErrNone)
   1.124 +			{
   1.125 +		 	err = fsSession. MkDirAll(fullFileName.DriveAndPath());
   1.126 +		 	if(err == KErrNone)
   1.127 +		 		{
   1.128 +			    iDatabase = CSDDatabase::NewL(KFileNameTestDatabase,EFalse);		
   1.129 +		 		}
   1.130 +		 	else
   1.131 +		 		{
   1.132 +			    User::LeaveIfError(err); 			
   1.133 +		 		}	
   1.134 +	  		}  				
   1.135 + 		}
   1.136 +  	else
   1.137 +  		{
   1.138 +	    User::LeaveIfError(err);
   1.139 +  		}
   1.140 +  	CleanupStack::PopAndDestroy(); //fsSession 
   1.141 +	}
   1.142 +
   1.143 +
   1.144 +
   1.145 +/**
   1.146 +*
   1.147 +* ~CCustomMmfAudioController
   1.148 +*
   1.149 +*/
   1.150 +CCustomMmfASRController::~CCustomMmfASRController()
   1.151 +	{
   1.152 +	delete iDatabase;
   1.153 +	}
   1.154 +
   1.155 +/**
   1.156 +*
   1.157 +* CCustomMmfAudioController
   1.158 +*
   1.159 +*/
   1.160 +CCustomMmfASRController::CCustomMmfASRController()
   1.161 +	{	
   1.162 +	}
   1.163 +
   1.164 +/**
   1.165 +*
   1.166 +* CustomCommand
   1.167 +*
   1.168 +*/
   1.169 +void CCustomMmfASRController::CustomCommand(TMMFMessage& /*aMessage*/)
   1.170 +	{
   1.171 +     // The custom command is the final stopping off point
   1.172 +	 // in the command processing chain and in this case it does
   1.173 +	 // nothing!
   1.174 +	}
   1.175 +
   1.176 +/**
   1.177 + *  AddDataSourceL
   1.178 + *
   1.179 + *	Adds a data source to the controller
   1.180 + *
   1.181 + *	@param aSource
   1.182 + * Preconditions:
   1.183 + * We are stopped
   1.184 + * Source does not already exist
   1.185 + * Postconditions:
   1.186 + * iDataSource != NULL
   1.187 + * iDataSourceAdded == ETrue
   1.188 + *
   1.189 + */
   1.190 +void CCustomMmfASRController::AddDataSourceL(MDataSource& /*aSource*/)
   1.191 +	{
   1.192 +	 //[This function is deprecated and should not have been called]
   1.193 +     Panic(EDeprecatedFunction);
   1.194 +	}
   1.195 +
   1.196 +/**
   1.197 + *  AddDataSinkL
   1.198 + *
   1.199 + *	Adds a data sink to the controller
   1.200 + *
   1.201 + *	@param aSink
   1.202 + *
   1.203 + */
   1.204 +void CCustomMmfASRController::AddDataSinkL(MDataSink& )
   1.205 +	{
   1.206 +	 //[This function is deprecated and should not have been called]
   1.207 +     Panic(EDeprecatedFunction);
   1.208 +	}
   1.209 +
   1.210 +/**
   1.211 + *  PrimeL
   1.212 + *
   1.213 + *  If Prime fails the client should reset the controller
   1.214 + *  because as noted below this code is not transactional.
   1.215 + *
   1.216 + */
   1.217 +void CCustomMmfASRController::PrimeL()
   1.218 +	{
   1.219 +	//[This function is deprecated and should not have been called]
   1.220 +    Panic(EDeprecatedFunction);
   1.221 +	}
   1.222 +
   1.223 +/**
   1.224 + *  ResetL
   1.225 + *  This method resets the controller
   1.226 + *
   1.227 + */
   1.228 +void CCustomMmfASRController::ResetL()
   1.229 +	{
   1.230 +	//[This function is deprecated and should not have been called]
   1.231 +    Panic(EDeprecatedFunction);
   1.232 +	}
   1.233 +
   1.234 +/**
   1.235 + *
   1.236 + * PlayL
   1.237 + *
   1.238 + */
   1.239 +void CCustomMmfASRController::PlayL()
   1.240 +	{
   1.241 +	//[This function is deprecated and should not have been called]
   1.242 +    Panic(EDeprecatedFunction);
   1.243 +	}
   1.244 +
   1.245 +/**
   1.246 + *  PauseL
   1.247 + *
   1.248 + */
   1.249 +void CCustomMmfASRController::PauseL()
   1.250 +	{
   1.251 +	//[This function is deprecated and should not have been called]
   1.252 +    Panic(EDeprecatedFunction);
   1.253 +	}
   1.254 +
   1.255 +/**
   1.256 + *  StopL
   1.257 + *
   1.258 + */
   1.259 +void CCustomMmfASRController::StopL()
   1.260 +	{
   1.261 +	//[This function is deprecated and should not have been called]
   1.262 +    Panic(EDeprecatedFunction);
   1.263 +	}
   1.264 +
   1.265 +/**
   1.266 + *  PositionL
   1.267 + * Preconditions:
   1.268 + * The Controller is in the state EPrimed
   1.269 + * @return TTimeIntervalMicroSeconds
   1.270 + *
   1.271 + */
   1.272 +TTimeIntervalMicroSeconds CCustomMmfASRController::PositionL() const
   1.273 +	{
   1.274 +	//[This function is deprecated and should not have been called]
   1.275 +    Panic(EDeprecatedFunction);
   1.276 +	TTimeIntervalMicroSeconds position(0);
   1.277 +	return position;
   1.278 +	}
   1.279 +
   1.280 +/**
   1.281 +* SetPositionL
   1.282 +*
   1.283 +* @param aPosition
   1.284 +*
   1.285 +*/
   1.286 +void CCustomMmfASRController::SetPositionL(const TTimeIntervalMicroSeconds& )
   1.287 +	{
   1.288 +	//[This function is deprecated and should not have been called]
   1.289 +    Panic(EDeprecatedFunction);
   1.290 +	}
   1.291 +
   1.292 +/**
   1.293 +*
   1.294 +* MSrAddPronunciationL
   1.295 +* @param aLexiconID
   1.296 +* @param aModelID
   1.297 +* @param aPronunciationID
   1.298 +* Add pronunciation to the lexicon
   1.299 +* @precondition lexicon is loaded
   1.300 +* @precondition lexicon has specified id
   1.301 +* @post condition lexicon has pronunciation
   1.302 +*
   1.303 +*/
   1.304 +void CCustomMmfASRController::MSrAddPronunciationL( TLexiconID aLexiconID, TModelBankID aModelBankID,
   1.305 +							  TModelID aModelID, TPronunciationID& aPronunciationID )
   1.306 +	{
   1.307 +	//[ assert the InVariant ]
   1.308 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));       
   1.309 +
   1.310 +	//[ precondition that are in training mode ]
   1.311 +    __ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
   1.312 +
   1.313 +	//[ add new pronunciation ]
   1.314 +	TInt err = KErrNone;
   1.315 +
   1.316 +	CSDDatabase::TPronunciationData pronunciationData=CSDDatabase::TPronunciationData();
   1.317 +	pronunciationData.iModelBankID = aModelBankID;
   1.318 +	pronunciationData.iModelID = aModelID;
   1.319 +	
   1.320 +	TRAP(err, aPronunciationID = iDatabase->CreatePronunciationL(aLexiconID, pronunciationData));
   1.321 +	
   1.322 +	TMMFEvent addPronunciationComplete( KUidAsrEventAddPronunciation, err );
   1.323 +	SendEventToClient( addPronunciationComplete );
   1.324 +
   1.325 +	// [ assert the Invariant  ]
   1.326 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.327 +
   1.328 +	}
   1.329 +	
   1.330 +	
   1.331 +
   1.332 +void CCustomMmfASRController::MSrSetClientUid( TUid aClientUid)
   1.333 +	{
   1.334 +	//[ assert the InVariant ]
   1.335 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.336 +	
   1.337 +	iDatabase->SetClientUid(aClientUid);
   1.338 +       
   1.339 +	}
   1.340 +
   1.341 +
   1.342 +/**
   1.343 +*
   1.344 +* MSrAddRule
   1.345 +* @param aGrammarID
   1.346 +* @param aLexiconID
   1.347 +* @param aPronunciationID
   1.348 +* @param aRuleID
   1.349 +* @postcondition grammar has rule
   1.350 +*/
   1.351 +void CCustomMmfASRController::MSrAddRuleL( 
   1.352 +				TGrammarID aGrammarID, TLexiconID aLexiconID,
   1.353 +				TPronunciationID aPronunciationID, TRuleID& aRuleID ) 
   1.354 +	{
   1.355 +	//[ assert the InVariant ]
   1.356 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.357 +
   1.358 +	//[ precondition that are in training mode ]
   1.359 +    __ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
   1.360 +  
   1.361 +
   1.362 +	//[ if the grammar has the rule ]
   1.363 +	TInt err = KErrNone;
   1.364 +	CSDDatabase::TRuleData ruleData=CSDDatabase::TRuleData();
   1.365 +	ruleData.iLexiconID = aLexiconID;
   1.366 +	ruleData.iPronunciationID = aPronunciationID;
   1.367 +
   1.368 +	TRAP( err, aRuleID = iDatabase->CreateRuleL( aGrammarID, ruleData));
   1.369 +
   1.370 +
   1.371 +	TMMFEvent event( KUidAsrEventAddRule, err );
   1.372 +	SendEventToClient( event );
   1.373 +
   1.374 +	// [ assert the Invariant  ]
   1.375 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.376 +
   1.377 +	}
   1.378 +
   1.379 +
   1.380 +/**
   1.381 +*
   1.382 +* MSrCancel
   1.383 +*
   1.384 +*/
   1.385 +void CCustomMmfASRController::MSrCancel() 
   1.386 +	{
   1.387 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.388 +	// Send back a test event to the client to indicate this has been called, note this is test controller specific event
   1.389 +	TMMFEvent testCancelEvent( KUidTestASRCancel, KErrNone );
   1.390 +	SendEventToClient( testCancelEvent );
   1.391 +	}
   1.392 +
   1.393 +/**
   1.394 +*
   1.395 +* MSrCommitChangesL
   1.396 +*
   1.397 +*/
   1.398 +void CCustomMmfASRController::MSrCommitChangesL() 
   1.399 +	{
   1.400 +	//[ assert the Invariant ]
   1.401 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.402 +
   1.403 +	iDatabase->CommitChangesL();
   1.404 +
   1.405 +	// [ assert the invariant ]
   1.406 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.407 +	}
   1.408 +
   1.409 +/**
   1.410 +*
   1.411 +* MSrCreateGrammarL
   1.412 +* Creates a Grammar and makes it the currently loaded grammar
   1.413 +* @param aGrammarID
   1.414 +* @precondition State == ESTraining
   1.415 +* @postcondition iAsrSchema has grammar with id aGrammarID
   1.416 +*
   1.417 +*/
   1.418 +void CCustomMmfASRController::MSrCreateGrammarL( TGrammarID& aGrammarID ) 
   1.419 +	{
   1.420 +    //[ assert the Invariant ]
   1.421 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.422 +
   1.423 +	//[ precondition that we are in trainning state ]
   1.424 +	__ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
   1.425 +	
   1.426 +	aGrammarID = iDatabase->CreateGrammarL();
   1.427 +	
   1.428 +	 TMMFEvent event( KUidAsrEventCreateGrammar, KErrNone );
   1.429 +	 SendEventToClient( event );
   1.430 +	
   1.431 +	//[ assert the invariant ]
   1.432 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.433 +	}
   1.434 +
   1.435 +/**
   1.436 +*
   1.437 +* MSrCreateLexiconL
   1.438 +* @param aLexiconID
   1.439 +* Creates a Lexicon with Id aLexiconId
   1.440 +*
   1.441 +*/
   1.442 +void CCustomMmfASRController::MSrCreateLexiconL( TLexiconID& aLexiconID ) 
   1.443 +	{
   1.444 +	//[ assert the Invariant ]
   1.445 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.446 +
   1.447 +	//[ precondition that we are in trainning state ]
   1.448 +	__ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
   1.449 +
   1.450 +	//[ create the Lexicon ]
   1.451 +	aLexiconID = iDatabase->CreateLexiconL();
   1.452 +	
   1.453 +	TMMFEvent event( KUidAsrEventCreateLexicon, KErrNone );
   1.454 +	SendEventToClient( event );
   1.455 +
   1.456 +	//[ assert the invariant ]
   1.457 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.458 +
   1.459 +	}
   1.460 +
   1.461 +/**
   1.462 +*
   1.463 +* MSrCreateModelBankL
   1.464 +* @param aModelBankID
   1.465 +* @precondition state == ESTraining
   1.466 +* @precondition invariant holds
   1.467 +* @postcondition currentModelbank id == modelbank id
   1.468 +* 
   1.469 +*/
   1.470 +void CCustomMmfASRController::MSrCreateModelBankL( TModelBankID& aModelBankID ) 
   1.471 +	{
   1.472 +	//[ assert the Invariant ]
   1.473 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.474 +
   1.475 +	//[ precondition that we are in trainning state ]
   1.476 +	__ASSERT_ALWAYS( State() == ESTraining, Panic(EBadState) );
   1.477 +
   1.478 +	//[ create the new ModelBank]
   1.479 +    TRAPD(err, aModelBankID = iDatabase->CreateModelBankL());
   1.480 +    
   1.481 +   	TMMFEvent event( KUidAsrEventCreateModelBank, err);
   1.482 +	SendEventToClient( event );
   1.483 +
   1.484 +	//[ assert the invariant ]
   1.485 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.486 +	}
   1.487 +
   1.488 +/**
   1.489 +*
   1.490 +* MSrEndRecSessionL
   1.491 +* End a recognition session
   1.492 +* @precondition State is ESRecognition
   1.493 +* @postcondition State is Idle
   1.494 +*/
   1.495 +void CCustomMmfASRController::MSrEndRecSessionL()
   1.496 +	{
   1.497 +	//[ The Invariant must hold ]
   1.498 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.499 +	//[ precondition that the state is recognise ]
   1.500 +	__ASSERT_ALWAYS( State() == ESRecognition, Panic(EBadState) );
   1.501 +	//[ transitionn to Idle state ]
   1.502 +    SetState( ESTraining );
   1.503 +
   1.504 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.505 +	}
   1.506 +
   1.507 +/**
   1.508 +*
   1.509 +* MSrGetAllModelIDsL
   1.510 +* Gets all the model ids in a model bank
   1.511 +* @precondition iModelBank is loaded
   1.512 +* @postcondition model ids are returned
   1.513 +* @postcondition invariant holds
   1.514 +*/
   1.515 +void CCustomMmfASRController::MSrGetAllModelIDsL( TModelBankID aModelBankID, RArray<TModelID>& aModelIDs ) 
   1.516 +	{
   1.517 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.518 +
   1.519 +	TRAPD(err, iDatabase->GetAllModelIDsL(aModelBankID, aModelIDs));
   1.520 +
   1.521 +	TMMFEvent event( KUidAsrEventGetAllModelIDs, err );
   1.522 +	SendEventToClient( event );
   1.523 +
   1.524 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.525 +	}
   1.526 +
   1.527 +/**
   1.528 +*
   1.529 +* MSrGetAllPronunciationIDsL
   1.530 +* @precondition InVariant holds
   1.531 +* @postcondition InVariantHolds
   1.532 +*/
   1.533 +void CCustomMmfASRController::MSrGetAllPronunciationIDsL( TLexiconID aLexiconID, RArray<TPronunciationID>& aPronunciationIDs ) 
   1.534 +	{
   1.535 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.536 +	
   1.537 +	TRAPD(err, iDatabase->GetAllPronunciationIDsL(aLexiconID, aPronunciationIDs));
   1.538 +	
   1.539 +	TMMFEvent event( KUidAsrEventGetAllPronunciationIDs, err );
   1.540 +	SendEventToClient( event );
   1.541 +
   1.542 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.543 +	
   1.544 +	}
   1.545 +
   1.546 +/**
   1.547 +*
   1.548 +* MSrGetAllRuleIDsL
   1.549 +* Get all the rule ids contained in the grammar
   1.550 +* @param aLexiconID
   1.551 +* @param aRuleIDs
   1.552 +* @precondition Invariant holds
   1.553 +* @precondition Lexicon is Loaded
   1.554 +* @postcondition Invariant holds
   1.555 +*/
   1.556 +void CCustomMmfASRController::MSrGetAllRuleIDsL( TLexiconID aLexiconID, RArray<TRuleID>& aRuleIDs ) 
   1.557 +	{
   1.558 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.559 +	
   1.560 +	TRAPD(err, iDatabase->GetAllRuleIDsL(aLexiconID, aRuleIDs));
   1.561 +	
   1.562 +	TMMFEvent event( KUidAsrEventGetAllRuleIDs, err );
   1.563 +	SendEventToClient( event );
   1.564 +	
   1.565 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.566 +	}
   1.567 +	
   1.568 +	
   1.569 +void CCustomMmfASRController::MSrGetAllClientModelBankIDsL(RArray<TModelBankID>& aModelBankIDs ) 
   1.570 +	{
   1.571 +     __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.572 +
   1.573 +	TRAPD(err, iDatabase->GetAllModelBankIDsL(aModelBankIDs,ETrue));
   1.574 +
   1.575 +	TMMFEvent event( KUidAsrEventGetAllClientModelBankIDs, err );
   1.576 +	SendEventToClient( event );
   1.577 +
   1.578 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.579 +	}
   1.580 +
   1.581 +void CCustomMmfASRController::MSrGetAllClientLexiconIDsL(RArray<TLexiconID>& aLexiconIDs ) 
   1.582 +	{
   1.583 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.584 +	
   1.585 +	TRAPD(err, iDatabase->GetAllLexiconIDsL(aLexiconIDs, ETrue));
   1.586 +
   1.587 +	TMMFEvent event( KUidAsrEventGetAllClientLexiconIDs, err );
   1.588 +	SendEventToClient( event );
   1.589 +
   1.590 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.591 +	
   1.592 +	}
   1.593 +
   1.594 +void CCustomMmfASRController::MSrGetAllClientGrammarIDsL(RArray<TGrammarID>& aGrammarIDs ) 
   1.595 +	{
   1.596 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.597 +	
   1.598 +	TRAPD(err, iDatabase->GetAllGrammarIDsL(aGrammarIDs, ETrue));
   1.599 +
   1.600 +	TMMFEvent event( KUidAsrEventGetAllClientGrammarIDs, err );
   1.601 +	SendEventToClient( event );
   1.602 +	
   1.603 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.604 +	}
   1.605 +	
   1.606 +void CCustomMmfASRController::MSrGetAllModelBankIDsL(RArray<TModelBankID>& aModelBankIDs ) 
   1.607 +	{
   1.608 +     __ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.609 +
   1.610 +	TRAPD(err, iDatabase->GetAllModelBankIDsL(aModelBankIDs));
   1.611 +
   1.612 +	TMMFEvent event( KUidAsrEventGetAllModelBankIDs, err );
   1.613 +	SendEventToClient( event );
   1.614 +
   1.615 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.616 +	}
   1.617 +
   1.618 +void CCustomMmfASRController::MSrGetAllLexiconIDsL(RArray<TLexiconID>& aLexiconIDs ) 
   1.619 +	{
   1.620 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.621 +	
   1.622 +	TRAPD(err, iDatabase->GetAllLexiconIDsL(aLexiconIDs));
   1.623 +
   1.624 +	TMMFEvent event( KUidAsrEventGetAllLexiconIDs, err );
   1.625 +	SendEventToClient( event );
   1.626 +
   1.627 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.628 +	
   1.629 +	}
   1.630 +
   1.631 +void CCustomMmfASRController::MSrGetAllGrammarIDsL(RArray<TGrammarID>& aGrammarIDs ) 
   1.632 +	{
   1.633 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.634 +	
   1.635 +	TRAPD(err, iDatabase->GetAllGrammarIDsL(aGrammarIDs));
   1.636 +
   1.637 +	TMMFEvent event( KUidAsrEventGetAllGrammarIDs, err );
   1.638 +	SendEventToClient( event );
   1.639 +	
   1.640 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.641 +	}
   1.642 +
   1.643 +
   1.644 +/**
   1.645 +*
   1.646 +* MSrGetAvailableStorageL
   1.647 +* gets the available storage
   1.648 +* For this simulation the function always returns zero space available
   1.649 +* @parameter aCount
   1.650 +* @precondition Invariant holds
   1.651 +*
   1.652 +*/
   1.653 +void CCustomMmfASRController::MSrGetAvailableStorageL( TInt& aCount ) 
   1.654 +	{
   1.655 +	//[ assert the invariant ]
   1.656 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.657 +	
   1.658 +	//[ for now we will return no space available ]
   1.659 +	aCount = 0;
   1.660 +	
   1.661 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.662 +	}
   1.663 +
   1.664 +/**
   1.665 +*
   1.666 +* MSrGetEnginePropertiesL
   1.667 +* @param aProperties
   1.668 +* @precondition Invariant holds
   1.669 +*
   1.670 +*/
   1.671 +void CCustomMmfASRController::MSrGetEnginePropertiesL( const RArray<TInt>& aPropertyId,
   1.672 +						RArray<TInt>& aPropertyValue ) 
   1.673 +	{
   1.674 +	//[ assert the invariant ]
   1.675 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.676 +
   1.677 +	//[ empty the src array ]
   1.678 +    aPropertyValue.Reset();
   1.679 +
   1.680 +	//[ for all the ids specified ]
   1.681 +    for( TInt count = 0; count < aPropertyId.Count(); count++ )
   1.682 +		{
   1.683 +		//[ we are just faking this for the moment ]
   1.684 +		aPropertyValue.Append( count );
   1.685 +		}
   1.686 +
   1.687 +    //[assert there are properties for all the ids]
   1.688 +	__ASSERT_ALWAYS( aPropertyValue.Count() == aPropertyId.Count(), Panic(EPostConditionViolation) );
   1.689 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.690 +	}
   1.691 +
   1.692 +/**
   1.693 +*
   1.694 +* MSrLoadEngineParametersL
   1.695 +*
   1.696 +*/
   1.697 +void CCustomMmfASRController::MSrLoadEngineParametersL( const RArray<TInt>& aParameterId, 
   1.698 +						const RArray<TInt>& aParameterValue )
   1.699 +	{
   1.700 +	TBool pass = ETrue;
   1.701 +	if (aParameterId.Count()!=KNumParameters ||
   1.702 +		aParameterValue.Count()!=KNumParameters)
   1.703 +		pass = EFalse;
   1.704 +	else 
   1.705 +		{
   1.706 +		TInt i;
   1.707 +		for (i=0;i<aParameterId.Count() && pass;i++)
   1.708 +			if (aParameterId[i]!=KParameterIDs[i])
   1.709 +				pass = EFalse;
   1.710 +				
   1.711 +		for (i=0;i<aParameterValue.Count() && pass;i++)
   1.712 +			if (aParameterValue[i]!=KParameterValues[i])
   1.713 +				pass = EFalse;
   1.714 +				
   1.715 +	
   1.716 +		}
   1.717 +	if (pass)
   1.718 +		{
   1.719 +		TMMFEvent event( KUidTestASRLoadParameters, KErrNone );
   1.720 +		SendEventToClient(event);					
   1.721 +		}
   1.722 +	else
   1.723 +		{
   1.724 +		TMMFEvent event( KUidTestASRLoadParameters, KErrArgument );
   1.725 +		SendEventToClient(event);					
   1.726 +		}
   1.727 +	}
   1.728 +
   1.729 +/**
   1.730 +*
   1.731 +* MSrGetModelCountL
   1.732 +* @param aModelBankID
   1.733 +* @param aCount
   1.734 +* @precondition Invariant holds
   1.735 +* @precondition model is loaded
   1.736 +* @postcondition Invariant holds
   1.737 +* @postcondition modelcount >=0
   1.738 +*/
   1.739 +void CCustomMmfASRController::MSrGetModelCountL( TModelBankID aModelBankID, TInt& aCount ) 
   1.740 +	{
   1.741 +	//[ assert the invariant ]
   1.742 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.743 +
   1.744 +	RArray<TPronunciationID> ids;
   1.745 +	CleanupClosePushL(ids);
   1.746 +	TRAPD(err, iDatabase->GetAllModelIDsL(aModelBankID,ids));
   1.747 +	
   1.748 +	if (err==KErrNone)
   1.749 +		aCount = ids.Count();
   1.750 +		
   1.751 +	CleanupStack::PopAndDestroy(&ids);
   1.752 +	
   1.753 +	TMMFEvent event( KUidAsrEventGetModelCount, err );
   1.754 +	SendEventToClient( event );
   1.755 +
   1.756 +
   1.757 +	//[ assert the invariant ]
   1.758 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.759 +	}
   1.760 +
   1.761 +
   1.762 +
   1.763 +/**
   1.764 +*
   1.765 +* MSrGetRuleValidityL
   1.766 +* @param aGrammarID
   1.767 +* @param aRuleID
   1.768 +* @param aValid
   1.769 +* @precondition InVariantHolds
   1.770 +* @precondition state is training or state is recognition
   1.771 +* @precondition grammar is loaded
   1.772 +* @postcondition InVariantHolds
   1.773 +*/
   1.774 +void CCustomMmfASRController::MSrGetRuleValidityL( TGrammarID aGrammarID, TRuleID aRuleID, TBool& aValid ) 
   1.775 +	{
   1.776 +	//[ assert the invariant ]
   1.777 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.778 +	//[ precondition the schema exists ]
   1.779 +
   1.780 +	CSDDatabase::RSDRuleTable ruleTable(*iDatabase);
   1.781 +	CleanupClosePushL(ruleTable);
   1.782 +	ruleTable.OpenL(aGrammarID);
   1.783 +	TRAPD(err, aValid = ruleTable.IsRuleValidL(aRuleID));
   1.784 +	CleanupStack::PopAndDestroy(&ruleTable);
   1.785 +
   1.786 +   	TMMFEvent event( KUidAsrEventGetRuleValidity, err );
   1.787 +	SendEventToClient( event );
   1.788 +
   1.789 +	//[ assert the invariant ]
   1.790 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.791 +	}
   1.792 +
   1.793 +/**
   1.794 +*
   1.795 +* MSrGetUtteranceDurationL
   1.796 +* @param aModelBankID
   1.797 +* @param aModelID
   1.798 +* @param aDuration
   1.799 +* @param aFromMemory
   1.800 +* 
   1.801 +*/
   1.802 +void CCustomMmfASRController::MSrGetUtteranceDurationL( TModelBankID aModelBankID, TModelID aModelID,
   1.803 +								   TTimeIntervalMicroSeconds32& aDuration) 
   1.804 +	{
   1.805 +    //[ assert the Invariant ]
   1.806 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
   1.807 +
   1.808 +	CSDDatabase::TModelData modelData = CSDDatabase::TModelData();
   1.809 +
   1.810 +	TInt err;
   1.811 +	TRAP(err, iDatabase->GetModelDataL(aModelBankID, aModelID, modelData));
   1.812 +	if (err==KErrNone)
   1.813 +		{
   1.814 +		aDuration = modelData.iUtteranceDurationMicroSeconds;
   1.815 +		}
   1.816 +
   1.817 +	TMMFEvent event( KUidAsrEventGetUtteranceDuration, err );
   1.818 +	SendEventToClient( event );
   1.819 +
   1.820 +
   1.821 +	//[ assert the Invariant ]
   1.822 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   1.823 +	}
   1.824 +
   1.825 +/**
   1.826 +*
   1.827 +* MSrLoadGrammarL
   1.828 +* @param aGrammarID
   1.829 +* @precondition aGrammarId is supported by the test controller
   1.830 +* @postcondition aGrammarId == id of loaded grammar
   1.831 +*/
   1.832 +void CCustomMmfASRController::MSrLoadGrammarL( TGrammarID aGrammarID ) 
   1.833 +	{
   1.834 +	//[ assert the Invariant ]
   1.835 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   1.836 +
   1.837 +	//[ must be in trainning or recognition state ]
   1.838 +	__ASSERT_ALWAYS( (State() == ESRecognition ) || ( State() == ESTraining ), Panic(EBadState) );
   1.839 +
   1.840 +	TInt err = KErrNone;	
   1.841 +	if (iDatabase->GrammarExistsL(aGrammarID))
   1.842 +		{
   1.843 +		iLoadedGrammarID = aGrammarID;
   1.844 +		}
   1.845 +	else
   1.846 +		err = KErrNotFound;
   1.847 +		
   1.848 +	TMMFEvent event( KUidAsrEventLoadGrammar, err );
   1.849 +	SendEventToClient( event );
   1.850 +
   1.851 +	//[ assert the Invariant ]
   1.852 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   1.853 +	}
   1.854 +
   1.855 +/**
   1.856 +*
   1.857 +* MSrLoadLexiconL
   1.858 +* @param aLexiconID
   1.859 +* @precondition Invariant Holds
   1.860 +* @precondition state is Training or Recognition
   1.861 +* @precondition controller supports the lexicon
   1.862 +* @postcondition iLexicon has id aLexiconId
   1.863 +* @psotcondition InVariant holds
   1.864 +*/
   1.865 +void CCustomMmfASRController::MSrLoadLexiconL( TLexiconID aLexiconID ) 
   1.866 +	{
   1.867 +	//[ assert the Invariant ]
   1.868 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   1.869 +
   1.870 +	//[ must be in trainning or recognition state ]
   1.871 +	__ASSERT_ALWAYS( (State() == ESRecognition ) || ( State() == ESTraining ), Panic(EBadState));
   1.872 +
   1.873 +	TInt err = KErrNone;
   1.874 +	if (iDatabase->LexiconExistsL(aLexiconID))
   1.875 +		{
   1.876 +		iLoadedLexiconID = aLexiconID;
   1.877 +		}
   1.878 +	else
   1.879 +		err = KErrNotFound;
   1.880 +
   1.881 +	TMMFEvent event( KUidAsrEventLoadLexicon, err );
   1.882 +	SendEventToClient( event );
   1.883 +
   1.884 +	//[ assert the Invariant ]
   1.885 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   1.886 +	}
   1.887 +
   1.888 +/**
   1.889 +*
   1.890 +* MSrLoadModelsL
   1.891 +* @param aModelBankID
   1.892 +* @precondition InVariant holds
   1.893 +* @precondition state is training or recognition
   1.894 +* @precondition model bank is is supported by the controller
   1.895 +* @postcondition modelbank id is equal to aModelBankId
   1.896 +* @postcondition InVariant holds
   1.897 +*/
   1.898 +void CCustomMmfASRController::MSrLoadModelsL( TModelBankID aModelBankID ) 
   1.899 +	{
   1.900 +	//[ assert the Invariant ]
   1.901 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   1.902 +
   1.903 +	//[ must be in trainning or recognition state ]
   1.904 +	__ASSERT_ALWAYS( (State() == ESRecognition ) || ( State() == ESTraining ), Panic(EBadState));
   1.905 +
   1.906 +	TInt err = KErrNone;
   1.907 +	if (iDatabase->ModelBankExistsL(aModelBankID))
   1.908 +		{
   1.909 +		iLoadedModelBankID = aModelBankID;
   1.910 +		}
   1.911 +	else
   1.912 +		err = KErrNotFound;
   1.913 +
   1.914 +	TMMFEvent event( KUidAsrEventLoadModels, err );
   1.915 +	SendEventToClient( event );
   1.916 +
   1.917 +	//[ assert the Invariant ]
   1.918 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   1.919 +
   1.920 +	}
   1.921 +
   1.922 +/**
   1.923 +*
   1.924 +* MSrPlayUtteranceL
   1.925 +* @param aModelBankID 
   1.926 +* @param aModelID
   1.927 +* @param aPlayFromMemory
   1.928 +* Always plays froms memory
   1.929 +*/
   1.930 +void CCustomMmfASRController::MSrPlayUtteranceL( TModelBankID aModelBankID, TModelID aModelID ) 
   1.931 +	{
   1.932 +	//[ assert the InVariant ]
   1.933 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   1.934 +
   1.935 +	if (!iDatabase->ModelExistsL(aModelBankID, aModelID))
   1.936 +		{
   1.937 +		User::Leave(KErrNotFound);
   1.938 +		}
   1.939 +	else
   1.940 +		{
   1.941 +		TMMFEvent aPlayStarted( KUidAsrEventPlayStarted, KErrNone );
   1.942 +		SendEventToClient( aPlayStarted );
   1.943 +		
   1.944 +		TMMFEvent aPlayComplete( KUidAsrEventPlay, KErrNone );
   1.945 +		SendEventToClient( aPlayComplete );
   1.946 +		}
   1.947 +
   1.948 +	//[ assert the InVariant ]
   1.949 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   1.950 +	}
   1.951 +
   1.952 +/**
   1.953 +*
   1.954 +* MSrRecognizeL
   1.955 +* @param aResultSet
   1.956 +*
   1.957 +*/
   1.958 +void CCustomMmfASRController::MSrRecognizeL( CSDClientResultSet& aResultSet ) 
   1.959 +	{
   1.960 +	//[ assert the Invariant ]
   1.961 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   1.962 +
   1.963 +	//[ Precondition that we are in a recognition session ]
   1.964 +	if( State() != ESRecognition )
   1.965 +		{
   1.966 +		TMMFEvent recognitionFailed( KUidAsrEventRecognition, KErrNotReady );
   1.967 +		SendEventToClient( recognitionFailed );
   1.968 +		return;
   1.969 +		}
   1.970 +
   1.971 +	TMMFEvent recognitionReady( KUidAsrEventRecognitionReady,KErrNone );
   1.972 +	SendEventToClient( recognitionReady );
   1.973 +
   1.974 +	//[ return a result set ]
   1.975 +	iMaxResults = aResultSet.MaxResults();
   1.976 +    iResultSet = &aResultSet;
   1.977 +
   1.978 +    iRecognizeComplete = ETrue;
   1.979 +	
   1.980 +	//[ assert the Invariant ]
   1.981 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   1.982 +	}
   1.983 +
   1.984 +/*
   1.985 +*
   1.986 +* MSrRecordL
   1.987 +* @param aRecordTime
   1.988 +* @precondition InVariant holds
   1.989 +* @postcondition 
   1.990 +*/
   1.991 +void CCustomMmfASRController::MSrRecordL( TTimeIntervalMicroSeconds32 aRecordTime ) 
   1.992 +	{
   1.993 +	//[ assert the invariant ]
   1.994 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
   1.995 +	
   1.996 +	//[ remember the record time 
   1.997 +	// and for the purpose of simulation recording takes zero time ]
   1.998 +	iRecordTime = aRecordTime ;
   1.999 +
  1.1000 +	TMMFEvent aRecordStartedEvent( KUidAsrEventRecordStarted, KErrNone );
  1.1001 +	SendEventToClient( aRecordStartedEvent );
  1.1002 +
  1.1003 +	TMMFEvent aEndOfUtteranceEvent( KUidAsrEventEouDetected, KErrNone );
  1.1004 +	SendEventToClient( aEndOfUtteranceEvent );
  1.1005 +
  1.1006 +	if( iRecognizeComplete )
  1.1007 +		{
  1.1008 +		iRecognizeComplete = EFalse;
  1.1009 +		
  1.1010 +		for (TInt i=0;i<iMaxResults && i<KMaxAvailableResults;i++)
  1.1011 +		{
  1.1012 +			CSDClientResult& result = CONST_CAST(CSDClientResult&, iResultSet->At(i));
  1.1013 +			result.SetGrammarID(KResultsGrammarID[i]);
  1.1014 +			result.SetRuleID(KResultsRuleID[i]);
  1.1015 +		}
  1.1016 +		
  1.1017 +		TMMFEvent recognitionComplete( KUidAsrEventRecognition, KErrNone );
  1.1018 +		SendEventToClient( recognitionComplete );
  1.1019 +		}
  1.1020 +
  1.1021 + 	//[ assert the invaraint ]
  1.1022 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1023 +	}
  1.1024 +
  1.1025 +/**
  1.1026 +*
  1.1027 +* MSrRemoveGrammarL
  1.1028 +* Interpreted as unload from memory here 
  1.1029 +*
  1.1030 +*/
  1.1031 +void CCustomMmfASRController::MSrRemoveGrammarL( TGrammarID aGrammarID ) 
  1.1032 +	{
  1.1033 +	//[ assert the invaraint ]
  1.1034 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));
  1.1035 +    
  1.1036 +
  1.1037 +	if (iLoadedGrammarID == aGrammarID)
  1.1038 +		{
  1.1039 +		TMMFEvent event( KUidAsrEventRemoveGrammar, KErrInUse );
  1.1040 +		SendEventToClient( event );
  1.1041 +		}		
  1.1042 +	else
  1.1043 +		{		
  1.1044 +		TRAPD(err, iDatabase->RemoveGrammarL(aGrammarID));
  1.1045 +		//[ send message to client of success ]
  1.1046 +		TMMFEvent event( KUidAsrEventRemoveGrammar, err );
  1.1047 +		SendEventToClient( event );
  1.1048 +		}
  1.1049 +
  1.1050 +	//[ assert the invaraint ]
  1.1051 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1052 +	}
  1.1053 +
  1.1054 +/**
  1.1055 +*
  1.1056 +* MSrRemoveLexiconL
  1.1057 +* @param aLexiconID
  1.1058 +* slightly different interpretation here 
  1.1059 +*/
  1.1060 +void CCustomMmfASRController::MSrRemoveLexiconL( TLexiconID aLexiconID ) 
  1.1061 +	{
  1.1062 +    //[ assert the invaraint ]
  1.1063 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1064 +
  1.1065 +
  1.1066 +	if (iLoadedLexiconID == aLexiconID)
  1.1067 +		{
  1.1068 +		TMMFEvent event( KUidAsrEventRemoveLexicon, KErrInUse );
  1.1069 +		SendEventToClient( event );
  1.1070 +		}		
  1.1071 +	else
  1.1072 +		{		
  1.1073 +		TRAPD(err, iDatabase->RemoveLexiconL(aLexiconID));
  1.1074 +		//[ send message to client of success ]
  1.1075 +		TMMFEvent event( KUidAsrEventRemoveLexicon, err );
  1.1076 +		SendEventToClient( event );
  1.1077 +		}
  1.1078 +	
  1.1079 +	//[ assert the invaraint ]
  1.1080 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1081 +	
  1.1082 +
  1.1083 +	}
  1.1084 +
  1.1085 +/**
  1.1086 +*
  1.1087 +* MSrRemoveModelBankL
  1.1088 +*
  1.1089 +*
  1.1090 +*/
  1.1091 +void CCustomMmfASRController::MSrRemoveModelBankL( TModelBankID aModelBankID )
  1.1092 +	{
  1.1093 +    //[ assert the invaraint ]
  1.1094 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1095 +
  1.1096 +
  1.1097 +	if (iLoadedModelBankID == aModelBankID)
  1.1098 +		{
  1.1099 +		TMMFEvent event( KUidAsrEventRemoveModelBank, KErrInUse );
  1.1100 +		SendEventToClient( event );
  1.1101 +		}		
  1.1102 +	else
  1.1103 +		{		
  1.1104 +		TRAPD(err, iDatabase->RemoveModelBankL(aModelBankID));
  1.1105 +		//[ send message to client of success ]
  1.1106 +		TMMFEvent event( KUidAsrEventRemoveModelBank, err );
  1.1107 +		SendEventToClient( event );
  1.1108 +		}
  1.1109 +	
  1.1110 +	//[ assert the invaraint ]
  1.1111 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1112 +
  1.1113 +	}
  1.1114 +
  1.1115 +/**
  1.1116 +*
  1.1117 +* MSrRemoveModelL
  1.1118 +* @param aModelBankID
  1.1119 +* @param aModeID
  1.1120 +* @precondition InVariant holds
  1.1121 +* @precondition model bank exists
  1.1122 +* @precondition modelbank contains the model
  1.1123 +* @postcondition model bank does not contain model
  1.1124 +*
  1.1125 +*/
  1.1126 +void CCustomMmfASRController::MSrRemoveModelL( TModelBankID aModelBankID, TModelID aModelID )
  1.1127 +	{
  1.1128 +	//[ assert the invariant ]
  1.1129 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1130 +	
  1.1131 +	if (iLoadedModelBankID == aModelBankID)
  1.1132 +		{
  1.1133 +		TMMFEvent event( KUidAsrEventRemoveModelBank, KErrInUse );
  1.1134 +		SendEventToClient( event );
  1.1135 +		}		
  1.1136 +	else
  1.1137 +		{	
  1.1138 +		TInt err = KErrNone;
  1.1139 +		if (!iDatabase->ModelBankExistsL(aModelBankID))
  1.1140 +			err = KErrNotFound;
  1.1141 +		else 
  1.1142 +			{
  1.1143 +			CSDDatabase::RSDModelTable view(*iDatabase);
  1.1144 +			CleanupClosePushL(view);
  1.1145 +			view.OpenL(aModelBankID);
  1.1146 +			if (view.FindModelL(aModelID))
  1.1147 +				{
  1.1148 +				view.RemoveModelL(aModelID);
  1.1149 +				}
  1.1150 +			else
  1.1151 +				err = KErrNotFound;
  1.1152 +				
  1.1153 +			CleanupStack::PopAndDestroy(&view);
  1.1154 +			}
  1.1155 +		//[ send message to client of success ]
  1.1156 +		TMMFEvent event( KUidAsrEventRemoveModel, err );
  1.1157 +		SendEventToClient( event );
  1.1158 +		}
  1.1159 +	
  1.1160 +	//[ assert the invaraint ]
  1.1161 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1162 +	}
  1.1163 +
  1.1164 +/**
  1.1165 +*
  1.1166 +* MSrRemovePronunciationL
  1.1167 +* @param aLexiconID
  1.1168 +* @param aPronunciationID
  1.1169 +* @precondition lexicon exists
  1.1170 +* @precondition lexicon has id specified
  1.1171 +* @postconfition lexicon does not have pronunication
  1.1172 +*
  1.1173 +*/
  1.1174 +void CCustomMmfASRController::MSrRemovePronunciationL( TLexiconID aLexiconID, TPronunciationID aPronunciationID )
  1.1175 +	{
  1.1176 +   	//[ assert the invaraint ]
  1.1177 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1178 +	
  1.1179 +	if (iLoadedLexiconID == aLexiconID)
  1.1180 +		{
  1.1181 +		TMMFEvent event( KUidAsrEventRemovePronunciation, KErrInUse );
  1.1182 +		SendEventToClient( event );
  1.1183 +		}		
  1.1184 +	else
  1.1185 +		{	
  1.1186 +		TInt err = KErrNone;
  1.1187 +		if (!iDatabase->LexiconExistsL(aLexiconID))
  1.1188 +			err = KErrNotFound;
  1.1189 +		else 
  1.1190 +			{
  1.1191 +			CSDDatabase::RSDPronunciationTable view(*iDatabase);
  1.1192 +			CleanupClosePushL(view);
  1.1193 +			view.OpenL(aLexiconID);
  1.1194 +			if (view.FindPronunciationL(aPronunciationID))
  1.1195 +				{
  1.1196 +				view.RemovePronunciationL(aPronunciationID);
  1.1197 +				}
  1.1198 +			else
  1.1199 +				err = KErrNotFound;
  1.1200 +				
  1.1201 +			CleanupStack::PopAndDestroy(&view);
  1.1202 +			}
  1.1203 +		//[ send message to client of success ]
  1.1204 +		TMMFEvent event( KUidAsrEventRemovePronunciation, err );
  1.1205 +		SendEventToClient( event );
  1.1206 +		}
  1.1207 +	
  1.1208 +	//[ assert the invaraint ]
  1.1209 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1210 +	}
  1.1211 +
  1.1212 +/**
  1.1213 +*
  1.1214 +* MSrRemoveRuleL
  1.1215 +* @param aLexiconID
  1.1216 +* @param aRuleID
  1.1217 +* @precondition InVariant holds
  1.1218 +* @precondition grammar is loaded
  1.1219 +* @precondition grammar has id specified
  1.1220 +* @postcondition grammar does not contain rule
  1.1221 +*
  1.1222 +*/
  1.1223 +void CCustomMmfASRController::MSrRemoveRuleL( TGrammarID aGrammarID, TRuleID aRuleID )
  1.1224 +	{
  1.1225 +	//[ assert the invaraint ]
  1.1226 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1227 +	
  1.1228 +	if (iLoadedGrammarID == aGrammarID)
  1.1229 +		{
  1.1230 +		TMMFEvent event( KUidAsrEventRemoveRule, KErrInUse );
  1.1231 +		SendEventToClient( event );
  1.1232 +		}		
  1.1233 +	else
  1.1234 +		{		
  1.1235 +		TInt err = KErrNone;
  1.1236 +		if (!iDatabase->GrammarExistsL(aGrammarID))
  1.1237 +			err = KErrNotFound;
  1.1238 +		else 
  1.1239 +			{
  1.1240 +			CSDDatabase::RSDRuleTable view(*iDatabase);
  1.1241 +			CleanupClosePushL(view);
  1.1242 +			view.OpenL(aGrammarID);
  1.1243 +			if (view.FindRuleL(aRuleID))
  1.1244 +				{
  1.1245 +				view.RemoveRuleL(aRuleID);
  1.1246 +				}
  1.1247 +			else
  1.1248 +				err = KErrNotFound;
  1.1249 +				
  1.1250 +			CleanupStack::PopAndDestroy(&view);
  1.1251 +			}
  1.1252 +		//[ send message to client of success ]
  1.1253 +		TMMFEvent event( KUidAsrEventRemoveRule, err );
  1.1254 +		SendEventToClient( event );
  1.1255 +		}
  1.1256 +	
  1.1257 +	//[ assert the invaraint ]
  1.1258 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1259 +	}
  1.1260 +
  1.1261 +/**
  1.1262 +*
  1.1263 +* MSrStartRecSessionL
  1.1264 +* @param aMode
  1.1265 +* @precondition mode is valid
  1.1266 +*
  1.1267 +*/
  1.1268 +void CCustomMmfASRController::MSrStartRecSessionL( TRecognitionMode aMode )
  1.1269 +	{
  1.1270 +	//[ assert the invariant holds ]
  1.1271 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1272 +
  1.1273 +	//[ precondition the mode is valid ]
  1.1274 +	if( (aMode < ESdMode ) || ( aMode > ESdSiMode) )
  1.1275 +		{
  1.1276 +		User::Leave( KErrArgument );
  1.1277 +		}
  1.1278 +
  1.1279 +	//[ it does not matter which state we are in we can
  1.1280 +	// always transition to recognition ]
  1.1281 +	SetState( ESRecognition );
  1.1282 +
  1.1283 +	//[ set the recognition mode ]
  1.1284 +	iRecognitionMode = aMode ;
  1.1285 +
  1.1286 +	//[ assert the Invariant holds ]
  1.1287 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1288 +
  1.1289 +	//[ assert the post condition that the mode has been en
  1.1290 +	__ASSERT_ALWAYS( iRecognitionMode == aMode, Panic(EPostConditionViolation) );
  1.1291 +	}
  1.1292 +
  1.1293 +/**
  1.1294 +*
  1.1295 +* MSrTrainL
  1.1296 +* @param aModelBankID
  1.1297 +* @param aModelID
  1.1298 +*
  1.1299 +*/
  1.1300 +void CCustomMmfASRController::MSrTrainL( TModelBankID aModelBankID, TModelID& aModelID )
  1.1301 +	{
  1.1302 +	// fixed duration to return for training
  1.1303 +	const TInt KUtteranceDuration = 2000;
  1.1304 +     //[ must be in training mode
  1.1305 +	//   must have a lexicon that is not empty 
  1.1306 +	//   must have a grammar
  1.1307 +	//   must have a model bank loaded ]
  1.1308 +	//[ presume train adds a new model id to the bank ]
  1.1309 +	//[ finally send event to client ]
  1.1310 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1311 +	TMMFEvent event( KUidAsrEventTrainReady, KErrNone );
  1.1312 +	SendEventToClient( event );
  1.1313 +
  1.1314 +	// [ precondition model bank is loaded ]
  1.1315 +	if( iLoadedModelBankID != aModelBankID )
  1.1316 +		 {
  1.1317 +	 	 TMMFEvent event( KUidAsrEventTrain, KErrNotReady );
  1.1318 +		 SendEventToClient( event );
  1.1319 +		 return;
  1.1320 +		 }
  1.1321 +
  1.1322 +	TInt err = KErrNone;
  1.1323 +	
  1.1324 +	CSDDatabase::TModelData modelData=CSDDatabase::TModelData();
  1.1325 +	modelData.iUtteranceDurationMicroSeconds = KUtteranceDuration;
  1.1326 +	TRAP(err, aModelID = iDatabase->CreateModelL( aModelBankID, modelData));
  1.1327 +
  1.1328 +	TMMFEvent trainCompleteEvent( KUidAsrEventTrain, err );
  1.1329 +	SendEventToClient( trainCompleteEvent );
  1.1330 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1331 +	}
  1.1332 +
  1.1333 +/**
  1.1334 +*
  1.1335 +* MSrUnloadRuleL
  1.1336 +* @param aGrammarID
  1.1337 +* @param aRuleID
  1.1338 +* @precondition state == ESTraining
  1.1339 +* @postcondition grammar does not contain rule
  1.1340 +*
  1.1341 +*/
  1.1342 +void CCustomMmfASRController::MSrUnloadRuleL( TGrammarID aGrammarID, TRuleID aRuleID )
  1.1343 +	{
  1.1344 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1345 +
  1.1346 +	//[ precondition grammar loaded is grammar with id ]
  1.1347 +	__ASSERT_ALWAYS( iLoadedGrammarID == aGrammarID, Panic(EPreConditionViolation) );
  1.1348 +
  1.1349 +	TBool ruleExists = EFalse;
  1.1350 +
  1.1351 +	TRAPD(err, ruleExists = iDatabase->RuleExistsL(aGrammarID, aRuleID));
  1.1352 +
  1.1353 +	if (err == KErrNone)
  1.1354 +		{
  1.1355 +		if (!ruleExists)
  1.1356 +			err = KErrNotFound;
  1.1357 +		}
  1.1358 +
  1.1359 +	//[ send message to client of success ]
  1.1360 +	TMMFEvent event( KUidAsrEventUnloadRule, err );
  1.1361 +	SendEventToClient( event );
  1.1362 +
  1.1363 +	__ASSERT_ALWAYS(InVariant(),Panic(EBadInvariant));;
  1.1364 +	}
  1.1365 +	
  1.1366 +/**
  1.1367 + *  SendEventToClient
  1.1368 + *
  1.1369 + *	@param aEvent
  1.1370 + */
  1.1371 +TInt CCustomMmfASRController::SendEventToClient(const TMMFEvent& aEvent)
  1.1372 +	{
  1.1373 +	//now send event to client...
  1.1374 +	return DoSendEventToClient(aEvent);
  1.1375 +	}
  1.1376 +
  1.1377 +/**
  1.1378 +*
  1.1379 +* GetNumberOfMetaDataEntriesL
  1.1380 +*
  1.1381 +* @param "TInt"
  1.1382 +*
  1.1383 +*/
  1.1384 +void CCustomMmfASRController::GetNumberOfMetaDataEntriesL(TInt& /*aNumberOfEntries*/ ) 
  1.1385 +	{
  1.1386 +	 //[This function is deprecated and should not have been called]
  1.1387 +     Panic(EDeprecatedFunction);
  1.1388 +	}
  1.1389 +
  1.1390 +/**
  1.1391 +* GetMetaDataEntryL
  1.1392 +* @param aIndex
  1.1393 +* @returns "CMMFMetaDataEntry*"
  1.1394 +*/
  1.1395 +CMMFMetaDataEntry* CCustomMmfASRController::GetMetaDataEntryL(TInt /*aIndex*/ ) 
  1.1396 +	{
  1.1397 +	//[This function is deprecated and should not have been called]
  1.1398 +    Panic(EDeprecatedFunction);
  1.1399 +	return NULL;
  1.1400 +	}
  1.1401 +
  1.1402 +/**
  1.1403 +* RemoveDataSourceL
  1.1404 +* @param aDataSource
  1.1405 +* 
  1.1406 +*/
  1.1407 +void CCustomMmfASRController::RemoveDataSourceL(MDataSource& /*aDataSource*/ )
  1.1408 +	{
  1.1409 +	//[This function is deprecated and should not have been called]
  1.1410 +    Panic(EDeprecatedFunction);
  1.1411 +	}
  1.1412 +
  1.1413 +/**
  1.1414 +* RemoveDataSinkL
  1.1415 +* 
  1.1416 +* @param aDataSink
  1.1417 +*
  1.1418 +*/
  1.1419 +void CCustomMmfASRController::RemoveDataSinkL(MDataSink& /*aDataSink*/ )
  1.1420 +	{
  1.1421 +	 //[This function is deprecated and should not have been called]
  1.1422 +     Panic(EDeprecatedFunction);
  1.1423 +	}
  1.1424 +
  1.1425 +/**
  1.1426 + *  SetPrioritySettings
  1.1427 + *
  1.1428 + *	@param aPrioritySettings
  1.1429 + */
  1.1430 +void CCustomMmfASRController::SetPrioritySettings(const TMMFPrioritySettings& /*aPrioritySettings*/)
  1.1431 +	{
  1.1432 +	}
  1.1433 +
  1.1434 +/**
  1.1435 +*
  1.1436 +* DurationL
  1.1437 +*
  1.1438 +* @returns TTimeIntervalMicroSeconds 
  1.1439 +*
  1.1440 +*/
  1.1441 +TTimeIntervalMicroSeconds CCustomMmfASRController::DurationL() const
  1.1442 +	{
  1.1443 +	TTimeIntervalMicroSeconds xx(0);
  1.1444 +	return xx; 
  1.1445 +	}
  1.1446 +
  1.1447 +/**
  1.1448 +*
  1.1449 +* InVariant
  1.1450 +* @returns TBool
  1.1451 +*
  1.1452 +*/
  1.1453 +TBool CCustomMmfASRController::InVariant() const
  1.1454 +	{
  1.1455 +	 TBool status = EFalse;
  1.1456 +	 //[ for now the invariant is simply that we have a valid state ]
  1.1457 +	 if( (iState == ESTraining ) || ( iState == ESTraining ) || ( iState == ESRecognition ) )
  1.1458 +		 {
  1.1459 +		 status = ETrue;
  1.1460 +		 }
  1.1461 +	 
  1.1462 +	 return status;
  1.1463 +	}
  1.1464 +
  1.1465 +/**
  1.1466 +*
  1.1467 +* State
  1.1468 +* @returns TControllerState
  1.1469 +*
  1.1470 +*/
  1.1471 +CCustomMmfASRController::TControllerState CCustomMmfASRController::State() const
  1.1472 +	{
  1.1473 +	return iState;	
  1.1474 +	}