srsf/vcommandhandler/src/tagplayer.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:  Plays voice commands
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "rubydebug.h"
       
    20 #include "tagplayer.h"
       
    21 
       
    22 _LIT( KStoredVCommandPlayerPanic, "SVCP" );
       
    23 
       
    24 CTagPlayer* CTagPlayer::NewL()
       
    25     {
       
    26     CTagPlayer* self = new (ELeave) CTagPlayer;
       
    27     return self;
       
    28     }
       
    29     
       
    30 CTagPlayer::~CTagPlayer()
       
    31     {
       
    32     // if any
       
    33     delete iPlaybackTag;  
       
    34     // to panic in HandlePlays if they are called after the object destruction
       
    35     iPlaybackTag = NULL;  
       
    36     }
       
    37 
       
    38 /**
       
    39 * Attempts to play back the text expected to be recognized. 
       
    40 * To be playable command has to be added to CVCommandHandler AND
       
    41 * then retrieved back. This function is asynchronous
       
    42 *
       
    43 * @param aHandler CVCommandHandler where the command is stored
       
    44 * @param aPlayEventHandler Entity that handles the playback callbacks
       
    45 * @see NssVasMPlayEventHandler.h
       
    46 *
       
    47 * @leave KErrBadHandle if the current command has not been retrieved 
       
    48 *        from CVCommandHandler (i.e. was not trained for recognition)
       
    49 * @leave KErrNotFound if this command cannot be found in aHandler
       
    50 * @leave KErrNotReady @see nssvasmspeechitem.h MNssSpeechItem::TNssSpeechItemResult 
       
    51 *                                              EVasUnexpectedRequest
       
    52 * @leave KErrInUse @see nssvasmspeechitem.h MNssSpeechItem::TNssSpeechItemResult 
       
    53 *                                              EVasInUse
       
    54 * @leave KErrArgument @see nssvasmspeechitem.h MNssSpeechItem::TNssSpeechItemResult 
       
    55 *                                              EVasInvalidParameter
       
    56 * @leave KErrGeneral @see nssvasmspeechitem.h MNssSpeechItem::TNssSpeechItemResult 
       
    57 *                                             EVasPlayFailed
       
    58 */
       
    59 void CTagPlayer::PlayTagL( MNssTag* aTag, MNssPlayEventHandler& aPlayEventHandler )
       
    60     {
       
    61     RUBY_DEBUG_BLOCK( "CTagPlayer::PlayTagL" );
       
    62     CleanupDeletePushL( aTag );
       
    63     __ASSERT_ALWAYS( !iPlaybackTag, User::Leave( KErrLocked ) );
       
    64     CleanupStack::Pop( aTag );
       
    65     iPlaybackTag = aTag;
       
    66     iPlayEventHandler = &aPlayEventHandler;
       
    67 
       
    68     MNssSpeechItem::TNssSpeechItemResult err = iPlaybackTag->SpeechItem()->PlayL( this );
       
    69     switch( err ) 
       
    70         {
       
    71         case MNssSpeechItem::EVasErrorNone:
       
    72             break;
       
    73         case MNssSpeechItem::EVasUnexpectedRequest:
       
    74             User::Leave( KErrNotReady );
       
    75         case MNssSpeechItem::EVasInUse:
       
    76             User::Leave( KErrInUse );
       
    77         case MNssSpeechItem::EVasInvalidParameter:
       
    78             User::Leave( KErrArgument );
       
    79         case MNssSpeechItem::EVasPlayFailed:
       
    80             User::Leave( KErrGeneral );
       
    81         case MNssSpeechItem::EVasTrainFailed:
       
    82         default:
       
    83             RUBY_ERROR1( "CTagPlayer::PlaySpokenTextL Unexpected error code [%d]", err );
       
    84             User::Leave( KErrGeneral );
       
    85         }
       
    86     }
       
    87     
       
    88 /**
       
    89 * Cancels playback. No PlayStarted/PlayComplete after it
       
    90 *
       
    91 * @leave KErrNotReady if playback has never been started
       
    92 */                                   
       
    93 void CTagPlayer::CancelPlaybackL()
       
    94     {
       
    95     RUBY_DEBUG_BLOCK( "CTagPlayer::CancelPlaybackL" );
       
    96     __ASSERT_ALWAYS( iPlaybackTag, User::Leave( KErrNotReady ) );
       
    97     TInt err = iPlaybackTag->SpeechItem()->CancelL();
       
    98     RUBY_DEBUG1( "CTagPlayer::CancelPlaybackL Canceled with the error code [%d]", err );
       
    99     delete iPlaybackTag;
       
   100     iPlaybackTag = NULL;
       
   101     iPlayEventHandler = NULL;
       
   102     }
       
   103 
       
   104 // From MNsPlayEventHandler
       
   105 
       
   106 /**
       
   107 * The HandlePlayStarted method is a virtual method implemented by the
       
   108 * client and is called when play is started
       
   109 * @param aDuration - the duration of the utterance data
       
   110 */       
       
   111 void CTagPlayer::HandlePlayStarted( TTimeIntervalMicroSeconds32 aDuration )
       
   112     {
       
   113     __ASSERT_ALWAYS( iPlaybackTag, User::Panic( KStoredVCommandPlayerPanic, KErrNotReady ) );
       
   114     iPlayEventHandler->HandlePlayStarted( aDuration );
       
   115     }
       
   116 
       
   117 /**
       
   118 * The HandlePlayComplete method is a virtual method implemented by the
       
   119 * client and is called when play is completed
       
   120 * @param aErrorCode EVasErrorNone if playing was successfull
       
   121 */       
       
   122 void CTagPlayer::HandlePlayComplete( TNssPlayResult aErrorCode )
       
   123     {
       
   124     __ASSERT_ALWAYS( iPlaybackTag, User::Panic( KStoredVCommandPlayerPanic, KErrNotReady ) );
       
   125     delete iPlaybackTag;
       
   126     iPlaybackTag = NULL;
       
   127     iPlayEventHandler->HandlePlayComplete( aErrorCode );
       
   128     iPlayEventHandler = NULL;
       
   129     }
       
   130 
       
   131 //End of file