srsf/siutility/src/nsssispeechrecognitionutility.cpp
branchRCL_3
changeset 23 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
22:cad71a31b7fc 23:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2004-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This is the implementation of the speech recognition utility.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "rubydebug.h"
       
    21 #include "srsfbldvariant.hrh"
       
    22 #include "nsssispeechrecognitionutility.h"
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS ===============================
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CSISpeechRecognitionUtility::CSISpeechRecognitionUtility
       
    28 // C++ default constructor.
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CSISpeechRecognitionUtility::CSISpeechRecognitionUtility(
       
    32 	MSISpeechRecognitionUtilityObserver& aSpeechRecognitionUtilityObserver ) : 
       
    33 	iSrCustomCommands(iMMFController)
       
    34 	{	
       
    35 
       
    36 	iSpeechRecognitionUtilityObserver = &aSpeechRecognitionUtilityObserver;
       
    37 
       
    38 	}
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CSISpeechRecognitionUtility::CreateInstanceL
       
    42 // Creates instance of CSISpeechRecognitionUtility
       
    43 // Needed when dynamically loading nsssispeechrecognitionutility.dll
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 EXPORT_C TAny* CSISpeechRecognitionUtility::CreateInstanceL()
       
    47     {
       
    48     CSISpeechRecognitionUtility* utility = new (ELeave) CSISpeechRecognitionUtility();
       
    49     return static_cast<MSISpeechRecognitionUtilityBase*>( utility );
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CSISpeechRecognitionUtility::CreateInstanceSecondPhaseL
       
    54 // Does second phase construction after CreateInstanceL
       
    55 // Needed when dynamically loading nsssispeechrecognitionutility.dll
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 EXPORT_C void CSISpeechRecognitionUtility::CreateInstanceSecondPhaseL( TUid aClientUid, 
       
    59                                                                        TUid aPluginUid, 
       
    60                                                                        MSISpeechRecognitionUtilityObserver& aObserver )
       
    61     {
       
    62     ConstructL( aClientUid, aPluginUid, aObserver );
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CSISpeechRecognitionUtility::CSISpeechRecognitionUtility
       
    67 // C++ default constructor.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CSISpeechRecognitionUtility::CSISpeechRecognitionUtility(): iSrCustomCommands( iMMFController )
       
    71     {	
       
    72     // Nothing
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // FindSpeechPluginL
       
    77 // Searches for SI Controller Plugin.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 TUid FindSpeechPluginL()
       
    81     {
       
    82     RUBY_DEBUG_BLOCK( "CSISpeechRecognitionUtility::FindSpeechPluginL" );
       
    83 
       
    84 	RMMFControllerImplInfoArray controllers;
       
    85 	CleanupResetAndDestroyPushL(controllers);
       
    86 
       
    87 	CMMFControllerPluginSelectionParameters* selectionParams = 
       
    88 					CMMFControllerPluginSelectionParameters::NewLC();
       
    89 
       
    90 	// Select the media IDs to allow
       
    91 	RArray<TUid> mediaIds;
       
    92 	CleanupClosePushL(mediaIds);
       
    93 	User::LeaveIfError(mediaIds.Append(KUidMediaTypeSI));
       
    94 	selectionParams->SetMediaIdsL(mediaIds,
       
    95 			CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds);
       
    96 	CleanupStack::PopAndDestroy(&mediaIds);
       
    97 
       
    98 	selectionParams->ListImplementationsL(controllers);	
       
    99 	
       
   100 	// make sure at least on controller has been found
       
   101 	if( ! controllers.Count() )
       
   102 	    {
       
   103         RUBY_DEBUG1( "No controllers found using media type %x", KUidMediaTypeSI );
       
   104 		User::Leave( KErrNotFound );
       
   105     	}
       
   106 
       
   107     TUid result = controllers[0]->Uid();
       
   108 
       
   109     CleanupStack::PopAndDestroy( 2 );
       
   110     return( result );
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CSISpeechRecognitionUtility::ConstructL
       
   115 // Symbian 2nd phase constructor can leave.
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void CSISpeechRecognitionUtility::ConstructL( TUid aClientUid, 
       
   119                                               TUid aPluginUid, 
       
   120                                               MSISpeechRecognitionUtilityObserver& aObserver )
       
   121     {
       
   122     RUBY_DEBUG_BLOCK( "CSISpeechRecognitionUtility::ConstructL" );
       
   123     
       
   124     iSpeechRecognitionUtilityObserver = &aObserver;
       
   125     
       
   126     // dummy priority settings, they are set for real when record, recognize 
       
   127     // and playback are called
       
   128     TMMFPrioritySettings prioritySettings;
       
   129     prioritySettings.iPriority = 0;
       
   130     prioritySettings.iPref = (TMdaPriorityPreference) 0;
       
   131     prioritySettings.iState = EMMFStateIdle; // idle
       
   132     
       
   133     if ( aPluginUid.iUid == 0 )
       
   134         {
       
   135         aPluginUid = FindSpeechPluginL();
       
   136         }
       
   137     
       
   138     // load the controller
       
   139     // coded this way for debugging
       
   140     TInt err;
       
   141     if ((err = iMMFController.Open(aPluginUid, prioritySettings))
       
   142         == KErrNone) 
       
   143         {
       
   144         // start the event monitor
       
   145         iControllerEventMonitor = 
       
   146             CMMFControllerEventMonitor::NewL(*this, iMMFController);
       
   147         iControllerEventMonitor->Start();
       
   148         }
       
   149     else
       
   150         {
       
   151         RUBY_DEBUG2( "Unable to load controller plugin, error = %d, UID = %x", err, aPluginUid.iUid );
       
   152         User::Leave(err);
       
   153         }
       
   154     
       
   155     User::LeaveIfError(iSrCustomCommands.SetClientUid(aClientUid));
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CSISpeechRecognitionUtility::NewL
       
   160 // Two-phased constructor.
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 EXPORT_C CSISpeechRecognitionUtility* CSISpeechRecognitionUtility::NewL(
       
   164 	MSISpeechRecognitionUtilityObserver& aSpeechRecognitionUtilityObserver, TUid aClientUid)
       
   165 	{
       
   166 
       
   167 	CSISpeechRecognitionUtility* self = NewLC(aSpeechRecognitionUtilityObserver, aClientUid);
       
   168 	// remove the pointer from the cleanup stack
       
   169 	CleanupStack::Pop( self );	
       
   170     return self;
       
   171 
       
   172 	}
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CSISpeechRecognitionUtility::NewLC
       
   176 // Two-phased constructor, leaves a pointer to the object on the stack.
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 EXPORT_C CSISpeechRecognitionUtility* CSISpeechRecognitionUtility::NewLC(
       
   180 	MSISpeechRecognitionUtilityObserver& aSpeechRecognitionUtilityObserver, TUid aClientUid)
       
   181 	{
       
   182 
       
   183 	CSISpeechRecognitionUtility* self = new (ELeave)  
       
   184 		CSISpeechRecognitionUtility(aSpeechRecognitionUtilityObserver);
       
   185     // push onto cleanup stack 
       
   186     // (in case self->ConstructL leaves)
       
   187     CleanupStack::PushL(self);
       
   188 	// use two-stage construct
       
   189     // Plugin UID == 0 -> List all plugins and pick any suitable
       
   190     self->ConstructL( aClientUid, KNullUid, aSpeechRecognitionUtilityObserver );
       
   191     return self;
       
   192 	}
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CSISpeechRecognitionUtility::NewL
       
   196 // Two-phased constructor.
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 EXPORT_C CSISpeechRecognitionUtility* CSISpeechRecognitionUtility::NewL(
       
   200 	MSISpeechRecognitionUtilityObserver& aSpeechRecognitionUtilityObserver,
       
   201     TUid aClientUid,
       
   202     TUid aMmfPluginUid )
       
   203     {
       
   204 	CSISpeechRecognitionUtility* self = new (ELeave)  
       
   205 		CSISpeechRecognitionUtility(aSpeechRecognitionUtilityObserver);
       
   206     // push onto cleanup stack 
       
   207     // (in case self->ConstructL leaves)
       
   208     CleanupStack::PushL( self );
       
   209 	// use two-stage construct
       
   210     self->ConstructL(aClientUid, aMmfPluginUid, aSpeechRecognitionUtilityObserver);      
       
   211     CleanupStack::Pop( self );
       
   212     return( NULL );
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // CSISpeechRecognitionUtility::~CSISpeechRecognitionUtility
       
   217 // The destructor.
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 EXPORT_C CSISpeechRecognitionUtility::~CSISpeechRecognitionUtility()
       
   221 	{
       
   222 
       
   223 	// indicate we don't want any callbacks
       
   224 	SetEventHandler(NULL);
       
   225 	// cancel any pending requests
       
   226 	if ( iControllerEventMonitor )	// make sure we have a valid pointer
       
   227 	{
       
   228 		iControllerEventMonitor->Cancel();
       
   229 	}
       
   230 
       
   231 	delete iControllerEventMonitor;
       
   232 	iMMFController.Close();
       
   233 
       
   234     REComSession::FinalClose();
       
   235 	}
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CSISpeechRecognitionUtility::GetEngineProperties
       
   239 // Retreive the properties of the underlying speech recognition engine. Returns
       
   240 // an object containing the engine properties in the aProperties variable.
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 EXPORT_C TInt CSISpeechRecognitionUtility::GetEngineProperties(
       
   244 	const RArray<TInt>& aPropertyId, 
       
   245 	RArray<TInt>& aPropertyValue)
       
   246 	{
       
   247 	return iSrCustomCommands.GetEngineProperties(aPropertyId, 
       
   248 									aPropertyValue);
       
   249 	}
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CSISpeechRecognitionUtility::Adapt
       
   253 // Performs adaptation for acoustic models based on correct result.
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 EXPORT_C TInt CSISpeechRecognitionUtility::Adapt(
       
   257     const CSIClientResultSet& aResultSet,
       
   258     TInt aCorrect )
       
   259     {
       
   260     return iSrCustomCommands.Adapt( aResultSet, aCorrect );
       
   261     }
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CSISpeechRecognitionUtility::AddPronunciation
       
   265 // Adds a new pronunciation into the Lexicon. Returns an the ID of the 
       
   266 // pronunciation in the aPronunciationID variable.
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 EXPORT_C TInt CSISpeechRecognitionUtility::AddPronunciation(
       
   270     TSILexiconID aLexiconID,
       
   271     const TDesC& aTextForTraining,
       
   272     TLanguage aLanguage,
       
   273     TSIPronunciationID& aPronunciationID)
       
   274     {
       
   275     return iSrCustomCommands.AddPronunciation( aLexiconID, aTextForTraining,
       
   276                                                aLanguage, aPronunciationID );
       
   277     }
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // CSISpeechRecognitionUtility::AddRule
       
   281 // Adds a new rule into the Grammar. Returns an the ID of the pronunciation 
       
   282 // in the aPronunciationID variable.
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 EXPORT_C TInt CSISpeechRecognitionUtility::AddRule(
       
   286 	TSIGrammarID aGrammarID, 
       
   287 	TSILexiconID aLexiconID, 
       
   288 	TSIPronunciationID aPronunciationID, 
       
   289 	TSIRuleID& aRuleID)
       
   290 	{
       
   291 
       
   292 	// async
       
   293 	return iSrCustomCommands.AddRule(aGrammarID, aLexiconID, 
       
   294 				aPronunciationID, aRuleID);
       
   295 
       
   296 	}
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CSISpeechRecognitionUtility::AddRuleVariant
       
   300 // Adds a new rule variant for the given pronunciation into the 
       
   301 // specified grammar.
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 EXPORT_C TInt CSISpeechRecognitionUtility::AddRuleVariant(
       
   305     TSIGrammarID aGrammarID,
       
   306     TSILexiconID aLexiconID,
       
   307     RArray<TSIPronunciationID>& aPronunciationIDs,
       
   308     TSIRuleID aRuleID,
       
   309     TSIRuleVariantID& aRuleVariantID )
       
   310     {
       
   311     return iSrCustomCommands.AddRuleVariant( aGrammarID, aLexiconID, aPronunciationIDs, aRuleID, aRuleVariantID );
       
   312     }
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // CSISpeechRecognitionUtility::AddVoiceTag
       
   316 // Adds a new rule for the given phrase into the 
       
   317 // specified grammar.
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 EXPORT_C TInt CSISpeechRecognitionUtility::AddVoiceTag( MDesCArray& aTextArray,
       
   321                                                         const RArray<TLanguage>& aLanguageArray,
       
   322                                                         TSILexiconID aLexiconID,
       
   323                                                         TSIGrammarID aGrammarID,
       
   324                                                         TSIRuleID& aRuleID )
       
   325     {
       
   326     return iSrCustomCommands.AddVoiceTag( aTextArray, aLanguageArray,
       
   327                                           aLexiconID, aGrammarID, aRuleID );
       
   328     }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // CSISpeechRecognitionUtility::AddVoiceTag
       
   332 // Adds a new rule for the given phrase into the 
       
   333 // specified grammar.
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 #ifdef __SINDE_TRAINING
       
   337 EXPORT_C TInt CSISpeechRecognitionUtility::AddVoiceTag( MDesCArray& aTextArray,
       
   338                                                         const RArray<RLanguageArray>& aLanguageArray,
       
   339                                                         TSILexiconID aLexiconID,
       
   340                                                         TSIGrammarID aGrammarID,
       
   341                                                         TSIRuleID& aRuleID )
       
   342     {
       
   343     return iSrCustomCommands.AddVoiceTag( aTextArray, aLanguageArray,
       
   344                                           aLexiconID, aGrammarID, aRuleID );
       
   345     }
       
   346 #else
       
   347 EXPORT_C TInt CSISpeechRecognitionUtility::AddVoiceTag( MDesCArray& /*aTextArray*/,
       
   348                                                         const RArray<RLanguageArray>& /*aLanguageArray*/,
       
   349                                                         TSILexiconID /*aLexiconID*/,
       
   350                                                         TSIGrammarID /*aGrammarID*/,
       
   351                                                         TSIRuleID& /*aRuleID*/ )
       
   352     {
       
   353     return KErrNotSupported;
       
   354     }
       
   355 #endif // __SINDE_TRAINING
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // CSISpeechRecognitionUtility::AddVoiceTags
       
   359 // Adds a new rules for the given phrases into the 
       
   360 // specified grammar.
       
   361 // -----------------------------------------------------------------------------
       
   362 //
       
   363 EXPORT_C TInt CSISpeechRecognitionUtility::AddVoiceTags( const RPointerArray<MDesCArray>& aTextArrayArray,
       
   364                                                          const RArray<TLanguage>& aLanguageArray,
       
   365                                                          TSILexiconID aLexiconID,
       
   366                                                          TSIGrammarID aGrammarID, 
       
   367                                                          RArray<TSIRuleID>& aRuleIDArray )
       
   368     {
       
   369     if ( iRuleIDs != 0 )
       
   370         {
       
   371         return( KErrInUse );
       
   372         }
       
   373     iRuleIDs = &aRuleIDArray;
       
   374 
       
   375     return iSrCustomCommands.AddVoiceTags( aTextArrayArray, aLanguageArray,
       
   376                                            aLexiconID, aGrammarID, aRuleIDArray);
       
   377     }
       
   378 
       
   379 // -----------------------------------------------------------------------------
       
   380 // CSISpeechRecognitionUtility::AddVoiceTags
       
   381 // Adds a new rules for the given phrases into the 
       
   382 // specified grammar.
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 #ifdef __SINDE_TRAINING
       
   386 EXPORT_C TInt CSISpeechRecognitionUtility::AddVoiceTags( const RPointerArray<MDesCArray>& aTextArrayArray,
       
   387                                                          const RArray<RLanguageArray>& aLanguageArray,
       
   388                                                          TSILexiconID aLexiconID,
       
   389                                                          TSIGrammarID aGrammarID, 
       
   390                                                          RArray<TSIRuleID>& aRuleIDArray )
       
   391     {
       
   392     if ( iRuleIDs != 0 )
       
   393         {
       
   394         return( KErrInUse );
       
   395         }
       
   396     iRuleIDs = &aRuleIDArray;
       
   397 
       
   398     return iSrCustomCommands.AddVoiceTags( aTextArrayArray, aLanguageArray,
       
   399                                            aLexiconID, aGrammarID, aRuleIDArray );
       
   400     }
       
   401 #else
       
   402 EXPORT_C TInt CSISpeechRecognitionUtility::AddVoiceTags( const RPointerArray<MDesCArray>& /*aTextArrayArray*/,
       
   403                                                          const RArray<RLanguageArray>& /*aLanguageArray*/,
       
   404                                                          TSILexiconID /*aLexiconID*/,
       
   405                                                          TSIGrammarID /*aGrammarID*/, 
       
   406                                                          RArray<TSIRuleID>& /*aRuleIDArray*/ )
       
   407     {
       
   408     return KErrNotSupported;
       
   409     }
       
   410 #endif // __SINDE_TRAINING
       
   411 
       
   412 // -----------------------------------------------------------------------------
       
   413 // CSISpeechRecognitionUtility::Cancel
       
   414 // Cancel the current asynchronous operation.
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 EXPORT_C void CSISpeechRecognitionUtility::Cancel()
       
   418 	{
       
   419 
       
   420 	iSrCustomCommands.Cancel();
       
   421 
       
   422 	// Now cancel has been called, so we can get rid of pointers
       
   423 	iPronunciationIDs = NULL;
       
   424 	iRuleIDs = NULL;
       
   425 	iModelIDs = NULL;
       
   426 	iResultSet = NULL;
       
   427 	iGrammarIDs = NULL;
       
   428 	iLexiconIDs = NULL;
       
   429 	iModelBankIDs = NULL;
       
   430 
       
   431     iSIResultSet = NULL;
       
   432     iResultSet = NULL;
       
   433 	}
       
   434 
       
   435 // -----------------------------------------------------------------------------
       
   436 // CSpeechRecognitionCustomCommandParser::CommitChanges
       
   437 // Commit the current changes to permanent storage.
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 EXPORT_C TInt CSISpeechRecognitionUtility::CommitChanges()
       
   441 	{
       
   442 
       
   443 	// async
       
   444 	return iSrCustomCommands.CommitChanges();
       
   445 
       
   446 	}
       
   447 
       
   448 // -----------------------------------------------------------------------------
       
   449 // CSISpeechRecognitionUtility::CreateGrammar
       
   450 // Create a new grammar.
       
   451 // -----------------------------------------------------------------------------
       
   452 //
       
   453 EXPORT_C TInt CSISpeechRecognitionUtility::CreateGrammar(
       
   454 	TSIGrammarID& aGrammarID)
       
   455 	{
       
   456 
       
   457 	// async
       
   458 	return iSrCustomCommands.CreateGrammar(aGrammarID);
       
   459 
       
   460 	}
       
   461 
       
   462 // -----------------------------------------------------------------------------
       
   463 // CSISpeechRecognitionUtility::CreateLexicon
       
   464 // Create a new lexicon.
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 EXPORT_C TInt CSISpeechRecognitionUtility::CreateLexicon(
       
   468 	TSILexiconID& aLexiconID)
       
   469 	{
       
   470 
       
   471 	// async
       
   472 	return iSrCustomCommands.CreateLexicon(aLexiconID);
       
   473 
       
   474 	}
       
   475 
       
   476 // -----------------------------------------------------------------------------
       
   477 // CSISpeechRecognitionUtility::CreateRule
       
   478 // Creates a new rule.
       
   479 // -----------------------------------------------------------------------------
       
   480 //
       
   481 EXPORT_C TInt CSISpeechRecognitionUtility::CreateRule(
       
   482     TSIGrammarID aGrammarID,
       
   483     TSIRuleID& aRuleID )
       
   484     {
       
   485     return iSrCustomCommands.CreateRule( aGrammarID, aRuleID );
       
   486     }
       
   487 
       
   488 // -----------------------------------------------------------------------------
       
   489 // CSISpeechRecognitionUtility::LoadModels
       
   490 // Loads the model specified by aModelBankID into the recognizer.
       
   491 // -----------------------------------------------------------------------------
       
   492 //
       
   493 EXPORT_C TInt CSISpeechRecognitionUtility::LoadModels(
       
   494 	TSIModelBankID aModelBankID)
       
   495 	{
       
   496 
       
   497 	// async
       
   498 	return iSrCustomCommands.LoadModels(aModelBankID);
       
   499 
       
   500 	}
       
   501 
       
   502 // -----------------------------------------------------------------------------
       
   503 // CSISpeechRecognitionUtility::LoadGrammar
       
   504 // Loads the grammar specified by aGrammarID into the recognizer.
       
   505 // -----------------------------------------------------------------------------
       
   506 //
       
   507 EXPORT_C TInt CSISpeechRecognitionUtility::LoadGrammar(
       
   508 	TSIGrammarID aGrammarID)
       
   509 	{
       
   510 
       
   511 	// async
       
   512 	return iSrCustomCommands.LoadGrammar(aGrammarID);
       
   513 	
       
   514 	}
       
   515 
       
   516 // -----------------------------------------------------------------------------
       
   517 // CSISpeechRecognitionUtility::ActivateGrammar
       
   518 // Activates the grammar.
       
   519 // -----------------------------------------------------------------------------
       
   520 //
       
   521 EXPORT_C TInt CSISpeechRecognitionUtility::ActivateGrammar(
       
   522 	TSIGrammarID aGrammarID)
       
   523 	{
       
   524 
       
   525 	// async
       
   526 	return iSrCustomCommands.ActivateGrammar(aGrammarID);
       
   527 	
       
   528 	}
       
   529 
       
   530 // -----------------------------------------------------------------------------
       
   531 // CSISpeechRecognitionUtility::DeactivateGrammar
       
   532 // Deactivates the grammar.
       
   533 // -----------------------------------------------------------------------------
       
   534 //
       
   535 EXPORT_C TInt CSISpeechRecognitionUtility::DeactivateGrammar(
       
   536 	TSIGrammarID aGrammarID)
       
   537 	{
       
   538 
       
   539 	// async
       
   540 	return iSrCustomCommands.DeactivateGrammar(aGrammarID);
       
   541 	
       
   542 	}
       
   543 
       
   544 // -----------------------------------------------------------------------------
       
   545 // CSISpeechRecognitionUtility::LoadLexicon
       
   546 // Loads the lexicon specified by aLexiconID into the recognizer.
       
   547 // -----------------------------------------------------------------------------
       
   548 //
       
   549 EXPORT_C TInt CSISpeechRecognitionUtility::LoadLexicon(
       
   550 	TSILexiconID aLexiconID)
       
   551 	{
       
   552 
       
   553 	// async
       
   554 	return iSrCustomCommands.LoadLexicon(aLexiconID);
       
   555 
       
   556 	}
       
   557 
       
   558 // -----------------------------------------------------------------------------
       
   559 // CSISpeechRecognitionUtility::GetModelCount
       
   560 // Returns the number of models in the model bank specified by aModelBankID.
       
   561 // -----------------------------------------------------------------------------
       
   562 //
       
   563 EXPORT_C TInt CSISpeechRecognitionUtility::GetModelCount(
       
   564 	TSIModelBankID aModelBankID, 
       
   565 	TInt& aModelCount)
       
   566 	{
       
   567 
       
   568 	// async
       
   569 	return iSrCustomCommands.GetModelCount(aModelBankID, aModelCount);
       
   570 
       
   571 	}
       
   572 
       
   573 // -----------------------------------------------------------------------------
       
   574 // CSISpeechRecognitionUtility::EndRecSession
       
   575 // Ends the current recognition session and frees the associated resources.
       
   576 // -----------------------------------------------------------------------------
       
   577 //
       
   578 EXPORT_C TInt CSISpeechRecognitionUtility::EndRecSession()
       
   579 	{
       
   580 
       
   581 	return iSrCustomCommands.EndRecSession();
       
   582 
       
   583 	}
       
   584 
       
   585 
       
   586 // -----------------------------------------------------------------------------
       
   587 // CSISpeechRecognitionUtility::EndRecSession
       
   588 // Start a recognition session and and allocate the required resources.
       
   589 // -----------------------------------------------------------------------------
       
   590 //
       
   591 EXPORT_C TInt CSISpeechRecognitionUtility::StartRecSession(
       
   592 	TNSSRecognitionMode aMode)
       
   593 	{
       
   594 
       
   595 	return iSrCustomCommands.StartRecSession(aMode);
       
   596 
       
   597 	}
       
   598 
       
   599 // -----------------------------------------------------------------------------
       
   600 // CSISpeechRecognitionUtility::Recognize
       
   601 // Initiates recognition.
       
   602 // -----------------------------------------------------------------------------
       
   603 //
       
   604 EXPORT_C TInt CSISpeechRecognitionUtility::Recognize(
       
   605 	CSIClientResultSet& aResultSet)
       
   606 	{
       
   607     if ( iSIResultSet != NULL || iResultSet != NULL )
       
   608         {
       
   609         return( KErrInUse );
       
   610         }
       
   611 	TInt err = iSrCustomCommands.Recognize( aResultSet );
       
   612 
       
   613     if ( err == KErrNone )
       
   614         {
       
   615         iSIResultSet = &aResultSet;
       
   616         }
       
   617 
       
   618     return( err );
       
   619 	}
       
   620 
       
   621 // -----------------------------------------------------------------------------
       
   622 // CSISpeechRecognitionUtility::Record
       
   623 // Begins recording the utterance for aRecordTime microseconds.
       
   624 // -----------------------------------------------------------------------------
       
   625 //
       
   626 EXPORT_C TInt CSISpeechRecognitionUtility::Record(
       
   627 	TTimeIntervalMicroSeconds32 aRecordTime)
       
   628 	{
       
   629     // setup the priority for recognition
       
   630 	TMMFPrioritySettings prioritySettings;
       
   631 	prioritySettings.iPriority = iAudioPriority;
       
   632 	prioritySettings.iPref = (TMdaPriorityPreference) iRecognitionPreference;
       
   633 	prioritySettings.iState = EMMFStateIdle; // idle
       
   634 	iMMFController.SetPrioritySettings(prioritySettings);
       
   635 
       
   636 	// async
       
   637 	return iSrCustomCommands.Record(aRecordTime);
       
   638 
       
   639 	}
       
   640 
       
   641 // -----------------------------------------------------------------------------
       
   642 // CSISpeechRecognitionUtility::EndRecord
       
   643 // Begins recording the utterance for aRecordTime microseconds.
       
   644 // -----------------------------------------------------------------------------
       
   645 //
       
   646 EXPORT_C TInt CSISpeechRecognitionUtility::EndRecord()
       
   647 	{
       
   648     return iSrCustomCommands.EndRecord();
       
   649 	}
       
   650 	
       
   651 // -----------------------------------------------------------------------------
       
   652 // CSISpeechRecognitionUtility::PreStartSampling
       
   653 // Begins sampling before the actual recognition.
       
   654 // -----------------------------------------------------------------------------
       
   655 //	
       
   656 EXPORT_C TInt CSISpeechRecognitionUtility::PreStartSampling()
       
   657     {
       
   658     return iSrCustomCommands.PreStartSampling();
       
   659     }
       
   660 
       
   661 // -----------------------------------------------------------------------------
       
   662 // CSISpeechRecognitionUtility::RemoveGrammar
       
   663 // Removes the grammer specified by aGrammarID from permanent storage.
       
   664 // -----------------------------------------------------------------------------
       
   665 //
       
   666 EXPORT_C TInt CSISpeechRecognitionUtility::RemoveGrammar(
       
   667 	TSIGrammarID aGrammarID)
       
   668 	{
       
   669 
       
   670 	// async
       
   671 	return iSrCustomCommands.RemoveGrammar(aGrammarID);
       
   672 
       
   673 	}
       
   674 
       
   675 // -----------------------------------------------------------------------------
       
   676 // CSISpeechRecognitionUtility::RemovePronunciation
       
   677 // Removes the pronunciation specified by aPronunciationID from permanent storage.
       
   678 // -----------------------------------------------------------------------------
       
   679 //
       
   680 EXPORT_C TInt CSISpeechRecognitionUtility::RemovePronunciation(
       
   681 	TSILexiconID aLexiconID, 
       
   682 	TSIPronunciationID aPronunciationID)
       
   683 	{
       
   684 
       
   685 	// async
       
   686 	return iSrCustomCommands.RemovePronunciation(aLexiconID, aPronunciationID);
       
   687 
       
   688 	}
       
   689 
       
   690 // -----------------------------------------------------------------------------
       
   691 // CSISpeechRecognitionUtility::RemoveLexicon
       
   692 // Removes the lexicon specified by aLexiconID from permanent storage.
       
   693 // -----------------------------------------------------------------------------
       
   694 //
       
   695 EXPORT_C TInt CSISpeechRecognitionUtility::RemoveLexicon(
       
   696 	TSILexiconID aLexiconID)
       
   697 	{
       
   698 
       
   699 	// async
       
   700 	return iSrCustomCommands.RemoveLexicon(aLexiconID);
       
   701 
       
   702 	}
       
   703 
       
   704 // -----------------------------------------------------------------------------
       
   705 // CSISpeechRecognitionUtility::RemoveModel
       
   706 // Removes the model specified by aModelID from permanent storage.
       
   707 // -----------------------------------------------------------------------------
       
   708 //
       
   709 EXPORT_C TInt CSISpeechRecognitionUtility::RemoveModel(
       
   710 	TSIModelBankID aModelBankID, 
       
   711 	TSIModelID aModelID)
       
   712 	{
       
   713 
       
   714 	// async
       
   715 	return iSrCustomCommands.RemoveModel(aModelBankID, aModelID);
       
   716 
       
   717 	}
       
   718 
       
   719 // -----------------------------------------------------------------------------
       
   720 // CSISpeechRecognitionUtility::RemoveRule
       
   721 // Removes the rule specified by aRuleID from permanent storage.
       
   722 // -----------------------------------------------------------------------------
       
   723 //
       
   724 EXPORT_C TInt CSISpeechRecognitionUtility::RemoveRule(
       
   725 	TSIGrammarID aGrammarID, 
       
   726 	TSIRuleID aRuleID)
       
   727 	{
       
   728 
       
   729 	// async
       
   730 	return iSrCustomCommands.RemoveRule(aGrammarID, aRuleID);
       
   731 
       
   732 	}
       
   733 
       
   734 // -----------------------------------------------------------------------------
       
   735 // CSISpeechRecognitionUtility::RemoveRules
       
   736 // Removes the rule specified by aRuleID from permanent storage.
       
   737 // -----------------------------------------------------------------------------
       
   738 //
       
   739 EXPORT_C TInt CSISpeechRecognitionUtility::RemoveRules(
       
   740 	TSIGrammarID aGrammarID, 
       
   741 	RArray<TSIRuleID>& aRuleIDs)
       
   742 	{
       
   743 
       
   744 	// async
       
   745 	return iSrCustomCommands.RemoveRules(aGrammarID, aRuleIDs);
       
   746 
       
   747 	}
       
   748 
       
   749 // -----------------------------------------------------------------------------
       
   750 // CSISpeechRecognitionUtility::UnloadRule
       
   751 // Unloads a rule temporary memory. The rule in the permanent storage is not 
       
   752 // removed.
       
   753 // -----------------------------------------------------------------------------
       
   754 //
       
   755 EXPORT_C TInt CSISpeechRecognitionUtility::UnloadRule(
       
   756 	TSIGrammarID aGrammarID, 
       
   757 	TSIRuleID aRuleID)
       
   758 	{
       
   759 
       
   760 	// async
       
   761 	return iSrCustomCommands.UnloadRule(aGrammarID, aRuleID);
       
   762 
       
   763 	}
       
   764 
       
   765 // -----------------------------------------------------------------------------
       
   766 // CSISpeechRecognitionUtility::UnloadGrammar
       
   767 // Unloads the specified grammar from the list of grammars
       
   768 // in temporary memory, previously loaded with LoadGrammarL.  
       
   769 // The grammar in the permanent storage remains intact.
       
   770 // -----------------------------------------------------------------------------
       
   771 //
       
   772 EXPORT_C TInt CSISpeechRecognitionUtility::UnloadGrammar(
       
   773     TSIGrammarID aGrammarID )
       
   774     {
       
   775     return iSrCustomCommands.UnloadGrammar( aGrammarID );
       
   776     }
       
   777 
       
   778 // -----------------------------------------------------------------------------
       
   779 // CSISpeechRecognitionUtility::SetEventHandler
       
   780 // Sets the callback address for asynchronous functions.
       
   781 // -----------------------------------------------------------------------------
       
   782 //
       
   783 EXPORT_C void CSISpeechRecognitionUtility::SetEventHandler(
       
   784 	MSISpeechRecognitionUtilityObserver* aSpeechRecognitionUtilityObserver)
       
   785 	{
       
   786 
       
   787 	// save the new event handler callback address
       
   788 	iSpeechRecognitionUtilityObserver = aSpeechRecognitionUtilityObserver;
       
   789 
       
   790 	}
       
   791 
       
   792 // -----------------------------------------------------------------------------
       
   793 // CSISpeechRecognitionUtility::GetAllPronunciationIDs
       
   794 // Returns all pronunciation IDs that exist in the aLexiconID lexicon.
       
   795 // -----------------------------------------------------------------------------
       
   796 //
       
   797 EXPORT_C TInt CSISpeechRecognitionUtility::GetAllPronunciationIDs(
       
   798 	TSILexiconID aLexiconID, 
       
   799 	RArray <TSIPronunciationID>& aPronunciationIDs)
       
   800 	{
       
   801 
       
   802 	if (iPronunciationIDs != NULL)
       
   803 	{
       
   804 		return KErrInUse;
       
   805 	}
       
   806 
       
   807 	TInt err = iSrCustomCommands.GetAllPronunciationIDs(aLexiconID);
       
   808 	
       
   809 	
       
   810 	if (err == KErrNone)
       
   811 	{
       
   812 		iPronunciationIDs = &aPronunciationIDs;
       
   813 	}
       
   814 	
       
   815 	return err;
       
   816 
       
   817 	}
       
   818 
       
   819 // -----------------------------------------------------------------------------
       
   820 // CSpeechRecognitionCustomCommandParser::GetAllClientGrammarIDs
       
   821 // Returns all client grammar IDs.
       
   822 // -----------------------------------------------------------------------------
       
   823 //
       
   824 EXPORT_C TInt CSISpeechRecognitionUtility::GetAllClientGrammarIDs( 
       
   825 	RArray <TSIGrammarID>& aGrammarIDs )
       
   826 	{
       
   827 
       
   828 
       
   829 	if (iGrammarIDs != NULL)
       
   830 	{
       
   831 		return KErrInUse;
       
   832 	}
       
   833 
       
   834 	TInt err = iSrCustomCommands.GetAllClientGrammarIDs();
       
   835 	
       
   836 	if (err == KErrNone)
       
   837 	{
       
   838 		iGrammarIDs = &aGrammarIDs;
       
   839 	}
       
   840 	
       
   841 	return err;
       
   842 
       
   843 	}
       
   844 
       
   845 // -----------------------------------------------------------------------------
       
   846 // CSpeechRecognitionCustomCommandParser::GetAllClientLexiconIDs
       
   847 // Returns all client lexicon IDs.
       
   848 // -----------------------------------------------------------------------------
       
   849 //
       
   850 EXPORT_C TInt CSISpeechRecognitionUtility::GetAllClientLexiconIDs( 
       
   851 	RArray <TSILexiconID>& aLexiconIDs )
       
   852 	{
       
   853 
       
   854 	if (iLexiconIDs != NULL)
       
   855 	{
       
   856 		return KErrInUse;
       
   857 	}
       
   858 
       
   859 	TInt err = iSrCustomCommands.GetAllClientLexiconIDs();
       
   860 	
       
   861 	if (err == KErrNone)
       
   862 	{
       
   863 		iLexiconIDs = &aLexiconIDs;
       
   864 	}
       
   865 	
       
   866 	return err;
       
   867 
       
   868 	}
       
   869 
       
   870 // -----------------------------------------------------------------------------
       
   871 // CSpeechRecognitionCustomCommandParser::GetAllClientModelBankIDs
       
   872 // Returns all client model bank IDs.
       
   873 // -----------------------------------------------------------------------------
       
   874 //
       
   875 EXPORT_C TInt CSISpeechRecognitionUtility::GetAllClientModelBankIDs( 
       
   876 	RArray <TSIModelBankID>& aModelBankIDs )
       
   877 	{
       
   878 
       
   879 	if (iModelBankIDs != NULL)
       
   880 	{
       
   881 		return KErrInUse;
       
   882 	}
       
   883 
       
   884 	TInt err = iSrCustomCommands.GetAllClientModelBankIDs();
       
   885 	
       
   886 	if (err == KErrNone)
       
   887 	{
       
   888 		iModelBankIDs = &aModelBankIDs;
       
   889 	}
       
   890 	
       
   891 	return err;
       
   892 
       
   893 	}
       
   894 
       
   895 
       
   896 // -----------------------------------------------------------------------------
       
   897 // CSpeechRecognitionCustomCommandParser::GetAllGrammarIDs
       
   898 // Returns all grammar IDs for all clients.
       
   899 // -----------------------------------------------------------------------------
       
   900 //
       
   901 EXPORT_C TInt CSISpeechRecognitionUtility::GetAllGrammarIDs( 
       
   902 	RArray <TSIGrammarID>& aGrammarIDs )
       
   903 	{
       
   904 
       
   905 	if (iGrammarIDs != NULL)
       
   906 	{
       
   907 		return KErrInUse;
       
   908 	}
       
   909 
       
   910 	TInt err = iSrCustomCommands.GetAllGrammarIDs();
       
   911 	
       
   912 	if (err == KErrNone)
       
   913 	{
       
   914 		iGrammarIDs = &aGrammarIDs;
       
   915 	}
       
   916 	
       
   917 	return err;
       
   918 
       
   919 	}
       
   920 
       
   921 // -----------------------------------------------------------------------------
       
   922 // CSpeechRecognitionCustomCommandParser::GetAllLexiconIDs
       
   923 // Returns all lexicon IDs for all clients.
       
   924 // -----------------------------------------------------------------------------
       
   925 //
       
   926 EXPORT_C TInt CSISpeechRecognitionUtility::GetAllLexiconIDs( 
       
   927 	RArray <TSILexiconID>& aLexiconIDs )
       
   928 	{
       
   929 
       
   930 	if (iLexiconIDs != NULL)
       
   931 	{
       
   932 		return KErrInUse;
       
   933 	}
       
   934 
       
   935 	TInt err = iSrCustomCommands.GetAllLexiconIDs();
       
   936 	
       
   937 	if (err == KErrNone)
       
   938 	{
       
   939 		iLexiconIDs = &aLexiconIDs;
       
   940 	}
       
   941 	
       
   942 	return err;
       
   943 
       
   944 	}
       
   945 
       
   946 // -----------------------------------------------------------------------------
       
   947 // CSpeechRecognitionCustomCommandParser::GetAllModelBankIDs
       
   948 // Returns all model bank IDs for all clients.
       
   949 // -----------------------------------------------------------------------------
       
   950 //
       
   951 EXPORT_C TInt CSISpeechRecognitionUtility::GetAllModelBankIDs( 
       
   952 	RArray <TSIModelBankID>& aModelBankIDs )
       
   953 	{
       
   954 
       
   955 	if (iModelBankIDs != NULL)
       
   956 	{
       
   957 		return KErrInUse;
       
   958 	}
       
   959 
       
   960 	TInt err = iSrCustomCommands.GetAllModelBankIDs();
       
   961 	
       
   962 	if (err == KErrNone)
       
   963 	{
       
   964 		iModelBankIDs = &aModelBankIDs;
       
   965 	}
       
   966 
       
   967 	return err;
       
   968 
       
   969 	}
       
   970 
       
   971 
       
   972 // -----------------------------------------------------------------------------
       
   973 // CSISpeechRecognitionUtility::GetAllModelIDs
       
   974 // Returns all model IDs that exist in the aModelBankID bank.
       
   975 // -----------------------------------------------------------------------------
       
   976 //
       
   977 EXPORT_C TInt CSISpeechRecognitionUtility::GetAllModelIDs(
       
   978 	TSIModelBankID aModelBankID, 
       
   979 	RArray <TSIModelID>& aModelIDs)
       
   980 	{
       
   981 
       
   982 	if (iModelIDs != NULL)
       
   983 	{
       
   984 		return KErrInUse;
       
   985 	}
       
   986 
       
   987 	TInt err = iSrCustomCommands.GetAllModelIDs(aModelBankID);
       
   988 	
       
   989 	if (err == KErrNone)
       
   990 	{
       
   991 		iModelIDs = &aModelIDs;
       
   992 	}
       
   993 
       
   994 	return err;
       
   995 	
       
   996 	}
       
   997 
       
   998 // -----------------------------------------------------------------------------
       
   999 // CSISpeechRecognitionUtility::GetRuleValidity
       
  1000 // Returns whether the specified rule is valid in the aValid variable.
       
  1001 // -----------------------------------------------------------------------------
       
  1002 //
       
  1003 EXPORT_C TInt CSISpeechRecognitionUtility::GetRuleValidity(
       
  1004 	TSIGrammarID aGrammarID, 
       
  1005 	TSIRuleID aRuleID, 
       
  1006 	TBool& aValid)
       
  1007 	{
       
  1008 
       
  1009 	// async
       
  1010 	return iSrCustomCommands.GetRuleValidity(aGrammarID, aRuleID, aValid);
       
  1011 
       
  1012 	}
       
  1013 
       
  1014 // -----------------------------------------------------------------------------
       
  1015 // CSISpeechRecognitionUtility::GetAllRuleIDs
       
  1016 // Returns all grammar IDs that exist in the aGrammarID bank.
       
  1017 // -----------------------------------------------------------------------------
       
  1018 //
       
  1019 EXPORT_C TInt CSISpeechRecognitionUtility::GetAllRuleIDs(
       
  1020 	TSIGrammarID aGrammarID, 
       
  1021 	RArray <TSIRuleID>& aRuleIDs)
       
  1022 	{
       
  1023 
       
  1024 	if (iRuleIDs != NULL)
       
  1025 	{
       
  1026 		return KErrInUse;
       
  1027 	}
       
  1028 		
       
  1029 	TInt err = iSrCustomCommands.GetAllRuleIDs(aGrammarID);
       
  1030 	
       
  1031 	if (err == KErrNone)	
       
  1032 	{
       
  1033 		iRuleIDs = &aRuleIDs;
       
  1034 	}
       
  1035 		
       
  1036 	return err;
       
  1037 	
       
  1038 	}
       
  1039 
       
  1040 // -----------------------------------------------------------------------------
       
  1041 // CSISpeechRecognitionUtility::CreateModelBank
       
  1042 // Creates a model bank and returns ID of the new model bank in aModelBankID.
       
  1043 // -----------------------------------------------------------------------------
       
  1044 //
       
  1045 EXPORT_C TInt CSISpeechRecognitionUtility::CreateModelBank(
       
  1046 	TSIModelBankID& aModelBankID)
       
  1047 	{
       
  1048 
       
  1049 	// async
       
  1050 	return iSrCustomCommands.CreateModelBank(aModelBankID);
       
  1051 
       
  1052 	}
       
  1053 
       
  1054 // -----------------------------------------------------------------------------
       
  1055 // CSISpeechRecognitionUtility::RemoveModelBank
       
  1056 // Removes the model bank specified by aModelBankID from permanent storage.
       
  1057 // -----------------------------------------------------------------------------
       
  1058 //
       
  1059 EXPORT_C TInt CSISpeechRecognitionUtility::RemoveModelBank(
       
  1060 	TSIModelBankID aModelBankID)
       
  1061 	{
       
  1062 
       
  1063 	// async
       
  1064 	return iSrCustomCommands.RemoveModelBank(aModelBankID);
       
  1065 
       
  1066 	}
       
  1067 
       
  1068 // -----------------------------------------------------------------------------
       
  1069 // CSISpeechRecognitionUtility::LoadEngineParameters
       
  1070 // Sends a command to the controller to load the parameters into
       
  1071 // the engine.
       
  1072 // -----------------------------------------------------------------------------
       
  1073 //
       
  1074 EXPORT_C TInt CSISpeechRecognitionUtility::LoadEngineParameters(
       
  1075 	const RArray<TInt>& aParameterId, 
       
  1076 	const RArray<TInt>& aParameterValue)
       
  1077 	{
       
  1078 
       
  1079 	return iSrCustomCommands.LoadEngineParameters(aParameterId, aParameterValue);
       
  1080 
       
  1081 	}
       
  1082 
       
  1083 // -----------------------------------------------------------------------------
       
  1084 // CSISpeechRecognitionUtility::SetAudioPriority
       
  1085 // Set the audio priority and preference for training, recognition and
       
  1086 // playback.
       
  1087 // -----------------------------------------------------------------------------
       
  1088 //
       
  1089 EXPORT_C TInt CSISpeechRecognitionUtility::SetAudioPriority(
       
  1090 	TInt aPriority, 
       
  1091 	TInt aTrainPreference, 
       
  1092 	TInt aPlaybackPreference, 
       
  1093 	TInt aRecognitionPreference)
       
  1094 	{
       
  1095 	
       
  1096 	iAudioPriority = aPriority;
       
  1097 	iTrainPreference = aTrainPreference;
       
  1098 	iPlaybackPreference = aPlaybackPreference;
       
  1099 	iRecognitionPreference = aRecognitionPreference;
       
  1100 
       
  1101 	return KErrNone;
       
  1102 
       
  1103 	}
       
  1104 
       
  1105 
       
  1106 // -----------------------------------------------------------------------------
       
  1107 // CSISpeechRecognitionUtility::HandleEvent
       
  1108 // Callback function for asynchrounus events. Settting the address to NULL
       
  1109 // insures no unexpected callback will occur.
       
  1110 // -----------------------------------------------------------------------------
       
  1111 //
       
  1112 void CSISpeechRecognitionUtility::HandleEvent( const TMMFEvent& aEvent )
       
  1113 	{
       
  1114 
       
  1115 	TBool cancelled = EFalse;
       
  1116 
       
  1117 	TInt event = (TInt)aEvent.iEventType.iUid;
       
  1118 	TInt result = (TInt)aEvent.iErrorCode;
       
  1119 
       
  1120     RUBY_DEBUG2( "CSISpeechRecognitionUtility::HandleEvent() - Event Type = %d, Event Result = %d", event, result );
       
  1121 
       
  1122 	switch (event)
       
  1123 	    {
       
  1124 		case KUidAsrEventGetAllPronunciationIDsVal:
       
  1125 			if (iPronunciationIDs)
       
  1126 			{
       
  1127 				if ( result == KErrNone )
       
  1128 				{
       
  1129 					TRAP(result, 
       
  1130 						iSrCustomCommands.GetPronunciationIDArrayL(*iPronunciationIDs));
       
  1131 				}
       
  1132 				// async operation complete, so no need to store pointer anymore
       
  1133 				iPronunciationIDs = NULL;
       
  1134 			}
       
  1135 			else 
       
  1136 			{
       
  1137 				cancelled = ETrue;
       
  1138 			}
       
  1139 			break;
       
  1140 		
       
  1141 
       
  1142 		case KUidAsrEventGetAllRuleIDsVal:
       
  1143 			if (iRuleIDs)
       
  1144 			{
       
  1145 				if ( result == KErrNone )
       
  1146 				{
       
  1147 					TRAP(result, iSrCustomCommands.GetRuleIDArrayL(*iRuleIDs));		
       
  1148 				}
       
  1149 				// async operation complete, so no need to store pointer anymore	
       
  1150 				iRuleIDs = NULL;
       
  1151 			}
       
  1152 			else
       
  1153 			{
       
  1154 				cancelled = ETrue;
       
  1155 			}
       
  1156 			break;
       
  1157 
       
  1158 		case KUidAsrEventGetAllModelIDsVal:
       
  1159 			if (iModelIDs)
       
  1160 			{
       
  1161 				if ( result == KErrNone )
       
  1162 				{
       
  1163 					TRAP(result, iSrCustomCommands.GetModelIDArrayL(*iModelIDs));
       
  1164 				}
       
  1165 				// async operation complete, so no need to store pointer anymore
       
  1166 				iModelIDs = NULL;
       
  1167 			}
       
  1168 			else
       
  1169 			{
       
  1170 				cancelled = ETrue;
       
  1171 			}
       
  1172 			break;
       
  1173 
       
  1174 		case KUidAsrEventRecordVal:
       
  1175 			// if the record function has an error during recognition 
       
  1176 			// then clear iResultSet pointer.
       
  1177 			if ( (iResultSet) && (result != KErrNone) )
       
  1178 			{
       
  1179 				// async operation complete, so no need to store pointer anymore
       
  1180 				iResultSet = NULL;
       
  1181 			}
       
  1182 			break;
       
  1183 
       
  1184 		// both of these conditions can use the same functionality
       
  1185 		case KUidAsrEventGetAllClientGrammarIDsVal:
       
  1186 		case KUidAsrEventGetAllGrammarIDsVal:
       
  1187 			if (iGrammarIDs)
       
  1188 			{
       
  1189 				if ( result == KErrNone )
       
  1190 				{
       
  1191 					TRAP(result, iSrCustomCommands.GetGrammarIDArrayL(*iGrammarIDs));
       
  1192 				}
       
  1193 				// async operation complete, so no need to store pointer anymore
       
  1194 				iGrammarIDs = NULL;
       
  1195 			}
       
  1196 			else
       
  1197 			{
       
  1198 				cancelled = ETrue;
       
  1199 			}
       
  1200 			break;
       
  1201 
       
  1202 		// both of these conditions can use the same functionality
       
  1203 		case KUidAsrEventGetAllClientLexiconIDsVal:
       
  1204 		case KUidAsrEventGetAllLexiconIDsVal:
       
  1205 			if (iLexiconIDs)
       
  1206 			{
       
  1207 				if ( result == KErrNone )
       
  1208 				{
       
  1209 					TRAP(result, iSrCustomCommands.GetLexiconIDArrayL(*iLexiconIDs));
       
  1210 				}
       
  1211 				// async operation complete, so no need to store pointer anymore
       
  1212 				iLexiconIDs = NULL;
       
  1213 			}
       
  1214 			else
       
  1215 			{
       
  1216 				cancelled = ETrue;
       
  1217 			}
       
  1218 			break;
       
  1219 
       
  1220 		// both of these conditions can use the same functionality
       
  1221 		case KUidAsrEventGetAllClientModelBankIDsVal:
       
  1222 		case KUidAsrEventGetAllModelBankIDsVal:
       
  1223 
       
  1224 			if (iModelBankIDs)
       
  1225 			{
       
  1226 				if ( result == KErrNone )
       
  1227 				{
       
  1228 					TRAP(result, iSrCustomCommands.GetModelBankIDArrayL(*iModelBankIDs));
       
  1229 				}
       
  1230 				// async operation complete, so no need to store pointer anymore
       
  1231 				iModelBankIDs = NULL;
       
  1232 			}
       
  1233 			else
       
  1234 			{
       
  1235 				cancelled = ETrue;
       
  1236 			}
       
  1237 			break;
       
  1238 
       
  1239         // SI functions, which require postprocessing
       
  1240         case KUidAsrEventAddVoiceTagsVal:
       
  1241 
       
  1242 			if (iRuleIDs)
       
  1243 			{
       
  1244 				if ( result == KErrNone )
       
  1245 				{
       
  1246 					TRAP(result, 
       
  1247 						iSrCustomCommands.GetRuleIDArrayL(*iRuleIDs));
       
  1248 				}
       
  1249 				// async operation complete, so no need to store pointer anymore
       
  1250 				iRuleIDs = NULL;
       
  1251 			}
       
  1252 			else 
       
  1253 			{
       
  1254 				cancelled = ETrue;
       
  1255 			}
       
  1256             break;
       
  1257 
       
  1258         case KUidAsrEventRecognitionVal:
       
  1259 
       
  1260 			if (iSIResultSet)
       
  1261 			{
       
  1262 				if ( result == KErrNone )
       
  1263 				{
       
  1264 					TRAP(result, iSrCustomCommands.GetSIResultSetL(*iSIResultSet));
       
  1265 				}
       
  1266 				// async operation complete, so no need to store pointer anymore
       
  1267 				iSIResultSet = NULL;
       
  1268 			}
       
  1269 			else
       
  1270 			{
       
  1271 				cancelled = ETrue;
       
  1272 			}
       
  1273 			break;
       
  1274           
       
  1275 		default:
       
  1276 			break;
       
  1277 	
       
  1278 	    }
       
  1279 
       
  1280 	if ( iSpeechRecognitionUtilityObserver && !cancelled )
       
  1281         {
       
  1282         iSpeechRecognitionUtilityObserver->MsruoEvent( aEvent.iEventType, result );
       
  1283         }
       
  1284 	}
       
  1285 
       
  1286 // end of file