srsf/sicc/src/nsssispeechrecognitioncustomcommands.cpp
changeset 13 57b735022c18
parent 1 b13cd05eeb2f
equal deleted inserted replaced
1:b13cd05eeb2f 13:57b735022c18
     1 /*
       
     2 * Copyright (c) 2004-2006 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 client interface for the
       
    15 *               speaker independent custom commands.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "srsfbldvariant.hrh"
       
    22 #include "nsssispeechrecognitioncustomcommands.h"
       
    23 #include <nsssispeechrecognitiondatacommon.h>
       
    24 #include <badesca.h>
       
    25 #include "nsssispeechrecognitioncustomcommandcommon.h"
       
    26 #include "nsssicustomcommanddata.h"
       
    27 #include "rubydebug.h"
       
    28 
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // RSISpeechRecognitionCustomCommands::RSISpeechRecognitionCustomCommands
       
    34 // C++ constructor.
       
    35 // -----------------------------------------------------------------------------
       
    36 
       
    37 EXPORT_C RSISpeechRecognitionCustomCommands::RSISpeechRecognitionCustomCommands(
       
    38 	RMMFController& aController) :
       
    39 	RMMFCustomCommandsBase(aController, 
       
    40 	KUidInterfaceSpeakerIndependent)
       
    41 	{
       
    42 
       
    43 	}
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // RSISpeechRecognitionCustomCommands::AddRule
       
    47 // Sends a command to the controller to add a rule.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 EXPORT_C TInt RSISpeechRecognitionCustomCommands::AddRule(
       
    51 	TSIGrammarID aGrammarID, 
       
    52 	TSILexiconID aLexiconID, 
       
    53 	TSIPronunciationID aPronunciationID, 
       
    54 	TSIRuleID& aRuleID)
       
    55 	{
       
    56 
       
    57 	TSrsAddRule srsAddRule(aGrammarID, aLexiconID, aPronunciationID, &aRuleID);
       
    58 	TSrsAddRulePckg pckg(srsAddRule);
       
    59 	return iController.CustomCommandSync(iDestinationPckg, ESrAddRule,
       
    60 											pckg, KNullDesC8); // Async
       
    61 
       
    62 	}
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // RSISpeechRecognitionCustomCommands::Cancel
       
    66 // Sends a command to the controller to cancel the currect asynchronous 
       
    67 // operation.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 EXPORT_C void RSISpeechRecognitionCustomCommands::Cancel()
       
    71 	{
       
    72 
       
    73 	iController.CustomCommandSync(iDestinationPckg, ESrCancel,
       
    74 											KNullDesC8, KNullDesC8);
       
    75 
       
    76 	}
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // RSISpeechRecognitionCustomCommands::CommitChanges
       
    80 // Sends a command to the controller to commit the current changes.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 EXPORT_C TInt RSISpeechRecognitionCustomCommands::CommitChanges()
       
    84 	{
       
    85 
       
    86 	return iController.CustomCommandSync(iDestinationPckg, ESrCommitChanges,
       
    87 											KNullDesC8, KNullDesC8); // Async
       
    88 
       
    89 	}
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // RSISpeechRecognitionCustomCommands::CreateGrammar
       
    93 // Sends a command to the controller to create a grammar.
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 EXPORT_C TInt RSISpeechRecognitionCustomCommands::CreateGrammar(
       
    97 	TSIGrammarID& aGrammarID)
       
    98 	{
       
    99 
       
   100 	TSrsGrammarIDPtrPckg srsGrammarIDPtrPckg = &aGrammarID;
       
   101 	return iController.CustomCommandSync(iDestinationPckg, ESrCreateGrammar,
       
   102 											srsGrammarIDPtrPckg, KNullDesC8);
       
   103 
       
   104 	}
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // RSISpeechRecognitionCustomCommands::CreateLexicon
       
   108 // Sends a command to the controller to create a lexicon.
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 EXPORT_C TInt RSISpeechRecognitionCustomCommands::CreateLexicon(
       
   112 	TSILexiconID& aLexiconID)
       
   113 	{
       
   114 
       
   115 	TSrsLexiconIDPtrPckg srsLexiconIDPtrPckg = &aLexiconID;
       
   116 	return iController.CustomCommandSync(iDestinationPckg, ESrCreateLexicon,
       
   117 											srsLexiconIDPtrPckg, KNullDesC8);
       
   118 
       
   119 	}
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // RSISpeechRecognitionCustomCommands::CreateModelBank
       
   123 // Sends a command to the controller to create a model bank.
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 EXPORT_C TInt RSISpeechRecognitionCustomCommands::CreateModelBank(
       
   127 	TSIModelBankID& aModelBankID)
       
   128 	{
       
   129 
       
   130 	TSrsModelBankIDPtrPckg modelBankIDPtrPckg = &aModelBankID;
       
   131 	return iController.CustomCommandSync(iDestinationPckg, ESrCreateModelBank,
       
   132 											modelBankIDPtrPckg, KNullDesC8);
       
   133 	
       
   134 	}
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // RSISpeechRecognitionCustomCommands::EndRecSession
       
   138 // Sends a command to the controller to end the current recognition session and 
       
   139 // free the allocated resources.
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 EXPORT_C TInt RSISpeechRecognitionCustomCommands::EndRecSession()
       
   143 	{
       
   144 
       
   145 	TInt err = iController.CustomCommandSync(iDestinationPckg, ESrEndRecSession,
       
   146 											KNullDesC8, KNullDesC8);
       
   147 	return err;
       
   148 
       
   149 	}
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // RSISpeechRecognitionCustomCommands::GetAllClientGrammarIDs
       
   153 // Calls the controller plugin to get all client grammar IDs.
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 EXPORT_C TInt RSISpeechRecognitionCustomCommands::GetAllClientGrammarIDs()
       
   157 	{
       
   158 
       
   159 	return iController.CustomCommandSync(iDestinationPckg, 
       
   160 			ESrGetAllClientGrammarIDs, KNullDesC8, KNullDesC8); // Async
       
   161 
       
   162 	}
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // RSISpeechRecognitionCustomCommands::GetAllClientLexiconIDs
       
   166 // Calls the controller plugin to get all client lexicon IDs.
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 EXPORT_C TInt RSISpeechRecognitionCustomCommands::GetAllClientLexiconIDs()
       
   170 	{
       
   171 
       
   172 	return iController.CustomCommandSync(iDestinationPckg, 
       
   173 			ESrGetAllClientLexiconIDs, KNullDesC8, KNullDesC8); // Async
       
   174 
       
   175 	}
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // RSISpeechRecognitionCustomCommands::GetAllClientModelBankIDs
       
   179 // Calls the controller plugin to get all client model bank IDs.
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 EXPORT_C TInt RSISpeechRecognitionCustomCommands::GetAllClientModelBankIDs()
       
   183 	{
       
   184 
       
   185 	return iController.CustomCommandSync(iDestinationPckg, ESrGetAllClientModelBankIDs,
       
   186 							KNullDesC8, KNullDesC8); // Async
       
   187 
       
   188 	}
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // RSISpeechRecognitionCustomCommands::GetAllGrammarIDs
       
   192 // Calls the controller plugin to get all grammar IDs for all clients.
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 EXPORT_C TInt RSISpeechRecognitionCustomCommands::GetAllGrammarIDs()
       
   196 	{
       
   197 
       
   198 	return iController.CustomCommandSync(iDestinationPckg, ESrGetAllGrammarIDs,
       
   199 							KNullDesC8, KNullDesC8); // Async
       
   200 	
       
   201 	}
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // RSISpeechRecognitionCustomCommands::GetAllLexiconIDs
       
   205 // Calls the controller plugin to get all lexicon IDs for all clients.
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 EXPORT_C TInt RSISpeechRecognitionCustomCommands::GetAllLexiconIDs()
       
   209 	{	
       
   210 
       
   211 	return iController.CustomCommandSync(iDestinationPckg, ESrGetAllLexiconIDs,
       
   212 							KNullDesC8, KNullDesC8); // Async
       
   213 
       
   214 	}
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // RSISpeechRecognitionCustomCommands::GetAllModelBankIDs
       
   218 // Calls the controller plugin to get all model bank IDs.
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 EXPORT_C TInt RSISpeechRecognitionCustomCommands::GetAllModelBankIDs()
       
   222 	{
       
   223 
       
   224 	return iController.CustomCommandSync(iDestinationPckg, ESrGetAllModelBankIDs,
       
   225 							KNullDesC8, KNullDesC8); // Async
       
   226 
       
   227 	}
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // RSISpeechRecognitionCustomCommands::GetAllModelIDs
       
   231 // Sends a command to the controller to get all model IDs from a model bank.
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 EXPORT_C TInt RSISpeechRecognitionCustomCommands::GetAllModelIDs(
       
   235 	TSIModelBankID aModelBankID)
       
   236 	{
       
   237 
       
   238 	TSrsModelBankIDPckg modelBankIDPckg = aModelBankID;
       
   239 
       
   240 	return iController.CustomCommandSync(iDestinationPckg, ESrGetAllModelIDs,
       
   241 							modelBankIDPckg, KNullDesC8); // Async
       
   242 
       
   243 	}
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // RSISpeechRecognitionCustomCommands::GetAllPronunciationIDs
       
   247 // Sends a command to the controller to get all pronunciation IDs from a lexicon.
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 EXPORT_C TInt RSISpeechRecognitionCustomCommands::GetAllPronunciationIDs(
       
   251 	TSILexiconID aLexiconID)
       
   252 	{
       
   253 
       
   254 	TSrsLexiconIDPckg lexiconIDPckg = aLexiconID;
       
   255 	return iController.CustomCommandSync(iDestinationPckg, 
       
   256 						ESrGetAllPronunciationIDs,
       
   257 						lexiconIDPckg, KNullDesC8); // Async
       
   258 
       
   259 	}
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // RSISpeechRecognitionCustomCommands::GetAllRuleIDs
       
   263 // Sends a command to the controller to get all rule IDs from a grammar.
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 EXPORT_C TInt RSISpeechRecognitionCustomCommands::GetAllRuleIDs(
       
   267 	TSIGrammarID aGrammarID)
       
   268 	{
       
   269 
       
   270 	TSrsGrammarIDPckg grammarIDPckg = aGrammarID;
       
   271 
       
   272 	return iController.CustomCommandSync(iDestinationPckg, ESrGetAllRuleIDs,
       
   273 							grammarIDPckg, KNullDesC8); // Async
       
   274 
       
   275 	}
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // RSISpeechRecognitionCustomCommands::GetEngineProperties
       
   279 // Sends a command to the controller to get the engine properties.
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 EXPORT_C TInt RSISpeechRecognitionCustomCommands::GetEngineProperties(
       
   283 	const RArray<TInt>& aPropertyId, 
       
   284 	RArray<TInt>& aPropertyValue)
       
   285 	{
       
   286 
       
   287 	TRAPD(err, DoGetEnginePropertiesL(aPropertyId, aPropertyValue));
       
   288 	return err;	
       
   289 
       
   290 	}
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // RSISpeechRecognitionCustomCommands::GetModelCount
       
   294 // Sends a command to the controller to get the number of models in a model bank.
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 EXPORT_C TInt RSISpeechRecognitionCustomCommands::GetModelCount(
       
   298 	TSIModelBankID aModelBankID, TInt& aModelCount)
       
   299 	{
       
   300 
       
   301 	TSrsModelBankIDPckg modelBankPckg = aModelBankID;
       
   302 	TSrsIntPtrPckg modelCountPtrPckg = &aModelCount;
       
   303 
       
   304 	return iController.CustomCommandSync(iDestinationPckg, ESrGetModelCount,
       
   305 											modelBankPckg, modelCountPtrPckg);
       
   306 
       
   307 	}
       
   308 
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // RSISpeechRecognitionCustomCommands::GetRuleValidity
       
   312 // Sends a command to the controller to determine if a rule is valid.
       
   313 // -----------------------------------------------------------------------------
       
   314 //
       
   315 EXPORT_C TInt RSISpeechRecognitionCustomCommands::GetRuleValidity(
       
   316 	TSIGrammarID aGrammarID, 
       
   317 	TSIRuleID aRuleID, TBool& aValid)
       
   318 	{
       
   319 
       
   320 	TSrsRuleValidity srsRuleValidity(aGrammarID, aRuleID, &aValid);
       
   321 	TSrsRuleValidityPckg srsRuleValidityPckg(srsRuleValidity);
       
   322 
       
   323 	return iController.CustomCommandSync(iDestinationPckg, ESrGetRuleValidity,
       
   324 											srsRuleValidityPckg, KNullDesC8);
       
   325 
       
   326 	}
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // RSISpeechRecognitionCustomCommands::LoadGrammar
       
   330 // Sends a command to the controller to load the specified grammar.
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 EXPORT_C TInt RSISpeechRecognitionCustomCommands::LoadGrammar(
       
   334 	TSIGrammarID aGrammarID)
       
   335 	{
       
   336 
       
   337 	TSrsGrammarIDPckg pckg = aGrammarID;
       
   338 	return iController.CustomCommandSync(iDestinationPckg, ESrLoadGrammar,
       
   339 											pckg, KNullDesC8); // Async
       
   340 
       
   341 	}
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // RSISpeechRecognitionCustomCommands::ActivateGrammar
       
   345 // Sends a command to the controller to activate a grammar
       
   346 // -----------------------------------------------------------------------------
       
   347 //
       
   348 EXPORT_C TInt RSISpeechRecognitionCustomCommands::ActivateGrammar(
       
   349 	TSIGrammarID aGrammarID)
       
   350 	{
       
   351 	TSrsGrammarIDPckg pckg = aGrammarID;
       
   352 	return iController.CustomCommandSync( iDestinationPckg, ESrActivateGrammar,
       
   353                                           pckg, KNullDesC8 ); // Async
       
   354 
       
   355 	}
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // RSISpeechRecognitionCustomCommands::DeactivateGrammar
       
   359 // Sends a command to the controller to deactivate a gramamr
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 EXPORT_C TInt RSISpeechRecognitionCustomCommands::DeactivateGrammar(
       
   363 	TSIGrammarID aGrammarID)
       
   364 	{
       
   365 	TSrsGrammarIDPckg pckg = aGrammarID;
       
   366 	return iController.CustomCommandSync( iDestinationPckg, ESrDeactivateGrammar,
       
   367                                           pckg, KNullDesC8); // Async
       
   368 
       
   369 	}
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // RSISpeechRecognitionCustomCommands::LoadLexicon
       
   373 // Sends a command to the controller to load the specified lexican.
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 EXPORT_C TInt RSISpeechRecognitionCustomCommands::LoadLexicon(
       
   377 	TSILexiconID aLexiconID)
       
   378 	{
       
   379 
       
   380 	TSrsLexiconIDPckg pckg = aLexiconID;
       
   381 	return iController.CustomCommandSync(iDestinationPckg, ESrLoadLexicon,
       
   382 											pckg, KNullDesC8); // Async
       
   383 
       
   384 	}
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // RSISpeechRecognitionCustomCommands::LoadModels
       
   388 // Sends a command to the controller to load all models from a model bank.
       
   389 // -----------------------------------------------------------------------------
       
   390 //
       
   391 EXPORT_C TInt RSISpeechRecognitionCustomCommands::LoadModels(
       
   392 	TSIModelBankID aModelBankID)
       
   393 	{
       
   394 
       
   395 	TSrsModelIDPckg pckg = aModelBankID;
       
   396 	return iController.CustomCommandSync(iDestinationPckg, ESrLoadModels,
       
   397 											pckg, KNullDesC8);  // Async
       
   398 
       
   399 	}
       
   400 
       
   401 // -----------------------------------------------------------------------------
       
   402 // RSISpeechRecognitionCustomCommands::Record
       
   403 // Sends a command to the controller to start recording an utterance for either 
       
   404 // training or recognition
       
   405 // -----------------------------------------------------------------------------
       
   406 //
       
   407 EXPORT_C TInt RSISpeechRecognitionCustomCommands::Record(
       
   408 	TTimeIntervalMicroSeconds32 aRecordTime)
       
   409 	{
       
   410 
       
   411 	TSrsTimeIntervalMicroSeconds32Pckg pckg = aRecordTime;
       
   412 	return iController.CustomCommandSync(iDestinationPckg, ESrRecord,
       
   413 											pckg, KNullDesC8); // Async
       
   414 
       
   415 	}
       
   416 
       
   417 // -----------------------------------------------------------------------------
       
   418 // RSISpeechRecognitionCustomCommands::RemoveGrammar
       
   419 // Sends a command to the controller to remove a grammar.
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 EXPORT_C TInt RSISpeechRecognitionCustomCommands::RemoveGrammar(
       
   423 	TSIGrammarID aGrammarID)
       
   424 	{
       
   425 
       
   426 	TSrsGrammarIDPckg pckg = aGrammarID;
       
   427 	return iController.CustomCommandSync(iDestinationPckg, ESrRemoveGrammar,
       
   428 											pckg, KNullDesC8);
       
   429 
       
   430 	}
       
   431 
       
   432 // -----------------------------------------------------------------------------
       
   433 // RSISpeechRecognitionCustomCommands::RemoveLexicon
       
   434 // Sends a command to the controller to remove a lexicon.
       
   435 // -----------------------------------------------------------------------------
       
   436 //
       
   437 EXPORT_C TInt RSISpeechRecognitionCustomCommands::RemoveLexicon(
       
   438 	TSILexiconID aLexiconID)
       
   439 	{
       
   440 
       
   441 	TSrsLexiconIDPckg pckg = aLexiconID;
       
   442 	return iController.CustomCommandSync(iDestinationPckg, ESrRemoveLexicon,
       
   443 											pckg, KNullDesC8);
       
   444 
       
   445 	}
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // RSISpeechRecognitionCustomCommands::RemoveModelBank
       
   449 // Sends a command to the controller to remove a model bank and all associated 
       
   450 // models.
       
   451 // -----------------------------------------------------------------------------
       
   452 //
       
   453 EXPORT_C TInt RSISpeechRecognitionCustomCommands::RemoveModelBank(
       
   454 	TSIModelBankID aModelBankID)
       
   455 	{
       
   456 
       
   457 	TSrsModelBankIDPckg modelBankIDPckg = aModelBankID;
       
   458 	return iController.CustomCommandSync(iDestinationPckg, ESrRemoveModelBank,
       
   459 											modelBankIDPckg, KNullDesC8);
       
   460 
       
   461 	}
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // RSISpeechRecognitionCustomCommands::RemoveModel
       
   465 // Sends a command to the controller to remove a model from a model bank.
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 EXPORT_C TInt RSISpeechRecognitionCustomCommands::RemoveModel(
       
   469 	TSIModelBankID aModelBankID, 
       
   470 	TSIModelID aModelID)
       
   471 	{
       
   472 
       
   473 	TSrsModelBankIDPckg modelBankIDPckg = aModelBankID;
       
   474 	TSrsModelIDPckg modelIDPckg = aModelID;
       
   475 
       
   476 	return iController.CustomCommandSync(iDestinationPckg, ESrRemoveModel,
       
   477 										modelBankIDPckg, modelIDPckg); // Async
       
   478 
       
   479 	}
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // RSISpeechRecognitionCustomCommands::RemovePronunciation
       
   483 // Sends a command to the controller to remove a pronunciation.
       
   484 // -----------------------------------------------------------------------------
       
   485 //
       
   486 EXPORT_C TInt RSISpeechRecognitionCustomCommands::RemovePronunciation(
       
   487 	TSILexiconID aLexiconID, 
       
   488 	TSIPronunciationID aPronunciationID)
       
   489 	{
       
   490 
       
   491 	TSrsLexiconIDPckg lexiconIDPckg = aLexiconID;
       
   492 	TSrsPronunciationIDPckg pronunciationIDPckg = aPronunciationID;
       
   493 
       
   494 	return iController.CustomCommandSync(iDestinationPckg, ESrRemovePronunciation,
       
   495 										lexiconIDPckg, pronunciationIDPckg); // Async
       
   496 
       
   497 	}
       
   498 
       
   499 // -----------------------------------------------------------------------------
       
   500 // RSISpeechRecognitionCustomCommands::RemoveRule
       
   501 // Sends a command to the controller to remove a rule.
       
   502 // -----------------------------------------------------------------------------
       
   503 //
       
   504 EXPORT_C TInt RSISpeechRecognitionCustomCommands::RemoveRule(
       
   505 	TSIGrammarID aGrammarID, 
       
   506 	TSIRuleID aRuleID)
       
   507 	{
       
   508 
       
   509 	TSrsGrammarIDPckg grammarIDPckg = aGrammarID;
       
   510 	TSrsRuleIDPckg ruleIDPckg = aRuleID;
       
   511 
       
   512 	return iController.CustomCommandSync(iDestinationPckg, ESrRemoveRule,
       
   513 											grammarIDPckg, ruleIDPckg); // Async
       
   514 
       
   515 	}
       
   516 
       
   517 // -----------------------------------------------------------------------------
       
   518 // RSISpeechRecognitionCustomCommands::RemoveRules
       
   519 // Sends a command to the controller to remove a rule.
       
   520 // -----------------------------------------------------------------------------
       
   521 //
       
   522 EXPORT_C TInt RSISpeechRecognitionCustomCommands::RemoveRules(
       
   523 	TSIGrammarID aGrammarID, 
       
   524 	RArray<TSIRuleID>& aRuleIDs)
       
   525 	{
       
   526     RUBY_DEBUG1( "RSISpeechRecognitionCustomCommands::RemoveRules GrammarID [%d]", aGrammarID );
       
   527 	
       
   528 	TSrsGrammarIDPckg grammarIDPckg = aGrammarID;
       
   529 
       
   530     CBufFlat* flatBuf = 0;
       
   531     
       
   532     /** @todo Implement externalize, that takes arrays of Uint32? */
       
   533     TRAPD( err, flatBuf
       
   534         = ExternalizeIntArrayL( reinterpret_cast<RArray<TInt>&> ( aRuleIDs ) ) );
       
   535 	
       
   536     if ( err != KErrNone )
       
   537        	{
       
   538        	delete flatBuf;
       
   539        	return err;
       
   540        	}
       
   541 	// SRS will signal, when the rule IDs are ready.
       
   542 	TInt ret = iController.CustomCommandSync(iDestinationPckg, ESrRemoveRules,
       
   543                                              grammarIDPckg, flatBuf->Ptr(0) ); // Async
       
   544     delete flatBuf;
       
   545 
       
   546     return( ret );
       
   547 	}
       
   548 
       
   549 // -----------------------------------------------------------------------------
       
   550 // RSISpeechRecognitionCustomCommands::SetClientUid
       
   551 // Sends a command to the controller to set the client UID.
       
   552 // -----------------------------------------------------------------------------
       
   553 //
       
   554 EXPORT_C TInt RSISpeechRecognitionCustomCommands::SetClientUid( TUid aClientUid )
       
   555 {
       
   556 
       
   557 	TSrsUidPckg uidPckg = aClientUid;
       
   558 	return iController.CustomCommandSync(iDestinationPckg, 
       
   559 						ESrSetClientUid, uidPckg, KNullDesC8);
       
   560 
       
   561 }
       
   562 
       
   563 
       
   564 // -----------------------------------------------------------------------------
       
   565 // RSISpeechRecognitionCustomCommands::StartRecSession
       
   566 // Sends a command to the controller to begin a recognition session.
       
   567 // -----------------------------------------------------------------------------
       
   568 //
       
   569 EXPORT_C TInt RSISpeechRecognitionCustomCommands::StartRecSession(
       
   570 	TNSSRecognitionMode aMode)
       
   571 	{
       
   572 
       
   573 	TSrsRecognitionModePckg recognitionModePckg = aMode;
       
   574 	TInt err = iController.CustomCommandSync(iDestinationPckg, 
       
   575 						ESrStartRecSession, recognitionModePckg, KNullDesC8);
       
   576 
       
   577 	return err;
       
   578 
       
   579 	}
       
   580 
       
   581 // -----------------------------------------------------------------------------
       
   582 // RSISpeechRecognitionCustomCommands::UnloadRule
       
   583 // Sends a command to the controller to add a rule.
       
   584 // -----------------------------------------------------------------------------
       
   585 //
       
   586 EXPORT_C TInt RSISpeechRecognitionCustomCommands::UnloadRule(
       
   587 	TSIGrammarID aGrammarID, 
       
   588 	TSIRuleID aRuleID)
       
   589 	{
       
   590 
       
   591 	TSrsGrammarIDPckg grammarIDPckg = aGrammarID;
       
   592 	TSrsRuleIDPckg ruleIDPtrPckg = aRuleID;
       
   593 
       
   594 	return iController.CustomCommandSync(iDestinationPckg, ESrUnloadRule,
       
   595 											grammarIDPckg, ruleIDPtrPckg);
       
   596 	
       
   597 	}
       
   598 
       
   599 // -----------------------------------------------------------------------------
       
   600 // RSISpeechRecognitionCustomCommands::LoadEngineParameters
       
   601 // Sends a command to the controller to load the parameters into
       
   602 // the engine.
       
   603 // -----------------------------------------------------------------------------
       
   604 //
       
   605 EXPORT_C TInt RSISpeechRecognitionCustomCommands::LoadEngineParameters(
       
   606 	const RArray<TInt>& aParameterId, 
       
   607 	const RArray<TInt>& aParameterValue)
       
   608 	{
       
   609 
       
   610 	TRAPD(error, DoLoadEngineParametersL(aParameterId, aParameterValue));
       
   611 	return error;	
       
   612 
       
   613 	}
       
   614 
       
   615 
       
   616 // -----------------------------------------------------------------------------
       
   617 // RSISpeechRecognitionCustomCommands::GetPronunciationIDArrayL
       
   618 // Sends a command to get the pronunciation ID array.
       
   619 // -----------------------------------------------------------------------------
       
   620 //
       
   621 EXPORT_C void RSISpeechRecognitionCustomCommands::GetPronunciationIDArrayL(
       
   622 	RArray<TSIPronunciationID>& aPronunciationIDs)
       
   623 	{
       
   624 	
       
   625 	TPckgBuf<TInt> pckgSize;
       
   626 	
       
   627 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   628 												ESrGetPronunciationIDArraySize, 
       
   629 												KNullDesC8,
       
   630 												KNullDesC8,
       
   631 												pckgSize));
       
   632 	
       
   633 
       
   634 	HBufC8* buf = HBufC8::NewLC(pckgSize()*sizeof(TUint32));
       
   635 	TPtr8 ptr = buf->Des();
       
   636 
       
   637 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   638 													 ESrGetPronunciationIDArrayContents,
       
   639 													 KNullDesC8,
       
   640 													 KNullDesC8,
       
   641 													 ptr));
       
   642 													 
       
   643 	RDesReadStream stream(ptr);
       
   644 	CleanupClosePushL(stream);
       
   645 
       
   646 	for (TInt i=0; i<pckgSize(); i++)
       
   647 		{
       
   648 		User::LeaveIfError(aPronunciationIDs.Append(stream.ReadUint32L()));
       
   649 		}
       
   650 
       
   651 	CleanupStack::PopAndDestroy(2);//stream, buf
       
   652 		
       
   653 	}
       
   654 
       
   655 // -----------------------------------------------------------------------------
       
   656 // RSISpeechRecognitionCustomCommands::GetRuleIDArrayL
       
   657 // Sends a command to get the rule ID array.
       
   658 // -----------------------------------------------------------------------------
       
   659 //
       
   660 EXPORT_C void RSISpeechRecognitionCustomCommands::GetRuleIDArrayL(
       
   661 	RArray<TSIRuleID>& aRuleIDs)
       
   662 	{
       
   663 
       
   664 	TPckgBuf<TInt> pckgSize;
       
   665 	
       
   666 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   667 												ESrGetRuleIDArraySize, 
       
   668 												KNullDesC8,
       
   669 												KNullDesC8,
       
   670 												pckgSize));
       
   671 												
       
   672 	HBufC8* buf = HBufC8::NewLC(pckgSize()*sizeof(TUint32));
       
   673 	TPtr8 ptr = buf->Des();
       
   674 
       
   675 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   676 													 ESrGetRuleIDArrayContents,
       
   677 													 KNullDesC8,
       
   678 													 KNullDesC8,
       
   679 													 ptr));
       
   680 													 
       
   681 	RDesReadStream stream(ptr);
       
   682 	CleanupClosePushL(stream);
       
   683 
       
   684 	for (TInt i=0; i<pckgSize(); i++)
       
   685 		{
       
   686 		User::LeaveIfError(aRuleIDs.Append(stream.ReadUint32L()));
       
   687 		}
       
   688 
       
   689 	CleanupStack::PopAndDestroy(2);//stream, buf
       
   690 	
       
   691 	}
       
   692 
       
   693 // -----------------------------------------------------------------------------
       
   694 // RSISpeechRecognitionCustomCommands::GetModelIDArrayL
       
   695 // Sends a command to get the model ID array.
       
   696 // -----------------------------------------------------------------------------
       
   697 //	
       
   698 EXPORT_C void RSISpeechRecognitionCustomCommands::GetModelIDArrayL(
       
   699 	RArray<TSIModelID>& aModelIDs)
       
   700 	{
       
   701 
       
   702 	TPckgBuf<TInt> pckgSize;
       
   703 	
       
   704 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   705 												ESrGetModelIDArraySize, 
       
   706 												KNullDesC8,
       
   707 												KNullDesC8,
       
   708 												pckgSize));
       
   709 												
       
   710 	HBufC8* buf = HBufC8::NewLC(pckgSize()*sizeof(TUint32));
       
   711 	TPtr8 ptr = buf->Des();
       
   712 
       
   713 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   714 													 ESrGetModelIDArrayContents,
       
   715 													 KNullDesC8,
       
   716 													 KNullDesC8,
       
   717 													 ptr));
       
   718 													 
       
   719 	RDesReadStream stream(ptr);
       
   720 	CleanupClosePushL(stream);
       
   721 
       
   722 	for (TInt i=0; i<pckgSize(); i++)
       
   723 		{
       
   724 		User::LeaveIfError( aModelIDs.Append( (TSIModelID)stream.ReadUint32L() ) );
       
   725 		}
       
   726 
       
   727 	CleanupStack::PopAndDestroy( 2 );//stream, buf
       
   728 	
       
   729 	}
       
   730 
       
   731 // -----------------------------------------------------------------------------
       
   732 // RSISpeechRecognitionCustomCommands::GetGrammarIDArrayL
       
   733 // Sends a command to get the grammar ID array.
       
   734 // -----------------------------------------------------------------------------
       
   735 //
       
   736 EXPORT_C void RSISpeechRecognitionCustomCommands::GetGrammarIDArrayL(
       
   737 	RArray<TSIGrammarID>& aGrammarIDs)
       
   738 	{
       
   739 
       
   740 	TPckgBuf<TInt> pckgSize;
       
   741 	
       
   742 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   743 												ESrGetGrammarIDArraySize, 
       
   744 												KNullDesC8,
       
   745 												KNullDesC8,
       
   746 												pckgSize));
       
   747 												
       
   748 	HBufC8* buf = HBufC8::NewLC(pckgSize()*sizeof(TUint32));
       
   749 	TPtr8 ptr = buf->Des();
       
   750 
       
   751 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   752 													 ESrGetGrammarIDArrayContents,
       
   753 													 KNullDesC8,
       
   754 													 KNullDesC8,
       
   755 													 ptr));
       
   756 													 
       
   757 	RDesReadStream stream(ptr);
       
   758 	CleanupClosePushL(stream);
       
   759 
       
   760 	for ( TInt i = 0; i < pckgSize(); i++ )
       
   761 		{
       
   762 		User::LeaveIfError( aGrammarIDs.Append( (TSIGrammarID)stream.ReadUint32L() ) );
       
   763 		}
       
   764 
       
   765 	CleanupStack::PopAndDestroy( 2 );//stream, buf
       
   766 	
       
   767 	}
       
   768 
       
   769 // -----------------------------------------------------------------------------
       
   770 // RSISpeechRecognitionCustomCommands::GetLexiconIDArrayL
       
   771 // Sends a command to get the lexicon ID array.
       
   772 // -----------------------------------------------------------------------------
       
   773 //
       
   774 EXPORT_C void RSISpeechRecognitionCustomCommands::GetLexiconIDArrayL(
       
   775 	RArray<TSILexiconID>& aLexiconIDs)
       
   776 	{
       
   777 
       
   778 	TPckgBuf<TInt> pckgSize;
       
   779 
       
   780 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   781 												ESrGetLexiconIDArraySize, 
       
   782 												KNullDesC8,
       
   783 												KNullDesC8,
       
   784 												pckgSize));
       
   785 
       
   786     TInt size = pckgSize();
       
   787 	HBufC8* buf = HBufC8::NewLC(size*sizeof(TUint32));
       
   788 	TPtr8 ptr = buf->Des();
       
   789 
       
   790 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   791 													 ESrGetLexiconIDArrayContents,
       
   792 													 KNullDesC8,
       
   793 													 KNullDesC8,
       
   794 													 ptr));
       
   795 
       
   796 	RDesReadStream stream(ptr);
       
   797 	CleanupClosePushL(stream);
       
   798 
       
   799 	for ( TInt i = 0; i < pckgSize(); i++ )
       
   800 		{
       
   801 		User::LeaveIfError( aLexiconIDs.Append( (TSILexiconID)stream.ReadUint32L() ) );
       
   802 		}
       
   803 
       
   804 	CleanupStack::PopAndDestroy(2);//stream, buf
       
   805 	
       
   806 	}
       
   807 
       
   808 // -----------------------------------------------------------------------------
       
   809 // RSISpeechRecognitionCustomCommands::GetLexiconIDArrayL
       
   810 // Sends a command to get the lexicon ID array.
       
   811 // -----------------------------------------------------------------------------
       
   812 //
       
   813 EXPORT_C void RSISpeechRecognitionCustomCommands::GetModelBankIDArrayL(
       
   814 	RArray<TSIModelBankID>& aModelBankIDs)
       
   815 	{
       
   816 
       
   817 	TPckgBuf<TInt> pckgSize;
       
   818 	
       
   819 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   820 												ESrGetModelBankIDArraySize, 
       
   821 												KNullDesC8,
       
   822 												KNullDesC8,
       
   823 												pckgSize));
       
   824 												
       
   825 	HBufC8* buf = HBufC8::NewLC(pckgSize()*sizeof(TUint32));
       
   826 	TPtr8 ptr = buf->Des();
       
   827 
       
   828 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   829 													 ESrGetModelBankIDArrayContents,
       
   830 													 KNullDesC8,
       
   831 													 KNullDesC8,
       
   832 													 ptr));
       
   833 													 
       
   834 	RDesReadStream stream(ptr);
       
   835 	CleanupClosePushL(stream);
       
   836 
       
   837 	for ( TInt i = 0; i < pckgSize(); i++ )
       
   838 		{
       
   839 		User::LeaveIfError( aModelBankIDs.Append( (TSIModelBankID)stream.ReadUint32L() ) );
       
   840 		}
       
   841 
       
   842 	CleanupStack::PopAndDestroy(2);//stream, buf
       
   843 	
       
   844 	}
       
   845 
       
   846 // -----------------------------------------------------------------------------
       
   847 // RSISpeechRecognitionCustomCommands::GetSIResultSetL
       
   848 // Sends a command to get the speaker independent recognition result set.
       
   849 // -----------------------------------------------------------------------------
       
   850 //	
       
   851 EXPORT_C void RSISpeechRecognitionCustomCommands::GetSIResultSetL(
       
   852 	CSIClientResultSet& aResultSet)
       
   853 	{
       
   854 	
       
   855 	TPckgBuf<TInt> pckgSize;
       
   856 	
       
   857 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   858 												ESrGetClientResultSetSizeSI, 
       
   859 												KNullDesC8,
       
   860 												KNullDesC8,
       
   861 												pckgSize));
       
   862 
       
   863 	HBufC8* buf = HBufC8::NewLC( pckgSize() );
       
   864 	TPtr8 ptr = buf->Des();
       
   865 
       
   866 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   867 													 ESrGetClientResultSet,
       
   868 													 KNullDesC8,
       
   869 													 KNullDesC8,
       
   870 													 ptr));
       
   871 
       
   872 	RDesReadStream stream(ptr);
       
   873 	CleanupClosePushL(stream);
       
   874 
       
   875 	aResultSet.InternalizeL(stream);
       
   876 	CleanupStack::PopAndDestroy(2);//stream, buf
       
   877 
       
   878 	}
       
   879 
       
   880 // -----------------------------------------------------------------------------
       
   881 // RSISpeechRecognitionCustomCommands::DoRecognizeL
       
   882 // Sends a command to get the recognition result set.
       
   883 // -----------------------------------------------------------------------------
       
   884 //	
       
   885 void RSISpeechRecognitionCustomCommands::DoRecognizeL(CSDClientResultSet& /*aResultSet*/)
       
   886 	{
       
   887     RUBY_DEBUG0( "RSISpeechRecognitionCustomCommands::DoRecognizeL is NOT supported" );
       
   888 	User::Leave( KErrNotSupported );
       
   889 	}
       
   890 
       
   891 // -----------------------------------------------------------------------------
       
   892 // RSISpeechRecognitionCustomCommands::DoRecognizeSIL
       
   893 // Sends a command to get the recognition result set.
       
   894 // -----------------------------------------------------------------------------
       
   895 //	
       
   896 void RSISpeechRecognitionCustomCommands::DoRecognizeSIL(CSIClientResultSet& aResultSet)
       
   897 	{
       
   898 	CBufFlat* dataCopyBuffer = CBufFlat::NewL(KExpandSize);
       
   899 	CleanupStack::PushL(dataCopyBuffer);
       
   900 
       
   901 	RBufWriteStream stream;
       
   902 	stream.Open(*dataCopyBuffer);
       
   903 	CleanupClosePushL(stream);
       
   904 
       
   905 	aResultSet.ExternalizeL(stream);
       
   906 
       
   907 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg,
       
   908 												ESrRecognizeSI,
       
   909 												dataCopyBuffer->Ptr(0),
       
   910 												KNullDesC8));
       
   911 
       
   912 	CleanupStack::PopAndDestroy(2); //stream,dataCopyBuffer
       
   913 	}
       
   914 
       
   915 // -----------------------------------------------------------------------------
       
   916 // RSISpeechRecognitionCustomCommands::DoGetEnginePropertiesL
       
   917 // Sends a command to get the engine properties.
       
   918 // -----------------------------------------------------------------------------
       
   919 //	
       
   920 void RSISpeechRecognitionCustomCommands::DoGetEnginePropertiesL(
       
   921 	const RArray<TInt>& aPropertyId, 
       
   922 	RArray<TInt>& aPropertyValue)
       
   923 	{
       
   924 	
       
   925 	CBufFlat* param1 = ExternalizeIntArrayL(aPropertyId);
       
   926 	CleanupStack::PushL(param1);
       
   927 	
       
   928 	TInt aNumberResults = aPropertyId.Count(); // same number of values as properties
       
   929 	
       
   930 	HBufC8* buf = HBufC8::NewLC(aNumberResults *sizeof(TInt));
       
   931 	TPtr8 ptr = buf->Des();
       
   932 
       
   933 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   934 												ESrGetEngineProperties, 
       
   935 												param1->Ptr(0),
       
   936 												KNullDesC8,
       
   937 												ptr));
       
   938 
       
   939 	
       
   940 	InternalizeIntArrayL(ptr,aNumberResults,aPropertyValue);
       
   941 	CleanupStack::PopAndDestroy(2);//buf,param1
       
   942 
       
   943 	}
       
   944 
       
   945 // -----------------------------------------------------------------------------
       
   946 // RSISpeechRecognitionCustomCommands::DoLoadEngineParametersL
       
   947 // Sends a command to load the engine parameters.
       
   948 // -----------------------------------------------------------------------------
       
   949 //	
       
   950 void RSISpeechRecognitionCustomCommands::DoLoadEngineParametersL(
       
   951 	const RArray<TInt>& aParameterId, 
       
   952 	const RArray<TInt>& aParameterValue)
       
   953 	{
       
   954 
       
   955 	CBufFlat* param1 = ExternalizeIntArrayL(aParameterId);
       
   956 	CleanupStack::PushL(param1);
       
   957 	CBufFlat* param2 = ExternalizeIntArrayL(aParameterValue);
       
   958 	CleanupStack::PushL(param2);
       
   959 	User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, 
       
   960 												ESrLoadEngineParameters, 
       
   961 												param1->Ptr(0),
       
   962 												param2->Ptr(0)));
       
   963 												
       
   964 	CleanupStack::PopAndDestroy(2); //param2, param1	
       
   965 
       
   966 	}
       
   967 
       
   968 // -----------------------------------------------------------------------------
       
   969 // RSISpeechRecognitionCustomCommands::ExternalizeIntArrayL
       
   970 // Externalizes an interger array.
       
   971 // -----------------------------------------------------------------------------
       
   972 //	
       
   973 CBufFlat* RSISpeechRecognitionCustomCommands::ExternalizeIntArrayL(
       
   974 	const RArray<TInt>& aArray)
       
   975 	{
       
   976 
       
   977 	CBufFlat* dataCopyBuffer = CBufFlat::NewL(KExpandSize);
       
   978 	CleanupStack::PushL(dataCopyBuffer);
       
   979 	RBufWriteStream stream;
       
   980 	stream.Open(*dataCopyBuffer);
       
   981 	CleanupClosePushL(stream);
       
   982 	
       
   983 	stream.WriteInt32L(aArray.Count());
       
   984 	
       
   985 	for (TInt i=0;i<aArray.Count();i++)
       
   986 		stream.WriteUint32L(aArray[i]);
       
   987 
       
   988 	CleanupStack::PopAndDestroy(1); //stream
       
   989 	CleanupStack::Pop(); //dataCopyBuffer;
       
   990 	return dataCopyBuffer;	
       
   991 	
       
   992 	}
       
   993 
       
   994 // -----------------------------------------------------------------------------
       
   995 // RSISpeechRecognitionCustomCommands::InternalizeIntArrayL
       
   996 // Internalizes an interger array.
       
   997 // -----------------------------------------------------------------------------
       
   998 //
       
   999 void RSISpeechRecognitionCustomCommands::InternalizeIntArrayL(
       
  1000 	TDes8& aDes, 
       
  1001 	TInt aNumberElements, 
       
  1002 	RArray<TInt>& aArray)
       
  1003 	{
       
  1004 
       
  1005 	RDesReadStream stream(aDes);
       
  1006 	CleanupClosePushL(stream);
       
  1007 
       
  1008 	for (TInt i=0; i<aNumberElements; i++)
       
  1009 		{
       
  1010 		User::LeaveIfError(aArray.Append(stream.ReadInt32L()));
       
  1011 		}
       
  1012 
       
  1013 	CleanupStack::PopAndDestroy();//stream
       
  1014 
       
  1015 	}
       
  1016 
       
  1017 /************************** New SI functions start here ***********************/
       
  1018 
       
  1019 // -----------------------------------------------------------------------------
       
  1020 // Adapts speaker independent models according using a correct recognition result.
       
  1021 // -----------------------------------------------------------------------------
       
  1022 //
       
  1023 EXPORT_C TInt RSISpeechRecognitionCustomCommands::Adapt(const CSIClientResultSet& aResultSet, TInt aCorrect)
       
  1024     {
       
  1025     CBufFlat* dataBuf = 0;
       
  1026     RBufWriteStream dataStream;
       
  1027     TInt ret = KErrNone;
       
  1028     TBool forever = ETrue;
       
  1029 
       
  1030     TPckgBuf<TInt> correctPckg( aCorrect );
       
  1031 
       
  1032     while(forever)
       
  1033         {
       
  1034 // Poor man's exception handling: while and break
       
  1035 #define BREAK( error ) if ( error != KErrNone ) { break; }
       
  1036 
       
  1037         // Allocate buffer for storing CSIClientResultSet
       
  1038         TRAP ( ret, dataBuf = CBufFlat::NewL( KExpandSize ) );
       
  1039         BREAK( ret );
       
  1040 
       
  1041         // Open a stream to the buffer
       
  1042         dataStream.Open( *dataBuf );
       
  1043 
       
  1044         // Pack the data
       
  1045         TRAP ( ret, aResultSet.ExternalizeL( dataStream ) );
       
  1046         BREAK( ret );
       
  1047 
       
  1048         // Send through MMF
       
  1049         ret = iController.CustomCommandSync(
       
  1050             iDestinationPckg,
       
  1051             ESrAdapt,
       
  1052             dataBuf->Ptr( 0 ),
       
  1053             correctPckg );
       
  1054 
       
  1055         break;
       
  1056         }
       
  1057 
       
  1058     dataStream.Close();
       
  1059     delete dataBuf;
       
  1060 
       
  1061     return ret;
       
  1062     }
       
  1063 
       
  1064 // -----------------------------------------------------------------------------
       
  1065 // Adds a pronunciation to the given lexicon.
       
  1066 // -----------------------------------------------------------------------------
       
  1067 //
       
  1068 EXPORT_C TInt RSISpeechRecognitionCustomCommands::AddPronunciation(
       
  1069     TSILexiconID aLexiconID,
       
  1070     const TDesC& aTrainText,
       
  1071     TLanguage aLanguage,
       
  1072     TSIPronunciationID& aPronunciationID)
       
  1073     {
       
  1074     TSrsAddPronunciationSI srsAddPronunciation( aLexiconID, aTrainText.Length(),
       
  1075                                                 aLanguage, aPronunciationID );
       
  1076     TSrsAddPronunciationSIPckg pckg( srsAddPronunciation );
       
  1077 
       
  1078     TInt    trainTextSize( aTrainText.Size() );
       
  1079     TUint8* trainTextPtr = (TUint8*)aTrainText.Ptr();
       
  1080     TPtrC8  trainTextDes( trainTextPtr, trainTextSize );
       
  1081 
       
  1082     return iController.CustomCommandSync(iDestinationPckg, ESrAddPronunciationSI,
       
  1083                                          pckg, trainTextDes );
       
  1084     }
       
  1085 
       
  1086 // -----------------------------------------------------------------------------
       
  1087 // Adds a rule variant to a rule in a grammar.
       
  1088 // -----------------------------------------------------------------------------
       
  1089 //
       
  1090 EXPORT_C TInt RSISpeechRecognitionCustomCommands::AddRuleVariant(
       
  1091     TSIGrammarID aGrammarID,
       
  1092     TSILexiconID aLexiconID,
       
  1093     const RArray<TSIPronunciationID>& aPronunciationIDs,
       
  1094     TSIRuleID aRuleID,
       
  1095     TSIRuleVariantID& aRuleVariantID )
       
  1096     {
       
  1097     TSrsAddRuleVariant srsAddRuleVariant( aGrammarID,
       
  1098                                           aLexiconID,
       
  1099                                           aPronunciationIDs.Count(),
       
  1100                                           aRuleID,
       
  1101                                           &aRuleVariantID );
       
  1102     TSrsAddRuleVariantPckg pckg( srsAddRuleVariant );
       
  1103 
       
  1104     TUint8* pronunIdPtr = (TUint8*)&(aPronunciationIDs[0]);
       
  1105     TPtrC8  pronunIdDes( pronunIdPtr, 
       
  1106                          sizeof( TSIPronunciationID ) * aPronunciationIDs.Count()
       
  1107                          );
       
  1108 
       
  1109     return iController.CustomCommandSync(iDestinationPckg, ESrAddRuleVariant,
       
  1110                                          pckg, pronunIdDes );
       
  1111     }
       
  1112 
       
  1113 // -----------------------------------------------------------------------------
       
  1114 // Trains a voice tag. Adds the text to the lexicon, and creates the required
       
  1115 // rules and rule variants.
       
  1116 // -----------------------------------------------------------------------------
       
  1117 //
       
  1118 EXPORT_C TInt RSISpeechRecognitionCustomCommands::AddVoiceTag(
       
  1119     const MDesCArray& aTrainArray,
       
  1120     const RArray<TLanguage>& aLanguageArray,
       
  1121     TSILexiconID aLexiconID,
       
  1122     TSIGrammarID aGrammarID,
       
  1123     TSIRuleID& aRuleID)
       
  1124     {
       
  1125     TSrsAddVoiceTag srsAddVoiceTagData( aLexiconID, aGrammarID, &aRuleID, aLanguageArray );
       
  1126     TSrsAddVoiceTagPckg pckg( srsAddVoiceTagData );
       
  1127 
       
  1128     CBufFlat* flatBuf = 0;
       
  1129     TRAPD( err, flatBuf
       
  1130         = SICustomCommandData::ExternalizeDesCArrayL( aTrainArray ) );
       
  1131 
       
  1132     if ( err != KErrNone )
       
  1133         return( err );
       
  1134 
       
  1135     // SRS will signal, when the rule IDs are ready.
       
  1136 	TInt ret = iController.CustomCommandSync( iDestinationPckg, ESrAddVoiceTag,
       
  1137                                               pckg, flatBuf->Ptr( 0 ) ); // Async
       
  1138 
       
  1139     delete flatBuf;
       
  1140 
       
  1141     return( ret );
       
  1142     }
       
  1143 
       
  1144 // -----------------------------------------------------------------------------
       
  1145 // Trains voice tags. If the training fails for some of the names (but not all),
       
  1146 // it is signaled by setting the Rule ID to KInvalidRuleID.
       
  1147 // -----------------------------------------------------------------------------
       
  1148 //
       
  1149 EXPORT_C TInt RSISpeechRecognitionCustomCommands::AddVoiceTags(
       
  1150     const RPointerArray<MDesCArray>& aTrainArray,
       
  1151     const RArray<TLanguage>& aLanguageArray,
       
  1152     TSILexiconID aLexiconID,
       
  1153     TSIGrammarID aGrammarID,
       
  1154     RArray<TSIRuleID>& /*aRuleID*/)
       
  1155     {
       
  1156     TSrsAddVoiceTag srsAddVoiceTagData( aLexiconID, aGrammarID, NULL, aLanguageArray );
       
  1157     TSrsAddVoiceTagPckg pckg( srsAddVoiceTagData );
       
  1158 
       
  1159     CBufFlat* flatBuf = 0;
       
  1160     TRAPD( err, flatBuf
       
  1161         = SICustomCommandData::ExternalizeDesCArrayArrayL( aTrainArray ) );
       
  1162 
       
  1163     if ( err != KErrNone )
       
  1164         {
       
  1165         delete flatBuf;
       
  1166         return err;
       
  1167         }
       
  1168 
       
  1169     // SRS will signal, when the rule IDs are ready.
       
  1170 	TInt ret = iController.CustomCommandSync( iDestinationPckg, ESrAddVoiceTags,
       
  1171                                               pckg, flatBuf->Ptr( 0 ) ); // Async
       
  1172     delete flatBuf;
       
  1173 
       
  1174     return( ret );
       
  1175     }
       
  1176 
       
  1177 #ifdef __SINDE_TRAINING
       
  1178 // -----------------------------------------------------------------------------
       
  1179 // Trains a voice tag. Adds the text to the lexicon, and creates the required
       
  1180 // rules and rule variants.
       
  1181 // -----------------------------------------------------------------------------
       
  1182 //
       
  1183 EXPORT_C TInt RSISpeechRecognitionCustomCommands::AddVoiceTag( const MDesCArray& aTrainArray,
       
  1184                                                                const RArray<RLanguageArray>& aLanguageArray,
       
  1185                                                                TSILexiconID aLexiconID,
       
  1186                                                                TSIGrammarID aGrammarID,
       
  1187                                                                TSIRuleID& aRuleID )
       
  1188     {
       
  1189     TSrsAddSindeVoiceTag srsAddVoiceTagData( aLexiconID, aGrammarID, &aRuleID, aLanguageArray );
       
  1190     TSrsAddSindeVoiceTagPckg pckg( srsAddVoiceTagData );
       
  1191 
       
  1192     CBufFlat* flatBuf( NULL );
       
  1193     TRAPD( err, flatBuf = SICustomCommandData::ExternalizeDesCArrayL( aTrainArray ) );
       
  1194 
       
  1195     if ( err != KErrNone )
       
  1196         {
       
  1197         return err;
       
  1198         }
       
  1199 
       
  1200     // SRS plugin will signal, when the rule IDs are ready.
       
  1201 	TInt ret = iController.CustomCommandSync( iDestinationPckg, ESrAddSindeVoiceTag,
       
  1202                                               pckg, flatBuf->Ptr( 0 ) ); // Async
       
  1203 
       
  1204     delete flatBuf;
       
  1205 
       
  1206     return ret;
       
  1207     }
       
  1208 
       
  1209 // -----------------------------------------------------------------------------
       
  1210 // Trains voice tags. If the training fails for some of the names (but not all),
       
  1211 // it is signaled by setting the Rule ID to KInvalidRuleID.
       
  1212 // -----------------------------------------------------------------------------
       
  1213 //
       
  1214 EXPORT_C TInt RSISpeechRecognitionCustomCommands::AddVoiceTags( const RPointerArray<MDesCArray>& aTrainArray,
       
  1215                                                                 const RArray<RLanguageArray>& aLanguageArray,
       
  1216                                                                 TSILexiconID aLexiconID,
       
  1217                                                                 TSIGrammarID aGrammarID,
       
  1218                                                                 RArray<TSIRuleID>& /*aRuleID*/)
       
  1219     {
       
  1220     TSrsAddSindeVoiceTag srsAddVoiceTagData( aLexiconID, aGrammarID, NULL, aLanguageArray );
       
  1221     TSrsAddSindeVoiceTagPckg pckg( srsAddVoiceTagData );
       
  1222 
       
  1223     CBufFlat* flatBuf( NULL );
       
  1224     TRAPD( err, flatBuf = SICustomCommandData::ExternalizeDesCArrayArrayL( aTrainArray ) );
       
  1225 
       
  1226     if ( err != KErrNone )
       
  1227         {
       
  1228         delete flatBuf;
       
  1229         return err;
       
  1230         }
       
  1231 
       
  1232     // SRS plugin will signal, when the rule IDs are ready.
       
  1233 	TInt ret = iController.CustomCommandSync( iDestinationPckg, ESrAddSindeVoiceTags,
       
  1234                                               pckg, flatBuf->Ptr( 0 ) ); // Async
       
  1235     delete flatBuf;
       
  1236 
       
  1237     return ret;
       
  1238     }
       
  1239 
       
  1240 // -----------------------------------------------------------------------------
       
  1241 // Pre-starts sampling before Record() call
       
  1242 // -----------------------------------------------------------------------------
       
  1243 //
       
  1244 EXPORT_C TInt RSISpeechRecognitionCustomCommands::PreStartSampling()
       
  1245     {
       
  1246     return iController.CustomCommandSync( iDestinationPckg, ESrPreStartSampling,
       
  1247                                           KNullDesC8, KNullDesC8 ); // Async      
       
  1248     }
       
  1249     
       
  1250 #endif // SINDE_TRAINING
       
  1251 
       
  1252 // -----------------------------------------------------------------------------
       
  1253 // Creates a new rule.
       
  1254 // -----------------------------------------------------------------------------
       
  1255 //
       
  1256 EXPORT_C TInt RSISpeechRecognitionCustomCommands::CreateRule(TSIGrammarID aGrammarID, TSIRuleID& aRuleID)
       
  1257     {
       
  1258     TSrsAddRule srsCreateRule( aGrammarID, KInvalidLexiconID, KInvalidPronunciationID, &aRuleID );
       
  1259     TSrsAddRulePckg pckg( srsCreateRule );
       
  1260 
       
  1261 	return iController.CustomCommandSync(iDestinationPckg, ESrCreateRule,
       
  1262                                          pckg, KNullDesC8 ); // Async    
       
  1263     }
       
  1264 
       
  1265 // -----------------------------------------------------------------------------
       
  1266 // Starts recognition
       
  1267 // -----------------------------------------------------------------------------
       
  1268 //
       
  1269 EXPORT_C TInt RSISpeechRecognitionCustomCommands::Recognize( CSIClientResultSet& aResultSet )
       
  1270     {
       
  1271     TRAPD( err, DoRecognizeSIL( aResultSet ) );
       
  1272     return err;
       
  1273     }
       
  1274 
       
  1275 // -----------------------------------------------------------------------------
       
  1276 // Stops recognition. Unlike Cancel(), this function gives
       
  1277 // the recognition result, if it can be guessed.
       
  1278 // -----------------------------------------------------------------------------
       
  1279 //
       
  1280 EXPORT_C TInt RSISpeechRecognitionCustomCommands::EndRecord()
       
  1281     {
       
  1282     return iController.CustomCommandSync( iDestinationPckg, ESrEndRecord,
       
  1283                                           KNullDesC8, KNullDesC8 ); // Async
       
  1284     }
       
  1285 
       
  1286 // -----------------------------------------------------------------------------
       
  1287 // Deactivates a grammar.
       
  1288 // -----------------------------------------------------------------------------
       
  1289 //
       
  1290 EXPORT_C TInt RSISpeechRecognitionCustomCommands::UnloadGrammar( TSIGrammarID aGrammarID )
       
  1291     {
       
  1292     TSrsGrammarIDPckg pckg( aGrammarID );
       
  1293 
       
  1294 	return iController.CustomCommandSync(iDestinationPckg, ESrUnloadGrammar,
       
  1295                                          pckg, KNullDesC8 ); // Async
       
  1296     }
       
  1297 
       
  1298 
       
  1299 /************************** New SI functions stop here ************************/
       
  1300 
       
  1301 // End of file