phoneengine/callhandling/src/cpecallhandling.cpp
changeset 36 2eacb6118286
parent 30 ebdbd102c78a
child 37 ba76fc04e6c2
equal deleted inserted replaced
30:ebdbd102c78a 36:2eacb6118286
     1 /*
       
     2 * Copyright (c) 2002-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:  This file contains the implementation of CPECallHandling class 
       
    15 *                member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "cpecallhandling.h"
       
    22 #include    "cpevideocallhandling.h"
       
    23 #include    "cpesinglecall.h"
       
    24 #include    "cpedtmfhandling.h"
       
    25 #include    "cpesupplementaryservicesmonitor.h"
       
    26 #include    "mpephonemodelinternal.h"
       
    27 #include    "cpeconferencecall.h"
       
    28 #include    "cpecallarrayowner.h"
       
    29 #include    "mpecallhandling.h"
       
    30 #include    "cpecceobserver.h"
       
    31 #include    "cpesystemcallstate.h"
       
    32 
       
    33 #include    <gsmerror.h>
       
    34 #include    <mpedatastore.h>
       
    35 #include    <pepanic.pan>
       
    36 #include    <talogger.h>
       
    37 #include    <PSVariables.h>
       
    38 #include    <ctsydomainpskeys.h>
       
    39 #include    <mccecall.h>
       
    40 #include    <psetsaobserver.h>
       
    41 #include    <cccecallparameters.h>
       
    42 
       
    43 // EXTERNAL DATA STRUCTURES
       
    44 // None
       
    45 
       
    46 // EXTERNAL FUNCTION PROTOTYPES  
       
    47 // None
       
    48 
       
    49 // CONSTANTS
       
    50 // None
       
    51 
       
    52 // MACROS
       
    53 // None
       
    54 
       
    55 // LOCAL CONSTANTS AND MACROS
       
    56 
       
    57 // MODULE DATA STRUCTURES
       
    58 // None
       
    59 
       
    60 // LOCAL FUNCTION PROTOTYPES
       
    61 // None
       
    62 
       
    63 // FORWARD DECLARATIONS
       
    64 // None
       
    65 
       
    66 // ============================= LOCAL FUNCTIONS ===============================
       
    67 // None
       
    68 
       
    69 // ============================ MEMBER FUNCTIONS ===============================
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CPECallHandling::CPECallHandling
       
    73 // C++ default constructor can NOT contain any code, that
       
    74 // might leave.
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CPECallHandling::CPECallHandling(
       
    78     MPEPhoneModelInternal& aModel,
       
    79     CCCE& aConvergedCallEngine,
       
    80     MCCEDtmfInterface& aDtmfInterface
       
    81     ) : iModel( aModel ),
       
    82         iConvergedCallEngine( aConvergedCallEngine ),
       
    83         iDtmfInterface( aDtmfInterface ),
       
    84         iReplaceActive( EFalse ),
       
    85         iDialRequest( EFalse )
       
    86     {
       
    87     TEFLOGSTRING( KTAOBJECT, "CALL CPECallHandling::CPECallHandling()");
       
    88     }
       
    89 
       
    90 // Destructor
       
    91 EXPORT_C CPECallHandling::~CPECallHandling()
       
    92     {  
       
    93     TEFLOGSTRING( KTAOBJECT, "CALL CPECallHandling::~CPECallHandling() start");
       
    94     
       
    95     delete iSystemCallState;
       
    96     delete iDtmfHandling;
       
    97     
       
    98     // No need to uninitialize feature manager - this is done in MPEPhoneModelInternal .cpp
       
    99         
       
   100     delete iSupplementaryServicesMonitor;
       
   101     delete iCCEObserver;
       
   102 
       
   103     delete iVideoCallHandling;
       
   104     delete iConferenceCall;
       
   105     delete iCallArrayOwner;
       
   106     delete iPsetSAObserver;
       
   107     delete iCallOpenParams;
       
   108     
       
   109     TEFLOGSTRING( KTAOBJECT, "CALL CPECallHandling::~CPECallHandling() complete");    
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CPECallHandling::NewL
       
   114 // Two-phased constructor.
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 EXPORT_C CPECallHandling* CPECallHandling::NewL(
       
   118         MPEPhoneModelInternal& aModel,                    
       
   119         CCCE& aConvergedCallEngine,
       
   120         MCCEDtmfInterface& aDtmfInterface )
       
   121     {
       
   122     TEFLOGSTRING( KTAOBJECT, "CALL CPECallHandling::NewL start." );
       
   123     CPECallHandling* self = new (ELeave) CPECallHandling( aModel,
       
   124         aConvergedCallEngine, aDtmfInterface );
       
   125     CleanupStack::PushL( self );
       
   126     self->ConstructL();
       
   127     CleanupStack::Pop( self );
       
   128     TEFLOGSTRING( KTAOBJECT, "CALL CPECallHandling::NewL complete." );
       
   129     return self;
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CPECallHandling::ConstructL
       
   134 // Symbian 2nd phase constructor can leave.
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CPECallHandling::ConstructL()
       
   138     {
       
   139     TEFLOGSTRING( KTAOBJECT, "CALL CPECallHandling::BaseConstructL() start"); 
       
   140 
       
   141     // Creates a supplementary services monitor
       
   142     iSupplementaryServicesMonitor = new (ELeave) CPESupplementaryServicesMonitor( 
       
   143         *this, *iModel.DataStore() );
       
   144     
       
   145     iCCEObserver = CPECCEObserver::NewL( *this, iModel );
       
   146     
       
   147     iConvergedCallEngine.SetObserver( *iCCEObserver, *iSupplementaryServicesMonitor );
       
   148 
       
   149     // Creates CPEDtmfSender object
       
   150     iDtmfHandling = CPEDtmfHandling::NewL( *this, iDtmfInterface );
       
   151 
       
   152     // Creates a call array owner object
       
   153     iCallArrayOwner = CPECallArrayOwner::NewL( 
       
   154             iConvergedCallEngine, 
       
   155             *this );
       
   156     
       
   157     iVideoCallHandling = CPEVideoCallHandling::NewL( 
       
   158             *this, 
       
   159             iModel, 
       
   160             iConvergedCallEngine,
       
   161             *iCallArrayOwner );
       
   162                                                           
       
   163     iCallOpenParams = CCCECallParameters::NewL();
       
   164     
       
   165     iSystemCallState = CPESystemCallState::NewL( *iCallArrayOwner, *iModel.DataStore() );
       
   166     
       
   167     TEFLOGSTRING( KTAOBJECT, "CALL CPECallHandling::BaseConstructL() complete");
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CPECallHandling::SendErrorMessage
       
   172 // Reroutes error messages to the Phone Engine, usable by other than call objects
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 void CPECallHandling::SendErrorMessage(
       
   176         const TInt aErrorCode )
       
   177     {
       
   178     TEFLOGSTRING2( KTAINT, 
       
   179         "CALL CPECallHandling::SendErrorMessage, error code: %d", 
       
   180         aErrorCode );
       
   181 
       
   182     iModel.DataStore()->SetErrorCode( aErrorCode );
       
   183     iModel.SendMessage( MEngineMonitor::EPEMessageCallHandlingError );
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CPECallHandling::SendErrorMessage
       
   188 // Reroutes error messages to the Phone Engine, usable by call objects
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 void CPECallHandling::SendErrorMessage( 
       
   192         const TInt aCallId,
       
   193         const TInt aErrorCode )
       
   194     {
       
   195     TEFLOGSTRING3( KTAINT, 
       
   196         "CALL CPECallHandling::SendErrorMessage, error code: %d, call id: %d", 
       
   197         aErrorCode,
       
   198         aCallId );
       
   199     
       
   200     // Dial request failed - resume held call
       
   201     if( aErrorCode == ECCPErrorInvalidFDN )
       
   202         {
       
   203         HandleAutoResume();
       
   204         }
       
   205 
       
   206     if ( aCallId == KPECallIdNotUsed )
       
   207         {
       
   208         SendErrorMessage( aErrorCode );
       
   209         }
       
   210     else
       
   211         {
       
   212         iModel.DataStore()->SetErrorCode( aErrorCode );
       
   213         iModel.SendMessage( MEngineMonitor::EPEMessageCallHandlingError, aCallId );
       
   214         
       
   215         //Handle call objet deleting if dialing fail.
       
   216         if( ECCPErrorNone != aErrorCode )
       
   217             {
       
   218             CPESingleCall* callData = iCallArrayOwner->GetCallObject( aCallId );
       
   219             if( callData )
       
   220                 {
       
   221                 TEFLOGSTRING2( KTAINT, 
       
   222                     "CALL CPECallHandling::SendErrorMessage, call state %d", callData->GetCallState() );
       
   223                 if( callData->GetCallState() == EPEStateIdle )
       
   224                     {
       
   225                     ReleaseCallObject( aCallId  );
       
   226                     iDialRequest = EFalse;
       
   227                     }
       
   228                 }
       
   229             }
       
   230 
       
   231         if( ( KPEConferenceCallID == aCallId ) && ( ECCPConferenceErrorAddCall == aErrorCode ) &&
       
   232               iConferenceCall && ( iConferenceCall->EnumerateCalls() == 0 ) )
       
   233            { 
       
   234            delete iConferenceCall; 
       
   235            iConferenceCall = NULL;
       
   236            iModel.DataStore()->ResetCallInfo( aCallId );
       
   237            } 
       
   238         }
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CPECallHandling::SendMessage
       
   243 // Reroutes messages to the Phone Engine, usable by other than call objects
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 void CPECallHandling::SendMessage( 
       
   247     MEngineMonitor::TPEMessagesFromPhoneEngine aMessage )
       
   248     {
       
   249     TEFLOGSTRING2( KTAINT,
       
   250         "CALL CPECallHandling::SendMessage, message id: %d", aMessage );
       
   251    
       
   252     iModel.SendMessage( aMessage );
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CPECallHandling::SendMessage
       
   257 // Reroutes messages to the Phone Engine, usable by call objects
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 void CPECallHandling::SendMessage( 
       
   261     MEngineMonitor::TPEMessagesFromPhoneEngine aMessage,
       
   262     TInt aCallId )
       
   263     {
       
   264     TEFLOGSTRING3( KTAINT, 
       
   265         "CALL CPECallHandling::SendMessage, message id: %d, call id: %d", 
       
   266         aMessage, 
       
   267         aCallId );
       
   268     
       
   269     TInt errorCode( KErrNone );
       
   270     
       
   271     switch ( aMessage )
       
   272         {
       
   273         case MEngineMonitor::EPEMessageDialing:
       
   274             {
       
   275             iDialRequest = EFalse;
       
   276             CPESingleCall* callData = iCallArrayOwner->GetCallObject( aCallId );
       
   277             if( callData )
       
   278                 {
       
   279                 MCCECall& call = callData->Call();
       
   280                 iModel.DataStore()->SetCallIndex(call.CallIndex(), aCallId );                
       
   281                 SetCallOrigin( aCallId, call );                        
       
   282                 }  
       
   283             break;
       
   284             }
       
   285         case MEngineMonitor::EPEMessageChangedCallDuration:
       
   286             {
       
   287             TTimeIntervalSeconds duration;
       
   288  
       
   289             errorCode = GetCallDuration( duration, aCallId );
       
   290             if ( errorCode == KErrNone )
       
   291                 {
       
   292                 iModel.DataStore()->SetCallDuration( duration, aCallId );
       
   293                 }
       
   294             break;
       
   295             }
       
   296         case MEngineMonitor::EPEMessageIdle:
       
   297             {
       
   298             HandleAutoResume();
       
   299             break;
       
   300             }
       
   301         case MEngineMonitor::EPEMessageAddedConferenceMember:
       
   302             {
       
   303             TName memberName;
       
   304             TInt count;
       
   305 
       
   306             errorCode = GetNumberOfParticipants( count );
       
   307             TEFLOGSTRING2( 
       
   308                 KTAMESIN, 
       
   309                 "CALL CPECallHandling::SendMessage EPEMessageAddedConferenceMember errorCode %d", 
       
   310                 errorCode );
       
   311             if ( errorCode == KErrNone )
       
   312                 {
       
   313                 iModel.DataStore()->SetNumberOfConferenceMembers( count, KPEConferenceCallID );
       
   314 
       
   315                 iConferenceCall->GetConferenceMemberName( memberName );
       
   316 
       
   317                 if ( errorCode == KErrNone )
       
   318                     {
       
   319                     iModel.DataStore()->SetConferenceMemberInfo( 
       
   320                         memberName, 
       
   321                         KPEConferenceCallID, 
       
   322                         aCallId );
       
   323                     iModel.DataStore()->SetCallConference( aCallId, 
       
   324                             KPEConferenceCallID );
       
   325                     }
       
   326                 }
       
   327             break;
       
   328             }
       
   329         case MEngineMonitor::EPEMessageDroppedConferenceMember:                
       
   330             {
       
   331             TName memberName;
       
   332             TInt memberCallId;
       
   333             TInt count;
       
   334 
       
   335             errorCode = GetNumberOfParticipants( count );
       
   336             TEFLOGSTRING2( 
       
   337                 KTAMESIN, 
       
   338                 "CALL CPECallHandling::SendMessage EPEMessageAddedConferenceMember EPEMessageDroppedConferenceMember %d", 
       
   339                 errorCode );
       
   340             if ( errorCode == KErrNone )
       
   341                 {
       
   342                 iModel.DataStore()->SetNumberOfConferenceMembers( count, KPEConferenceCallID );
       
   343 
       
   344                 errorCode = GetConferenceMemberNameAndId( memberName, 
       
   345                                                           memberCallId );
       
   346 
       
   347                 // Member has been taken to OneToOne conversation and is still alive
       
   348                 if ( errorCode == KErrNone )
       
   349                     {
       
   350                     iModel.DataStore()->SetConferenceMemberInfo( 
       
   351                         memberName, 
       
   352                         KPECallIdNotUsed, 
       
   353                         aCallId );
       
   354                     iModel.DataStore()->SetCallConference( 
       
   355                         KPENormalVoiceCall,
       
   356                         memberCallId );
       
   357                     }
       
   358                 else
       
   359                     {
       
   360                     // Member has been dropped and its state is idle, so no 
       
   361                     // information can be found...
       
   362                     // So actually not an error situation memberName is empty
       
   363                     // (set in GetConferenceMemberNameAndId method) 
       
   364                     iModel.DataStore()->SetConferenceMemberInfo( 
       
   365                         memberName, 
       
   366                         KPECallIdNotUsed, 
       
   367                         aCallId );
       
   368                     errorCode = KErrNone;
       
   369                     }
       
   370                 }                
       
   371             break;    
       
   372             }
       
   373         case MEngineMonitor::EPEMessageCallControlCapsChanged: 
       
   374             {
       
   375             TPECallControlCaps callControlCaps;
       
   376             errorCode = GetCallControlCaps( callControlCaps, aCallId );
       
   377             if ( errorCode == KErrNone )
       
   378                 {
       
   379                 iModel.DataStore()->SetCallControlCaps( 
       
   380                     callControlCaps, 
       
   381                     aCallId );
       
   382                 }
       
   383             break;
       
   384             }
       
   385         case MEngineMonitor::EPEMessageConferenceCapsChange:                             
       
   386             {
       
   387             TUint32 caps;
       
   388             errorCode = GetConferenceCallCaps( caps );
       
   389             if ( errorCode == KErrNone )
       
   390                 {
       
   391                 iModel.DataStore()->SetConferenceCallCaps( caps, aCallId );
       
   392                 }
       
   393             break;    
       
   394             }
       
   395         case MEngineMonitor::EPEMessageDisconnecting:
       
   396             {
       
   397             CPESingleCall* callData = iCallArrayOwner->GetCallObject( aCallId );
       
   398             if ( callData )
       
   399                 {
       
   400                 TCCPTone inbandTone = callData->Tone();
       
   401                 iModel.DataStore()->SetInbandTone( inbandTone );
       
   402                 }
       
   403             break;
       
   404             }
       
   405         case MEngineMonitor::EPEMessageConferenceErrorAddCall:
       
   406         case MEngineMonitor::EPEMessageConferenceErrorRemoveCall:
       
   407         case MEngineMonitor::EPEMessageConferenceErrorSwap:
       
   408         case MEngineMonitor::EPEMessageConferenceErrorHold:
       
   409         case MEngineMonitor::EPEMessageConferenceErrorResume:
       
   410         case MEngineMonitor::EPEMessageConferenceErrorGoOneToOne:
       
   411         case MEngineMonitor::EPEMessageConferenceErrorCurrentCallsToConference:
       
   412             {
       
   413             errorCode = KErrGeneral;
       
   414             if( iConferenceCall && ( iConferenceCall->EnumerateCalls() == 0 ) )
       
   415                 {
       
   416                 delete iConferenceCall;
       
   417                 iConferenceCall = NULL;
       
   418                 }
       
   419             break;
       
   420             }
       
   421         case MEngineMonitor::EPEMessageCallSecureStatusChanged:
       
   422             {
       
   423             iModel.DataStore()->SetCallSecureStatus( 
       
   424                 IsSecureCall( aCallId ), 
       
   425                 aCallId );
       
   426             // Secure is specified  
       
   427             iModel.DataStore()->SetSecureSpecified( ETrue );
       
   428             break;
       
   429             }          
       
   430         case MEngineMonitor::EPEMessageSecureNotSpecified:
       
   431             {
       
   432             iModel.DataStore()->SetSecureSpecified( EFalse );
       
   433             break;
       
   434             }                     
       
   435             
       
   436         case MEngineMonitor::EPEMessageRemotePartyInfoChanged:
       
   437             {
       
   438             TEFLOGSTRING( KTAMESINT, "CALL CPECallHandling::SendMessage -> EPEMessageRemotePartyInfoChanged");
       
   439             // HO cases call type can changes
       
   440             CPESingleCall* connectedCall;
       
   441             connectedCall = iCallArrayOwner->CallPointerByState( EPEStateConnected );
       
   442             
       
   443             if( connectedCall )
       
   444                 {
       
   445                 CCPCall::TCallType callType = connectedCall->Call().Parameters().CallType();
       
   446                 
       
   447                 if ( callType == CCPCall::ECallTypePS ) 
       
   448                     {
       
   449                     TEFLOGSTRING( KTAMESINT, 
       
   450                         "CALL CPECallHandling::SendMessage -> EPEMessageRemotePartyInfoChanged->update call type to PS");
       
   451                     iModel.DataStore()->SetCallType( EPECallTypeVoIP, aCallId ); 
       
   452                     iModel.DataStore()->SetServiceIdCommand( connectedCall->Call().Parameters().ServiceId() );
       
   453                     iCallOpenParams->SetCallType( CCPCall::ECallTypePS); 
       
   454                     }
       
   455                 else if ( callType == CCPCall::ECallTypeCSVoice )
       
   456                     {
       
   457                      TEFLOGSTRING( KTAMESINT, 
       
   458                         "CALL CPECallHandling::SendMessage -> EPEMessageRemotePartyInfoChanged->update call type to CS");
       
   459                     iCallOpenParams->SetCallType( CCPCall::ECallTypeCSVoice );
       
   460                     iModel.DataStore()->SetServiceIdCommand( 1 );
       
   461                     iModel.DataStore()->SetCallType( EPECallTypeCSVoice, aCallId );    
       
   462                     }
       
   463                 }
       
   464             }
       
   465        // Flow throught
       
   466             
       
   467         case MEngineMonitor::EPEMessageIncoming:
       
   468             {
       
   469             CPESingleCall* callData = iCallArrayOwner->GetCallObject( aCallId );
       
   470             if( callData )
       
   471                 {
       
   472                 MCCECall& call = callData->Call();
       
   473                 iModel.DataStore()->SetRemotePartyName( call.RemotePartyName(), aCallId );
       
   474                 iModel.DataStore()->SetRemotePhoneNumber( call.RemoteParty().Left( KPEPhoneNumberMaxLength ), aCallId );
       
   475                 iModel.DataStore()->SetCallIndex(call.CallIndex(), aCallId );
       
   476                 }
       
   477             break;
       
   478             }
       
   479         case MEngineMonitor::EPEMessageForwardUnconditionalModeActive:
       
   480             {
       
   481             UpdateSaSetting();
       
   482             break;
       
   483             }
       
   484         case MEngineMonitor::EPEMessageUnattendedTransferRequest:
       
   485             {
       
   486             CPESingleCall* call = iCallArrayOwner->GetCallObject( aCallId );
       
   487             __ASSERT_DEBUG( NULL != call, Panic( EPEPanicIllegalCommand ) );
       
   488             if ( call )
       
   489                 {
       
   490                 iModel.DataStore()->SetUnattendedTransferTarget( 
       
   491                     call->UnattendedTransferTarget(), aCallId );
       
   492                 }
       
   493             
       
   494             break;
       
   495             }
       
   496         case MEngineMonitor::EPEMessageALSLineChanged:
       
   497             {
       
   498             SetActiveLine();
       
   499             break;
       
   500             }
       
   501         case MEngineMonitor::EPEMessageMovedPermanently:
       
   502         case MEngineMonitor::EPEMessageMultipleChoices:
       
   503             {
       
   504             /* Incoming moved permanently request from server,
       
   505              * store target addresses for later use
       
   506              */
       
   507             CPESingleCall* call = iCallArrayOwner->GetCallObject( aCallId );
       
   508             __ASSERT_DEBUG( NULL != call, Panic( EPEPanicIllegalCommand ) );
       
   509             if ( call )
       
   510                 {
       
   511                 iModel.DataStore()->SetForwardAddressChoices( 
       
   512                     call->ForwardAddressChoices(), aCallId );
       
   513                 }
       
   514             
       
   515             break;
       
   516             }
       
   517         default:
       
   518             // Other messages cause no action.
       
   519             break;
       
   520         } 
       
   521 
       
   522     if( aCallId != KPECallIdNotUsed )
       
   523         {
       
   524         // Preferred to be before sendmessage
       
   525         // f.e active idle update before display to screen
       
   526         iSystemCallState->NotifySystemCallStateChanged( aMessage, aCallId );
       
   527         }
       
   528     
       
   529     if ( errorCode )
       
   530         {
       
   531         SendErrorMessage( aCallId, errorCode );
       
   532         }
       
   533     else
       
   534         {
       
   535         iModel.SendMessage( aMessage, aCallId );
       
   536         }
       
   537 
       
   538     // Call obect deleting in idle state is handled here because phoneengine 
       
   539     // uses call object during idle state handling
       
   540     if( aMessage == MEngineMonitor::EPEMessageIdle )
       
   541         {
       
   542         TEFLOGSTRING2( KTAINT, 
       
   543            "CALL CPECallHandling::SendMessage DeleteCallObject %d", aCallId );
       
   544         iCallArrayOwner->DeleteCallObject( aCallId );
       
   545         }
       
   546     else if( aMessage == MEngineMonitor::EPEMessageConferenceIdle )
       
   547         {
       
   548         delete iConferenceCall;
       
   549         iConferenceCall = NULL;
       
   550         if ( iReplaceActive )
       
   551             {
       
   552             AnswerCall();
       
   553             iReplaceActive = EFalse;
       
   554             }
       
   555         }
       
   556     }
       
   557 
       
   558 // -----------------------------------------------------------------------------
       
   559 // CPECallHandling::AnswerCall
       
   560 // Answers an incoming call
       
   561 // -----------------------------------------------------------------------------
       
   562 //
       
   563 EXPORT_C TInt CPECallHandling::AnswerCall()
       
   564     {
       
   565     TEFLOGSTRING( KTAMESINT, "CALL CPECallHandling::AnswerCall");
       
   566     TInt callIndex;
       
   567     CPESingleCall* callData;
       
   568     CPESingleCall* connectedCall;
       
   569     TInt errorCode( ECCPErrorNotFound );
       
   570 
       
   571     callData = VoiceCallDataByState( EPEStateRinging, callIndex );
       
   572     connectedCall = iCallArrayOwner->CallPointerByState( EPEStateConnected );
       
   573     if( connectedCall && !iReplaceActive )
       
   574         {
       
   575         CCPCall::TCallType callType = connectedCall->Call().Parameters().CallType();
       
   576         TEFLOGSTRING2( KTAINT, 
       
   577             "CALL CPECallHandling::AnswerCall EPEStateConnected type %d", callType );
       
   578         if( callType == CCPCall::ECallTypeVideo )
       
   579             {
       
   580             TEFLOGSTRING( KTAINT, 
       
   581                 "CALL CPECallHandling::AnswerCall ECCPErrorNotAllowed" );
       
   582             return ECCPErrorNotAllowed;
       
   583             }
       
   584         }
       
   585         
       
   586     if ( callData )
       
   587         {
       
   588         TEFLOGSTRING2( KTAINT, 
       
   589             "CALL CPECallHandling::AnswerCall > CPESingleCall::Answer %d", 
       
   590             callData->GetCallId() );
       
   591         errorCode = callData->Answer();        
       
   592         }
       
   593     else
       
   594         {
       
   595         TEFLOGSTRING( KTAINT, 
       
   596             "CALL CPECallHandling::AnswerCall > iVideoCallHandling->AnswerCall");
       
   597         errorCode = iVideoCallHandling->AnswerCall();
       
   598         }
       
   599         
       
   600     return errorCode;
       
   601     }
       
   602 
       
   603 // -----------------------------------------------------------------------------
       
   604 // CPECallHandling::DialCall
       
   605 // creates dial request to the CPESingleCall object
       
   606 // -----------------------------------------------------------------------------
       
   607 //
       
   608 EXPORT_C TInt CPECallHandling::DialCall( 
       
   609     const TPEPhoneNumber& aNumber,
       
   610     TInt& aCallId )
       
   611     {
       
   612     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::DialCall" );
       
   613     CPESingleCall* callData( NULL );
       
   614     TInt errorCode( KErrNone );
       
   615 
       
   616     // If there is allready video call, one dial in connecting, dialing or disconnecting state,
       
   617     // we just ignore new dial request and send KErrInUse back to UI
       
   618     if( iDialRequest )
       
   619         {
       
   620         // Dial request already send, waiting for dialing state.
       
   621         errorCode = KErrGeneral;
       
   622         TEFLOGSTRING( KTAERROR, 
       
   623             "CALL CPECALLHANDLING::DIALCALL ! DIAL FAILED: DIAL REQUEST ALREADY ACTIVE" );
       
   624         }
       
   625     else if ( IsDialAllowed ( EFalse ) )
       
   626         {
       
   627         // Set user to user info call params.
       
   628                 // Set user to user info call params.
       
   629                 
       
   630         const CCCECallParameters& params = iModel.DataStore()->CallParameters();
       
   631         iCallOpenParams->SetBearer( params.Bearer() );
       
   632         iCallOpenParams->SetSubAddress( params.SubAddress() );
       
   633         iCallOpenParams->SetOrigin( params.Origin() );
       
   634         iCallOpenParams->SetUUSId( iModel.DataStore()->UserToUserInformation() );
       
   635         
       
   636         TRAP( errorCode, callData = OpenNewCallL( aNumber ) );
       
   637         if( errorCode == KErrNone )
       
   638             {
       
   639             if( iModel.DataStore()->CallOriginCommand() == EPECallOriginSAT )
       
   640                 {
       
   641                 // disable number matching for SAT calls
       
   642                 callData->DisableFDNCheck();
       
   643                 }
       
   644             
       
   645             TEFLOGSTRING( KTAINT, "CALL CPECallHandling::DialCall > Dial" );
       
   646             iDialRequest = ETrue;
       
   647             errorCode = callData->Dial( aNumber );
       
   648             
       
   649             if ( errorCode != KErrNone )
       
   650                 {
       
   651                 iDialRequest = EFalse;
       
   652                 // Dial failed: clean up
       
   653                 ReleaseCallObject( callData->GetCallId() );
       
   654                 TEFLOGSTRING2( KTAERROR, 
       
   655                     "CALL CPECALLHANDLING::DIALCALL ! DIAL FAILED: MAY NOT PROCEED! %d", errorCode );
       
   656                 }
       
   657             else
       
   658                 {
       
   659                 // Dial request passed on successfully: forward new call id
       
   660                 aCallId = callData->GetCallId();
       
   661                 }
       
   662             }
       
   663         }
       
   664     else
       
   665         {
       
   666         errorCode = KErrInUse;
       
   667         }
       
   668         
       
   669     return errorCode;
       
   670     }
       
   671 
       
   672 // -----------------------------------------------------------------------------
       
   673 // CPECallHandling::DialMultimedia
       
   674 // creates dial request to the CPESingleCall object
       
   675 // -----------------------------------------------------------------------------
       
   676 //
       
   677 EXPORT_C TInt CPECallHandling::DialMultimedia( 
       
   678         const TPEPhoneNumber& aNumber,
       
   679         TInt& aCallId
       
   680         )
       
   681     {
       
   682     TEFLOGSTRING( KTAMESINT, "CALL CPECallHandling::DialMultimedia");
       
   683     TInt errorCode( ECCPErrorNone );
       
   684     
       
   685     // If there is allready call, one dial in connecting, dialing or disconnecting state,
       
   686     // we just ignore new dial request and send KErrInUse back to UI    
       
   687     if ( IsDialAllowed ( ETrue ) )
       
   688         {
       
   689         errorCode = iVideoCallHandling->DialCall( aNumber, aCallId );
       
   690         }
       
   691     else
       
   692         {
       
   693         errorCode = ECCPErrorAlreadyInUse;
       
   694         }
       
   695     return errorCode;
       
   696     }
       
   697 // -----------------------------------------------------------------------------
       
   698 // CPECallHandling::IsDialAllowed
       
   699 //  
       
   700 // -----------------------------------------------------------------------------
       
   701 //
       
   702 TBool CPECallHandling::IsDialAllowed( TBool aMultimediaDial )
       
   703     {
       
   704     TEFLOGSTRING( KTAMESINT, "CALL CPECallHandling::IsDialAllowed");
       
   705     
       
   706     CPESingleCall* call = iCallArrayOwner->CallPointerByState( EPEStateConnected );
       
   707     CPESingleCall* heldCall = iCallArrayOwner->CallPointerByState( EPEStateHeld );
       
   708     
       
   709     TBool status = EFalse;
       
   710     
       
   711     if( ( call || heldCall ) && aMultimediaDial )
       
   712         {
       
   713         // A call was found when tried video call
       
   714         TEFLOGSTRING( KTAERROR, 
       
   715             "CALL CPECALLHANDLING::IsDialAllowed() CANNOT CREATE A VIDEO CALL IN CALL STATE!");
       
   716         }
       
   717     else if( call && iVideoCallHandling->IsMultimedia( call->GetCallId() ) )
       
   718         {
       
   719         // A video call was found when tried voice or video call
       
   720         TEFLOGSTRING( KTAERROR, 
       
   721             "CALL CPECALLHANDLING::IsDialAllowed() CANNOT CREATE A CALL IN VIDEO CALL STATE!");
       
   722         }
       
   723     else if( iCallArrayOwner->CallPointerByState( EPEStateDialing ) ) 
       
   724         {
       
   725         // A dialing call was found
       
   726             TEFLOGSTRING( KTAERROR, 
       
   727                 "CALL CPECALLHANDLING::IsDialAllowed() CANNOT CREATE A CALL IN DIALING STATE!");
       
   728          }
       
   729     else if( iCallArrayOwner->CallPointerByState( EPEStateConnecting ) ) 
       
   730         { 
       
   731         // A connecting call was found
       
   732          TEFLOGSTRING( KTAERROR, 
       
   733              "CALL CPECALLHANDLING::IsDialAllowed() CANNOT CREATE A CALL IN CONNECTING STATE!");
       
   734 
       
   735         }
       
   736     else if( iCallArrayOwner->CallPointerByState( EPEStateDisconnecting ) ) 
       
   737         {
       
   738         // A disconnecting call was found
       
   739         TEFLOGSTRING( KTAERROR, 
       
   740             "CALL CPECALLHANDLING::IsDialAllowed() CANNOT CREATE A CALL IN DISCONNECTING STATE!");
       
   741          }
       
   742     else if( ( iConferenceCall && iConferenceCall->GetCallState() == EPEStateConnectedConference && ( heldCall ) ) ||
       
   743             ( iConferenceCall && iConferenceCall->GetCallState() == EPEStateHeldConference && ( call ) ) )
       
   744         {
       
   745         // coference and single call found
       
   746         TEFLOGSTRING( KTAERROR, 
       
   747             "CALL CPECALLHANDLING::IsDialAllowed() CANNOT CREATE A CALL IN CONFERENCE AND SINGLE STATE!");
       
   748         }
       
   749     else
       
   750         {
       
   751         status = ETrue; // Dial allowed
       
   752         }
       
   753     return status; 
       
   754     }
       
   755 
       
   756 // -----------------------------------------------------------------------------
       
   757 // CPECallHandling::HangUp
       
   758 // Terminates an ongoing call
       
   759 // -----------------------------------------------------------------------------
       
   760 //
       
   761 EXPORT_C TInt  CPECallHandling::HangUp( 
       
   762         TInt aCallId, 
       
   763         TPEHangUpOptions aAutoResumeOption )
       
   764     {
       
   765     TEFLOGSTRING3( KTAMESINT, "CALL CPECallHandling::HangUp aCallId= %d aAutoResumeOption= %d ", aCallId, aAutoResumeOption );
       
   766     TInt errorCode( ECCPErrorNotFound );
       
   767     
       
   768     CPESingleCall* heldcall = iCallArrayOwner->CallPointerByState( EPEStateHeld );
       
   769 
       
   770     if( aAutoResumeOption == ETPEHangUpResumeHeldCall )
       
   771         {
       
   772         if( heldcall )
       
   773             {
       
   774             iModel.DataStore()->SetResumeHeldCall( ETrue, heldcall->GetCallId() );
       
   775             }
       
   776         else if( iConferenceCall && ( iConferenceCall->GetCallState() == EPEStateHeldConference ) )
       
   777             {
       
   778             iModel.DataStore()->SetResumeHeldCall( ETrue, KPEConferenceCallID );
       
   779             }
       
   780         }
       
   781     else if( aAutoResumeOption == ETPEHangUpNotResumeHeldCall )
       
   782         {
       
   783         if( heldcall )
       
   784             {
       
   785             iModel.DataStore()->SetResumeHeldCall( EFalse, heldcall->GetCallId() );
       
   786             }
       
   787         else if( iConferenceCall && ( iConferenceCall->GetCallState() == EPEStateHeldConference ) )
       
   788             {
       
   789             iModel.DataStore()->SetResumeHeldCall( EFalse, KPEConferenceCallID );
       
   790             }
       
   791         }
       
   792 
       
   793     if ( CallIdCheck::IsVoice( aCallId )) 
       
   794         {
       
   795         CPESingleCall* callData = iCallArrayOwner->GetCallObject( aCallId );
       
   796         if( callData )
       
   797             {
       
   798             // conference call that is not yet created, must be cancelled.
       
   799             if( iConferenceCall && iConferenceCall->GetCallState() == EPEStateCreatingConference )
       
   800                 {
       
   801                 TEFLOGSTRING( KTAERROR, 
       
   802                     "CPECallHandling::HangUp Delete conference call.");
       
   803                 delete iConferenceCall;
       
   804                 iConferenceCall = NULL;
       
   805                 }
       
   806             
       
   807             errorCode = callData->HangUp();
       
   808             }
       
   809         else
       
   810             {
       
   811             TEFLOGSTRING( KTAERROR, 
       
   812                 "CALL CPECALLHANDLING::HANGUP ! CALL OBJECT IN IDLE STATE OR ALREADY HANGING UP" );
       
   813             }
       
   814         }
       
   815 
       
   816     else if ( CallIdCheck::IsVideo( aCallId ) ) 
       
   817         {
       
   818         errorCode = iVideoCallHandling->HangUp( aCallId );
       
   819         }
       
   820 
       
   821     else if ( CallIdCheck::IsConference( aCallId ) )
       
   822         {
       
   823         if( iConferenceCall )
       
   824             {
       
   825             errorCode = iConferenceCall->HangUp();
       
   826             }
       
   827         }
       
   828     return errorCode;
       
   829     }
       
   830 
       
   831 // -----------------------------------------------------------------------------
       
   832 // CPECallHandling::TerminateAllConnections
       
   833 // Terminates all ringing voice and data calls
       
   834 // -----------------------------------------------------------------------------
       
   835 //
       
   836 EXPORT_C TInt CPECallHandling::TerminateAllConnections()
       
   837     {
       
   838     CPESingleCall* callData;
       
   839     TPEState callState;
       
   840 
       
   841     TEFLOGSTRING( KTAMESINT, "CALL CPECallHandling::TerminateAllConnections");
       
   842     
       
   843     RejectCall(); // Rejects ringing call if one exists.
       
   844 
       
   845     if ( iConferenceCall )
       
   846         {
       
   847         TEFLOGSTRING( KTAMESOUT, 
       
   848             "CALL CPECallHandling::TerminateAllConnections: Hanging Up conference call" );
       
   849         iConferenceCall->HangUp();
       
   850         }
       
   851             
       
   852     // Hangup normal Voice Calls
       
   853     for( TInt callId = 0; callId < KPEMaximumNumberOfVoiceCalls; callId++ )
       
   854         {
       
   855         callData = iCallArrayOwner->GetCallObject( callId );
       
   856         if( callData )
       
   857             {
       
   858             callState = callData->GetCallState();
       
   859             if ( callState != EPEStateIdle ) 
       
   860                 {
       
   861                 TEFLOGSTRING2( KTAREQOUT, 
       
   862                     "CALL CPECallHandling::TerminateAllConnections: Hanging Up call id %d...", 
       
   863                     callId );
       
   864                 callData->HangUp();
       
   865                 }
       
   866             }
       
   867         }
       
   868     //Terminate all ringing data calls, connected data calls and packet data connections
       
   869     return iVideoCallHandling->TerminateAllConnections();
       
   870     }
       
   871 
       
   872 // -----------------------------------------------------------------------------
       
   873 // CPECallHandling::UpdatePhoneIdentity
       
   874 // Method updates phone identity
       
   875 // -----------------------------------------------------------------------------
       
   876 //
       
   877 EXPORT_C TInt CPECallHandling::UpdatePhoneIdentity(
       
   878     MEngineMonitor::TPEMessagesFromPhoneEngine /*aMessage*/ )
       
   879     {
       
   880     TInt retValue( KErrNone ); 
       
   881     CSInfo csinfo;
       
   882     retValue = iConvergedCallEngine.GetCSInfo( csinfo );
       
   883     
       
   884     TPEPhoneIdentityParameters phoneIdentityParameters;
       
   885     
       
   886     phoneIdentityParameters.iSerialNumber = csinfo.iSerialNumber;
       
   887         
       
   888     iModel.DataStore()->SetPhoneIdentityParameters( phoneIdentityParameters );
       
   889 
       
   890     SendMessage( MEngineMonitor::EPEMessageShowIMEI );
       
   891     return retValue;
       
   892     }
       
   893 
       
   894 // -----------------------------------------------------------------------------
       
   895 // CPECallHandling::IsCallInState
       
   896 // returns ETrue if there is a call in given state; otherwise EFalse
       
   897 // -----------------------------------------------------------------------------
       
   898 //
       
   899 EXPORT_C TBool CPECallHandling::IsCallInState( TPEState aState ) const
       
   900     {
       
   901     TBool isCallInState( EFalse );
       
   902     iCallArrayOwner->CallPointerByState( aState ) ? isCallInState = ETrue : isCallInState = EFalse;
       
   903     
       
   904     return isCallInState;
       
   905     }
       
   906 
       
   907 // -----------------------------------------------------------------------------
       
   908 // CPECallHandling::GetCallIdByState
       
   909 // returns return callid is there is a call; otherwise KPECallIdNotUsed( -1 ).
       
   910 // -----------------------------------------------------------------------------
       
   911 //
       
   912 EXPORT_C TInt CPECallHandling::GetCallIdByState( TPEState aState ) const
       
   913     {
       
   914     TInt callId( KPECallIdNotUsed );
       
   915     CPESingleCall* call = iCallArrayOwner->CallPointerByState( aState );
       
   916     if( call )
       
   917         {
       
   918         callId = call->GetCallId();
       
   919         }
       
   920     TEFLOGSTRING2( KTAREQOUT, 
       
   921                    "CALL CPECallHandling::GetCallIdByState: callid %d", 
       
   922                    callId );
       
   923     return callId;
       
   924     }
       
   925     
       
   926 // -----------------------------------------------------------------------------
       
   927 // CPECallHandling::GetMissedCall
       
   928 // Returns the missed voice call indicator.
       
   929 // Method checks that call id is valid number
       
   930 // Method gets CPECallData object from the CArrayPtrFlat and
       
   931 // Method gets the missed voice call indicator from CPECallData object
       
   932 // -----------------------------------------------------------------------------
       
   933 //
       
   934 EXPORT_C TInt CPECallHandling::GetMissedCall( 
       
   935         TBool& aMissedCall,
       
   936         TInt aCallId )
       
   937     {
       
   938     TInt errorCode( ECCPErrorNotFound );
       
   939 
       
   940     CPESingleCall* voiceCall = iCallArrayOwner->GetCallObject( aCallId );
       
   941     if( voiceCall )
       
   942         {
       
   943         errorCode = voiceCall->GetMissedCall( aMissedCall );
       
   944         }
       
   945     else
       
   946         {
       
   947         __ASSERT_DEBUG( EFalse, Panic( EPEPanicIllegalCommand) );
       
   948         }
       
   949 
       
   950     return errorCode;
       
   951     }
       
   952     
       
   953 // -----------------------------------------------------------------------------
       
   954 // CPECallHandling::GetCallInfo
       
   955 // Returns call info
       
   956 // -----------------------------------------------------------------------------
       
   957 //
       
   958 EXPORT_C TInt CPECallHandling::GetCallInfo( 
       
   959     RMobileCall::TMobileCallInfoV3& aCallInfo,
       
   960     TInt aCallId )
       
   961     {
       
   962     CPESingleCall* callData;
       
   963     TInt errorCode( ECCPErrorNotFound );
       
   964 
       
   965     if ( CallIdCheck::IsVoice( aCallId ))
       
   966         {
       
   967         callData = iCallArrayOwner->GetCallObject( aCallId );
       
   968         if( callData )
       
   969             {
       
   970             errorCode = callData->GetCallInfo( aCallInfo );
       
   971             }
       
   972         else
       
   973             {
       
   974             __ASSERT_DEBUG( EFalse, Panic( EPEPanicIllegalCommand) );
       
   975             }
       
   976         }
       
   977         
       
   978     else if ( CallIdCheck::IsVideo( aCallId ) )
       
   979         {
       
   980         errorCode = iVideoCallHandling->GetCallInfo( aCallInfo, aCallId );
       
   981         }
       
   982         
       
   983     return errorCode;
       
   984     }
       
   985 
       
   986 // -----------------------------------------------------------------------------
       
   987 // CPECallHandling::GetCallState
       
   988 // Returns call state
       
   989 // -----------------------------------------------------------------------------
       
   990 //
       
   991 EXPORT_C TPEState CPECallHandling::GetCallState( 
       
   992         TInt aCallId )
       
   993     {
       
   994     TPEState callState( EPEStateUnknown );
       
   995     
       
   996     if ( CallIdCheck::IsConference( aCallId ) )
       
   997         {
       
   998         if( iConferenceCall )
       
   999             {
       
  1000             callState = iConferenceCall->GetCallState();
       
  1001             }
       
  1002         else
       
  1003             {
       
  1004             callState = EPEStateConferenceIdle;
       
  1005             }
       
  1006         }
       
  1007     else
       
  1008         {
       
  1009         CPESingleCall* callData = iCallArrayOwner->GetCallObject( aCallId );
       
  1010         if( callData )
       
  1011             {
       
  1012             callState = callData->GetCallState();
       
  1013             }
       
  1014         else
       
  1015             {
       
  1016             callState = EPEStateIdle;
       
  1017             }
       
  1018         }
       
  1019 
       
  1020     TEFLOGSTRING2( KTAINT, "CALL CPECallHandling::GetCallState, callState: %d", callState );
       
  1021     return callState;
       
  1022     }
       
  1023 
       
  1024 // -----------------------------------------------------------------------------
       
  1025 // CPECallHandling::GetNumberOfCalls
       
  1026 // Returns number of non-idle calls
       
  1027 // -----------------------------------------------------------------------------
       
  1028 //
       
  1029 EXPORT_C TInt CPECallHandling::GetNumberOfCalls()
       
  1030     {
       
  1031     // Count ongoing calls
       
  1032     return iCallArrayOwner->ActiveCallCount();
       
  1033     }
       
  1034 
       
  1035 // -----------------------------------------------------------------------------
       
  1036 // CPECallHandling::GetCallDuration
       
  1037 // Returns voice call duration.
       
  1038 // -----------------------------------------------------------------------------
       
  1039 //
       
  1040 EXPORT_C TInt CPECallHandling::GetCallDuration( 
       
  1041     TTimeIntervalSeconds& aDuration,
       
  1042     TInt aCallId )
       
  1043     {
       
  1044     TInt errorCode( KErrNone );
       
  1045 
       
  1046     if ( CallIdCheck::IsVoice( aCallId ))
       
  1047         {
       
  1048         CPESingleCall* callData = iCallArrayOwner->GetCallObject( aCallId );
       
  1049         if( callData )
       
  1050             {
       
  1051             callData->GetCallDuration( aDuration );
       
  1052             }
       
  1053         else
       
  1054             {
       
  1055             __ASSERT_DEBUG( EFalse, Panic( EPEPanicIllegalCommand) );
       
  1056             }
       
  1057         }
       
  1058     else if ( CallIdCheck::IsVideo( aCallId ) )
       
  1059         {
       
  1060         iVideoCallHandling->GetCallDuration( aDuration, aCallId );
       
  1061         }
       
  1062     else if ( CallIdCheck::IsConference( aCallId ) )
       
  1063         {
       
  1064         if( iConferenceCall )
       
  1065             {
       
  1066             iConferenceCall->GetCallDuration( aDuration );
       
  1067             errorCode = KErrNone;
       
  1068             }
       
  1069         else
       
  1070             {
       
  1071             errorCode = ECCPErrorNotFound;
       
  1072             }
       
  1073         }
       
  1074     else
       
  1075         {
       
  1076         errorCode = ECCPErrorNotFound;
       
  1077         }
       
  1078     return errorCode;
       
  1079     }
       
  1080 
       
  1081 // -----------------------------------------------------------------------------
       
  1082 // CPECallHandling::RejectCall
       
  1083 // rejects the incoming call
       
  1084 // -----------------------------------------------------------------------------
       
  1085 //
       
  1086 EXPORT_C TInt CPECallHandling::RejectCall()
       
  1087     {
       
  1088     TEFLOGSTRING( KTAMESINT, "CALL CPECallHandling::RejectCall");
       
  1089     TInt callIndex;
       
  1090     TInt errorCode( ECCPErrorNotFound );
       
  1091     
       
  1092     CPESingleCall* callData = VoiceCallDataByState( EPEStateRinging, callIndex );
       
  1093     if( callIndex >= 0 )
       
  1094         {
       
  1095         callData->HangUp();
       
  1096         errorCode = KErrNone;
       
  1097         }
       
  1098     else
       
  1099         {
       
  1100         // Data call reject
       
  1101         errorCode = iVideoCallHandling->RejectCall();
       
  1102         }
       
  1103     return errorCode;
       
  1104     }
       
  1105 
       
  1106 // -----------------------------------------------------------------------------
       
  1107 // CPECallHandling::ReleaseAll
       
  1108 // Release ongoing calls
       
  1109 // -----------------------------------------------------------------------------
       
  1110 //
       
  1111 EXPORT_C TInt CPECallHandling::ReleaseAll()
       
  1112     {
       
  1113     TEFLOGSTRING( KTAMESINT, "CALL CPECallHandling::ReleaseAll");
       
  1114     CPESingleCall* callData;
       
  1115     TInt errorCode( ECCPErrorNotFound );
       
  1116     
       
  1117     // Normal Voice Calls
       
  1118     for ( TInt callId=0; callId < KPEMaximumNumberOfVoiceCalls; callId++ )
       
  1119         {
       
  1120         callData = iCallArrayOwner->GetCallObject( callId );
       
  1121         if( callData && 
       
  1122             callData->GetCallState() != EPEStateIdle &&
       
  1123             callData->GetCallState() != EPEStateRinging )
       
  1124             {
       
  1125             callData->HangUp();
       
  1126             errorCode = KErrNone;
       
  1127             }
       
  1128         }
       
  1129     
       
  1130     // Release ongoing data calls
       
  1131     errorCode ? errorCode = iVideoCallHandling->ReleaseAll() : iVideoCallHandling->ReleaseAll();
       
  1132       
       
  1133     TEFLOGSTRING2( KTAINT, "PE CPECallHandling::ReleaseAll, error id: %d", 
       
  1134         errorCode );
       
  1135     
       
  1136     return errorCode;
       
  1137     }
       
  1138 
       
  1139 // -----------------------------------------------------------------------------
       
  1140 // CPECallHandling::SendDtmf
       
  1141 // sends dtmf string
       
  1142 // -----------------------------------------------------------------------------
       
  1143 //
       
  1144 EXPORT_C TInt CPECallHandling::SendDtmf( 
       
  1145     const TPEDtmfString& aDtmfString )
       
  1146     {
       
  1147     return iDtmfHandling->SendDtmfString( aDtmfString );
       
  1148     }
       
  1149 
       
  1150 // -----------------------------------------------------------------------------
       
  1151 // CPECallHandling::ContinueDtmfSending
       
  1152 // Continues dtmf sending after 'w'-character
       
  1153 // -----------------------------------------------------------------------------
       
  1154 //
       
  1155 EXPORT_C void CPECallHandling::ContinueDtmfSending()
       
  1156     {
       
  1157     iDtmfHandling->ContinueDtmfSending();
       
  1158     }
       
  1159 
       
  1160 // -----------------------------------------------------------------------------
       
  1161 // CPECallHandling::StartDtmfTone
       
  1162 // sends dtmf tone to the remote party
       
  1163 // -----------------------------------------------------------------------------
       
  1164 //
       
  1165 EXPORT_C TInt CPECallHandling::StartDtmfTone( 
       
  1166     const TChar& aTone )
       
  1167     {
       
  1168     iDtmfHandling->StartDtmfTone(aTone);
       
  1169     return KErrNone;
       
  1170     }
       
  1171 
       
  1172 // -----------------------------------------------------------------------------
       
  1173 // CPECallHandling::StopDtmfSending
       
  1174 // Stops dtmf sending after 'w'-character
       
  1175 // -----------------------------------------------------------------------------
       
  1176 //
       
  1177 EXPORT_C void CPECallHandling::StopDtmfSending()
       
  1178     {
       
  1179     iDtmfHandling->StopDtmfSending();
       
  1180     }
       
  1181 
       
  1182 // -----------------------------------------------------------------------------
       
  1183 // CPECallHandling::StopDtmfTone
       
  1184 // stops sending dtmf tone to the remote party
       
  1185 // -----------------------------------------------------------------------------
       
  1186 //
       
  1187 EXPORT_C TInt CPECallHandling::StopDtmfTone()
       
  1188     {
       
  1189     iDtmfHandling->StopDtmfTone();
       
  1190     return KErrNone;
       
  1191     }
       
  1192 
       
  1193 // -----------------------------------------------------------------------------
       
  1194 // CPECallHandling::CancelDtmfPlay
       
  1195 // Cancels Dtmf string sending
       
  1196 // -----------------------------------------------------------------------------
       
  1197 //
       
  1198 EXPORT_C void CPECallHandling::CancelDtmfPlay()
       
  1199     {
       
  1200     iDtmfHandling->CancelDtmfString();
       
  1201     }
       
  1202 
       
  1203 // -----------------------------------------------------------------------------
       
  1204 // CPECallHandling::VoiceCallDataByState
       
  1205 // returns CPESingleCall voice call object by State
       
  1206 // -----------------------------------------------------------------------------
       
  1207 //
       
  1208 EXPORT_C CPESingleCall* CPECallHandling::VoiceCallDataByState( 
       
  1209     TPEState aState,
       
  1210     TInt& aIndex ) const
       
  1211     {
       
  1212     aIndex = KPECallIdNotUsed;
       
  1213     CPESingleCall* returnValue = NULL;
       
  1214     if ( aState != EPEStateIdle )
       
  1215         {
       
  1216         for ( TInt callId=0; callId < KPEMaximumNumberOfVoiceCalls; callId++ )
       
  1217             {        
       
  1218             CPESingleCall* callData = iCallArrayOwner->GetCallObject( callId );
       
  1219             if( callData )
       
  1220                 {
       
  1221                 if ( callData->GetCallState() == aState )
       
  1222                     {
       
  1223                     TEFLOGSTRING2( 
       
  1224                         KTAREQEND, 
       
  1225                         "CALL CPECallHandling::VoiceCallDataByState: , aState: %d", 
       
  1226                         aState );
       
  1227                     TEFLOGSTRING2( 
       
  1228                         KTAREQEND, 
       
  1229                         "CALL CPECallHandling::VoiceCallDataByState: , callId: %d", 
       
  1230                         aState );
       
  1231                     aIndex = callId;
       
  1232                     returnValue = callData;
       
  1233                     break;
       
  1234                     }
       
  1235                 }
       
  1236             }
       
  1237         }
       
  1238     return returnValue;
       
  1239     }
       
  1240 
       
  1241 // -----------------------------------------------------------------------------
       
  1242 // From base class MPECallInitiator
       
  1243 // Initialises (incoming,external) voice call.
       
  1244 // -----------------------------------------------------------------------------
       
  1245 //
       
  1246 void CPECallHandling::InitVoiceCall( MCCECall& aNewCall )
       
  1247     {
       
  1248     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::InitVoiceCall" );
       
  1249     CPESingleCall* callData( NULL );
       
  1250     TRAP_IGNORE( ( callData = iCallArrayOwner->CreateCallL( *this ) ) );
       
  1251 
       
  1252     if ( callData )
       
  1253         {
       
  1254         iModel.DataStore()->SetPhoneNumber( KNullDesC() );
       
  1255         iModel.DataStore()->SetServiceId( callData->GetCallId(), aNewCall.ServiceId() );
       
  1256         const CCCPCallParameters& callParameters = aNewCall.Parameters();
       
  1257         
       
  1258         TEFLOGSTRING2( KTAINT, "CALL CPECallHandling::InitVoiceCall call type: %d",  callParameters.CallType() );
       
  1259         switch ( callParameters.CallType() )
       
  1260             {
       
  1261             case CCPCall::ECallTypeCSVoice:
       
  1262                 {
       
  1263                 iModel.DataStore()->SetCallType( EPECallTypeCSVoice, callData->GetCallId() );
       
  1264                 // Set incoming Call's Als line
       
  1265                 const CCCECallParameters& cceparams = 
       
  1266                     static_cast<const CCCECallParameters&> (callParameters);
       
  1267                 iModel.DataStore()->SetCallALSLine( cceparams.LineType(), callData->GetCallId() );
       
  1268                 }
       
  1269                 break;
       
  1270             case CCPCall::ECallTypePS:
       
  1271                 {
       
  1272                 iModel.DataStore()->SetCallType( EPECallTypeVoIP, callData->GetCallId() );
       
  1273                 }
       
  1274                 break;
       
  1275             default:
       
  1276                 __ASSERT_DEBUG( EFalse, Panic( EPEPanicIndexOutOfRange ));
       
  1277                 break;
       
  1278             }
       
  1279         callData->SetCall( aNewCall );
       
  1280         TPECallControlCaps callControlCaps;
       
  1281         TInt err = GetCallControlCaps( callControlCaps, callData->GetCallId() );
       
  1282         if ( err == KErrNone )
       
  1283             {
       
  1284             iModel.DataStore()->SetCallControlCaps( callControlCaps, callData->GetCallId() );
       
  1285             }
       
  1286         iModel.DataStore()->SetCallSecureStatus( IsSecureCall( callData->GetCallId() ), callData->GetCallId() );
       
  1287         iModel.DataStore()->SetSecureSpecified( callData->SecureSpecified() );
       
  1288         }
       
  1289     else
       
  1290         {
       
  1291         Panic( EPEPanicNoFreeCalls );
       
  1292         }
       
  1293     }
       
  1294 
       
  1295 // -----------------------------------------------------------------------------
       
  1296 // From base class MPECallInitiator
       
  1297 // Initialises (incoming,external) video call.
       
  1298 // -----------------------------------------------------------------------------
       
  1299 //
       
  1300 void CPECallHandling::InitVideoCall( MCCECall& aNewCall )
       
  1301     {
       
  1302     iVideoCallHandling->InitCall( aNewCall );
       
  1303     }
       
  1304 
       
  1305 // -----------------------------------------------------------------------------
       
  1306 // CPECallHandling::ConnectedCalls
       
  1307 // Indicates if there is any connected calls
       
  1308 // -----------------------------------------------------------------------------
       
  1309 //
       
  1310 EXPORT_C TBool CPECallHandling::ConnectedCalls()
       
  1311     {
       
  1312     TInt index;
       
  1313     return ( VoiceCallDataByState( EPEStateConnected, index ) ||
       
  1314              VoiceCallDataByState( EPEStateHeld, index ) ||
       
  1315              iVideoCallHandling->ConnectedCalls() );
       
  1316     }
       
  1317 
       
  1318 
       
  1319 // -----------------------------------------------------------------------------
       
  1320 // CPECallHandling::StartUp
       
  1321 // Starts monitoring incoming data calls
       
  1322 // -----------------------------------------------------------------------------
       
  1323 //
       
  1324 EXPORT_C void CPECallHandling::StartUp()
       
  1325     {
       
  1326     }
       
  1327 
       
  1328 // -----------------------------------------------------------------------------
       
  1329 // CPECallHandling::SetCallParams
       
  1330 //
       
  1331 // -----------------------------------------------------------------------------
       
  1332 //
       
  1333 void CPECallHandling::SetCallParams( TInt aCallId )
       
  1334     {
       
  1335     iCallOpenParams->SetLineType( iActiveLine );
       
  1336     iModel.DataStore()->SetCallALSLine( iActiveLine, aCallId );
       
  1337     switch ( iModel.DataStore()->CallTypeCommand() )
       
  1338         {
       
  1339         case EPECallTypeCSVoice:
       
  1340             {
       
  1341             iCallOpenParams->SetCallType( CCPCall::ECallTypeCSVoice );
       
  1342             iModel.DataStore()->SetServiceIdCommand( 1 );
       
  1343             iModel.DataStore()->SetCallType( EPECallTypeCSVoice, aCallId );
       
  1344             }
       
  1345             break;
       
  1346         case EPECallTypeVideo:
       
  1347             {
       
  1348             iCallOpenParams->SetCallType( CCPCall::ECallTypeVideo);
       
  1349             iModel.DataStore()->SetServiceIdCommand( 1 );
       
  1350             iModel.DataStore()->SetCallType( EPECallTypeVideo, aCallId );
       
  1351             }
       
  1352             break;
       
  1353         case EPECallTypeVoIP:
       
  1354             {
       
  1355             iCallOpenParams->SetCallType( CCPCall::ECallTypePS);
       
  1356             iModel.DataStore()->SetCallType( EPECallTypeVoIP, aCallId );
       
  1357             //PhoneApp set service id in voip call case
       
  1358             }
       
  1359             break;
       
  1360         case EPECallTypeUninitialized:
       
  1361         default:
       
  1362             iCallOpenParams->SetCallType( CCPCall::ECallTypeCSVoice);
       
  1363             iModel.DataStore()->SetServiceIdCommand( 1 );
       
  1364             iModel.DataStore()->SetCallType( EPECallTypeCSVoice, aCallId );
       
  1365             break;
       
  1366         } 
       
  1367     iCallOpenParams->SetServiceId( iModel.DataStore()->ServiceIdCommand() );
       
  1368     }
       
  1369 
       
  1370 // -----------------------------------------------------------------------------
       
  1371 // CPECallHandling::SendMessage
       
  1372 // Reroutes messages to the Phone Engine
       
  1373 // -----------------------------------------------------------------------------
       
  1374 //
       
  1375 void CPECallHandling::SendMessage( 
       
  1376     const MEngineMonitor::TPEMessagesFromPhoneEngine aMessage,
       
  1377     const TName& aName )
       
  1378     {
       
  1379     TEFLOGSTRING2( KTAINT, "CALL CPECallHandling::SendMessage, message id: %d", aMessage );
       
  1380     TInt callId( KPECallIdNotUsed );
       
  1381     MPECall* call = iCallArrayOwner->CallByName( aName );
       
  1382     if( call )
       
  1383         {
       
  1384         callId = call->GetCallId();
       
  1385         }
       
  1386 
       
  1387     SendMessage( aMessage, callId );
       
  1388     }
       
  1389 
       
  1390 // -----------------------------------------------------------------------------
       
  1391 // CPECallHandling::HandleInternalMessage
       
  1392 // Reroutes messages to the Phone Engine
       
  1393 // -----------------------------------------------------------------------------
       
  1394 //
       
  1395 void CPECallHandling::HandleInternalMessage(
       
  1396     TInt aMessage )
       
  1397     {
       
  1398     iModel.HandleInternalMessage( aMessage );
       
  1399     }
       
  1400 
       
  1401 // -----------------------------------------------------------------------------
       
  1402 // CPECallHandling::OpenNewCallL
       
  1403 // returns ETrue if hangup active
       
  1404 // -----------------------------------------------------------------------------
       
  1405 //
       
  1406 CPESingleCall* CPECallHandling::OpenNewCallL( const TPEPhoneNumber& aNumber )
       
  1407     {
       
  1408     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::OpenNewCallL");
       
  1409     TInt errorCode( KErrNone );
       
  1410     CPESingleCall* callData( NULL );
       
  1411     MCCECall* cceCall( NULL );
       
  1412     callData = iCallArrayOwner->CreateCallL( *this );
       
  1413     SetCallParams( callData->GetCallId() );
       
  1414     
       
  1415     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::OpenNewCallL > CCCE::OpenNewCallL");
       
  1416     TRAP( errorCode, 
       
  1417           cceCall = &( iConvergedCallEngine.OpenNewCallL( aNumber, 
       
  1418                                                           *iCallOpenParams, 
       
  1419                                                           *callData ) ) );
       
  1420     if ( errorCode == KErrNone )
       
  1421         {
       
  1422         callData->SetCall( *cceCall );
       
  1423         iModel.DataStore()->SetServiceId( callData->GetCallId(), cceCall->ServiceId() );
       
  1424         iModel.DataStore()->SetCallSecureStatus( callData->IsSecureCall(), callData->GetCallId() );
       
  1425         iModel.DataStore()->SetSecureSpecified( callData->SecureSpecified() ); 
       
  1426         TPECallControlCaps callControlCaps;
       
  1427         TInt err = GetCallControlCaps( callControlCaps, callData->GetCallId() );
       
  1428         if ( err == KErrNone )
       
  1429             {
       
  1430             iModel.DataStore()->SetCallControlCaps( callControlCaps, callData->GetCallId() );
       
  1431             }
       
  1432         }
       
  1433     else
       
  1434         {
       
  1435         // Open new call failed
       
  1436         ReleaseCallObject( callData->GetCallId() );
       
  1437         TEFLOGSTRING2( KTAERROR, 
       
  1438             "CALL CPECALLHANDLING::OPENNEWCALLL ! OPENNEWCALL FAILED: MAY NOT PROCEED! %d", errorCode );
       
  1439         User::Leave( errorCode );
       
  1440         }
       
  1441     return callData;
       
  1442     }
       
  1443  
       
  1444 // -----------------------------------------------------------------------------
       
  1445 // CPECallHandling::SetActiveLine
       
  1446 // Sets active line
       
  1447 // -----------------------------------------------------------------------------
       
  1448 //
       
  1449 EXPORT_C void CPECallHandling::SetActiveLine()
       
  1450     {
       
  1451     TEFLOGSTRING( KTAINT, "PE CPECallHandling::SetActiveLine" );
       
  1452     iActiveLine = iModel.DataStore()->ALSLine();
       
  1453     }
       
  1454 
       
  1455 // -----------------------------------------------------------------------------
       
  1456 // CPECallHandling::IsSecureCall
       
  1457 // Returns the call secure status
       
  1458 // -----------------------------------------------------------------------------
       
  1459 //
       
  1460 TBool CPECallHandling::IsSecureCall( const TInt aCallId ) const
       
  1461     {
       
  1462     TEFLOGSTRING2( 
       
  1463         KTAINT, 
       
  1464         "PE CPECallHandling::IsSecureCall:  aCallId = %d", 
       
  1465         aCallId );
       
  1466     CPESingleCall* call = iCallArrayOwner->GetCallObject( aCallId );
       
  1467     
       
  1468     __ASSERT_DEBUG( call, Panic( EPEPanicIndexOutOfRange ) );  
       
  1469     TBool secured( EFalse );
       
  1470     if( call )
       
  1471         {
       
  1472         secured = call->IsSecureCall();
       
  1473         }
       
  1474     return secured;
       
  1475     }
       
  1476 
       
  1477 // -----------------------------------------------------------------------------
       
  1478 // CPECallHandling::GetNumberOfParticipants
       
  1479 // returns number of conference members
       
  1480 // -----------------------------------------------------------------------------
       
  1481 //
       
  1482 TInt CPECallHandling::GetNumberOfParticipants( 
       
  1483         TInt& aCount )    // The Number of participants 
       
  1484     {
       
  1485     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::GetNumberOfParticipants" );
       
  1486     TInt errorCode( ECCPErrorNotFound );
       
  1487 
       
  1488     if ( iConferenceCall )
       
  1489         {
       
  1490         aCount = iConferenceCall->EnumerateCalls();
       
  1491         TEFLOGSTRING2( KTAINT, "CALL CPECallHandling::GetNumberOfParticipants count %d", aCount );
       
  1492         errorCode = KErrNone;
       
  1493         }
       
  1494     return errorCode;
       
  1495     }
       
  1496  
       
  1497 // -----------------------------------------------------------------------------
       
  1498 // CPECallHandling::GetConferenceMemberNameAndId
       
  1499 // Returns added or removeds members TName information and CallId.
       
  1500 // -----------------------------------------------------------------------------
       
  1501 //
       
  1502 TInt CPECallHandling::GetConferenceMemberNameAndId( 
       
  1503         TName& aCallName,   // Added or removed members TName information is returned here
       
  1504         TInt& aMemberCallId ) // Added or removed members callid is returned here
       
  1505     {
       
  1506     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::GetConferenceMemberNameAndId" );
       
  1507     TInt errorCode( ECCPErrorNotFound );
       
  1508 
       
  1509     if ( iConferenceCall )
       
  1510         {
       
  1511         iConferenceCall->GetConferenceMemberName( aCallName );
       
  1512         MPECall* call = iCallArrayOwner->CallByName( aCallName );
       
  1513         
       
  1514         if( call )
       
  1515             {
       
  1516             aMemberCallId = call->GetCallId();
       
  1517             TEFLOGSTRING2( KTAINT, "CALL CPECallHandling::GetConferenceMemberNameAndId CallId %d", aMemberCallId );
       
  1518             errorCode = KErrNone;
       
  1519             }
       
  1520         else
       
  1521             {
       
  1522             aMemberCallId = -1;
       
  1523             aCallName = KNullDesC;
       
  1524             }   
       
  1525         }
       
  1526     TEFLOGSTRING2( KTAINT, "CALL CPECallHandling::GetConferenceMemberNameAndId errorCode %d", errorCode );
       
  1527     return errorCode;
       
  1528     }
       
  1529 
       
  1530 // -----------------------------------------------------------------------------
       
  1531 // CPECallHandling::GetCallControlCaps
       
  1532 // returns call info
       
  1533 // Method checks that call id is valid number
       
  1534 // Method gets CPESingleCall object from the CArrayPtrFlat and
       
  1535 // Method gets call info from CPESingleCall object
       
  1536 // -----------------------------------------------------------------------------
       
  1537 //
       
  1538 TInt CPECallHandling::GetCallControlCaps(
       
  1539         TPECallControlCaps& aCallControlCaps,
       
  1540         TInt aCallId )
       
  1541     {
       
  1542     TEFLOGSTRING2( KTAINT, "CALL CPECallHandling::GetCallControlCaps %d", aCallId );
       
  1543     CPESingleCall* callData;
       
  1544     TInt errorCode( ECCPErrorNotFound );
       
  1545     MCCECallObserver::TCCECallControlCaps callControlCaps;
       
  1546     callData = iCallArrayOwner->GetCallObject( aCallId );
       
  1547 
       
  1548     if ( callData )
       
  1549         {
       
  1550         callData->GetCallControlCaps( callControlCaps );
       
  1551         aCallControlCaps = static_cast<TPECallControlCaps>( callControlCaps );
       
  1552         errorCode = KErrNone;
       
  1553         }
       
  1554     return errorCode;
       
  1555     }
       
  1556 
       
  1557 // -----------------------------------------------------------------------------
       
  1558 // CPECallHandling::GetConferenceCallCaps
       
  1559 // returns conference call capabilities
       
  1560 // Checks that call id is valid and gets CPEConferenceCall object and calls its method
       
  1561 // to get capabilities
       
  1562 // -----------------------------------------------------------------------------
       
  1563 //
       
  1564 TInt CPECallHandling::GetConferenceCallCaps( 
       
  1565         TUint32& aCaps )     // capabilities are returned in this parameter
       
  1566     {
       
  1567     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::GetConferenceCallCaps" );
       
  1568     TInt errorCode( ECCPErrorNotFound );
       
  1569     if ( iConferenceCall  )
       
  1570         {
       
  1571         aCaps = iConferenceCall->CallCaps();
       
  1572         errorCode = KErrNone;
       
  1573         }
       
  1574     return errorCode;
       
  1575     }
       
  1576 
       
  1577 // -----------------------------------------------------------------------------
       
  1578 // CPECallHandling::AddMember
       
  1579 // Adds member to the conference call
       
  1580 // -----------------------------------------------------------------------------
       
  1581 //
       
  1582 TInt CPECallHandling::AddMember(
       
  1583         TInt aCallId )
       
  1584     {
       
  1585     TEFLOGSTRING2( KTAINT, "CALL CPECallHandling::AddMember %d", aCallId );
       
  1586     TInt errorCode( KErrNone );
       
  1587     TRAP( errorCode, AddMemberL( aCallId ));
       
  1588     return errorCode;
       
  1589     }
       
  1590 
       
  1591 
       
  1592 // -----------------------------------------------------------------------------
       
  1593 // CPECallHandling::AddMemberL
       
  1594 // Adds member to the conference call
       
  1595 // -----------------------------------------------------------------------------
       
  1596 //
       
  1597 void CPECallHandling::AddMemberL(
       
  1598         TInt aCallId )
       
  1599     {
       
  1600     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::AddMemberL" );
       
  1601     CPESingleCall* callData;
       
  1602     callData = iCallArrayOwner->GetCallObject( aCallId );
       
  1603     
       
  1604     if ( callData && iConferenceCall && CallIdCheck::IsVoice( aCallId ))
       
  1605         {
       
  1606         iConferenceCall->AddCallL( callData->Call() );
       
  1607         }
       
  1608     else
       
  1609         {
       
  1610         User::Leave( ECCPErrorNotFound );
       
  1611         }
       
  1612     }
       
  1613 
       
  1614 // -----------------------------------------------------------------------------
       
  1615 // CPECallHandling::CallTerminatedError
       
  1616 // Handles RemoteTerminated. 
       
  1617 // -----------------------------------------------------------------------------
       
  1618 // 
       
  1619 EXPORT_C TInt CPECallHandling::CallTerminatedError(
       
  1620         const TInt aCallId )
       
  1621     {
       
  1622     TInt errorCode( KErrNone );
       
  1623     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::CallTerminatedError" );
       
  1624     CPESingleCall* callObject = iCallArrayOwner->GetCallObject( aCallId );
       
  1625     if ( callObject )
       
  1626         {
       
  1627         callObject->GetErrorCode( errorCode );
       
  1628         }
       
  1629     
       
  1630     return errorCode;
       
  1631     }
       
  1632 
       
  1633 // -----------------------------------------------------------------------------
       
  1634 // CPECallHandling::BuildConference
       
  1635 // creates conference call
       
  1636 // -----------------------------------------------------------------------------
       
  1637 //
       
  1638 EXPORT_C TInt CPECallHandling::BuildConference()
       
  1639     {
       
  1640     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::BuildConference" );
       
  1641     TInt heldcallid;
       
  1642     CPESingleCall* heldcall( NULL );
       
  1643     TInt connectedcallid;
       
  1644     CPESingleCall* connectedcall( NULL );
       
  1645     TInt errorCode( ECCPErrorNotAllowed );
       
  1646 
       
  1647     heldcall = VoiceCallDataByState( EPEStateHeld, heldcallid );
       
  1648     if ( heldcall )
       
  1649         {
       
  1650         connectedcall = VoiceCallDataByState( EPEStateConnected, connectedcallid );
       
  1651         
       
  1652         if ( connectedcall )
       
  1653             {
       
  1654             TRAP( errorCode, CreateConferenceCallL( *heldcall, *connectedcall ) );
       
  1655             }
       
  1656         }
       
  1657     
       
  1658     return errorCode;
       
  1659     }
       
  1660 
       
  1661 // -----------------------------------------------------------------------------
       
  1662 // CPECallHandling::SwapCalls
       
  1663 // resumes a held call
       
  1664 // Method search active and held call
       
  1665 // Method gets CPESingleCall object from the CArrayPtrFlat and
       
  1666 // Method checks that call is in held state
       
  1667 // Method makes swap request to CPESingleCall object.
       
  1668 // -----------------------------------------------------------------------------
       
  1669 //
       
  1670 EXPORT_C TInt CPECallHandling::SwapCalls()
       
  1671     {
       
  1672     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::SwapCalls" );
       
  1673     TInt callIndex;
       
  1674     CPESingleCall* callData;
       
  1675     TInt errorCode( ECCPErrorNotFound );
       
  1676 
       
  1677     if ( ( iConferenceCall ) && 
       
  1678          ( iConferenceCall->GetCallState() == EPEStateConnectedConference ) )
       
  1679         {
       
  1680         errorCode = iConferenceCall->Swap();
       
  1681         }
       
  1682     else
       
  1683         {
       
  1684         callData = VoiceCallDataByState( EPEStateConnected, callIndex );
       
  1685         if( callData )
       
  1686             {
       
  1687             errorCode = callData->Swap();
       
  1688             }
       
  1689         }
       
  1690 
       
  1691     return errorCode;
       
  1692     }   
       
  1693 
       
  1694 // -----------------------------------------------------------------------------
       
  1695 // CPECallHandling::AddConferenceMember
       
  1696 // Handles add conference member
       
  1697 // -----------------------------------------------------------------------------
       
  1698 //
       
  1699 EXPORT_C TInt CPECallHandling::AddConferenceMember()
       
  1700     {
       
  1701     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::AddConferenceMember" );
       
  1702 
       
  1703     CPESingleCall* callData;
       
  1704     TInt errorCode( ECCPErrorNotFound );
       
  1705     TPEState callState;
       
  1706     
       
  1707     // Checks that call is single call and state of call is connected or held
       
  1708     for( TInt callId = 0; callId < KPEMaximumNumberOfVoiceCalls; callId++ )
       
  1709         {
       
  1710         callData = iCallArrayOwner->GetCallObject( callId );
       
  1711         if( callData )
       
  1712             {
       
  1713             // Check that call is not already join to Conference
       
  1714             if ( iModel.DataStore()->IsConferenceMemberId( callId ) == KPECallIdNotUsed )
       
  1715                 {
       
  1716                 callState = callData->GetCallState();
       
  1717                 if ( callState == EPEStateConnected || callState == EPEStateHeld )
       
  1718                     {
       
  1719                     TEFLOGSTRING2( KTAINT, 
       
  1720                         "CALL CPECallHandling::AddConferenceMember > AddMember, CallId =  %d"
       
  1721                         , callId );
       
  1722                     errorCode = AddMember( callId );
       
  1723                     break;
       
  1724                     }
       
  1725                 }
       
  1726             }
       
  1727         }
       
  1728     return errorCode;
       
  1729     }
       
  1730 
       
  1731 // -----------------------------------------------------------------------------
       
  1732 // CPECallHandling::DropMember
       
  1733 // drops member from the conference call
       
  1734 // -----------------------------------------------------------------------------
       
  1735 //
       
  1736 EXPORT_C TInt CPECallHandling::DropMember( 
       
  1737         TInt aCallId )
       
  1738     {
       
  1739     TEFLOGSTRING2( KTAINT, "CALL CPECallHandling::DropMember %d", aCallId );
       
  1740     CPESingleCall* callData;
       
  1741     TInt errorCode( ECCPErrorNotFound );
       
  1742 
       
  1743     if ( CallIdCheck::IsVoice( aCallId ))
       
  1744         {
       
  1745         callData = iCallArrayOwner->GetCallObject( aCallId );
       
  1746         if ( callData )
       
  1747             {
       
  1748             callData->HangUp();
       
  1749             errorCode = KErrNone;
       
  1750             }
       
  1751         }
       
  1752     return errorCode;
       
  1753     }
       
  1754 
       
  1755 // -----------------------------------------------------------------------------
       
  1756 // CPECallHandling::GoOneToOne
       
  1757 // Splits one call to private conversation.
       
  1758 // -----------------------------------------------------------------------------
       
  1759 //
       
  1760 EXPORT_C TInt CPECallHandling::GoOneToOne( 
       
  1761         TInt aCallId )
       
  1762     {
       
  1763     TEFLOGSTRING2( KTAINT, "CALL CPECallHandling::GoOneToOne %d", aCallId );
       
  1764     TInt errorCode( ECCPErrorNotFound );
       
  1765     CPESingleCall* callData;
       
  1766     
       
  1767     callData = iCallArrayOwner->GetCallObject( aCallId );
       
  1768             
       
  1769     if ( iConferenceCall && callData )
       
  1770         {
       
  1771         TRAP( errorCode, iConferenceCall->GoOneToOneL( callData->Call() ) );
       
  1772         }
       
  1773     return errorCode;
       
  1774     }
       
  1775  
       
  1776 // -----------------------------------------------------------------------------
       
  1777 // CPECallHandling::HoldCall
       
  1778 // holds an active call
       
  1779 // Method checks that call id is valid number and
       
  1780 // Method gets CPESingleCall object from the CArrayPtrFlat and
       
  1781 // Method checks that call is in connected state
       
  1782 // Method makes hold request to CPESingleCall object.
       
  1783 // -----------------------------------------------------------------------------
       
  1784 //
       
  1785 EXPORT_C TInt CPECallHandling::HoldCall()
       
  1786     {
       
  1787     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::HoldCall" );
       
  1788     CPESingleCall* callData;
       
  1789     TInt callIndex;
       
  1790     TInt errorCode( ECCPErrorNotAllowed );
       
  1791 
       
  1792     if ( iConferenceCall && ( iConferenceCall->GetCallState() == EPEStateConnectedConference ) )
       
  1793         {
       
  1794         // hold was explicitly requested by the user, 
       
  1795         // update information to engine info
       
  1796         iModel.DataStore()->SetResumeHeldCall( EFalse, KPEConferenceCallID );
       
  1797         errorCode = iConferenceCall->Swap();
       
  1798         }
       
  1799     else
       
  1800         {
       
  1801         callData = VoiceCallDataByState( EPEStateConnected, callIndex );   
       
  1802         if( callData )
       
  1803             {
       
  1804             // hold was explicitly requested by the user, 
       
  1805             // update information to engine info
       
  1806             iModel.DataStore()->SetResumeHeldCall( EFalse, callIndex );
       
  1807             errorCode = callData->Hold();
       
  1808             }
       
  1809         }
       
  1810 
       
  1811     return errorCode;
       
  1812     }
       
  1813 
       
  1814 // -----------------------------------------------------------------------------
       
  1815 // CPECallHandling::ResumeCall
       
  1816 // resumes a held call
       
  1817 // Method checks that call id is valid number and
       
  1818 // Method gets CPESingleCall object from the CArrayPtrFlat and
       
  1819 // Method checks that call is in held state
       
  1820 // Method makes resume request to CPESingleCall object.
       
  1821 // -----------------------------------------------------------------------------
       
  1822 //
       
  1823 EXPORT_C TInt CPECallHandling::ResumeCall()
       
  1824     {
       
  1825     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::ResumeCall" );
       
  1826     CPESingleCall* callData;
       
  1827     TInt callIndex;
       
  1828     TInt errorCode( ECCPErrorNotAllowed );
       
  1829 
       
  1830     if ( iConferenceCall && ( iConferenceCall->GetCallState() == EPEStateHeldConference ) )
       
  1831         {
       
  1832         // resume was explicitly requested by the user, update information to engine info
       
  1833         iModel.DataStore()->SetResumeHeldCall( ETrue, KPEConferenceCallID );
       
  1834         errorCode = iConferenceCall->Swap();
       
  1835         }
       
  1836     else
       
  1837         {
       
  1838         callData = VoiceCallDataByState( EPEStateHeld, callIndex );
       
  1839         if( callData )
       
  1840             {
       
  1841             // resume was explicitly requested by the user, update information to engine info
       
  1842             iModel.DataStore()->SetResumeHeldCall( ETrue, callIndex );
       
  1843             errorCode = callData->Resume();
       
  1844             }
       
  1845         }
       
  1846 
       
  1847     return errorCode;
       
  1848     }
       
  1849 
       
  1850 // -----------------------------------------------------------------------------
       
  1851 // CPECallHandling::TransferCalls
       
  1852 // transfers the held party to the active party
       
  1853 // Method search active and held call
       
  1854 // Method gets CPESingleCall object from the CArrayPtrFlat and
       
  1855 // Method checks that call is in held state
       
  1856 // Method makes transfer request to CPESingleCall object.
       
  1857 // -----------------------------------------------------------------------------
       
  1858 //
       
  1859 EXPORT_C TInt CPECallHandling::TransferCalls()
       
  1860     {
       
  1861     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::TransferCalls" );
       
  1862     TInt callIndex;
       
  1863     CPESingleCall* callData;
       
  1864     CPESingleCall* callDataHeld;
       
  1865     TInt errorCode( ECCPErrorNotAllowed );
       
  1866 
       
  1867     callDataHeld = VoiceCallDataByState( EPEStateHeld, callIndex );
       
  1868     if( callDataHeld && !iConferenceCall )
       
  1869         { // found one held call
       
  1870         callData = VoiceCallDataByState( EPEStateConnected, callIndex );
       
  1871         if ( callData ) // found the connected call
       
  1872            {
       
  1873            TEFLOGSTRING( KTAINT, "CALL CPECallHandling::TransferCalls > Transfer" );
       
  1874            callDataHeld->Transfer( callData->Call().DialledParty() );
       
  1875            errorCode = KErrNone;
       
  1876            }
       
  1877         else
       
  1878            {
       
  1879            callData = VoiceCallDataByState( EPEStateConnecting, callIndex );
       
  1880            if ( callData ) // The connecting call found
       
  1881               {
       
  1882               TEFLOGSTRING( KTAINT, "CALL CPECallHandling::TransferCalls > Transfer" );
       
  1883               callDataHeld->Transfer( callData->Call().DialledParty() );
       
  1884               errorCode = KErrNone;
       
  1885               }
       
  1886            }
       
  1887         }
       
  1888         
       
  1889     return errorCode;
       
  1890     }
       
  1891 
       
  1892 // -----------------------------------------------------------------------------
       
  1893 // CPECallHandling::DialEmergencyCall
       
  1894 // creates emergency dial request to the CPESingleCall object
       
  1895 //    Method gets CPESingleCall object from the CArrayPtrFlat
       
  1896 //    Method makes emergency dial request
       
  1897 // -----------------------------------------------------------------------------
       
  1898 //
       
  1899 EXPORT_C void CPECallHandling::DialEmergencyCall( const TPEPhoneNumber& aEmergencyNumber )
       
  1900     {
       
  1901     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::DialEmergencyCall" );
       
  1902     
       
  1903     SendMessage( MEngineMonitor::EPEMessageInitiatedEmergencyCall );
       
  1904     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::DialEmergencyCall start emergency dialing" );
       
  1905     CPESingleCall* callData = iCallArrayOwner->GetCallObject( KPEEmergencyCallId );
       
  1906     callData->DialEmergency( aEmergencyNumber );   
       
  1907     }
       
  1908 
       
  1909 // -----------------------------------------------------------------------------
       
  1910 // CPECallHandling::GetCallTerminatedDiagnostics
       
  1911 // Returns call terminated diagnostics of a call
       
  1912 // Method returns valid info only after call state has changed to Idle.
       
  1913 // -----------------------------------------------------------------------------
       
  1914 //
       
  1915 EXPORT_C TInt CPECallHandling::GetCallTerminatedDiagnostics( 
       
  1916         TName& /*aCallName*/ ) const
       
  1917     {
       
  1918         
       
  1919     TInt diagnosticsInfo = 0/*iCustomAPI.GetDiagnosticInfo( aCallName )*/;
       
  1920     TEFLOGSTRING2( KTAMESIN, 
       
  1921             "CALL CPECallHandling::GetCallTerminatedDiagnostics: RMmCustomAPI::GetDiagnosticInfo, diagnosticInfo: %d", 
       
  1922             diagnosticsInfo );
       
  1923     return diagnosticsInfo;        
       
  1924     }
       
  1925 
       
  1926 // -----------------------------------------------------------------------------
       
  1927 // CPECallHandling::CreateConferenceCallL
       
  1928 // -----------------------------------------------------------------------------
       
  1929 //
       
  1930 void CPECallHandling::CreateConferenceCallL( 
       
  1931     CPESingleCall& aCall1, 
       
  1932     CPESingleCall& aCall2 )
       
  1933     {
       
  1934     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::CreateConferenceCallL start" );
       
  1935     if( !iConferenceCall )
       
  1936         {
       
  1937         iConferenceCall = CPEConferenceCall::NewL( *this, iConvergedCallEngine );
       
  1938         iConferenceCall->SetCallId( KPEConferenceCallID );
       
  1939         iConferenceCall->AddCallL( aCall1.Call() );
       
  1940         iConferenceCall->AddCallL( aCall2.Call() );
       
  1941         InitialiseConferenceCallInfo( aCall1.Call(), aCall2.Call() );
       
  1942         }
       
  1943     else
       
  1944         {
       
  1945         TEFLOGSTRING( KTAERROR, "CALL CPECallHandling::CreateConferenceCallL already exist" );
       
  1946         User::Leave( KErrAlreadyExists );
       
  1947         }
       
  1948 
       
  1949     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::CreateConferenceCallL end" );
       
  1950     }
       
  1951 
       
  1952 // -----------------------------------------------------------------------------
       
  1953 // CPECallHandling::GetLifeTime
       
  1954 // -----------------------------------------------------------------------------
       
  1955 //
       
  1956 EXPORT_C TBool CPECallHandling::GetLifeTime( TDes8& aLifeTimeInfo )
       
  1957     {
       
  1958     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::GetLifeTime" );
       
  1959     return iConvergedCallEngine.GetLifeTime( aLifeTimeInfo );
       
  1960     }
       
  1961     
       
  1962 // -----------------------------------------------------------------------------
       
  1963 // CPECallHandling::UpdateSaSetting
       
  1964 // -----------------------------------------------------------------------------
       
  1965 //
       
  1966 void CPECallHandling::UpdateSaSetting()
       
  1967     {
       
  1968     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::UpdateSaSetting start" );
       
  1969     
       
  1970     TUnconditionalCFStatus status( KCFIndicatorUnknown );
       
  1971     TSelectedLine line( ENotSupportedLine );
       
  1972     CCCECallParameters::TCCELineType lineType( CCCECallParameters::ECCELineTypePrimary );
       
  1973     CPESingleCall* call( NULL );
       
  1974     TCallDivertNotifySetting notifySet;
       
  1975     notifySet.Initialize();
       
  1976     notifySet.iCfActivated = ETrue;
       
  1977     
       
  1978     // Get dialing call object
       
  1979     call = iCallArrayOwner->CallPointerByState( EPEStateDialing );
       
  1980      
       
  1981     // Determinate als support and used line
       
  1982     lineType = iModel.DataStore()->ALSLine();
       
  1983     if( iModel.DataStore()->ALSLineSupport() )
       
  1984         {
       
  1985         if( CCCECallParameters::ECCELineTypePrimary == lineType )
       
  1986             {
       
  1987             line = EPrimaryLine;
       
  1988             }
       
  1989         else
       
  1990             {
       
  1991             line = EAuxiliaryLine;
       
  1992             }
       
  1993         }
       
  1994     TEFLOGSTRING2( KTAINT, "CALL CPECallHandling::UpdateSaSetting line %d", line );
       
  1995     
       
  1996     // Determinate basic service code
       
  1997     notifySet.iBasicServiceCode = DefineDivertBsc( lineType, call  ); 
       
  1998     
       
  1999     // Create phonesetting connection
       
  2000     if( !iPsetSAObserver )
       
  2001         {
       
  2002         TRAPD( errorCode, iPsetSAObserver = CPsetSAObserver::NewL() );
       
  2003         if( errorCode != KErrNone )
       
  2004             {
       
  2005             TEFLOGSTRING2( 
       
  2006                KTAERROR, 
       
  2007                "CALL CPECallHandling::UpdateSaSetting FAIL with error %d", 
       
  2008                errorCode );
       
  2009             return;
       
  2010             }
       
  2011         }
       
  2012         
       
  2013     // Get diver status
       
  2014     TInt error = iPsetSAObserver->GetCurrentDivertStatus( status );
       
  2015     if ( error != KErrNone )
       
  2016         {
       
  2017         status = KCFNoCallsForwarded;
       
  2018         }
       
  2019     notifySet.iPreviousCfStatus = status;
       
  2020     
       
  2021     // Update dovert indicator.
       
  2022     iPsetSAObserver->NotifyDivertChange( 
       
  2023         line, 
       
  2024         notifySet,
       
  2025         0 );
       
  2026         
       
  2027     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::UpdateSaSetting end" );
       
  2028     }
       
  2029 
       
  2030 // -----------------------------------------------------------------------------
       
  2031 // CPECallHandling::DefineDivertBsc
       
  2032 // -----------------------------------------------------------------------------
       
  2033 //  
       
  2034 TInt CPECallHandling::DefineDivertBsc( CCCECallParameters::TCCELineType aLineType, 
       
  2035                                        CPESingleCall* call )
       
  2036     {
       
  2037     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::DefineDivertBsc start" );
       
  2038     TInt bsc( EAllTele );
       
  2039     
       
  2040     if ( !call )
       
  2041         {
       
  2042         TEFLOGSTRING( KTAINT, "CALL CPECallHandling::DefineDivertBsc EUnknown" );
       
  2043         bsc = EUnknown;
       
  2044         return bsc;
       
  2045         }
       
  2046     else if ( call->Call().Parameters().CallType() == CCPCall::ECallTypeVideo  )
       
  2047         {
       
  2048         // If initiated call is video set bsc as ESyncData.
       
  2049         TEFLOGSTRING( KTAINT, "CALL CPECallHandling::DefineDivertBsc ESyncData" );
       
  2050         bsc = ESyncData;
       
  2051         return bsc;
       
  2052         }
       
  2053 
       
  2054     switch ( aLineType )
       
  2055         {
       
  2056         case CCCECallParameters::ECCELineTypePrimary:
       
  2057             // Call is done using line 1.
       
  2058             TEFLOGSTRING( KTAINT, "CALL CPECallHandling::DefineDivertBsc EAllTele" );
       
  2059             bsc = EAllTele;  
       
  2060             break;
       
  2061         case CCCECallParameters::ECCELineTypeAux:
       
  2062             // Call is done using line 2.
       
  2063             TEFLOGSTRING( KTAINT, "CALL CPECallHandling::DefineDivertBsc EAltTele" );
       
  2064             bsc = EAltTele;  
       
  2065             break;
       
  2066         default:
       
  2067             // Defauld case no alternate line service.
       
  2068             TEFLOGSTRING( KTAINT, "CALL CPECallHandling::DefineDivertBsc EAllTele default" );
       
  2069             bsc = EAllTele;  
       
  2070             break;
       
  2071         }
       
  2072         
       
  2073     TEFLOGSTRING2( KTAINT, "CALL CPECallHandling::DefineDivertBsc end, bsc = %d", bsc );
       
  2074     return bsc;
       
  2075     }
       
  2076 
       
  2077 // -----------------------------------------------------------------------------
       
  2078 // CPECallHandling::ReplaceActive
       
  2079 // Terminates an active call and answer waiting call
       
  2080 // -----------------------------------------------------------------------------
       
  2081 //
       
  2082 EXPORT_C TInt CPECallHandling::ReplaceActive()
       
  2083     {
       
  2084     TEFLOGSTRING( KTAMESINT, "CALL CPECallHandling::ReplaceActive");
       
  2085     TInt errorCode( ECCPErrorNotFound );
       
  2086     TInt callIdConnected = KPECallIdNotUsed;
       
  2087          
       
  2088     CPESingleCall* replacingcall = iCallArrayOwner->CallPointerByState( EPEStateRinging );
       
  2089 
       
  2090     if( iConferenceCall && iConferenceCall->GetCallState() == EPEStateConnectedConference )
       
  2091         {
       
  2092         callIdConnected = iConferenceCall->GetCallId(); 
       
  2093         }
       
  2094     else
       
  2095         {
       
  2096         CPESingleCall* connectedcall = iCallArrayOwner->CallPointerByState( EPEStateConnected );
       
  2097         if ( connectedcall )
       
  2098             {
       
  2099             callIdConnected = connectedcall->GetCallId();
       
  2100             }
       
  2101         }
       
  2102     if ( callIdConnected != KPECallIdNotUsed && replacingcall ) 
       
  2103         {
       
  2104         if( CallIdCheck::IsConference( callIdConnected ) || CallIdCheck::IsVoice( callIdConnected ) )
       
  2105             {
       
  2106             iReplaceActive = ETrue;
       
  2107             errorCode = HangUp( callIdConnected , ETPEHangUpNotResumeHeldCall );
       
  2108             TEFLOGSTRING2( KTAMESINT, "CALL CPECallHandling::ReplaceActive HangUp error %d", errorCode );
       
  2109             if ( !CallIdCheck::IsConference( callIdConnected ) && errorCode == KErrNone ) // Conference replace when idle
       
  2110                 {
       
  2111                 errorCode = AnswerCall();
       
  2112                 iReplaceActive = EFalse;
       
  2113                 TEFLOGSTRING2( KTAMESINT, "CALL CPECallHandling::ReplaceActive AnswerCall error %d", errorCode );
       
  2114                 }
       
  2115             else if ( errorCode != KErrNone )
       
  2116                 {
       
  2117                 iReplaceActive = EFalse;
       
  2118                 }
       
  2119             }
       
  2120         else
       
  2121             {
       
  2122             errorCode = iVideoCallHandling->ReplaceActive( callIdConnected );
       
  2123             TEFLOGSTRING2( KTAMESINT, "CALL CPECallHandling::ReplaceActive DataCallHandling::ReplaceActive error %d", errorCode );
       
  2124             }
       
  2125         }
       
  2126     else
       
  2127         {
       
  2128         TEFLOGSTRING( KTAERROR, "CALL CPECALLHANDLING::REPLACEACTIVE ! CALL OBJECT NOT FOUND" );
       
  2129         }
       
  2130 
       
  2131     return errorCode;
       
  2132     }
       
  2133 
       
  2134 // -----------------------------------------------------------------------------
       
  2135 // CPECallHandling::AcceptUnattendedTransfer
       
  2136 // -----------------------------------------------------------------------------
       
  2137 //
       
  2138 EXPORT_C TInt CPECallHandling::AcceptUnattendedTransfer()
       
  2139     {
       
  2140     TEFLOGSTRING( KTAMESINT, "CALL CPECallHandling::AcceptUnattendedTransfer" );
       
  2141     
       
  2142     TInt callId = iModel.DataStore()->CallId();
       
  2143     CPESingleCall* call = iCallArrayOwner->GetCallObject( callId );
       
  2144     __ASSERT_DEBUG( NULL != call, Panic( EPEPanicIllegalCommand ) );
       
  2145     if ( NULL != call )
       
  2146         {
       
  2147         return call->AcceptUnattendedTransfer();
       
  2148         }
       
  2149     else
       
  2150         {
       
  2151         return KErrNotFound;
       
  2152         }
       
  2153     }
       
  2154 
       
  2155 // -----------------------------------------------------------------------------
       
  2156 // CPECallHandling::RejectUnattendedTransfer
       
  2157 // -----------------------------------------------------------------------------
       
  2158 //
       
  2159 EXPORT_C TInt CPECallHandling::RejectUnattendedTransfer()
       
  2160     {
       
  2161     TEFLOGSTRING( KTAMESINT, "CALL CPECallHandling::RejectUnattendedTransfer" );
       
  2162     
       
  2163     TInt callId = iModel.DataStore()->CallId();
       
  2164     CPESingleCall* call = iCallArrayOwner->GetCallObject( callId );
       
  2165     __ASSERT_DEBUG( NULL != call, Panic( EPEPanicIllegalCommand ) );
       
  2166     if ( NULL != call )
       
  2167         {
       
  2168         return call->RejectUnattendedTransfer();
       
  2169         }
       
  2170     else
       
  2171         {
       
  2172         return KErrNotFound;
       
  2173         }
       
  2174     }
       
  2175 
       
  2176 // -----------------------------------------------------------------------------
       
  2177 // CPECallHandling::DoUnattendedTransfer
       
  2178 // Does unattended transfer request for the connected VoIP call
       
  2179 // -----------------------------------------------------------------------------
       
  2180 //
       
  2181 EXPORT_C TInt CPECallHandling::DoUnattendedTransfer( const TDesC& aTransferTarget )
       
  2182     {
       
  2183     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::DoUnattendedTransfer" );
       
  2184     CPESingleCall* callData;
       
  2185     TInt callIndex;
       
  2186     TInt errorCode( ECCPErrorNotAllowed );
       
  2187     callData = VoiceCallDataByState( EPEStateConnected, callIndex );  
       
  2188    
       
  2189     if( callData )
       
  2190         { 
       
  2191         errorCode = callData->UnattendedTransfer( aTransferTarget );
       
  2192         }
       
  2193        
       
  2194     return errorCode;
       
  2195     }
       
  2196 
       
  2197 // -----------------------------------------------------------------------------
       
  2198 // CPECallHandling::ForwardCallToAddress
       
  2199 // Forwards call by user selected address
       
  2200 // -----------------------------------------------------------------------------
       
  2201 //
       
  2202 EXPORT_C TInt CPECallHandling::ForwardCallToAddress( TInt aIndex )
       
  2203     {
       
  2204     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::ForwardCallToAddress" );
       
  2205     CPESingleCall* callData;
       
  2206     TInt callIndex;
       
  2207     TInt errorCode( ECCPErrorNotAllowed );
       
  2208     callData = VoiceCallDataByState( EPEStateDialing, callIndex );  
       
  2209    
       
  2210     if ( NULL == callData )
       
  2211         {
       
  2212         callData = VoiceCallDataByState( EPEStateConnecting, callIndex );
       
  2213         }
       
  2214     
       
  2215     if ( NULL == callData )
       
  2216         {
       
  2217         callData = VoiceCallDataByState( EPEStateConnected, callIndex );
       
  2218         }
       
  2219 
       
  2220     if( callData )
       
  2221         { 
       
  2222         errorCode = callData->ForwardCallToAddress( aIndex );
       
  2223         }
       
  2224        
       
  2225     return errorCode;
       
  2226     }
       
  2227 
       
  2228 // -----------------------------------------------------------------------------
       
  2229 // CPECallHandling::SecureSpecified
       
  2230 // Returns the call secure specified status
       
  2231 // -----------------------------------------------------------------------------
       
  2232 //
       
  2233 TBool CPECallHandling::SecureSpecified( const TInt aCallId ) const
       
  2234     {
       
  2235     CPESingleCall* call = iCallArrayOwner->GetCallObject( aCallId );
       
  2236     
       
  2237     __ASSERT_DEBUG( call, Panic( EPEPanicIndexOutOfRange ) );  
       
  2238     TBool secureSpecified( ETrue );
       
  2239     if( call )
       
  2240         {
       
  2241         secureSpecified = call->SecureSpecified();
       
  2242         }
       
  2243 
       
  2244     TEFLOGSTRING3( 
       
  2245         KTAINT, 
       
  2246         "PE CPECallHandling::SecureSpecified securespecified:%d  aCallId:%d", 
       
  2247         secureSpecified, aCallId );
       
  2248 
       
  2249     return secureSpecified;
       
  2250     }
       
  2251 
       
  2252 // -----------------------------------------------------------------------------
       
  2253 // CPECallHandling::InitConferenceCall
       
  2254 // -----------------------------------------------------------------------------
       
  2255 //
       
  2256 void CPECallHandling::InitConferenceCall( MCCEConferenceCall& aConference )
       
  2257     {
       
  2258     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::InitConferenceCall start" );
       
  2259     if( iConferenceCall )
       
  2260         {
       
  2261         TEFLOGSTRING( KTAINT, "CALL CPECallHandling::InitConferenceCall already exist" );
       
  2262         delete iConferenceCall;
       
  2263         iConferenceCall = NULL;
       
  2264         }
       
  2265     
       
  2266     TRAPD( error, ( iConferenceCall = CPEConferenceCall::NewL( *this, aConference ) ) );
       
  2267     if( error != KErrNone )
       
  2268         {
       
  2269         SendMessage( MEngineMonitor::EPEMessageConferenceErrorCurrentCallsToConference );
       
  2270         RPointerArray<MCCECall> callArray; 
       
  2271         TInt err = aConference.GetCallArray( callArray );
       
  2272         for( TInt index = 0 ; index < callArray.Count() ; index++ )
       
  2273             {
       
  2274             TRAP_IGNORE( aConference.RemoveCallL( *callArray[index] ) );
       
  2275             }
       
  2276         aConference.Release();
       
  2277         callArray.Close();
       
  2278         TEFLOGSTRING( KTAERROR, "CALL CPECallHandling::InitConferenceCall FAIL" );
       
  2279         }
       
  2280     else
       
  2281         {
       
  2282         iConferenceCall->SetCallId( KPEConferenceCallID );
       
  2283                 
       
  2284         RPointerArray<MCCECall> callArray;
       
  2285         TInt err = aConference.GetCallArray( callArray );
       
  2286         
       
  2287         if( err == KErrNone && callArray.Count() >= 2 )
       
  2288             {
       
  2289             InitialiseConferenceCallInfo( *callArray[0], *callArray[1] );
       
  2290             iConferenceCall->CallStateChanged( MCCEConferenceCallObserver::ECCEConferenceActive );
       
  2291             }
       
  2292         callArray.Close();
       
  2293         }    
       
  2294     
       
  2295     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::InitConferenceCall end" );
       
  2296     }
       
  2297 
       
  2298 // -----------------------------------------------------------------------------
       
  2299 // CPECallHandling::CallOwner
       
  2300 // -----------------------------------------------------------------------------
       
  2301 //
       
  2302 EXPORT_C MPECallOwner& CPECallHandling::CallOwner() const
       
  2303     {
       
  2304     return *iCallArrayOwner;
       
  2305     }
       
  2306 
       
  2307 // -----------------------------------------------------------------------------
       
  2308 // CPECallHandling::InitialiseConferenceCallInfo
       
  2309 // -----------------------------------------------------------------------------
       
  2310 //
       
  2311 void CPECallHandling::InitialiseConferenceCallInfo( 
       
  2312     MCCECall& aCall1, 
       
  2313     MCCECall& aCall2 )
       
  2314     {
       
  2315     TTimeIntervalSeconds call1Duration, call2Duration;
       
  2316     call1Duration = aCall1.CallDuration();
       
  2317     call2Duration = aCall2.CallDuration();
       
  2318     
       
  2319     // Set conference call duration to match the longest running call.
       
  2320     // If this is not done, zero call duration is shown in case the
       
  2321     // conference call fails or user rejects it instantly
       
  2322     // --- See CPEGsmMessageHandler::HandleConferenceIdleState how
       
  2323     // the duration is handled in these scenarios.
       
  2324     if ( call1Duration > call2Duration )
       
  2325        {
       
  2326        iModel.DataStore()->SetCallDuration( call1Duration.Int(), KPEConferenceCallID );
       
  2327        }
       
  2328     else
       
  2329        {
       
  2330        iModel.DataStore()->SetCallDuration( call2Duration.Int(), KPEConferenceCallID );
       
  2331        }
       
  2332        
       
  2333     if ( aCall1.Parameters().CallType()  
       
  2334         == CCPCall::ECallTypeCSVoice )
       
  2335        {
       
  2336        iModel.DataStore()->SetCallType( EPECallTypeCSVoice, KPEConferenceCallID );
       
  2337        }
       
  2338     else if ( aCall1.Parameters().CallType()  
       
  2339         == CCPCall::ECallTypePS )
       
  2340        {
       
  2341        iModel.DataStore()->SetCallType( EPECallTypeVoIP, KPEConferenceCallID );
       
  2342        }
       
  2343     
       
  2344     __ASSERT_DEBUG( aCall1.ServiceId() == aCall2.ServiceId(), 
       
  2345         Panic( EPEPanicInvalidParameter ) );
       
  2346     iModel.DataStore()->SetServiceId( KPEConferenceCallID, aCall1.ServiceId() );
       
  2347     }
       
  2348     
       
  2349 // -----------------------------------------------------------------------------
       
  2350 // CPECallHandling::HandleAutoResume
       
  2351 // -----------------------------------------------------------------------------
       
  2352 //
       
  2353 void CPECallHandling::HandleAutoResume()
       
  2354     {
       
  2355     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::HandleAutoResume" );
       
  2356     if ( iConferenceCall && ( iConferenceCall->GetCallState() == EPEStateHeldConference ) )
       
  2357         {
       
  2358         // Check that no conference + single case
       
  2359         CPESingleCall* callData = iCallArrayOwner->CallPointerByState( EPEStateConnected );
       
  2360         if( !callData && iModel.DataStore()->ResumeHeldCall( KPEConferenceCallID ))
       
  2361             {
       
  2362             TEFLOGSTRING( KTAINT, "CALL CPECallHandling::HandleAutoResume conference" );
       
  2363             iConferenceCall->Swap();
       
  2364             }
       
  2365         }
       
  2366     else
       
  2367         {
       
  2368         CPESingleCall* callData = iCallArrayOwner->CallPointerByState( EPEStateHeld );
       
  2369         // Check that no actice and held call, if waiting call gets idle
       
  2370         CPESingleCall* connectedCallData = iCallArrayOwner->CallPointerByState( EPEStateConnected );
       
  2371         if( callData && ( iModel.DataStore()->ResumeHeldCall( callData->GetCallId() ) )
       
  2372                     && !connectedCallData )
       
  2373             {
       
  2374             TEFLOGSTRING( KTAINT, "CALL CPECallHandling::HandleAutoResume single" );
       
  2375             callData->Resume();
       
  2376             }
       
  2377         }
       
  2378     }
       
  2379 
       
  2380 // -----------------------------------------------------------------------------
       
  2381 // CPECallHandling::ReleaseCallObject
       
  2382 // -----------------------------------------------------------------------------
       
  2383 //
       
  2384 TInt CPECallHandling::ReleaseCallObject( const TInt aCallId  )
       
  2385     {
       
  2386     TInt error(KErrNone);
       
  2387     TEFLOGSTRING2( KTAINT, 
       
  2388             "CALL CPECallHandling::ReleaseCallObject ReleaseCallObject %d", aCallId );
       
  2389     error = iCallArrayOwner->DeleteCallObject( aCallId );
       
  2390     // Reset datastore to prevent invalid usage in next call
       
  2391     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::ReleaseCallObject, Reset CallInfo" );
       
  2392     iModel.DataStore()->ResetCallInfo( aCallId );
       
  2393     return error;
       
  2394     }
       
  2395 
       
  2396 // -----------------------------------------------------------------------------
       
  2397 // CPECallHandling::SetCallOrigin
       
  2398 // -----------------------------------------------------------------------------
       
  2399 //
       
  2400 void  CPECallHandling::SetCallOrigin( const TInt aCallId, const MCCECall& aCall ) const
       
  2401     {
       
  2402     TEFLOGSTRING( KTAINT, "CALL CPECallHandling::SetCallOrigin" );
       
  2403     
       
  2404     //ToDo: casting not needed when CCE API is fixed.
       
  2405     const CCCPCallParameters& parameters = aCall.Parameters();
       
  2406     CCPCall::TCallType callType = parameters.CallType();
       
  2407     if ( callType == CCPCall::ECallTypeCSVoice || callType == CCPCall::ECallTypeVideo )
       
  2408         {
       
  2409         const CCCECallParameters& params = static_cast<const CCCECallParameters&>( parameters );
       
  2410                                                     
       
  2411         if ( params.Origin() == CCCECallParameters::ECCECallOriginSAT )
       
  2412             {
       
  2413             iModel.DataStore()->SetCallOrigin( EPECallOriginSAT, aCallId );
       
  2414             iModel.DataStore()->SetRemoteName( params.AlphaId(), aCallId );
       
  2415             iModel.DataStore()->SetRemotePhoneNumber( KNullDesC(), aCallId );
       
  2416             }                 
       
  2417         }                
       
  2418     }
       
  2419 
       
  2420 
       
  2421 //  End of File