voiceui/voiceuivoicerecognition/src/vuicpropertyhandler.cpp
branchRCL_3
changeset 23 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
22:cad71a31b7fc 23:e36f3802f733
       
     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:  Active object for subscribing to Publish & Suscribe properties
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32svr.h>
       
    21 #include <voiceuidomainpskeys.h>
       
    22 
       
    23 #include <vuivoicerecogdefs.h>
       
    24 
       
    25 #include "vuicpropertyhandler.h"
       
    26 #include "vuicvoicerecogdialogimpl.h"
       
    27 
       
    28 #include "rubydebug.h"
       
    29 
       
    30 // ---------------------------------------------------------
       
    31 // CPropertyHandler::NewL
       
    32 // Symbian OS two-phased constructor
       
    33 // ---------------------------------------------------------
       
    34 //
       
    35 CPropertyHandler* CPropertyHandler::NewL( TUid aFirstCategory,
       
    36                                           TUint aFirstKey, 
       
    37                                           TUid aSecondCategory,
       
    38                                           TUint aSecondKey )
       
    39     {
       
    40     RUBY_DEBUG_BLOCK( "CPropertyHandler::NewL" );
       
    41     
       
    42     CPropertyHandler* self = new ( ELeave ) CPropertyHandler();
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL( aFirstCategory, aFirstKey, 
       
    45                       aSecondCategory, aSecondKey );
       
    46     CleanupStack::Pop( self );
       
    47     return self;
       
    48     }
       
    49 
       
    50 
       
    51 // ---------------------------------------------------------
       
    52 // CPropertyHandler::CPropertyHandler
       
    53 // C++ constructor
       
    54 // ---------------------------------------------------------
       
    55 //
       
    56 CPropertyHandler::CPropertyHandler()
       
    57     : CActive( EPriorityStandard )
       
    58     {
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------
       
    62 // CPropertyHandler::ConstructL
       
    63 // Symbian OS 2nd phase constructor
       
    64 // ---------------------------------------------------------
       
    65 //
       
    66 void CPropertyHandler::ConstructL( TUid aFirstCategory, TUint aFirstKey, 
       
    67                                    TUid aSecondCategory, TUint aSecondKey )
       
    68     {
       
    69     RUBY_DEBUG_BLOCK( "CPropertyHandler::ConstructL" );   
       
    70  
       
    71     iFirstCategory = aFirstCategory;
       
    72     iFirstKey = aFirstKey;
       
    73     
       
    74     /*****************************
       
    75     * KPSUidVoiceUiAccMonitor
       
    76     ******************************/
       
    77 
       
    78     
       
    79     TInt err = iProperty.Define( iFirstCategory, iFirstKey,
       
    80                                  RProperty::EInt );
       
    81     
       
    82     RUBY_DEBUG1( "CPropertyHandler::ConstructL - aFirstCategory err[%d]", err );
       
    83    
       
    84     if ( err == KErrNone || err == KErrAlreadyExists )
       
    85         {
       
    86         // Set VoiceUI P&S key to ON
       
    87         User::LeaveIfError( iProperty.Set( iFirstCategory, iFirstKey, 
       
    88                                            KVoiceUiIsOpen ) );
       
    89         }
       
    90 
       
    91         TInt error = iProperty.Define( aSecondCategory, aSecondKey,
       
    92                                        RProperty::EInt );
       
    93     
       
    94     RUBY_DEBUG1( "CPropertyHandler::ConstructL - aSecondCategory err[%d]", err );
       
    95      
       
    96     if ( error == KErrNone || error == KErrAlreadyExists )
       
    97         {
       
    98         // Start to listen RemCon events
       
    99         User::LeaveIfError( iProperty.Attach( aSecondCategory, aSecondKey ) );
       
   100         }
       
   101     
       
   102     CActiveScheduler::Add( this );
       
   103     // Initial subscription and process current property value
       
   104     RunL();
       
   105 
       
   106     iRequestIssued = ETrue;
       
   107     }
       
   108 
       
   109 // Destructor
       
   110 CPropertyHandler::~CPropertyHandler()
       
   111     {
       
   112     RUBY_DEBUG0( "CPropertyHandler::~CPropertyHandler START" );
       
   113 
       
   114     // Set VoiceUI P&S key to OFF
       
   115     iProperty.Set( iFirstCategory, iFirstKey, KVoiceUiIsClose );
       
   116     
       
   117     Cancel();
       
   118     iProperty.Close();
       
   119 
       
   120     RUBY_DEBUG0( "CPropertyHandler::~CPropertyHandler EXIT" );
       
   121     }
       
   122 
       
   123 
       
   124 // ---------------------------------------------------------
       
   125 // CPropertyHandler::DoCancel   
       
   126 // Cancel the request to receive events
       
   127 // ---------------------------------------------------------
       
   128 //
       
   129 void CPropertyHandler::DoCancel()
       
   130     {
       
   131     RUBY_DEBUG0( "CPropertyHandler::DoCancel START" );
       
   132     
       
   133     iProperty.Cancel();
       
   134     
       
   135     RUBY_DEBUG0( "CPropertyHandler::DoCancel EXIT" );
       
   136     }
       
   137 
       
   138 
       
   139 // ---------------------------------------------------------
       
   140 // CPropertyHandler::RunL
       
   141 // Handle a change event.
       
   142 // ---------------------------------------------------------
       
   143 //
       
   144 void CPropertyHandler::RunL()
       
   145     {
       
   146     RUBY_DEBUG_BLOCK( "CPropertyHandler::RunL" ); 
       
   147     
       
   148     // Resubscribe before processing new value to prevent missing updates
       
   149     iProperty.Subscribe( iStatus );
       
   150     SetActive();
       
   151 
       
   152     if ( iRequestIssued && iRecogObserver )
       
   153         {
       
   154         RUBY_DEBUG0( "CPropertyHandler::RunL - Call HandlePropertyValueChange for RecogObserver" );
       
   155         
       
   156         TInt value = 0;
       
   157         iProperty.Get( value );
       
   158         
       
   159         iRecogObserver->HandlePropertyValueChange( value );
       
   160         }
       
   161     else
       
   162         {
       
   163         RUBY_DEBUG0( "CPropertyHandler::RunL - Pass" );
       
   164         }
       
   165              
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CPropertyHandler::Register
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CPropertyHandler::Register( CVoiceRecognitionDialogImpl* aRecogObserver )
       
   173     {
       
   174     RUBY_DEBUG0( "CPropertyHandler::Register START" );
       
   175 
       
   176     if ( aRecogObserver )
       
   177         {
       
   178         iRecogObserver = aRecogObserver;
       
   179         }
       
   180         
       
   181     RUBY_DEBUG0( "CPropertyHandler::Register EXIT" );        
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CPropertyHandler::DeRegister
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 void CPropertyHandler::DeRegister( CVoiceRecognitionDialogImpl* aRecogObserver )
       
   189     {
       
   190     RUBY_DEBUG0( "CPropertyHandler::DeRegister START" );
       
   191 
       
   192     if ( aRecogObserver )
       
   193         {
       
   194         iRecogObserver = NULL;
       
   195         }
       
   196         
       
   197     RUBY_DEBUG0( "CPropertyHandler::DeRegister EXIT" );
       
   198     }    
       
   199     
       
   200 
       
   201 // End of File