phoneengine/phonemodel/src/cpeparserphonenumberhandler.cpp
changeset 0 5f000ab63145
child 9 8871b09be73b
child 21 92ab7f8d0eab
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2004-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:  CPEParserPhoneNumberHandler class methods implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "cpeclientcallrequestmonitor.h"
       
    22 #include "cpemessagehandler.h"
       
    23 #include "cpeparserphonenumberhandler.h"
       
    24 #include <featmgr.h>
       
    25 #include <gsmerror.h>
       
    26 #include <mpecallhandling.h>
       
    27 #include <mpedatastore.h>
       
    28 #include <talogger.h>
       
    29 
       
    30 // CONSTANTS
       
    31 _LIT( KClirSuppress, "*31#" );
       
    32 _LIT( KClirInvoke, "#31#" );
       
    33 
       
    34 // ================= MEMBER FUNCTIONS =======================================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CPEParserPhoneNumberHandler::CPEParserPhoneNumberHandler
       
    38 // C++ default constructor can NOT contain any code, that
       
    39 // might leave.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CPEParserPhoneNumberHandler::CPEParserPhoneNumberHandler( 
       
    43         CPEMessageHandler& aOwner, 
       
    44         MPECallHandling& aCallHandling,
       
    45         MPEDataStore& aDataStore
       
    46         ) : iOwner( aOwner ), 
       
    47             iCallHandling( aCallHandling ),
       
    48             iDataStore( aDataStore )
       
    49     {
       
    50     TEFLOGSTRING( KTAOBJECT, "PE CPEParserPhoneNumberHandler::CPEParserPhoneNumberHandler" )
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CPEParserPhoneNumberHandler::ProcessDialToNumberL
       
    55 // Process dial to number.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 void CPEParserPhoneNumberHandler::ProcessDialToNumberL( 
       
    59         const TDesC& aNumber,
       
    60         const TDesC& aDtmfPostfix,
       
    61         TClir aClir )
       
    62     {
       
    63     TInt errorCode( ECCPErrorNotFound );
       
    64     TPEPhoneNumber phoneNumber;
       
    65     TInt callId;
       
    66         
       
    67     TEFLOGSTRING3( KTAINT, 
       
    68         "PE CPEParserPhoneNumberHandler::ProcessDialToNumberL, number: %S, dtmf postfix: %S", 
       
    69         &aNumber, 
       
    70         &aDtmfPostfix );
       
    71     
       
    72     // Check if phone is locked
       
    73     iOwner.CheckIfPhoneIsLockedL();
       
    74     
       
    75     if ( aNumber.Length() == 0 )
       
    76         {
       
    77         User::Leave( ECCPErrorInvalidPhoneNumber );
       
    78         }
       
    79 
       
    80     if ( aClir == EClirSuppress )
       
    81         {
       
    82         phoneNumber.Copy( KClirSuppress );
       
    83         }
       
    84     else if ( aClir == EClirInvoke )
       
    85         {
       
    86         phoneNumber.Copy( KClirInvoke );
       
    87         }
       
    88     
       
    89     phoneNumber.Append( aNumber );
       
    90     
       
    91     TPECallType processType = iDataStore.CallTypeCommand();
       
    92     if( processType != EPECallTypeVideo )
       
    93         {
       
    94         // TSY not accept phone number that include + or w chartes.
       
    95         TPEPhoneNumber postfix = FilterPostfix( aDtmfPostfix );
       
    96         if( postfix.Length() )
       
    97             {
       
    98             phoneNumber.Append( postfix );
       
    99             }
       
   100         }
       
   101     TEFLOGSTRING2( KTAINT, 
       
   102           "PE CPEParserPhoneNumberHandler::ProcessDialToNumberL, phoneNumber: %S"
       
   103             , &phoneNumber );
       
   104     //Check for Offline mode
       
   105     if ( IsPhoneOffline() )
       
   106         {
       
   107         //Offline mode is active or network registration failed,
       
   108         //only emergency calls allowed
       
   109         TEFLOGSTRING( KTAERROR, 
       
   110             "PE CPEGSMPARSERPHONENUMBERHANDLER::PROCESSDIALTONUMBERL: CURRENTLY IN OFFLINE MODE: EMERGENCY CALLS ONLY! " );
       
   111         errorCode = ECCPErrorNotAllowedInOfflineMode;
       
   112         }
       
   113     else
       
   114         {
       
   115         switch ( processType )
       
   116             { 
       
   117             case EPECallTypeUninitialized: // There is no information about call, assume voice call
       
   118             case EPECallTypeCSVoice: //Make Dial request
       
   119             case EPECallTypeVoIP:
       
   120                 {
       
   121 
       
   122                 TBool clientCall = iDataStore.CallOriginCommand() != EPECallOriginPhone;
       
   123                 errorCode = iCallHandling.DialCall( phoneNumber, callId );
       
   124                 //PhoneClient originated call
       
   125                 if( clientCall && ( ECCPErrorNone == errorCode ) )
       
   126                     {
       
   127                     iOwner.SetClientInformation( callId, phoneNumber );
       
   128                     }
       
   129                 break;
       
   130                 }
       
   131             case EPECallTypeVideo:
       
   132                 {
       
   133 
       
   134                 TBool clientCall = iDataStore.CallOriginCommand() != EPECallOriginPhone;
       
   135                 errorCode = iCallHandling.DialMultimedia( phoneNumber, callId );
       
   136                 // Note that video call dialing does not return an error code if it fails
       
   137                 // due to insufficient free memory, so we have to check the call identifier as well.
       
   138                 if( clientCall
       
   139                         && callId != KPECallIdNotUsed
       
   140                         && ( ECCPErrorNone == errorCode ) )
       
   141                     {
       
   142                     iOwner.SetClientInformation( callId, phoneNumber );
       
   143                     }
       
   144                 break;
       
   145                 }
       
   146             default:
       
   147                 {
       
   148                 errorCode = ECCPErrorNotFound;
       
   149                 break;
       
   150                 }
       
   151             } 
       
   152         if ( !errorCode )
       
   153             {
       
   154             //Set Dtmf string to dataStore
       
   155             iDataStore.SetDtmfPostFix( aDtmfPostfix, callId );
       
   156             }
       
   157         }
       
   158     iOwner.SetGsmParserErrorCode( errorCode );
       
   159 
       
   160     // KErrInUse is returned when we are not allowed to make the call.
       
   161     // One of these cases would be where a MO call is alerting and the user
       
   162     // tries to dial another number via Dialer
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CPEParserPhoneNumberHandler::FilterPostfix
       
   167 // -----------------------------------------------------------------------------
       
   168 // 
       
   169 TPtrC CPEParserPhoneNumberHandler::FilterPostfix( TPtrC aPostfix )
       
   170     {
       
   171     TLex input( aPostfix );
       
   172     TInt stripStart = KErrNotFound;
       
   173     TInt postfixLength = aPostfix.Length();
       
   174     for ( TInt i = 0; i != postfixLength; i ++ )
       
   175         {
       
   176         TChar ch( input.Peek() );
       
   177         if ( ch == KDtmfWait ||
       
   178              ch == KDtmfPlus )
       
   179             {
       
   180             if ( i < stripStart || stripStart == KErrNotFound )
       
   181                 {
       
   182                 stripStart = i;
       
   183                 }
       
   184             }
       
   185         }
       
   186     if ( stripStart != KErrNotFound )
       
   187         {
       
   188         return aPostfix.Left( stripStart );
       
   189         }
       
   190     else
       
   191         {
       
   192         return aPostfix;
       
   193         }
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CPEParserPhoneNumberHandler::IsPhoneOffline
       
   198 // -----------------------------------------------------------------------------
       
   199 // 
       
   200 TBool CPEParserPhoneNumberHandler::IsPhoneOffline()
       
   201     {
       
   202     TBool isPhoneOffline( EFalse );
       
   203 
       
   204     if( FeatureManager::FeatureSupported( KFeatureIdOfflineMode )
       
   205         && ( iDataStore.ProfileId() == EProfileOffLineId ) )
       
   206         {
       
   207         isPhoneOffline = ETrue;
       
   208         }
       
   209     
       
   210     TNWNetworkRegistrationStatus networkRegStatus
       
   211         = iDataStore.NetworkRegistrationStatus();
       
   212     
       
   213     if( ( networkRegStatus == ENWStatusRegistrationUnknown )
       
   214         || ( networkRegStatus == ENWStatusNotRegisteredNoService )
       
   215         || ( networkRegStatus == ENWStatusNotRegisteredEmergencyOnly )
       
   216         || ( networkRegStatus == ENWStatusRegistrationDenied ) )
       
   217         {
       
   218         isPhoneOffline = ETrue;
       
   219         }
       
   220     
       
   221     return isPhoneOffline;
       
   222     }
       
   223 
       
   224     
       
   225 //  End of File