phoneengine/callhandling/src/cpevideocallhandling.cpp
changeset 0 5f000ab63145
child 21 92ab7f8d0eab
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2002-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:  This file contains implementation of CPEVideoCallHandling class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "cpevideocallhandling.h"
       
    21 #include "cpesinglecall.h"
       
    22 #include "pevirtualengine.h"
       
    23 #include "cpecallarrayowner.h"
       
    24 #include "cpecallarrayowner.h"
       
    25 #include "cpegprstermination.h"
       
    26 
       
    27 #include <mpephonemodelinternal.h>
       
    28 #include <e32property.h>
       
    29 #include <gsmerror.h>
       
    30 #include <mpedatastore.h>
       
    31 #include <NetworkHandlingDomainPSKeys.h>
       
    32 #include <pepanic.pan>
       
    33 #include <pevirtualengine.h>
       
    34 #include <talogger.h>
       
    35 #include <ctsydomainpskeys.h>
       
    36 #include <connect/sbdefs.h>
       
    37 #include <ccce.h>
       
    38 #include <mccecall.h>
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CPEVideoCallHandling::CPEVideoCallHandling
       
    42 // C++ default constructor can NOT contain any code, that
       
    43 // might leave.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CPEVideoCallHandling::CPEVideoCallHandling(
       
    47         MPEMessageSender& aOwner,
       
    48         MPEPhoneModelInternal& aModel,        
       
    49         CCCE& aConvergedCallEngine,
       
    50         CPECallArrayOwner& aCallArrayOwner
       
    51         ) : iOwner( aOwner ),
       
    52             iModel( aModel ),
       
    53             iConvergedCallEngine( aConvergedCallEngine ),
       
    54             iDataCallName( KNullDesC ),
       
    55             iCallArrayOwner( aCallArrayOwner ),
       
    56             iDataStore( *( aModel.DataStore( ) ) ),
       
    57             iRestoreCauseVTCallReject( EFalse )
       
    58     {
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CPEVideoCallHandling::ConstructL
       
    63 // Symbian 2nd phase constructor can leave.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CPEVideoCallHandling::ConstructL()
       
    67     {
       
    68     TEFLOGSTRING( KTAOBJECT, "VID CPEVideoCallHandling::ConstructL start." );
       
    69 
       
    70     iCallOpenParams = CCCECallParameters::NewL();
       
    71     TEFLOGSTRING( KTAOBJECT, "VID CPEVideoCallHandling::ConstructL complete." );
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CPEVideoCallHandling::NewL
       
    76 // Two-phased constructor.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 CPEVideoCallHandling* CPEVideoCallHandling::NewL(
       
    80         MPEMessageSender& aOwner,
       
    81         MPEPhoneModelInternal& aModel,         
       
    82         CCCE& aConvergedCallEngine,
       
    83         CPECallArrayOwner& aCallArrayOwner )
       
    84     {
       
    85     TEFLOGSTRING( KTAOBJECT, "VID CPEVideoCallHandling::NewL start." );
       
    86     CPEVideoCallHandling* self = new ( ELeave ) CPEVideoCallHandling( aOwner, 
       
    87                                                                       aModel, 
       
    88                                                                       aConvergedCallEngine,
       
    89                                                                       aCallArrayOwner );
       
    90     CleanupStack::PushL( self );
       
    91     self->ConstructL();
       
    92     CleanupStack::Pop( self );
       
    93     TEFLOGSTRING( KTAOBJECT, "VID CPEVideoCallHandling::NewL complete." );
       
    94     return self;
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CPEVideoCallHandling::~CPEVideoCallHandling()
       
    99 // Destructor
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 CPEVideoCallHandling::~CPEVideoCallHandling()
       
   103     {
       
   104     TFLOGSTRING( "CallHandling: CPEVideoCallHandling::~CPEVideoCallHandling() Start");
       
   105     delete iGprsInterface;
       
   106     iGprsInterface = NULL;
       
   107     delete iCallOpenParams;
       
   108     TFLOGSTRING( "CallHandling: CPEVideoCallHandling::~CPEVideoCallHandling() complete");
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CPEVideoCallHandling::AnswerCall
       
   113 // Answers the incoming call
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TInt CPEVideoCallHandling::AnswerCall()
       
   117     {
       
   118     TEFLOGSTRING( KTAINT, "VID CPEVideoCallHandling::AnswerCall");
       
   119     TInt errorCode( KErrNotFound );
       
   120     CPESingleCall* dataCallData = VideoCallByState( EPEStateRinging );
       
   121     if ( dataCallData )
       
   122         {
       
   123         if ( GetNumberOfCalls() == 1 )
       
   124             {
       
   125             TEFLOGSTRING( KTAINT, "VID CPEVideoCallHandling::AnswerCall > CPEDataCall::Answer" );
       
   126             dataCallData->Answer();
       
   127             errorCode = KErrNone;
       
   128             }
       
   129         else
       
   130             {
       
   131             TEFLOGSTRING( KTAERROR, 
       
   132                     "VID CPEVIDEOCALLHANDLING::ANSWERCALL: NOT ALLOWED WITH EXISTING CALLS!" );
       
   133             errorCode = ECCPErrorNotAllowed;
       
   134             }
       
   135         }
       
   136     else
       
   137         {
       
   138         TEFLOGSTRING( KTAERROR, 
       
   139                 "VID CPEVIDEOCALLHANDLING::ANSWERCALL: NO RINGING CALLS FOUND!" );
       
   140         }
       
   141 
       
   142     return errorCode;
       
   143     }
       
   144     
       
   145 // -----------------------------------------------------------------------------
       
   146 // CPEVideoCallHandling::VideoCallByState
       
   147 // Finds a data call object that is in specified  state
       
   148 // -----------------------------------------------------------------------------
       
   149 //  
       
   150 CPESingleCall* CPEVideoCallHandling::VideoCallByState( 
       
   151         const TPEState aState ) const
       
   152     {
       
   153     TEFLOGSTRING( KTAINT, "CALL CPEVideoCallHandling::DataCallByState" );
       
   154     CPESingleCall* returnValue( NULL );
       
   155     CPESingleCall* callData;
       
   156         
       
   157     for ( TInt callId = KPEDataCallIdBase; 
       
   158           callId < ( KPEDataCallIdBase + KPEMaximumNumberOfDataCalls ); 
       
   159           callId++ )
       
   160         {
       
   161         callData = iCallArrayOwner.GetCallObject( callId );
       
   162         if ( callData 
       
   163              && ( callData->GetCallState() == aState ) )
       
   164             {
       
   165             returnValue = callData;
       
   166             TEFLOGSTRING2( KTAINT, 
       
   167                 "CALL CPEVideoCallHandling::DataCallByState %d", callId );
       
   168             break;
       
   169             }
       
   170         }
       
   171     return returnValue;
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CPEVideoCallHandling::CallTerminatedError
       
   176 // Handles RemoteTerminated. 
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 TInt CPEVideoCallHandling::CallTerminatedError( const TInt aCallId )
       
   180     {
       
   181     TEFLOGSTRING2( KTAINT, 
       
   182             "VID CPEVideoCallHandling::CallTerminatedError, aCallId: %d",
       
   183             aCallId );
       
   184     
       
   185     TInt errorCode( KErrNone );    
       
   186 	CPESingleCall* dataCall = iCallArrayOwner.GetCallObject( aCallId );
       
   187 	if ( dataCall )
       
   188 	    {
       
   189 	    dataCall->GetErrorCode( errorCode );
       
   190 	    }
       
   191 	
       
   192 	TEFLOGSTRING2( KTAINT, 
       
   193 	            "VID CPEVideoCallHandling::CallTerminatedError, errorCode: %d",
       
   194 	            errorCode );
       
   195     return errorCode;
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CPEVideoCallHandling::DataPortInUse
       
   200 // Tells if the call has reserved serial communications data port for use
       
   201 // The default value is EFalse, i.e. the data port has not been reserved for
       
   202 // use. The data port is recovered when no longer needed.
       
   203 // -----------------------------------------------------------------------------
       
   204 // 
       
   205 TBool CPEVideoCallHandling::DataPortInUse(
       
   206         TInt aCallId ) const
       
   207     {
       
   208     TBool dataPortInUse( EFalse );
       
   209     TPEState state;
       
   210     
       
   211     if ( CallIdCheck::IsVideo( aCallId ) )
       
   212         {
       
   213         CPESingleCall* callData = iCallArrayOwner.GetCallObject( aCallId );
       
   214         if( callData )
       
   215             {
       
   216             state = callData->GetCallState();
       
   217             if( state == EPEStateConnected )
       
   218                 {
       
   219                 dataPortInUse = ETrue;
       
   220                 }
       
   221             }
       
   222         }
       
   223     return dataPortInUse;
       
   224     }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CPEVideoCallHandling::DialCall
       
   228 // Creates dialing request to the Multimode ETel. 
       
   229 // This request is for creating a new multimedia (=data) call
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 TInt CPEVideoCallHandling::DialCall(
       
   233         const TPEPhoneNumber& aNumber,
       
   234         TInt& aCallId )
       
   235     {
       
   236     TEFLOGSTRING( KTAINT, "VID CPEVideoCallHandling::DialCall" );
       
   237     TInt errorCode( KErrNone );
       
   238     TInt networkMode( ENWNetworkModeUnknown );
       
   239     CPESingleCall* callData( NULL );
       
   240     
       
   241     RProperty::Get( KPSUidNetworkInfo, KNWTelephonyNetworkMode, networkMode );   
       
   242 
       
   243     TInt restoreValue;
       
   244     RProperty::Get( KUidSystemCategory, conn::KUidBackupRestoreKey, restoreValue );       
       
   245     
       
   246     if ( networkMode == ENWNetworkModeWcdma && 
       
   247         !( restoreValue & ( conn::EBURRestoreFull | conn::EBURRestorePartial )) )
       
   248         {
       
   249         TRAP( errorCode, callData = OpenNewCallL( aNumber ) );
       
   250         if( errorCode == KErrNone )
       
   251             {
       
   252             TEFLOGSTRING( KTAINT, "CALL CPEVideoCallHandling::DialCall > Dial" );
       
   253             errorCode = callData->Dial( aNumber );
       
   254             if ( errorCode != KErrNone )
       
   255                 {
       
   256                 // Dial failed: clean up
       
   257                 ReleaseCallObject( callData->GetCallId() );
       
   258                 TEFLOGSTRING2( KTAERROR, 
       
   259                         "VID CALL CPEVideoCallHandling::DialCall ! DIAL FAILED: MAY NOT PROCEED! %d",
       
   260                         errorCode );
       
   261                 }
       
   262             else
       
   263                 {
       
   264                 // Dial request passed on successfully: forward new call id
       
   265                 aCallId = callData->GetCallId();
       
   266                 }
       
   267             }
       
   268         }
       
   269     else
       
   270         {
       
   271         TEFLOGSTRING( KTAERROR, 
       
   272             "VID CPEVideoCallHandling::DialCall: Attempting video call in 2G network!" );
       
   273         errorCode = ( networkMode != ENWNetworkModeWcdma ) ? 
       
   274                       ECCPErrorVideoCallNotSupportedByNetwork : 
       
   275                       ECCPErrorVideoCallNotAllowedDuringRestore;
       
   276         }    
       
   277         
       
   278     return errorCode;
       
   279     }
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CPEVideoCallHandling::HangUp
       
   283 // terminates an ongoing call
       
   284 // Method checks that call id is valid number and
       
   285 // hangups conference or data call or reroutes call to base class.
       
   286 // (other items were commented in a header).
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 TInt CPEVideoCallHandling::HangUp( TInt aCallId )
       
   290     {
       
   291     TEFLOGSTRING( KTAINT, "VID CPEVideoCallHandling::HangUp" );
       
   292     TInt errorCode( KErrNotFound );
       
   293     CPESingleCall* videoCall = iCallArrayOwner.GetCallObject( aCallId );
       
   294     
       
   295     if ( videoCall && CallIdCheck::IsVideo( aCallId ) ) 
       
   296         {
       
   297 
       
   298         errorCode = videoCall->HangUp();
       
   299         }
       
   300     return errorCode;
       
   301     }
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CPEVideoCallHandling::InitCall
       
   305 // Handles the initializing of a single data/video call.
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 void CPEVideoCallHandling::InitCall( MCCECall& aCall )
       
   309     {
       
   310     TEFLOGSTRING( KTAINT, "CALL CPEVideoCallHandling::InitCall" );
       
   311     CPESingleCall* callData( NULL );
       
   312 	  TRAP_IGNORE( callData = iCallArrayOwner.CreateDataCallL( *this ) );
       
   313 
       
   314     if ( callData )
       
   315         {
       
   316         iModel.DataStore()->SetPhoneNumber( KNullDesC() );
       
   317         iModel.DataStore()->SetServiceId( callData->GetCallId(), aCall.ServiceId() );
       
   318         callData->SetCall( aCall );
       
   319         iModel.DataStore()->SetCallSecureStatus( callData->IsSecureCall(), callData->GetCallId() );
       
   320         iModel.DataStore()->SetSecureSpecified( callData->SecureSpecified() );
       
   321         
       
   322     	const CCCPCallParameters& callParameters = aCall.Parameters();
       
   323         switch ( callParameters.CallType() )
       
   324             {
       
   325             case CCPCall::ECallTypeCSVoice:
       
   326                 {
       
   327                 iModel.DataStore()->SetCallType( EPECallTypeCSVoice, callData->GetCallId() );
       
   328                 }
       
   329                 break;
       
   330             case CCPCall::ECallTypeVideo:
       
   331                 {
       
   332                 iModel.DataStore()->SetCallType( EPECallTypeVideo, callData->GetCallId() );
       
   333                 }
       
   334                 break;
       
   335             case CCPCall::ECallTypePS:
       
   336                 {
       
   337                 iModel.DataStore()->SetCallType( EPECallTypeVoIP, callData->GetCallId() );
       
   338                 }
       
   339                 break;
       
   340             default:
       
   341                 __ASSERT_DEBUG( EFalse, Panic( EPEPanicIndexOutOfRange ));
       
   342                 break;
       
   343             }
       
   344         }
       
   345     else
       
   346     	{
       
   347     	Panic( EPEPanicNoFreeCalls );
       
   348     	}
       
   349     }
       
   350  
       
   351 // -----------------------------------------------------------------------------
       
   352 // CPEVideoCallHandling::IsMultimedia
       
   353 // Checks if the data call is a multimedia call. Requires that the data call has
       
   354 // already been opened.
       
   355 // -----------------------------------------------------------------------------
       
   356 //
       
   357 TBool CPEVideoCallHandling::IsMultimedia( TInt aCallId ) const
       
   358     {
       
   359     TEFLOGSTRING2( KTAINT, "VID CPEVideoCallHandling::IsMultimedia %d", aCallId );
       
   360     
       
   361     TBool multimedia( EFalse );
       
   362     CPESingleCall* videoCall = iCallArrayOwner.GetCallObject( aCallId );
       
   363     
       
   364     if ( videoCall && CallIdCheck::IsVideo( aCallId ) 
       
   365          && videoCall->Call().Parameters().CallType()  
       
   366                 == CCPCall::ECallTypeVideo )
       
   367         {
       
   368         multimedia = ETrue;
       
   369         }
       
   370         
       
   371     return multimedia;
       
   372     }
       
   373 
       
   374 // -----------------------------------------------------------------------------
       
   375 // CPEVideoCallHandling::NotifySystemCallStateChanged
       
   376 // Notifies system for changes to the call state.
       
   377 // -----------------------------------------------------------------------------
       
   378 //
       
   379 void CPEVideoCallHandling::NotifySystemCallStateChanged( 
       
   380         MEngineMonitor::TPEMessagesFromPhoneEngine aMessage,  // The enumeration number of the message
       
   381         TInt aCallId )
       
   382     {
       
   383     TEFLOGSTRING2( KTAINT, "VID CPEVideoCallHandling::NotifySystemCallStateChanged %d", aCallId );
       
   384 	// this needs to be checked because this function is called for all data calls
       
   385 	if ( IsMultimedia( aCallId ) )
       
   386         {
       
   387 	    if ( aMessage == MEngineMonitor::EPEMessageIncoming ||
       
   388 	       aMessage == MEngineMonitor::EPEMessageDialing )
       
   389 	        {
       
   390             TInt updateError = RProperty::Set( KPSUidCtsyCallInformation, 
       
   391                 KCTsyCallType, EPSCTsyCallTypeH324Multimedia );
       
   392             TEFLOGSTRING2( updateError?KTAERROR:KTAMESOUT, 
       
   393                 "VID CPEVideoCallHandling::NotifySystemCallStateChanged request RProperty::Set, EPSCTsyCallTypeH324Multimedia, updateError: ",
       
   394                 updateError );
       
   395 	        }
       
   396         }
       
   397     }
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CPEVideoCallHandling::SendMessage
       
   401 // Overrides CPECallHandling::SendMessage to provide internal handling for gsm events
       
   402 // and common events related to multimedia calls.
       
   403 // -----------------------------------------------------------------------------
       
   404 //
       
   405 void CPEVideoCallHandling::SendMessage(
       
   406         MEngineMonitor::TPEMessagesFromPhoneEngine aMessage,
       
   407         TInt aCallId )
       
   408     {
       
   409     TEFLOGSTRING3( KTAINT, 
       
   410         "VID CPEVideoCallHandling::SendMessage, message id: %d, call id: %d", 
       
   411         aMessage, 
       
   412         aCallId );
       
   413         
       
   414     TInt error( KErrNone );
       
   415     CPESingleCall* videoCall = iCallArrayOwner.GetCallObject( aCallId );
       
   416     CPESingleCall* connectedVideoCall = VideoCallByState( EPEStateConnected );
       
   417 
       
   418     if ( IsMultimedia( aCallId ) )
       
   419         {
       
   420         switch ( aMessage )
       
   421             {
       
   422             case MEngineMonitor::EPEMessageIncoming:
       
   423             case MEngineMonitor::EPEMessageDialing:
       
   424                 {
       
   425                 TInt restoreValue;
       
   426                 RProperty::Get( KUidSystemCategory, conn::KUidBackupRestoreKey, restoreValue );
       
   427                 if( ( restoreValue & ( conn::EBURRestoreFull | conn::EBURRestorePartial ) ) )
       
   428                     {
       
   429                     // First phase VT and restore: Check if there is a arriving VT 
       
   430             	    // call and Restore ongoing.
       
   431             	    TEFLOGSTRING( KTAINT, 
       
   432                         "VID CPEVideoCallHandling::SendMessage > HangUp restore active " );
       
   433                	    iRestoreCauseVTCallReject = ETrue;
       
   434                	    if( videoCall )
       
   435                	        {
       
   436                	        videoCall->HangUp();
       
   437                	        }
       
   438                	    aMessage = MEngineMonitor::EPEMessageDoNotSendMe;
       
   439                     }
       
   440                 break;
       
   441                 }
       
   442             case MEngineMonitor::EPEMessageDisconnecting:
       
   443                 {
       
   444                 if( iRestoreCauseVTCallReject )
       
   445 	                {
       
   446 	            	// Second phase VT and restore: Check if there is a rejected arriving VT call 
       
   447 	                // and Restore ongoing, then don't notify observers.
       
   448 	                iRestoreCauseVTCallReject = EFalse;
       
   449 	                TEFLOGSTRING( KTAINT, 
       
   450 				        "VID CPEVideoCallHandling::SendMessage Second phase Restore and VT call" );
       
   451 	                aMessage = MEngineMonitor::EPEMessageDoNotSendMe;
       
   452 	                }
       
   453                 break;
       
   454                 }
       
   455             case MEngineMonitor::EPEMessageIdle:
       
   456                 {
       
   457                 iRestoreCauseVTCallReject = EFalse;
       
   458                 // Check reject video cace, if there is connect VT call don't disconnect
       
   459                 if( !connectedVideoCall )
       
   460 	                {
       
   461 	                if ( CallTerminatedError( aCallId ) == KErrGsmCCIncompatibleDestination )
       
   462 	                    {
       
   463 	                    error = KErrGsmCCIncompatibleDestination;
       
   464 	                    }
       
   465 	                }
       
   466                 break;
       
   467                 }
       
   468             default:
       
   469                 {
       
   470                 TEFLOGSTRING2( 
       
   471                     KTAINT, 
       
   472                     "VID CPEVideoCallHandling::SendMessage: multimedia call, message: %d", 
       
   473                     aMessage );
       
   474                 break;
       
   475                 }
       
   476             } 
       
   477         }
       
   478     else
       
   479         {
       
   480         TEFLOGSTRING2( 
       
   481             KTAINT, 
       
   482             "VID CPEVideoCallHandling::SendMessage, isMultimedia: %d", 
       
   483             IsMultimedia( aCallId ) );
       
   484         }
       
   485     if ( error == KErrNone )
       
   486         {
       
   487         iOwner.SendMessage( aMessage, aCallId );
       
   488         }
       
   489     else
       
   490         {
       
   491         SendErrorMessage( aCallId, error );
       
   492         }
       
   493     }
       
   494 
       
   495 // -----------------------------------------------------------------------------
       
   496 // CPEVideoCallHandling::VideoCallInState
       
   497 // Checks if there are any data calls in the specified state
       
   498 // -----------------------------------------------------------------------------
       
   499 //
       
   500 TBool CPEVideoCallHandling::VideoCallInState( const TPEState& aState ) const
       
   501     {
       
   502     TEFLOGSTRING( KTAINT, "CALL CPEVideoCallHandling::DataCallInState" );
       
   503     TBool returnValue( EFalse );
       
   504     if( VideoCallByState( aState ) )
       
   505         {
       
   506         returnValue = ETrue;
       
   507         }
       
   508     return returnValue;
       
   509     }
       
   510 
       
   511 
       
   512 // -----------------------------------------------------------------------------
       
   513 // CPEVideoCallHandling::IsPhoneNumberAvailable
       
   514 // -----------------------------------------------------------------------------
       
   515 //
       
   516 TBool CPEVideoCallHandling::IsPhoneNumberAvailable( const TInt aCallId )
       
   517     {
       
   518     TEFLOGSTRING2( KTAINT, 
       
   519         "VID CPEVideoCallHandling::IsPhoneNumberAvailable, aCallId: %d"
       
   520         , aCallId );
       
   521     TBool phoneNumberAvailable ( EFalse );
       
   522         
       
   523     if ( iDataStore.CallDirection( aCallId ) == RMobileCall::EMobileOriginated )
       
   524 	    {
       
   525 	    phoneNumberAvailable = ETrue;	
       
   526 	    }
       
   527     else
       
   528 	    {
       
   529 	    RMobileCall::TMobileCallRemoteIdentityStatus remoteIdentity;
       
   530 	    remoteIdentity = iDataStore.RemoteIdentity( aCallId );
       
   531 	    TEFLOGSTRING2( KTAINT, 
       
   532 	        "VID CPEVideoCallHandling::IsPhoneNumberAvailable, remoteIdentity: %d", 
       
   533 	        remoteIdentity);
       
   534 	    phoneNumberAvailable = ( remoteIdentity == RMobileCall::ERemoteIdentityAvailable ); 	
       
   535 	    }
       
   536     TEFLOGSTRING2( KTAINT, 
       
   537         "VID CPEVideoCallHandling::IsPhoneNumberAvailable, isAvailable: %d", 
       
   538         phoneNumberAvailable );
       
   539     return phoneNumberAvailable;
       
   540     }
       
   541     
       
   542 // -----------------------------------------------------------------------------
       
   543 // CPEVideoCallHandling::VideoCallByState
       
   544 // returns CPEVoiceCall video call object by State
       
   545 // -----------------------------------------------------------------------------
       
   546 //
       
   547 CPESingleCall* CPEVideoCallHandling::VideoCallByState( TPEState aState )
       
   548     {
       
   549     TEFLOGSTRING2( KTAINT, 
       
   550             "CPEVideoCallHandling::VideoCallByState, aState: %d", aState );    
       
   551     TPEState state;
       
   552     CPESingleCall* returnValue( NULL );
       
   553 
       
   554     for ( TInt callId = KPEDataCallIdBase; 
       
   555           callId < ( KPEDataCallIdBase + KPEMaximumNumberOfDataCalls );
       
   556           callId++ )
       
   557         {        
       
   558         CPESingleCall* callData = iCallArrayOwner.GetCallObject( callId );
       
   559         if( callData )
       
   560             {
       
   561             state = callData->GetCallState();
       
   562 
       
   563             if ( state == aState )
       
   564                 {
       
   565                 returnValue = callData;
       
   566                 break;
       
   567                 }
       
   568             }
       
   569         }
       
   570     return returnValue;
       
   571     }
       
   572 
       
   573 // -----------------------------------------------------------------------------
       
   574 // Replace active video call with a waiting video call
       
   575 // NOT SUPPORTED AS OF 5.1
       
   576 // -----------------------------------------------------------------------------
       
   577 //    
       
   578 TInt CPEVideoCallHandling::ReplaceActive( TInt /*aCallId*/  )
       
   579     {
       
   580     return KErrNone;
       
   581     }
       
   582 
       
   583 // -----------------------------------------------------------------------------
       
   584 // CPEVideoCallHandling::SetCallParams
       
   585 //
       
   586 // -----------------------------------------------------------------------------
       
   587 //
       
   588 void CPEVideoCallHandling::SetCallParams( TInt aCallId )
       
   589     {
       
   590     TEFLOGSTRING2( KTAINT, 
       
   591             "VID CCPEVideoCallHandling::SetCallParams, aCallId: %d", aCallId );
       
   592     iCallOpenParams->SetLineType( CCCECallParameters::ECCELineTypePrimary );
       
   593 
       
   594     switch ( iModel.DataStore()->CallTypeCommand() )
       
   595         {
       
   596         case EPECallTypeVideo:
       
   597             {
       
   598             iCallOpenParams->SetCallType( CCPCall::ECallTypeVideo );
       
   599             iModel.DataStore()->SetServiceIdCommand( 1 );
       
   600             iModel.DataStore()->SetCallType( EPECallTypeVideo, aCallId );
       
   601             }
       
   602             break;
       
   603         default:
       
   604             __ASSERT_DEBUG( EFalse, Panic( EPEPanicIndexOutOfRange ));
       
   605             iCallOpenParams->SetCallType( CCPCall::ECallTypeVideo );
       
   606             iModel.DataStore()->SetServiceIdCommand( 1 );
       
   607             iModel.DataStore()->SetCallType( EPECallTypeVideo, aCallId );
       
   608             break;
       
   609         } 
       
   610     iCallOpenParams->SetServiceId( iModel.DataStore()->ServiceIdCommand() );
       
   611     }
       
   612 
       
   613 // -----------------------------------------------------------------------------
       
   614 // CPEVideoCallHandling::OpenNewCallL
       
   615 // returns ETrue if hangup active
       
   616 // -----------------------------------------------------------------------------
       
   617 //
       
   618 CPESingleCall* CPEVideoCallHandling::OpenNewCallL( const TPEPhoneNumber& aNumber )
       
   619     {
       
   620     TEFLOGSTRING( KTAINT, "VID CPEVideoCallHandling::OpenNewCallL");
       
   621     TInt errorCode( KErrNone );
       
   622     CPESingleCall* callData( NULL );
       
   623     MCCECall* cceCall( NULL );
       
   624     
       
   625     callData = iCallArrayOwner.CreateDataCallL( *this );
       
   626     SetCallParams( callData->GetCallId() );
       
   627     
       
   628     TEFLOGSTRING( KTAINT, 
       
   629         "VID CPEVideoCallHandling::OpenNewCallL > CCCE::OpenNewCallL");
       
   630     TRAP( errorCode, 
       
   631           cceCall = &( iConvergedCallEngine.OpenNewCallL( aNumber, 
       
   632                                                           *iCallOpenParams, 
       
   633                                                           *callData ) ) );
       
   634     if ( errorCode == KErrNone )
       
   635     	{
       
   636     	callData->SetCall( *cceCall );
       
   637     	iModel.DataStore()->SetServiceId( callData->GetCallId(), cceCall->ServiceId() );
       
   638     	iModel.DataStore()->SetCallSecureStatus( callData->IsSecureCall(), callData->GetCallId() );
       
   639         iModel.DataStore()->SetSecureSpecified( callData->SecureSpecified() );
       
   640     	}
       
   641     else
       
   642     	{
       
   643     	// Open new call failed
       
   644     	ReleaseCallObject( callData->GetCallId() );
       
   645 		TEFLOGSTRING2( KTAERROR, 
       
   646 		        "VID CPEVideoCallHandling::DIALCALL ! OPENNEWCALL FAILED: MAY NOT PROCEED! %d", 
       
   647 		        errorCode );
       
   648 	    User::Leave( errorCode );
       
   649     	}
       
   650     return callData;
       
   651     }
       
   652 
       
   653 // -----------------------------------------------------------------------------
       
   654 // CPEVideoCallHandling::GetCallState
       
   655 // Returns call state information.
       
   656 // -----------------------------------------------------------------------------
       
   657 //
       
   658 TPEState CPEVideoCallHandling::GetCallState( TInt aCallId  )
       
   659     {
       
   660     TEFLOGSTRING2( KTAINT, 
       
   661             "CALL CPEVideoCallHandling::GetCallState %d", aCallId );
       
   662     TPEState callState( EPEStateUnknown );
       
   663     CPESingleCall* callData = iCallArrayOwner.GetCallObject( aCallId );
       
   664     if( callData )
       
   665         {
       
   666         callState = callData->GetCallState();
       
   667         }
       
   668     else
       
   669         {
       
   670         callState = EPEStateIdle;
       
   671         }
       
   672     TEFLOGSTRING2( KTAINT, 
       
   673             "CALL CPEVideoCallHandling::GetCallState, callState: %d", 
       
   674             callState );
       
   675     return callState;
       
   676     }
       
   677     
       
   678 // -----------------------------------------------------------------------------
       
   679 // CPEVideoCallHandling::VideoCallById
       
   680 // returns CPESingleCall video call object by State
       
   681 // -----------------------------------------------------------------------------
       
   682 //
       
   683 CPESingleCall* CPEVideoCallHandling::VideoCallById( TInt aCallId )
       
   684     {
       
   685     TEFLOGSTRING2( KTAINT, "VID CPEVideoCallHandling::VideoCallById %d", aCallId );
       
   686     return iCallArrayOwner.GetCallObject( aCallId );
       
   687     }
       
   688 
       
   689 // -----------------------------------------------------------------------------
       
   690 // CPEVideoCallHandling::GetNumberOfCalls
       
   691 // Returns number of data calls.
       
   692 // -----------------------------------------------------------------------------
       
   693 //
       
   694 TInt CPEVideoCallHandling::GetNumberOfCalls()
       
   695     {
       
   696     TEFLOGSTRING( KTAINT, "CALL CPEVideoCallHandling::GetNumberOfCalls" );
       
   697     // Count ongoing calls
       
   698     return iCallArrayOwner.ActiveCallCount();
       
   699     }
       
   700     
       
   701 
       
   702 // -----------------------------------------------------------------------------
       
   703 // CPEVideoCallHandling::SendMessage
       
   704 // Reroutes messages to the Phone Engine
       
   705 // -----------------------------------------------------------------------------
       
   706 //
       
   707 void CPEVideoCallHandling::SendMessage( 
       
   708     MEngineMonitor::TPEMessagesFromPhoneEngine aMessage,
       
   709     const TName& aName )
       
   710     {
       
   711     TEFLOGSTRING2( KTAINT, "CALL CPECallHandling::SendMessage, message id: %d", aMessage );
       
   712     CPESingleCall* videoCall = VideoCallByName( aName );
       
   713     if( videoCall )
       
   714         {
       
   715         SendMessage( aMessage, videoCall->GetCallId() );
       
   716         }
       
   717     }
       
   718 
       
   719 // -----------------------------------------------------------------------------
       
   720 // CPEVideoCallHandling::VideoCallByName
       
   721 // returns data call object by name
       
   722 // -----------------------------------------------------------------------------
       
   723 //
       
   724 CPESingleCall* CPEVideoCallHandling::VideoCallByName( const TName& aName )
       
   725     {       
       
   726     TEFLOGSTRING( KTAINT, "CALL CPEVideoCallHandling::DataCallByName" );
       
   727     CPESingleCall* returnValue( NULL );
       
   728     CPESingleCall* callData;
       
   729     for ( TInt callId = KPEDataCallIdBase; 
       
   730           callId < ( KPEDataCallIdBase + KPEMaximumNumberOfDataCalls ); 
       
   731           callId++ )
       
   732         {
       
   733         callData = iCallArrayOwner.GetCallObject( callId );
       
   734 
       
   735         if ( callData 
       
   736              && ( VideoCallName( callId ) == aName ) )
       
   737             {
       
   738             returnValue = callData;
       
   739             TEFLOGSTRING2( KTAINT, 
       
   740                 "CALL CPEVideoCallHandling::DataCallByName %d", callId );
       
   741             break;
       
   742             }
       
   743         }
       
   744     return returnValue;
       
   745     }
       
   746 
       
   747 // -----------------------------------------------------------------------------
       
   748 // CPEVideoCallHandling::VideoCallName
       
   749 // Finds data call name given the call id.
       
   750 // -----------------------------------------------------------------------------
       
   751 //  
       
   752 TName& CPEVideoCallHandling::VideoCallName( const TInt aCallId )
       
   753     {
       
   754     TEFLOGSTRING( KTAINT, "CALL CPEVideoCallHandling::DataCallName" );
       
   755     
       
   756     iDataCallName = KNullDesC;
       
   757     TInt errorCode( KErrNone );
       
   758 
       
   759     if ( CallIdCheck::IsVideo( aCallId ) )
       
   760         {
       
   761         RMobileCall::TMobileCallInfoV3* dataCallInfo = NULL;
       
   762         dataCallInfo = new RMobileCall::TMobileCallInfoV3;
       
   763         
       
   764         if ( dataCallInfo )
       
   765             {
       
   766             errorCode = GetCallInfo( *dataCallInfo, aCallId );
       
   767             TEFLOGSTRING2( KTAINT, 
       
   768                 "CALL CPEVideoCallHandling::DataCallName > GetCallInfo, error code: %d", 
       
   769                 errorCode );
       
   770  
       
   771             if ( errorCode == KErrNone )
       
   772                 {
       
   773                 iDataCallName = dataCallInfo->iCallName;
       
   774                 }
       
   775             }
       
   776         else
       
   777             {
       
   778             errorCode = KErrNoMemory;
       
   779             TEFLOGSTRING( KTAINT, 
       
   780                 "CALL CPEVideoCallHandling::DataCallName, error code = KErrNoMemory" );
       
   781             }
       
   782         delete dataCallInfo;
       
   783         }
       
   784     return iDataCallName;
       
   785     }
       
   786 
       
   787 
       
   788 // -----------------------------------------------------------------------------
       
   789 // CPEVideoCallHandling::GetCallInfo
       
   790 // Returns data call information.
       
   791 // -----------------------------------------------------------------------------
       
   792 //
       
   793 TInt CPEVideoCallHandling::GetCallInfo( 
       
   794         RMobileCall::TMobileCallInfoV3& aCallInfo,
       
   795         TInt aCallId )
       
   796     {
       
   797     TEFLOGSTRING2( KTAINT, "CALL CPEVideoCallHandling::GetCallInfo %d", aCallId );
       
   798     CPESingleCall* videoCall( NULL );
       
   799     TInt errorCode( KErrNotFound );
       
   800     videoCall = iCallArrayOwner.GetCallObject( aCallId );
       
   801     if ( videoCall && CallIdCheck::IsVideo( aCallId ) )
       
   802         {
       
   803         errorCode = videoCall->GetCallInfo( aCallInfo );
       
   804         errorCode = KErrNone;
       
   805         }
       
   806     else
       
   807         {
       
   808         __ASSERT_DEBUG( EFalse, Panic( EPEPanicIllegalCommand) );
       
   809         }
       
   810     return errorCode;
       
   811     }
       
   812  
       
   813 // -----------------------------------------------------------------------------
       
   814 // CPEVideoCallHandling::SendErrorMessage
       
   815 // Reroutes error code to Call Handling interface.
       
   816 // -----------------------------------------------------------------------------
       
   817 //
       
   818 void CPEVideoCallHandling::SendErrorMessage(
       
   819     const TInt aCallId,
       
   820     const TInt aErrorCode )
       
   821     {
       
   822     TEFLOGSTRING3( KTAINT, 
       
   823         "CALL CPEVideoCallHandling::SendErrorMessage, error code: %d, error cause: %d, call id: %d", 
       
   824         aErrorCode, 
       
   825         aCallId );
       
   826     iOwner.SendErrorMessage( aCallId, aErrorCode );
       
   827     }
       
   828 
       
   829 
       
   830 // -----------------------------------------------------------------------------
       
   831 // CPEVideoCallHandling::HandleInternalMessage
       
   832 // Reroutes messages to the Phone Engine
       
   833 // -----------------------------------------------------------------------------
       
   834 //
       
   835 void CPEVideoCallHandling::HandleInternalMessage( TInt aMessage )
       
   836     {
       
   837     TEFLOGSTRING2( KTAINT, "CALL CPEVideoCallHandling::HandleInternalMessage, message: %d", aMessage );
       
   838     iOwner.HandleInternalMessage( aMessage );
       
   839     }
       
   840 
       
   841 // -----------------------------------------------------------------------------
       
   842 // CPEVideoCallHandling::ConnectedCalls
       
   843 // Indicates if there are any connected calls.
       
   844 // -----------------------------------------------------------------------------
       
   845 //
       
   846 TBool CPEVideoCallHandling::ConnectedCalls()
       
   847     {
       
   848     TEFLOGSTRING( KTAINT, "CALL CPEVideoCallHandling::ConnectedCalls" );
       
   849     TBool returnValue( EFalse );
       
   850     if( VideoCallByState( EPEStateConnected ) )
       
   851         {
       
   852         returnValue = ETrue;
       
   853         }
       
   854     return returnValue ;
       
   855     }
       
   856 
       
   857 // -----------------------------------------------------------------------------
       
   858 // CPEVideoCallHandling::RejectCall
       
   859 // Rejects the incoming call.
       
   860 // -----------------------------------------------------------------------------
       
   861 //
       
   862 TInt CPEVideoCallHandling::RejectCall()
       
   863     {
       
   864     TEFLOGSTRING( KTAINT, "CALL CPEVideoCallHandling::RejectCall" );
       
   865     TInt errorCode( KErrNotFound );
       
   866     
       
   867     CPESingleCall* videoCall = VideoCallByState( EPEStateRinging );
       
   868     if( videoCall )
       
   869         {
       
   870         videoCall->HangUp();
       
   871         errorCode = KErrNone;
       
   872         }
       
   873     return errorCode;
       
   874     }
       
   875 
       
   876 // -----------------------------------------------------------------------------
       
   877 // CPEVideoCallHandling::ReleaseAll
       
   878 // Releases all ongoing calls.
       
   879 // -----------------------------------------------------------------------------
       
   880 //
       
   881 TInt CPEVideoCallHandling::ReleaseAll()
       
   882     {
       
   883     CPESingleCall* callData;
       
   884     TInt errorCode( KErrNotFound );
       
   885     TPEState callState;
       
   886     
       
   887     TEFLOGSTRING( KTAINT, "CALL CPEVideoCallHandling::ReleaseAll " );
       
   888     
       
   889     for ( TInt callId = KPEDataCallIdBase; 
       
   890           callId < ( KPEDataCallIdBase + KPEMaximumNumberOfDataCalls ); 
       
   891           callId++ )
       
   892         {
       
   893         callData = iCallArrayOwner.GetCallObject( callId );
       
   894         if ( callData )
       
   895             {
       
   896             callState = callData->GetCallState();
       
   897             if ( callState != EPEStateIdle && callState != EPEStateRinging )
       
   898                 {
       
   899                 TEFLOGSTRING2( KTAINT, 
       
   900                     "CALL CPEVideoCallHandling::ReleaseAll, call id: %d", 
       
   901                     callId );
       
   902                 HangUp( callId );
       
   903                 errorCode = KErrNone;
       
   904                 }
       
   905             }
       
   906         }
       
   907         
       
   908     TEFLOGSTRING2( KTAINT, 
       
   909         "CALL CPEVideoCallHandling::ReleaseAll, error code: %d", 
       
   910         errorCode );
       
   911             
       
   912     return errorCode;
       
   913     }
       
   914 
       
   915 // -----------------------------------------------------------------------------
       
   916 // CPEVideoCallHandling::TerminateAllConnections
       
   917 // Terminates all ringing data calls, connected data calls and packet data
       
   918 // connections.
       
   919 // -----------------------------------------------------------------------------
       
   920 //
       
   921 TInt CPEVideoCallHandling::TerminateAllConnections()
       
   922     {
       
   923     TEFLOGSTRING( KTAMESINT, 
       
   924         "CALL CPEVideoCallHandling::TerminateAllConnections");    
       
   925     // Terminate GPRS connection.
       
   926     // If GPRS connections are being terminated, 
       
   927     // then we do not start again.
       
   928     TBool canBeDeleted = ETrue;
       
   929     if ( iGprsInterface )
       
   930         {
       
   931         canBeDeleted = !iGprsInterface->IsTerminating();
       
   932         }
       
   933 
       
   934     TInt error( KErrNone );
       
   935     if ( canBeDeleted )
       
   936         {
       
   937         delete iGprsInterface;
       
   938         iGprsInterface = NULL;
       
   939         TRAP( error,
       
   940             iGprsInterface = new (ELeave) CPEGprsTermination;
       
   941             iGprsInterface->StartL() );
       
   942         }
       
   943     // Hangup Data calls
       
   944     ReleaseAll();
       
   945     
       
   946     return error;
       
   947     }
       
   948 
       
   949 // -----------------------------------------------------------------------------
       
   950 // CPEVideoCallHandling::GetCallDuration
       
   951 // Returns voice and conference (master call) call duration.
       
   952 // Method checks that call id is valid number and gets
       
   953 // call duration from conference or data call object or from
       
   954 // calls base class for voice call duration.
       
   955 // -----------------------------------------------------------------------------
       
   956 //
       
   957  TInt CPEVideoCallHandling::GetCallDuration( 
       
   958          TTimeIntervalSeconds& aDuration, 
       
   959          TInt aCallId )
       
   960     {
       
   961     TEFLOGSTRING2( KTAINT, "CALL CPEVideoCallHandling::GetCallDuration %d", aCallId ); 
       
   962     TInt errorCode( KErrNotFound );
       
   963     CPESingleCall* callData( NULL );
       
   964     callData = iCallArrayOwner.GetCallObject( aCallId );
       
   965     
       
   966     if ( callData && CallIdCheck::IsVideo( aCallId ) )
       
   967         {
       
   968         callData->GetCallDuration( aDuration );
       
   969         errorCode = KErrNone;
       
   970         }
       
   971     else
       
   972         {
       
   973         __ASSERT_DEBUG( EFalse, Panic( EPEPanicIllegalCommand) );
       
   974         }
       
   975 
       
   976     return errorCode;
       
   977     }
       
   978  
       
   979  // -----------------------------------------------------------------------------
       
   980  // CPEVideoCallHandling::ReleaseCallObject
       
   981  // -----------------------------------------------------------------------------
       
   982  //
       
   983  TInt CPEVideoCallHandling::ReleaseCallObject( const TInt aCallId  )
       
   984      {
       
   985      TInt error(KErrNone);
       
   986      TEFLOGSTRING2( KTAINT, 
       
   987              "CALL CPEVideoCallHandling::ReleaseCallObject ReleaseCallObject %d", aCallId );
       
   988      error = iCallArrayOwner.DeleteCallObject( aCallId );
       
   989      // Reset datastore to prevent invalid usage in next call
       
   990      TEFLOGSTRING( KTAINT, "CALL CPEVideoCallHandling::ReleaseCallObject, Reset CallInfo" );
       
   991      iModel.DataStore()->ResetCallInfo( aCallId );
       
   992      return error;
       
   993      }
       
   994  
       
   995 //  End of File