1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmdevicefw/speechrecogsupport/ASR/src/SpeechRecognitionUtilityBody.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,787 @@
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 +// SpeechRecognitionUtility.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32base.h>
1.22 +#include <mmf/common/mmfcontroller.h>
1.23 +#include <mmf/common/speechrecognitioncustomcommands.h>
1.24 +#include <mmf/common/speechrecognitiondatacommon.h>
1.25 +
1.26 +#include <speechrecognitionutility.h>
1.27 +#include "SpeechRecognitionUtilityBody.h"
1.28 +
1.29 +//_LIT(KMMFSpeechRecognitionUtilityPanic,"Speech Recognition Utility Bad State");
1.30 +enum ASRPanics
1.31 + {
1.32 + KMMFSpeechRecognitionUtilityPanicBadState,
1.33 + KMMFSpeechRecognitionUtilityPanicUnrecognisedEvent
1.34 + };
1.35 +
1.36 +CSpeechRecognitionUtility::CBody* CSpeechRecognitionUtility::CBody::NewL( TUid aClientUid, MSpeechRecognitionUtilityObserver& aSpeechRecognitionUtilityObserver)
1.37 + {
1.38 + CSpeechRecognitionUtility::CBody* self = CSpeechRecognitionUtility::CBody::NewLC(aClientUid, aSpeechRecognitionUtilityObserver);
1.39 + CleanupStack::Pop(self);
1.40 + return self;
1.41 + }
1.42 +
1.43 +CSpeechRecognitionUtility::CBody* CSpeechRecognitionUtility::CBody::NewLC(TUid aClientUid, MSpeechRecognitionUtilityObserver& aSpeechRecognitionUtilityObserver)
1.44 + {
1.45 + CSpeechRecognitionUtility::CBody* self = new(ELeave) CSpeechRecognitionUtility::CBody(aClientUid, aSpeechRecognitionUtilityObserver);
1.46 + CleanupStack::PushL(self);
1.47 + self->ConstructL();
1.48 + return self;
1.49 + }
1.50 +
1.51 +void CSpeechRecognitionUtility::CBody::ConstructL()
1.52 + {
1.53 + iAudioPriority = EMdaPriorityNormal;
1.54 + iTrainPreference = EMdaPriorityPreferenceNone;
1.55 + iRecognitionPreference = EMdaPriorityPreferenceNone;
1.56 + iPlaybackPreference = EMdaPriorityPreferenceNone;
1.57 +
1.58 + iPrioritySettings.iPriority = iAudioPriority;
1.59 + iPrioritySettings.iPref = iTrainPreference;
1.60 +
1.61 + iControllerEventMonitor = CMMFControllerEventMonitor::NewL(*this, iMMFController);
1.62 +
1.63 + RMMFControllerImplInfoArray controllers;
1.64 + CleanupResetAndDestroyPushL(controllers);
1.65 +
1.66 + CMMFControllerPluginSelectionParameters* cSelect = CMMFControllerPluginSelectionParameters::NewLC();
1.67 +
1.68 + // Select the media IDs to allow
1.69 + RArray<TUid> mediaIds;
1.70 + CleanupClosePushL(mediaIds);
1.71 + User::LeaveIfError(mediaIds.Append(KUidMediaTypeASR));
1.72 + cSelect->SetMediaIdsL(mediaIds,CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds);
1.73 + CleanupStack::PopAndDestroy(&mediaIds);
1.74 +
1.75 + cSelect->ListImplementationsL(controllers);
1.76 +
1.77 + //[ Open and configure a controller]
1.78 + iControllerEventMonitor->Cancel();
1.79 + iMMFController.Close();
1.80 + //[check controller array is not empty]
1.81 + if( ! controllers.Count() )
1.82 + User::Leave( KErrNotFound );
1.83 +
1.84 + //[ simply open the first controller in the array ]
1.85 + User::LeaveIfError( iMMFController.Open(controllers[0]->Uid(), iPrioritySettings));
1.86 + iControllerEventMonitor->Start();
1.87 +
1.88 + iSrCustomCommands.SetClientUid(iClientUid);
1.89 +
1.90 + CleanupStack::PopAndDestroy(2, &controllers);//controllers, cSelect
1.91 +
1.92 + }
1.93 +
1.94 +CSpeechRecognitionUtility::CBody::CBody(TUid aClientUid, MSpeechRecognitionUtilityObserver& aSpeechRecognitionUtilityObserver)
1.95 + : iSrCustomCommands(iMMFController),
1.96 + iSpeechRecognitionUtilityObserver(&aSpeechRecognitionUtilityObserver),
1.97 + iClientUid(aClientUid)
1.98 + {
1.99 + }
1.100 +
1.101 +CSpeechRecognitionUtility::CBody::~CBody()
1.102 + {
1.103 + if (iControllerEventMonitor)
1.104 + {
1.105 + iControllerEventMonitor->Cancel();
1.106 + delete iControllerEventMonitor;
1.107 + }
1.108 + iMMFController.Close();
1.109 + }
1.110 +
1.111 +TInt CSpeechRecognitionUtility::CBody::GetEngineProperties(const RArray<TInt>& aPropertyIDs, RArray<TInt>& aPropertyValues)
1.112 + {
1.113 + aPropertyValues.Reset();
1.114 + return iSrCustomCommands.GetEngineProperties(aPropertyIDs, aPropertyValues);
1.115 + }
1.116 +
1.117 +TInt CSpeechRecognitionUtility::CBody::AddPronunciation(TLexiconID aLexiconID, TModelBankID aModelBankID, TModelID aModelID, TPronunciationID& aPronunciationID)
1.118 + {
1.119 + if (iAsyncCallBusy)
1.120 + return KErrInUse;
1.121 +
1.122 + TInt err = iSrCustomCommands.AddPronunciation(aLexiconID, aModelBankID, aModelID, aPronunciationID);
1.123 +
1.124 + if (err == KErrNone)
1.125 + iAsyncCallBusy=ETrue;
1.126 + return err;
1.127 + }
1.128 +
1.129 +TInt CSpeechRecognitionUtility::CBody::AddRule(TGrammarID aGrammarID, TLexiconID aLexiconID, TPronunciationID aPronunciationID, TRuleID& aRuleID)
1.130 + {
1.131 + if (iAsyncCallBusy)
1.132 + return KErrInUse;
1.133 +
1.134 + TInt err = iSrCustomCommands.AddRule(aGrammarID, aLexiconID, aPronunciationID, aRuleID);
1.135 +
1.136 + if (err == KErrNone)
1.137 + iAsyncCallBusy=ETrue;
1.138 + return err;
1.139 +
1.140 + }
1.141 +
1.142 +void CSpeechRecognitionUtility::CBody::Cancel()
1.143 + {
1.144 + iSrCustomCommands.Cancel();
1.145 + // Now cancel has been called, so remove any pointers storing references to arrays to be filled
1.146 + // These arrays are not owned by this object, so they must not be destroyed
1.147 + iPronunciationIDs = NULL;
1.148 + iRuleIDs = NULL;
1.149 + iModelIDs = NULL;
1.150 + iAsyncCallBusy = EFalse;
1.151 + }
1.152 +
1.153 +TInt CSpeechRecognitionUtility::CBody::CommitChanges()
1.154 + {
1.155 + if (iAsyncCallBusy)
1.156 + return KErrInUse;
1.157 +
1.158 + return iSrCustomCommands.CommitChanges();
1.159 + }
1.160 +
1.161 +TInt CSpeechRecognitionUtility::CBody::CreateGrammar(TGrammarID& aGrammarID)
1.162 + {
1.163 + if (iAsyncCallBusy)
1.164 + return KErrInUse;
1.165 + TInt err = iSrCustomCommands.CreateGrammar(aGrammarID);
1.166 +
1.167 + if (err == KErrNone)
1.168 + iAsyncCallBusy=ETrue;
1.169 + return err;
1.170 + }
1.171 +
1.172 +TInt CSpeechRecognitionUtility::CBody::CreateLexicon(TLexiconID& aLexiconID)
1.173 + {
1.174 + if (iAsyncCallBusy)
1.175 + return KErrInUse;
1.176 + TInt err = iSrCustomCommands.CreateLexicon(aLexiconID);
1.177 +
1.178 + if (err == KErrNone)
1.179 + iAsyncCallBusy=ETrue;
1.180 + return err;
1.181 + }
1.182 +
1.183 +TInt CSpeechRecognitionUtility::CBody::LoadModels(TModelBankID aModelBankID)
1.184 + {
1.185 + if (iAsyncCallBusy)
1.186 + return KErrInUse;
1.187 +
1.188 + TInt err = iSrCustomCommands.LoadModels(aModelBankID);
1.189 +
1.190 + if (err == KErrNone)
1.191 + iAsyncCallBusy=ETrue;
1.192 +
1.193 + return err;
1.194 + }
1.195 +
1.196 +TInt CSpeechRecognitionUtility::CBody::LoadGrammar(TGrammarID aGrammarID)
1.197 + {
1.198 + if (iAsyncCallBusy)
1.199 + return KErrInUse;
1.200 +
1.201 + TInt err = iSrCustomCommands.LoadGrammar(aGrammarID);
1.202 +
1.203 + if (err == KErrNone)
1.204 + iAsyncCallBusy=ETrue;
1.205 +
1.206 + return err;
1.207 +
1.208 + }
1.209 +
1.210 +TInt CSpeechRecognitionUtility::CBody::LoadLexicon(TLexiconID aLexiconID)
1.211 + {
1.212 + if (iAsyncCallBusy)
1.213 + return KErrInUse;
1.214 +
1.215 + TInt err = iSrCustomCommands.LoadLexicon(aLexiconID);
1.216 +
1.217 + if (err == KErrNone)
1.218 + iAsyncCallBusy=ETrue;
1.219 +
1.220 + return err;
1.221 +
1.222 + }
1.223 +
1.224 +
1.225 +TInt CSpeechRecognitionUtility::CBody::GetUtteranceDuration(TModelBankID aModelBankID, TModelID aModelID, TTimeIntervalMicroSeconds32& aDuration)
1.226 + {
1.227 + if (iAsyncCallBusy)
1.228 + return KErrInUse;
1.229 +
1.230 + TInt err = iSrCustomCommands.GetUtteranceDuration(aModelBankID, aModelID, aDuration);
1.231 +
1.232 + if (err == KErrNone)
1.233 + iAsyncCallBusy=ETrue;
1.234 +
1.235 + return err;
1.236 + }
1.237 +
1.238 +
1.239 +TInt CSpeechRecognitionUtility::CBody::PlayUtterance(TModelBankID aModelBankID, TModelID aModelID)
1.240 + {
1.241 + if (iAsyncCallBusy)
1.242 + return KErrInUse;
1.243 +
1.244 + iPrioritySettings.iPriority = iAudioPriority;
1.245 + iPrioritySettings.iPref = iPlaybackPreference;
1.246 +
1.247 + TInt err = iMMFController.SetPrioritySettings(iPrioritySettings);
1.248 +
1.249 + if (err == KErrNone)
1.250 + err = iSrCustomCommands.PlayUtterance(aModelBankID, aModelID);
1.251 +
1.252 + if (err == KErrNone)
1.253 + iAsyncCallBusy=ETrue;
1.254 +
1.255 + return err;
1.256 + }
1.257 +
1.258 +TInt CSpeechRecognitionUtility::CBody::GetModelCount(TModelBankID aModelBankID, TInt& aModelCount)
1.259 + {
1.260 + if (iAsyncCallBusy)
1.261 + return KErrInUse;
1.262 +
1.263 + TInt err = iSrCustomCommands.GetModelCount(aModelBankID, aModelCount);
1.264 +
1.265 + if (err == KErrNone)
1.266 + iAsyncCallBusy=ETrue;
1.267 +
1.268 + return err;
1.269 + }
1.270 +
1.271 +TInt CSpeechRecognitionUtility::CBody::StartRecSession(TRecognitionMode aMode)
1.272 + {
1.273 + if (iAsyncCallBusy)
1.274 + return KErrInUse;
1.275 +
1.276 + return iSrCustomCommands.StartRecSession(aMode);
1.277 + }
1.278 +
1.279 +TInt CSpeechRecognitionUtility::CBody::EndRecSession()
1.280 + {
1.281 + if (iAsyncCallBusy)
1.282 + return KErrInUse;
1.283 +
1.284 + return iSrCustomCommands.EndRecSession();
1.285 + }
1.286 +
1.287 +TInt CSpeechRecognitionUtility::CBody::Recognize(CSDClientResultSet& aResultSet)
1.288 + {
1.289 + if (iAsyncCallBusy)
1.290 + return KErrInUse;
1.291 +
1.292 + ASSERT(iResultSet==NULL); // this should be NULL unless we have problems
1.293 +
1.294 + iPrioritySettings.iPriority = iAudioPriority;
1.295 + iPrioritySettings.iPref = iRecognitionPreference;
1.296 + TInt err = iMMFController.SetPrioritySettings(iPrioritySettings);
1.297 +
1.298 + if (err == KErrNone)
1.299 + err = iSrCustomCommands.Recognize(aResultSet);
1.300 +
1.301 + if (err == KErrNone)
1.302 + {
1.303 + iResultSet = &aResultSet;
1.304 + iAsyncCallBusy = ETrue;
1.305 + }
1.306 + return err;
1.307 + }
1.308 +
1.309 +TInt CSpeechRecognitionUtility::CBody::Record(TTimeIntervalMicroSeconds32 aRecordTime)
1.310 + {
1.311 + if (iAsyncCallBusy)
1.312 + return KErrInUse;
1.313 +
1.314 + TInt err = iSrCustomCommands.Record(aRecordTime);
1.315 +
1.316 + if (err == KErrNone)
1.317 + iAsyncCallBusy=ETrue;
1.318 +
1.319 + return err;
1.320 + }
1.321 +
1.322 +TInt CSpeechRecognitionUtility::CBody::RemoveGrammar(TGrammarID aGrammarID)
1.323 + {
1.324 + if (iAsyncCallBusy)
1.325 + return KErrInUse;
1.326 +
1.327 + TInt err = iSrCustomCommands.RemoveGrammar(aGrammarID);
1.328 +
1.329 + if (err == KErrNone)
1.330 + iAsyncCallBusy = ETrue;
1.331 + return err;
1.332 + }
1.333 +
1.334 +TInt CSpeechRecognitionUtility::CBody::RemovePronunciation(TLexiconID aLexiconID, TPronunciationID aPronunciationID)
1.335 + {
1.336 + if (iAsyncCallBusy)
1.337 + return KErrInUse;
1.338 +
1.339 + TInt err = iSrCustomCommands.RemovePronunciation(aLexiconID, aPronunciationID);
1.340 +
1.341 + if (err == KErrNone)
1.342 + iAsyncCallBusy = ETrue;
1.343 + return err;
1.344 + }
1.345 +
1.346 +TInt CSpeechRecognitionUtility::CBody::RemoveLexicon(TLexiconID aLexiconID)
1.347 + {
1.348 + if (iAsyncCallBusy)
1.349 + return KErrInUse;
1.350 +
1.351 + TInt err = iSrCustomCommands.RemoveLexicon(aLexiconID);
1.352 +
1.353 + if (err == KErrNone)
1.354 + iAsyncCallBusy = ETrue;
1.355 + return err;
1.356 + }
1.357 +
1.358 +TInt CSpeechRecognitionUtility::CBody::RemoveModel(TModelBankID aModelBankID, TModelID aModelID)
1.359 + {
1.360 + if (iAsyncCallBusy)
1.361 + return KErrInUse;
1.362 +
1.363 + TInt err = iSrCustomCommands.RemoveModel(aModelBankID, aModelID);
1.364 +
1.365 + if (err == KErrNone)
1.366 + iAsyncCallBusy = ETrue;
1.367 +
1.368 + return err;
1.369 + }
1.370 +
1.371 +TInt CSpeechRecognitionUtility::CBody::RemoveRule(TGrammarID aGrammarID, TRuleID aRuleID)
1.372 + {
1.373 + if (iAsyncCallBusy)
1.374 + return KErrInUse;
1.375 +
1.376 + TInt err = iSrCustomCommands.RemoveRule(aGrammarID, aRuleID);
1.377 +
1.378 + if (err == KErrNone)
1.379 + iAsyncCallBusy = ETrue;
1.380 +
1.381 + return err;
1.382 +
1.383 + }
1.384 +TInt CSpeechRecognitionUtility::CBody::Train(TModelBankID aModelBankID, TModelID& aModelID)
1.385 + {
1.386 + if (iAsyncCallBusy)
1.387 + return KErrInUse;
1.388 +
1.389 + iPrioritySettings.iPriority = iAudioPriority;
1.390 + iPrioritySettings.iPref = iTrainPreference;
1.391 + TInt err = iMMFController.SetPrioritySettings(iPrioritySettings);
1.392 +
1.393 + if (err == KErrNone)
1.394 + err = iSrCustomCommands.Train(aModelBankID, aModelID);
1.395 +
1.396 + if (err == KErrNone)
1.397 + iAsyncCallBusy = ETrue;
1.398 +
1.399 + return err;
1.400 + }
1.401 +
1.402 +TInt CSpeechRecognitionUtility::CBody::UnloadRule(TGrammarID aGrammarID, TRuleID aRuleID)
1.403 + {
1.404 + if (iAsyncCallBusy)
1.405 + return KErrInUse;
1.406 +
1.407 + TInt err = iSrCustomCommands.UnloadRule(aGrammarID, aRuleID);
1.408 +
1.409 + if (err == KErrNone)
1.410 + iAsyncCallBusy = ETrue;
1.411 +
1.412 + return err;
1.413 +
1.414 + }
1.415 +
1.416 +void CSpeechRecognitionUtility::CBody::SetEventHandler(MSpeechRecognitionUtilityObserver* aSpeechRecognitionUtilityObserver)
1.417 + {
1.418 + iSpeechRecognitionUtilityObserver = aSpeechRecognitionUtilityObserver;
1.419 + }
1.420 +
1.421 +
1.422 +TInt CSpeechRecognitionUtility::CBody::GetAllPronunciationIDs(TLexiconID aLexiconID, RArray <TPronunciationID>& aPronunciationIDs)
1.423 + {
1.424 + if (iAsyncCallBusy)
1.425 + return KErrInUse;
1.426 +
1.427 + ASSERT(iPronunciationIDs==NULL);
1.428 +
1.429 + TInt err = iSrCustomCommands.GetAllPronunciationIDs(aLexiconID);
1.430 +
1.431 + if (err==KErrNone)
1.432 + {
1.433 + iPronunciationIDs = &aPronunciationIDs;
1.434 + iPronunciationIDs->Reset();
1.435 + iAsyncCallBusy = ETrue;
1.436 + }
1.437 +
1.438 + return err;
1.439 + }
1.440 +
1.441 +TInt CSpeechRecognitionUtility::CBody::GetAllModelIDs(TModelBankID aModelBankID, RArray <TModelID>& aModelIDs)
1.442 + {
1.443 + if (iAsyncCallBusy)
1.444 + return KErrInUse;
1.445 +
1.446 + ASSERT(iModelIDs==NULL);
1.447 +
1.448 + TInt err = iSrCustomCommands.GetAllModelIDs(aModelBankID);
1.449 +
1.450 + if (err==KErrNone)
1.451 + {
1.452 + iModelIDs = &aModelIDs;
1.453 + iModelIDs->Reset();
1.454 + iAsyncCallBusy = ETrue;
1.455 + }
1.456 + return err;
1.457 + }
1.458 +
1.459 +
1.460 +TInt CSpeechRecognitionUtility::CBody::GetAllRuleIDs(TGrammarID aGrammarID, RArray <TRuleID>& aRuleIDs)
1.461 + {
1.462 + if (iAsyncCallBusy)
1.463 + return KErrInUse;
1.464 +
1.465 + ASSERT(iRuleIDs==NULL);
1.466 +
1.467 + TInt err = iSrCustomCommands.GetAllRuleIDs(aGrammarID);
1.468 +
1.469 + if (err==KErrNone)
1.470 + {
1.471 + iRuleIDs = &aRuleIDs;
1.472 + iRuleIDs->Reset();
1.473 + iAsyncCallBusy = ETrue;
1.474 + }
1.475 + return err;
1.476 + }
1.477 +
1.478 +
1.479 +TInt CSpeechRecognitionUtility::CBody::GetAllClientLexiconIDs(RArray <TLexiconID>& aLexiconIDs)
1.480 + {
1.481 + if (iAsyncCallBusy)
1.482 + return KErrInUse;
1.483 +
1.484 + ASSERT(iLexiconIDs==NULL);
1.485 +
1.486 + TInt err = iSrCustomCommands.GetAllClientLexiconIDs();
1.487 +
1.488 + if (err==KErrNone)
1.489 + {
1.490 + iLexiconIDs = &aLexiconIDs;
1.491 + iLexiconIDs->Reset();
1.492 + iAsyncCallBusy = ETrue;
1.493 + }
1.494 +
1.495 + return err;
1.496 + }
1.497 +
1.498 +TInt CSpeechRecognitionUtility::CBody::GetAllClientModelBankIDs(RArray <TModelBankID>& aModelBankIDs)
1.499 + {
1.500 + if (iAsyncCallBusy)
1.501 + return KErrInUse;
1.502 +
1.503 + ASSERT(iModelBankIDs==NULL);
1.504 +
1.505 + TInt err = iSrCustomCommands.GetAllClientModelBankIDs();
1.506 +
1.507 + if (err==KErrNone)
1.508 + {
1.509 + iModelBankIDs = &aModelBankIDs;
1.510 + iModelBankIDs->Reset();
1.511 + iAsyncCallBusy = ETrue;
1.512 + }
1.513 + return err;
1.514 + }
1.515 +
1.516 +
1.517 +TInt CSpeechRecognitionUtility::CBody::GetAllClientGrammarIDs(RArray <TGrammarID>& aGrammarIDs)
1.518 + {
1.519 + if (iAsyncCallBusy)
1.520 + return KErrInUse;
1.521 +
1.522 + ASSERT(iGrammarIDs==NULL);
1.523 +
1.524 + TInt err = iSrCustomCommands.GetAllClientGrammarIDs();
1.525 +
1.526 + if (err==KErrNone)
1.527 + {
1.528 + iGrammarIDs = &aGrammarIDs;
1.529 + iGrammarIDs->Reset();
1.530 + iAsyncCallBusy = ETrue;
1.531 + }
1.532 + return err;
1.533 + }
1.534 +
1.535 +
1.536 +TInt CSpeechRecognitionUtility::CBody::GetAllLexiconIDs(RArray <TLexiconID>& aLexiconIDs)
1.537 + {
1.538 + if (iAsyncCallBusy)
1.539 + return KErrInUse;
1.540 +
1.541 + ASSERT(iLexiconIDs==NULL);
1.542 +
1.543 + TInt err = iSrCustomCommands.GetAllLexiconIDs();
1.544 +
1.545 + if (err==KErrNone)
1.546 + {
1.547 + iLexiconIDs = &aLexiconIDs;
1.548 + iLexiconIDs->Reset();
1.549 + iAsyncCallBusy = ETrue;
1.550 + }
1.551 +
1.552 + return err;
1.553 + }
1.554 +
1.555 +TInt CSpeechRecognitionUtility::CBody::GetAllModelBankIDs(RArray <TModelBankID>& aModelBankIDs)
1.556 + {
1.557 + if (iAsyncCallBusy)
1.558 + return KErrInUse;
1.559 +
1.560 + ASSERT(iModelBankIDs==NULL);
1.561 +
1.562 + TInt err = iSrCustomCommands.GetAllModelBankIDs();
1.563 +
1.564 + if (err==KErrNone)
1.565 + {
1.566 + iModelBankIDs = &aModelBankIDs;
1.567 + iModelBankIDs->Reset();
1.568 + iAsyncCallBusy = ETrue;
1.569 + }
1.570 + return err;
1.571 + }
1.572 +
1.573 +
1.574 +TInt CSpeechRecognitionUtility::CBody::GetAllGrammarIDs(RArray <TGrammarID>& aGrammarIDs)
1.575 + {
1.576 + if (iAsyncCallBusy)
1.577 + return KErrInUse;
1.578 +
1.579 + ASSERT(iGrammarIDs==NULL);
1.580 +
1.581 + TInt err = iSrCustomCommands.GetAllGrammarIDs();
1.582 +
1.583 + if (err==KErrNone)
1.584 + {
1.585 + iGrammarIDs = &aGrammarIDs;
1.586 + iGrammarIDs->Reset();
1.587 + iAsyncCallBusy = ETrue;
1.588 + }
1.589 + return err;
1.590 + }
1.591 +
1.592 +
1.593 +TInt CSpeechRecognitionUtility::CBody::GetRuleValidity(TGrammarID aGrammarID, TRuleID aRuleID, TBool& aValid)
1.594 + {
1.595 + if (iAsyncCallBusy)
1.596 + return KErrInUse;
1.597 +
1.598 + TInt err = iSrCustomCommands.GetRuleValidity(aGrammarID, aRuleID, aValid);
1.599 +
1.600 + if (err == KErrNone)
1.601 + iAsyncCallBusy = ETrue;
1.602 + return err;
1.603 + }
1.604 +
1.605 +
1.606 +TInt CSpeechRecognitionUtility::CBody::CreateModelBank(TModelBankID& aModelBankID)
1.607 + {
1.608 + if (iAsyncCallBusy)
1.609 + return KErrInUse;
1.610 + TInt err = iSrCustomCommands.CreateModelBank(aModelBankID);
1.611 + if (err == KErrNone)
1.612 + iAsyncCallBusy = ETrue;
1.613 + return err;
1.614 + }
1.615 +
1.616 +TInt CSpeechRecognitionUtility::CBody::RemoveModelBank(TModelBankID aModelBankID)
1.617 + {
1.618 + if (iAsyncCallBusy)
1.619 + return KErrInUse;
1.620 +
1.621 + TInt err = iSrCustomCommands.RemoveModelBank(aModelBankID);
1.622 + if (err == KErrNone)
1.623 + iAsyncCallBusy = ETrue;
1.624 + return err;
1.625 + }
1.626 +
1.627 +TInt CSpeechRecognitionUtility::CBody::GetAvailableStorage(TInt& aAvailableStorage)
1.628 + {
1.629 + if (iAsyncCallBusy)
1.630 + return KErrInUse;
1.631 +
1.632 + TInt err = iSrCustomCommands.GetAvailableStorage(aAvailableStorage);
1.633 +
1.634 + if (err == KErrNone)
1.635 + iAsyncCallBusy = ETrue;
1.636 +
1.637 + return err;
1.638 + }
1.639 +
1.640 +TInt CSpeechRecognitionUtility::CBody::LoadEngineParameters(const RArray<TInt>& aParameterId, const RArray<TInt>& aParameterValue)
1.641 + {
1.642 + if (iAsyncCallBusy)
1.643 + return KErrInUse;
1.644 +
1.645 + return iSrCustomCommands.LoadEngineParameters(aParameterId, aParameterValue);
1.646 + }
1.647 +
1.648 +TInt CSpeechRecognitionUtility::CBody::SetAudioPriority(TInt aPriority, TInt aTrainPreference, TInt aPlaybackPreference, TInt aRecognitionPreference)
1.649 + {
1.650 + iAudioPriority = aPriority;
1.651 + iTrainPreference = (TMdaPriorityPreference)aTrainPreference;
1.652 + iPlaybackPreference = (TMdaPriorityPreference)aPlaybackPreference;
1.653 + iRecognitionPreference = (TMdaPriorityPreference)aRecognitionPreference;
1.654 +
1.655 + return KErrNone;
1.656 + }
1.657 +
1.658 +void CSpeechRecognitionUtility::CBody::HandleEvent(const TMMFEvent& aEvent)
1.659 + {
1.660 + TBool cancelled = EFalse;
1.661 + TBool asyncCallComplete = ETrue;
1.662 +
1.663 + TUid event = aEvent.iEventType;
1.664 + TInt errorCode = aEvent.iErrorCode;
1.665 +
1.666 +
1.667 + switch (event.iUid)
1.668 + {
1.669 + case KUidAsrEventGetAllPronunciationIDsVal :
1.670 + {
1.671 + if (iPronunciationIDs)
1.672 + {
1.673 + if (errorCode==KErrNone)
1.674 + TRAP(errorCode, iSrCustomCommands.GetPronunciationIDArrayL(*iPronunciationIDs));
1.675 + // async operation complete, so get rid of reference to array
1.676 + iPronunciationIDs = NULL;
1.677 + }
1.678 + else
1.679 + cancelled = ETrue;
1.680 + }
1.681 + break;
1.682 + case KUidAsrEventGetAllRuleIDsVal :
1.683 + {
1.684 + if (iRuleIDs)
1.685 + {
1.686 + if (errorCode==KErrNone)
1.687 + TRAP(errorCode, iSrCustomCommands.GetRuleIDArrayL(*iRuleIDs));
1.688 + // async operation complete, so get rid of reference to array
1.689 + iRuleIDs = NULL;
1.690 + }
1.691 + else
1.692 + cancelled = ETrue;
1.693 + }
1.694 + break;
1.695 + case KUidAsrEventGetAllModelIDsVal :
1.696 + {
1.697 + if (iModelIDs)
1.698 + {
1.699 + if (errorCode==KErrNone)
1.700 + TRAP(errorCode, iSrCustomCommands.GetModelIDArrayL(*iModelIDs));
1.701 + // async operation complete, so get rid of reference to array
1.702 + iModelIDs = NULL;
1.703 + }
1.704 + else
1.705 + cancelled = ETrue;
1.706 + }
1.707 + break;
1.708 + case KUidAsrEventGetAllClientModelBankIDsVal :
1.709 + case KUidAsrEventGetAllModelBankIDsVal :
1.710 + {
1.711 + if (iModelBankIDs)
1.712 + {
1.713 + if (errorCode==KErrNone)
1.714 + TRAP(errorCode, iSrCustomCommands.GetModelBankIDArrayL(*iModelBankIDs));
1.715 + // async operation complete, so get rid of reference to array
1.716 + iModelBankIDs = NULL;
1.717 + }
1.718 + else
1.719 + cancelled = ETrue;
1.720 + }
1.721 + break;
1.722 + case KUidAsrEventGetAllClientGrammarIDsVal :
1.723 + case KUidAsrEventGetAllGrammarIDsVal :
1.724 + {
1.725 + if (iGrammarIDs)
1.726 + {
1.727 + if (errorCode==KErrNone)
1.728 + TRAP(errorCode, iSrCustomCommands.GetGrammarIDArrayL(*iGrammarIDs));
1.729 + // async operation complete, so get rid of reference to array
1.730 + iGrammarIDs = NULL;
1.731 + }
1.732 + else
1.733 + cancelled = ETrue;
1.734 + }
1.735 + break;
1.736 + case KUidAsrEventGetAllClientLexiconIDsVal :
1.737 + case KUidAsrEventGetAllLexiconIDsVal :
1.738 + {
1.739 + if (iLexiconIDs)
1.740 + {
1.741 + if (errorCode==KErrNone)
1.742 + TRAP(errorCode, iSrCustomCommands.GetLexiconIDArrayL(*iLexiconIDs));
1.743 + // async operation complete, so get rid of reference to array
1.744 + iLexiconIDs = NULL;
1.745 + }
1.746 + else
1.747 + cancelled = ETrue;
1.748 + }
1.749 + break;
1.750 +
1.751 + case KUidAsrEventRecognitionVal :
1.752 + {
1.753 + if (iResultSet)
1.754 + {
1.755 + if (errorCode==KErrNone)
1.756 + TRAP(errorCode, iSrCustomCommands.GetResultSetL(*iResultSet));
1.757 + iResultSet = NULL;
1.758 + }
1.759 + else
1.760 + cancelled = ETrue;
1.761 + }
1.762 + break;
1.763 + case KUidAsrEventTrainVal:
1.764 + break;
1.765 + case KUidAsrEventPlayStartedVal:
1.766 + case KUidAsrEventRecordStartedVal:
1.767 + asyncCallComplete = EFalse;
1.768 + break;
1.769 + default:
1.770 + break;
1.771 +
1.772 + }
1.773 + if (event == KMMFErrorCategoryControllerGeneralError)
1.774 + {
1.775 + // clear these, as the error callback
1.776 + iPronunciationIDs = NULL;
1.777 + iRuleIDs = NULL;
1.778 + iModelIDs = NULL;
1.779 + iLexiconIDs = NULL;
1.780 + iGrammarIDs = NULL;
1.781 + iModelBankIDs = NULL;
1.782 + }
1.783 + if (asyncCallComplete)
1.784 + iAsyncCallBusy = EFalse;
1.785 +
1.786 + if (iSpeechRecognitionUtilityObserver && !cancelled)
1.787 + iSpeechRecognitionUtilityObserver->MsruoEvent(event, errorCode);
1.788 +
1.789 + }
1.790 +