phoneengine/phonemodel/src/cpemessagehandler.cpp
changeset 0 5f000ab63145
child 1 838b0a10d15b
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     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:  Message handler
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "cpecenrepmonitor.h"
       
    20 #include "cpeclientcallrequestmonitor.h"
       
    21 #include "cpeclientcallrequestmonitor.h"
       
    22 #include "cpeclientcommandhandlermonitor.h"
       
    23 #include "cpeclientservices.h"
       
    24 #include "cpeexternaldatahandler.h"
       
    25 #include "cpemanualcallcontrolhandler.h"
       
    26 #include "cpemessagehandler.h"
       
    27 #include "cpeparseremergencynumberhandler.h"
       
    28 #include "cpeparsermanufacturerhandler.h"
       
    29 #include "cpeparsermischandler.h"
       
    30 #include "cpeparserphonenumberhandler.h"
       
    31 #include "cpeparsersimcontrolhandler.h"
       
    32 #include "cpeparsersscallhandler.h"
       
    33 #include "cpeparsersshandler.h"
       
    34 #include "cpeparservoipnumberhandler.h"
       
    35 #include "cpepcnparserprocedurehandler.h"
       
    36 #include "cpesimstatemonitor.h"
       
    37 #include "cpetimer.h"
       
    38 #include "mpephonemodelinternal.h"
       
    39 #include "mpeservicehandling.h"
       
    40 #include "cperemotepartyinfomediator.h"
       
    41 
       
    42 #include <apacmdln.h>
       
    43 #include <apgcli.h>
       
    44 #include <apgtask.h>
       
    45 #include <AudioPreference.h>
       
    46 #include <barsc.h> 
       
    47 #include <barsread.h>
       
    48 #include <bldvariant.hrh>
       
    49 #include <ccpdefs.h>
       
    50 #include <coreapplicationuisdomainpskeys.h>
       
    51 #include <cpeclientinformation.h>
       
    52 #include <cpegsmaudiodata.h>
       
    53 #include <CPhoneGsmHandlerContainer.h>
       
    54 #include <CPhoneGsmOptionContainerBase.h>
       
    55 #include <CPhoneGsmParserBase.h>
       
    56 #include <CPhoneGsmParserResult.h>
       
    57 #include <featmgr.h>
       
    58 #include <mccecall.h>
       
    59 #include <mpeaudiodata.h>
       
    60 #include <mpecallhandling.h>
       
    61 #include <mpecontacthandling.h>
       
    62 #include <mpedatastore.h>
       
    63 #include <mpeloghandling.h>
       
    64 #include <pathinfo.h>
       
    65 #include <pepanic.pan>
       
    66 #include <PhCltTypes.h>
       
    67 #include <PhoneGsmParser.h>
       
    68 #include <ProfileEngineDomainConstants.h>
       
    69 #include <talogger.h>
       
    70 #include <w32std.h>
       
    71 
       
    72 // EXTERNAL DATA STRUCTURES
       
    73 // None.
       
    74 
       
    75 // EXTERNAL FUNCTION PROTOTYPES  
       
    76 // None.
       
    77 
       
    78 // CONSTANTS
       
    79 // Prefix change off. See SettingsInternalCRKeys.h
       
    80 const TInt KPEPrefixChangeOff = 0;
       
    81 // Prefix change on. See SettingsInternalCRKeys.h
       
    82 const TInt KPEPrefixChangeOn = 1;
       
    83 // International prefix
       
    84 _LIT( KPEIntPrefix, "+" );
       
    85 // Japan prefix
       
    86 _LIT( KPEJapanPrefix, "+81" );
       
    87 // Zero prefix
       
    88 _LIT( KPEZeroPrefix, "0" );
       
    89 // Valid dtmf sting
       
    90 _LIT( KValidDtmfChars, "0123456789pw*+#" );
       
    91 
       
    92 // Timeout for automatic answer. 
       
    93 const TInt KPEAutomaticAnswerTimeOut = 5000000;
       
    94 
       
    95 _LIT( KPEClirSuppress, "*31#" );
       
    96 _LIT( KPEClirInvoke, "#31#" );
       
    97 
       
    98 const TInt KPENumberPlus = '+';
       
    99 const TInt KPENumberHash = '#'; 
       
   100 const TInt KPENumberAsterisk = '*'; 
       
   101 
       
   102 // ============================ MEMBER FUNCTIONS ===============================
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CPEMessageHandler::NewL
       
   106 // Two-phased constructor.
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 CPEMessageHandler* CPEMessageHandler::NewL
       
   110         ( 
       
   111         MPEPhoneModelInternal& aModel,
       
   112         MPECallHandling& aCallHandling,
       
   113         MEngineMonitor& aEngineMonitor,
       
   114         CPEGsmAudioData& aAudioData,
       
   115         MPELogHandling& aLogHandling,
       
   116         MPEContactHandling& aContactHandling,
       
   117         CPESimStateMonitor& aSimStateMonitor,
       
   118         CPEExternalDataHandler& aGsmExternalDataHandler,
       
   119         MPEServiceHandling& aServiceHandling,
       
   120         RFs& aFsSession )
       
   121     {
       
   122     CPEMessageHandler* self = new ( ELeave ) CPEMessageHandler( 
       
   123         aModel, 
       
   124         aCallHandling, 
       
   125         aEngineMonitor, 
       
   126         aAudioData, 
       
   127         aLogHandling, 
       
   128         aContactHandling, 
       
   129         aSimStateMonitor,
       
   130         aGsmExternalDataHandler,
       
   131         aServiceHandling,
       
   132         aFsSession );
       
   133     CleanupStack::PushL( self );
       
   134     self->ConstructL();
       
   135     CleanupStack::Pop( self );
       
   136     return self;
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CPEMessageHandler::CPEMessageHandler
       
   141 // C++ default constructor can NOT contain any code, that
       
   142 // might leave.
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 CPEMessageHandler::CPEMessageHandler( 
       
   146         MPEPhoneModelInternal& aModel,                 // The model of the phone object which owns this object
       
   147         MPECallHandling& aCallHandling,              // The reference parameter of the phone data object which is used to create call handling request
       
   148         MEngineMonitor& aEngineMonitor,        // The reference parameter of the engine monitor object which is used to communication with phone application
       
   149         CPEGsmAudioData& aAudioData,              // The reference parameter of the audio data object which is used to handle audio requests
       
   150         MPELogHandling& aLogHandling,                // The reference parameter of the logs data object which is used to handle log requests   
       
   151         MPEContactHandling& aContactHandling,          // The reference parameter of the contact data object which is used to handle contact requests
       
   152         CPESimStateMonitor& aSimStateMonitor,
       
   153         CPEExternalDataHandler& aExternalDataHandler, // The reference parameter of external data handler object
       
   154         MPEServiceHandling& aServiceHandling,
       
   155         RFs& aFsSession )                // The reference parameter of CustomAPI
       
   156         : iModel( aModel ), 
       
   157             iCallHandling( aCallHandling ),
       
   158             iEngineMonitor( aEngineMonitor ),
       
   159             iGsmAudioData( aAudioData ),
       
   160             iLogHandling( aLogHandling ),
       
   161             iContactHandling( aContactHandling ),
       
   162             iExternalDataHandler( aExternalDataHandler ),
       
   163             iSimStateMonitor( aSimStateMonitor ),
       
   164             iFsSession( aFsSession ),
       
   165             iServiceHandling( aServiceHandling ),
       
   166             iDataStore( *aModel.DataStore() )
       
   167     {
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CPEMessageHandler::BaseConstructL
       
   172 // Performs base construction of the object.
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 void CPEMessageHandler::ConstructL()
       
   176     {
       
   177     iClientInformation = CPEClientInformation::NewL();
       
   178 
       
   179     iParser = PhoneGsmParser::CreateParserL();
       
   180     iOptions = PhoneGsmParser::CreateOptionContainerL();
       
   181     iManualCallControlHandler = CPEManualCallControlHandler::NewL( iCallHandling, *this, iDataStore );
       
   182     iClientServices = CPEClientServices::NewL( iModel, *this, iCallHandling, *iManualCallControlHandler );
       
   183     iParserHandlerContainer = CPhoneGsmHandlerContainer::NewL();
       
   184 
       
   185     // NOTE: The handler objects will break some CleanUpStack usage rules:
       
   186     // CPEMessageHandler class construct handler objects but ownership will be 
       
   187     // transfered to Handler Container. And therefore CleanUpStack will be 
       
   188     // used to member object because if iParserHandlerContainer->AddHandlerL 
       
   189     // leaves CPEMessageHandler don't delete handler object hence CleanUpStack
       
   190     // must delete handler object. 
       
   191 
       
   192     // Handles manufacturer specific codes from the parser.
       
   193     CPEParserManufacturerHandler* manufacturerHandler = 
       
   194         new ( ELeave ) CPEParserManufacturerHandler( iModel, iCallHandling, iFsSession );
       
   195     CleanupStack::PushL( manufacturerHandler );
       
   196     iParserHandlerContainer->AddHandlerL( *manufacturerHandler ); // ownership will be transfered to Handler Container.
       
   197     CleanupStack::Pop( manufacturerHandler );
       
   198 
       
   199     // Handles misc codes from the parser.
       
   200     CPEParserMiscHandler* miscHandler = new ( ELeave ) CPEParserMiscHandler( 
       
   201         *this, 
       
   202         iCallHandling );
       
   203     CleanupStack::PushL( miscHandler );
       
   204     iParserHandlerContainer->AddHandlerL( *miscHandler );// ownership will be transfered to Handler Container.
       
   205     CleanupStack::Pop( miscHandler );
       
   206 
       
   207     CPEParserPhoneNumberHandler* tempPhoneNumberHandler = 
       
   208         new ( ELeave ) CPEParserPhoneNumberHandler( *this, 
       
   209                                                        iCallHandling, 
       
   210                                                        iDataStore );
       
   211     CleanupStack::PushL( tempPhoneNumberHandler );
       
   212     iParserHandlerContainer->AddHandlerL( *tempPhoneNumberHandler ); // ownership will be transfered to Handler Container.
       
   213     CleanupStack::Pop( tempPhoneNumberHandler );
       
   214     iPhoneNumberHandler = tempPhoneNumberHandler;
       
   215 
       
   216     // Handles sim control procedures from the parser.
       
   217     CPEParserSimControlHandler* simControlHandler = CPEParserSimControlHandler::NewL( 
       
   218         iModel, 
       
   219         iContactHandling );
       
   220     CleanupStack::PushL( simControlHandler );
       
   221     iParserHandlerContainer->AddHandlerL( *simControlHandler );// ownership will be transfered to Handler Container.
       
   222     CleanupStack::Pop( simControlHandler );
       
   223 
       
   224     // Handles supplementary services during calls from the parser.
       
   225     CPEParserSSCallHandler* sSCallHandler = new ( ELeave ) CPEParserSSCallHandler( 
       
   226         *this, 
       
   227         iModel, 
       
   228         *iManualCallControlHandler );
       
   229     CleanupStack::PushL( sSCallHandler );
       
   230     iParserHandlerContainer->AddHandlerL( *sSCallHandler );// ownership will be transfered to Handler Container.
       
   231     CleanupStack::Pop( sSCallHandler );
       
   232 
       
   233     iSSHandler = CPEParserSSHandler::NewL( *this, iModel ); 
       
   234     iParserHandlerContainer->AddHandlerL( *iSSHandler );// ownership will be transfered to Handler Container.
       
   235 
       
   236     // Handles pcn service requests from the parser.
       
   237     CPEPcnParserProcedureHandler* pcnProcedureHandler = CPEPcnParserProcedureHandler::NewL( 
       
   238         *this, 
       
   239         iModel ); 
       
   240     CleanupStack::PushL( pcnProcedureHandler );
       
   241     iParserHandlerContainer->AddHandlerL( *pcnProcedureHandler );// ownership will be transfered to Handler Container.
       
   242     CleanupStack::Pop( pcnProcedureHandler );
       
   243     
       
   244     // Handles emergency phone number
       
   245     CPEParserEmergencyNumberHandler* tempEmergencyNumberHandler 
       
   246         = new ( ELeave ) CPEParserEmergencyNumberHandler( *this, 
       
   247                                                           iCallHandling, 
       
   248                                                           iDataStore );
       
   249     CleanupStack::PushL( tempEmergencyNumberHandler );
       
   250     iParserHandlerContainer->AddHandlerL( *tempEmergencyNumberHandler ); // ownership will be transfered to Handler Container.
       
   251     CleanupStack::Pop( tempEmergencyNumberHandler );
       
   252     iEmergencyNumberHandler = tempEmergencyNumberHandler;
       
   253 
       
   254     CPEParserVoipNumberHandler* tempVoipNumberHandler
       
   255         = CPEParserVoipNumberHandler::NewLC( *this, 
       
   256                                                iCallHandling, 
       
   257                                                iServiceHandling,
       
   258                                                iDataStore );
       
   259 
       
   260     iParserHandlerContainer->AddHandlerL( *tempVoipNumberHandler ); // ownership will be transfered to Handler Container.
       
   261     CleanupStack::Pop( tempVoipNumberHandler );
       
   262     iVoipNumberHandler = tempVoipNumberHandler;
       
   263     
       
   264     iAutomaticAnswerTimer = CPETimer::NewL( iModel );
       
   265  
       
   266     // Reserve needed callinfo and remoteinfo from heap.
       
   267     iCallInfo = new ( ELeave ) RMobileCall::TMobileCallInfoV3;
       
   268     
       
   269     iResult = PhoneGsmParser::CreateResultL();
       
   270     }
       
   271         
       
   272 // Destructor
       
   273 CPEMessageHandler::~CPEMessageHandler()
       
   274     {
       
   275     delete iClientInformation;
       
   276     delete iAsyncCallBack;
       
   277     delete iCallInfo;
       
   278     delete iAutomaticAnswerTimer;
       
   279     delete iParserHandlerContainer;
       
   280     delete iClientServices;
       
   281     delete iManualCallControlHandler;
       
   282     delete iOptions;
       
   283     delete iParser;
       
   284     delete iResult;
       
   285     }
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // CPEMessageHandler::HandleAnswerCall
       
   289 // Handles answer message from phone application. Method calls AnswerCall 
       
   290 // method from the CallHandling subsystem.
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 TInt CPEMessageHandler::HandleAnswerCall(
       
   294         const TBool aAutomaticAnswer ) // Informs is this automatic answer or not
       
   295     {
       
   296     // Stop DTMF sending and empty buffers if answer was requested in the
       
   297     // middle of DTMF sequence.
       
   298     StopDtmfSending();
       
   299     
       
   300     //Check if this is automatic answer and play redialCompletedTone (confusing naming)
       
   301     if( !aAutomaticAnswer )
       
   302         {
       
   303         iAutomaticAnswerTimer->Cancel();
       
   304         }
       
   305 
       
   306     return iCallHandling.AnswerCall();
       
   307     }
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CPEMessageHandler::HandleAudioRouting
       
   311 // Handles accessory mode changed message from AudioHandling subsystem. Method 
       
   312 // fecths accessory mode from AudioHandling subsystem and method sets new accessory
       
   313 // mode value to the CPEEngineInfo class. Method finds previously used volume
       
   314 // values for accessory and changes volume accordingly.
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 TInt CPEMessageHandler::HandleAudioRouting( TBool aVideoCall, TInt aCallId )
       
   318     {
       
   319     TInt error( ECCPErrorNone );
       
   320     
       
   321     if ( aCallId == KPEEmergencyCallId )     
       
   322          {
       
   323          error = iGsmAudioData.HandleEnergencyCallStarting();
       
   324          }
       
   325      else
       
   326          {
       
   327          error = iGsmAudioData.HandleCallStarting( aVideoCall );
       
   328          }
       
   329     
       
   330     return error;
       
   331     }
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // CPEMessageHandler::HandleRoutePreferenceChanged
       
   335 // Handles route preference changed message from AudioHandling subsystem. 
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 TInt CPEMessageHandler::HandleRoutePreferenceChanged()
       
   339     {
       
   340     TInt error( ECCPErrorNone );
       
   341     
       
   342     TEFLOGSTRING( KTAMESINT, "PE CPEMessageHandler::HandleRoutePreferenceChanged()" );
       
   343     
       
   344     error = iGsmAudioData.CallAudioRoutePreferenceChanged();
       
   345      
       
   346     return error;
       
   347     }    
       
   348 // -----------------------------------------------------------------------------
       
   349 // CPEMessageHandler::HandleContinueDtmfSending
       
   350 // Handles continue dtmf sending after 'w' character in the dtmf string
       
   351 // Method calls ContinueDtmfSending or StopDtmfSending method from the 
       
   352 // CallHandling subsystem.
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 void CPEMessageHandler::HandleContinueDtmfSending( 
       
   356         const TBool aContinue )
       
   357     {
       
   358     if ( aContinue )
       
   359         {
       
   360         HandleSendDtmf();
       
   361         }
       
   362     else
       
   363         {
       
   364         StopDtmfSending();
       
   365         }
       
   366     }
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // CPEMessageHandler::HandleReleaseAll
       
   370 // Handles release all message from phone application
       
   371 // Method calls ReleaseAll method from the CallHandling subsystem object..
       
   372 // -----------------------------------------------------------------------------
       
   373 //
       
   374 TInt CPEMessageHandler::HandleReleaseAll()
       
   375     {
       
   376     return iCallHandling.ReleaseAll();
       
   377     }
       
   378 
       
   379 // -----------------------------------------------------------------------------
       
   380 // CPEMessageHandler::HandleReleaseCall
       
   381 // Handles release message from phone application
       
   382 // Method fecths call id number from the CPEEngineInfo structure and then
       
   383 // Method calls HangUp method from the CallHandling subsystem.
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 TInt CPEMessageHandler::HandleReleaseCall( TPEHangUpOptions aAutoResumeOption )
       
   387     {
       
   388     TInt callId;
       
   389     TInt errorCode( ECCPErrorNone );
       
   390     callId = iDataStore.CallId();
       
   391     
       
   392     if ( CallIdCheck::IsVideo( callId ) )
       
   393         {
       
   394         //Video call
       
   395         iGsmAudioData.StopInbandTonePlay();
       
   396         errorCode = iCallHandling.HangUp( callId, ETPEHangUpNotResumeHeldCall );
       
   397         }
       
   398     else
       
   399         {
       
   400         errorCode = iCallHandling.HangUp( callId, aAutoResumeOption );
       
   401         }
       
   402     return errorCode;
       
   403     }
       
   404 
       
   405 // -----------------------------------------------------------------------------
       
   406 // CPEMessageHandler::HandleSendDtmf
       
   407 // Handles send dtmf message from phone application
       
   408 // Method fetches dtmf string from the CPEEngineInfo class and then
       
   409 // Method parses the DTMF string and then take action properly: 
       
   410 // hard pause: triggers sending MEngineMonitor::EPEMessageStoppedDTMF 
       
   411 //      to phone model
       
   412 // '+': triggers substitution speed dial digit with speed dial number. 
       
   413 //
       
   414 // Method calls SendDtmf method from the CallHandling subsystem.
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 TInt CPEMessageHandler::HandleSendDtmf()
       
   418     {
       
   419     TInt errorCode( ECCPErrorNone );
       
   420     TPEDtmfString dtmfString = iDataStore.DtmfStringCommand();
       
   421 
       
   422     RemoveInvalidChars( dtmfString, KPEClientValidChars, EFalse );
       
   423 
       
   424     if ( dtmfString.Length() == 0 )
       
   425         {
       
   426         iDataStore.SetDtmfString( KNullDesC() ); 
       
   427         errorCode = KErrArgument;
       
   428         }
       
   429     // Parse the first character of the string
       
   430     else if ( dtmfString[ 0 ] == KPEDtmfStopCharLowercase || 
       
   431               dtmfString[ 0 ] == KPEDtmfStopCharUppercase ) // hard pause
       
   432         {
       
   433         TEFLOGSTRING( KTAMESINT, "PE CPEMessageHandler::HandleSendDtmf(), Processing W" );
       
   434         // remove the hard pause char from the string
       
   435         iDataStore.SetDtmfString( dtmfString.Mid( 1 ) );
       
   436         iDataStore.SetDtmfStringCommand( dtmfString.Mid( 1 ) );
       
   437         
       
   438         // Send EPEMessageStoppedDTMF message asynchronic.
       
   439 
       
   440         TCallBack callBack( CallbackSendMessageStoppedDTMF, this );
       
   441         delete iAsyncCallBack;
       
   442         iAsyncCallBack = NULL;
       
   443         // Function does not allow to leave.
       
   444         iAsyncCallBack = new CAsyncCallBack( callBack, CActive::EPriorityHigh );
       
   445         if ( iAsyncCallBack )
       
   446             {
       
   447             iAsyncCallBack->CallBack();
       
   448             }
       
   449         else
       
   450             {
       
   451             iModel.SendMessage( MEngineMonitor::EPEMessageStoppedDTMF );
       
   452             }
       
   453         
       
   454         dtmfString = KNullDesC;
       
   455         }    
       
   456     else if ( dtmfString[ 0 ] == KPEDtmfPlusChar ) // speed-dial substitution
       
   457         {
       
   458         TEFLOGSTRING( KTAMESINT, "PE CPEMessageHandler::HandleSendDtmf(), Processing +" );
       
   459         HandlePlusSignInDtmf( dtmfString );
       
   460         dtmfString = KNullDesC;
       
   461         }
       
   462     else if ( dtmfString[ 0 ] == KPEDtmfPauseCharLowercase || 
       
   463               dtmfString[ 0 ] == KPEDtmfPauseCharUppercase ) // soft pause
       
   464         {
       
   465         TEFLOGSTRING( KTAMESINT, "PE CPEMessageHandler::HandleSendDtmf(), Processing P" );
       
   466         
       
   467         // store the full string for UI to display 
       
   468         iDataStore.SetDtmfString( dtmfString );
       
   469 
       
   470         if ( dtmfString.Length() > 1 )
       
   471             {
       
   472             // store the remainder of the string to be processed later
       
   473             iDataStore.SetDtmfStringCommand( dtmfString.Mid( 1 ) ); 
       
   474             }
       
   475         else
       
   476             {
       
   477             // nothing left to process
       
   478             iDataStore.SetDtmfStringCommand( KNullDesC() );
       
   479             }
       
   480         // set the dtmf string to send 
       
   481         dtmfString = dtmfString.Left( 1 );
       
   482         }
       
   483     else 
       
   484         {
       
   485         // store the full string for UI to display 
       
   486         iDataStore.SetDtmfString( dtmfString );
       
   487         
       
   488         // Find the next stop point
       
   489         TInt stopPoint = ECCPErrorNotFound;
       
   490         TPtrC validDtmfStringStopChars( KPEValidDTMFStringStopChars );
       
   491         for ( TInt index = 0 ; index < dtmfString.Length(); index++ )
       
   492             {
       
   493             if ( validDtmfStringStopChars.Locate( dtmfString[index] ) != ECCPErrorNotFound )
       
   494                 {
       
   495                 stopPoint = index;
       
   496                 break; 
       
   497                 }
       
   498             }
       
   499 
       
   500         if ( stopPoint != ECCPErrorNotFound ) 
       
   501             {
       
   502             // store the remainder of the string to be processed later
       
   503             iDataStore.SetDtmfStringCommand( dtmfString.Mid( stopPoint ) ); 
       
   504             // set the dtmf string to send 
       
   505             dtmfString = dtmfString.Left( stopPoint );            
       
   506             }
       
   507         else
       
   508             {
       
   509             // nothing left to process
       
   510             iDataStore.SetDtmfStringCommand( KNullDesC() );
       
   511             }
       
   512         }
       
   513 
       
   514     if ( dtmfString.Length() )  
       
   515         {
       
   516         TEFLOGSTRING2( KTAMESINT, "PE CPEMessageHandler::HandleSendDtmf(), Starting to play %S", &dtmfString );
       
   517         // send the dtmf string to call handling subsystem
       
   518         errorCode = iCallHandling.SendDtmf( dtmfString );
       
   519         }
       
   520     return errorCode;
       
   521     }
       
   522 
       
   523 // -----------------------------------------------------------------------------
       
   524 // CPEMessageHandler::CallBackHandleSendDtmf
       
   525 // Asyncronous callback for HandleSendDtmf() function.
       
   526 // -----------------------------------------------------------------------------
       
   527 //
       
   528 TInt CPEMessageHandler::CallBackHandleSendDtmf( TAny* aAny )
       
   529     {
       
   530     __ASSERT_ALWAYS( aAny , Panic( EPEPanicNullPointer ) );
       
   531     CPEMessageHandler* self = static_cast<CPEMessageHandler*>(aAny);
       
   532 
       
   533     delete self->iAsyncCallBack;
       
   534     self->iAsyncCallBack = NULL;
       
   535     return self->HandleSendDtmf();  
       
   536     }
       
   537 
       
   538 // -----------------------------------------------------------------------------
       
   539 // CPEMessageHandler::HandlePlusSignInDtmf
       
   540 // Handles plus (+) sign in a DTMF string.
       
   541 // -----------------------------------------------------------------------------
       
   542 //
       
   543 void CPEMessageHandler::HandlePlusSignInDtmf(const TPEDtmfString& aDtmfString )
       
   544     {
       
   545     TEFLOGSTRING2( KTAMESINT, "PE CPEMessageHandler::HandlePlusSignInDtmf(), aDtmfString: %S", &aDtmfString ); 
       
   546           
       
   547     // Find the SD index after the plus sign
       
   548     TPtrC validManualDTMFChars( KPEValidSpeedDialChars );
       
   549     TInt index = ECCPErrorNotFound;
       
   550     for ( index = 1 ; index < aDtmfString.Length() ; index++ )
       
   551         {
       
   552         if ( validManualDTMFChars.Locate( aDtmfString[index] ) == ECCPErrorNotFound )
       
   553             {
       
   554             TEFLOGSTRING( KTAMESINT, "PE CPEMessageHandler::HandlePlusSignInDtmf(), Not Found" ); 
       
   555             break; 
       
   556             }
       
   557         }
       
   558     TPESpeedDialSubstituionStatus sdStatus = EPEDtmfSpeedDialOk;
       
   559     
       
   560     // Empty string after the plus sign
       
   561     if ( index == 1 )
       
   562         {
       
   563         if ( aDtmfString.Length() > 1 )
       
   564             {
       
   565             // pw+ after the plus sign.
       
   566             sdStatus = EPEDtmfSpeedDialInvalidSpeedDial;
       
   567             }
       
   568         else
       
   569             {
       
   570             // string ended with the plus sign.
       
   571             sdStatus = EPEDtmfSpeedDialPromptUser;
       
   572             }
       
   573         // Clear DTMF string.
       
   574         iDataStore.SetDtmfString( KNullDesC() );
       
   575         }
       
   576     // Else if the SD location ends the DTMF string, move the index to the
       
   577     // last character instead of one over.
       
   578     else if ( index == aDtmfString.Length() )
       
   579         {
       
   580         index--;
       
   581         }
       
   582     
       
   583     // Check that the index is valid
       
   584     TInt sdIndex = ECCPErrorNotFound; 
       
   585     if ( sdStatus == EPEDtmfSpeedDialOk )
       
   586         {
       
   587         TLex lexer( aDtmfString.Mid( 1, index ) );
       
   588         // convert it to a number
       
   589         if ( lexer.Val(sdIndex) == ECCPErrorNone )
       
   590             {
       
   591             // Is it out of range
       
   592             if ( sdIndex < KPESpeedDialIndexMin  ||
       
   593                 sdIndex > KPESpeedDialIndexMax )
       
   594                 {
       
   595                 sdStatus = EPEDtmfSpeedDialInvalidSpeedDial;
       
   596                 }
       
   597             }
       
   598         else
       
   599             {
       
   600             sdStatus = EPEDtmfSpeedDialInvalidSpeedDial;
       
   601             }
       
   602         }
       
   603     
       
   604     // Fetch the SD location
       
   605     TPEPhoneNumber speedDialLocationString;
       
   606     if ( sdStatus == EPEDtmfSpeedDialOk )
       
   607         {
       
   608         TEFLOGSTRING2( KTAMESINT, "PE CPEMessageHandler::HandlePlusSignInDtmf(), SD location %i", sdIndex ); 
       
   609         if ( iContactHandling.GetSpeedDialLocation( 
       
   610             sdIndex, speedDialLocationString ) == ECCPErrorNone )
       
   611             {
       
   612             // Is content found
       
   613             if ( speedDialLocationString.Length() == 0)
       
   614                 {
       
   615                 sdStatus = EPEDtmfSpeedDialNotAssigned;
       
   616                 }
       
   617             else if ( speedDialLocationString[0] == KPEDtmfPlusChar)  
       
   618                 {
       
   619                 // plus char must be removed from dtmf string before sending
       
   620                 RemovePlusPrefix( speedDialLocationString );
       
   621                 }
       
   622             }
       
   623         else
       
   624             {
       
   625             sdStatus = EPEDtmfSpeedDialInvalidSpeedDial;
       
   626             }
       
   627         }
       
   628     
       
   629     // Now interpret the sdStatus to the next action
       
   630     switch ( sdStatus )
       
   631         {
       
   632         case EPEDtmfSpeedDialOk:
       
   633             {
       
   634             TEFLOGSTRING2( KTAMESINT, "PE CPEMessageHandler::HandlePlusSignInDtmf(), SD result: %S", &speedDialLocationString ); 
       
   635             // Take the SD location string and use that as new DTMF string
       
   636             iDataStore.SetDtmfStringCommand( speedDialLocationString );
       
   637             
       
   638             // Do recursion asyncronously                        
       
   639             TCallBack callBack( CallBackHandleSendDtmf, this );
       
   640             delete iAsyncCallBack;
       
   641             iAsyncCallBack = NULL;
       
   642             // Function does not allow to leave.
       
   643             iAsyncCallBack = new CAsyncCallBack( callBack, CActive::EPriorityStandard );
       
   644             if ( iAsyncCallBack )
       
   645                 {
       
   646                 iAsyncCallBack->CallBack();
       
   647                 }
       
   648             else
       
   649                 {
       
   650                 iModel.SendMessage( MEngineMonitor::EPEMessageDTMFSendingAborted );
       
   651                 }
       
   652             }
       
   653             break;
       
   654         case EPEDtmfSpeedDialPromptUser:
       
   655             // Speed dial location not given.
       
   656             iDataStore.SetDtmfString( KNullDesC() );
       
   657             iModel.SendMessage( MEngineMonitor::EPEMessagePromptSpeedDial );
       
   658             break;
       
   659         case EPEDtmfSpeedDialNotAssigned:
       
   660             // Speed dial location valid but not assigned
       
   661             iDataStore.SetDtmfString( KNullDesC() );
       
   662             iDataStore.SetDtmfStringCommand( KNullDesC() );
       
   663             iModel.SendMessage( MEngineMonitor::EPEMessageDTMFSendingAborted);
       
   664             iModel.SendMessage( MEngineMonitor::EPEMessageSpeedDialNotAssigned );
       
   665             break;
       
   666         case EPEDtmfSpeedDialInvalidSpeedDial:
       
   667             // Speed dial location invalid
       
   668             iDataStore.SetDtmfString( KNullDesC() );
       
   669             iDataStore.SetDtmfStringCommand( KNullDesC() );
       
   670             iModel.SendMessage( MEngineMonitor::EPEMessageDTMFSendingAborted);
       
   671             iModel.SendMessage( MEngineMonitor::EPEMessageInvalidSpeedDial );
       
   672             break;
       
   673         default:
       
   674             Panic( EPEPanicInvalidState );
       
   675             break;
       
   676         } // end switch
       
   677     }
       
   678 
       
   679 // -----------------------------------------------------------------------------
       
   680 // CPEMessageHandler::CheckPrefix
       
   681 // Checks the status of phone number prefix change setting
       
   682 // and calls CPEMessageHandler::ChangePrefix for execution.
       
   683 // If error occurs the phone number is left untouched
       
   684 // -----------------------------------------------------------------------------
       
   685 //
       
   686 void CPEMessageHandler::CheckPrefix()
       
   687     {
       
   688     TInt err = ECCPErrorNone;
       
   689     TBool checkPrefix = 
       
   690         FeatureManager::FeatureSupported( KFeatureIdJapanPrefixChange );
       
   691 
       
   692     if ( checkPrefix )
       
   693         {
       
   694         TInt prefixMode = KPEPrefixChangeOff; // Default is "off"
       
   695 
       
   696         err = iExternalDataHandler.Get(
       
   697             EPEDialPrefixChangeSetting,
       
   698             prefixMode );
       
   699 
       
   700         if ( !err )
       
   701             {
       
   702             if ( prefixMode == KPEPrefixChangeOn )
       
   703                 {
       
   704                 TPEPrefixText prefixText;
       
   705                 
       
   706                 err = iExternalDataHandler.GetText(
       
   707                     EPEDialPrefixTextSetting,
       
   708                     prefixText );
       
   709 
       
   710                 if ( !err )
       
   711                     {
       
   712                     err = ChangePrefix( prefixText );
       
   713                     }
       
   714                 }
       
   715             }
       
   716         }
       
   717     }
       
   718 
       
   719 // -----------------------------------------------------------------------------
       
   720 // CPEMessageHandler::ChangePrefix
       
   721 // Executes phone number prefix change.
       
   722 // -----------------------------------------------------------------------------
       
   723 //
       
   724 TInt CPEMessageHandler::ChangePrefix(
       
   725     const TPEPrefixText& aPrefixText )
       
   726     {
       
   727     TInt err = ECCPErrorNone;
       
   728 
       
   729     const TInt beginning = 0; // The beginning for replacement.
       
   730     TInt replaceLength = 0; // The string length to be replaced.
       
   731     TInt location = ECCPErrorNotFound; // The location of searched string.
       
   732     TPEPhoneNumber phoneNumber = iDataStore.PhoneNumber();
       
   733 
       
   734     // Try to find Japan prefix.
       
   735     location = phoneNumber.Find( KPEJapanPrefix );
       
   736     if ( location == beginning )
       
   737         {
       
   738         // The string was found, so make replacement. 
       
   739         // Safe because KPEZeroPrefix < KPEJapanPrefix.
       
   740         replaceLength = KPEJapanPrefix().Length();
       
   741         phoneNumber.Replace( beginning, replaceLength, KPEZeroPrefix );
       
   742         }
       
   743     else
       
   744         {
       
   745         // Try to find international prefix.
       
   746         location = phoneNumber.Find( KPEIntPrefix );
       
   747         if ( location == beginning )
       
   748             {
       
   749             replaceLength = KPEIntPrefix().Length();
       
   750             // The string was found, so try to make replacement. 
       
   751             const TInt phoneNumLength = phoneNumber.Length();
       
   752             const TInt prefixLength = aPrefixText.Length();
       
   753 
       
   754             TInt stringLength = 
       
   755                 ( phoneNumLength + prefixLength - replaceLength );
       
   756 
       
   757             if ( phoneNumber.MaxLength() >= stringLength )
       
   758                 {
       
   759                 // There is enough space to make this replace.
       
   760                 phoneNumber.Replace( beginning, replaceLength, aPrefixText );
       
   761                 }
       
   762             else
       
   763                 {
       
   764                 // There is no space to combine the strings, so inform it.
       
   765                 err = KErrOverflow;
       
   766                 }
       
   767             }
       
   768         }
       
   769 
       
   770     if ( err == ECCPErrorNone )
       
   771         {
       
   772         iDataStore.SetPhoneNumber( phoneNumber );
       
   773         }
       
   774 
       
   775     return err;
       
   776     }
       
   777 
       
   778 // -----------------------------------------------------------------------------
       
   779 // CPEMessageHandler::HandleDtmfSent
       
   780 // Handles DTMF sent message from the CallHandling subsystem.
       
   781 // -----------------------------------------------------------------------------
       
   782 //
       
   783 TInt CPEMessageHandler::HandleDtmfSent()
       
   784     {
       
   785     TInt errorCode( ECCPErrorNone );
       
   786 
       
   787     // check if there are still parts of the string left to process
       
   788     if ( iDataStore.DtmfStringCommand().Length() ) 
       
   789         {
       
   790         HandleSendDtmf();
       
   791         errorCode = KPEDontSendMessage;
       
   792         }
       
   793     else 
       
   794         {
       
   795         // dtmf sending complete
       
   796         iDataStore.SetDtmfString( KNullDesC() );
       
   797         }
       
   798     return errorCode;
       
   799     }
       
   800 
       
   801 // -----------------------------------------------------------------------------
       
   802 // CPEMessageHandler::StopPlayingDtmf
       
   803 // Stops/Cancels playing dtmf tones and string (audio feedback and network)
       
   804 // -----------------------------------------------------------------------------
       
   805 //
       
   806 void CPEMessageHandler::StopDtmfSending()
       
   807     {
       
   808     // cancel subtitution callback:
       
   809     if ( iAsyncCallBack )
       
   810         {
       
   811         iAsyncCallBack->Cancel();
       
   812         delete iAsyncCallBack;
       
   813         iAsyncCallBack = NULL;
       
   814         }
       
   815 
       
   816     iCallHandling.StopDtmfSending();
       
   817     
       
   818     iDataStore.SetDtmfString( KNullDesC() ); 
       
   819     iDataStore.SetDtmfStringCommand( KNullDesC() );
       
   820     }
       
   821 
       
   822 // -----------------------------------------------------------------------------
       
   823 // CPEMessageHandler::HandleSetAudioMute
       
   824 // Handles audio mute message from the phone application.
       
   825 // Method fecths mute value from the CPEEngineInfo and then
       
   826 // Method sets mute value to the AudioHandling subsystem.
       
   827 // (other items were commented in a header).
       
   828 // -----------------------------------------------------------------------------
       
   829 //
       
   830 void CPEMessageHandler::HandleSetAudioMute()
       
   831     {
       
   832     TEFLOGSTRING( KTAGENERAL, "PE: CPEMessageHandler::HandleSetAudioMute" );
       
   833     TBool mute = iDataStore.AudioMuteCommand();
       
   834     iGsmAudioData.SetAudioMuteSync( mute );
       
   835     }
       
   836 
       
   837 // -----------------------------------------------------------------------------
       
   838 // CPEMessageHandler::HandleSetAudioOutput
       
   839 // Handles audio output from the phone application.
       
   840 // Method fecths output and note values from the CPEEngineInfo and then
       
   841 // -----------------------------------------------------------------------------
       
   842 //
       
   843 TInt CPEMessageHandler::HandleSetAudioOutput()
       
   844     {
       
   845     TEFLOGSTRING( KTAGENERAL, "PE: CPEMessageHandler::HandleSetAudioOutput" );
       
   846     return iGsmAudioData.SetAudioOutput( iDataStore.AudioOutputCommand(),
       
   847                                       iDataStore.ShowNoteCommand() );
       
   848     }
       
   849 
       
   850 // -----------------------------------------------------------------------------
       
   851 // CPEMessageHandler::HandleSetAudioVolume
       
   852 // Handles change volume message from the phone application.
       
   853 // Method fecths volume value from the CPEEngineInfo and then
       
   854 // Method sets volume value to the AudioHandling subsystem.
       
   855 // -----------------------------------------------------------------------------
       
   856 //
       
   857 void CPEMessageHandler::HandleSetAudioVolume()
       
   858     {    
       
   859     TInt volume = iDataStore.AudioVolumeCommand();
       
   860     TEFLOGSTRING2( KTAGENERAL, "PE: CPEMessageHandler::HandleSetAudioVolume %d", volume );
       
   861     iGsmAudioData.SetAudioVolumeSync( volume );
       
   862     }
       
   863 
       
   864 // -----------------------------------------------------------------------------
       
   865 // CPEMessageHandler::HandlePlayDTMFL
       
   866 // Handles key down event.
       
   867 // -----------------------------------------------------------------------------
       
   868 //
       
   869 void CPEMessageHandler::HandlePlayDTMFL()
       
   870     {
       
   871     ProcessPlayDTMFL();
       
   872     }
       
   873 
       
   874 // -----------------------------------------------------------------------------
       
   875 // CPEMessageHandler::HandleEndDTMF
       
   876 // Handles key up event.
       
   877 // -----------------------------------------------------------------------------
       
   878 //
       
   879 TInt CPEMessageHandler::HandleEndDTMF()
       
   880     {
       
   881     return ProcessEndDTMF();
       
   882     }
       
   883     
       
   884 // -----------------------------------------------------------------------------
       
   885 // CPEMessageHandler::SetClientInformation
       
   886 // Sets client information.
       
   887 // -----------------------------------------------------------------------------
       
   888 // 
       
   889 void CPEMessageHandler::SetClientInformation(
       
   890         const TInt aCallId,  
       
   891         const TDesC& aMainPartOfPhoneNumber ) 
       
   892     {
       
   893     // Other ClientInformation it was already set before, in SetClientData
       
   894     // method. Methods is called from HandleClientCallDataL before CallId is known.
       
   895     iClientInformation->SetNumber( aMainPartOfPhoneNumber );
       
   896     
       
   897     iDataStore.SetCallClientInformation( *iClientInformation, aCallId );
       
   898     
       
   899     const TPECallOrigin& origin = iDataStore.CallOriginCommand();    
       
   900     iDataStore.SetCallOrigin( origin, aCallId );    
       
   901     }
       
   902  
       
   903 // -----------------------------------------------------------------------------
       
   904 // CPEMessageHandler::SetClientData
       
   905 // Sets client dial data to member variable.
       
   906 // -----------------------------------------------------------------------------
       
   907 // 
       
   908 void CPEMessageHandler::SetClientData(
       
   909         const CPhCltDialData& aClientDialData ) 
       
   910     {
       
   911     CCCECallParameters& params = iDataStore.CallParameters();
       
   912     
       
   913     iClientDialData = &const_cast<CPhCltDialData&>( aClientDialData );
       
   914 
       
   915     iClientInformation->SetName( iClientDialData->Name() );
       
   916     
       
   917     if ( iClientDialData->CallType() == EPhCltVideo || 
       
   918         iClientDialData->CallType() == EPhCltForcedVideo )
       
   919         {
       
   920         iClientInformation->SetCallType( EPECallTypeVideo );
       
   921         iDataStore.SetCallTypeCommand( EPECallTypeVideo );
       
   922         params.SetCallType( CCPCall::ECallTypeVideo );
       
   923         }
       
   924     else if ( iClientDialData->CallType() == EPhCltCallVoIP )
       
   925         {
       
   926         iClientInformation->SetCallType( EPECallTypeVoIP );
       
   927         iDataStore.SetCallTypeCommand( EPECallTypeVoIP );        
       
   928         params.SetCallType( CCPCall::ECallTypePS );
       
   929         }
       
   930     else
       
   931         {
       
   932         iClientInformation->SetCallType( EPECallTypeCSVoice );
       
   933         iDataStore.SetCallTypeCommand( EPECallTypeCSVoice );
       
   934         params.SetCallType( CCPCall::ECallTypeCSVoice );
       
   935         }
       
   936       
       
   937     iClientInformation->SetEndOtherCalls( iClientDialData->EndOtherCalls() );
       
   938     
       
   939     iClientInformation->SetAllowMatch( iClientDialData->AllowMatch() );
       
   940     
       
   941     iClientInformation->SetContactLink( iClientDialData->ContactLink() );
       
   942    
       
   943     iClientInformation->SetShowNumber( iClientDialData->ShowNumber() );
       
   944 
       
   945     // Not accept 0, TODO Requirement clarification needed, 
       
   946     // does service id 0 need special handling!
       
   947     if ( iClientDialData->ServiceId() != 0 )
       
   948         {
       
   949         iDataStore.SetServiceIdCommand( iClientDialData->ServiceId() );
       
   950         params.SetServiceId( iClientDialData->ServiceId() );
       
   951         }
       
   952         
       
   953     iDataStore.SetUserToUserInformation( iClientDialData->UUI() );
       
   954     
       
   955     params.SetBearer( iClientDialData->Bearer() );
       
   956     params.SetSubAddress( iClientDialData->SubAddress() );
       
   957     
       
   958     if ( iClientDialData->SATCall() )
       
   959         {
       
   960         params.SetOrigin( CCCECallParameters::ECCECallOriginSAT );
       
   961         }
       
   962     else
       
   963         {
       
   964         params.SetOrigin( CCCECallParameters::ECCECallOriginPhone );
       
   965         }
       
   966     }
       
   967      
       
   968 // -----------------------------------------------------------------------------
       
   969 // CPEMessageHandler::HandleTerminateAllConnections
       
   970 // Method resets redial timer if active and calls TerminateAllConnection 
       
   971 // method from the CallHandling subsytem object.
       
   972 // -----------------------------------------------------------------------------
       
   973 //
       
   974 TInt CPEMessageHandler::HandleTerminateAllConnections()
       
   975     {
       
   976     TInt errorCode( ECCPErrorNone );
       
   977     errorCode = iCallHandling.TerminateAllConnections();
       
   978     TEFLOGSTRING2( 
       
   979         KTAGENERAL, 
       
   980         "PE: CPEMessageHandler::HandleTerminateAllConnections: Callhandling::TerminateAllConnections() called, Error code: %d", 
       
   981         errorCode );
       
   982 
       
   983     return errorCode;
       
   984     }
       
   985 
       
   986 // -----------------------------------------------------------------------------
       
   987 // CPEMessageHandler::IsItCharThatCanDelete
       
   988 // Checks if character can be delete. If given charter can be located from 
       
   989 // KPECharsThatCanBeDelete, method returns ETrue else EFalse.
       
   990 // -----------------------------------------------------------------------------
       
   991 //
       
   992 TBool CPEMessageHandler::IsItCharThatCanDelete( 
       
   993         const TChar& aChar ) const
       
   994     {
       
   995     TPtrC Invalid( KPECharsThatCanBeDelete );
       
   996 
       
   997     return Invalid.Locate( aChar ) != ECCPErrorNotFound;
       
   998     }
       
   999 
       
  1000 // -----------------------------------------------------------------------------
       
  1001 // CPEMessageHandler::IsValidChar
       
  1002 // Checks if character is acceptable. If given charter can be located from 
       
  1003 // KPEClientValidChars, method returns ETrue else EFalse.
       
  1004 // -----------------------------------------------------------------------------
       
  1005 //
       
  1006 TBool CPEMessageHandler::IsValidChar( 
       
  1007         const TChar& aChar, //character to be checked
       
  1008         const TDesC& aValidChars ) const
       
  1009     {
       
  1010     return aValidChars.Locate( aChar ) != ECCPErrorNotFound;
       
  1011     }
       
  1012 
       
  1013 // -----------------------------------------------------------------------------
       
  1014 // CPEMessageHandler::RemoveInvalidChars
       
  1015 // Check all characters validity from descriptor one by one. 
       
  1016 //    (1) If chater is valid then OK and next charter... 
       
  1017 //    (2) If invalid check if that can be delete from string.
       
  1018 //    (3) If it can be delete then DELETE and next charter... 
       
  1019 //    (4) But if charter can NOT be delete then return value is EFalse.
       
  1020 // -----------------------------------------------------------------------------
       
  1021 //
       
  1022 TBool CPEMessageHandler::RemoveInvalidChars( 
       
  1023         TDes& aString, //string to be processed
       
  1024         const TDesC& aValidChars,
       
  1025         const TBool aCheckForDelete ) const
       
  1026     {
       
  1027     TBool returnValue = ETrue;
       
  1028     TInt index = aString.Length() - 1;
       
  1029 
       
  1030     TEFLOGSTRING2( KTAGENERAL, 
       
  1031         "PE: CPEMessageHandler::RemoveInvalidChars, String to parse = %S", &aString );
       
  1032 
       
  1033     for ( ; index >= 0; index-- )
       
  1034         {
       
  1035         if ( !IsValidChar( aString[ index ], aValidChars ) )//(1)
       
  1036             {
       
  1037             if ( !aCheckForDelete 
       
  1038                 || ( aCheckForDelete && IsItCharThatCanDelete( aString[index] ) ) )//(2)
       
  1039                 {
       
  1040                 aString.Delete( index, 1 ); // one character  //(3)
       
  1041                 }
       
  1042             else
       
  1043                 {
       
  1044                 returnValue = EFalse;//(4) //if String includes alphabets or other forbidden characters return TFalse
       
  1045                 }
       
  1046             }
       
  1047         }
       
  1048     if ( aCheckForDelete )
       
  1049         {
       
  1050         TLex input( aString );
       
  1051 
       
  1052         TLexMark start;
       
  1053         input.Mark( start );
       
  1054 
       
  1055         while ( input.Peek().IsDigit() ) 
       
  1056             {
       
  1057             input.Inc();
       
  1058             }
       
  1059 
       
  1060         TPtrC mainpart( input.MarkedToken( start ) );
       
  1061         if ( mainpart.Length() )
       
  1062             {
       
  1063             aString = mainpart;
       
  1064             }
       
  1065     
       
  1066         if ( input.Remainder().Length() > 0 )
       
  1067             {
       
  1068             TPEDtmfString dtmfString = input.Remainder();
       
  1069             iDataStore.SetDtmfStringCommand( dtmfString );
       
  1070             }
       
  1071         else
       
  1072             {
       
  1073             TPEDtmfString dtmfString( KNullDesC );
       
  1074             iDataStore.SetDtmfStringCommand( dtmfString );
       
  1075             } 
       
  1076         
       
  1077         }
       
  1078     TEFLOGSTRING2( 
       
  1079         KTAGENERAL, 
       
  1080         "PE: CPEMessageHandler::RemoveInvalidChars, Parsed string = %S", 
       
  1081         &aString);
       
  1082     return returnValue;
       
  1083     }
       
  1084 
       
  1085 
       
  1086 // -----------------------------------------------------------------------------
       
  1087 // CPEMessageHandler::HandleGetLifeTimerData
       
  1088 // Reads lifetimerdata from custom api and stores it to engine info
       
  1089 // -----------------------------------------------------------------------------
       
  1090 //
       
  1091 TInt CPEMessageHandler::HandleGetLifeTimerData() const
       
  1092     {
       
  1093     TCCPLifeTimeData lifeTimeData; 
       
  1094     TCCPLifeTimeDataPckg pckg( lifeTimeData );
       
  1095 
       
  1096     if ( iCallHandling.GetLifeTime( pckg ) )
       
  1097         {
       
  1098         TEFLOGSTRING2( 
       
  1099             KTAGENERAL, 
       
  1100             "PE: CPEMessageHandler::HandleGetLifeTimerData, iHours = %d", 
       
  1101             lifeTimeData.iHours);
       
  1102         TEFLOGSTRING2( 
       
  1103             KTAGENERAL, 
       
  1104             "PE: CPEMessageHandler::HandleGetLifeTimerData, iMinutes = %d", 
       
  1105             lifeTimeData.iMinutes);
       
  1106             
       
  1107         iDataStore.SetLifeTimerData( pckg );
       
  1108         }
       
  1109     
       
  1110     return ECCPErrorNone;
       
  1111     }
       
  1112     
       
  1113 // -----------------------------------------------------------------------------
       
  1114 // CPEMessageHandler::CallbackSendMessageStoppedDTMF
       
  1115 // -----------------------------------------------------------------------------
       
  1116 //
       
  1117 TInt CPEMessageHandler::CallbackSendMessageStoppedDTMF( TAny* aAny )
       
  1118     {
       
  1119     __ASSERT_ALWAYS( aAny , Panic( EPEPanicNullPointer ) );
       
  1120     CPEMessageHandler* self = static_cast<CPEMessageHandler*>(aAny);
       
  1121 
       
  1122     delete self->iAsyncCallBack;
       
  1123     self->iAsyncCallBack = NULL;
       
  1124     self->iModel.SendMessage( MEngineMonitor::EPEMessageStoppedDTMF ); 
       
  1125 
       
  1126     return ECCPErrorNone;
       
  1127     }
       
  1128     
       
  1129 // -----------------------------------------------------------------------------
       
  1130 // CPEMessageHandler::RemovePlusPrefix
       
  1131 // Remove '+' from begin of the string
       
  1132 // -----------------------------------------------------------------------------
       
  1133 //
       
  1134 void CPEMessageHandler::RemovePlusPrefix(
       
  1135     TPEPhoneNumber& aPhoneNumber )
       
  1136     {
       
  1137     TLex input( aPhoneNumber);
       
  1138 
       
  1139     if ( input.Peek() == KPEDtmfPlusChar )
       
  1140         {
       
  1141         // remove plus char 
       
  1142         input.Inc();
       
  1143         aPhoneNumber = input.Remainder();
       
  1144         TEFLOGSTRING2( KTAMESINT, 
       
  1145             "PE CPEMessageHandler::RemovePlusPrefix(), aPhoneNumber: %S"
       
  1146             , &aPhoneNumber ); 
       
  1147         }
       
  1148     }
       
  1149 
       
  1150 // -----------------------------------------------------------------------------
       
  1151 // CPEMessageHandler::HandleBuildConferenceCall
       
  1152 // Handles Create conference message from phone application.
       
  1153 // Method calls BuildConference method from MPECallHandling object.
       
  1154 // -----------------------------------------------------------------------------
       
  1155 //
       
  1156 TInt CPEMessageHandler::HandleBuildConferenceCall()
       
  1157     {
       
  1158     return iCallHandling.BuildConference();
       
  1159     }
       
  1160 
       
  1161 
       
  1162 // -----------------------------------------------------------------------------
       
  1163 // CPEMessageHandler::HandleGoOneToOne
       
  1164 // Handles GoOneToOne message from PhoneApplication. Calls GoOneToOne
       
  1165 // method from CallHandling object.
       
  1166 // -----------------------------------------------------------------------------
       
  1167 // 
       
  1168 TInt CPEMessageHandler::HandleGoOneToOne()
       
  1169     {
       
  1170     TInt callId = iDataStore.CallId();
       
  1171     __ASSERT_DEBUG( CallIdCheck::IsVoice( callId ), 
       
  1172         Panic( EPEPanicCallIndexOutOfRange ) );
       
  1173     return iCallHandling.GoOneToOne( callId );
       
  1174     }
       
  1175 
       
  1176 // -----------------------------------------------------------------------------
       
  1177 // CPEMessageHandler::HandleAddConferenceMember
       
  1178 // Handles Add conference member message from phone application.
       
  1179 // Method creates AddMember request to the CallHandling object.
       
  1180 // -----------------------------------------------------------------------------
       
  1181 //
       
  1182 TInt CPEMessageHandler::HandleAddConferenceMember()
       
  1183     {
       
  1184     TEFLOGSTRING( KTAINT, 
       
  1185        "PE CPEMessageHandler::HandleAddConferenceMember ");
       
  1186     return iCallHandling.AddConferenceMember();
       
  1187     }
       
  1188 
       
  1189 // -----------------------------------------------------------------------------
       
  1190 // CPEMessageHandler::HandleAddConferenceMember
       
  1191 // Handles dropped conference member message from callhandling subsystem.
       
  1192 // In case a long dtmf string is being sent, cancels the sending process.
       
  1193 // -----------------------------------------------------------------------------
       
  1194 //
       
  1195 void CPEMessageHandler::HandleDroppedConferenceMember()
       
  1196     {
       
  1197     TEFLOGSTRING( KTAINT, 
       
  1198        "PE CPEMessageHandler::HandleDroppedConferenceMember");
       
  1199     
       
  1200     StopDtmfSending();
       
  1201     }
       
  1202 
       
  1203 // -----------------------------------------------------------------------------
       
  1204 // CPEMessageHandler::HandleCallHandlingError
       
  1205 // Handles error message from CallHandling subsystem
       
  1206 // Method fetches error code from CallHandling subsystem and
       
  1207 // Method sends error code to SAT
       
  1208 // -----------------------------------------------------------------------------
       
  1209 // 
       
  1210 void CPEMessageHandler::HandleCallHandlingError(
       
  1211         const TInt aCallId,
       
  1212         const TBool /*aBusyCall*/ )
       
  1213     {
       
  1214     // Call data not valid for call id -1, i.e. non-call error situations
       
  1215     if ( aCallId != KPECallIdNotUsed )
       
  1216         {
       
  1217         //Update local call info
       
  1218         const TInt errorCode = iCallHandling.GetCallInfo( *iCallInfo, aCallId );
       
  1219         
       
  1220         // Take the error from call handling.
       
  1221         TInt errorForClient = iDataStore.ErrorCode(); 
       
  1222         if (  errorCode == ECCPErrorNone )
       
  1223             {
       
  1224             const TInt diagnosticInfo = 
       
  1225                 iCallHandling.CallTerminatedError( aCallId );
       
  1226             if ( diagnosticInfo != ECCPErrorNone )
       
  1227                 {
       
  1228                 errorForClient = diagnosticInfo;
       
  1229                 }
       
  1230             }
       
  1231         
       
  1232         TEFLOGSTRING2( KTAINT,
       
  1233                 "PE CPEMessageHandler::HandleCallHandlingError, SendRespond errorForClient: %d", errorForClient );
       
  1234         iClientServices->CallRequestMonitor()->SendRespond( errorForClient );            
       
  1235         }
       
  1236     }
       
  1237 
       
  1238 // -----------------------------------------------------------------------------
       
  1239 // CPEMessageHandler::HandleEngineInfo
       
  1240 // Handles call logging. Method add and update the call info.
       
  1241 // -----------------------------------------------------------------------------
       
  1242 // 
       
  1243 TInt CPEMessageHandler::HandleEngineInfo(
       
  1244     const TInt aCallId )       
       
  1245     {
       
  1246     TEFLOGSTRING2( KTAINT,
       
  1247         "PE CPEMessageHandler::HandleEngineInfo, call id: %d", aCallId );
       
  1248     TInt errorCode(  ECCPErrorNone );
       
  1249     TPEState callState;
       
  1250     
       
  1251     errorCode = FindCallInfo( aCallId );
       
  1252 
       
  1253     if ( !errorCode )
       
  1254         {
       
  1255         callState = iCallHandling.GetCallState( aCallId );
       
  1256         TEFLOGSTRING2( KTAINT, 
       
  1257             "PE CPEMessageHandler::HandleEngineInfo, call state: %d", 
       
  1258             callState );
       
  1259 
       
  1260         SetPhoneNumberForCallLogging( aCallId );
       
  1261 
       
  1262         if ( callState == EPEStateDialing || callState == EPEStateRinging )
       
  1263             {
       
  1264             errorCode = UpdateClientInfo( aCallId );
       
  1265 
       
  1266             iDataStore.SetRemoteIdentity( 
       
  1267                 static_cast< RMobileCall::TMobileCallRemoteIdentityStatus > ( 
       
  1268                     iCallInfo->iRemoteParty.iRemoteIdStatus ), 
       
  1269                 aCallId );
       
  1270             iTime.UniversalTime();
       
  1271             iDataStore.SetCallStartTime( iTime, aCallId );
       
  1272             iDataStore.SetCallDuration( 0, aCallId );
       
  1273             }
       
  1274 
       
  1275         // Calls have to log also without a contact (ECCPErrorNotFound).
       
  1276         if ( errorCode == ECCPErrorNone || errorCode == ECCPErrorNotFound)
       
  1277             {
       
  1278             errorCode = ECCPErrorNone;
       
  1279             
       
  1280             // If call is emergency call, phonenumber must be fetched from engine info
       
  1281             // Log type must be recognized from call id also, because in idle state
       
  1282             // TSY has cleaned call info information
       
  1283             CheckAndHideIdentity( aCallId );
       
  1284 
       
  1285             // Save the rest of information to EngineInfo.
       
  1286             SetLoggingInfo( aCallId, callState );
       
  1287             // Set missed call to EngineInfo.
       
  1288             IsMissedCall( aCallId, callState );
       
  1289             errorCode = iLogHandling.SaveCallEntry( aCallId );
       
  1290             }
       
  1291         } //if ( !errorCode )
       
  1292         
       
  1293     return errorCode;
       
  1294     }   
       
  1295  
       
  1296 // -----------------------------------------------------------------------------
       
  1297 // CPEMessageHandler::UpdateClientInfo
       
  1298 // -----------------------------------------------------------------------------
       
  1299 // 
       
  1300 TInt CPEMessageHandler::UpdateClientInfo( 
       
  1301     const TInt aCallId )
       
  1302     {
       
  1303     TInt errorCode( ECCPErrorNone );
       
  1304     const MPEClientInformation& clientInformation = iDataStore.CallClientInformation( aCallId );
       
  1305     
       
  1306     TEFLOGSTRING2( 
       
  1307         KTAINT, 
       
  1308         "PE CPEMessageHandler::UpdateClientInfo, remote name: '%S'", 
       
  1309         &iDataStore.RemoteName( aCallId ) );
       
  1310 
       
  1311     TEFLOGSTRING2( 
       
  1312         KTAINT, 
       
  1313         "PE CPEMessageHandler::UpdateClientInfo, name: '%S'", 
       
  1314         &clientInformation.Name() );
       
  1315 
       
  1316     TEFLOGSTRING2( 
       
  1317         KTAINT, 
       
  1318         "PE CPEMessageHandler::UpdateClientInfo, allowmatch: %d", 
       
  1319         clientInformation.AllowMatch() );
       
  1320     
       
  1321     if ( clientInformation.AllowMatch() && ( aCallId != KPEEmergencyCallId ) )
       
  1322         {
       
  1323         TEFLOGSTRING2( 
       
  1324             KTAINT, 
       
  1325             "PE CPEMessageHandler::UpdateClientInfo, match phone number: '%S'", 
       
  1326             &iDataStore.RemotePhoneNumber( aCallId ) );
       
  1327         if ( clientInformation.ContactLink().Length() > 0 )
       
  1328             {
       
  1329             errorCode = iContactHandling.FindContactInfoSync( 
       
  1330             aCallId, 
       
  1331             EPEFindWithContactId );
       
  1332             }    
       
  1333         else
       
  1334             {
       
  1335             errorCode = iContactHandling.FindContactInfoSync( 
       
  1336             aCallId, 
       
  1337             EPEFindWithPhoneNumber );            
       
  1338             }
       
  1339             
       
  1340         TEFLOGSTRING2( 
       
  1341             KTAINT, 
       
  1342             "PE CPEMessageHandler::UpdateClientInfo > MPEContactHandling::FindContactInfoSync( EPEFindWithPhoneNumber ), error code: %d", 
       
  1343             errorCode );
       
  1344         }
       
  1345     else if ( clientInformation.Name().Length() )
       
  1346         {
       
  1347         iDataStore.SetRemoteName( clientInformation.Name(), aCallId );
       
  1348         }
       
  1349     
       
  1350     // Calls have to log also without a contact (ECCPErrorNotFound).
       
  1351     if ( errorCode == ECCPErrorNone || errorCode == ECCPErrorNotFound)
       
  1352         {
       
  1353         // Set name to EngineInfo
       
  1354         SetName( aCallId );
       
  1355         }
       
  1356      return errorCode;   
       
  1357      }   
       
  1358     
       
  1359 // -----------------------------------------------------------------------------
       
  1360 // CPEMessageHandler::CheckAndHideIdentity
       
  1361 // -----------------------------------------------------------------------------
       
  1362 // 
       
  1363 void CPEMessageHandler::CheckAndHideIdentity(
       
  1364     const TInt aCallId )   
       
  1365     {
       
  1366     // If call is emergency call, phonenumber must be fetched from engine info
       
  1367     // Log type must be recognized from call id also, because in idle state
       
  1368     // TSY has cleaned call info information
       
  1369     RMobileCall::TMobileCallRemoteIdentityStatus tempIdentity;
       
  1370     tempIdentity = iDataStore.RemoteIdentity( aCallId );
       
  1371     
       
  1372     TEFLOGSTRING2( KTAINT,
       
  1373         "PE CPEMessageHandler::CheckAndHideIdentity, Identity: %d", tempIdentity );
       
  1374     if ( iCallInfo->iEmergency || aCallId == KPEEmergencyCallId ) 
       
  1375         {
       
  1376         iDataStore.SetRemotePhoneNumberType( EPEEmergencyNumber, aCallId );
       
  1377         }
       
  1378     else if( iDataStore.CallDirection( aCallId ) != RMobileCall::EMobileOriginated )
       
  1379 		{
       
  1380 		switch( tempIdentity )
       
  1381 			{
       
  1382 			case RMobileCall::ERemoteIdentitySuppressed:
       
  1383 				{
       
  1384 				// It is neccessary to perform an additional check for available
       
  1385 				// remote party phone number to comply with Italian operator
       
  1386 				// requirement: "If CLIR is active but network still provides
       
  1387 				// the device with a phone number, it should not be blocked
       
  1388 				// but passed to a client when requested."
       
  1389 				if( iDataStore.RemotePhoneNumber( aCallId ).Length() == 0 )
       
  1390 					{
       
  1391 					HideIdentification( EPEPrivateNumber, aCallId );
       
  1392 					}
       
  1393 				else
       
  1394 				    {
       
  1395 				    // Align remote identity with remote phone number availability.
       
  1396 				    iDataStore.SetRemoteIdentity( RMobileCall::ERemoteIdentityAvailable, aCallId );
       
  1397 				    }
       
  1398 				break;
       
  1399 				}
       
  1400 			case RMobileCall::ERemoteIdentityAvailableNoCliRejectedByUser:
       
  1401 				{
       
  1402 				HideIdentification( EPEPrivateNumber, aCallId );
       
  1403 				break;
       
  1404 				}
       
  1405 			case RMobileCall::ERemoteIdentityUnknown:
       
  1406 			case RMobileCall::ERemoteIdentityAvailableNoCliInteractionWithOtherService:
       
  1407 			case RMobileCall::ERemoteIdentityUnavailableNoCliInteractionWithOtherService:
       
  1408 			case RMobileCall::ERemoteIdentityAvailableNoCliCoinOrPayphone:
       
  1409 			case RMobileCall::ERemoteIdentityUnavailableNoCliCoinOrPayphone:
       
  1410 			case RMobileCall::ERemoteIdentityAvailableNoCliUnavailable:
       
  1411 				{
       
  1412 				HideIdentification( EPEUnknownNumber, aCallId );
       
  1413 				break;
       
  1414 				}
       
  1415 			case RMobileCall::ERemoteIdentityAvailable:
       
  1416 			default:
       
  1417 				{
       
  1418 				TEFLOGSTRING( KTAINT,
       
  1419 					"PE CPEMessageHandler::CheckAndHideIdentity, CLI available" );
       
  1420 				break;
       
  1421 				}
       
  1422 			}
       
  1423 		}
       
  1424 	}
       
  1425     
       
  1426 // -----------------------------------------------------------------------------
       
  1427 // CPEMessageHandler::FindCallInfo
       
  1428 // Return callInfo from Etel/TSY.
       
  1429 // -----------------------------------------------------------------------------
       
  1430 // 
       
  1431 TInt CPEMessageHandler::FindCallInfo(
       
  1432         const TInt aCallId )
       
  1433     {
       
  1434     TInt errorCode( ECCPErrorNone );
       
  1435     if ( CallIdCheck::IsVoice( aCallId ) || CallIdCheck::IsVideo( aCallId ) )
       
  1436         {
       
  1437         // Single call
       
  1438         errorCode = iCallHandling.GetCallInfo( *iCallInfo, aCallId );
       
  1439         TEFLOGSTRING3( 
       
  1440             KTAREQOUT, 
       
  1441             "CNT CPEMessageHandler::FindCallInfo > MPECallHandling::GetCallInfo, call id: %d, error code: %d", 
       
  1442             aCallId, 
       
  1443             errorCode );
       
  1444         TEFLOGSTRING2( 
       
  1445             KTAINT, 
       
  1446             "CNT CPEMessageHandler::FindCallInfo, remote number: '%S'", 
       
  1447             &iCallInfo->iRemoteParty.iRemoteNumber );
       
  1448         TEFLOGSTRING2( 
       
  1449             KTAINT, 
       
  1450             "CNT CPEMessageHandler::FindCallInfo, direction: %d", 
       
  1451             iDataStore.CallDirection( aCallId ) );
       
  1452         TEFLOGSTRING2( 
       
  1453             KTAINT, 
       
  1454             "CNT CPEMessageHandler::FindCallInfo, id status: %d", 
       
  1455             iCallInfo->iRemoteParty.iRemoteIdStatus );
       
  1456         }
       
  1457     else
       
  1458         {
       
  1459         // We don't log the master conference call and other unknown calls.
       
  1460         errorCode = KErrUnknown;
       
  1461         }
       
  1462     return errorCode;
       
  1463     }
       
  1464 
       
  1465 // -----------------------------------------------------------------------------
       
  1466 // CPEMessageHandler::SetPhoneNumberForCallLogging
       
  1467 // Set phonenumber for call logging
       
  1468 // -----------------------------------------------------------------------------
       
  1469 // 
       
  1470 void CPEMessageHandler::SetPhoneNumberForCallLogging(
       
  1471         const TInt aCallId )
       
  1472     {
       
  1473     // if call is MO then the phonenumber must be stored from dialled party.
       
  1474     if ( iDataStore.CallDirection( aCallId ) == RMobileCall::EMobileOriginated )
       
  1475         {
       
  1476 
       
  1477         TPEPhoneNumber number;        
       
  1478         const TPECallOrigin origin = iDataStore.CallOrigin( aCallId );
       
  1479         
       
  1480         if ( origin == EPECallOriginSAT )
       
  1481             {
       
  1482             // Dont set for SAT calls >> number not logged
       
  1483             }
       
  1484         else if( iDataStore.PhoneNumber().Length() )
       
  1485             {
       
  1486             // Phonenumber given by user, includes pfe- and postfix.
       
  1487             number = iDataStore.PhoneNumber();
       
  1488             }   
       
  1489         else
       
  1490             {
       
  1491             // If call is made using ETel api, then phonenumber must take from callinfo.
       
  1492             number = iCallInfo->iDialledParty.iTelNumber;
       
  1493             }
       
  1494         
       
  1495         
       
  1496         // WholeOutgoingPhoneNumber should set only one time because in connected state 
       
  1497         // PhoneNumber is cleaned from datastore.
       
  1498         if( !iDataStore.WholeOutgoingPhoneNumber( aCallId ).Length() )
       
  1499             {
       
  1500         
       
  1501             TEFLOGSTRING2( KTAINT,
       
  1502                     "PE CPEMessageHandler::SetPhoneNumberAndDataCallLogging, number: '%S'"
       
  1503                     ,&number );
       
  1504             iDataStore.SetWholeOutgoingPhoneNumber( number, aCallId ); 
       
  1505             }
       
  1506         
       
  1507         // RemotePhoneNumber should set only one time because user can edit DataStore::PhoneNumber after dialing was started.
       
  1508         if( !iDataStore.RemotePhoneNumber( aCallId ).Length() )
       
  1509             {
       
  1510             TEFLOGSTRING3( 
       
  1511                 KTAMESINT, 
       
  1512                 "PE CPEMessageHandler::SetPhoneNumberForCallLogging, remote phone number: '%S', call id: %d", 
       
  1513                 &number, aCallId );
       
  1514                                          
       
  1515             RemovePreAndPostFix( number );
       
  1516   
       
  1517             iDataStore.SetRemotePhoneNumber( number, aCallId );
       
  1518             }
       
  1519         
       
  1520         // The Colp number is stored to remoteparty in connected state.
       
  1521         TPEPhoneNumber colpNumber = iCallInfo->iRemoteParty.iRemoteNumber.iTelNumber;
       
  1522         RemovePreAndPostFix( colpNumber );
       
  1523         iDataStore.SetRemoteColpNumber( colpNumber, aCallId ); 
       
  1524         TEFLOGSTRING3( 
       
  1525             KTAMESINT, 
       
  1526             "PE CPEMessageHandler::SetPhoneNumberForCallLogging, colp number: '%S', call id: %d", 
       
  1527             &colpNumber, aCallId );
       
  1528         }
       
  1529     else if ( iDataStore.CallDirection( aCallId ) == RMobileCall::EMobileTerminated )
       
  1530         {
       
  1531         iDataStore.SetRemotePhoneNumber( iCallInfo->iRemoteParty.iRemoteNumber.iTelNumber, aCallId );
       
  1532         TEFLOGSTRING2( 
       
  1533             KTAMESINT, 
       
  1534             "PE CPEMessageHandler::SetPhoneNumberForCallLogging: remote phone number: '%S'", 
       
  1535             &iCallInfo->iRemoteParty.iRemoteNumber.iTelNumber );
       
  1536         }
       
  1537     }
       
  1538 
       
  1539 // -----------------------------------------------------------------------------
       
  1540 // CPEMessageHandler::SetLoggingInfo
       
  1541 // Store call information for logging
       
  1542 // -----------------------------------------------------------------------------
       
  1543 // 
       
  1544 void CPEMessageHandler::SetLoggingInfo(
       
  1545         const TInt aCallId,
       
  1546         TPEState aCallState )
       
  1547     {
       
  1548     if ( aCallState == EPEStateConnected )
       
  1549         {
       
  1550         iDataStore.SetCallStartTime( iCallInfo->iStartTime, aCallId );   
       
  1551         }
       
  1552     iDataStore.SetCallForwarded( iCallInfo->iForwarded, aCallId );
       
  1553     iDataStore.SetCallService( iCallInfo->iService, aCallId );
       
  1554     iDataStore.SetCallState( aCallState, aCallId );
       
  1555     iDataStore.SetCallDuration( iCallInfo->iDuration.Int() );
       
  1556     }
       
  1557 
       
  1558 // -----------------------------------------------------------------------------
       
  1559 // CPEMessageHandler::SetName
       
  1560 // Set calling name or client name to RemoteInfo.
       
  1561 // -----------------------------------------------------------------------------
       
  1562 // 
       
  1563 void CPEMessageHandler::SetName( const TInt aCallId )
       
  1564     {
       
  1565     if ( iDataStore.RemoteName( aCallId ).Length() <= 0 &&
       
  1566          iDataStore.RemoteCompanyName( aCallId ).Length() <= 0 &&
       
  1567          iCallInfo->iRemoteParty.iCallingName.Length() >0 ) 
       
  1568         { 
       
  1569         iDataStore.SetRemoteName( iCallInfo->iRemoteParty.iCallingName, aCallId );
       
  1570         }
       
  1571     }
       
  1572 
       
  1573 // -----------------------------------------------------------------------------
       
  1574 // CPEMessageHandler::HideIdentification
       
  1575 // Hide identification to RemoteInfo.
       
  1576 // -----------------------------------------------------------------------------
       
  1577 // 
       
  1578 void CPEMessageHandler::HideIdentification(
       
  1579         TPEPhoneNumberIdType aPhoneNumberId,
       
  1580         const TInt aCallId )
       
  1581     {
       
  1582     TEFLOGSTRING2( KTAINT,
       
  1583         "PE CPEMessageHandler::HideIdentification: aPhoneNumberId = %d", aPhoneNumberId );
       
  1584     iDataStore.SetRemotePhoneNumberType( aPhoneNumberId, aCallId );
       
  1585     iDataStore.SetRemotePhoneNumber( KNullDesC(), aCallId );
       
  1586     iDataStore.SetRemoteName( KNullDesC(), aCallId );
       
  1587     iDataStore.SetRemotePartyName( KNullDesC(), aCallId );
       
  1588     }
       
  1589 
       
  1590 // -----------------------------------------------------------------------------
       
  1591 // CPEMessageHandler::IsMissedCall
       
  1592 // Check missed call in the idle state.
       
  1593 // -----------------------------------------------------------------------------
       
  1594 // 
       
  1595 void CPEMessageHandler::IsMissedCall(
       
  1596         const TInt aCallId,
       
  1597         TPEState aCallState )
       
  1598     {
       
  1599     if ( iDataStore.CallDirection( aCallId ) == RMobileCall::EMobileTerminated )
       
  1600         {
       
  1601         // If remote party has hanged up the current call on Ringing state, 
       
  1602         // this call is the missed call in the idle state.
       
  1603         if ( aCallState == EPEStateIdle )
       
  1604             {
       
  1605             TBool missedCall = EFalse;
       
  1606 
       
  1607             if ( CallIdCheck::IsVoice( aCallId ) || CallIdCheck::IsVideo( aCallId ) )
       
  1608                 {
       
  1609                 iCallHandling.GetMissedCall( missedCall, aCallId );
       
  1610                 }
       
  1611 
       
  1612             iDataStore.SetMissedCall( missedCall, aCallId );
       
  1613             } 
       
  1614         }
       
  1615     }
       
  1616 
       
  1617 // -----------------------------------------------------------------------------
       
  1618 // CPEMessageHandler::HandleCancelSSstringCommand
       
  1619 // Handles cancel SS string command.
       
  1620 // -----------------------------------------------------------------------------
       
  1621 // 
       
  1622 TInt CPEMessageHandler::HandleCancelSSstringCommand()
       
  1623     {
       
  1624     TInt returnValue( ECCPErrorNone );
       
  1625 
       
  1626     returnValue = iSSHandler->Cancel();
       
  1627 
       
  1628     return returnValue;
       
  1629     }
       
  1630 
       
  1631 // -----------------------------------------------------------------------------
       
  1632 // CPEMessageHandler::HandleConferenceIdleState
       
  1633 // Handles EPEMessageConferenceIdle message.
       
  1634 // -----------------------------------------------------------------------------
       
  1635 // 
       
  1636 TInt CPEMessageHandler::HandleConferenceIdleState( 
       
  1637         const TInt aCallId )
       
  1638     {
       
  1639     TInt counter;
       
  1640     TInt conferenceValue;
       
  1641 
       
  1642     TTimeIntervalSeconds duration;
       
  1643     TInt errorCode = iCallHandling.GetCallDuration( duration, aCallId );
       
  1644     
       
  1645     // Duration offset is stored previously to data store using conference members
       
  1646     // duration. If we do not check for null here then the stored offset is ignored..
       
  1647     if ( ECCPErrorNone == errorCode && duration.Int() > 0 ) 
       
  1648         {
       
  1649         // Set last conference duration
       
  1650         iDataStore.SetCallDuration( duration.Int() );
       
  1651         }
       
  1652     else if ( ECCPErrorNone == errorCode && duration.Int() == 0 )
       
  1653         {
       
  1654         // copy conference call duration to last call duration
       
  1655         // all call specific data is erased a few lines down
       
  1656         iDataStore.SetCallDuration( iDataStore.CallDuration( aCallId ).Int() );
       
  1657         }   
       
  1658 
       
  1659     //Reset values to the TPECallInfo structure
       
  1660     iDataStore.ResetCallInfo( aCallId );
       
  1661 
       
  1662     // Reset Conference Master info from all ex-members
       
  1663     for ( counter = 0; counter < KPEMaximumNumberOfVoiceCalls; counter++ )
       
  1664         {
       
  1665         conferenceValue = iDataStore.CallConference( counter );
       
  1666         if ( conferenceValue == aCallId )
       
  1667             {
       
  1668             iDataStore.SetCallConference( KPENormalVoiceCall, counter );
       
  1669             }
       
  1670         }
       
  1671     
       
  1672     //Stops possible ringing tone playing
       
  1673     //APS Stops possible remote alerting tone playing
       
  1674     TEFLOGSTRING( KTAMESINT, 
       
  1675         "PE  CPEMessageHandler::HandleConferenceIdleState > iGsmAudioData.StopInbandTonePlay()");
       
  1676     iGsmAudioData.StopInbandTonePlay(); 
       
  1677     
       
  1678     ClearCallAudio();    
       
  1679         
       
  1680     return ECCPErrorNone;
       
  1681     }
       
  1682 
       
  1683 // -----------------------------------------------------------------------------
       
  1684 // CPEMessageHandler::HandleConnectedState
       
  1685 // Handles connected message from the CallHandling subsystem 
       
  1686 // 
       
  1687 //  Method fetches call state and ALS line values from the Callhandling subsystem and then
       
  1688 //  Method fetches remote information from the CPEEngineInfo class and then
       
  1689 //  Method sets new values to the logInfo parameters and then
       
  1690 //  Method updates call values to the LogHandling subsystem and then
       
  1691 //  Method sets new values to the CPEEngineInfo class and then
       
  1692 //  Method fecths possible dtmf string from the CPEParserPhoneNumberHandler class and then
       
  1693 //  Method calls HandleSendDtmf method if dtmf string lenght was more than zero.
       
  1694 // -----------------------------------------------------------------------------
       
  1695 //
       
  1696 TInt CPEMessageHandler::HandleConnectedState( 
       
  1697         const TInt aCallId )
       
  1698     {
       
  1699     TInt errorCode( ECCPErrorNone );
       
  1700     TPEState callState;
       
  1701     TPEDtmfString dtmfString;
       
  1702 
       
  1703     RMobileCall::TMobileCallDirection callDirection;
       
  1704     callDirection = iDataStore.CallDirection( aCallId );
       
  1705 
       
  1706     //Stops possible local playing of remote alerting tone
       
  1707     TEFLOGSTRING( 
       
  1708         KTAMESINT, 
       
  1709         "PE  CPEMessageHandler::HandleConnectedState: Calling iGsmAudioData.StopInbandTonePlay()");
       
  1710     iGsmAudioData.StopInbandTonePlay();
       
  1711 
       
  1712     //If call was held then no logging is done.
       
  1713     callState = iDataStore.CallState( aCallId );
       
  1714     if ( callState != EPEStateHeld )
       
  1715         {
       
  1716         errorCode = HandleEngineInfo( aCallId );
       
  1717 
       
  1718         // If phone number has contained dtmf string, phone engine sends dtmf string now.
       
  1719         // Only in MO - call.
       
  1720 
       
  1721         if ( callDirection == RMobileCall::EMobileOriginated )
       
  1722             {
       
  1723             if ( aCallId == KPEEmergencyCallId )
       
  1724                 {
       
  1725                 dtmfString = iDataStore.DtmfStringCommand();
       
  1726                 if ( dtmfString.Length() > 0 )
       
  1727                     {
       
  1728                     errorCode = HandleSendDtmf();
       
  1729                     }
       
  1730                 }
       
  1731              else 
       
  1732                 {
       
  1733 
       
  1734                 dtmfString = iDataStore.DtmfPostFix( aCallId );
       
  1735 				
       
  1736                 if ( dtmfString.Length() > 0 )
       
  1737                     {
       
  1738                     iDataStore.SetDtmfStringCommand( dtmfString );
       
  1739                     errorCode = HandleSendDtmf();
       
  1740                     }
       
  1741                 }
       
  1742 
       
  1743             iDataStore.SetErrorCode( errorCode );
       
  1744             }
       
  1745         }
       
  1746     // For Sat call ( normal or emergency )    
       
  1747     iClientServices->CallRequestMonitor()->SendRespond( ECCPErrorNone );
       
  1748     
       
  1749     // Reset Phonenumber from engine info, this is necessary so that call number
       
  1750     // logging works OK (see CPEMessageHandler::SetPhoneNumberForCallLogging).  
       
  1751     iDataStore.SetPhoneNumber( KNullDesC() );
       
  1752     
       
  1753     // COLP number is updated in connected state 
       
  1754     UpdateRemotePartyInfo();
       
  1755    
       
  1756     return ECCPErrorNone;
       
  1757     }
       
  1758 
       
  1759 // -----------------------------------------------------------------------------
       
  1760 // CPEMessageHandler::HandleDialCall
       
  1761 // Handles dial message from phone application
       
  1762 // 
       
  1763 // -----------------------------------------------------------------------------
       
  1764 // 
       
  1765 TInt CPEMessageHandler::HandleDialCall(
       
  1766     const TBool aClientCall )
       
  1767     {
       
  1768     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDialCall" );
       
  1769     TInt errorCode( ECCPErrorNone );
       
  1770 
       
  1771     TRAPD( trapError, errorCode = HandleDialCallL( aClientCall ));
       
  1772 
       
  1773     if ( trapError )    
       
  1774         {
       
  1775         if ( aClientCall )    
       
  1776             {
       
  1777             iClientServices->CallRequestMonitor()->SendRespond( trapError );                    
       
  1778             }
       
  1779         TEFLOGSTRING2( KTAINT, "PE CPEMessageHandler::HandleDialCall: trapError = %d", trapError );
       
  1780         return trapError;
       
  1781         }
       
  1782     return errorCode;
       
  1783     }
       
  1784 
       
  1785 
       
  1786 // -----------------------------------------------------------------------------
       
  1787 // CPEMessageHandler::HandleDialEmergencyCall
       
  1788 // Handles dial message from phone application
       
  1789 // 
       
  1790 // -----------------------------------------------------------------------------
       
  1791 // 
       
  1792 TInt CPEMessageHandler::HandleDialEmergencyCall(
       
  1793     const TBool aClientCall )
       
  1794     {
       
  1795     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDialEmergencyCall" );
       
  1796     TInt errorCode( ECCPErrorNone );
       
  1797 
       
  1798     if( iEmergencyCallActive && aClientCall )
       
  1799         {
       
  1800         // Client tried to make an emergency call even though we already
       
  1801         // have an active emergency call.
       
  1802         iClientServices->CallRequestMonitor()->SendRespond( ECCPErrorAlreadyInUse );
       
  1803         // Notify PhoneApp which is responsible for showing the error note
       
  1804         return ECCPErrorAlreadyInUse;
       
  1805         }
       
  1806     
       
  1807     iDataStore.SetCallTypeCommand( EPECallTypeCSVoice );
       
  1808         
       
  1809     // Check the phone number and change the prefix if needed
       
  1810     CheckPrefix();
       
  1811     
       
  1812     if ( aClientCall )
       
  1813         {
       
  1814         TPEPhoneNumber phoneNumber = iDataStore.PhoneNumber();
       
  1815         __ASSERT_DEBUG( !( phoneNumber == KNullDesC ), Panic( EPEPanicInvalidParameter));
       
  1816 
       
  1817         TBuf<KPEPhoneNumberMaxLength> tempPhoneNumber = phoneNumber;
       
  1818         RemoveInvalidChars( tempPhoneNumber, KPEClientValidChars, ETrue );
       
  1819         RemovePreAndPostFix( tempPhoneNumber );
       
  1820         
       
  1821         SetClientInformation( KPEEmergencyCallId, tempPhoneNumber );
       
  1822         iClientServices->CallRequestMonitor()->SendRespond( ECCPErrorNone );
       
  1823         }
       
  1824 
       
  1825     if ( IsActiveVideo() )
       
  1826         {
       
  1827         // PhoneApp needs to request releasing of data port from video telephony engine
       
  1828         // Emergency call initialization will continue after receiving MPEPhoneModel::
       
  1829         // EPEMessageContinueEmergencyCallInitialization
       
  1830         iModel.SendMessage( MEngineMonitor::EPEMessageInitiatedEmergencyWhileActiveVideo );
       
  1831         }
       
  1832     else
       
  1833         {
       
  1834         ContinueDialEmergency();
       
  1835         }
       
  1836 
       
  1837     return errorCode;
       
  1838     }
       
  1839 
       
  1840 // -----------------------------------------------------------------------------
       
  1841 // CPEMessageHandler::HandleDialCallL
       
  1842 // Handles dial message from phone application
       
  1843 // 
       
  1844 //  Method fecths phone number from the CPEEngineInfo class and then
       
  1845 //  Method sets process type to the CPEParserPhoneNumberHandler and then
       
  1846 //  Method fecths clir settings from the Settings utility subsystem and tehn
       
  1847 //  Method fecths call parameters from the CallHandling subsystem and then
       
  1848 //  Method sets updated call parameter to the CallHandling subsystem and then
       
  1849 //  Method parsers phonenumber and then
       
  1850 //  Method process parsing result with PhoneParser
       
  1851 // -----------------------------------------------------------------------------
       
  1852 // 
       
  1853 TInt CPEMessageHandler::HandleDialCallL(
       
  1854     const TBool aClientCall )
       
  1855     {
       
  1856     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDialCallL" );
       
  1857     TBool parsingResult;
       
  1858     TPEPhoneNumber phoneNumber;
       
  1859     TInt errorCode( ECCPErrorNone );
       
  1860     TInt numberOfCalls;
       
  1861     
       
  1862     if ( aClientCall )
       
  1863         {
       
  1864         HandleClientCallData();
       
  1865         }
       
  1866         
       
  1867     //Get number of calls
       
  1868     numberOfCalls = iCallHandling.GetNumberOfCalls();
       
  1869 
       
  1870     // Check the phone number for prefix change and change the prefix if needed
       
  1871     CheckPrefix();
       
  1872 
       
  1873     phoneNumber = iDataStore.PhoneNumber();
       
  1874   
       
  1875     __ASSERT_ALWAYS( !( phoneNumber == KNullDesC ), User::Leave( ECCPErrorInvalidPhoneNumber ));
       
  1876     
       
  1877     // Number parser operations
       
  1878     iOptions->SetOptionStatus( KPhoneOptionSend, ETrue );
       
  1879     iOptions->SetOptionStatus( KPhoneOptionInCall, numberOfCalls > 0 );
       
  1880     // If voip call request
       
  1881     if( iDataStore.CallTypeCommand() == EPECallTypeVoIP )
       
  1882         {
       
  1883         iOptions->SetOptionStatus( KPhoneOptionVoipCall, ETrue );
       
  1884         }
       
  1885     else
       
  1886         {
       
  1887         iOptions->SetOptionStatus( KPhoneOptionVoipCall, EFalse );
       
  1888         }
       
  1889 
       
  1890     parsingResult = iParser->ParseL( phoneNumber, *iResult, *iOptions );
       
  1891     if ( parsingResult )
       
  1892         {
       
  1893         iGsmParserErrorCode = ECCPErrorNone;
       
  1894         iParserHandlerContainer->ProcessL( *iResult );
       
  1895         errorCode = iGsmParserErrorCode;
       
  1896         }
       
  1897     else
       
  1898         {
       
  1899         // string was not recognised by any of the parser objects
       
  1900         TEFLOGSTRING( KTAERROR, 
       
  1901             "PE CPEMessageHandler::HANDLEDIALCALLL: PHONEPARSER DID NOT RECOGNIZE THE STRING!" );
       
  1902         errorCode = KErrArgument;
       
  1903         }
       
  1904 
       
  1905     if ( aClientCall )
       
  1906         {
       
  1907         // Do not sent the response to SAT, unless there is error.
       
  1908         const TPECallOrigin& origin = iDataStore.CallOriginCommand();            
       
  1909         if ( origin != EPECallOriginSAT || errorCode )    
       
  1910             {
       
  1911             iClientServices->CallRequestMonitor()->SendRespond( errorCode );                    
       
  1912             }
       
  1913         }
       
  1914 
       
  1915     TEFLOGSTRING2( KTAINT, "PE CPEMessageHandler::HandleDialCallL: errorCode = %d", errorCode );
       
  1916         
       
  1917     return errorCode;
       
  1918     }
       
  1919 
       
  1920 // -----------------------------------------------------------------------------
       
  1921 // CPEMessageHandler::HandleSatCallRequestCompleted
       
  1922 // Sends respond to SAT after dial request completion
       
  1923 // -----------------------------------------------------------------------------
       
  1924 // 
       
  1925 void CPEMessageHandler::HandleSatCallRequestCompleted()
       
  1926     {
       
  1927     // Monitor with active request completes
       
  1928     iClientServices->CallRequestMonitor()->
       
  1929         SendRespond( iCallHandling.CallTerminatedError( iDataStore.CallId() ));                    
       
  1930     }
       
  1931 
       
  1932 // -----------------------------------------------------------------------------
       
  1933 // CPEMessageHandler::HandleDialEmergency
       
  1934 // Handles emergency call message from phone application
       
  1935 //
       
  1936 //  Method calls DialEmergencyCall method from the CallHandling subsystem.
       
  1937 // -----------------------------------------------------------------------------
       
  1938 // 
       
  1939 void CPEMessageHandler::ContinueDialEmergency()
       
  1940     {
       
  1941     iDataStore.SetCallId( KPEEmergencyCallId );
       
  1942     if ( !iEmergencyCallActive )
       
  1943         {
       
  1944         iExternalDataHandler.Set( EPEEmergencyCallInfo, ETrue );  
       
  1945         iEmergencyCallActive = ETrue;        
       
  1946         }
       
  1947         // unmute mic
       
  1948         iDataStore.SetAudioMuteCommand( EFalse );
       
  1949         HandleSetAudioMute();
       
  1950 
       
  1951     iCallHandling.DialEmergencyCall( iDataStore.PhoneNumber() );
       
  1952     }
       
  1953 
       
  1954 // -----------------------------------------------------------------------------
       
  1955 // CPEMessageHandler::HandleDialingStateL
       
  1956 // Handles dialing state transition for voice and video calls
       
  1957 // -----------------------------------------------------------------------------
       
  1958 // 
       
  1959 void CPEMessageHandler::HandleDialingStateL( 
       
  1960         const TInt aCallId )
       
  1961     {
       
  1962     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDialingStateL <");
       
  1963     
       
  1964     if( iCallHandling.GetNumberOfCalls() == 1 )
       
  1965         {
       
  1966         // Check volume levels - zero level needs to be reset to default value
       
  1967         iGsmAudioData.SetDefaultVolume();
       
  1968         }
       
  1969     // Save call direction to engine info.
       
  1970     iDataStore.SetCallDirection( RMobileCall::EMobileOriginated, aCallId );
       
  1971     
       
  1972     // Log the call information.
       
  1973     User::LeaveIfError( HandleEngineInfo( aCallId ) );
       
  1974     
       
  1975     // publish remote party info to Mediator after contact matching is done
       
  1976     // as remote party info contains information from contact matching. 
       
  1977     UpdateRemotePartyInfo();
       
  1978     
       
  1979     TBool videoCall =
       
  1980         ( iDataStore.CallType( aCallId ) == EPECallTypeVideo ) ? ETrue : EFalse;
       
  1981 
       
  1982     TEFLOGSTRING2(
       
  1983             KTAINT,
       
  1984             "CPEMessageHandler::HandleDialingStateL, callType: %d",
       
  1985             iDataStore.CallType( aCallId ) );
       
  1986         
       
  1987     // Determine the preferred output for call audio and route accordingly.
       
  1988     // Routing for incoming voice call is done in answering state.
       
  1989     HandleAudioRouting( videoCall, aCallId );
       
  1990     }
       
  1991 
       
  1992 // -----------------------------------------------------------------------------
       
  1993 // CPEMessageHandler::HandleIncomingCallL
       
  1994 // Handles incoming voice and video call
       
  1995 // -----------------------------------------------------------------------------
       
  1996 //
       
  1997 void CPEMessageHandler::HandleIncomingCallL( 
       
  1998         const TInt aCallId )
       
  1999     {
       
  2000     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleIncomingCallL <");
       
  2001     
       
  2002     // Save call direction to engine info.
       
  2003     iDataStore.SetCallDirection( RMobileCall::EMobileTerminated, aCallId );
       
  2004 
       
  2005     // Log the call information.
       
  2006     User::LeaveIfError( HandleEngineInfo( aCallId ) );
       
  2007     
       
  2008     // publish remote party info to Mediator after contact matching is done
       
  2009     // as remote party info contains information from contact matching. 
       
  2010     UpdateRemotePartyInfo();    
       
  2011     
       
  2012     TInt numberOfCalls = iCallHandling.GetNumberOfCalls();
       
  2013     
       
  2014     if( numberOfCalls > 1 )
       
  2015         {
       
  2016         TEFLOGSTRING( 
       
  2017             KTAMESINT, 
       
  2018             "PE  CPEMessageHandler::HandleIncomingCallL: Calling iGsmAudioData->PlayInbandTone() for call waiting tone");
       
  2019         iDataStore.SetInbandTone( ECCPCallWaiting );
       
  2020         iGsmAudioData.PlayInbandTone();
       
  2021         iWaitingCallId = aCallId;
       
  2022         }
       
  2023     else if( numberOfCalls == 1 )
       
  2024         {
       
  2025         // Check volume levels - zero level needs to be reset to default value
       
  2026         iGsmAudioData.SetDefaultVolume();
       
  2027         }
       
  2028     if( AutomaticAnswer( aCallId ) )
       
  2029         {
       
  2030         TEFLOGSTRING( KTAINT, 
       
  2031         "PE  CPEMessageHandler::HandleIncomingCallL: iAutomaticAnswerTimer->StartTimer");
       
  2032         iAutomaticAnswerTimer->StartTimer( KPEAutomaticAnswerTimeOut, MEngineMonitor::EPEMessageAnswer, aCallId );
       
  2033         }
       
  2034 
       
  2035     // Cancel EnableService, if in progress
       
  2036     iServiceHandling.CancelServiceEnabling();
       
  2037     }
       
  2038 
       
  2039 // -----------------------------------------------------------------------------
       
  2040 // CPEMessageHandler::HandleDisconnecting
       
  2041 // Handles disconnecting. This means network doesn't play inband tones, but PE must play those.
       
  2042 // -----------------------------------------------------------------------------
       
  2043 // 
       
  2044 TInt CPEMessageHandler::HandleDisconnecting
       
  2045         (
       
  2046         const TInt /*aCallId*/  //The identification number of the call.
       
  2047         )
       
  2048     {
       
  2049     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDisconnecting" );
       
  2050 
       
  2051     iAutomaticAnswerTimer->Cancel();
       
  2052 
       
  2053     TEFLOGSTRING( KTAMESOUT, 
       
  2054         "PE CPEMessageHandler::HandleDisconnecting > iGsmAudioData.PlayInbandTone()");
       
  2055     iGsmAudioData.PlayInbandTone();
       
  2056     
       
  2057     return ECCPErrorNone;
       
  2058     }
       
  2059 
       
  2060 // -----------------------------------------------------------------------------
       
  2061 // CPEMessageHandler::HandleDisconnectingWithInband
       
  2062 // Handles disconnecting with inband. This means network plays the inband tones
       
  2063 // and PhoneEngine does not.
       
  2064 // -----------------------------------------------------------------------------
       
  2065 // 
       
  2066 TInt CPEMessageHandler::HandleDisconnectingWithInband(
       
  2067         const TInt /*aCallId*/ )
       
  2068     {
       
  2069     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDisconnectingWithInband" );
       
  2070     return ECCPErrorNone;
       
  2071     }
       
  2072 
       
  2073 // -----------------------------------------------------------------------------
       
  2074 // CPEMessageHandler::HandleDropConferenceMember
       
  2075 // Handles drop message from phone application
       
  2076 // Method calls DropMember method from CallHandling object.
       
  2077 // -----------------------------------------------------------------------------
       
  2078 // 
       
  2079 TInt CPEMessageHandler::HandleDropConferenceMember()
       
  2080     {
       
  2081     TInt callId = iDataStore.CallId();
       
  2082     __ASSERT_DEBUG( CallIdCheck::IsVoice( callId ), 
       
  2083         Panic( EPEPanicCallIndexOutOfRange ) );
       
  2084     return iCallHandling.DropMember( callId );
       
  2085     }
       
  2086 
       
  2087 // -----------------------------------------------------------------------------
       
  2088 // CPEMessageHandler::HandleHoldCall
       
  2089 // Handles hold message from phone application
       
  2090 // Method fecths call id number from the CPEEngineInfo class and then
       
  2091 // Method calls HoldCall method from the CallHandling subsystem.
       
  2092 // -----------------------------------------------------------------------------
       
  2093 // 
       
  2094 TInt CPEMessageHandler::HandleHoldCall()
       
  2095     {
       
  2096     return iCallHandling.HoldCall();
       
  2097     }
       
  2098 
       
  2099 // -----------------------------------------------------------------------------
       
  2100 // CPEMessageHandler::HandleVoiceCallIdleState
       
  2101 // Handles idle message from the CallHandling subsystem.
       
  2102 //
       
  2103 //  Method stops playing possible ringing tone and the
       
  2104 //  Method gets call and ALS line information from the CallHandling subsystem and then
       
  2105 //  Method fecth remote party information from the CPEEngineInfo class and then
       
  2106 //  Method sets new values to the logInfo parameter and then
       
  2107 //  Method updates log values to the LogHandling subsystem and then
       
  2108 //  Method updates Engine Info's call terminated diagnostics value and then
       
  2109 //  Method resets call information.
       
  2110 // -----------------------------------------------------------------------------
       
  2111 // 
       
  2112 TInt CPEMessageHandler::HandleVoiceCallIdleState( 
       
  2113     const TInt aCallId )
       
  2114     {
       
  2115     TInt errorCode( ECCPErrorGeneral );
       
  2116     TInt returnValue( ECCPErrorNone );
       
  2117     TInt numberOfCalls;
       
  2118 
       
  2119     //Stops possible ringing tone playing
       
  2120     //APS Stops possible remote alerting tone playing
       
  2121     TEFLOGSTRING( KTAMESINT, 
       
  2122         "PE  CPEMessageHandler::HandleVoiceCallIdleState > iGsmAudioData.StopInbandTonePlay()");
       
  2123     iGsmAudioData.StopInbandTonePlay(); 
       
  2124     
       
  2125     ClearCallAudio();
       
  2126     
       
  2127     errorCode = iCallHandling.GetCallInfo( *iCallInfo, aCallId );
       
  2128     
       
  2129     if (  errorCode == ECCPErrorNone )
       
  2130         {
       
  2131         TInt diagnosticInfo = iCallHandling.GetCallTerminatedDiagnostics( 
       
  2132             iCallInfo->iCallName );
       
  2133         // if diagnosticInfo available set diagnostic error code to DataStore    
       
  2134         if ( diagnosticInfo != ECCPErrorNone )
       
  2135             {
       
  2136             iDataStore.SetErrorCode( diagnosticInfo );
       
  2137             }
       
  2138         }
       
  2139 
       
  2140     errorCode = HandleEngineInfo( aCallId );  
       
  2141     iDataStore.SetErrorCode( ECCPErrorNone );
       
  2142 
       
  2143     numberOfCalls = iCallHandling.GetNumberOfCalls();
       
  2144 
       
  2145     if ( numberOfCalls == 0 )
       
  2146         {
       
  2147         // unmute mic
       
  2148         iDataStore.SetAudioMuteCommand( EFalse );
       
  2149         HandleSetAudioMute();
       
  2150         
       
  2151         if ( iEmergencyCallActive )
       
  2152             {
       
  2153             iExternalDataHandler.Set( EPEEmergencyCallInfo, EFalse );
       
  2154             iEmergencyCallActive = EFalse;
       
  2155             }
       
  2156         }
       
  2157 
       
  2158     // If there is a waiting call (voice or data) on 
       
  2159     // the line, and no other calls, play ringing tones for it.
       
  2160     else if ( numberOfCalls == 1 )
       
  2161         {
       
  2162         TPEState callState;
       
  2163         callState = iCallHandling.GetCallState( iWaitingCallId );
       
  2164         // EPEStateRinging equals MT call
       
  2165         if( callState == EPEStateRinging )
       
  2166             {
       
  2167             // unmute mic
       
  2168             iDataStore.SetAudioMuteCommand( EFalse );
       
  2169             HandleSetAudioMute();
       
  2170             TEFLOGSTRING2( KTAMESINT, 
       
  2171                 "CPEMessageHandler::HandleVoiceCallIdleState: aCallId = %d", 
       
  2172                 aCallId );
       
  2173             }
       
  2174         else 
       
  2175             {
       
  2176             TEFLOGSTRING2( KTAMESINT, 
       
  2177                 "CPEMessageHandler::HandleVoiceCallIdleState: callState = %d", 
       
  2178                 callState );
       
  2179             }
       
  2180         }
       
  2181     else
       
  2182         {
       
  2183         TEFLOGSTRING2( KTAMESINT, 
       
  2184             "CPEMessageHandler::HandleVoiceCallIdleState: numberOfCalls = %d", 
       
  2185             numberOfCalls );
       
  2186         }
       
  2187     
       
  2188     iDataStore.ResetCallInfo( aCallId );    
       
  2189     
       
  2190     //publish remote party info to Mediator after call info has been cleared.
       
  2191     UpdateRemotePartyInfo();    
       
  2192 
       
  2193     return returnValue;
       
  2194     }
       
  2195 
       
  2196 // -----------------------------------------------------------------------------
       
  2197 // CPEMessageHandler::ProcessPlayDTMFL
       
  2198 // Handles key down message from phone application
       
  2199 //
       
  2200 //  Method fecths key code value from the CallHandling subsystem and then
       
  2201 //  Method calls StartDtmfTone method from the CallHandling subsystem.
       
  2202 
       
  2203 // -----------------------------------------------------------------------------
       
  2204 // 
       
  2205 void CPEMessageHandler::ProcessPlayDTMFL()
       
  2206     {
       
  2207     const TChar keyCode = iDataStore.KeyCode();
       
  2208     
       
  2209     TBuf<1> keyCodeBuf;
       
  2210     keyCodeBuf.Append( keyCode );
       
  2211     
       
  2212     if ( KPEValidDTMFChars().Find( keyCodeBuf ) >= 0 )
       
  2213         {
       
  2214         if ( iCallHandling.GetNumberOfCalls() > 0 )
       
  2215             {   //There is ongoing call(s)
       
  2216             iCallHandling.StartDtmfTone( keyCode );
       
  2217             }
       
  2218         else
       
  2219             {
       
  2220             iGsmAudioData.PlayDtmfTone( keyCode );            
       
  2221             }
       
  2222         }
       
  2223         
       
  2224     }
       
  2225 
       
  2226 // -----------------------------------------------------------------------------
       
  2227 // CPEMessageHandler::ProcessEndDTMF
       
  2228 // Handles end playing DTMF message from phone application
       
  2229 // Method calls StopDtmfTone method from the CallHandling subsystem.
       
  2230 // -----------------------------------------------------------------------------
       
  2231 // 
       
  2232 TInt CPEMessageHandler::ProcessEndDTMF()
       
  2233     {
       
  2234     TInt returnValue( ECCPErrorNone ); 
       
  2235     // Number parser operations
       
  2236     if ( iCallHandling.GetNumberOfCalls() > 0 )
       
  2237         {   //There is ongoing call(s)
       
  2238         returnValue =  iCallHandling.StopDtmfTone();
       
  2239         }
       
  2240     iGsmAudioData.StopDtmfTonePlay();
       
  2241     return returnValue;
       
  2242     }
       
  2243 
       
  2244 
       
  2245 // -----------------------------------------------------------------------------
       
  2246 // CPEMessageHandler::HandleRejectCall
       
  2247 // Handles reject message from phone application
       
  2248 //  Method stops playing possible ringing tone and then
       
  2249 //  Method calls RejectCall method from the CallHandling subsystem.
       
  2250 // -----------------------------------------------------------------------------
       
  2251 // 
       
  2252 TInt CPEMessageHandler::HandleRejectCall
       
  2253         (
       
  2254         // None.
       
  2255         )
       
  2256     {
       
  2257     //Stops playing ringing tone
       
  2258     //Data call
       
  2259     iGsmAudioData.StopInbandTonePlay(); 
       
  2260     iAutomaticAnswerTimer->Cancel();
       
  2261     return iCallHandling.RejectCall( );
       
  2262     }
       
  2263 
       
  2264 // -----------------------------------------------------------------------------
       
  2265 // CPEMessageHandler::HandleResumeCall
       
  2266 // Handles resume message from phone application
       
  2267 // -----------------------------------------------------------------------------
       
  2268 // 
       
  2269 TInt CPEMessageHandler::HandleResumeCall()
       
  2270     {
       
  2271     return iCallHandling.ResumeCall();
       
  2272     }
       
  2273 
       
  2274 // -----------------------------------------------------------------------------
       
  2275 // CPEMessageHandler::HandleSendUssd
       
  2276 // Handles request from CPEParserMiscHandler
       
  2277 // -----------------------------------------------------------------------------
       
  2278 // 
       
  2279 TInt CPEMessageHandler::HandleSendUssd(
       
  2280         const TDesC& aString )   // USSD string to be sent.
       
  2281 
       
  2282     {
       
  2283     return iClientServices->SendUssd( aString );
       
  2284     }
       
  2285 
       
  2286 // -----------------------------------------------------------------------------
       
  2287 // CPEMessageHandler::HandleSimStateChanged
       
  2288 // Handles EPEMessageSIMStateChanged message from DosServer.
       
  2289 // -----------------------------------------------------------------------------
       
  2290 // 
       
  2291 void CPEMessageHandler::HandleSimStateChanged()  
       
  2292     {
       
  2293     iDataStore.SetSimState( iSimStateMonitor.SimState() );
       
  2294     }
       
  2295 
       
  2296 // -----------------------------------------------------------------------------
       
  2297 // CPEMessageHandler::HandleStartUpL
       
  2298 // Handles startup message from the phone application.
       
  2299 // Method calls StartUp method from the CallHandling subsystem and then
       
  2300 // Method calls StartUp method from the AudioHandling subsystem and then
       
  2301 // Method starts monitoring client originated calls.
       
  2302 // -----------------------------------------------------------------------------
       
  2303 // 
       
  2304 void CPEMessageHandler::HandleStartUp()
       
  2305     {
       
  2306     iCallHandling.StartUp( );
       
  2307     iGsmAudioData.StartUp( );
       
  2308     
       
  2309     iClientServices->StartMonitoring( );
       
  2310     }
       
  2311 
       
  2312 // -----------------------------------------------------------------------------
       
  2313 // CPEMessageHandler::HandleVideoCallConnected
       
  2314 // Handles data call logging in connected and idle state.
       
  2315 // -----------------------------------------------------------------------------
       
  2316 // 
       
  2317 TInt CPEMessageHandler::HandleVideoCallConnected(
       
  2318         const TInt aCallId )
       
  2319     {
       
  2320     //Stops possible remote alerting tone playing
       
  2321     TEFLOGSTRING( 
       
  2322         KTAINT, 
       
  2323         "PE  CPEMessageHandler::HandleVideoCallConnected > CPEGsmAudioData::StopInbandTonePlay()");
       
  2324     iGsmAudioData.StopInbandTonePlay(); 
       
  2325     // EFalse updates log information.
       
  2326     TInt errorCode = HandleEngineInfo( aCallId );
       
  2327     iDataStore.SetErrorCode( errorCode );
       
  2328     return ECCPErrorNone; 
       
  2329     }
       
  2330 
       
  2331 // -----------------------------------------------------------------------------
       
  2332 // CPEMessageHandler::HandleVideoCallIdle
       
  2333 // Handles data call logging and a possible waiting voice call in Idle state.
       
  2334 // -----------------------------------------------------------------------------
       
  2335 // 
       
  2336 TInt CPEMessageHandler::HandleVideoCallIdle(
       
  2337         const TInt aCallId )
       
  2338     {
       
  2339     TInt numberOfCalls;
       
  2340     //Stops possible remote alerting tone playing
       
  2341     TEFLOGSTRING( KTAINT,
       
  2342         "PE CPEMessageHandler::HandleVideoCallIdle > CPEGsmAudioData::StopInbandTonePlay()");
       
  2343     iGsmAudioData.StopInbandTonePlay(); 
       
  2344     HandleEngineInfo( aCallId );
       
  2345     iDataStore.SetErrorCode( ECCPErrorNone );
       
  2346     TInt returnValue( ECCPErrorNone );
       
  2347 
       
  2348     numberOfCalls = iCallHandling.GetNumberOfCalls();
       
  2349     if ( numberOfCalls == 0 )
       
  2350         {
       
  2351         iGsmAudioData.HandleCallEnding();
       
  2352 
       
  2353         // unmute mic
       
  2354         iDataStore.SetAudioMuteCommand( EFalse );
       
  2355         HandleSetAudioMute();
       
  2356         }
       
  2357     else if ( numberOfCalls == 1 )
       
  2358         {
       
  2359         TPEState callState;
       
  2360         callState = iCallHandling.GetCallState( iWaitingCallId );
       
  2361         // EPEStateRinging equals MT call
       
  2362         if ( callState == EPEStateRinging )
       
  2363             {
       
  2364             TEFLOGSTRING2( KTAMESINT, 
       
  2365                 "CPEMessageHandler::HandleVideoCallIdle: aCallId = %d", 
       
  2366                 aCallId );
       
  2367             iGsmAudioData.HandleCallEnding();
       
  2368             
       
  2369             // unmute mic
       
  2370             iDataStore.SetAudioMuteCommand( EFalse );
       
  2371             HandleSetAudioMute();
       
  2372             }
       
  2373         else 
       
  2374             {
       
  2375             TEFLOGSTRING2( KTAMESINT, 
       
  2376                 "CPEMessageHandler::HandleVideoCallIdle: callState = %d", 
       
  2377                 callState );
       
  2378             }
       
  2379         }
       
  2380     else
       
  2381         {
       
  2382         TEFLOGSTRING2( KTAMESINT, 
       
  2383             "CPEMessageHandler::HandleVideoCallIdle: numberOfCalls = %d", 
       
  2384             numberOfCalls );
       
  2385         }
       
  2386     iDataStore.ResetCallInfo( aCallId );
       
  2387     
       
  2388     //publish remote party info to Mediator after call info has been cleared.
       
  2389     UpdateRemotePartyInfo();    
       
  2390     
       
  2391     return returnValue;
       
  2392     }
       
  2393 
       
  2394 // -----------------------------------------------------------------------------
       
  2395 // CPEMessageHandler::HandleEmergencyCheck
       
  2396 // Check is given number emergency number.
       
  2397 // -----------------------------------------------------------------------------
       
  2398 // 
       
  2399 TInt CPEMessageHandler::HandleEmergencyCheck( )
       
  2400     {
       
  2401     TInt errorCode( ECCPErrorNone );
       
  2402     TPEPhoneNumber emergencyNumber;
       
  2403     TBool isEmergency;
       
  2404     emergencyNumber = iDataStore.PhoneNumber();
       
  2405 
       
  2406     errorCode = iClientServices->IsEmergencyPhoneNumber( emergencyNumber, isEmergency );
       
  2407     if ( isEmergency  && errorCode == ECCPErrorNone )
       
  2408         {
       
  2409         iModel.SendMessage( MEngineMonitor::EPEMessageValidEmergencyNumber );
       
  2410         }
       
  2411     else
       
  2412         {
       
  2413         iModel.SendMessage( MEngineMonitor::EPEMessageInValidEmergencyNumber );
       
  2414         }
       
  2415 
       
  2416     return errorCode;
       
  2417     }
       
  2418 
       
  2419 // -----------------------------------------------------------------------------
       
  2420 // CPEMessageHandler::HandlePhoneNumberEditedL
       
  2421 // Handles Phone Number Edited message from phone application, 
       
  2422 // called when user is used paste or delete command.
       
  2423 // Method check if there is ongoing call(s) if there is return ECCPErrorNone else
       
  2424 // method fecths phone number from the CPEEngineInfo class and 
       
  2425 // then method parsers phonenumber and then method process parsing result
       
  2426 // with PhoneParser and Phoneengine.
       
  2427 // (other items were commented in a header).
       
  2428 // -----------------------------------------------------------------------------
       
  2429 // 
       
  2430 void CPEMessageHandler::HandlePhoneNumberEditedL()
       
  2431     {
       
  2432     TBool isServiceCode( EFalse );
       
  2433 
       
  2434     iOptions->SetOptionStatus( KPhoneOptionInCall, 
       
  2435         ( iCallHandling.GetNumberOfCalls() > 0 ) );
       
  2436 
       
  2437     iOptions->SetOptionStatus( KPhoneOptionSend, EFalse );
       
  2438     iOptions->SetOptionStatus( KPhoneOptionVoipCall, EFalse );
       
  2439 
       
  2440     if( iParser->ParseL( iDataStore.PhoneNumber(), *iResult, *iOptions ) )
       
  2441         {
       
  2442         isServiceCode = ETrue;
       
  2443         iGsmParserErrorCode = ECCPErrorNone;
       
  2444         iParserHandlerContainer->ProcessL( *iResult );
       
  2445         }
       
  2446     else // check for service codes that require SEND
       
  2447         {
       
  2448         iOptions->SetOptionStatus( KPhoneOptionSend, ETrue );
       
  2449         if ( iParser->ParseL( iDataStore.PhoneNumber(), *iResult, *iOptions ) )
       
  2450             {
       
  2451             // if there is an incoming call only certain codes are allowed       
       
  2452             if ( iCallHandling.IsCallInState( EPEStateRinging ) &&
       
  2453                  !iCallHandling.IsCallInState( EPEStateConnected ) )
       
  2454                 {
       
  2455                 isServiceCode = PhoneGsmParser::IsAllowedForArriving( *iResult );
       
  2456                 }
       
  2457             else
       
  2458                 {
       
  2459                 const PhoneGsmParser::TContentType type = 
       
  2460                     PhoneGsmParser::DetermineContentType( *iResult );
       
  2461                     
       
  2462                 if ( type == PhoneGsmParser::EContentSupplementaryService ||
       
  2463                      type == PhoneGsmParser::EContentUnstructuredService )
       
  2464                     {
       
  2465                     isServiceCode = ETrue;
       
  2466                     }
       
  2467                 }
       
  2468             }
       
  2469         }
       
  2470         
       
  2471     iDataStore.SetPhoneNumberIsServiceCode( isServiceCode );    
       
  2472     }
       
  2473 
       
  2474 // -----------------------------------------------------------------------------
       
  2475 // CPEMessageHandler::AutomaticAnswer
       
  2476 // Checks if automatic answer is defined for connected accessory.
       
  2477 // -----------------------------------------------------------------------------
       
  2478 // 
       
  2479 TBool CPEMessageHandler::AutomaticAnswer( const TInt aCallId ) const
       
  2480     {
       
  2481     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::AutomaticAnswer <" );
       
  2482     
       
  2483     TInt automaticAnswer( EFalse );
       
  2484     TInt accessory( 0 );
       
  2485          
       
  2486     if ( iCallHandling.GetNumberOfCalls() > 1 ) // The new call need to be the first in the array
       
  2487         {
       
  2488         return EFalse;
       
  2489         }
       
  2490         
       
  2491     iExternalDataHandler.Get( EPEAccessoryMode, accessory );
       
  2492     
       
  2493     switch ( accessory )
       
  2494         {
       
  2495         case EAccModeWiredHeadset:    //Wired headset
       
  2496         case EAccModeWirelessHeadset: //Wireless headset
       
  2497             {
       
  2498             // Safe to ignore error code here, 
       
  2499             // automatic answer setting just equals zero == EFalse if it fails
       
  2500             iExternalDataHandler.Get( EPEAutomaticAnswerHeadsetSetting, automaticAnswer );
       
  2501             break;
       
  2502             }
       
  2503         case EAccModeWiredCarKit:     //Wired carkit
       
  2504             {
       
  2505             iExternalDataHandler.Get( EPEAutomaticAnswerCarkitSetting, automaticAnswer );
       
  2506             break;
       
  2507             }           
       
  2508         case EAccModeWirelessCarKit:  //Wireless carkit
       
  2509             {
       
  2510             iExternalDataHandler.Get( EPEAutomaticAnswerWirelessCarkitSetting, automaticAnswer );                
       
  2511             break;
       
  2512             }           
       
  2513         case EAccModeLoopset:         //Loopset
       
  2514             {
       
  2515             iExternalDataHandler.Get( EPEAutomaticAnswerLoopsetSetting, automaticAnswer );                
       
  2516             break;
       
  2517             }           
       
  2518         case EAccModeMusicStand:      //Musicstand
       
  2519             {
       
  2520             iExternalDataHandler.Get( EPEAutomaticAnswerMusicStandSetting, automaticAnswer );                
       
  2521             break;
       
  2522             }
       
  2523          default:
       
  2524             break;
       
  2525          }
       
  2526 
       
  2527     if ( automaticAnswer )
       
  2528         {
       
  2529         TFileName noneFilepath;
       
  2530         noneFilepath.Append( TParsePtrC( PathInfo::RomRootPath() ).Drive() );
       
  2531         noneFilepath.Append( KProfileNoSoundPath() );
       
  2532         
       
  2533         TProfileRingingType ringingType = iDataStore.RingingType(); 
       
  2534         TPEContactFileName ringingTone = iDataStore.RingingTone( aCallId );
       
  2535          
       
  2536         if ( ringingType == EProfileRingingTypeBeepOnce ||
       
  2537              ringingType == EProfileRingingTypeSilent ||
       
  2538              ringingTone == noneFilepath )
       
  2539             {
       
  2540             automaticAnswer = EFalse;
       
  2541             }
       
  2542         } 
       
  2543     TEFLOGSTRING2( KTAINT, 
       
  2544         "PE CPEMessageHandler::AutomaticAnswer > ret: %d", automaticAnswer );
       
  2545     return automaticAnswer;
       
  2546     }
       
  2547 
       
  2548 // -----------------------------------------------------------------------------
       
  2549 // CPEMessageHandler::HandleStopInbandTonePlay
       
  2550 // Stop playing a InBand tone
       
  2551 // -----------------------------------------------------------------------------
       
  2552 //
       
  2553 void CPEMessageHandler::HandleStopInbandTonePlay()
       
  2554     {
       
  2555     iGsmAudioData.StopInbandTonePlay();
       
  2556     }
       
  2557 
       
  2558 // -----------------------------------------------------------------------------
       
  2559 // CPEMessageHandler::HandleAutomaticAnswerOff
       
  2560 // Gets EPEMessageAutomaticAnswerOff from UI and makes soft cancelation of the
       
  2561 // automatic answer when needed
       
  2562 // -----------------------------------------------------------------------------
       
  2563 //
       
  2564 void CPEMessageHandler::HandleAutomaticAnswerOff() const
       
  2565     {
       
  2566     iAutomaticAnswerTimer->Cancel();
       
  2567     }
       
  2568 
       
  2569 // -----------------------------------------------------------------------------
       
  2570 // CPEMessageHandler::HandleATDialingStarted()
       
  2571 // Handles AT dialing completed message from Phone UI
       
  2572 // -----------------------------------------------------------------------------
       
  2573 //
       
  2574 void CPEMessageHandler::HandleATDialingStarted( const TBool aSucceed ) const
       
  2575     {
       
  2576     iClientServices->CommandHandlerMonitor()->DoCompleteCmdAtd( aSucceed ); 
       
  2577     }    
       
  2578 
       
  2579 // -----------------------------------------------------------------------------
       
  2580 // CPEMessageHandler::IsEmergencyAllowed()
       
  2581 // Checks if emergency call is allowed. 
       
  2582 // -----------------------------------------------------------------------------
       
  2583 //
       
  2584 TBool CPEMessageHandler::IsEmergencyAllowed() const
       
  2585     {
       
  2586     TBool networkConnectionAllowed( EFalse );
       
  2587     //It is safe to ignore error code here: a default value of EFalse is used if the get fails
       
  2588     iExternalDataHandler.Get( EPENetworkConnectionAllowedSetting, networkConnectionAllowed );
       
  2589     return networkConnectionAllowed;
       
  2590     }
       
  2591     
       
  2592 // -----------------------------------------------------------------------------
       
  2593 // CPEMessageHandler::HandleClientCallData()
       
  2594 // Handle Client Call Data.
       
  2595 // -----------------------------------------------------------------------------
       
  2596 //
       
  2597 void CPEMessageHandler::HandleClientCallData() 
       
  2598     {
       
  2599     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleClientCallData" );
       
  2600     
       
  2601     CPhCltDialData* dialData = iClientServices->CallRequestMonitor()->ClientDialData();
       
  2602     
       
  2603     // Set already known Client information
       
  2604     SetClientData( *dialData );
       
  2605     
       
  2606     if ( dialData->CallType() == EPhCltVideo || dialData->CallType() == EPhCltForcedVideo )
       
  2607         {
       
  2608         iDataStore.SetCallTypeCommand( EPECallTypeVideo );
       
  2609         }
       
  2610     else if( dialData->CallType() == EPhCltCallVoIP )
       
  2611         {
       
  2612         iDataStore.SetCallTypeCommand( EPECallTypeVoIP );
       
  2613         }
       
  2614     else
       
  2615         {
       
  2616         iDataStore.SetCallTypeCommand( EPECallTypeCSVoice );
       
  2617         }
       
  2618         
       
  2619     // End other calls before dial SAT call
       
  2620     if ( dialData->EndOtherCalls() )
       
  2621         {
       
  2622         HandleReleaseAll();
       
  2623         TEFLOGSTRING( KTAINT,
       
  2624             "PE CPEMessageHandler::HandleClientCallData > HandleReleaseAll()" );
       
  2625          }       
       
  2626     }    
       
  2627     
       
  2628 // -----------------------------------------------------------------------------
       
  2629 // CPEMessageHandler::ClearCallAudio
       
  2630 // Notifies audio handling that there is no active call and audio should be routed
       
  2631 // accordingly.
       
  2632 // -----------------------------------------------------------------------------
       
  2633 //
       
  2634 void CPEMessageHandler::ClearCallAudio()
       
  2635     {
       
  2636     TEFLOGSTRING( KTAMESINT, "PE CPEMGsmessageHandler::ClearCallAudio()" );
       
  2637     TBool restrictingCalls( EFalse );
       
  2638 
       
  2639     if ( iCallHandling.GetNumberOfCalls() > 0 )
       
  2640         {
       
  2641         restrictingCalls = 
       
  2642             // Single call states restricting the devsound notification
       
  2643             iCallHandling.IsCallInState( EPEStateConnected ) ||
       
  2644             iCallHandling.IsCallInState( EPEStateConnecting ) ||
       
  2645             iCallHandling.IsCallInState( EPEStateDialing ) ||
       
  2646             iCallHandling.IsCallInState( EPEStateHeld ) ||
       
  2647             // Conference call states restricting the devsound notification
       
  2648             ( iDataStore.CallState( KPEConferenceCallID )== EPEStateConnectedConference ) ||
       
  2649             ( iDataStore.CallState( KPEConferenceCallID ) == EPEStateCreatingConference ) ||
       
  2650             ( iDataStore.CallState( KPEConferenceCallID ) == EPEStateGoingOneToOne ) ||
       
  2651             ( iDataStore.CallState( KPEConferenceCallID ) == EPEStateAddingConferenceMember ) ||
       
  2652             ( iDataStore.CallState( KPEConferenceCallID ) == EPEStateAddedConferenceMember ) ||
       
  2653             ( iDataStore.CallState( KPEConferenceCallID ) == EPEStateDroppingConferenceMember ) ||
       
  2654             ( iDataStore.CallState( KPEConferenceCallID ) == EPEStateDroppedConferenceMember );
       
  2655         }
       
  2656     
       
  2657     if ( restrictingCalls == EFalse )
       
  2658         {
       
  2659         // deactivate audio
       
  2660         TEFLOGSTRING( KTAMESINT, "PE CPEMGsmessageHandler::ClearCallAudio() Deactivating" );
       
  2661         iGsmAudioData.HandleCallEnding();
       
  2662         }
       
  2663     }
       
  2664 
       
  2665 // -----------------------------------------------------------------------------
       
  2666 // CPEMessageHandler::HandleSwitchToVideoOrVoice 
       
  2667 // This method handle EPEMessageSwitchToVideoOrVoice message. If current call id
       
  2668 // is Data then call will be switched to Voice call and the other way around. 
       
  2669 // Method set current phonenumber to dataStore and get call parameter and call 
       
  2670 // hangUp to current call. 
       
  2671 // When hangUp is completed (EPEMessageIdle was sent) sequence will be continue 
       
  2672 // from ContinueSwitchToCall method.
       
  2673 // -----------------------------------------------------------------------------
       
  2674 //
       
  2675 TInt CPEMessageHandler::HandleSwitchToVideoOrVoice( const TInt aCallId )
       
  2676     {
       
  2677     // First get the current phone number and then end voice call
       
  2678     // or video call.
       
  2679     TInt err( ECCPErrorNone );
       
  2680     
       
  2681     TEFLOGSTRING2( KTAINT, 
       
  2682         "PE CPEMessageHandler::HandleSwitchToVideoOrVoice, aCallId : %d", aCallId );
       
  2683     // if out of memory case then phonenumber is already datastore.
       
  2684     if( aCallId != KPECallIdNotUsed )
       
  2685         {
       
  2686         if ( iDataStore.CallDirection( aCallId ) == RMobileCall::EMobileOriginated )
       
  2687             {
       
  2688             iDataStore.SetSwitchToNumberCommand( iDataStore.WholeOutgoingPhoneNumber( aCallId ) );  
       
  2689             // Clear phonenumber to prevent using the wrong number in MO video call.
       
  2690             iDataStore.SetPhoneNumber( KNullDesC() );
       
  2691             }
       
  2692         else
       
  2693             {
       
  2694             iDataStore.SetSwitchToNumberCommand( iDataStore.RemotePhoneNumber( aCallId ) );
       
  2695             // Remote phone number must be stored as the phone number in case of low-memory situation where 
       
  2696             // an MO voice call can be initiated after failing to answer an MT video call.
       
  2697             iDataStore.SetPhoneNumber( iDataStore.RemotePhoneNumber( aCallId ) );
       
  2698             }
       
  2699 
       
  2700         err = HandleReleaseCall();
       
  2701         }
       
  2702 
       
  2703     return err;
       
  2704     }
       
  2705     
       
  2706 // -----------------------------------------------------------------------------
       
  2707 // CPEMessageHandler::ContinueSwitchToCall
       
  2708 // Metdod calls dial to multimedia call or voice call.
       
  2709 // -----------------------------------------------------------------------------
       
  2710 //
       
  2711 TInt CPEMessageHandler::ContinueSwitchToCall( const TInt aCallId )  
       
  2712     {
       
  2713     TEFLOGSTRING2( KTAINT, 
       
  2714         "PE CPEMessageHandler::ContinueSwitchToCall, aCallId : %d", aCallId );
       
  2715     TInt callId;
       
  2716     TInt errorCode( ECCPErrorNone );
       
  2717   
       
  2718     TPEPhoneNumber phoneNumber = iDataStore.SwitchToNumberCommand();
       
  2719     TEFLOGSTRING2( KTAINT, 
       
  2720         "PE CPEMessageHandler::ContinueSwitchToCall, phoneNumber : %S", 
       
  2721         &phoneNumber );
       
  2722 
       
  2723     // Check is current call voice or video
       
  2724     if ( CallIdCheck::IsVoice( aCallId ) )
       
  2725         {
       
  2726         // Create new video call to same phonenumber
       
  2727         iDataStore.SetCallTypeCommand( EPECallTypeVideo );
       
  2728         errorCode = iCallHandling.DialMultimedia( phoneNumber, callId );
       
  2729         }
       
  2730     else if ( CallIdCheck::IsVideo( aCallId ) )
       
  2731         {
       
  2732         // Create new voice call to same phonenumber
       
  2733         iDataStore.SetCallTypeCommand( EPECallTypeCSVoice );
       
  2734         errorCode = iCallHandling.DialCall( phoneNumber, callId );
       
  2735         }
       
  2736     TEFLOGSTRING2( KTAINT, 
       
  2737         "PE CPEMessageHandler::ContinueSwitchToCall(), error : %d", errorCode );    
       
  2738     return errorCode;    
       
  2739     }
       
  2740 
       
  2741 // -----------------------------------------------------------------------------
       
  2742 // CPEMessageHandler::RemovePreAndPostFix
       
  2743 // Remmove supplementary service prefix and dtmf postfix.
       
  2744 // Phone number can contain following parts: supplementary
       
  2745 // service prefix, main part and dtmf postfix.
       
  2746 // -----------------------------------------------------------------------------
       
  2747 //
       
  2748 void CPEMessageHandler::RemovePreAndPostFix( 
       
  2749         TDes& aString )
       
  2750     {
       
  2751     // Check that string contains only valid dtmf characters.
       
  2752     if ( IsValidDtmfString( aString ))
       
  2753         {
       
  2754         TLex input( aString ); 
       
  2755         
       
  2756         RemovePrefix( input );
       
  2757         // Take number part.
       
  2758         HandleNumberPart( input, aString );        
       
  2759         }
       
  2760     }
       
  2761 
       
  2762 // -----------------------------------------------------------------------------
       
  2763 // CPEMessageHandler::RemovePrefix
       
  2764 // Removes clir suppress/invoke prefix in the string.
       
  2765 // -----------------------------------------------------------------------------
       
  2766 //
       
  2767 void CPEMessageHandler::RemovePrefix( 
       
  2768         TLex& aLex )
       
  2769     {
       
  2770     TPtrC remainder( aLex.Remainder() );
       
  2771 
       
  2772     if ( EqualsLeft( remainder, KPEClirSuppress ) )
       
  2773         {
       
  2774         aLex.Inc( KPEClirSuppress().Length() );
       
  2775         }
       
  2776     else if ( EqualsLeft( remainder, KPEClirInvoke ) )
       
  2777         {
       
  2778         aLex.Inc( KPEClirSuppress().Length() );
       
  2779         }
       
  2780     }
       
  2781 
       
  2782 // -----------------------------------------------------------------------------
       
  2783 // CPEMessageHandler::HandleNumberPart
       
  2784 // Search the main part of the phone number.
       
  2785 // -----------------------------------------------------------------------------
       
  2786 //
       
  2787 void CPEMessageHandler::HandleNumberPart(
       
  2788         TLex& aLex,
       
  2789         TDes& aNumberPart )
       
  2790     {   
       
  2791     TLexMark start;
       
  2792     aLex.Mark( start );
       
  2793   
       
  2794     // Optional forced call prefixes. 
       
  2795     if ( aLex.Peek() == KPENumberAsterisk || 
       
  2796          aLex.Peek() == KPENumberHash ) 
       
  2797          {
       
  2798          aLex.Inc(); 
       
  2799          }
       
  2800          
       
  2801     // Optional international prefix. 
       
  2802     if ( aLex.Peek() == KPENumberPlus ) 
       
  2803         { 
       
  2804         aLex.Inc(); 
       
  2805         } 
       
  2806 
       
  2807     // And the rest of number. 
       
  2808     while ( ( aLex.Peek().IsDigit() ) ||  
       
  2809             ( aLex.Peek() == KPENumberAsterisk ) || 
       
  2810             ( aLex.Peek() == KPENumberHash ) ) 
       
  2811         {
       
  2812         aLex.Inc(); 
       
  2813         }
       
  2814 
       
  2815     TPtrC mainpart( aLex.MarkedToken( start ) );
       
  2816     const TInt length = mainpart.Length();
       
  2817     if ( length <= KPEPhoneNumberMaxLength )
       
  2818         {
       
  2819         aNumberPart.Copy( mainpart );
       
  2820         }
       
  2821     }
       
  2822 
       
  2823 // -----------------------------------------------------------------------------
       
  2824 // CPEMessageHandler::EqualsLeft
       
  2825 // -----------------------------------------------------------------------------
       
  2826 //
       
  2827 TBool CPEMessageHandler::EqualsLeft( 
       
  2828         const TDesC& aString, 
       
  2829         const TDesC& aPrefix )
       
  2830     {
       
  2831     TBool result = EFalse;
       
  2832 
       
  2833     if ( aPrefix.Length() <= aString.Length() )
       
  2834         {
       
  2835         TPtrC part( aString.Left( aPrefix.Length() ) );
       
  2836 
       
  2837         result = ( part == aPrefix );
       
  2838         }
       
  2839 
       
  2840     return result;
       
  2841     }
       
  2842 
       
  2843 // -----------------------------------------------------------------------------
       
  2844 // CPEMessageHandler::HandleReplaceActive
       
  2845 // -----------------------------------------------------------------------------
       
  2846 // 
       
  2847 TInt CPEMessageHandler::HandleReplaceActive()
       
  2848     {
       
  2849     return iCallHandling.ReplaceActive();
       
  2850     }
       
  2851 
       
  2852 // -----------------------------------------------------------------------------
       
  2853 // CPEMessageHandler::CheckIfPhoneIsLockedL
       
  2854 // -----------------------------------------------------------------------------
       
  2855 //
       
  2856 void CPEMessageHandler::CheckIfPhoneIsLockedL()
       
  2857     {
       
  2858     // Check if phone is locked
       
  2859     TInt  keyLockStatus( EAutolockStatusUninitialized );
       
  2860     TInt err = RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, keyLockStatus );
       
  2861     const TBool phoneIsLocked = ( keyLockStatus > EAutolockOff );
       
  2862 
       
  2863     if ( phoneIsLocked && err == KErrNone )
       
  2864         {
       
  2865         // New call is not possible if device lock is on 
       
  2866         TEFLOGSTRING2( KTAERROR,
       
  2867             "PE CPEMessageHandler::CheckIfPhoneIsLockedL, keyLockStatus : %d", keyLockStatus );
       
  2868         User::Leave( ECCPErrorAuthenticationFailed );
       
  2869         }
       
  2870     }
       
  2871 
       
  2872 // -----------------------------------------------------------------------------
       
  2873 // CPEMessageHandler::IsActiveVideo
       
  2874 // Checks if there are any connected video calls
       
  2875 // -----------------------------------------------------------------------------
       
  2876 // 
       
  2877 TBool CPEMessageHandler::IsActiveVideo()
       
  2878     {
       
  2879     TBool activeVideoCall( EFalse );
       
  2880     
       
  2881     TInt callId = iCallHandling.GetCallIdByState( EPEStateConnected );
       
  2882     if ( callId > ECCPErrorNotFound && iDataStore.CallType( callId ) == EPECallTypeVideo )
       
  2883         {
       
  2884         activeVideoCall = ETrue;
       
  2885         }
       
  2886     return activeVideoCall;
       
  2887     }
       
  2888 
       
  2889 // -----------------------------------------------------------------------------
       
  2890 // CPEMessageHandler::HandleServiceEnabled
       
  2891 // -----------------------------------------------------------------------------
       
  2892 //
       
  2893 TInt CPEMessageHandler::HandleServiceEnabled()
       
  2894     {
       
  2895     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleServiceEnabled ");
       
  2896 
       
  2897     
       
  2898     return iVoipNumberHandler->ContinueVoipDial();
       
  2899     }
       
  2900 
       
  2901 // -----------------------------------------------------------------------------
       
  2902 // CPEMessageHandler::HandleRemotePartyInfoChanged
       
  2903 // -----------------------------------------------------------------------------
       
  2904 //
       
  2905 void CPEMessageHandler::HandleRemotePartyInfoChanged()
       
  2906     {
       
  2907     UpdateRemotePartyInfo();      
       
  2908     }
       
  2909 
       
  2910 
       
  2911 // -----------------------------------------------------------------------------
       
  2912 // CPEMessageHandler::HandleUnattendedTransferRequestResponse
       
  2913 // -----------------------------------------------------------------------------
       
  2914 //
       
  2915 TInt CPEMessageHandler::HandleUnattendedTransferRequestResponse( 
       
  2916         TBool aAcceptRequest )
       
  2917     {
       
  2918     TEFLOGSTRING( KTAINT, 
       
  2919         "PE CPEMessageHandler::HandleUnattendedTransferRequestResponse" );
       
  2920     
       
  2921     if ( aAcceptRequest )
       
  2922         {
       
  2923         return iCallHandling.AcceptUnattendedTransfer();
       
  2924         }
       
  2925     else
       
  2926         {
       
  2927         return iCallHandling.RejectUnattendedTransfer();
       
  2928         }
       
  2929     }
       
  2930 
       
  2931 // -----------------------------------------------------------------------------
       
  2932 // CPEMessageHandler::HandleUnattendedTransfer
       
  2933 // -----------------------------------------------------------------------------
       
  2934 //
       
  2935 TInt CPEMessageHandler::HandleUnattendedTransfer()
       
  2936     {
       
  2937     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleUnattendedTransfer ");
       
  2938     TInt errorCode = iCallHandling.DoUnattendedTransfer( 
       
  2939             iDataStore.TransferTargetCommand() );
       
  2940      
       
  2941     return errorCode;
       
  2942     }
       
  2943 
       
  2944 // -----------------------------------------------------------------------------
       
  2945 // CPEMessageHandler::ForwardCallToAddress
       
  2946 // -----------------------------------------------------------------------------
       
  2947 //
       
  2948 TInt CPEMessageHandler::ForwardCallToAddress()
       
  2949     {
       
  2950     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::ForwardCallToAddress ");
       
  2951     TInt errorCode = iCallHandling.ForwardCallToAddress( 
       
  2952             iDataStore.ForwardAddressIndex() );
       
  2953      
       
  2954     return errorCode;
       
  2955     }
       
  2956 
       
  2957 // -----------------------------------------------------------------------------
       
  2958 // CPEMessageHandler::HandleDisableService
       
  2959 // -----------------------------------------------------------------------------
       
  2960 //
       
  2961 void CPEMessageHandler::HandleDisableService()
       
  2962     {
       
  2963     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDisableService ");
       
  2964     iServiceHandling.DisableService();
       
  2965     }
       
  2966 
       
  2967 // -----------------------------------------------------------------------------
       
  2968 // CPEMessageHandler::IsValidDtmfString
       
  2969 // -----------------------------------------------------------------------------
       
  2970 //
       
  2971 TBool CPEMessageHandler::IsValidDtmfString( TDes& aString )
       
  2972     { 
       
  2973     TBool validDtmf = ETrue;
       
  2974 
       
  2975     for( TInt i = 0; i < aString.Length(); i++ )
       
  2976         {
       
  2977         if ( KErrNotFound == KValidDtmfChars().Locate( aString[i] ) )
       
  2978             {
       
  2979             validDtmf = EFalse;
       
  2980             break;
       
  2981             }      
       
  2982         }
       
  2983     return validDtmf;
       
  2984     }
       
  2985 
       
  2986 // -----------------------------------------------------------------------------
       
  2987 // CPEMessageHandler::UpdateRemotePartyInfo
       
  2988 // -----------------------------------------------------------------------------
       
  2989 //
       
  2990 void CPEMessageHandler::UpdateRemotePartyInfo( )
       
  2991     { 
       
  2992     CPERemotePartyInfoMediator* mediatorUpdater = iModel.MediatorCommunicationHandler();
       
  2993     if ( mediatorUpdater ) 
       
  2994         {
       
  2995         mediatorUpdater->UpdateRemotePartyInfo();
       
  2996         }
       
  2997     }
       
  2998 	
       
  2999 //  End of File