srsf/nssvasapi/nssvascore/src/nssvassiutilitywrapper.cpp
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 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:  Class which hides the dynamic loading of 
       
    15 *               nsssispeechrecognitionutility.dll
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32std.h>
       
    22 #include <nsssiutilitybase.h>
       
    23 #include "rubydebug.h"
       
    24 #include "nssvassiutilitywrapper.h"
       
    25 
       
    26 // CONSTANTS
       
    27 // DLL name
       
    28 _LIT( KUtilityFilename, "nsssispeechrecognitionutility.dll" );
       
    29 // CreateInstanceL function ordinal number
       
    30 const TInt KFunctionOrdinal = 1;
       
    31 
       
    32 // ================= MEMBER FUNCTIONS =======================
       
    33 
       
    34 // ---------------------------------------------------------
       
    35 // CNssSiUtilityWrapper::NewL
       
    36 // Two-phased constructor
       
    37 // ---------------------------------------------------------
       
    38 //
       
    39 CNssSiUtilityWrapper* CNssSiUtilityWrapper::NewL( 
       
    40         MSISpeechRecognitionUtilityObserver& aObserver, TUid aClientUid )
       
    41     {
       
    42     CNssSiUtilityWrapper* self = new ( ELeave ) CNssSiUtilityWrapper( aObserver, aClientUid );
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------
       
    50 // CNssSiUtilityWrapper::~CNssSiUtilityWrapper
       
    51 // Destructor
       
    52 // ---------------------------------------------------------
       
    53 //
       
    54 CNssSiUtilityWrapper::~CNssSiUtilityWrapper()
       
    55     {
       
    56     RUBY_DEBUG0( "CNssSiUtilityWrapper::~CNssSiUtilityWrapper" );
       
    57 
       
    58     Cancel();
       
    59 
       
    60     delete iUtility;
       
    61     // Close RLibrary handle
       
    62     iLib.Close();
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------
       
    66 // CNssSiUtilityWrapper::CNssSiUtilityWrapper
       
    67 // C++ constructor
       
    68 // ---------------------------------------------------------
       
    69 //
       
    70 CNssSiUtilityWrapper::CNssSiUtilityWrapper( 
       
    71         MSISpeechRecognitionUtilityObserver& aObserver, TUid aClientUid ) : 
       
    72                                             CActive( EPriorityStandard ), 
       
    73                                             iClientUid( aClientUid ), 
       
    74                                             iObserver( aObserver )
       
    75     {
       
    76     // Nothing
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------
       
    80 // CNssSiUtilityWrapper::ConstructL
       
    81 // Second phase constructor
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 void CNssSiUtilityWrapper::ConstructL()
       
    85     {
       
    86     RUBY_DEBUG_BLOCK( "CNssSiUtilityWrapper::ConstructL" );
       
    87     
       
    88     // Load a DLL based on name with RLibrary
       
    89     User::LeaveIfError( iLib.Load( KUtilityFilename ) );
       
    90     
       
    91     // Find the TAny* CreateInstanceL() function
       
    92     TLibraryFunction entry = iLib.Lookup( KFunctionOrdinal );
       
    93     if ( !entry )
       
    94         {
       
    95         User::Leave( KErrNotFound );
       
    96         }    
       
    97   
       
    98     // Call CreateInstanceL  
       
    99     // Cannot use static_cast since entry() call returns TInt    
       
   100     iUtility = ( MSISpeechRecognitionUtilityBase* ) entry();
       
   101      
       
   102     // Do the 2nd phase construction
       
   103     iUtility->CreateInstanceSecondPhaseL( iClientUid, KNullUid, *this );
       
   104     
       
   105     CActiveScheduler::Add( this );
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------
       
   109 // CNssSiUtilityWrapper::Adapt
       
   110 // Forwards the call to Recognition Utility
       
   111 // ---------------------------------------------------------
       
   112 //
       
   113 TInt CNssSiUtilityWrapper::Adapt( const CSIClientResultSet& aResultSet,
       
   114                                   TInt aCorrect )
       
   115     {
       
   116     RUBY_DEBUG0( "CNssSiUtilityWrapper::Adapt" );
       
   117     return iUtility->Adapt( aResultSet, aCorrect );
       
   118     }
       
   119     
       
   120 // ---------------------------------------------------------
       
   121 // CNssSiUtilityWrapper::AddVoiceTags
       
   122 // Forwards the call to Recognition Utility
       
   123 // ---------------------------------------------------------
       
   124 //
       
   125 TInt CNssSiUtilityWrapper::AddVoiceTags( const RPointerArray<MDesCArray>& aTextArrayArray,
       
   126                                          const RArray<TLanguage>& aLanguageArray,
       
   127                                          TSILexiconID aLexiconID,
       
   128                                          TSIGrammarID aGrammarID, 
       
   129                                          RArray<TSIRuleID>& aRuleIDArray )
       
   130     {
       
   131     RUBY_DEBUG0( "CNssSiUtilityWrapper::AddVoiceTags" );
       
   132     return iUtility->AddVoiceTags( aTextArrayArray, aLanguageArray, 
       
   133                                    aLexiconID, aGrammarID, aRuleIDArray );
       
   134     }
       
   135     
       
   136 // ---------------------------------------------------------
       
   137 // CNssSiUtilityWrapper::AddVoiceTags
       
   138 // Forwards the call to Recognition Utility
       
   139 // ---------------------------------------------------------
       
   140 //
       
   141 TInt CNssSiUtilityWrapper::AddVoiceTags( const RPointerArray<MDesCArray>& aTextArrayArray,
       
   142                                          const RArray<RLanguageArray>& aLanguageArray,
       
   143                                          TSILexiconID aLexiconID,
       
   144                                          TSIGrammarID aGrammarID, 
       
   145                                          RArray<TSIRuleID>& aRuleIDArray )
       
   146     {
       
   147     RUBY_DEBUG0( "CNssSiUtilityWrapper::AddVoiceTags" );
       
   148     return iUtility->AddVoiceTags( aTextArrayArray, aLanguageArray, 
       
   149                                    aLexiconID, aGrammarID, aRuleIDArray );
       
   150     }
       
   151     
       
   152 // ---------------------------------------------------------
       
   153 // CNssSiUtilityWrapper::CancelUtility
       
   154 // Forwards the call to Recognition Utility
       
   155 // ---------------------------------------------------------
       
   156 //
       
   157 void CNssSiUtilityWrapper::CancelUtility()
       
   158     {
       
   159     RUBY_DEBUG0( "CNssSiUtilityWrapper::Cancel" );
       
   160     return iUtility->Cancel();
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------
       
   164 // CNssSiUtilityWrapper::CommitChanges
       
   165 // Forwards the call to Recognition Utility
       
   166 // ---------------------------------------------------------
       
   167 //
       
   168 TInt CNssSiUtilityWrapper::CommitChanges()
       
   169     {
       
   170     RUBY_DEBUG0( "CNssSiUtilityWrapper::CommitChanges" );
       
   171     return iUtility->CommitChanges();
       
   172     }
       
   173 
       
   174     
       
   175 // ---------------------------------------------------------
       
   176 // CNssSiUtilityWrapper::CreateGrammar
       
   177 // Forwards the call to Recognition Utility
       
   178 // ---------------------------------------------------------
       
   179 //
       
   180 TInt CNssSiUtilityWrapper::CreateGrammar( TSIGrammarID& aGrammarID )
       
   181     {
       
   182     RUBY_DEBUG0( "CNssSiUtilityWrapper::CreateGrammar" );
       
   183     return iUtility->CreateGrammar( aGrammarID );
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------
       
   187 // CNssSiUtilityWrapper::CreateLexicon
       
   188 // Forwards the call to Recognition Utility
       
   189 // ---------------------------------------------------------
       
   190 //
       
   191 TInt CNssSiUtilityWrapper::CreateLexicon( TSILexiconID& aLexiconID )
       
   192     {
       
   193     RUBY_DEBUG0( "CNssSiUtilityWrapper::CreateLexicon" );
       
   194     return iUtility->CreateLexicon( aLexiconID );
       
   195     }
       
   196         
       
   197 // ---------------------------------------------------------
       
   198 // CNssSiUtilityWrapper::CreateModelBank
       
   199 // Forwards the call to Recognition Utility
       
   200 // ---------------------------------------------------------
       
   201 //
       
   202 TInt CNssSiUtilityWrapper::CreateModelBank( TSIModelBankID& aModelBankID )
       
   203     {
       
   204     RUBY_DEBUG0( "CNssSiUtilityWrapper::CreateModelBank" );
       
   205     return iUtility->CreateModelBank( aModelBankID );
       
   206     }
       
   207         
       
   208 
       
   209 // ---------------------------------------------------------
       
   210 // CNssSiUtilityWrapper::EndRecSession
       
   211 // Forwards the call to Recognition Utility
       
   212 // ---------------------------------------------------------
       
   213 //
       
   214 TInt CNssSiUtilityWrapper::EndRecSession()
       
   215     {
       
   216     RUBY_DEBUG0( "CNssSiUtilityWrapper::EndRecSession" );
       
   217     return iUtility->EndRecSession();
       
   218     }
       
   219 
       
   220 
       
   221 // ---------------------------------------------------------
       
   222 // CNssSiUtilityWrapper::LoadGrammar
       
   223 // Forwards the call to Recognition Utility
       
   224 // ---------------------------------------------------------
       
   225 //
       
   226 TInt CNssSiUtilityWrapper::LoadGrammar( TSIGrammarID aGrammarID )
       
   227     {
       
   228     RUBY_DEBUG0( "CNssSiUtilityWrapper::LoadGrammar" );
       
   229     return iUtility->LoadGrammar( aGrammarID );
       
   230     }
       
   231         
       
   232 
       
   233 // ---------------------------------------------------------
       
   234 // CNssSiUtilityWrapper::LoadModels
       
   235 // Forwards the call to Recognition Utility
       
   236 // ---------------------------------------------------------
       
   237 //
       
   238 TInt CNssSiUtilityWrapper::LoadModels( TSIModelBankID aModelBankID )
       
   239     {
       
   240     RUBY_DEBUG0( "CNssSiUtilityWrapper::LoadModels" );
       
   241     return iUtility->LoadModels( aModelBankID );
       
   242     }
       
   243 
       
   244 
       
   245 // ---------------------------------------------------------
       
   246 // CNssSiUtilityWrapper::Record
       
   247 // Forwards the call to Recognition Utility
       
   248 // ---------------------------------------------------------
       
   249 //
       
   250 TInt CNssSiUtilityWrapper::Record( TTimeIntervalMicroSeconds32 aRecordTime )
       
   251     {
       
   252     RUBY_DEBUG0( "CNssSiUtilityWrapper::Record" );
       
   253     return iUtility->Record( aRecordTime );
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------
       
   257 // CNssSiUtilityWrapper::PreStartSampling
       
   258 // Forwards the call to Recognition Utility
       
   259 // ---------------------------------------------------------
       
   260 //
       
   261 TInt CNssSiUtilityWrapper::PreStartSampling()
       
   262     {
       
   263     RUBY_DEBUG0( "" );
       
   264     return iUtility->PreStartSampling();
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------
       
   268 // CNssSiUtilityWrapper::Recognize
       
   269 // Forwards the call to Recognition Utility
       
   270 // ---------------------------------------------------------
       
   271 //
       
   272 TInt CNssSiUtilityWrapper::Recognize( CSIClientResultSet& aResultSet )
       
   273     {
       
   274     RUBY_DEBUG0( "CNssSiUtilityWrapper::Recognize" );    
       
   275     return iUtility->Recognize( aResultSet ); 
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------
       
   279 // CNssSiUtilityWrapper::RemoveGrammar
       
   280 // Forwards the call to Recognition Utility
       
   281 // ---------------------------------------------------------
       
   282 //
       
   283 TInt CNssSiUtilityWrapper::RemoveGrammar( TSIGrammarID aGrammarID )
       
   284     {
       
   285     RUBY_DEBUG0( "CNssSiUtilityWrapper::RemoveGrammar" );   
       
   286     return iUtility->RemoveGrammar( aGrammarID );
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------
       
   290 // CNssSiUtilityWrapper::RemoveLexicon
       
   291 // Forwards the call to Recognition Utility
       
   292 // ---------------------------------------------------------
       
   293 //
       
   294 TInt CNssSiUtilityWrapper::RemoveLexicon( TSILexiconID aLexiconID )
       
   295     {
       
   296     RUBY_DEBUG0( "CNssSiUtilityWrapper::RemoveLexicon" );  
       
   297     return iUtility->RemoveLexicon( aLexiconID );
       
   298     }
       
   299 
       
   300 
       
   301 // ---------------------------------------------------------
       
   302 // CNssSiUtilityWrapper::RemoveModelBank
       
   303 // Forwards the call to Recognition Utility
       
   304 // ---------------------------------------------------------
       
   305 //
       
   306 TInt CNssSiUtilityWrapper::RemoveModelBank( TSIModelBankID aModelBankID )
       
   307     {
       
   308     RUBY_DEBUG0( "CNssSiUtilityWrapper::RemoveModelBank" );      
       
   309     return iUtility->RemoveModelBank( aModelBankID );
       
   310     }
       
   311 
       
   312 // ---------------------------------------------------------
       
   313 // CNssSiUtilityWrapper::RemoveRule
       
   314 // Forwards the call to Recognition Utility
       
   315 // ---------------------------------------------------------
       
   316 //
       
   317 TInt CNssSiUtilityWrapper::RemoveRule( TSIGrammarID aGrammarID, TSIRuleID aRuleID )
       
   318     {
       
   319     RUBY_DEBUG0( "CNssSiUtilityWrapper::RemoveRule" );  
       
   320     return iUtility->RemoveRule( aGrammarID, aRuleID );
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------
       
   324 // CNssSiUtilityWrapper::RemoveRules
       
   325 // Forwards the call to Recognition Utility
       
   326 // ---------------------------------------------------------
       
   327 //
       
   328 TInt CNssSiUtilityWrapper::RemoveRules( TSIGrammarID aGrammarID, RArray<TSIRuleID>& aRuleIDs )
       
   329     {
       
   330     RUBY_DEBUG0( "CNssSiUtilityWrapper::RemoveRules" );
       
   331     return iUtility->RemoveRules( aGrammarID, aRuleIDs );
       
   332     }
       
   333 
       
   334 // ---------------------------------------------------------
       
   335 // CNssSiUtilityWrapper::SetAudioPriority
       
   336 // Forwards the call to Recognition Utility
       
   337 // ---------------------------------------------------------
       
   338 //
       
   339 TInt CNssSiUtilityWrapper::SetAudioPriority( TInt aPriority, TInt aTrainPreference, 
       
   340                         TInt aPlaybackPreference, TInt aRecognitionPreference )
       
   341     {
       
   342     RUBY_DEBUG0( "CNssSiUtilityWrapper::SetAudioPriority" );
       
   343     return iUtility->SetAudioPriority( aPriority, aTrainPreference, 
       
   344                                 aPlaybackPreference, aRecognitionPreference );
       
   345     }
       
   346         
       
   347 // ---------------------------------------------------------
       
   348 // CNssSiUtilityWrapper::SetEventHandler
       
   349 // Forwards the call to Recognition Utility
       
   350 // ---------------------------------------------------------
       
   351 //
       
   352 void CNssSiUtilityWrapper::SetEventHandler( MSISpeechRecognitionUtilityObserver*
       
   353                                             aSpeechRecognitionUtilityObserver )
       
   354     {
       
   355     iObserver = *aSpeechRecognitionUtilityObserver;
       
   356     }
       
   357 
       
   358 // ---------------------------------------------------------
       
   359 // CNssSiUtilityWrapper::StartRecSession
       
   360 // Forwards the call to Recognition Utility
       
   361 // ---------------------------------------------------------
       
   362 //
       
   363 TInt CNssSiUtilityWrapper::StartRecSession( TNSSRecognitionMode aMode )
       
   364     {
       
   365     RUBY_DEBUG0( "CNssSiUtilityWrapper::StartRecSession" );
       
   366     return iUtility->StartRecSession( aMode );
       
   367     }
       
   368 
       
   369 // ---------------------------------------------------------
       
   370 // CNssSiUtilityWrapper::UnloadRule
       
   371 // Forwards the call to Recognition Utility
       
   372 // ---------------------------------------------------------
       
   373 //
       
   374 TInt CNssSiUtilityWrapper::UnloadRule( TSIGrammarID aGrammarID, TSIRuleID aRuleID )
       
   375     {
       
   376     RUBY_DEBUG0( "CNssSiUtilityWrapper::UnloadRule" );
       
   377     return iUtility->UnloadRule( aGrammarID, aRuleID );
       
   378     }
       
   379 
       
   380 // ---------------------------------------------------------
       
   381 // CNssSiUtilityWrapper::MsruoEvent
       
   382 // Callback from SI Utility
       
   383 // ---------------------------------------------------------
       
   384 //
       
   385 void CNssSiUtilityWrapper::MsruoEvent( TUid aEvent, TInt aResult )
       
   386     {
       
   387     RUBY_DEBUG2( "CNssSiUtilityWrapper::MsruoEvent, event[%d], result[%d]", aEvent, aResult );
       
   388     iEvent = aEvent;
       
   389     iResult = aResult;
       
   390     Ready();
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------
       
   394 // CNssSiUtilityWrapper::Ready
       
   395 // Sets active object ready to be run
       
   396 // ---------------------------------------------------------
       
   397 //
       
   398 void CNssSiUtilityWrapper::Ready()
       
   399     {
       
   400     if ( !IsActive() )
       
   401         {
       
   402         SetActive();
       
   403         TRequestStatus* stat = &iStatus;
       
   404         User::RequestComplete( stat, KErrNone );
       
   405         }
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------
       
   409 // CNssSiUtilityWrapper::RunL
       
   410 // From CActive
       
   411 // ---------------------------------------------------------
       
   412 //
       
   413 void CNssSiUtilityWrapper::RunL()
       
   414     {
       
   415     // Forwards callback to other parts of VAS
       
   416     RUBY_DEBUG2( "CNssSiUtilityWrapper::RunL calling callback function, event[%d], result[%d]", iEvent, iResult );
       
   417     iObserver.MsruoEvent( iEvent, iResult );
       
   418     RUBY_DEBUG0( "CNssSiUtilityWrapper::RunL callback called" );
       
   419     }
       
   420 	    
       
   421 // ---------------------------------------------------------
       
   422 // CNssSiUtilityWrapper::DoCancel
       
   423 // From CActive
       
   424 // ---------------------------------------------------------
       
   425 //
       
   426 void CNssSiUtilityWrapper::DoCancel()
       
   427     {
       
   428     // Nothing
       
   429     }
       
   430 
       
   431 
       
   432 // End of file