phoneclientserver/phoneserver/Src/Standard/Standard_Aiw/CPhSrvSubSessionExtCall.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  Sub Session Ext Call.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "cphsrvsubsessionextcall.h" 
       
    21 #include "cphsrvsession.h" 
       
    22 #include "cphsrvserver.h" 
       
    23 #include "mphsrvobjectnegotiators.h" 
       
    24 
       
    25 // Hash mark
       
    26 _LIT( KPhoneHash, "#" );
       
    27 
       
    28 // dtmf chars
       
    29 _LIT( KPhoneDtmfNumberChars, "pw" );
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CPhSrvSubSessionExtCall::CPhSrvSubSessionExtCall
       
    35 // 
       
    36 // C++ Constructor
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CPhSrvSubSessionExtCall::CPhSrvSubSessionExtCall(CPhSrvSession& aSession)
       
    40 :    CPhSrvSubSessionBase(aSession, EPhSrvSubSessionTypeExternalCall)
       
    41     {
       
    42     }
       
    43 
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CPhSrvSubSessionExtCall::PhSrvMessageDecoderCanProcessMessage
       
    47 // 
       
    48 // Framework function. Returns ETrue for the op codes that
       
    49 // this subsession can handle.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 TBool CPhSrvSubSessionExtCall::PhSrvMessageDecoderCanProcessMessage( 
       
    53     TInt aFunction )
       
    54     {
       
    55     switch( aFunction )
       
    56         {
       
    57         case EPhoneServerExtCallSubSessionClose:
       
    58         case EPhoneServerExtCallSubSessionMakeCall:
       
    59         case EPhoneServerExtCallSubSessionMakeCallCancel:
       
    60             return ETrue;
       
    61 
       
    62         default:
       
    63             return EFalse;
       
    64         }
       
    65     }
       
    66 
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CPhSrvSubSessionEmergencyNum::PhSrvMessageProcessorHandleMessageL
       
    70 // 
       
    71 // Framework function. Handle any op-codes here.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CPhSrvSubSessionExtCall::PhSrvMessageProcessorHandleMessageL( 
       
    75     const RMessage2& aMessage )
       
    76     {
       
    77     TBool permissionStatus ( EFalse );
       
    78     TBool dtmfNumber( EFalse ); //contains 'p' or 'w'  
       
    79     TBool isSSUssd( EFalse ); //is USSD/SS string
       
    80     TBool hasUssdSSCaps( EFalse ); //has USSD/SS string correct capabilities
       
    81      
       
    82     TBool hasCapNetworkServices( EFalse );
       
    83     TBool hasCapNetworkControlAndServices( EFalse );
       
    84     TBool hasCapWriteAndReadDeviceData ( EFalse );
       
    85     // Capabilities needed if NOT USSD/SS string                                                         
       
    86     hasCapNetworkServices = aMessage.HasCapability( ECapabilityNetworkServices );                                                                                                                   
       
    87       
       
    88     switch( aMessage.Function() )
       
    89         {
       
    90         case EPhoneServerExtCallSubSessionClose:
       
    91             CmdSubSessionCloseL( aMessage );
       
    92             permissionStatus = ETrue;
       
    93             break;
       
    94         case EPhoneServerExtCallSubSessionMakeCall:
       
    95             CreateCallArgsL( aMessage );
       
    96             // Checks if telephone number contains dtmf string
       
    97             dtmfNumber = IsDtmfPhoneNumber( iCallArgs->TelephoneNumber());
       
    98             if ( !dtmfNumber )
       
    99                 {
       
   100                 // Checks if telephone number is USSD/SS string
       
   101                 isSSUssd = ( iCallArgs->TelephoneNumber().Right( KPhoneHash().Length() ) == KPhoneHash );
       
   102                 if ( isSSUssd )
       
   103                     { 
       
   104                     // Capabilities needed if USSD/SS string
       
   105                     hasCapNetworkControlAndServices = aMessage.HasCapability( ECapabilityNetworkControl, 
       
   106                                                               ECapabilityNetworkServices );
       
   107                     hasCapWriteAndReadDeviceData = aMessage.HasCapability( ECapabilityReadDeviceData, ECapabilityWriteDeviceData );
       
   108                     hasUssdSSCaps =  hasCapNetworkControlAndServices && hasCapWriteAndReadDeviceData;
       
   109                     }   
       
   110                 }
       
   111            if ( ( hasCapNetworkServices && !isSSUssd ) ||  hasUssdSSCaps )
       
   112                 {
       
   113                 CmdSubSessionMakeCallL( aMessage );
       
   114                 permissionStatus = ETrue;
       
   115                 }
       
   116             break;
       
   117         case EPhoneServerExtCallSubSessionMakeCallCancel:
       
   118             if ( hasCapNetworkServices )
       
   119                 {
       
   120                 CmdSubSessionMakeCallCancelL( aMessage );
       
   121                 permissionStatus = ETrue;
       
   122                 }
       
   123             break;
       
   124 
       
   125         default:
       
   126             PhoneSession().PanicClient( 
       
   127                 aMessage,
       
   128                 EPhCltServerInitiatedPanicInvalidRequest );
       
   129             break;
       
   130         }
       
   131 
       
   132     // If caps are not ok 
       
   133      if( !permissionStatus )
       
   134         {
       
   135         aMessage.Complete( KErrPermissionDenied );    
       
   136         }
       
   137     }
       
   138 
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CPhSrvSubSessionExtCall::CmdSubSessionCloseL
       
   142 // 
       
   143 // Close the sub-session
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CPhSrvSubSessionExtCall::CmdSubSessionCloseL( const RMessage2& aMessage )
       
   147     {
       
   148     delete iCallArgs;
       
   149     iCallArgs =NULL;
       
   150     PhoneSession().CloseSubSession( aMessage );
       
   151     }
       
   152 
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CPhSrvSubSessionExtCall::CmdSubSessionMakeCallL
       
   156 // 
       
   157 // Setup an asynchronous request to handle external interface
       
   158 // call requests.
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 void CPhSrvSubSessionExtCall::CmdSubSessionMakeCallL( 
       
   162     const RMessage2& aMessage )
       
   163     {               
       
   164 
       
   165     // Submit a new request to the call manager
       
   166     MPhSrvNegotiatorCall& callNegotiator = PhoneSession().PhoneServer(
       
   167         ).CallNegotiatorL();
       
   168     callNegotiator.NegotiatorDialL( aMessage, *iCallArgs, *this );
       
   169     }
       
   170 
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CPhSrvSubSessionExtCall::CmdSubSessionMakeCallCancelL
       
   174 // 
       
   175 // Cancel an outstanding request to handle call initiations.
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 void CPhSrvSubSessionExtCall::CmdSubSessionMakeCallCancelL( 
       
   179     const RMessage2& aMessage )
       
   180     {
       
   181     // Ask the negotiator to delete any pending call request for this 
       
   182     // subsession. It will panic the client if one can't be found.
       
   183     MPhSrvNegotiatorCall& callNegotiator = PhoneSession().PhoneServer(
       
   184         ).CallNegotiatorL();
       
   185 
       
   186     callNegotiator.NegotiatorDialCancelL( *this );
       
   187     aMessage.Complete( KErrNone );
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CPhSrvSubSessionExtCall::CreateCallArgs
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 void CPhSrvSubSessionExtCall::CreateCallArgsL( const RMessage2& aMessage )
       
   195     {
       
   196     HBufC8* package = HBufC8::NewLC( aMessage.Int1() ); 
       
   197     TPtr8 calldata( package->Des() );
       
   198     PhoneSession().Read(
       
   199             aMessage,
       
   200             0,
       
   201             calldata );
       
   202                                              
       
   203     iCallArgs = CPhCltExtPhoneDialData::NewL( *package );
       
   204     CleanupStack::PopAndDestroy( package );
       
   205     }
       
   206     
       
   207 // -----------------------------------------------------------------------------
       
   208 // CPhSrvSubSessionExtCall::IsDtmfPhoneNumber
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 TBool CPhSrvSubSessionExtCall::IsDtmfPhoneNumber(
       
   212         const TDesC& aString )
       
   213     {
       
   214     
       
   215 
       
   216     // String must contain 'p' or 'w'.
       
   217     TBool must = EFalse;
       
   218 
       
   219         {
       
   220         TPtrC chs( KPhoneDtmfNumberChars );
       
   221         const TInt length = chs.Length();
       
   222         TInt index;
       
   223 
       
   224         for ( index = 0; index < length; index++ )
       
   225             {
       
   226             if ( aString.Locate( chs[ index ] ) != KErrNotFound )
       
   227                 {
       
   228                 must = ETrue;
       
   229                 break;
       
   230                 }
       
   231             }
       
   232         }
       
   233 
       
   234     return must; 
       
   235     }
       
   236 // End of File