mmdevicefw/speechrecogsupport/ASR/src/SpeechRecognitionUtilityBody.cpp
changeset 0 b8ed18f6c07b
equal deleted inserted replaced
-1:000000000000 0:b8ed18f6c07b
       
     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 // SpeechRecognitionUtility.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32base.h>
       
    19 #include <mmf/common/mmfcontroller.h>
       
    20 #include <mmf/common/speechrecognitioncustomcommands.h>
       
    21 #include <mmf/common/speechrecognitiondatacommon.h>
       
    22 
       
    23 #include <speechrecognitionutility.h>
       
    24 #include "SpeechRecognitionUtilityBody.h"
       
    25 
       
    26 //_LIT(KMMFSpeechRecognitionUtilityPanic,"Speech Recognition Utility Bad State");
       
    27 enum ASRPanics 
       
    28 	{
       
    29 	KMMFSpeechRecognitionUtilityPanicBadState,
       
    30 	KMMFSpeechRecognitionUtilityPanicUnrecognisedEvent
       
    31 	};
       
    32 
       
    33 CSpeechRecognitionUtility::CBody* CSpeechRecognitionUtility::CBody::NewL( TUid aClientUid, MSpeechRecognitionUtilityObserver& aSpeechRecognitionUtilityObserver)
       
    34 	{
       
    35 	CSpeechRecognitionUtility::CBody* self = CSpeechRecognitionUtility::CBody::NewLC(aClientUid, aSpeechRecognitionUtilityObserver);
       
    36 	CleanupStack::Pop(self);
       
    37 	return self;
       
    38 	}
       
    39 	
       
    40 CSpeechRecognitionUtility::CBody* CSpeechRecognitionUtility::CBody::NewLC(TUid aClientUid, MSpeechRecognitionUtilityObserver& aSpeechRecognitionUtilityObserver)
       
    41 	{
       
    42 	CSpeechRecognitionUtility::CBody* self = new(ELeave) CSpeechRecognitionUtility::CBody(aClientUid, aSpeechRecognitionUtilityObserver);
       
    43 	CleanupStack::PushL(self);
       
    44 	self->ConstructL();
       
    45 	return self;
       
    46 	}
       
    47 	
       
    48 void CSpeechRecognitionUtility::CBody::ConstructL()
       
    49 	{
       
    50 	iAudioPriority = EMdaPriorityNormal;
       
    51 	iTrainPreference = EMdaPriorityPreferenceNone;
       
    52 	iRecognitionPreference = EMdaPriorityPreferenceNone;
       
    53 	iPlaybackPreference = EMdaPriorityPreferenceNone;
       
    54 	
       
    55 	iPrioritySettings.iPriority = iAudioPriority; 
       
    56 	iPrioritySettings.iPref = iTrainPreference;
       
    57 
       
    58 	iControllerEventMonitor = CMMFControllerEventMonitor::NewL(*this, iMMFController);
       
    59 	
       
    60 	RMMFControllerImplInfoArray controllers;
       
    61 	CleanupResetAndDestroyPushL(controllers);
       
    62 
       
    63 	CMMFControllerPluginSelectionParameters* cSelect = CMMFControllerPluginSelectionParameters::NewLC();
       
    64 
       
    65 	// Select the media IDs to allow
       
    66 	RArray<TUid> mediaIds;
       
    67 	CleanupClosePushL(mediaIds);
       
    68 	User::LeaveIfError(mediaIds.Append(KUidMediaTypeASR));
       
    69 	cSelect->SetMediaIdsL(mediaIds,CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds);
       
    70 	CleanupStack::PopAndDestroy(&mediaIds);
       
    71 
       
    72 	cSelect->ListImplementationsL(controllers);	
       
    73 	
       
    74 	//[ Open and configure a controller]
       
    75 	iControllerEventMonitor->Cancel();
       
    76 	iMMFController.Close();
       
    77 	//[check controller array is not empty]
       
    78     if( ! controllers.Count() )
       
    79 		User::Leave( KErrNotFound );
       
    80 
       
    81 	//[ simply open the first controller in the array ]
       
    82 	User::LeaveIfError( iMMFController.Open(controllers[0]->Uid(), iPrioritySettings));
       
    83 	iControllerEventMonitor->Start();
       
    84 	
       
    85 	iSrCustomCommands.SetClientUid(iClientUid);
       
    86 
       
    87 	CleanupStack::PopAndDestroy(2, &controllers);//controllers, cSelect
       
    88 	
       
    89 	}
       
    90 
       
    91 CSpeechRecognitionUtility::CBody::CBody(TUid aClientUid, MSpeechRecognitionUtilityObserver& aSpeechRecognitionUtilityObserver)
       
    92 	: iSrCustomCommands(iMMFController),
       
    93 	  iSpeechRecognitionUtilityObserver(&aSpeechRecognitionUtilityObserver),
       
    94 	  iClientUid(aClientUid)
       
    95 	{
       
    96 	}
       
    97 	
       
    98 CSpeechRecognitionUtility::CBody::~CBody()
       
    99 	{
       
   100 	if (iControllerEventMonitor)
       
   101 		{
       
   102 		iControllerEventMonitor->Cancel();
       
   103 		delete iControllerEventMonitor;
       
   104 		}
       
   105 	iMMFController.Close();
       
   106 	}
       
   107 
       
   108 TInt CSpeechRecognitionUtility::CBody::GetEngineProperties(const RArray<TInt>& aPropertyIDs, RArray<TInt>& aPropertyValues)
       
   109 	{
       
   110 	aPropertyValues.Reset();
       
   111 	return iSrCustomCommands.GetEngineProperties(aPropertyIDs, aPropertyValues);
       
   112 	}
       
   113 
       
   114 TInt CSpeechRecognitionUtility::CBody::AddPronunciation(TLexiconID aLexiconID, TModelBankID aModelBankID, TModelID aModelID, TPronunciationID& aPronunciationID)
       
   115 	{
       
   116 	if (iAsyncCallBusy)
       
   117 		return KErrInUse;
       
   118 
       
   119 	TInt err = iSrCustomCommands.AddPronunciation(aLexiconID, aModelBankID, aModelID, aPronunciationID);
       
   120 	
       
   121 	if (err == KErrNone)
       
   122 		iAsyncCallBusy=ETrue;
       
   123 	return err;
       
   124 	}
       
   125 
       
   126 TInt CSpeechRecognitionUtility::CBody::AddRule(TGrammarID aGrammarID, TLexiconID aLexiconID, TPronunciationID aPronunciationID, TRuleID& aRuleID)
       
   127 	{
       
   128 	if (iAsyncCallBusy)
       
   129 		return KErrInUse;
       
   130 
       
   131 	TInt err = iSrCustomCommands.AddRule(aGrammarID, aLexiconID, aPronunciationID, aRuleID);
       
   132 
       
   133 	if (err == KErrNone)
       
   134 		iAsyncCallBusy=ETrue;
       
   135 	return err;
       
   136 
       
   137 	}
       
   138 
       
   139 void CSpeechRecognitionUtility::CBody::Cancel()
       
   140 	{
       
   141 	iSrCustomCommands.Cancel();
       
   142 	// Now cancel has been called, so remove any pointers storing references to arrays to be filled
       
   143 	// These arrays are not owned by this object, so they must not be destroyed
       
   144 	iPronunciationIDs = NULL;
       
   145 	iRuleIDs = NULL;
       
   146 	iModelIDs = NULL;
       
   147 	iAsyncCallBusy = EFalse;
       
   148 	}
       
   149 
       
   150 TInt CSpeechRecognitionUtility::CBody::CommitChanges()
       
   151 	{
       
   152 	if (iAsyncCallBusy)
       
   153 		return KErrInUse;
       
   154 
       
   155 	return iSrCustomCommands.CommitChanges();
       
   156 	}
       
   157 
       
   158 TInt CSpeechRecognitionUtility::CBody::CreateGrammar(TGrammarID& aGrammarID)
       
   159 	{
       
   160 	if (iAsyncCallBusy)
       
   161 		return KErrInUse;
       
   162 	TInt err = iSrCustomCommands.CreateGrammar(aGrammarID);
       
   163 	
       
   164 	if (err == KErrNone)
       
   165 		iAsyncCallBusy=ETrue;
       
   166 	return err;
       
   167 	}
       
   168 
       
   169 TInt CSpeechRecognitionUtility::CBody::CreateLexicon(TLexiconID& aLexiconID)
       
   170 	{
       
   171 	if (iAsyncCallBusy)
       
   172 		return KErrInUse;
       
   173 	TInt err = iSrCustomCommands.CreateLexicon(aLexiconID);
       
   174 	
       
   175 	if (err == KErrNone)
       
   176 		iAsyncCallBusy=ETrue;
       
   177 	return err;
       
   178 	}
       
   179 
       
   180 TInt CSpeechRecognitionUtility::CBody::LoadModels(TModelBankID aModelBankID)
       
   181 	{
       
   182 	if (iAsyncCallBusy)
       
   183 		return KErrInUse;
       
   184 
       
   185 	TInt err = iSrCustomCommands.LoadModels(aModelBankID);
       
   186 	
       
   187 	if (err == KErrNone)
       
   188 		iAsyncCallBusy=ETrue;
       
   189 		
       
   190 	return err;
       
   191 	}
       
   192 	
       
   193 TInt CSpeechRecognitionUtility::CBody::LoadGrammar(TGrammarID aGrammarID)
       
   194 	{
       
   195 	if (iAsyncCallBusy)
       
   196 		return KErrInUse;
       
   197 
       
   198 	TInt err = iSrCustomCommands.LoadGrammar(aGrammarID);
       
   199 	
       
   200 	if (err == KErrNone)
       
   201 		iAsyncCallBusy=ETrue;
       
   202 		
       
   203 	return err;
       
   204 
       
   205 	}
       
   206 
       
   207 TInt CSpeechRecognitionUtility::CBody::LoadLexicon(TLexiconID aLexiconID)
       
   208 	{
       
   209 	if (iAsyncCallBusy)
       
   210 		return KErrInUse;
       
   211 
       
   212 	TInt err = iSrCustomCommands.LoadLexicon(aLexiconID);
       
   213 	
       
   214 	if (err == KErrNone)
       
   215 		iAsyncCallBusy=ETrue;
       
   216 		
       
   217 	return err;
       
   218 
       
   219 	}
       
   220 
       
   221 
       
   222 TInt CSpeechRecognitionUtility::CBody::GetUtteranceDuration(TModelBankID aModelBankID, TModelID aModelID, TTimeIntervalMicroSeconds32& aDuration)
       
   223 	{
       
   224 	if (iAsyncCallBusy)
       
   225 		return KErrInUse;
       
   226 
       
   227 	TInt err = iSrCustomCommands.GetUtteranceDuration(aModelBankID, aModelID, aDuration);
       
   228 	
       
   229 	if (err == KErrNone)
       
   230 		iAsyncCallBusy=ETrue;
       
   231 		
       
   232 	return err;
       
   233 	}
       
   234 
       
   235 
       
   236 TInt CSpeechRecognitionUtility::CBody::PlayUtterance(TModelBankID aModelBankID, TModelID aModelID)
       
   237 	{
       
   238 	if (iAsyncCallBusy)
       
   239 		return KErrInUse;
       
   240 		
       
   241 	iPrioritySettings.iPriority = iAudioPriority;
       
   242 	iPrioritySettings.iPref = iPlaybackPreference;
       
   243 	
       
   244 	TInt err = iMMFController.SetPrioritySettings(iPrioritySettings);
       
   245 	
       
   246 	if (err == KErrNone)
       
   247 		err = iSrCustomCommands.PlayUtterance(aModelBankID, aModelID);
       
   248 	
       
   249 	if (err == KErrNone)
       
   250 		iAsyncCallBusy=ETrue;
       
   251 		
       
   252 	return err;
       
   253 	}
       
   254 
       
   255 TInt CSpeechRecognitionUtility::CBody::GetModelCount(TModelBankID aModelBankID, TInt& aModelCount)
       
   256 	{
       
   257 	if (iAsyncCallBusy)
       
   258 		return KErrInUse;
       
   259 
       
   260 	TInt err = iSrCustomCommands.GetModelCount(aModelBankID, aModelCount);
       
   261 	
       
   262 	if (err == KErrNone)
       
   263 		iAsyncCallBusy=ETrue;
       
   264 		
       
   265 	return err;
       
   266 	}
       
   267 
       
   268 TInt CSpeechRecognitionUtility::CBody::StartRecSession(TRecognitionMode aMode)
       
   269 	{
       
   270 	if (iAsyncCallBusy)
       
   271 		return KErrInUse;
       
   272 	
       
   273 	return iSrCustomCommands.StartRecSession(aMode);
       
   274 	}
       
   275 	
       
   276 TInt CSpeechRecognitionUtility::CBody::EndRecSession()
       
   277 	{
       
   278 	if (iAsyncCallBusy)
       
   279 		return KErrInUse;
       
   280 		
       
   281 	return iSrCustomCommands.EndRecSession();
       
   282 	}
       
   283 
       
   284 TInt CSpeechRecognitionUtility::CBody::Recognize(CSDClientResultSet& aResultSet)
       
   285 	{
       
   286 	if (iAsyncCallBusy)
       
   287 		return KErrInUse;
       
   288 		
       
   289 	ASSERT(iResultSet==NULL); // this should be NULL unless we have problems
       
   290 	
       
   291 	iPrioritySettings.iPriority = iAudioPriority;
       
   292 	iPrioritySettings.iPref = iRecognitionPreference;
       
   293 	TInt err = iMMFController.SetPrioritySettings(iPrioritySettings);
       
   294 	
       
   295 	if (err == KErrNone)
       
   296 		err =  iSrCustomCommands.Recognize(aResultSet);
       
   297 
       
   298 	if (err == KErrNone)
       
   299 		{
       
   300 		iResultSet = &aResultSet;
       
   301 		iAsyncCallBusy = ETrue;
       
   302 		}
       
   303 	return err;	
       
   304 	}
       
   305 
       
   306 TInt CSpeechRecognitionUtility::CBody::Record(TTimeIntervalMicroSeconds32 aRecordTime)
       
   307 	{
       
   308 	if (iAsyncCallBusy)
       
   309 		return KErrInUse;
       
   310 
       
   311 	TInt err = iSrCustomCommands.Record(aRecordTime);
       
   312 	
       
   313 	if (err == KErrNone)
       
   314 		iAsyncCallBusy=ETrue;
       
   315 		
       
   316 	return err;
       
   317 	}
       
   318 
       
   319 TInt CSpeechRecognitionUtility::CBody::RemoveGrammar(TGrammarID aGrammarID)
       
   320 	{
       
   321 	if (iAsyncCallBusy)
       
   322 		return KErrInUse;
       
   323 
       
   324 	TInt err = iSrCustomCommands.RemoveGrammar(aGrammarID);
       
   325 	
       
   326 	if (err == KErrNone)
       
   327 		iAsyncCallBusy = ETrue;
       
   328 	return err;
       
   329 	}
       
   330 
       
   331 TInt CSpeechRecognitionUtility::CBody::RemovePronunciation(TLexiconID aLexiconID, TPronunciationID aPronunciationID)
       
   332 	{
       
   333 	if (iAsyncCallBusy)
       
   334 		return KErrInUse;
       
   335 
       
   336 	TInt err = iSrCustomCommands.RemovePronunciation(aLexiconID, aPronunciationID);
       
   337 	
       
   338 	if (err == KErrNone)
       
   339 		iAsyncCallBusy = ETrue;
       
   340 	return err;
       
   341 	}
       
   342 
       
   343 TInt CSpeechRecognitionUtility::CBody::RemoveLexicon(TLexiconID aLexiconID)
       
   344 	{
       
   345 	if (iAsyncCallBusy)
       
   346 		return KErrInUse;
       
   347 
       
   348 	TInt err = iSrCustomCommands.RemoveLexicon(aLexiconID);
       
   349 	
       
   350 	if (err == KErrNone)
       
   351 		iAsyncCallBusy = ETrue;
       
   352 	return err;
       
   353 	}
       
   354 
       
   355 TInt CSpeechRecognitionUtility::CBody::RemoveModel(TModelBankID aModelBankID, TModelID aModelID)
       
   356 	{
       
   357 	if (iAsyncCallBusy)
       
   358 		return KErrInUse;
       
   359 
       
   360 	TInt err = iSrCustomCommands.RemoveModel(aModelBankID, aModelID);
       
   361 	
       
   362 	if (err == KErrNone)
       
   363 		iAsyncCallBusy = ETrue;
       
   364 		
       
   365 	return err;
       
   366 	}
       
   367 
       
   368 TInt CSpeechRecognitionUtility::CBody::RemoveRule(TGrammarID aGrammarID, TRuleID aRuleID)
       
   369 	{
       
   370 	if (iAsyncCallBusy)
       
   371 		return KErrInUse;
       
   372 
       
   373 	TInt err = iSrCustomCommands.RemoveRule(aGrammarID, aRuleID);
       
   374 	
       
   375 	if (err == KErrNone)
       
   376 		iAsyncCallBusy = ETrue;
       
   377 		
       
   378 	return err;
       
   379 
       
   380 	}
       
   381 TInt CSpeechRecognitionUtility::CBody::Train(TModelBankID aModelBankID, TModelID& aModelID)
       
   382 	{
       
   383 	if (iAsyncCallBusy)
       
   384 		return KErrInUse;
       
   385 		
       
   386 	iPrioritySettings.iPriority = iAudioPriority;
       
   387 	iPrioritySettings.iPref = iTrainPreference;
       
   388 	TInt err = iMMFController.SetPrioritySettings(iPrioritySettings);
       
   389 
       
   390 	if (err == KErrNone)
       
   391 		err = iSrCustomCommands.Train(aModelBankID, aModelID);
       
   392 	
       
   393 	if (err == KErrNone)
       
   394 		iAsyncCallBusy = ETrue;
       
   395 
       
   396 	return err;
       
   397 	}
       
   398 
       
   399 TInt CSpeechRecognitionUtility::CBody::UnloadRule(TGrammarID aGrammarID, TRuleID aRuleID)
       
   400 	{
       
   401 	if (iAsyncCallBusy)
       
   402 		return KErrInUse;
       
   403 
       
   404 	TInt err = iSrCustomCommands.UnloadRule(aGrammarID, aRuleID); 
       
   405 	
       
   406 	if (err == KErrNone)
       
   407 		iAsyncCallBusy = ETrue;
       
   408 		
       
   409 	return err;
       
   410 
       
   411 	}
       
   412 
       
   413 void CSpeechRecognitionUtility::CBody::SetEventHandler(MSpeechRecognitionUtilityObserver* aSpeechRecognitionUtilityObserver)
       
   414 	{
       
   415 	iSpeechRecognitionUtilityObserver = aSpeechRecognitionUtilityObserver;
       
   416 	}
       
   417 	
       
   418 
       
   419 TInt CSpeechRecognitionUtility::CBody::GetAllPronunciationIDs(TLexiconID aLexiconID, RArray <TPronunciationID>& aPronunciationIDs)
       
   420 	{
       
   421 	if (iAsyncCallBusy)
       
   422 		return KErrInUse;
       
   423 
       
   424 	ASSERT(iPronunciationIDs==NULL);
       
   425 
       
   426 	TInt err = iSrCustomCommands.GetAllPronunciationIDs(aLexiconID);
       
   427 	
       
   428 	if (err==KErrNone)
       
   429 		{
       
   430 		iPronunciationIDs = &aPronunciationIDs;
       
   431 		iPronunciationIDs->Reset();
       
   432 		iAsyncCallBusy = ETrue;
       
   433 		}
       
   434 		
       
   435 	return err;
       
   436 	}
       
   437 
       
   438 TInt CSpeechRecognitionUtility::CBody::GetAllModelIDs(TModelBankID aModelBankID, RArray <TModelID>& aModelIDs)
       
   439 	{
       
   440 	if (iAsyncCallBusy)
       
   441 		return KErrInUse;
       
   442 
       
   443 	ASSERT(iModelIDs==NULL);
       
   444 	
       
   445 	TInt err = iSrCustomCommands.GetAllModelIDs(aModelBankID);
       
   446 	
       
   447 	if (err==KErrNone) 
       
   448 		{
       
   449 		iModelIDs = &aModelIDs;
       
   450 		iModelIDs->Reset();
       
   451 		iAsyncCallBusy = ETrue;
       
   452 		}
       
   453 	return err;
       
   454 	}
       
   455 
       
   456 
       
   457 TInt CSpeechRecognitionUtility::CBody::GetAllRuleIDs(TGrammarID aGrammarID, RArray <TRuleID>& aRuleIDs)
       
   458 	{
       
   459 	if (iAsyncCallBusy)
       
   460 		return KErrInUse;
       
   461 
       
   462 	ASSERT(iRuleIDs==NULL);
       
   463 		
       
   464 	TInt err = iSrCustomCommands.GetAllRuleIDs(aGrammarID);
       
   465 	
       
   466 	if (err==KErrNone)	
       
   467 		{
       
   468 		iRuleIDs = &aRuleIDs;
       
   469 		iRuleIDs->Reset();
       
   470 		iAsyncCallBusy = ETrue;
       
   471 		}
       
   472 	return err;
       
   473 	}
       
   474 	
       
   475 	
       
   476 TInt CSpeechRecognitionUtility::CBody::GetAllClientLexiconIDs(RArray <TLexiconID>& aLexiconIDs)
       
   477 	{
       
   478 	if (iAsyncCallBusy)
       
   479 		return KErrInUse;
       
   480 
       
   481 	ASSERT(iLexiconIDs==NULL);
       
   482 
       
   483 	TInt err = iSrCustomCommands.GetAllClientLexiconIDs();
       
   484 	
       
   485 	if (err==KErrNone)
       
   486 		{
       
   487 		iLexiconIDs = &aLexiconIDs;
       
   488 		iLexiconIDs->Reset();
       
   489 		iAsyncCallBusy = ETrue;
       
   490 		}
       
   491 		
       
   492 	return err;
       
   493 	}
       
   494 
       
   495 TInt CSpeechRecognitionUtility::CBody::GetAllClientModelBankIDs(RArray <TModelBankID>& aModelBankIDs)
       
   496 	{
       
   497 	if (iAsyncCallBusy)
       
   498 		return KErrInUse;
       
   499 
       
   500 	ASSERT(iModelBankIDs==NULL);
       
   501 	
       
   502 	TInt err = iSrCustomCommands.GetAllClientModelBankIDs();
       
   503 	
       
   504 	if (err==KErrNone) 
       
   505 		{
       
   506 		iModelBankIDs = &aModelBankIDs;
       
   507 		iModelBankIDs->Reset();
       
   508 		iAsyncCallBusy = ETrue;
       
   509 		}
       
   510 	return err;
       
   511 	}
       
   512 
       
   513 
       
   514 TInt CSpeechRecognitionUtility::CBody::GetAllClientGrammarIDs(RArray <TGrammarID>& aGrammarIDs)
       
   515 	{
       
   516 	if (iAsyncCallBusy)
       
   517 		return KErrInUse;
       
   518 
       
   519 	ASSERT(iGrammarIDs==NULL);
       
   520 		
       
   521 	TInt err = iSrCustomCommands.GetAllClientGrammarIDs();
       
   522 	
       
   523 	if (err==KErrNone)	
       
   524 		{
       
   525 		iGrammarIDs = &aGrammarIDs;
       
   526 		iGrammarIDs->Reset();
       
   527 		iAsyncCallBusy = ETrue;
       
   528 		}
       
   529 	return err;
       
   530 	}
       
   531 	
       
   532 	
       
   533 TInt CSpeechRecognitionUtility::CBody::GetAllLexiconIDs(RArray <TLexiconID>& aLexiconIDs)
       
   534 	{
       
   535 	if (iAsyncCallBusy)
       
   536 		return KErrInUse;
       
   537 
       
   538 	ASSERT(iLexiconIDs==NULL);
       
   539 
       
   540 	TInt err = iSrCustomCommands.GetAllLexiconIDs();
       
   541 	
       
   542 	if (err==KErrNone)
       
   543 		{
       
   544 		iLexiconIDs = &aLexiconIDs;
       
   545 		iLexiconIDs->Reset();
       
   546 		iAsyncCallBusy = ETrue;
       
   547 		}
       
   548 		
       
   549 	return err;
       
   550 	}
       
   551 
       
   552 TInt CSpeechRecognitionUtility::CBody::GetAllModelBankIDs(RArray <TModelBankID>& aModelBankIDs)
       
   553 	{
       
   554 	if (iAsyncCallBusy)
       
   555 		return KErrInUse;
       
   556 
       
   557 	ASSERT(iModelBankIDs==NULL);
       
   558 	
       
   559 	TInt err = iSrCustomCommands.GetAllModelBankIDs();
       
   560 	
       
   561 	if (err==KErrNone) 
       
   562 		{
       
   563 		iModelBankIDs = &aModelBankIDs;
       
   564 		iModelBankIDs->Reset();
       
   565 		iAsyncCallBusy = ETrue;
       
   566 		}
       
   567 	return err;
       
   568 	}
       
   569 
       
   570 
       
   571 TInt CSpeechRecognitionUtility::CBody::GetAllGrammarIDs(RArray <TGrammarID>& aGrammarIDs)
       
   572 	{
       
   573 	if (iAsyncCallBusy)
       
   574 		return KErrInUse;
       
   575 
       
   576 	ASSERT(iGrammarIDs==NULL);
       
   577 		
       
   578 	TInt err = iSrCustomCommands.GetAllGrammarIDs();
       
   579 	
       
   580 	if (err==KErrNone)	
       
   581 		{
       
   582 		iGrammarIDs = &aGrammarIDs;
       
   583 		iGrammarIDs->Reset();
       
   584 		iAsyncCallBusy = ETrue;
       
   585 		}
       
   586 	return err;
       
   587 	}
       
   588 
       
   589 	
       
   590 TInt CSpeechRecognitionUtility::CBody::GetRuleValidity(TGrammarID aGrammarID, TRuleID aRuleID, TBool& aValid)
       
   591 	{
       
   592 	if (iAsyncCallBusy)
       
   593 		return KErrInUse;
       
   594 
       
   595 	TInt err = iSrCustomCommands.GetRuleValidity(aGrammarID, aRuleID, aValid);
       
   596 	
       
   597 	if (err == KErrNone)
       
   598 		iAsyncCallBusy = ETrue;
       
   599 	return err;
       
   600 	} 
       
   601 
       
   602 
       
   603 TInt CSpeechRecognitionUtility::CBody::CreateModelBank(TModelBankID& aModelBankID)
       
   604 	{
       
   605 	if (iAsyncCallBusy)
       
   606 		return KErrInUse;
       
   607 	TInt err = iSrCustomCommands.CreateModelBank(aModelBankID);
       
   608 	if (err == KErrNone)
       
   609 		iAsyncCallBusy = ETrue;
       
   610 	return err;
       
   611 	}
       
   612 
       
   613 TInt CSpeechRecognitionUtility::CBody::RemoveModelBank(TModelBankID aModelBankID)
       
   614 	{
       
   615 	if (iAsyncCallBusy)
       
   616 		return KErrInUse;
       
   617 
       
   618 	TInt err = iSrCustomCommands.RemoveModelBank(aModelBankID);
       
   619 	if (err == KErrNone)
       
   620 		iAsyncCallBusy = ETrue;
       
   621 	return err;
       
   622 	}
       
   623 
       
   624 TInt CSpeechRecognitionUtility::CBody::GetAvailableStorage(TInt& aAvailableStorage) 
       
   625 	{
       
   626 	if (iAsyncCallBusy)
       
   627 		return KErrInUse;
       
   628 		
       
   629 	TInt err = iSrCustomCommands.GetAvailableStorage(aAvailableStorage);
       
   630 	
       
   631 	if (err == KErrNone)
       
   632 		iAsyncCallBusy = ETrue;
       
   633 		
       
   634 	return err;
       
   635 	}
       
   636 
       
   637 TInt CSpeechRecognitionUtility::CBody::LoadEngineParameters(const RArray<TInt>& aParameterId, const RArray<TInt>& aParameterValue)
       
   638 	{
       
   639 	if (iAsyncCallBusy)
       
   640 		return KErrInUse;
       
   641 		
       
   642 	return iSrCustomCommands.LoadEngineParameters(aParameterId, aParameterValue);
       
   643 	}
       
   644 
       
   645 TInt CSpeechRecognitionUtility::CBody::SetAudioPriority(TInt aPriority, TInt aTrainPreference, TInt aPlaybackPreference, TInt aRecognitionPreference)
       
   646 	{
       
   647 	iAudioPriority = aPriority;
       
   648 	iTrainPreference = (TMdaPriorityPreference)aTrainPreference;
       
   649 	iPlaybackPreference = (TMdaPriorityPreference)aPlaybackPreference;
       
   650 	iRecognitionPreference = (TMdaPriorityPreference)aRecognitionPreference;
       
   651 	
       
   652 	return KErrNone;	
       
   653 	}
       
   654 
       
   655 void CSpeechRecognitionUtility::CBody::HandleEvent(const TMMFEvent& aEvent)
       
   656 	{
       
   657 	TBool cancelled = EFalse;
       
   658 	TBool asyncCallComplete = ETrue;
       
   659 
       
   660 	TUid event = aEvent.iEventType;
       
   661 	TInt errorCode = aEvent.iErrorCode;
       
   662 	
       
   663 		
       
   664 	switch (event.iUid)
       
   665 		{
       
   666 		case KUidAsrEventGetAllPronunciationIDsVal :
       
   667 			{
       
   668 			if (iPronunciationIDs)
       
   669 				{
       
   670 				if (errorCode==KErrNone)
       
   671 					TRAP(errorCode, iSrCustomCommands.GetPronunciationIDArrayL(*iPronunciationIDs));
       
   672 				// async operation complete, so get rid of reference to array
       
   673 				iPronunciationIDs = NULL;
       
   674 				}
       
   675 			else 
       
   676 				cancelled = ETrue;
       
   677 			} 
       
   678 			break;
       
   679 		case KUidAsrEventGetAllRuleIDsVal :
       
   680 			{
       
   681 			if (iRuleIDs)
       
   682 				{
       
   683 				if (errorCode==KErrNone)
       
   684 					TRAP(errorCode, iSrCustomCommands.GetRuleIDArrayL(*iRuleIDs));		
       
   685 				// async operation complete, so get rid of reference to array
       
   686 				iRuleIDs = NULL;
       
   687 				}
       
   688 			else
       
   689 				cancelled = ETrue;
       
   690 			}
       
   691 			break;
       
   692 		case KUidAsrEventGetAllModelIDsVal :
       
   693 			{
       
   694 			if (iModelIDs)
       
   695 				{
       
   696 				if (errorCode==KErrNone)
       
   697 					TRAP(errorCode, iSrCustomCommands.GetModelIDArrayL(*iModelIDs));
       
   698 				// async operation complete, so get rid of reference to array
       
   699 				iModelIDs = NULL;
       
   700 				}
       
   701 			else
       
   702 				cancelled = ETrue;
       
   703 			}
       
   704 			break;
       
   705 		case KUidAsrEventGetAllClientModelBankIDsVal :
       
   706 		case KUidAsrEventGetAllModelBankIDsVal :
       
   707 			{
       
   708 			if (iModelBankIDs)
       
   709 				{
       
   710 				if (errorCode==KErrNone)
       
   711 					TRAP(errorCode, iSrCustomCommands.GetModelBankIDArrayL(*iModelBankIDs));
       
   712 				// async operation complete, so get rid of reference to array
       
   713 				iModelBankIDs = NULL;
       
   714 				}
       
   715 			else
       
   716 				cancelled = ETrue;
       
   717 			}
       
   718 			break;
       
   719 		case KUidAsrEventGetAllClientGrammarIDsVal :
       
   720 		case KUidAsrEventGetAllGrammarIDsVal :
       
   721 			{
       
   722 			if (iGrammarIDs)
       
   723 				{
       
   724 				if (errorCode==KErrNone)
       
   725 					TRAP(errorCode, iSrCustomCommands.GetGrammarIDArrayL(*iGrammarIDs));
       
   726 				// async operation complete, so get rid of reference to array
       
   727 				iGrammarIDs = NULL;
       
   728 				}
       
   729 			else
       
   730 				cancelled = ETrue;
       
   731 			}
       
   732 			break;
       
   733 		case KUidAsrEventGetAllClientLexiconIDsVal :
       
   734 		case KUidAsrEventGetAllLexiconIDsVal :
       
   735 			{
       
   736 			if (iLexiconIDs)
       
   737 				{
       
   738 				if (errorCode==KErrNone)
       
   739 					TRAP(errorCode, iSrCustomCommands.GetLexiconIDArrayL(*iLexiconIDs));
       
   740 				// async operation complete, so get rid of reference to array
       
   741 				iLexiconIDs = NULL;
       
   742 				}
       
   743 			else
       
   744 				cancelled = ETrue;
       
   745 			}
       
   746 			break;
       
   747 
       
   748 		case KUidAsrEventRecognitionVal :
       
   749 			{
       
   750 			if (iResultSet)
       
   751 				{
       
   752 				if (errorCode==KErrNone)
       
   753 					TRAP(errorCode, iSrCustomCommands.GetResultSetL(*iResultSet));
       
   754 				iResultSet = NULL;
       
   755 				}
       
   756 			else
       
   757 				cancelled = ETrue;
       
   758 			}
       
   759 			break;
       
   760 		case KUidAsrEventTrainVal:
       
   761 			break;
       
   762 		case KUidAsrEventPlayStartedVal:
       
   763 		case KUidAsrEventRecordStartedVal:
       
   764 			asyncCallComplete = EFalse;
       
   765 			break;
       
   766 		default:
       
   767 			break;
       
   768 
       
   769 			}
       
   770 		if (event == KMMFErrorCategoryControllerGeneralError)
       
   771 			{
       
   772 			// clear these, as the error callback
       
   773 			iPronunciationIDs = NULL;
       
   774 			iRuleIDs = NULL;
       
   775 			iModelIDs = NULL;
       
   776 			iLexiconIDs = NULL;
       
   777 			iGrammarIDs = NULL;
       
   778 			iModelBankIDs = NULL;
       
   779 			}
       
   780 		if (asyncCallComplete)
       
   781 			iAsyncCallBusy = EFalse;
       
   782 			
       
   783 		if (iSpeechRecognitionUtilityObserver && !cancelled)
       
   784 			iSpeechRecognitionUtilityObserver->MsruoEvent(event, errorCode);
       
   785 
       
   786 	}
       
   787