vtengines/videoteleng/Src/Base/cvtengmediatorservice.cpp
changeset 0 ed9695c8bcbe
child 3 b1602a5ab0a3
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     1 /*
       
     2 * Copyright (c) 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:  Mediator service implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "cvtengmediatorservice.h"
       
    22 #include    "cvtenginternaloperation.h"
       
    23 #include    "CVtEngStateManager.h"
       
    24 #include    "CVtEngEventManager.h"
       
    25 #include    "VtEngUtils.h"
       
    26 #include    "CVtEngSettings.h"
       
    27 #include    <cvtlogger.h>
       
    28 #include    <mediatorcommandresponder.h>
       
    29 #include    <mediatordomainuids.h>
       
    30 #include    <videotelcontrolmediatorapi.h> 
       
    31 #include    <videoteltophonecommandsapi.h>
       
    32 #include    <vtinternalmediatorapi.h>
       
    33 
       
    34 // CONSTANTS
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CVtEngMediatorService::StartLD
       
    40 // Mediator service starter.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 void CVtEngMediatorService::StartLD( 
       
    44         CMediatorCommandResponder& aResponder,
       
    45         CVtEngUtility& aUtils,
       
    46         const TUid aCategory,
       
    47         const TInt aCommand )
       
    48     {
       
    49     __VTPRINTENTER( "CVtEngMediatorService.StartLD" )
       
    50     CVtEngMediatorService* self = new ( ELeave ) CVtEngMediatorService(
       
    51         aResponder, aUtils, aCategory, aCommand );
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructAndDoServiceL();
       
    54     CleanupStack::Pop();
       
    55     __VTPRINTEXIT( "CVtEngMediatorService.StartLD" )
       
    56     }
       
    57     
       
    58 // -----------------------------------------------------------------------------
       
    59 // Destructor
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CVtEngMediatorService::~CVtEngMediatorService()
       
    63     {
       
    64     // ensure this is removed
       
    65     __VTPRINTENTER( "CVtEngMediatorService::~CVtEngMediatorService" )
       
    66     iUtils.EventManager().RemoveObserver( this );
       
    67     
       
    68     // send response if destructed due to leave in ConstructAndDoServiceL
       
    69     SendMediatorResponseD( EFalse );
       
    70     __VTPRINTEXIT( "CVtEngMediatorService::~CVtEngMediatorService" )
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CVtEngMediatorService::SetOperation
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void CVtEngMediatorService::SetOperation( CVtEngOperation* /*aActiveOp*/ )
       
    78     {
       
    79     __VTPRINTENTER( "CVtEngMediatorService.SetOperation" )
       
    80     // no-op
       
    81     __VTPRINTEXIT( "CVtEngMediatorService.SetOperation" )
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CVtEngMediatorService::CommandCompleteL
       
    86 // callback to internal operation.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CVtEngMediatorService::CommandCompleteL(
       
    90     const TVtEngCommandId /*aCommand*/,
       
    91     const TInt aResult )
       
    92     {
       
    93     __VTPRINTENTER( "CVtEngMediatorService.CommandCompleteL" )
       
    94 
       
    95     iServiceStatus = aResult;
       
    96 
       
    97     // Sends response to Telephony if not already sent by
       
    98     // HandleVtEventL -> SendMediatorResponseD
       
    99     SendMediatorResponseD( ETrue );
       
   100     __VTPRINTEXITR( "CVtEngMediatorService.CommandCompleteL %d", aResult )
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CVtEngMediatorService::HandleVtEventL
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CVtEngMediatorService::HandleVtEventL( TInt aEvent )
       
   108     {
       
   109     __VTPRINTENTER( "CVtEngMediatorService.HandleVtEventL" )
       
   110     
       
   111     // This is registered event observer when shutdown mediator command was
       
   112     // received. Now send response if state precondition is met
       
   113     if ( aEvent == KVtEngSessionStateChanged &&
       
   114          IsShuttingDown() )
       
   115         {
       
   116         // no interest on events any more, task fulfilled
       
   117         iUtils.EventManager().RemoveObserver( this );
       
   118         
       
   119         // iServiceStatus used for mediator response
       
   120         iServiceStatus = KErrNone;
       
   121         
       
   122         SendMediatorResponseD( EFalse );
       
   123         }
       
   124     __VTPRINTEXIT( "CVtEngMediatorService.HandleVtEventL" )
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CVtEngMediatorService::CVtEngMediatorService
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 CVtEngMediatorService::CVtEngMediatorService( 
       
   132     CMediatorCommandResponder& aResponder, 
       
   133     CVtEngUtility& aUtils,
       
   134     const TUid aCategory,
       
   135     const TInt aCommandId ) :
       
   136     iResponder( aResponder ), 
       
   137     iUtils( aUtils ),
       
   138     iCategory( aCategory ),
       
   139     iCommandId( aCommandId ),
       
   140     iServiceStatus( KErrNotReady )
       
   141     {
       
   142     __VTPRINTENTER( "CVtEngMediatorService.CVtEngMediatorService" )
       
   143     __VTPRINTEXIT( "CVtEngMediatorService.CVtEngMediatorService" )
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CVtEngMediatorService::ConstructAndDoServiceL
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CVtEngMediatorService::ConstructAndDoServiceL()
       
   151     {
       
   152     __VTPRINTENTER( "CVtEngMediatorService.ConstructAndDoServiceL" )
       
   153     __VTPRINT2( DEBUG_GEN, " CVtEngMediatorService.ConstructAndDoServiceL command id=%d", iCommandId )
       
   154     // if starting of any operation below fails (StartOperationL leaves),
       
   155     // this object is deleted. Destructor sends mediator response.
       
   156     // non-supported command leads to leave+destructor also (see default case)
       
   157     if ( KCatVideotelInternalCommands == iCategory)
       
   158         {
       
   159         switch ( iCommandId )
       
   160             {
       
   161             case EVtMediatorReleaseDataport:
       
   162                 if ( !IsShuttingDown()  )
       
   163                     {
       
   164                     // Mediator response is sent when state becomes appropriate, 
       
   165                     // indicated by call to HandleVtEventL, or
       
   166                     // when operation callback CommandCompleteL is called,
       
   167                     // which ever comes first. However, this object is deleted
       
   168                     // only after operation callback is received.
       
   169                     iUtils.EventManager().AddObserverL( this );
       
   170                     StartOperationL( KVtEngTerminateSession );
       
   171                     }     
       
   172                 // if already shutting down this is no op (and self destructed)
       
   173                 // if get this command because endactivecall from vt menu, do not do any op from here
       
   174                 else 
       
   175                     {
       
   176                     SendMediatorResponseD(EFalse);
       
   177                     }
       
   178                 break;
       
   179             default:
       
   180                 // requested command that is not supported, issue "failed" response
       
   181                 iServiceStatus = KErrNotSupported;            
       
   182                 break;
       
   183             }
       
   184         }
       
   185     else
       
   186         {
       
   187         switch ( iCommandId )
       
   188             {
       
   189             case EVtCmdUnmute:
       
   190             case EVtCmdMute:
       
   191                 {
       
   192                 TVtEngCommandId engineCmd = ( iCommandId == 
       
   193                     EVtCmdUnmute ) ? KVtEngUnmuteOutgoingAudio : 
       
   194                     KVtEngMuteOutgoingAudio;
       
   195                 if ( !IsShuttingDown()  )
       
   196                     {
       
   197                     StartOperationL( engineCmd );
       
   198                     }
       
   199                 else
       
   200                     {
       
   201                     SendMediatorResponseD(EFalse);
       
   202                     }
       
   203                 }
       
   204                 break;
       
   205             default:
       
   206                 // requested command that is not supported, issue "failed" response
       
   207                 iServiceStatus = KErrNotSupported;            
       
   208                 break;
       
   209             }     
       
   210         }
       
   211     if ( iServiceStatus != KRequestPending && !IsShuttingDown() )
       
   212         { // results in destruction of this object and sending of mediator 
       
   213           // response with error
       
   214         //__VTPRINT2( DEBUG_GEN, "CVtEngMediatorService.ConstructAndDoServiceL leave by iServiceStatus: %d", iServiceStatus )
       
   215         User::Leave( iServiceStatus );
       
   216         }
       
   217      
       
   218     __VTPRINTEXIT( "CVtEngMediatorService.ConstructAndDoServiceL" )
       
   219     }
       
   220 // -----------------------------------------------------------------------------
       
   221 // CVtEngMediatorService::IsShuttingDown
       
   222 // Checks if shutdown is ongoing
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 TBool CVtEngMediatorService::IsShuttingDown() const
       
   226     {
       
   227     __VTPRINTENTER( "CVtEngMediatorService.IsShuttingDown" )
       
   228     const MVtEngSessionInfo::TSessionState state = 
       
   229         iUtils.StateManager()->SessionState();
       
   230     TBool isShuttingDown = EFalse;
       
   231     
       
   232     // consider shutdown true if clearing or idle
       
   233     if ( state == MVtEngSessionInfo::EClearing || 
       
   234          state == MVtEngSessionInfo::EIdle )
       
   235         {
       
   236         isShuttingDown = ETrue;            
       
   237         }
       
   238     __VTPRINTEXITR( "CVtEngMediatorService.IsShuttingDown %d",
       
   239         isShuttingDown )
       
   240     return isShuttingDown;
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CVtEngMediatorService::StartOperationL
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 void CVtEngMediatorService::StartOperationL( const TVtEngCommandId aCommand )
       
   248     {
       
   249     __VTPRINTENTER( "CVtEngMediatorService.StartOperationL" )
       
   250     iOperation = CVtEngInternalOperation::NewL( 
       
   251         aCommand,
       
   252         iUtils.StateManager()->Handlers(),
       
   253         *this );        
       
   254     iOperation->ExecuteL();
       
   255     iServiceStatus = KRequestPending;
       
   256     __VTPRINTEXIT( "CVtEngMediatorService.StartOperationL" )
       
   257     }
       
   258         
       
   259 // -----------------------------------------------------------------------------
       
   260 // CVtEngMediatorService::SendMediatorResponseD
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 void CVtEngMediatorService::SendMediatorResponseD( const TBool aDeleteThis )
       
   264     {
       
   265     __VTPRINTENTER( "CVtEngMediatorService.SendMediatorResponseD" )
       
   266     __VTPRINT2( DEBUG_GEN, "CVtEngMediatorService.SendMediatorResponseD command: %d", iCommandId )
       
   267     if ( iCommandId != KErrNotFound )
       
   268         {
       
   269         if ( iCategory == KCatVideotelInternalCommands && iCommandId == EVtMediatorReleaseDataport )
       
   270             {
       
   271             iResponder.IssueResponse(
       
   272                 KMediatorVideoTelephonyDomain,
       
   273                 KCatVideotelInternalCommands,
       
   274                 iCommandId,
       
   275                 iServiceStatus,
       
   276                 KNullDesC8() );
       
   277               }
       
   278         else
       
   279             {
       
   280             iResponder.IssueResponse(
       
   281                 KMediatorVideoTelephonyDomain,
       
   282                 KCatPhoneToVideotelCommands,
       
   283                 iCommandId,
       
   284                 iServiceStatus,
       
   285                 KNullDesC8() );
       
   286             }
       
   287             
       
   288         // prevents further response because destructor also calls this method
       
   289         iCommandId = KErrNotFound;
       
   290         }
       
   291     if ( aDeleteThis )
       
   292         {
       
   293         // note! check above is mandatory because this method is called
       
   294         // also from destructor.
       
   295         delete this;
       
   296         }
       
   297     __VTPRINTEXIT( "CVtEngMediatorService.SendMediatorResponseD" )
       
   298     }
       
   299         
       
   300 //  End of File
       
   301