voiceui/voiceuivoicerecognition/src/vuicverificationinitstate.cpp
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <avkon.hrh>
       
    21 
       
    22 #include "vuicstate.h"
       
    23 #include "vuicverificationinitstate.h"
       
    24 #include "vuicverificationstate.h"
       
    25 #include "vuicabortstate.h"
       
    26 #include "vuicerrorstate.h"
       
    27 
       
    28 #include "vuicdatastorage.h"
       
    29 
       
    30 #include "vuicvoicerecogdialogimpl.h"
       
    31 #include "vuictoneplayer.h"
       
    32 
       
    33 #include "rubydebug.h"
       
    34 
       
    35 // CONSTANTS
       
    36 
       
    37     
       
    38 // -----------------------------------------------------------------------------
       
    39 // CVerificationInitState::NewL
       
    40 // Two-phased constructor.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CVerificationInitState* CVerificationInitState::NewL( CDataStorage& aDataStorage, CUiModel& aUiModel )
       
    44     {
       
    45     CVerificationInitState* self = new (ELeave) CVerificationInitState( aDataStorage, aUiModel );
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }       
       
    51     
       
    52 // Destructor       
       
    53 CVerificationInitState::~CVerificationInitState()
       
    54     {
       
    55     RUBY_DEBUG0( "CVerificationInitState::~CVerificationInitState START" );
       
    56     
       
    57     if ( iInternalState != EReady )
       
    58         {
       
    59         DataStorage().VerificationRecognitionHandler()->Cancel();
       
    60         }
       
    61     
       
    62     RUBY_DEBUG0( "CVerificationInitState::~CVerificationInitState EXIT" );
       
    63     }
       
    64     
       
    65 // ---------------------------------------------------------
       
    66 // CVerificationInitState::HandleEventL
       
    67 // ---------------------------------------------------------
       
    68 //       
       
    69 void CVerificationInitState::HandleEventL( TInt aEvent )
       
    70     {
       
    71     RUBY_DEBUG_BLOCK( "CVerificationInitState::HandleEventL" );
       
    72 
       
    73     CState* nextState = NULL;
       
    74 
       
    75     switch( aEvent )
       
    76         {
       
    77         case KErrNone:
       
    78         
       
    79             if ( iInternalState == EStarted )
       
    80                 {
       
    81 #ifndef __WINS__
       
    82 #ifdef __FULLDUPLEX_CHANGE
       
    83                 iInternalState = ESamplingStarted;
       
    84                 nextState = this;
       
    85                 }
       
    86             else if ( iInternalState == ESamplingStarted )
       
    87                 {
       
    88 #endif // __FULLDUPLEX_CHANGE
       
    89 #endif // __WINS__ 
       
    90 
       
    91                 iInternalState = EInitialized;
       
    92                 }
       
    93             else
       
    94                 {
       
    95                 nextState = CVerificationState::NewL( DataStorage(), UiModel() );
       
    96                 iInternalState = EReady;
       
    97                 }
       
    98             break;
       
    99         
       
   100         case KErrInit:
       
   101         
       
   102             nextState = CErrorState::NewL( DataStorage(), UiModel(), aEvent );
       
   103             break;
       
   104             
       
   105         case EShortKeypress:
       
   106         case ELongKeypress:
       
   107         case EEndCallKeypress:
       
   108         
       
   109             // Do nothing
       
   110             break;
       
   111             
       
   112         default:
       
   113         
       
   114             nextState = CAbortState::NewL( DataStorage(), UiModel() );
       
   115             break;
       
   116         }
       
   117 
       
   118     DataStorage().VoiceRecognitionImpl()->ChangeState( nextState );
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------
       
   122 // CVerificationInitState::ExecuteL
       
   123 // ---------------------------------------------------------
       
   124 //       
       
   125 void CVerificationInitState::ExecuteL()
       
   126     {
       
   127     RUBY_DEBUG_BLOCK( "CVerificationInitState::ExecuteL" );
       
   128     
       
   129     if ( iInternalState == ENotStarted )
       
   130         {
       
   131         // Initialize recognition system
       
   132         InitializeL();
       
   133         iInternalState = EStarted;
       
   134         
       
   135 #ifndef __WINS__
       
   136 #ifdef __FULLDUPLEX_CHANGE
       
   137         // Initialize sampling
       
   138         StartSamplingL();
       
   139         }
       
   140     else if ( iInternalState == ESamplingStarted )
       
   141         {
       
   142 #endif // __FULLDUPLEX_CHANGE
       
   143 #endif // __WINS__ 
       
   144 
       
   145         // Initialize start tone
       
   146         DataStorage().TonePlayer()->InitToneL( EAvkonSIDNameDiallerStartTone );
       
   147 
       
   148         // Initialize recognition
       
   149         RecognizeInitL();
       
   150         }
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------
       
   154 // CVerificationInitState::CVerificationInitState
       
   155 // ---------------------------------------------------------
       
   156 //              
       
   157 CVerificationInitState::CVerificationInitState( CDataStorage& aDataStorage, CUiModel& aUiModel )
       
   158  : CState( aDataStorage, aUiModel ), iInternalState( ENotStarted )
       
   159     {
       
   160     }
       
   161     
       
   162 // ---------------------------------------------------------
       
   163 // CVerificationInitState::InitializeL
       
   164 // ---------------------------------------------------------
       
   165 //
       
   166 void CVerificationInitState::InitializeL()
       
   167     {
       
   168     RUBY_DEBUG_BLOCK( "CVerificationInitState::InitializeL" );
       
   169         
       
   170     CNssRecognitionHandlerBuilder* builder = CNssRecognitionHandlerBuilder::NewL();
       
   171     DataStorage().SetVerificationRecognitionHandlerBuilder( builder );    
       
   172     builder->InitializeL();
       
   173    
       
   174     DataStorage().SetVerificationRecognitionHandler( builder->GetRecognitionHandler() );
       
   175     }
       
   176 
       
   177 #ifndef __WINS__
       
   178 #ifdef __FULLDUPLEX_CHANGE
       
   179 // ---------------------------------------------------------
       
   180 // CVerificationInitState::StartSamplingL
       
   181 // ---------------------------------------------------------
       
   182 //
       
   183 void CVerificationInitState::StartSamplingL()
       
   184     {
       
   185     RUBY_DEBUG_BLOCK( "CVerificationInitState::StartSamplingL" );
       
   186     
       
   187     MNssRecognitionHandler* handler = DataStorage().VerificationRecognitionHandler(); 
       
   188     User::LeaveIfError(
       
   189         handler->PreStartSampling( DataStorage().VoiceRecognitionImpl() ) );
       
   190     }
       
   191 #endif // __FULLDUPLEX_CHANGE
       
   192 #endif // __WINS__ 
       
   193 
       
   194 // ---------------------------------------------------------
       
   195 // CVerificationInitState::RecognizeInitL
       
   196 // ---------------------------------------------------------
       
   197 //
       
   198 void CVerificationInitState::RecognizeInitL()
       
   199     {
       
   200     RUBY_DEBUG_BLOCK( "CVerificationInitState::RecognizeInitL" );
       
   201     
       
   202     // Content of this array may not be destroyed here. In case of a Leave content
       
   203     // will be destroyed in DataStorage.
       
   204     CArrayPtrFlat<MNssContext>* array = new (ELeave) CArrayPtrFlat<MNssContext>( 1 );
       
   205     CleanupDeletePushL( array );
       
   206         
       
   207     array->AppendL( DataStorage().Context() );
       
   208 
       
   209     MNssRecognitionHandler* handler = DataStorage().VerificationRecognitionHandler();
       
   210     User::LeaveIfError(
       
   211         handler->RecognizeInitL( DataStorage().VoiceRecognitionImpl(), *array, 1 ) );
       
   212                                  
       
   213     CleanupStack::PopAndDestroy( array );
       
   214     }
       
   215     
       
   216 // End of File
       
   217