voiceui/voiceuivoicerecognition/src/vuicinitstate.cpp
changeset 13 57b735022c18
parent 1 b13cd05eeb2f
equal deleted inserted replaced
1:b13cd05eeb2f 13:57b735022c18
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <avkon.hrh>
       
    21 
       
    22 #include <vasmbasepbkhandler.h>
       
    23 
       
    24 #include "vuicstate.h"
       
    25 #include "vuicinitstate.h"
       
    26 #include "vuicrecordstate.h"
       
    27 #include "vuicabortstate.h"
       
    28 #include "vuicerrorstate.h"
       
    29 
       
    30 #include "vuicdatastorage.h"
       
    31 
       
    32 #include "vuicvoicerecogdialogimpl.h"
       
    33 #include "vuictoneplayer.h"
       
    34 #include "vuicpropertyhandler.h"
       
    35 
       
    36 #include "rubydebug.h"
       
    37 
       
    38 // CONSTANTS
       
    39 
       
    40     
       
    41 // -----------------------------------------------------------------------------
       
    42 // CInitState::NewL
       
    43 // Two-phased constructor.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CInitState* CInitState::NewL( CDataStorage& aDataStorage, CUiModel& aUiModel )
       
    47     {
       
    48     CInitState* self = new (ELeave) CInitState( aDataStorage, aUiModel );
       
    49     CleanupStack::PushL( self );
       
    50     self->ConstructL();
       
    51     CleanupStack::Pop( self );
       
    52     return self;
       
    53     }       
       
    54     
       
    55 // Destructor       
       
    56 CInitState::~CInitState()
       
    57     {
       
    58     RUBY_DEBUG0( "CInitState::~CInitState START" );
       
    59     
       
    60     if ( iInternalState != EReady )
       
    61         {
       
    62         DataStorage().RecognitionHandler()->Cancel();
       
    63         }
       
    64     
       
    65     RUBY_DEBUG0( "CInitState::~CInitState EXIT" );
       
    66     }
       
    67     
       
    68 // ---------------------------------------------------------
       
    69 // CInitState::HandleEventL
       
    70 // ---------------------------------------------------------
       
    71 //       
       
    72 void CInitState::HandleEventL( TInt aEvent )
       
    73     {
       
    74     RUBY_DEBUG_BLOCK( "CInitState::HandleEventL" );
       
    75 
       
    76     CState* nextState = NULL;
       
    77 
       
    78     switch( aEvent )
       
    79         {
       
    80         case KErrNone:
       
    81         
       
    82             if ( iInternalState == EStarted )
       
    83                 {
       
    84 #ifndef __WINS__                  
       
    85 #ifdef __FULLDUPLEX_CHANGE
       
    86                 iInternalState = ESamplingStarted;
       
    87                 nextState = this;
       
    88                 }
       
    89             else if ( iInternalState == ESamplingStarted )
       
    90                 {
       
    91 #endif // __FULLDUPLEX_CHANGE
       
    92 #endif // __WINS__  
       
    93                 iInternalState = EInitialized;
       
    94                 }
       
    95             else if ( iInternalState == EInitialized )
       
    96                 {
       
    97                 iInternalState = EReady;
       
    98                 nextState = this;
       
    99                 }
       
   100             else
       
   101                 {
       
   102                 nextState = CRecordState::NewL( DataStorage(), UiModel() );
       
   103                 }
       
   104             break;
       
   105         
       
   106         case KErrInit:
       
   107         case KErrNoContacts:
       
   108         
       
   109             nextState = CErrorState::NewL( DataStorage(), UiModel(), aEvent );
       
   110             break;
       
   111             
       
   112         case ELongKeypress:
       
   113         case EEndCallKeypress:
       
   114         
       
   115             // Do nothing
       
   116             break;
       
   117             
       
   118         default:
       
   119         
       
   120             nextState = CAbortState::NewL( DataStorage(), UiModel() );
       
   121             break;
       
   122         }
       
   123 
       
   124     DataStorage().VoiceRecognitionImpl()->ChangeState( nextState );
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------
       
   128 // CInitState::ExecuteL
       
   129 // ---------------------------------------------------------
       
   130 //       
       
   131 void CInitState::ExecuteL()
       
   132     {
       
   133     RUBY_DEBUG_BLOCK( "CInitState::ExecuteL" );
       
   134     
       
   135     if ( iInternalState == ENotStarted )
       
   136         {
       
   137         // Initialize recognition system
       
   138         InitializeL();
       
   139         iInternalState = EStarted;
       
   140 
       
   141 #ifndef __WINS__          
       
   142 #ifdef __FULLDUPLEX_CHANGE
       
   143         // Initialize sampling
       
   144         StartSamplingL();
       
   145         }
       
   146     else if ( iInternalState == ESamplingStarted )
       
   147         {
       
   148 #endif // __FULLDUPLEX_CHANGE
       
   149 #endif // __WINS__  
       
   150         // Initialize phonebook handler
       
   151         TRAPD( error, DataStorage().PbkHandler()->InitializeL() );
       
   152         if ( error != KErrAlreadyExists )
       
   153             {
       
   154             User::LeaveIfError( error );
       
   155             }
       
   156         
       
   157         // Initialize start tone
       
   158         DataStorage().TonePlayer()->InitToneL( EAvkonSIDNameDiallerStartTone );
       
   159 
       
   160         // Initialize recognition
       
   161         RecognizeInitL();
       
   162         }
       
   163     else
       
   164         {
       
   165         // Play the starting tone
       
   166         DataStorage().TonePlayer()->PlayTone( EAvkonSIDNameDiallerStartTone ); 
       
   167         }
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------
       
   171 // CInitState::CInitState
       
   172 // ---------------------------------------------------------
       
   173 //              
       
   174 CInitState::CInitState( CDataStorage& aDataStorage, CUiModel& aUiModel )
       
   175  : CState( aDataStorage, aUiModel ), iInternalState( ENotStarted )
       
   176     {
       
   177     }
       
   178     
       
   179 // ---------------------------------------------------------
       
   180 // CInitState::InitializeL
       
   181 // ---------------------------------------------------------
       
   182 //
       
   183 void CInitState::InitializeL()
       
   184     {
       
   185     RUBY_DEBUG_BLOCK( "CInitState::InitializeL" );
       
   186 
       
   187     DataStorage().AccessoryButtonMonitor()->Register( DataStorage().VoiceRecognitionImpl() );
       
   188 
       
   189     CNssRecognitionHandlerBuilder* builder = CNssRecognitionHandlerBuilder::NewL();
       
   190     DataStorage().SetRecognitionHandlerBuilder( builder );    
       
   191     builder->InitializeL();
       
   192       
       
   193     DataStorage().SetRecognitionHandler( builder->GetRecognitionHandler() );
       
   194     }
       
   195 
       
   196 #ifndef __WINS__      
       
   197 #ifdef __FULLDUPLEX_CHANGE
       
   198 // ---------------------------------------------------------
       
   199 // CInitState::StartSamplingL
       
   200 // ---------------------------------------------------------
       
   201 //
       
   202 void CInitState::StartSamplingL()
       
   203     {
       
   204     RUBY_DEBUG_BLOCK( "CInitState::StartSamplingL" );
       
   205     
       
   206     MNssRecognitionHandler* handler = DataStorage().RecognitionHandler(); 
       
   207     User::LeaveIfError(
       
   208         handler->PreStartSampling( DataStorage().VoiceRecognitionImpl() ) );
       
   209     }
       
   210 #endif // __FULLDUPLEX_CHANGE
       
   211 #endif // __WINS__  
       
   212         
       
   213 // ---------------------------------------------------------
       
   214 // CInitState::RecognizeInitL
       
   215 // ---------------------------------------------------------
       
   216 //
       
   217 void CInitState::RecognizeInitL()
       
   218     {
       
   219     RUBY_DEBUG_BLOCK( "CInitState::RecognizeInitL" );
       
   220     
       
   221     TInt numResults = KSindMaxResults * 3;
       
   222 
       
   223     if ( DataStorage().VerificationMode() == EVoice )
       
   224         {
       
   225         numResults = KVerificationResults;
       
   226         }
       
   227 
       
   228     MNssRecognitionHandler* handler = DataStorage().RecognitionHandler();
       
   229     User::LeaveIfError(
       
   230         handler->RecognizeInitL( DataStorage().VoiceRecognitionImpl(), numResults ) );
       
   231     }
       
   232     
       
   233 // End of File
       
   234