vtengines/videoteleng/Src/Commands/CVtEngOperation.cpp
changeset 0 ed9695c8bcbe
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     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:  Operation base class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CVtEngOperation.h"
       
    22 #include    "CVtEngCommandHandler.h"
       
    23 #include    "TVtEngOperationUtils.h"
       
    24 #include    "VtEngUtils.h"
       
    25 #include    "cvtengmdtrcommandsender.h"
       
    26 #include    "cvtlogger.h"
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CVtEngOperation::NewL
       
    32 // Symbian two-phase constructor
       
    33 //
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CVtEngOperation* CVtEngOperation::NewL(
       
    37     TVtEngCommandId aCommandId,
       
    38     CVtEngHandlerContainer& aHandlers,
       
    39     MVtEngOperationObserver& aObserver,
       
    40     TBool aDelete )
       
    41     {
       
    42     CVtEngOperation* self = new ( ELeave )
       
    43     CVtEngOperation( aCommandId, aHandlers, aObserver, aDelete );
       
    44     
       
    45     CleanupStack::PushL( self );
       
    46     self->iAsyncCallback = new ( ELeave )
       
    47         CAsyncCallBack( CActive::EPriorityStandard );
       
    48     self->iAsyncCallback->Set( TCallBack( ASyncHandleOpComplete, self ) );
       
    49 
       
    50     CleanupStack::Pop();
       
    51     return self;
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CVtEngOperation::CVtEngOperation
       
    56 // C++ constructor can NOT contain any code, that
       
    57 // might leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CVtEngOperation::CVtEngOperation(
       
    61     TVtEngCommandId aCommandId,
       
    62     CVtEngHandlerContainer& aHandlers,
       
    63     MVtEngOperationObserver& aObserver,
       
    64     TBool aDelete ) :
       
    65     iCommand( aCommandId ),
       
    66     iHandlers( aHandlers ),
       
    67     iObserver( aObserver ),
       
    68     iDelete( aDelete )
       
    69     {
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CVtEngOperation::~CVtEngOperation
       
    74 // Destructor
       
    75 //
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CVtEngOperation::~CVtEngOperation()
       
    79     {
       
    80     Cancel();
       
    81     delete iAsyncCallback;
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CVtEngOperation::HandleOpCompleteL
       
    86 // Destructor
       
    87 //
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CVtEngOperation::HandleOpComplete( const TInt aResult )
       
    91     {
       
    92     __VTPRINTENTER( "EngOp.HandleOpComplete" )
       
    93     iObserver.SetOperation( NULL );
       
    94     CVtEngMdtrCommandSender& mediatorSender = 
       
    95         CVtEngUtility::EngineUtils()->MediatorCommands();
       
    96     switch( iCommand )
       
    97         {
       
    98     case KVtEngTerminateSession:
       
    99         // send mediator command to telephony for call release        
       
   100         mediatorSender.EndCall();
       
   101         break;
       
   102     case KVtEngMuteOutgoingAudio:
       
   103     case KVtEngUnmuteOutgoingAudio:
       
   104         // notify telephony subsystems about new microphone state
       
   105         mediatorSender.NotifyOutgoingAudioState( 
       
   106             iCommand == KVtEngUnmuteOutgoingAudio );
       
   107         break;   
       
   108     default:
       
   109         break;
       
   110     }
       
   111 #ifdef VTDEBUG
       
   112     TRAPD( err, iObserver.CommandCompleteL( iCommand, aResult ) );
       
   113     __VTPRINT2( DEBUG_GEN, "EngOp.Complete err=", err )
       
   114 #else
       
   115     TRAP_IGNORE( iObserver.CommandCompleteL( iCommand, aResult ) );
       
   116 #endif // VTDEBUG
       
   117     if ( iDelete )
       
   118         {
       
   119         delete this;
       
   120         }
       
   121     __VTPRINTEXITR( "EngOp.HandleOpComplete %d", aResult )
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CVtEngOperation::ASyncHandleOpComplete
       
   126 // Destructor
       
   127 //
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 TInt CVtEngOperation::ASyncHandleOpComplete( TAny* aPtr )
       
   131     {
       
   132     __VTPRINTENTER( "EngOp.ASyncHandleOpComplete" )
       
   133     CVtEngOperation* self = reinterpret_cast< CVtEngOperation* >( aPtr );
       
   134     TInt error( self->iAsyncErr );
       
   135     self->iAsyncErr = KErrNone;
       
   136     self->HandleOpComplete( error );
       
   137     __VTPRINTEXIT( "EngOp.ASyncHandleOpComplete" )
       
   138     return KErrNone;
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CVtEngOperation::ExecuteL
       
   143 // Destructor
       
   144 //
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 TBool CVtEngOperation::ExecuteL( TDesC8* aParams )
       
   148     {
       
   149     __VTPRINTENTER( "EngOp.ExecuteL" )
       
   150     TBool complete( EFalse );
       
   151         
       
   152     // Offer for synchronous handling.
       
   153     TRAPD( err, complete = OfferExecuteSyncL( aParams ) );
       
   154 #ifdef VTDEBUG
       
   155     if ( err < KErrNone )
       
   156         {
       
   157         __VTPRINT2( DEBUG_GEN, "EngOp.ExecuteL LEAVE = %d", err )
       
   158         }
       
   159 #endif
       
   160     User::LeaveIfError( err );
       
   161     if ( !complete )
       
   162         {
       
   163         // async request
       
   164         switch ( iCommand )
       
   165             {
       
   166             case KVtEngResetEngine:
       
   167             case KVtEngInitializeEngine:
       
   168             case KVtEngInitializeEngineTest:
       
   169             case KVtEngInitializeEngineDiag:
       
   170             case KVtEngTerminateSession:
       
   171             case KVtEngSwitchToVoice:
       
   172                 TVtEngEngineInitUtil::HandleL( *this, iHandlers );
       
   173                 break;
       
   174 
       
   175             case KVtEngSetSource:
       
   176             case KVtEngPrepareCamera:
       
   177             case KVtEngStartViewFinder:
       
   178             case KVtEngPauseViewFinder:
       
   179             case KVtEngStopViewFinder:
       
   180             case KVtEngStartRenderRemote:
       
   181             case KVtEngStopRenderRemote:
       
   182             case KVtEngHandleLayoutChange:
       
   183             case KVtEngUnfreeze:
       
   184 
       
   185             // Media object sharing
       
   186             case KVtEngStopShareImage:
       
   187                 TVtEngRenderUtil::HandleL( *this, iHandlers );
       
   188                 break;
       
   189 
       
   190             // Media object sharing
       
   191             // These two commands must be trapped and completed without leave
       
   192             // because Application UI has to be able to act according to error.
       
   193             case KVtEngInitializeShareImage:
       
   194             case KVtEngStartShareImage:
       
   195                 TRAP( err, TVtEngRenderUtil::HandleL( *this, iHandlers ) );
       
   196                 break;
       
   197 
       
   198             case KVtEngSetAudioRouting:
       
   199                 TVtEngAudioRoutingUtil::HandleL( *this );
       
   200                 break;
       
   201 
       
   202             case KVtEngSetAudioVolume:
       
   203             case KVtEngMuteOutgoingAudio:
       
   204             case KVtEngUnmuteOutgoingAudio:
       
   205                 TVtEngAudioPlaybackUtil::HandleL( *this, iHandlers );
       
   206                 break;
       
   207             default:
       
   208                 __VTPRINT( DEBUG_GEN, "EngOp.ExecuteL not handled" )
       
   209                 break;
       
   210             }
       
   211 
       
   212         iObserver.SetOperation( this );
       
   213 
       
   214         if ( err != KErrNone )
       
   215             {
       
   216             __VTPRINT2( DEBUG_GEN, "EngOp.ExecuteL completing command %d", err )
       
   217             iAsyncErr = err;
       
   218             iAsyncCallback->CallBack();
       
   219             }
       
   220         }
       
   221     else if ( iDelete )
       
   222         {
       
   223         delete this;
       
   224         }
       
   225     __VTPRINTEXITR( "EngOp.ExecuteL %d", complete )
       
   226     return complete;
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CVtEngOperation::Cancel
       
   231 // Cancels operation.
       
   232 //
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 TBool CVtEngOperation::Cancel()
       
   236     {
       
   237     __VTPRINTENTER( "EngOp.Cancel")
       
   238     __VTPRINT2( DEBUG_GEN, "Command id = %d", iCommand)
       
   239     switch ( iCommand )
       
   240         {
       
   241         case KVtEngInitializeEngine:
       
   242             //TVtEngEngineInitUtil::Cancel( *this );
       
   243             break;
       
   244         case KVtEngInitializeShareImage:
       
   245             TVtEngRenderUtil::Cancel( *this ,iHandlers);
       
   246             break;
       
   247         default:
       
   248             break;
       
   249         }
       
   250     __VTPRINTEXIT( "EngOp.Cancel" )
       
   251     return ETrue;
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CVtEngOperation::OfferExecuteSyncL
       
   256 //
       
   257 //
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 TBool CVtEngOperation::OfferExecuteSyncL( TDesC8* aParams )
       
   261     {
       
   262     __VTPRINTENTER( "EngOp.OfferExecuteSyncL" )
       
   263     TBool complete( EFalse );
       
   264     iParams = aParams; // reset back to null in ExecuteL
       
   265     // test
       
   266 
       
   267     switch ( iCommand )
       
   268         {
       
   269         case KVtEngIncreaseAudioVolume:
       
   270         case KVtEngDecreaseAudioVolume:
       
   271             TVtEngAudioPlaybackUtil::HandleL( *this, iHandlers );
       
   272             complete = ETrue;
       
   273             break;
       
   274         case KVtEngPrepareViewFinder:
       
   275         case KVtEngPrepareViewFinderDSA:
       
   276         case KVtEngPrepareViewFinderDP:
       
   277         case KVtEngStartViewFinder:
       
   278         case KVtEngPauseViewFinder:
       
   279         case KVtEngStopViewFinder:
       
   280         case KVtEngPrepareRemoteRenderDSA:
       
   281         case KVtEngPrepareRemoteRenderDP:
       
   282         case KVtEngPrepareRemoteRenderNGA:
       
   283         case KVtEngStartRenderRemote:
       
   284         case KVtEngStopRenderRemote:
       
   285         case KVtEngPauseRenderRemote:
       
   286         case KVtEngSetZoomStep:
       
   287         case KVtEngFreeze:
       
   288             TVtEngViewFinderConfigureUtil::HandleL( *this, iHandlers );
       
   289             complete = ETrue;
       
   290             break;
       
   291         case KVtEngPrepareRemoteRender:
       
   292             break;
       
   293         case KVtEngStartDtmfTone:
       
   294         case KVtEngStopDtmfTone:
       
   295             // Handling of different UIIs, support is there
       
   296         case KVtEngSetUIIDtmfSupport:
       
   297         case KVtEngSetUIIBasicStringSupport:
       
   298         case KVtEngSetUIIIA5StringSupport:
       
   299         case KVtEngSetUIIGeneralStringSupport:
       
   300 
       
   301              TVtEngMediaTransportUtil::HandleL( *this, iHandlers );
       
   302              complete = ETrue;
       
   303             break;
       
   304 
       
   305         case KVtEngSetUIForeground:
       
   306         case KVtEngSetVideoQuality:
       
   307         case KVtEngRequestLastRemoteFrame:
       
   308             TVtEngRenderUtil::HandleL( *this, iHandlers );
       
   309             complete = ETrue;
       
   310             break;
       
   311 
       
   312             // Extension commands
       
   313         case KVtEngSetContrast:
       
   314         case KVtEngSetBrightness:
       
   315         case KVtEngSetWhiteBalance:
       
   316         case KVtEngSetColorTone:
       
   317 #if defined ( RD_VT_RTF )
       
   318         case KVtEngStartRecord:
       
   319         case KVtEngStopRecord:
       
   320 #endif
       
   321             TVtEngExtensionUtil::HandleL( *this );
       
   322             complete = ETrue;
       
   323             break;
       
   324 
       
   325         default:
       
   326             __VTPRINT( DEBUG_GEN, "EngOp.ExecuteL not handled sync" )
       
   327             break;
       
   328         }
       
   329     __VTPRINTEXITR( "EngOp.OfferExecuteSyncL %d", complete )
       
   330     return complete;
       
   331     }
       
   332 
       
   333 //  End of File