phoneengine/phonemodel/src/cpemessagehandler.cpp
changeset 37 ba76fc04e6c2
child 45 6b911d05207e
equal deleted inserted replaced
36:2eacb6118286 37:ba76fc04e6c2
       
     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 ( EPECallOriginSAT != iDataStore.CallOrigin(aCallId) && 
       
  1322        ( aCallId != KPEEmergencyCallId ) )
       
  1323         {
       
  1324         TEFLOGSTRING2( 
       
  1325             KTAINT, 
       
  1326             "PE CPEMessageHandler::UpdateClientInfo, match phone number: '%S'", 
       
  1327             &iDataStore.RemotePhoneNumber( aCallId ) );
       
  1328         if ( clientInformation.ContactLink().Length() > 0 )
       
  1329             {
       
  1330             errorCode = iContactHandling.FindContactInfoSync( 
       
  1331             aCallId, 
       
  1332             EPEFindWithContactId );
       
  1333             }    
       
  1334         else
       
  1335             {
       
  1336             errorCode = iContactHandling.FindContactInfoSync( 
       
  1337             aCallId, 
       
  1338             EPEFindWithPhoneNumber );            
       
  1339             }
       
  1340             
       
  1341         TEFLOGSTRING2( 
       
  1342             KTAINT, 
       
  1343             "PE CPEMessageHandler::UpdateClientInfo > MPEContactHandling::FindContactInfoSync( EPEFindWithPhoneNumber ), error code: %d", 
       
  1344             errorCode );
       
  1345         }
       
  1346     
       
  1347     // Calls have to log also without a contact (ECCPErrorNotFound).
       
  1348     if ( errorCode == ECCPErrorNone || errorCode == ECCPErrorNotFound)
       
  1349         {
       
  1350         // Set name to EngineInfo
       
  1351         SetName( aCallId );
       
  1352         }
       
  1353      return errorCode;   
       
  1354      }   
       
  1355     
       
  1356 // -----------------------------------------------------------------------------
       
  1357 // CPEMessageHandler::CheckAndHideIdentity
       
  1358 // -----------------------------------------------------------------------------
       
  1359 // 
       
  1360 void CPEMessageHandler::CheckAndHideIdentity(
       
  1361     const TInt aCallId )   
       
  1362     {
       
  1363     // If call is emergency call, phonenumber must be fetched from engine info
       
  1364     // Log type must be recognized from call id also, because in idle state
       
  1365     // TSY has cleaned call info information
       
  1366     RMobileCall::TMobileCallRemoteIdentityStatus tempIdentity;
       
  1367     tempIdentity = iDataStore.RemoteIdentity( aCallId );
       
  1368     
       
  1369     TEFLOGSTRING2( KTAINT,
       
  1370         "PE CPEMessageHandler::CheckAndHideIdentity, Identity: %d", tempIdentity );
       
  1371     if ( iCallInfo->iEmergency || aCallId == KPEEmergencyCallId ) 
       
  1372         {
       
  1373         iDataStore.SetRemotePhoneNumberType( EPEEmergencyNumber, aCallId );
       
  1374         }
       
  1375     else if( iDataStore.CallDirection( aCallId ) != RMobileCall::EMobileOriginated )
       
  1376         {
       
  1377         switch( tempIdentity )
       
  1378             {
       
  1379             case RMobileCall::ERemoteIdentitySuppressed:
       
  1380                 {
       
  1381                 // It is neccessary to perform an additional check for available
       
  1382                 // remote party phone number to comply with Italian operator
       
  1383                 // requirement: "If CLIR is active but network still provides
       
  1384                 // the device with a phone number, it should not be blocked
       
  1385                 // but passed to a client when requested."
       
  1386                 if( iDataStore.RemotePhoneNumber( aCallId ).Length() == 0 )
       
  1387                     {
       
  1388                     HideIdentification( EPEPrivateNumber, aCallId );
       
  1389                     }
       
  1390                 else
       
  1391                     {
       
  1392                     // Align remote identity with remote phone number availability.
       
  1393                     iDataStore.SetRemoteIdentity( RMobileCall::ERemoteIdentityAvailable, aCallId );
       
  1394                     }
       
  1395                 break;
       
  1396                 }
       
  1397             case RMobileCall::ERemoteIdentityAvailableNoCliRejectedByUser:
       
  1398                 {
       
  1399                 HideIdentification( EPEPrivateNumber, aCallId );
       
  1400                 break;
       
  1401                 }
       
  1402             case RMobileCall::ERemoteIdentityUnknown:
       
  1403             case RMobileCall::ERemoteIdentityAvailableNoCliInteractionWithOtherService:
       
  1404             case RMobileCall::ERemoteIdentityUnavailableNoCliInteractionWithOtherService:
       
  1405             case RMobileCall::ERemoteIdentityAvailableNoCliCoinOrPayphone:
       
  1406             case RMobileCall::ERemoteIdentityUnavailableNoCliCoinOrPayphone:
       
  1407             case RMobileCall::ERemoteIdentityAvailableNoCliUnavailable:
       
  1408                 {
       
  1409                 HideIdentification( EPEUnknownNumber, aCallId );
       
  1410                 break;
       
  1411                 }
       
  1412             case RMobileCall::ERemoteIdentityAvailable:
       
  1413             default:
       
  1414                 {
       
  1415                 TEFLOGSTRING( KTAINT,
       
  1416                     "PE CPEMessageHandler::CheckAndHideIdentity, CLI available" );
       
  1417                 break;
       
  1418                 }
       
  1419             }
       
  1420         }
       
  1421     }
       
  1422     
       
  1423 // -----------------------------------------------------------------------------
       
  1424 // CPEMessageHandler::FindCallInfo
       
  1425 // Return callInfo from Etel/TSY.
       
  1426 // -----------------------------------------------------------------------------
       
  1427 // 
       
  1428 TInt CPEMessageHandler::FindCallInfo(
       
  1429         const TInt aCallId )
       
  1430     {
       
  1431     TInt errorCode( ECCPErrorNone );
       
  1432     if ( CallIdCheck::IsVoice( aCallId ) || CallIdCheck::IsVideo( aCallId ) )
       
  1433         {
       
  1434         // Single call
       
  1435         errorCode = iCallHandling.GetCallInfo( *iCallInfo, aCallId );
       
  1436         TEFLOGSTRING3( 
       
  1437             KTAREQOUT, 
       
  1438             "CNT CPEMessageHandler::FindCallInfo > MPECallHandling::GetCallInfo, call id: %d, error code: %d", 
       
  1439             aCallId, 
       
  1440             errorCode );
       
  1441         TEFLOGSTRING2( 
       
  1442             KTAINT, 
       
  1443             "CNT CPEMessageHandler::FindCallInfo, remote number: '%S'", 
       
  1444             &iCallInfo->iRemoteParty.iRemoteNumber );
       
  1445         TEFLOGSTRING2( 
       
  1446             KTAINT, 
       
  1447             "CNT CPEMessageHandler::FindCallInfo, direction: %d", 
       
  1448             iDataStore.CallDirection( aCallId ) );
       
  1449         TEFLOGSTRING2( 
       
  1450             KTAINT, 
       
  1451             "CNT CPEMessageHandler::FindCallInfo, id status: %d", 
       
  1452             iCallInfo->iRemoteParty.iRemoteIdStatus );
       
  1453         }
       
  1454     else
       
  1455         {
       
  1456         // We don't log the master conference call and other unknown calls.
       
  1457         errorCode = KErrUnknown;
       
  1458         }
       
  1459     return errorCode;
       
  1460     }
       
  1461 
       
  1462 // -----------------------------------------------------------------------------
       
  1463 // CPEMessageHandler::SetPhoneNumberForCallLogging
       
  1464 // Set phonenumber for call logging
       
  1465 // -----------------------------------------------------------------------------
       
  1466 // 
       
  1467 void CPEMessageHandler::SetPhoneNumberForCallLogging(
       
  1468         const TInt aCallId )
       
  1469     {
       
  1470     // if call is MO then the phonenumber must be stored from dialled party.
       
  1471     if ( iDataStore.CallDirection( aCallId ) == RMobileCall::EMobileOriginated )
       
  1472         {
       
  1473 
       
  1474         TPEPhoneNumber number;        
       
  1475         const TPECallOrigin origin = iDataStore.CallOrigin( aCallId );
       
  1476         
       
  1477         if ( origin == EPECallOriginSAT )
       
  1478             {
       
  1479             // Dont set for SAT calls >> number not logged
       
  1480             }
       
  1481         else if( iDataStore.PhoneNumber().Length() )
       
  1482             {
       
  1483             // Phonenumber given by user, includes pfe- and postfix.
       
  1484             number = iDataStore.PhoneNumber();
       
  1485             }   
       
  1486         else
       
  1487             {
       
  1488             // If call is made using ETel api, then phonenumber must take from callinfo.
       
  1489             number = iCallInfo->iDialledParty.iTelNumber;
       
  1490             }
       
  1491         
       
  1492         
       
  1493         // WholeOutgoingPhoneNumber should set only one time because in connected state 
       
  1494         // PhoneNumber is cleaned from datastore.
       
  1495         if( !iDataStore.WholeOutgoingPhoneNumber( aCallId ).Length() )
       
  1496             {
       
  1497         
       
  1498             TEFLOGSTRING2( KTAINT,
       
  1499                     "PE CPEMessageHandler::SetPhoneNumberAndDataCallLogging, number: '%S'"
       
  1500                     ,&number );
       
  1501             iDataStore.SetWholeOutgoingPhoneNumber( number, aCallId ); 
       
  1502             }
       
  1503         
       
  1504         // RemotePhoneNumber should set only one time because user can edit DataStore::PhoneNumber after dialing was started.
       
  1505         if( !iDataStore.RemotePhoneNumber( aCallId ).Length() )
       
  1506             {
       
  1507             TEFLOGSTRING3( 
       
  1508                 KTAMESINT, 
       
  1509                 "PE CPEMessageHandler::SetPhoneNumberForCallLogging, remote phone number: '%S', call id: %d", 
       
  1510                 &number, aCallId );
       
  1511                                          
       
  1512             RemovePreAndPostFix( number );
       
  1513   
       
  1514             iDataStore.SetRemotePhoneNumber( number, aCallId );
       
  1515             }
       
  1516         
       
  1517         // The Colp number is stored to remoteparty in connected state.
       
  1518         TPEPhoneNumber colpNumber = iCallInfo->iRemoteParty.iRemoteNumber.iTelNumber;
       
  1519         RemovePreAndPostFix( colpNumber );
       
  1520         iDataStore.SetRemoteColpNumber( colpNumber, aCallId ); 
       
  1521         TEFLOGSTRING3( 
       
  1522             KTAMESINT, 
       
  1523             "PE CPEMessageHandler::SetPhoneNumberForCallLogging, colp number: '%S', call id: %d", 
       
  1524             &colpNumber, aCallId );
       
  1525         }
       
  1526     else if ( iDataStore.CallDirection( aCallId ) == RMobileCall::EMobileTerminated )
       
  1527         {
       
  1528         iDataStore.SetRemotePhoneNumber( iCallInfo->iRemoteParty.iRemoteNumber.iTelNumber, aCallId );
       
  1529         TEFLOGSTRING2( 
       
  1530             KTAMESINT, 
       
  1531             "PE CPEMessageHandler::SetPhoneNumberForCallLogging: remote phone number: '%S'", 
       
  1532             &iCallInfo->iRemoteParty.iRemoteNumber.iTelNumber );
       
  1533         }
       
  1534     }
       
  1535 
       
  1536 // -----------------------------------------------------------------------------
       
  1537 // CPEMessageHandler::SetLoggingInfo
       
  1538 // Store call information for logging
       
  1539 // -----------------------------------------------------------------------------
       
  1540 // 
       
  1541 void CPEMessageHandler::SetLoggingInfo(
       
  1542         const TInt aCallId,
       
  1543         TPEState aCallState )
       
  1544     {
       
  1545     if ( aCallState == EPEStateConnected )
       
  1546         {
       
  1547         iDataStore.SetCallStartTime( iCallInfo->iStartTime, aCallId );   
       
  1548         }
       
  1549     iDataStore.SetCallForwarded( iCallInfo->iForwarded, aCallId );
       
  1550     iDataStore.SetCallService( iCallInfo->iService, aCallId );
       
  1551     iDataStore.SetCallState( aCallState, aCallId );
       
  1552     iDataStore.SetCallDuration( iCallInfo->iDuration.Int() );
       
  1553     }
       
  1554 
       
  1555 // -----------------------------------------------------------------------------
       
  1556 // CPEMessageHandler::SetName
       
  1557 // Set calling name or client name to RemoteInfo.
       
  1558 // -----------------------------------------------------------------------------
       
  1559 // 
       
  1560 void CPEMessageHandler::SetName( const TInt aCallId )
       
  1561     {
       
  1562     if ( iDataStore.RemoteName( aCallId ).Length() <= 0 &&
       
  1563          iDataStore.RemoteCompanyName( aCallId ).Length() <= 0 &&
       
  1564          iCallInfo->iRemoteParty.iCallingName.Length() >0 ) 
       
  1565         { 
       
  1566         iDataStore.SetRemoteName( iCallInfo->iRemoteParty.iCallingName, aCallId );
       
  1567         }
       
  1568     }
       
  1569 
       
  1570 // -----------------------------------------------------------------------------
       
  1571 // CPEMessageHandler::HideIdentification
       
  1572 // Hide identification to RemoteInfo.
       
  1573 // -----------------------------------------------------------------------------
       
  1574 // 
       
  1575 void CPEMessageHandler::HideIdentification(
       
  1576         TPEPhoneNumberIdType aPhoneNumberId,
       
  1577         const TInt aCallId )
       
  1578     {
       
  1579     TEFLOGSTRING2( KTAINT,
       
  1580         "PE CPEMessageHandler::HideIdentification: aPhoneNumberId = %d", aPhoneNumberId );
       
  1581     iDataStore.SetRemotePhoneNumberType( aPhoneNumberId, aCallId );
       
  1582     iDataStore.SetRemotePhoneNumber( KNullDesC(), aCallId );
       
  1583     iDataStore.SetRemoteName( KNullDesC(), aCallId );
       
  1584     iDataStore.SetRemotePartyName( KNullDesC(), aCallId );
       
  1585     }
       
  1586 
       
  1587 // -----------------------------------------------------------------------------
       
  1588 // CPEMessageHandler::IsMissedCall
       
  1589 // Check missed call in the idle state.
       
  1590 // -----------------------------------------------------------------------------
       
  1591 // 
       
  1592 void CPEMessageHandler::IsMissedCall(
       
  1593         const TInt aCallId,
       
  1594         TPEState aCallState )
       
  1595     {
       
  1596     if ( iDataStore.CallDirection( aCallId ) == RMobileCall::EMobileTerminated )
       
  1597         {
       
  1598         // If remote party has hanged up the current call on Ringing state, 
       
  1599         // this call is the missed call in the idle state.
       
  1600         if ( aCallState == EPEStateIdle )
       
  1601             {
       
  1602             TBool missedCall = EFalse;
       
  1603 
       
  1604             if ( CallIdCheck::IsVoice( aCallId ) || CallIdCheck::IsVideo( aCallId ) )
       
  1605                 {
       
  1606                 iCallHandling.GetMissedCall( missedCall, aCallId );
       
  1607                 }
       
  1608 
       
  1609             iDataStore.SetMissedCall( missedCall, aCallId );
       
  1610             } 
       
  1611         }
       
  1612     }
       
  1613 
       
  1614 // -----------------------------------------------------------------------------
       
  1615 // CPEMessageHandler::HandleCancelSSstringCommand
       
  1616 // Handles cancel SS string command.
       
  1617 // -----------------------------------------------------------------------------
       
  1618 // 
       
  1619 TInt CPEMessageHandler::HandleCancelSSstringCommand()
       
  1620     {
       
  1621     TInt returnValue( ECCPErrorNone );
       
  1622 
       
  1623     returnValue = iSSHandler->Cancel();
       
  1624 
       
  1625     return returnValue;
       
  1626     }
       
  1627 
       
  1628 // -----------------------------------------------------------------------------
       
  1629 // CPEMessageHandler::HandleConferenceIdleState
       
  1630 // Handles EPEMessageConferenceIdle message.
       
  1631 // -----------------------------------------------------------------------------
       
  1632 // 
       
  1633 TInt CPEMessageHandler::HandleConferenceIdleState( 
       
  1634         const TInt aCallId )
       
  1635     {
       
  1636     TInt counter;
       
  1637     TInt conferenceValue;
       
  1638 
       
  1639     TTimeIntervalSeconds duration;
       
  1640     TInt errorCode = iCallHandling.GetCallDuration( duration, aCallId );
       
  1641     
       
  1642     // Duration offset is stored previously to data store using conference members
       
  1643     // duration. If we do not check for null here then the stored offset is ignored..
       
  1644     if ( ECCPErrorNone == errorCode && duration.Int() > 0 ) 
       
  1645         {
       
  1646         // Set last conference duration
       
  1647         iDataStore.SetCallDuration( duration.Int() );
       
  1648         }
       
  1649     else if ( ECCPErrorNone == errorCode && duration.Int() == 0 )
       
  1650         {
       
  1651         // copy conference call duration to last call duration
       
  1652         // all call specific data is erased a few lines down
       
  1653         iDataStore.SetCallDuration( iDataStore.CallDuration( aCallId ).Int() );
       
  1654         }   
       
  1655 
       
  1656     //Reset values to the TPECallInfo structure
       
  1657     iDataStore.ResetCallInfo( aCallId );
       
  1658 
       
  1659     // Reset Conference Master info from all ex-members
       
  1660     for ( counter = 0; counter < KPEMaximumNumberOfVoiceCalls; counter++ )
       
  1661         {
       
  1662         conferenceValue = iDataStore.CallConference( counter );
       
  1663         if ( conferenceValue == aCallId )
       
  1664             {
       
  1665             iDataStore.SetCallConference( KPENormalVoiceCall, counter );
       
  1666             }
       
  1667         }
       
  1668     
       
  1669     //Stops possible ringing tone playing
       
  1670     //APS Stops possible remote alerting tone playing
       
  1671     TEFLOGSTRING( KTAMESINT, 
       
  1672         "PE  CPEMessageHandler::HandleConferenceIdleState > iGsmAudioData.StopInbandTonePlay()");
       
  1673     iGsmAudioData.StopInbandTonePlay(); 
       
  1674     
       
  1675     ClearCallAudio();    
       
  1676         
       
  1677     return ECCPErrorNone;
       
  1678     }
       
  1679 
       
  1680 // -----------------------------------------------------------------------------
       
  1681 // CPEMessageHandler::HandleConnectedState
       
  1682 // Handles connected message from the CallHandling subsystem 
       
  1683 // 
       
  1684 //  Method fetches call state and ALS line values from the Callhandling subsystem and then
       
  1685 //  Method fetches remote information from the CPEEngineInfo class and then
       
  1686 //  Method sets new values to the logInfo parameters and then
       
  1687 //  Method updates call values to the LogHandling subsystem and then
       
  1688 //  Method sets new values to the CPEEngineInfo class and then
       
  1689 //  Method fecths possible dtmf string from the CPEParserPhoneNumberHandler class and then
       
  1690 //  Method calls HandleSendDtmf method if dtmf string lenght was more than zero.
       
  1691 // -----------------------------------------------------------------------------
       
  1692 //
       
  1693 TInt CPEMessageHandler::HandleConnectedState( 
       
  1694         const TInt aCallId )
       
  1695     {
       
  1696     TInt errorCode( ECCPErrorNone );
       
  1697     TPEState callState;
       
  1698     TPEDtmfString dtmfString;
       
  1699 
       
  1700     RMobileCall::TMobileCallDirection callDirection;
       
  1701     callDirection = iDataStore.CallDirection( aCallId );
       
  1702 
       
  1703     //Stops possible local playing of remote alerting tone
       
  1704     TEFLOGSTRING( 
       
  1705         KTAMESINT, 
       
  1706         "PE  CPEMessageHandler::HandleConnectedState: Calling iGsmAudioData.StopInbandTonePlay()");
       
  1707     iGsmAudioData.StopInbandTonePlay();
       
  1708 
       
  1709     //If call was held then no logging is done.
       
  1710     callState = iDataStore.CallState( aCallId );
       
  1711     if ( callState != EPEStateHeld )
       
  1712         {
       
  1713         errorCode = HandleEngineInfo( aCallId );
       
  1714 
       
  1715         // If phone number has contained dtmf string, phone engine sends dtmf string now.
       
  1716         // Only in MO - call.
       
  1717 
       
  1718         if ( callDirection == RMobileCall::EMobileOriginated )
       
  1719             {
       
  1720             if ( aCallId == KPEEmergencyCallId )
       
  1721                 {
       
  1722                 dtmfString = iDataStore.DtmfStringCommand();
       
  1723                 if ( dtmfString.Length() > 0 )
       
  1724                     {
       
  1725                     errorCode = HandleSendDtmf();
       
  1726                     }
       
  1727                 }
       
  1728              else 
       
  1729                 {
       
  1730 
       
  1731                 dtmfString = iDataStore.DtmfPostFix( aCallId );
       
  1732                 
       
  1733                 if ( dtmfString.Length() > 0 )
       
  1734                     {
       
  1735                     iDataStore.SetDtmfStringCommand( dtmfString );
       
  1736                     errorCode = HandleSendDtmf();
       
  1737                     }
       
  1738                 }
       
  1739 
       
  1740             iDataStore.SetErrorCode( errorCode );
       
  1741             }
       
  1742         }
       
  1743     // For Sat call ( normal or emergency )    
       
  1744     iClientServices->CallRequestMonitor()->SendRespond( ECCPErrorNone );
       
  1745     
       
  1746     // Reset Phonenumber from engine info, this is necessary so that call number
       
  1747     // logging works OK (see CPEMessageHandler::SetPhoneNumberForCallLogging).  
       
  1748     iDataStore.SetPhoneNumber( KNullDesC() );
       
  1749     
       
  1750     // COLP number is updated in connected state 
       
  1751     UpdateRemotePartyInfo();
       
  1752    
       
  1753     return ECCPErrorNone;
       
  1754     }
       
  1755 
       
  1756 // -----------------------------------------------------------------------------
       
  1757 // CPEMessageHandler::HandleDialCall
       
  1758 // Handles dial message from phone application
       
  1759 // 
       
  1760 // -----------------------------------------------------------------------------
       
  1761 // 
       
  1762 TInt CPEMessageHandler::HandleDialCall(
       
  1763     const TBool aClientCall )
       
  1764     {
       
  1765     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDialCall" );
       
  1766     TInt errorCode( ECCPErrorNone );
       
  1767 
       
  1768     TRAPD( trapError, errorCode = HandleDialCallL( aClientCall ));
       
  1769 
       
  1770     if ( trapError )    
       
  1771         {
       
  1772         if ( aClientCall )    
       
  1773             {
       
  1774             iClientServices->CallRequestMonitor()->SendRespond( trapError );                    
       
  1775             }
       
  1776         TEFLOGSTRING2( KTAINT, "PE CPEMessageHandler::HandleDialCall: trapError = %d", trapError );
       
  1777         return trapError;
       
  1778         }
       
  1779     return errorCode;
       
  1780     }
       
  1781 
       
  1782 
       
  1783 // -----------------------------------------------------------------------------
       
  1784 // CPEMessageHandler::HandleDialEmergencyCall
       
  1785 // Handles dial message from phone application
       
  1786 // 
       
  1787 // -----------------------------------------------------------------------------
       
  1788 // 
       
  1789 TInt CPEMessageHandler::HandleDialEmergencyCall(
       
  1790     const TBool aClientCall )
       
  1791     {
       
  1792     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDialEmergencyCall" );
       
  1793     TInt errorCode( ECCPErrorNone );
       
  1794 
       
  1795     if( iEmergencyCallActive && aClientCall )
       
  1796         {
       
  1797         // Client tried to make an emergency call even though we already
       
  1798         // have an active emergency call.
       
  1799         iClientServices->CallRequestMonitor()->SendRespond( ECCPErrorAlreadyInUse );
       
  1800         // Notify PhoneApp which is responsible for showing the error note
       
  1801         return ECCPErrorAlreadyInUse;
       
  1802         }
       
  1803     
       
  1804     iDataStore.SetCallTypeCommand( EPECallTypeCSVoice );
       
  1805         
       
  1806     // Check the phone number and change the prefix if needed
       
  1807     CheckPrefix();
       
  1808     
       
  1809     if ( aClientCall )
       
  1810         {
       
  1811         TPEPhoneNumber phoneNumber = iDataStore.PhoneNumber();
       
  1812         __ASSERT_DEBUG( !( phoneNumber == KNullDesC ), Panic( EPEPanicInvalidParameter));
       
  1813 
       
  1814         TBuf<KPEPhoneNumberMaxLength> tempPhoneNumber = phoneNumber;
       
  1815         RemoveInvalidChars( tempPhoneNumber, KPEClientValidChars, ETrue );
       
  1816         RemovePreAndPostFix( tempPhoneNumber );
       
  1817         
       
  1818         SetClientInformation( KPEEmergencyCallId, tempPhoneNumber );
       
  1819         iClientServices->CallRequestMonitor()->SendRespond( ECCPErrorNone );
       
  1820         }
       
  1821 
       
  1822     if ( IsActiveVideo() )
       
  1823         {
       
  1824         // PhoneApp needs to request releasing of data port from video telephony engine
       
  1825         // Emergency call initialization will continue after receiving MPEPhoneModel::
       
  1826         // EPEMessageContinueEmergencyCallInitialization
       
  1827         iModel.SendMessage( MEngineMonitor::EPEMessageInitiatedEmergencyWhileActiveVideo );
       
  1828         }
       
  1829     else
       
  1830         {
       
  1831         ContinueDialEmergency();
       
  1832         }
       
  1833 
       
  1834     return errorCode;
       
  1835     }
       
  1836 
       
  1837 // -----------------------------------------------------------------------------
       
  1838 // CPEMessageHandler::HandleDialCallL
       
  1839 // Handles dial message from phone application
       
  1840 // 
       
  1841 //  Method fecths phone number from the CPEEngineInfo class and then
       
  1842 //  Method sets process type to the CPEParserPhoneNumberHandler and then
       
  1843 //  Method fecths clir settings from the Settings utility subsystem and tehn
       
  1844 //  Method fecths call parameters from the CallHandling subsystem and then
       
  1845 //  Method sets updated call parameter to the CallHandling subsystem and then
       
  1846 //  Method parsers phonenumber and then
       
  1847 //  Method process parsing result with PhoneParser
       
  1848 // -----------------------------------------------------------------------------
       
  1849 // 
       
  1850 TInt CPEMessageHandler::HandleDialCallL(
       
  1851     const TBool aClientCall )
       
  1852     {
       
  1853     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDialCallL" );
       
  1854     TBool parsingResult;
       
  1855     TPEPhoneNumber phoneNumber;
       
  1856     TInt errorCode( ECCPErrorNone );
       
  1857     TInt numberOfCalls;
       
  1858     
       
  1859     if ( aClientCall )
       
  1860         {
       
  1861         HandleClientCallData();
       
  1862         }
       
  1863     else 
       
  1864         {
       
  1865         iDataStore.SetCallOriginCommand(EPECallOriginPhone);
       
  1866         }
       
  1867         
       
  1868     //Get number of calls
       
  1869     numberOfCalls = iCallHandling.GetNumberOfCalls();
       
  1870 
       
  1871     // Check the phone number for prefix change and change the prefix if needed
       
  1872     CheckPrefix();
       
  1873 
       
  1874     phoneNumber = iDataStore.PhoneNumber();
       
  1875   
       
  1876     __ASSERT_ALWAYS( !( phoneNumber == KNullDesC ), User::Leave( ECCPErrorInvalidPhoneNumber ));
       
  1877     
       
  1878     // Number parser operations
       
  1879     iOptions->SetOptionStatus( KPhoneOptionSend, ETrue );
       
  1880     iOptions->SetOptionStatus( KPhoneOptionInCall, numberOfCalls > 0 );
       
  1881     // If voip call request
       
  1882     if( iDataStore.CallTypeCommand() == EPECallTypeVoIP )
       
  1883         {
       
  1884         iOptions->SetOptionStatus( KPhoneOptionVoipCall, ETrue );
       
  1885         }
       
  1886     else
       
  1887         {
       
  1888         iOptions->SetOptionStatus( KPhoneOptionVoipCall, EFalse );
       
  1889         }
       
  1890 
       
  1891     parsingResult = iParser->ParseL( phoneNumber, *iResult, *iOptions );
       
  1892     if ( parsingResult )
       
  1893         {
       
  1894         iGsmParserErrorCode = ECCPErrorNone;
       
  1895         iParserHandlerContainer->ProcessL( *iResult );
       
  1896         errorCode = iGsmParserErrorCode;
       
  1897         }
       
  1898     else
       
  1899         {
       
  1900         // string was not recognised by any of the parser objects
       
  1901         TEFLOGSTRING( KTAERROR, 
       
  1902             "PE CPEMessageHandler::HANDLEDIALCALLL: PHONEPARSER DID NOT RECOGNIZE THE STRING!" );
       
  1903         errorCode = KErrArgument;
       
  1904         }
       
  1905 
       
  1906     if ( aClientCall )
       
  1907         {
       
  1908         // Do not sent the response to SAT, unless there is error.
       
  1909         const TPECallOrigin& origin = iDataStore.CallOriginCommand();            
       
  1910         if ( origin != EPECallOriginSAT || errorCode )    
       
  1911             {
       
  1912             iClientServices->CallRequestMonitor()->SendRespond( errorCode );                    
       
  1913             }
       
  1914         }
       
  1915 
       
  1916     TEFLOGSTRING2( KTAINT, "PE CPEMessageHandler::HandleDialCallL: errorCode = %d", errorCode );
       
  1917         
       
  1918     return errorCode;
       
  1919     }
       
  1920 
       
  1921 // -----------------------------------------------------------------------------
       
  1922 // CPEMessageHandler::HandleSatCallRequestCompleted
       
  1923 // Sends respond to SAT after dial request completion
       
  1924 // -----------------------------------------------------------------------------
       
  1925 // 
       
  1926 void CPEMessageHandler::HandleSatCallRequestCompleted()
       
  1927     {
       
  1928     // Monitor with active request completes
       
  1929     iClientServices->CallRequestMonitor()->
       
  1930         SendRespond( iCallHandling.CallTerminatedError( iDataStore.CallId() ));                    
       
  1931     }
       
  1932 
       
  1933 // -----------------------------------------------------------------------------
       
  1934 // CPEMessageHandler::HandleDialEmergency
       
  1935 // Handles emergency call message from phone application
       
  1936 //
       
  1937 //  Method calls DialEmergencyCall method from the CallHandling subsystem.
       
  1938 // -----------------------------------------------------------------------------
       
  1939 // 
       
  1940 void CPEMessageHandler::ContinueDialEmergency()
       
  1941     {
       
  1942     iDataStore.SetCallId( KPEEmergencyCallId );
       
  1943     if ( !iEmergencyCallActive )
       
  1944         {
       
  1945         iExternalDataHandler.Set( EPEEmergencyCallInfo, ETrue );  
       
  1946         iEmergencyCallActive = ETrue;        
       
  1947         }
       
  1948         // unmute mic
       
  1949         iDataStore.SetAudioMuteCommand( EFalse );
       
  1950         HandleSetAudioMute();
       
  1951 
       
  1952     iCallHandling.DialEmergencyCall( iDataStore.PhoneNumber() );
       
  1953     }
       
  1954 
       
  1955 // -----------------------------------------------------------------------------
       
  1956 // CPEMessageHandler::HandleDialingStateL
       
  1957 // Handles dialing state transition for voice and video calls
       
  1958 // -----------------------------------------------------------------------------
       
  1959 // 
       
  1960 void CPEMessageHandler::HandleDialingStateL( 
       
  1961         const TInt aCallId )
       
  1962     {
       
  1963     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDialingStateL <");
       
  1964     
       
  1965     // Save call direction to engine info.
       
  1966     iDataStore.SetCallDirection( RMobileCall::EMobileOriginated, aCallId );
       
  1967     
       
  1968     // Log the call information.
       
  1969     User::LeaveIfError( HandleEngineInfo( aCallId ) );
       
  1970     
       
  1971     // publish remote party info to Mediator after contact matching is done
       
  1972     // as remote party info contains information from contact matching. 
       
  1973     UpdateRemotePartyInfo();
       
  1974     
       
  1975     TBool videoCall =
       
  1976         ( iDataStore.CallType( aCallId ) == EPECallTypeVideo ) ? ETrue : EFalse;
       
  1977 
       
  1978     TEFLOGSTRING2(
       
  1979             KTAINT,
       
  1980             "CPEMessageHandler::HandleDialingStateL, callType: %d",
       
  1981             iDataStore.CallType( aCallId ) );
       
  1982         
       
  1983     // Determine the preferred output for call audio and route accordingly.
       
  1984     // Routing for incoming voice call is done in answering state.
       
  1985     HandleAudioRouting( videoCall, aCallId );
       
  1986     }
       
  1987 
       
  1988 // -----------------------------------------------------------------------------
       
  1989 // CPEMessageHandler::HandleIncomingCallL
       
  1990 // Handles incoming voice and video call
       
  1991 // -----------------------------------------------------------------------------
       
  1992 //
       
  1993 void CPEMessageHandler::HandleIncomingCallL( 
       
  1994         const TInt aCallId )
       
  1995     {
       
  1996     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleIncomingCallL <");
       
  1997     
       
  1998     // Save call direction to engine info.
       
  1999     iDataStore.SetCallDirection( RMobileCall::EMobileTerminated, aCallId );
       
  2000 
       
  2001     // Log the call information.
       
  2002     User::LeaveIfError( HandleEngineInfo( aCallId ) );
       
  2003     
       
  2004     // publish remote party info to Mediator after contact matching is done
       
  2005     // as remote party info contains information from contact matching. 
       
  2006     UpdateRemotePartyInfo();    
       
  2007     
       
  2008     TInt numberOfCalls = iCallHandling.GetNumberOfCalls();
       
  2009     
       
  2010     if( numberOfCalls > 1 )
       
  2011         {
       
  2012         TEFLOGSTRING( 
       
  2013             KTAMESINT, 
       
  2014             "PE  CPEMessageHandler::HandleIncomingCallL: Calling iGsmAudioData->PlayInbandTone() for call waiting tone");
       
  2015         iDataStore.SetInbandTone( ECCPCallWaiting );
       
  2016         iGsmAudioData.PlayInbandTone();
       
  2017         iWaitingCallId = aCallId;
       
  2018         }
       
  2019 
       
  2020     if( AutomaticAnswer( aCallId ) )
       
  2021         {
       
  2022         TEFLOGSTRING( KTAINT, 
       
  2023         "PE  CPEMessageHandler::HandleIncomingCallL: iAutomaticAnswerTimer->StartTimer");
       
  2024         iAutomaticAnswerTimer->StartTimer( KPEAutomaticAnswerTimeOut, MEngineMonitor::EPEMessageAnswer, aCallId );
       
  2025         }
       
  2026 
       
  2027     // Cancel EnableService, if in progress
       
  2028     iServiceHandling.CancelServiceEnabling();
       
  2029     }
       
  2030 
       
  2031 // -----------------------------------------------------------------------------
       
  2032 // CPEMessageHandler::HandleDisconnecting
       
  2033 // Handles disconnecting. This means network doesn't play inband tones, but PE must play those.
       
  2034 // -----------------------------------------------------------------------------
       
  2035 // 
       
  2036 TInt CPEMessageHandler::HandleDisconnecting
       
  2037         (
       
  2038         const TInt /*aCallId*/  //The identification number of the call.
       
  2039         )
       
  2040     {
       
  2041     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDisconnecting" );
       
  2042 
       
  2043     iAutomaticAnswerTimer->Cancel();
       
  2044 
       
  2045     TEFLOGSTRING( KTAMESOUT, 
       
  2046         "PE CPEMessageHandler::HandleDisconnecting > iGsmAudioData.PlayInbandTone()");
       
  2047     iGsmAudioData.PlayInbandTone();
       
  2048     
       
  2049     return ECCPErrorNone;
       
  2050     }
       
  2051 
       
  2052 // -----------------------------------------------------------------------------
       
  2053 // CPEMessageHandler::HandleDisconnectingWithInband
       
  2054 // Handles disconnecting with inband. This means network plays the inband tones
       
  2055 // and PhoneEngine does not.
       
  2056 // -----------------------------------------------------------------------------
       
  2057 // 
       
  2058 TInt CPEMessageHandler::HandleDisconnectingWithInband(
       
  2059         const TInt /*aCallId*/ )
       
  2060     {
       
  2061     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDisconnectingWithInband" );
       
  2062     return ECCPErrorNone;
       
  2063     }
       
  2064 
       
  2065 // -----------------------------------------------------------------------------
       
  2066 // CPEMessageHandler::HandleDropConferenceMember
       
  2067 // Handles drop message from phone application
       
  2068 // Method calls DropMember method from CallHandling object.
       
  2069 // -----------------------------------------------------------------------------
       
  2070 // 
       
  2071 TInt CPEMessageHandler::HandleDropConferenceMember()
       
  2072     {
       
  2073     TInt callId = iDataStore.CallId();
       
  2074     __ASSERT_DEBUG( CallIdCheck::IsVoice( callId ), 
       
  2075         Panic( EPEPanicCallIndexOutOfRange ) );
       
  2076     return iCallHandling.DropMember( callId );
       
  2077     }
       
  2078 
       
  2079 // -----------------------------------------------------------------------------
       
  2080 // CPEMessageHandler::HandleHoldCall
       
  2081 // Handles hold message from phone application
       
  2082 // Method fecths call id number from the CPEEngineInfo class and then
       
  2083 // Method calls HoldCall method from the CallHandling subsystem.
       
  2084 // -----------------------------------------------------------------------------
       
  2085 // 
       
  2086 TInt CPEMessageHandler::HandleHoldCall()
       
  2087     {
       
  2088     return iCallHandling.HoldCall();
       
  2089     }
       
  2090 
       
  2091 // -----------------------------------------------------------------------------
       
  2092 // CPEMessageHandler::HandleVoiceCallIdleState
       
  2093 // Handles idle message from the CallHandling subsystem.
       
  2094 //
       
  2095 //  Method stops playing possible ringing tone and the
       
  2096 //  Method gets call and ALS line information from the CallHandling subsystem and then
       
  2097 //  Method fecth remote party information from the CPEEngineInfo class and then
       
  2098 //  Method sets new values to the logInfo parameter and then
       
  2099 //  Method updates log values to the LogHandling subsystem and then
       
  2100 //  Method updates Engine Info's call terminated diagnostics value and then
       
  2101 //  Method resets call information.
       
  2102 // -----------------------------------------------------------------------------
       
  2103 // 
       
  2104 TInt CPEMessageHandler::HandleVoiceCallIdleState( 
       
  2105     const TInt aCallId )
       
  2106     {
       
  2107     TInt errorCode( ECCPErrorGeneral );
       
  2108     TInt returnValue( ECCPErrorNone );
       
  2109     TInt numberOfCalls;
       
  2110 
       
  2111     //Stops possible ringing tone playing
       
  2112     //APS Stops possible remote alerting tone playing
       
  2113     TEFLOGSTRING( KTAMESINT, 
       
  2114         "PE  CPEMessageHandler::HandleVoiceCallIdleState > iGsmAudioData.StopInbandTonePlay()");
       
  2115     iGsmAudioData.StopInbandTonePlay(); 
       
  2116     
       
  2117     ClearCallAudio();
       
  2118     
       
  2119     errorCode = iCallHandling.GetCallInfo( *iCallInfo, aCallId );
       
  2120     
       
  2121     if (  errorCode == ECCPErrorNone )
       
  2122         {
       
  2123         TInt diagnosticInfo = iCallHandling.GetCallTerminatedDiagnostics( 
       
  2124             iCallInfo->iCallName );
       
  2125         // if diagnosticInfo available set diagnostic error code to DataStore    
       
  2126         if ( diagnosticInfo != ECCPErrorNone )
       
  2127             {
       
  2128             iDataStore.SetErrorCode( diagnosticInfo );
       
  2129             }
       
  2130         }
       
  2131 
       
  2132     errorCode = HandleEngineInfo( aCallId );  
       
  2133     iDataStore.SetErrorCode( ECCPErrorNone );
       
  2134 
       
  2135     numberOfCalls = iCallHandling.GetNumberOfCalls();
       
  2136 
       
  2137     if ( numberOfCalls == 0 )
       
  2138         {
       
  2139         // unmute mic
       
  2140         iDataStore.SetAudioMuteCommand( EFalse );
       
  2141         HandleSetAudioMute();
       
  2142         
       
  2143         if ( iEmergencyCallActive )
       
  2144             {
       
  2145             iExternalDataHandler.Set( EPEEmergencyCallInfo, EFalse );
       
  2146             iEmergencyCallActive = EFalse;
       
  2147             }
       
  2148         }
       
  2149 
       
  2150     // If there is a waiting call (voice or data) on 
       
  2151     // the line, and no other calls, play ringing tones for it.
       
  2152     else if ( numberOfCalls == 1 )
       
  2153         {
       
  2154         TPEState callState;
       
  2155         callState = iCallHandling.GetCallState( iWaitingCallId );
       
  2156         // EPEStateRinging equals MT call
       
  2157         if( callState == EPEStateRinging )
       
  2158             {
       
  2159             // unmute mic
       
  2160             iDataStore.SetAudioMuteCommand( EFalse );
       
  2161             HandleSetAudioMute();
       
  2162             TEFLOGSTRING2( KTAMESINT, 
       
  2163                 "CPEMessageHandler::HandleVoiceCallIdleState: aCallId = %d", 
       
  2164                 aCallId );
       
  2165             }
       
  2166         else 
       
  2167             {
       
  2168             TEFLOGSTRING2( KTAMESINT, 
       
  2169                 "CPEMessageHandler::HandleVoiceCallIdleState: callState = %d", 
       
  2170                 callState );
       
  2171             }
       
  2172         }
       
  2173     else
       
  2174         {
       
  2175         TEFLOGSTRING2( KTAMESINT, 
       
  2176             "CPEMessageHandler::HandleVoiceCallIdleState: numberOfCalls = %d", 
       
  2177             numberOfCalls );
       
  2178         }
       
  2179     
       
  2180     iDataStore.ResetCallInfo( aCallId );    
       
  2181     
       
  2182     //publish remote party info to Mediator after call info has been cleared.
       
  2183     UpdateRemotePartyInfo();    
       
  2184 
       
  2185     return returnValue;
       
  2186     }
       
  2187 
       
  2188 // -----------------------------------------------------------------------------
       
  2189 // CPEMessageHandler::ProcessPlayDTMFL
       
  2190 // Handles key down message from phone application
       
  2191 //
       
  2192 //  Method fecths key code value from the CallHandling subsystem and then
       
  2193 //  Method calls StartDtmfTone method from the CallHandling subsystem.
       
  2194 
       
  2195 // -----------------------------------------------------------------------------
       
  2196 // 
       
  2197 void CPEMessageHandler::ProcessPlayDTMFL()
       
  2198     {
       
  2199     const TChar keyCode = iDataStore.KeyCode();
       
  2200     
       
  2201     TBuf<1> keyCodeBuf;
       
  2202     keyCodeBuf.Append( keyCode );
       
  2203     
       
  2204     if ( KPEValidDTMFChars().Find( keyCodeBuf ) >= 0 )
       
  2205         {
       
  2206         if ( iCallHandling.GetNumberOfCalls() > 0 )
       
  2207             {   //There is ongoing call(s)
       
  2208             iCallHandling.StartDtmfTone( keyCode );
       
  2209             }
       
  2210         else
       
  2211             {
       
  2212             iGsmAudioData.PlayDtmfTone( keyCode );            
       
  2213             }
       
  2214         }
       
  2215         
       
  2216     }
       
  2217 
       
  2218 // -----------------------------------------------------------------------------
       
  2219 // CPEMessageHandler::ProcessEndDTMF
       
  2220 // Handles end playing DTMF message from phone application
       
  2221 // Method calls StopDtmfTone method from the CallHandling subsystem.
       
  2222 // -----------------------------------------------------------------------------
       
  2223 // 
       
  2224 TInt CPEMessageHandler::ProcessEndDTMF()
       
  2225     {
       
  2226     TInt returnValue( ECCPErrorNone ); 
       
  2227     // Number parser operations
       
  2228     if ( iCallHandling.GetNumberOfCalls() > 0 )
       
  2229         {   //There is ongoing call(s)
       
  2230         returnValue =  iCallHandling.StopDtmfTone();
       
  2231         }
       
  2232     iGsmAudioData.StopDtmfTonePlay();
       
  2233     return returnValue;
       
  2234     }
       
  2235 
       
  2236 
       
  2237 // -----------------------------------------------------------------------------
       
  2238 // CPEMessageHandler::HandleRejectCall
       
  2239 // Handles reject message from phone application
       
  2240 //  Method stops playing possible ringing tone and then
       
  2241 //  Method calls RejectCall method from the CallHandling subsystem.
       
  2242 // -----------------------------------------------------------------------------
       
  2243 // 
       
  2244 TInt CPEMessageHandler::HandleRejectCall
       
  2245         (
       
  2246         // None.
       
  2247         )
       
  2248     {
       
  2249     //Stops playing ringing tone
       
  2250     //Data call
       
  2251     iGsmAudioData.StopInbandTonePlay(); 
       
  2252     iAutomaticAnswerTimer->Cancel();
       
  2253     return iCallHandling.RejectCall( );
       
  2254     }
       
  2255 
       
  2256 // -----------------------------------------------------------------------------
       
  2257 // CPEMessageHandler::HandleResumeCall
       
  2258 // Handles resume message from phone application
       
  2259 // -----------------------------------------------------------------------------
       
  2260 // 
       
  2261 TInt CPEMessageHandler::HandleResumeCall()
       
  2262     {
       
  2263     return iCallHandling.ResumeCall();
       
  2264     }
       
  2265 
       
  2266 // -----------------------------------------------------------------------------
       
  2267 // CPEMessageHandler::HandleSendUssd
       
  2268 // Handles request from CPEParserMiscHandler
       
  2269 // -----------------------------------------------------------------------------
       
  2270 // 
       
  2271 TInt CPEMessageHandler::HandleSendUssd(
       
  2272         const TDesC& aString )   // USSD string to be sent.
       
  2273 
       
  2274     {
       
  2275     return iClientServices->SendUssd( aString );
       
  2276     }
       
  2277 
       
  2278 // -----------------------------------------------------------------------------
       
  2279 // CPEMessageHandler::HandleSimStateChanged
       
  2280 // Handles EPEMessageSIMStateChanged message from DosServer.
       
  2281 // -----------------------------------------------------------------------------
       
  2282 // 
       
  2283 void CPEMessageHandler::HandleSimStateChanged()  
       
  2284     {
       
  2285     iDataStore.SetSimState( iSimStateMonitor.SimState() );
       
  2286     }
       
  2287 
       
  2288 // -----------------------------------------------------------------------------
       
  2289 // CPEMessageHandler::HandleStartUpL
       
  2290 // Handles startup message from the phone application.
       
  2291 // Method calls StartUp method from the CallHandling subsystem and then
       
  2292 // Method calls StartUp method from the AudioHandling subsystem and then
       
  2293 // Method starts monitoring client originated calls.
       
  2294 // -----------------------------------------------------------------------------
       
  2295 // 
       
  2296 void CPEMessageHandler::HandleStartUp()
       
  2297     {
       
  2298     iCallHandling.StartUp( );
       
  2299     iGsmAudioData.StartUp( );
       
  2300     
       
  2301     iClientServices->StartMonitoring( );
       
  2302     }
       
  2303 
       
  2304 // -----------------------------------------------------------------------------
       
  2305 // CPEMessageHandler::HandleVideoCallConnected
       
  2306 // Handles data call logging in connected and idle state.
       
  2307 // -----------------------------------------------------------------------------
       
  2308 // 
       
  2309 TInt CPEMessageHandler::HandleVideoCallConnected(
       
  2310         const TInt aCallId )
       
  2311     {
       
  2312     //Stops possible remote alerting tone playing
       
  2313     TEFLOGSTRING( 
       
  2314         KTAINT, 
       
  2315         "PE  CPEMessageHandler::HandleVideoCallConnected > CPEGsmAudioData::StopInbandTonePlay()");
       
  2316     iGsmAudioData.StopInbandTonePlay(); 
       
  2317     // EFalse updates log information.
       
  2318     TInt errorCode = HandleEngineInfo( aCallId );
       
  2319     iDataStore.SetErrorCode( errorCode );
       
  2320     return ECCPErrorNone; 
       
  2321     }
       
  2322 
       
  2323 // -----------------------------------------------------------------------------
       
  2324 // CPEMessageHandler::HandleVideoCallIdle
       
  2325 // Handles data call logging and a possible waiting voice call in Idle state.
       
  2326 // -----------------------------------------------------------------------------
       
  2327 // 
       
  2328 TInt CPEMessageHandler::HandleVideoCallIdle(
       
  2329         const TInt aCallId )
       
  2330     {
       
  2331     TInt numberOfCalls;
       
  2332     //Stops possible remote alerting tone playing
       
  2333     TEFLOGSTRING( KTAINT,
       
  2334         "PE CPEMessageHandler::HandleVideoCallIdle > CPEGsmAudioData::StopInbandTonePlay()");
       
  2335     iGsmAudioData.StopInbandTonePlay(); 
       
  2336     HandleEngineInfo( aCallId );
       
  2337     iDataStore.SetErrorCode( ECCPErrorNone );
       
  2338     TInt returnValue( ECCPErrorNone );
       
  2339 
       
  2340     numberOfCalls = iCallHandling.GetNumberOfCalls();
       
  2341     if ( numberOfCalls == 0 )
       
  2342         {
       
  2343         iGsmAudioData.HandleCallEnding();
       
  2344 
       
  2345         // unmute mic
       
  2346         iDataStore.SetAudioMuteCommand( EFalse );
       
  2347         HandleSetAudioMute();
       
  2348         }
       
  2349     else if ( numberOfCalls == 1 )
       
  2350         {
       
  2351         TPEState callState;
       
  2352         callState = iCallHandling.GetCallState( iWaitingCallId );
       
  2353         // EPEStateRinging equals MT call
       
  2354         if ( callState == EPEStateRinging )
       
  2355             {
       
  2356             TEFLOGSTRING2( KTAMESINT, 
       
  2357                 "CPEMessageHandler::HandleVideoCallIdle: aCallId = %d", 
       
  2358                 aCallId );
       
  2359             iGsmAudioData.HandleCallEnding();
       
  2360             
       
  2361             // unmute mic
       
  2362             iDataStore.SetAudioMuteCommand( EFalse );
       
  2363             HandleSetAudioMute();
       
  2364             }
       
  2365         else 
       
  2366             {
       
  2367             TEFLOGSTRING2( KTAMESINT, 
       
  2368                 "CPEMessageHandler::HandleVideoCallIdle: callState = %d", 
       
  2369                 callState );
       
  2370             }
       
  2371         }
       
  2372     else
       
  2373         {
       
  2374         TEFLOGSTRING2( KTAMESINT, 
       
  2375             "CPEMessageHandler::HandleVideoCallIdle: numberOfCalls = %d", 
       
  2376             numberOfCalls );
       
  2377         }
       
  2378     iDataStore.ResetCallInfo( aCallId );
       
  2379     
       
  2380     //publish remote party info to Mediator after call info has been cleared.
       
  2381     UpdateRemotePartyInfo();    
       
  2382     
       
  2383     return returnValue;
       
  2384     }
       
  2385 
       
  2386 // -----------------------------------------------------------------------------
       
  2387 // CPEMessageHandler::HandleEmergencyCheck
       
  2388 // Check is given number emergency number.
       
  2389 // -----------------------------------------------------------------------------
       
  2390 // 
       
  2391 TInt CPEMessageHandler::HandleEmergencyCheck( )
       
  2392     {
       
  2393     TInt errorCode( ECCPErrorNone );
       
  2394     TPEPhoneNumber emergencyNumber;
       
  2395     TBool isEmergency;
       
  2396     emergencyNumber = iDataStore.PhoneNumber();
       
  2397 
       
  2398     errorCode = iClientServices->IsEmergencyPhoneNumber( emergencyNumber, isEmergency );
       
  2399     if ( isEmergency  && errorCode == ECCPErrorNone )
       
  2400         {
       
  2401         iModel.SendMessage( MEngineMonitor::EPEMessageValidEmergencyNumber );
       
  2402         }
       
  2403     else
       
  2404         {
       
  2405         iModel.SendMessage( MEngineMonitor::EPEMessageInValidEmergencyNumber );
       
  2406         }
       
  2407 
       
  2408     return errorCode;
       
  2409     }
       
  2410 
       
  2411 // -----------------------------------------------------------------------------
       
  2412 // CPEMessageHandler::HandlePhoneNumberEditedL
       
  2413 // Handles Phone Number Edited message from phone application, 
       
  2414 // called when user is used paste or delete command.
       
  2415 // Method check if there is ongoing call(s) if there is return ECCPErrorNone else
       
  2416 // method fecths phone number from the CPEEngineInfo class and 
       
  2417 // then method parsers phonenumber and then method process parsing result
       
  2418 // with PhoneParser and Phoneengine.
       
  2419 // (other items were commented in a header).
       
  2420 // -----------------------------------------------------------------------------
       
  2421 // 
       
  2422 void CPEMessageHandler::HandlePhoneNumberEditedL()
       
  2423     {
       
  2424     TBool isServiceCode( EFalse );
       
  2425 
       
  2426     iOptions->SetOptionStatus( KPhoneOptionInCall, 
       
  2427         ( iCallHandling.GetNumberOfCalls() > 0 ) );
       
  2428 
       
  2429     iOptions->SetOptionStatus( KPhoneOptionSend, EFalse );
       
  2430     iOptions->SetOptionStatus( KPhoneOptionVoipCall, EFalse );
       
  2431 
       
  2432     if( iParser->ParseL( iDataStore.PhoneNumber(), *iResult, *iOptions ) )
       
  2433         {
       
  2434         isServiceCode = ETrue;
       
  2435         iGsmParserErrorCode = ECCPErrorNone;
       
  2436         iParserHandlerContainer->ProcessL( *iResult );
       
  2437         }
       
  2438     else // check for service codes that require SEND
       
  2439         {
       
  2440         iOptions->SetOptionStatus( KPhoneOptionSend, ETrue );
       
  2441         if ( iParser->ParseL( iDataStore.PhoneNumber(), *iResult, *iOptions ) )
       
  2442             {
       
  2443             // if there is an incoming call only certain codes are allowed       
       
  2444             if ( iCallHandling.IsCallInState( EPEStateRinging ) &&
       
  2445                  !iCallHandling.IsCallInState( EPEStateConnected ) )
       
  2446                 {
       
  2447                 isServiceCode = PhoneGsmParser::IsAllowedForArriving( *iResult );
       
  2448                 }
       
  2449             else
       
  2450                 {
       
  2451                 const PhoneGsmParser::TContentType type = 
       
  2452                     PhoneGsmParser::DetermineContentType( *iResult );
       
  2453                     
       
  2454                 if ( type == PhoneGsmParser::EContentSupplementaryService ||
       
  2455                      type == PhoneGsmParser::EContentUnstructuredService )
       
  2456                     {
       
  2457                     isServiceCode = ETrue;
       
  2458                     }
       
  2459                 }
       
  2460             }
       
  2461         }
       
  2462         
       
  2463     iDataStore.SetPhoneNumberIsServiceCode( isServiceCode );    
       
  2464     }
       
  2465 
       
  2466 // -----------------------------------------------------------------------------
       
  2467 // CPEMessageHandler::AutomaticAnswer
       
  2468 // Checks if automatic answer is defined for connected accessory.
       
  2469 // -----------------------------------------------------------------------------
       
  2470 // 
       
  2471 TBool CPEMessageHandler::AutomaticAnswer( const TInt aCallId ) const
       
  2472     {
       
  2473     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::AutomaticAnswer <" );
       
  2474     
       
  2475     TInt automaticAnswer( EFalse );
       
  2476     TInt accessory( 0 );
       
  2477          
       
  2478     if ( iCallHandling.GetNumberOfCalls() > 1 ) // The new call need to be the first in the array
       
  2479         {
       
  2480         return EFalse;
       
  2481         }
       
  2482         
       
  2483     iExternalDataHandler.Get( EPEAccessoryMode, accessory );
       
  2484     
       
  2485     switch ( accessory )
       
  2486         {
       
  2487         case EAccModeWiredHeadset:    //Wired headset
       
  2488         case EAccModeWirelessHeadset: //Wireless headset
       
  2489             {
       
  2490             // Safe to ignore error code here, 
       
  2491             // automatic answer setting just equals zero == EFalse if it fails
       
  2492             iExternalDataHandler.Get( EPEAutomaticAnswerHeadsetSetting, automaticAnswer );
       
  2493             break;
       
  2494             }
       
  2495         case EAccModeWiredCarKit:     //Wired carkit
       
  2496             {
       
  2497             iExternalDataHandler.Get( EPEAutomaticAnswerCarkitSetting, automaticAnswer );
       
  2498             break;
       
  2499             }           
       
  2500         case EAccModeWirelessCarKit:  //Wireless carkit
       
  2501             {
       
  2502             iExternalDataHandler.Get( EPEAutomaticAnswerWirelessCarkitSetting, automaticAnswer );                
       
  2503             break;
       
  2504             }           
       
  2505         case EAccModeLoopset:         //Loopset
       
  2506             {
       
  2507             iExternalDataHandler.Get( EPEAutomaticAnswerLoopsetSetting, automaticAnswer );                
       
  2508             break;
       
  2509             }           
       
  2510         case EAccModeMusicStand:      //Musicstand
       
  2511             {
       
  2512             iExternalDataHandler.Get( EPEAutomaticAnswerMusicStandSetting, automaticAnswer );                
       
  2513             break;
       
  2514             }
       
  2515          default:
       
  2516             break;
       
  2517          }
       
  2518 
       
  2519     if ( automaticAnswer )
       
  2520         {
       
  2521         TFileName noneFilepath;
       
  2522         noneFilepath.Append( TParsePtrC( PathInfo::RomRootPath() ).Drive() );
       
  2523         noneFilepath.Append( KProfileNoSoundPath() );
       
  2524         
       
  2525         TProfileRingingType ringingType = iDataStore.RingingType(); 
       
  2526         TPEContactFileName ringingTone = iDataStore.RingingTone( aCallId );
       
  2527          
       
  2528         if ( ringingType == EProfileRingingTypeBeepOnce ||
       
  2529              ringingType == EProfileRingingTypeSilent ||
       
  2530              ringingTone == noneFilepath )
       
  2531             {
       
  2532             automaticAnswer = EFalse;
       
  2533             }
       
  2534         } 
       
  2535     TEFLOGSTRING2( KTAINT, 
       
  2536         "PE CPEMessageHandler::AutomaticAnswer > ret: %d", automaticAnswer );
       
  2537     return automaticAnswer;
       
  2538     }
       
  2539 
       
  2540 // -----------------------------------------------------------------------------
       
  2541 // CPEMessageHandler::HandleStopInbandTonePlay
       
  2542 // Stop playing a InBand tone
       
  2543 // -----------------------------------------------------------------------------
       
  2544 //
       
  2545 void CPEMessageHandler::HandleStopInbandTonePlay()
       
  2546     {
       
  2547     iGsmAudioData.StopInbandTonePlay();
       
  2548     }
       
  2549 
       
  2550 // -----------------------------------------------------------------------------
       
  2551 // CPEMessageHandler::HandleAutomaticAnswerOff
       
  2552 // Gets EPEMessageAutomaticAnswerOff from UI and makes soft cancelation of the
       
  2553 // automatic answer when needed
       
  2554 // -----------------------------------------------------------------------------
       
  2555 //
       
  2556 void CPEMessageHandler::HandleAutomaticAnswerOff() const
       
  2557     {
       
  2558     iAutomaticAnswerTimer->Cancel();
       
  2559     }
       
  2560 
       
  2561 // -----------------------------------------------------------------------------
       
  2562 // CPEMessageHandler::HandleATDialingStarted()
       
  2563 // Handles AT dialing completed message from Phone UI
       
  2564 // -----------------------------------------------------------------------------
       
  2565 //
       
  2566 void CPEMessageHandler::HandleATDialingStarted( const TBool aSucceed ) const
       
  2567     {
       
  2568     iClientServices->CommandHandlerMonitor()->DoCompleteCmdAtd( aSucceed ); 
       
  2569     }    
       
  2570 
       
  2571 // -----------------------------------------------------------------------------
       
  2572 // CPEMessageHandler::IsEmergencyAllowed()
       
  2573 // Checks if emergency call is allowed. 
       
  2574 // -----------------------------------------------------------------------------
       
  2575 //
       
  2576 TBool CPEMessageHandler::IsEmergencyAllowed() const
       
  2577     {
       
  2578     TBool networkConnectionAllowed( EFalse );
       
  2579     //It is safe to ignore error code here: a default value of EFalse is used if the get fails
       
  2580     iExternalDataHandler.Get( EPENetworkConnectionAllowedSetting, networkConnectionAllowed );
       
  2581     return networkConnectionAllowed;
       
  2582     }
       
  2583     
       
  2584 // -----------------------------------------------------------------------------
       
  2585 // CPEMessageHandler::HandleClientCallData()
       
  2586 // Handle Client Call Data.
       
  2587 // -----------------------------------------------------------------------------
       
  2588 //
       
  2589 void CPEMessageHandler::HandleClientCallData() 
       
  2590     {
       
  2591     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleClientCallData" );
       
  2592     
       
  2593     CPhCltDialData* dialData = iClientServices->CallRequestMonitor()->ClientDialData();
       
  2594     
       
  2595     // Set already known Client information
       
  2596     SetClientData( *dialData );
       
  2597     
       
  2598     if ( dialData->CallType() == EPhCltVideo || dialData->CallType() == EPhCltForcedVideo )
       
  2599         {
       
  2600         iDataStore.SetCallTypeCommand( EPECallTypeVideo );
       
  2601         }
       
  2602     else if( dialData->CallType() == EPhCltCallVoIP )
       
  2603         {
       
  2604         iDataStore.SetCallTypeCommand( EPECallTypeVoIP );
       
  2605         }
       
  2606     else
       
  2607         {
       
  2608         iDataStore.SetCallTypeCommand( EPECallTypeCSVoice );
       
  2609         }
       
  2610         
       
  2611     // End other calls before dial SAT call
       
  2612     if ( dialData->EndOtherCalls() )
       
  2613         {
       
  2614         HandleReleaseAll();
       
  2615         TEFLOGSTRING( KTAINT,
       
  2616             "PE CPEMessageHandler::HandleClientCallData > HandleReleaseAll()" );
       
  2617          }       
       
  2618     }    
       
  2619     
       
  2620 // -----------------------------------------------------------------------------
       
  2621 // CPEMessageHandler::ClearCallAudio
       
  2622 // Notifies audio handling that there is no active call and audio should be routed
       
  2623 // accordingly.
       
  2624 // -----------------------------------------------------------------------------
       
  2625 //
       
  2626 void CPEMessageHandler::ClearCallAudio()
       
  2627     {
       
  2628     TEFLOGSTRING( KTAMESINT, "PE CPEMGsmessageHandler::ClearCallAudio()" );
       
  2629     TBool restrictingCalls( EFalse );
       
  2630 
       
  2631     if ( iCallHandling.GetNumberOfCalls() > 0 )
       
  2632         {
       
  2633         restrictingCalls = 
       
  2634             // Single call states restricting the devsound notification
       
  2635             iCallHandling.IsCallInState( EPEStateConnected ) ||
       
  2636             iCallHandling.IsCallInState( EPEStateConnecting ) ||
       
  2637             iCallHandling.IsCallInState( EPEStateDialing ) ||
       
  2638             iCallHandling.IsCallInState( EPEStateHeld ) ||
       
  2639             // Conference call states restricting the devsound notification
       
  2640             ( iDataStore.CallState( KPEConferenceCallID )== EPEStateConnectedConference ) ||
       
  2641             ( iDataStore.CallState( KPEConferenceCallID ) == EPEStateCreatingConference ) ||
       
  2642             ( iDataStore.CallState( KPEConferenceCallID ) == EPEStateGoingOneToOne ) ||
       
  2643             ( iDataStore.CallState( KPEConferenceCallID ) == EPEStateAddingConferenceMember ) ||
       
  2644             ( iDataStore.CallState( KPEConferenceCallID ) == EPEStateAddedConferenceMember ) ||
       
  2645             ( iDataStore.CallState( KPEConferenceCallID ) == EPEStateDroppingConferenceMember ) ||
       
  2646             ( iDataStore.CallState( KPEConferenceCallID ) == EPEStateDroppedConferenceMember );
       
  2647         }
       
  2648     
       
  2649     if ( restrictingCalls == EFalse )
       
  2650         {
       
  2651         // deactivate audio
       
  2652         TEFLOGSTRING( KTAMESINT, "PE CPEMGsmessageHandler::ClearCallAudio() Deactivating" );
       
  2653         iGsmAudioData.HandleCallEnding();
       
  2654         }
       
  2655     }
       
  2656 
       
  2657 // -----------------------------------------------------------------------------
       
  2658 // CPEMessageHandler::HandleSwitchToVideoOrVoice 
       
  2659 // This method handle EPEMessageSwitchToVideoOrVoice message. If current call id
       
  2660 // is Data then call will be switched to Voice call and the other way around. 
       
  2661 // Method set current phonenumber to dataStore and get call parameter and call 
       
  2662 // hangUp to current call. 
       
  2663 // When hangUp is completed (EPEMessageIdle was sent) sequence will be continue 
       
  2664 // from ContinueSwitchToCall method.
       
  2665 // -----------------------------------------------------------------------------
       
  2666 //
       
  2667 TInt CPEMessageHandler::HandleSwitchToVideoOrVoice( const TInt aCallId )
       
  2668     {
       
  2669     // First get the current phone number and then end voice call
       
  2670     // or video call.
       
  2671     TInt err( ECCPErrorNone );
       
  2672     
       
  2673     TEFLOGSTRING2( KTAINT, 
       
  2674         "PE CPEMessageHandler::HandleSwitchToVideoOrVoice, aCallId : %d", aCallId );
       
  2675     // if out of memory case then phonenumber is already datastore.
       
  2676     if( aCallId != KPECallIdNotUsed )
       
  2677         {
       
  2678         if ( iDataStore.CallDirection( aCallId ) == RMobileCall::EMobileOriginated )
       
  2679             {
       
  2680             iDataStore.SetSwitchToNumberCommand( iDataStore.WholeOutgoingPhoneNumber( aCallId ) );  
       
  2681             // Clear phonenumber to prevent using the wrong number in MO video call.
       
  2682             iDataStore.SetPhoneNumber( KNullDesC() );
       
  2683             }
       
  2684         else
       
  2685             {
       
  2686             iDataStore.SetSwitchToNumberCommand( iDataStore.RemotePhoneNumber( aCallId ) );
       
  2687             // Remote phone number must be stored as the phone number in case of low-memory situation where 
       
  2688             // an MO voice call can be initiated after failing to answer an MT video call.
       
  2689             iDataStore.SetPhoneNumber( iDataStore.RemotePhoneNumber( aCallId ) );
       
  2690             }
       
  2691 
       
  2692         err = HandleReleaseCall();
       
  2693         }
       
  2694 
       
  2695     return err;
       
  2696     }
       
  2697     
       
  2698 // -----------------------------------------------------------------------------
       
  2699 // CPEMessageHandler::ContinueSwitchToCall
       
  2700 // Metdod calls dial to multimedia call or voice call.
       
  2701 // -----------------------------------------------------------------------------
       
  2702 //
       
  2703 TInt CPEMessageHandler::ContinueSwitchToCall( const TInt aCallId )  
       
  2704     {
       
  2705     TEFLOGSTRING2( KTAINT, 
       
  2706         "PE CPEMessageHandler::ContinueSwitchToCall, aCallId : %d", aCallId );
       
  2707     TInt callId;
       
  2708     TInt errorCode( ECCPErrorNone );
       
  2709   
       
  2710     TPEPhoneNumber phoneNumber = iDataStore.SwitchToNumberCommand();
       
  2711     TEFLOGSTRING2( KTAINT, 
       
  2712         "PE CPEMessageHandler::ContinueSwitchToCall, phoneNumber : %S", 
       
  2713         &phoneNumber );
       
  2714 
       
  2715     // Check is current call voice or video
       
  2716     if ( CallIdCheck::IsVoice( aCallId ) )
       
  2717         {
       
  2718         // Create new video call to same phonenumber
       
  2719         iDataStore.SetCallTypeCommand( EPECallTypeVideo );
       
  2720         errorCode = iCallHandling.DialMultimedia( phoneNumber, callId );
       
  2721         }
       
  2722     else if ( CallIdCheck::IsVideo( aCallId ) )
       
  2723         {
       
  2724         // Create new voice call to same phonenumber
       
  2725         iDataStore.SetCallTypeCommand( EPECallTypeCSVoice );
       
  2726         errorCode = iCallHandling.DialCall( phoneNumber, callId );
       
  2727         }
       
  2728     TEFLOGSTRING2( KTAINT, 
       
  2729         "PE CPEMessageHandler::ContinueSwitchToCall(), error : %d", errorCode );    
       
  2730     return errorCode;    
       
  2731     }
       
  2732 
       
  2733 // -----------------------------------------------------------------------------
       
  2734 // CPEMessageHandler::RemovePreAndPostFix
       
  2735 // Remmove supplementary service prefix and dtmf postfix.
       
  2736 // Phone number can contain following parts: supplementary
       
  2737 // service prefix, main part and dtmf postfix.
       
  2738 // -----------------------------------------------------------------------------
       
  2739 //
       
  2740 void CPEMessageHandler::RemovePreAndPostFix( 
       
  2741         TDes& aString )
       
  2742     {
       
  2743     // Check that string contains only valid dtmf characters.
       
  2744     if ( IsValidDtmfString( aString ))
       
  2745         {
       
  2746         TLex input( aString ); 
       
  2747         
       
  2748         RemovePrefix( input );
       
  2749         // Take number part.
       
  2750         HandleNumberPart( input, aString );        
       
  2751         }
       
  2752     }
       
  2753 
       
  2754 // -----------------------------------------------------------------------------
       
  2755 // CPEMessageHandler::RemovePrefix
       
  2756 // Removes clir suppress/invoke prefix in the string.
       
  2757 // -----------------------------------------------------------------------------
       
  2758 //
       
  2759 void CPEMessageHandler::RemovePrefix( 
       
  2760         TLex& aLex )
       
  2761     {
       
  2762     TPtrC remainder( aLex.Remainder() );
       
  2763 
       
  2764     if ( EqualsLeft( remainder, KPEClirSuppress ) )
       
  2765         {
       
  2766         aLex.Inc( KPEClirSuppress().Length() );
       
  2767         }
       
  2768     else if ( EqualsLeft( remainder, KPEClirInvoke ) )
       
  2769         {
       
  2770         aLex.Inc( KPEClirSuppress().Length() );
       
  2771         }
       
  2772     }
       
  2773 
       
  2774 // -----------------------------------------------------------------------------
       
  2775 // CPEMessageHandler::HandleNumberPart
       
  2776 // Search the main part of the phone number.
       
  2777 // -----------------------------------------------------------------------------
       
  2778 //
       
  2779 void CPEMessageHandler::HandleNumberPart(
       
  2780         TLex& aLex,
       
  2781         TDes& aNumberPart )
       
  2782     {   
       
  2783     TLexMark start;
       
  2784     aLex.Mark( start );
       
  2785   
       
  2786     // Optional forced call prefixes. 
       
  2787     if ( aLex.Peek() == KPENumberAsterisk || 
       
  2788          aLex.Peek() == KPENumberHash ) 
       
  2789          {
       
  2790          aLex.Inc(); 
       
  2791          }
       
  2792          
       
  2793     // Optional international prefix. 
       
  2794     if ( aLex.Peek() == KPENumberPlus ) 
       
  2795         { 
       
  2796         aLex.Inc(); 
       
  2797         } 
       
  2798 
       
  2799     // And the rest of number. 
       
  2800     while ( ( aLex.Peek().IsDigit() ) ||  
       
  2801             ( aLex.Peek() == KPENumberAsterisk ) || 
       
  2802             ( aLex.Peek() == KPENumberHash ) ) 
       
  2803         {
       
  2804         aLex.Inc(); 
       
  2805         }
       
  2806 
       
  2807     TPtrC mainpart( aLex.MarkedToken( start ) );
       
  2808     const TInt length = mainpart.Length();
       
  2809     if ( length <= KPEPhoneNumberMaxLength )
       
  2810         {
       
  2811         aNumberPart.Copy( mainpart );
       
  2812         }
       
  2813     }
       
  2814 
       
  2815 // -----------------------------------------------------------------------------
       
  2816 // CPEMessageHandler::EqualsLeft
       
  2817 // -----------------------------------------------------------------------------
       
  2818 //
       
  2819 TBool CPEMessageHandler::EqualsLeft( 
       
  2820         const TDesC& aString, 
       
  2821         const TDesC& aPrefix )
       
  2822     {
       
  2823     TBool result = EFalse;
       
  2824 
       
  2825     if ( aPrefix.Length() <= aString.Length() )
       
  2826         {
       
  2827         TPtrC part( aString.Left( aPrefix.Length() ) );
       
  2828 
       
  2829         result = ( part == aPrefix );
       
  2830         }
       
  2831 
       
  2832     return result;
       
  2833     }
       
  2834 
       
  2835 // -----------------------------------------------------------------------------
       
  2836 // CPEMessageHandler::HandleReplaceActive
       
  2837 // -----------------------------------------------------------------------------
       
  2838 // 
       
  2839 TInt CPEMessageHandler::HandleReplaceActive()
       
  2840     {
       
  2841     return iCallHandling.ReplaceActive();
       
  2842     }
       
  2843 
       
  2844 // -----------------------------------------------------------------------------
       
  2845 // CPEMessageHandler::CheckIfPhoneIsLockedL
       
  2846 // -----------------------------------------------------------------------------
       
  2847 //
       
  2848 void CPEMessageHandler::CheckIfPhoneIsLockedL()
       
  2849     {
       
  2850     // Check if phone is locked
       
  2851     TInt  keyLockStatus( EAutolockStatusUninitialized );
       
  2852     TInt err = RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, keyLockStatus );
       
  2853     const TBool phoneIsLocked = ( keyLockStatus > EAutolockOff );
       
  2854 
       
  2855     if ( phoneIsLocked && err == KErrNone )
       
  2856         {
       
  2857         // New call is not possible if device lock is on 
       
  2858         TEFLOGSTRING2( KTAERROR,
       
  2859             "PE CPEMessageHandler::CheckIfPhoneIsLockedL, keyLockStatus : %d", keyLockStatus );
       
  2860         User::Leave( ECCPErrorAuthenticationFailed );
       
  2861         }
       
  2862     }
       
  2863 
       
  2864 // -----------------------------------------------------------------------------
       
  2865 // CPEMessageHandler::IsActiveVideo
       
  2866 // Checks if there are any connected video calls
       
  2867 // -----------------------------------------------------------------------------
       
  2868 // 
       
  2869 TBool CPEMessageHandler::IsActiveVideo()
       
  2870     {
       
  2871     TBool activeVideoCall( EFalse );
       
  2872     
       
  2873     TInt callId = iCallHandling.GetCallIdByState( EPEStateConnected );
       
  2874     if ( callId > ECCPErrorNotFound && iDataStore.CallType( callId ) == EPECallTypeVideo )
       
  2875         {
       
  2876         activeVideoCall = ETrue;
       
  2877         }
       
  2878     return activeVideoCall;
       
  2879     }
       
  2880 
       
  2881 // -----------------------------------------------------------------------------
       
  2882 // CPEMessageHandler::HandleServiceEnabled
       
  2883 // -----------------------------------------------------------------------------
       
  2884 //
       
  2885 TInt CPEMessageHandler::HandleServiceEnabled()
       
  2886     {
       
  2887     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleServiceEnabled ");
       
  2888 
       
  2889     
       
  2890     return iVoipNumberHandler->ContinueVoipDial();
       
  2891     }
       
  2892 
       
  2893 // -----------------------------------------------------------------------------
       
  2894 // CPEMessageHandler::HandleRemotePartyInfoChanged
       
  2895 // -----------------------------------------------------------------------------
       
  2896 //
       
  2897 void CPEMessageHandler::HandleRemotePartyInfoChanged()
       
  2898     {
       
  2899     UpdateRemotePartyInfo();      
       
  2900     }
       
  2901 
       
  2902 
       
  2903 // -----------------------------------------------------------------------------
       
  2904 // CPEMessageHandler::HandleUnattendedTransferRequestResponse
       
  2905 // -----------------------------------------------------------------------------
       
  2906 //
       
  2907 TInt CPEMessageHandler::HandleUnattendedTransferRequestResponse( 
       
  2908         TBool aAcceptRequest )
       
  2909     {
       
  2910     TEFLOGSTRING( KTAINT, 
       
  2911         "PE CPEMessageHandler::HandleUnattendedTransferRequestResponse" );
       
  2912     
       
  2913     if ( aAcceptRequest )
       
  2914         {
       
  2915         return iCallHandling.AcceptUnattendedTransfer();
       
  2916         }
       
  2917     else
       
  2918         {
       
  2919         return iCallHandling.RejectUnattendedTransfer();
       
  2920         }
       
  2921     }
       
  2922 
       
  2923 // -----------------------------------------------------------------------------
       
  2924 // CPEMessageHandler::HandleUnattendedTransfer
       
  2925 // -----------------------------------------------------------------------------
       
  2926 //
       
  2927 TInt CPEMessageHandler::HandleUnattendedTransfer()
       
  2928     {
       
  2929     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleUnattendedTransfer ");
       
  2930     TInt errorCode = iCallHandling.DoUnattendedTransfer( 
       
  2931             iDataStore.TransferTargetCommand() );
       
  2932      
       
  2933     return errorCode;
       
  2934     }
       
  2935 
       
  2936 // -----------------------------------------------------------------------------
       
  2937 // CPEMessageHandler::ForwardCallToAddress
       
  2938 // -----------------------------------------------------------------------------
       
  2939 //
       
  2940 TInt CPEMessageHandler::ForwardCallToAddress()
       
  2941     {
       
  2942     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::ForwardCallToAddress ");
       
  2943     TInt errorCode = iCallHandling.ForwardCallToAddress( 
       
  2944             iDataStore.ForwardAddressIndex() );
       
  2945      
       
  2946     return errorCode;
       
  2947     }
       
  2948 
       
  2949 // -----------------------------------------------------------------------------
       
  2950 // CPEMessageHandler::HandleDisableService
       
  2951 // -----------------------------------------------------------------------------
       
  2952 //
       
  2953 void CPEMessageHandler::HandleDisableService()
       
  2954     {
       
  2955     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDisableService ");
       
  2956     iServiceHandling.DisableService();
       
  2957     }
       
  2958 
       
  2959 // -----------------------------------------------------------------------------
       
  2960 // CPEMessageHandler::IsValidDtmfString
       
  2961 // -----------------------------------------------------------------------------
       
  2962 //
       
  2963 TBool CPEMessageHandler::IsValidDtmfString( TDes& aString )
       
  2964     { 
       
  2965     TBool validDtmf = ETrue;
       
  2966 
       
  2967     for( TInt i = 0; i < aString.Length(); i++ )
       
  2968         {
       
  2969         if ( KErrNotFound == KValidDtmfChars().Locate( aString[i] ) )
       
  2970             {
       
  2971             validDtmf = EFalse;
       
  2972             break;
       
  2973             }      
       
  2974         }
       
  2975     return validDtmf;
       
  2976     }
       
  2977 
       
  2978 // -----------------------------------------------------------------------------
       
  2979 // CPEMessageHandler::UpdateRemotePartyInfo
       
  2980 // -----------------------------------------------------------------------------
       
  2981 //
       
  2982 void CPEMessageHandler::UpdateRemotePartyInfo( )
       
  2983     { 
       
  2984     CPERemotePartyInfoMediator* mediatorUpdater = iModel.MediatorCommunicationHandler();
       
  2985     if ( mediatorUpdater ) 
       
  2986         {
       
  2987         mediatorUpdater->UpdateRemotePartyInfo();
       
  2988         }
       
  2989     }
       
  2990 
       
  2991 // -----------------------------------------------------------------------------
       
  2992 // CPEMessageHandler::HandleDialCall
       
  2993 // Handles dial message from dial service
       
  2994 // 
       
  2995 // -----------------------------------------------------------------------------
       
  2996 // 
       
  2997 TInt CPEMessageHandler::HandleDialServiceCall(
       
  2998     const TBool /*aClientCall*/ )
       
  2999     {
       
  3000     TEFLOGSTRING( KTAINT, "PE CPEMessageHandler::HandleDialCall" );
       
  3001     TInt errorCode( ECCPErrorNone );
       
  3002     //TODO 
       
  3003     iModel.HandleInternalMessage( MPEPhoneModel::EPEMessageDialServiceCall );
       
  3004     return errorCode;
       
  3005     }
       
  3006 
       
  3007 
       
  3008 // -----------------------------------------------------------------------------
       
  3009 // CPEMessageHandler::ExecuteKeySequenceL
       
  3010 // Only sequences which are not issued with send-key are handled here. SS 
       
  3011 // commands etc. are processed in HandleDialCallL().
       
  3012 // -----------------------------------------------------------------------------
       
  3013 //
       
  3014 TBool CPEMessageHandler::ExecuteKeySequenceL( const TDesC16 &aSequence )
       
  3015 {
       
  3016     TBool keySequenceProcessed( EFalse );
       
  3017     
       
  3018     iOptions->SetOptionStatus( KPhoneOptionInCall, 
       
  3019         ( iCallHandling.GetNumberOfCalls() > 0 ) );
       
  3020     iOptions->SetOptionStatus( KPhoneOptionSend, EFalse );
       
  3021     iOptions->SetOptionStatus( KPhoneOptionVoipCall, EFalse );
       
  3022     
       
  3023     if ( iParser->ParseL( aSequence, *iResult, *iOptions ) )
       
  3024         {
       
  3025         keySequenceProcessed = ETrue;
       
  3026         iGsmParserErrorCode = ECCPErrorNone;
       
  3027         iParserHandlerContainer->ProcessL( *iResult );
       
  3028         }
       
  3029     
       
  3030     return keySequenceProcessed;
       
  3031 }
       
  3032 
       
  3033 //  End of File