phonecmdhandler/phonecmdhnlr/src/PhoneHandlerControl.cpp
changeset 0 ff3b6d0fd310
child 3 a4a774cb6ea7
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     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:  Receives call handling related key presses from accessories and 
       
    15 *				 executes them. 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "PhoneHandlerControl.h"
       
    23 #include "PhoneHandlerService.h"
       
    24 #include "PhoneHandlerAnswerCall.h"
       
    25 #include "PhoneHandlerEndCall.h"
       
    26 #include "PhoneHandlerDialCall.h"
       
    27 #include "PhoneHandlerVoiceDial.h"
       
    28 #include "PhoneHandlerRedial.h"
       
    29 #include "PhoneHandlerMultipartyCall.h"
       
    30 #include "PhoneHandlerDTMF.h"
       
    31 #include "PhoneHandlerActive.h"
       
    32 #include "PhoneHandlerResponse.h"
       
    33 #include "PhoneHandlerCallState.h"
       
    34 #include "PhoneHandlerDebug.h"
       
    35 #include <remconinterfaceselector.h>
       
    36 #include <RemConCallHandlingTarget.h>
       
    37 #include <CPbkContactEngine.h>
       
    38 #include <ctsydomainpskeys.h>
       
    39 
       
    40 #if 0
       
    41 #include <VoiceUIDomainPSKeys.h>
       
    42 #endif
       
    43 
       
    44 #include <connect/sbdefs.h>
       
    45 #include <coreapplicationuisdomainpskeys.h>
       
    46 
       
    47 // EXTERNAL DATA STRUCTURES
       
    48 
       
    49 // EXTERNAL FUNCTION PROTOTYPES  
       
    50 
       
    51 // CONSTANTS
       
    52 
       
    53 // MACROS
       
    54 
       
    55 // LOCAL CONSTANTS AND MACROS
       
    56 
       
    57 // MODULE DATA STRUCTURES
       
    58 
       
    59 // LOCAL FUNCTION PROTOTYPES
       
    60 const TInt KMultipartyCallMinParam = 1;
       
    61 const TInt KMultipartyCallMaxParam = 2;
       
    62 
       
    63 // FORWARD DECLARATIONS
       
    64 
       
    65 // ============================= LOCAL FUNCTIONS ===============================
       
    66 
       
    67 
       
    68 // ============================ MEMBER FUNCTIONS ===============================
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CPhoneHandlerControl::CPhoneHandlerControl
       
    72 // C++ default constructor can NOT contain any code, that
       
    73 // might leave.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CPhoneHandlerControl::CPhoneHandlerControl()
       
    77 	: iPrevState( EPSCTsyCallStateNone )
       
    78     {
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CPhoneHandlerControl::ConstructL
       
    83 // Symbian 2nd phase constructor can leave.
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void CPhoneHandlerControl::ConstructL( CRemConInterfaceSelector* aIfSelector )
       
    87     {
       
    88     COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::ConstructL() start" );
       
    89 		
       
    90     if( !aIfSelector )
       
    91     	{
       
    92     	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::ConstructL() Create connection to RemCon." );
       
    93 	    	
       
    94     	// Target connection to RemCon FW hasn't been done.
       
    95     	iInterfaceSelector = CRemConInterfaceSelector::NewL();
       
    96 	   	iTarget = CRemConCallHandlingTarget::NewL( *iInterfaceSelector, *this );
       
    97 		iInterfaceSelector->OpenTargetL();
       
    98 		}
       
    99 	else
       
   100 		{
       
   101 		COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::ConstructL() Don't create connection to RemCon." );
       
   102 	    		
       
   103 		// Connection to RemCon FW as target has already been done in a process.
       
   104 		iTarget = CRemConCallHandlingTarget::NewL( *aIfSelector, *this );
       
   105 		}
       
   106     	
       
   107 	iResponse = CPhoneHandlerResponse::NewL( *this );
       
   108 	iCallStateObserver = CPhoneHandlerCallState::NewL( *this );
       
   109 			
       
   110 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::ConstructL() end" );
       
   111 	}
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CPhoneHandlerControl::NewL
       
   115 // Two-phased constructor.
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 CPhoneHandlerControl* CPhoneHandlerControl::NewL( 
       
   119 									CRemConInterfaceSelector* aIfSelector )
       
   120     {
       
   121     COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::NewL() start" );
       
   122     
       
   123     CPhoneHandlerControl* self = new ( ELeave ) CPhoneHandlerControl();
       
   124     
       
   125     CleanupStack::PushL( self );
       
   126     self->ConstructL( aIfSelector );
       
   127     CleanupStack::Pop( self );
       
   128     
       
   129     COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::NewL() end" );
       
   130     
       
   131     return self;
       
   132     }
       
   133 
       
   134 // Destructor
       
   135 CPhoneHandlerControl::~CPhoneHandlerControl()
       
   136     {
       
   137     COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::~CPhoneHandlerControl() start" );
       
   138     
       
   139     if( iInterfaceSelector )
       
   140     	{
       
   141     	delete iInterfaceSelector;
       
   142        	}
       
   143     
       
   144     if( iResponse )
       
   145     	{
       
   146     	iResponse->Delete();
       
   147        	}
       
   148        	
       
   149     if( iCallStateObserver )
       
   150     	{
       
   151     	delete iCallStateObserver;
       
   152     	}
       
   153             
       
   154     COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::~CPhoneHandlerControl() end" );
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CPhoneHandlerControl::TelephoneNumber
       
   159 // Provides phone number for service.
       
   160 // (other items were commented in a header).
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 const TPhCltTelephoneNumber& 
       
   164     CPhoneHandlerControl::TelephoneNumber() const
       
   165     {
       
   166     return iTelNumber;
       
   167     }
       
   168     
       
   169 // -----------------------------------------------------------------------------
       
   170 // CPhoneHandlerControl::VoiceDialStatus
       
   171 // Provides voice dial status for service.
       
   172 // (other items were commented in a header).
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 const TBool& 
       
   176     CPhoneHandlerControl::VoiceDialStatus() const
       
   177     {
       
   178     return iActivate;
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CPhoneHandlerControl::ChldCommand
       
   183 // Provides CHLD command for service.
       
   184 // (other items were commented in a header).
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 const TInt& 
       
   188     CPhoneHandlerControl::ChldCommand() const
       
   189     {
       
   190     return iChldCommand;
       
   191     }
       
   192     
       
   193 // -----------------------------------------------------------------------------
       
   194 // CPhoneHandlerControl::ChldCallNumber
       
   195 // Provides CHLD call number for service.
       
   196 // (other items were commented in a header).
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 const TInt& 
       
   200     CPhoneHandlerControl::ChldCallNumber() const
       
   201     {
       
   202     return iChldCallNumber;
       
   203     }
       
   204     
       
   205 // -----------------------------------------------------------------------------
       
   206 // CPhoneHandlerControl::Tone
       
   207 // Provides DTMF tone for service.
       
   208 // (other items were commented in a header).
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 const TChar& 
       
   212     CPhoneHandlerControl::Tone() const
       
   213     {
       
   214     return iChar;
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CPhoneHandlerControl::CommandInitiator
       
   219 // Provides API that service uses to send reponse to command.
       
   220 // (other items were commented in a header).
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 CRemConCallHandlingTarget& 
       
   224     CPhoneHandlerControl::CommandInitiator() const
       
   225     {
       
   226     return *iTarget;
       
   227     }
       
   228     
       
   229 // -----------------------------------------------------------------------------
       
   230 // CPhoneHandlerControl::NotifyCallState
       
   231 // (other items were commented in a header).
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 void CPhoneHandlerControl::NotifyCallState( const TInt aState )
       
   235     {
       
   236     COM_TRACE_1( "[PHONECMDHANDLER] CPhoneHandlerControl::NotifyCallState() aState=%d", aState );
       
   237     
       
   238 	if( aState == EPSCTsyCallStateConnected && iPrevState != EPSCTsyCallStateHold )
       
   239 		{
       
   240 		COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::NotifyCallState(): iActiveCalls++" );
       
   241 		
       
   242 		iActiveCalls++;
       
   243 		}
       
   244 	else if( aState == EPSCTsyCallStateDisconnecting && 
       
   245 			( iPrevState == EPSCTsyCallStateConnected || iPrevState == EPSCTsyCallStateHold ))
       
   246 		{
       
   247 		COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::NotifyCallState(): iActiveCalls--" );
       
   248 		
       
   249 		iActiveCalls--;
       
   250 		}
       
   251 	else if( aState == EPSCTsyCallStateNone )
       
   252 		{
       
   253 		COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::NotifyCallState(): iActiveCalls = 0" );
       
   254 		iActiveCalls = 0;
       
   255 		}
       
   256 		
       
   257 	iPrevState = aState;
       
   258 	COM_TRACE_1( "[PHONECMDHANDLER] CPhoneHandlerControl::NotifyCallState() iActiveCalls=%d", iActiveCalls );
       
   259 	}
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CPhoneHandlerControl::AnswerCall
       
   263 // (other items were commented in a header).
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 void CPhoneHandlerControl::AnswerCall()
       
   267 	{
       
   268 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::AnswerCall() start" );
       
   269 	
       
   270 	StartProcessing( ERemConExtAnswerCall );
       
   271 	
       
   272 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::AnswerCall() end" );
       
   273     }
       
   274 	
       
   275 // -----------------------------------------------------------------------------
       
   276 // CPhoneHandlerControl::EndCall
       
   277 // (other items were commented in a header).
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void CPhoneHandlerControl::EndCall()
       
   281 	{
       
   282 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::EndCall() start" );
       
   283     
       
   284     StartProcessing( ERemConExtEndCall );
       
   285     	    
       
   286 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::EndCall() end" );
       
   287     }
       
   288     
       
   289 // -----------------------------------------------------------------------------
       
   290 // CPhoneHandlerControl::AnswerEndCall
       
   291 // (other items were commented in a header).
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 void CPhoneHandlerControl::AnswerEndCall()
       
   295 	{
       
   296 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::AnswerEndCall() start" );
       
   297     
       
   298     StartProcessing( ERemConExtAnswerEnd );
       
   299     	   
       
   300 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::AnswerEndCall() end" );
       
   301     }
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CPhoneHandlerControl::VoiceDial
       
   305 // (other items were commented in a header).
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 #if 0 // SCB CR EHSA-7APJWF: SIND subscribes to RemCon directly	
       
   309 void CPhoneHandlerControl::VoiceDial( const TBool aActivate )
       
   310     {
       
   311     COM_TRACE_1( "[PHONECMDHANDLER] CPhoneHandlerControl::VoiceDial() aActivate=%d", aActivate );
       
   312 
       
   313     TInt callState( EPSCTsyCallStateUninitialized );
       
   314     iProperty.Get( KPSUidCtsyCallInformation, KCTsyCallState, callState ); 
       
   315 
       
   316     COM_TRACE_1( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() call state = %d", callState );
       
   317 
       
   318     if( callState == EPSCTsyCallStateUninitialized ||
       
   319         callState == EPSCTsyCallStateNone )
       
   320         {
       
   321         TInt voiceUiState( KVoiceUiIsClose );
       
   322         iProperty.Get( KPSUidVoiceUiAccMonitor, KVoiceUiOpenKey, voiceUiState ); 
       
   323 
       
   324         if( voiceUiState == KVoiceUiIsOpen )
       
   325 	        {
       
   326 	        COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::VoiceDial() voice UI is open!" );
       
   327 	        iProperty.Set( KPSUidVoiceUiAccMonitor , KVoiceUiAccessoryEvent, ERemConExtVoiceDial );
       
   328 	        iResponse->SetResponse( ERemConExtVoiceDial, KErrNone );
       
   329 	        iResponse->Process();
       
   330 	        }
       
   331         else
       
   332 	        {
       
   333 	        iActivate = aActivate;
       
   334 	        StartProcessing( ERemConExtVoiceDial );
       
   335 	        }
       
   336         }
       
   337     else
       
   338         {
       
   339         iResponse->SetResponse( ERemConExtVoiceDial, KErrNone );
       
   340         iResponse->Process();
       
   341         }
       
   342 
       
   343     COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::VoiceDial() end" );
       
   344     }
       
   345 #else	
       
   346 void CPhoneHandlerControl::VoiceDial( const TBool /*aActivate*/ )
       
   347     {
       
   348     COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::VoiceDial()" );
       
   349 
       
   350     if ( IsAutoLockOn() && !IsBTAccessoryCmd() )
       
   351         {
       
   352         iResponse->SetResponse( ERemConExtVoiceDial, KErrAccessDenied );
       
   353         iResponse->Process();
       
   354         return;
       
   355         }
       
   356         
       
   357     iResponse->SetResponse( ERemConExtVoiceDial, KErrNone );
       
   358     iResponse->Process();
       
   359 
       
   360     COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::VoiceDial() end" );
       
   361     }
       
   362 #endif
       
   363 // -----------------------------------------------------------------------------
       
   364 // CPhoneHandlerControl::LastNumberRedial
       
   365 // (other items were commented in a header).
       
   366 // -----------------------------------------------------------------------------
       
   367 //
       
   368 void CPhoneHandlerControl::LastNumberRedial( )
       
   369 	{
       
   370 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::LastNumberRedial() start" );
       
   371 	
       
   372 	if ( IsAutoLockOn() && !IsBTAccessoryCmd() )
       
   373         {
       
   374         iResponse->SetResponse( ERemConExtLastNumberRedial, KErrAccessDenied );
       
   375         iResponse->Process();
       
   376         return;
       
   377         }
       
   378 
       
   379 	StartProcessing( ERemConExtLastNumberRedial );
       
   380 	
       
   381 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::LastNumberRedial() end" );
       
   382 	}
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 // CPhoneHandlerControl::DialCall
       
   386 // (other items were commented in a header).
       
   387 // -----------------------------------------------------------------------------
       
   388 //
       
   389 void CPhoneHandlerControl::DialCall( const TDesC8& aTelNumber )
       
   390 	{
       
   391 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::DialCall() start" );
       
   392     
       
   393 	if ( IsAutoLockOn() && !IsBTAccessoryCmd() )
       
   394 	        {
       
   395  	        iResponse->SetResponse( ERemConExtDialCall, KErrAccessDenied );
       
   396 	        iResponse->Process();
       
   397 	        return;
       
   398 	        }
       
   399  	
       
   400     // Check aTelNumber range    
       
   401    	if( KPhCltTelephoneNumberLength < aTelNumber.Length() )
       
   402    		{
       
   403   		COM_TRACE_1( "[PHONECMDHANDLER] CPhoneHandlerControl::DialCall() number value=%d too long", aTelNumber.Size() );
       
   404   		iResponse->SetResponse( ERemConExtDialCall, KErrArgument );
       
   405   		iResponse->Process();
       
   406   		return; 
       
   407   		}
       
   408   	
       
   409   	iTelNumber.Copy( aTelNumber );
       
   410   	      	  	    
       
   411     StartProcessing( ERemConExtDialCall );
       
   412     
       
   413 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::DialCall() end" );
       
   414 	}
       
   415 
       
   416 // -----------------------------------------------------------------------------
       
   417 // CPhoneHandlerControl::MultipartyCalling
       
   418 // Method supports multiparty call handling according to BT handsfree profile 
       
   419 // (HFP) 1.5. BT HFP 1.5 defines contents of aData parameter as follows: 0, 1, 
       
   420 // 1<idx>, 2, 2<idx>, 3 and 4, where: 
       
   421 //
       
   422 // 0 = Releases all held calls or sets User Determined User Busy (UDUB) for 
       
   423 // a waiting call. 
       
   424 // 1 = Releases all active calls (if any exist) and accepts the other 
       
   425 // (held or waiting) call. 
       
   426 // 1<idx> = Releases specified active call only (<idx> = digit from 1 to 9. 
       
   427 // Command is e.g. "11" ). 
       
   428 // 2 = Places all active calls (if any exist) on hold and accepts the other 
       
   429 // (held or waiting) call. 
       
   430 // 2<idx> = Request private consultation mode with specified call (<idx> = 
       
   431 // from 1 to 9. Command is e.g. "21" ). 
       
   432 // (Place all calls on hold EXCEPT the call indicated by <idx>.) 
       
   433 // 3 = Adds a held call to the conversation. 
       
   434 // 4 = Connects the two calls and disconnects the subscriber from both calls 
       
   435 // (Explicit Call Transfer). Support for this value and its associated 
       
   436 // functionality is optional for the HF. 
       
   437 // 
       
   438 // (other items were commented in a header).
       
   439 // -----------------------------------------------------------------------------
       
   440 //
       
   441 void CPhoneHandlerControl::MultipartyCalling( const TDesC8& aData )
       
   442 	{
       
   443 	TBool error( EFalse );
       
   444 	iChldCommand = 0;
       
   445 	iChldCallNumber = 0;
       
   446 	TBuf8< KRemConExtParamMaxLength > buf( aData );
       
   447 	buf.Trim();
       
   448 	TInt length = buf.Length();
       
   449 	
       
   450 	// Check invalid number of characters
       
   451 	if ( length < KMultipartyCallMinParam || length > KMultipartyCallMaxParam )
       
   452 	    {
       
   453 	    error = ETrue;
       
   454 	    }
       
   455 	else
       
   456 	    {
       
   457 	    TLex8 param;
       
   458 	    // Set command	
       
   459 		param.Assign( buf.Mid( 0, 1 ) );
       
   460 		if( param.Val( iChldCommand ) != KErrNone )
       
   461 			{
       
   462 			error = ETrue;
       
   463 			}
       
   464 		else if ( length == KMultipartyCallMaxParam )
       
   465 	    	{
       
   466 			// Set call number
       
   467 			param.Assign( buf.Mid(1) );
       
   468 			if( param.Val( iChldCallNumber ) != KErrNone )
       
   469 				{
       
   470 				error = ETrue;
       
   471 				}
       
   472 	    	}
       
   473 	    }
       
   474 
       
   475 	if( error )
       
   476 		{
       
   477 		// Invalid command 
       
   478 		iResponse->SetResponse( ERemConExt3WaysCalling, KErrArgument );
       
   479   		iResponse->Process();
       
   480   		return;	
       
   481 		}
       
   482 		
       
   483 	COM_TRACE_2( "[PHONECMDHANDLER] CPhoneHandlerControl::MultipartyCalling() iChldCommand=%d, iChldCallNumber=%d", iChldCommand, iChldCallNumber );
       
   484 		
       
   485 	StartProcessing( ERemConExt3WaysCalling );
       
   486 	
       
   487 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::MultipartyCalling() end" );
       
   488 	}
       
   489 	
       
   490 // -----------------------------------------------------------------------------
       
   491 // CPhoneHandlerControl::GenerateDTMF
       
   492 // (other items were commented in a header).
       
   493 // -----------------------------------------------------------------------------
       
   494 //
       
   495 void CPhoneHandlerControl::GenerateDTMF( const TChar aChar )
       
   496 	{
       
   497 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::GenerateDTMF() start" );
       
   498 	
       
   499 	iChar = aChar;
       
   500 	
       
   501 	StartProcessing( ERemConExtGenerateDTMF );
       
   502 	
       
   503 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::GenerateDTMF() end" );
       
   504 	}
       
   505 	
       
   506 // -----------------------------------------------------------------------------
       
   507 // CPhoneHandlerControl::SpeedDial
       
   508 // (other items were commented in a header).
       
   509 // -----------------------------------------------------------------------------
       
   510 //
       
   511 void CPhoneHandlerControl::SpeedDial( const TInt aIndex )
       
   512 	{
       
   513 	COM_TRACE_1( "[PHONECMDHANDLER] CPhoneHandlerControl::SpeedDial() aIndex=%d", aIndex );
       
   514 
       
   515 	iIndex = aIndex;
       
   516 	
       
   517 	StartProcessing( ERemConExtSpeedDial );
       
   518 	
       
   519 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::SpeedDial() end" );
       
   520 	}
       
   521 
       
   522 // -----------------------------------------------------------------------------
       
   523 // CPhoneHandlerControl::StartProcessing
       
   524 // Creates an object that executes call handling command received from 
       
   525 // accessory.
       
   526 // (other items were commented in a header).
       
   527 // -----------------------------------------------------------------------------
       
   528 //
       
   529 void CPhoneHandlerControl::StartProcessing(	
       
   530 	const TRemConExtCallHandlingApiOperationId aOperation )
       
   531 	{
       
   532 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::StartProcessing() start" );
       
   533     		
       
   534 	// Create a service
       
   535 	MPhoneHandlerService* service = NULL;
       
   536 	TInt error( KErrNone );
       
   537 	TRAP( error, service = CreateServiceL( aOperation ) ); 
       
   538 		
       
   539 	COM_TRACE_1( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() returned %d", error );
       
   540 		
       
   541 	if( error )
       
   542 		{
       
   543 		COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::StartProcessing(): service wasn't created succesfully." );
       
   544 		
       
   545 		// An error happened. Delete service, if it exists.
       
   546 		if( service )
       
   547 			{
       
   548 			service->Delete();
       
   549 			service = NULL;
       
   550 			}
       
   551 		
       
   552 		iResponse->SetResponse( aOperation, error );
       
   553   		iResponse->Process();
       
   554   		return;
       
   555 		}
       
   556 	else
       
   557 		{
       
   558 		// start service
       
   559 		service->Process();	
       
   560 		iSwitchCall = EFalse;
       
   561 		}
       
   562 			
       
   563 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::StartProcessing() end" );
       
   564     }
       
   565     
       
   566 // -----------------------------------------------------------------------------
       
   567 // CPhoneHandlerControl::CreateServiceL
       
   568 // (other items were commented in a header).
       
   569 // -----------------------------------------------------------------------------
       
   570 //
       
   571 MPhoneHandlerService* CPhoneHandlerControl::
       
   572 	CreateServiceL( const TRemConExtCallHandlingApiOperationId aOperation )
       
   573     {
       
   574     COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() start" );
       
   575       
       
   576     MPhoneHandlerService* pService = NULL;
       
   577 
       
   578     switch( aOperation )
       
   579         {
       
   580         case ERemConExtAnswerCall:
       
   581 		    {
       
   582 		    COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() - ERemConExtAnswerCall command" );
       
   583 		    COM_TRACE_1( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() - iActiveCalls is %d", iActiveCalls );
       
   584 
       
   585 			/*    	    
       
   586     	    if( iActiveCalls > 0 )
       
   587     	    	{
       
   588     	    	// Multiparty call
       
   589     	    	iSwitchCall = ETrue;
       
   590     	    	pService = CPhoneHandlerMultipartyCall::NewL( *this );
       
   591     	    	}
       
   592     	    else
       
   593     	    	{
       
   594     	    	// non-multiparty call
       
   595     	    	pService = CPhoneHandlerAnswerCall::NewL( *this );
       
   596     	    	}
       
   597     	    */
       
   598     	    pService = CPhoneHandlerAnswerCall::NewL( *this );
       
   599 
       
   600             break;	
       
   601 		    }
       
   602 		    
       
   603         case ERemConExtEndCall:
       
   604 		    {
       
   605 		    COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() - ERemConExtEndCall command" );
       
   606     	    
       
   607 		    pService = CPhoneHandlerEndCall::NewL( *this );
       
   608 		    
       
   609 		    break;	
       
   610 		    }
       
   611 		    
       
   612         case ERemConExtAnswerEnd:
       
   613         	{
       
   614         	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() - ERemConExtAnswerEnd command" );
       
   615     	            	
       
   616         	TInt callState( EPSCTsyCallStateUninitialized );
       
   617     		iProperty.Get( KPSUidCtsyCallInformation, KCTsyCallState, callState ); 
       
   618     		
       
   619     		COM_TRACE_1( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() call state = %d", callState );
       
   620 			   
       
   621 		    if( callState != EPSCTsyCallStateUninitialized &&
       
   622 		    	callState != EPSCTsyCallStateNone && 
       
   623 		    	callState != EPSCTsyCallStateDisconnecting )
       
   624 		    	{
       
   625 		    	if( callState == EPSCTsyCallStateAlerting ||
       
   626 		    		callState == EPSCTsyCallStateDialling ||
       
   627 		    		callState == EPSCTsyCallStateAnswering ||
       
   628 		    		callState == EPSCTsyCallStateConnected ||
       
   629 		    		callState == EPSCTsyCallStateHold )
       
   630 		    		{
       
   631 		    		pService = CPhoneHandlerEndCall::NewL( *this, 
       
   632 		    									   	   aOperation );
       
   633 		    		}
       
   634 		    	// callState == EPSTelephonyCallStateRinging
       
   635 		    	else
       
   636 		    		{
       
   637 		    		COM_TRACE_1( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() iActiveCalls = %d", iActiveCalls );
       
   638 		    		if( iActiveCalls > 0 )
       
   639 		    			{
       
   640 		    			// multicall case : End call that has existed longer.
       
   641 		    			// (From UI viewpoint ringing call is in waiting state.)
       
   642 		    			pService = CPhoneHandlerEndCall::NewL( *this, 
       
   643 		    									   	   aOperation );
       
   644 		    	        if( callState == EPSCTsyCallStateRinging )
       
   645 		    	            {
       
   646 		    	            // In multiparty case the telephony key is not
       
   647 		    	            // updated. The call amount is updated manually.
       
   648 		    	            iActiveCalls--;
       
   649 		    	            }
       
   650 		    			}
       
   651 		    		else
       
   652 		    			{
       
   653 		    			pService = CPhoneHandlerAnswerCall::NewL( 
       
   654 		    							*this, 
       
   655 		    							aOperation );
       
   656 		    			}
       
   657 		    		}
       
   658 		    	}
       
   659 		    else
       
   660 		    	{
       
   661 		    	// Send / end button was pressed when there were not 
       
   662 		    	// any calls active. Response has to be sent back to accessory
       
   663 		    	// at least for following reasons:
       
   664 		    	
       
   665 		    	// 1. RemCon FW releases message related memory only when response
       
   666 		    	// is sent back to accessory.
       
   667 		    	
       
   668 		    	// 2. BT accessory key press producing ERemConExtAnswerEnd 
       
   669 		    	// operation has some other meaning than answer/end call 
       
   670 		    	// and it's processed by proper client. However, there 
       
   671 		    	// might be a situation where proper client isn't active 
       
   672 		    	// and can't process command. In any case RemCon/BT accessory
       
   673 		    	// requires response to command. That's why PhoneCmdHandler 
       
   674 		    	// sends reponse to command. 
       
   675 								
       
   676 				iResponse->SetResponse( aOperation, KErrNone );
       
   677 				pService = iResponse;
       
   678 				}
       
   679         	break;
       
   680         	} 
       
   681 		    
       
   682 		case ERemConExtDialCall:
       
   683 		    {
       
   684 		    COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() - ERemConExtDialCall command" );
       
   685     	    		    
       
   686 		   	pService = CPhoneHandlerDialCall::NewL( *this );
       
   687             break;	
       
   688 		    }
       
   689 		    
       
   690 		case ERemConExtVoiceDial:
       
   691         	{
       
   692 		    COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() - ERemConExtVoiceDial command" );
       
   693     	    		    
       
   694 		    pService = CPhoneHandlerVoiceDial::NewL( *this );
       
   695             break;	
       
   696 		    }
       
   697 		    
       
   698         case ERemConExtLastNumberRedial:
       
   699         	{
       
   700 		    COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() - ERemConExtLastNumberRedial command" );
       
   701     	    		    
       
   702 		    pService = CPhoneHandlerLastNumberRedial::NewL( *this );
       
   703             break;	
       
   704 		    }
       
   705 		    
       
   706 		case ERemConExt3WaysCalling:
       
   707         	{
       
   708 		    COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() - ERemConExt3WaysCalling command" );
       
   709     	    		    
       
   710 		    pService = CPhoneHandlerMultipartyCall::NewL( *this );
       
   711             break;	
       
   712 		    }
       
   713 		    
       
   714 		case ERemConExtGenerateDTMF:
       
   715         	{
       
   716 		    COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() - ERemConExtGenerateDTMF command" );
       
   717     	    		    
       
   718 		    pService = CPhoneHandlerDTMF::NewL( *this );
       
   719             break;	
       
   720 		    }
       
   721 		    
       
   722         case ERemConExtSpeedDial:
       
   723         	{
       
   724         	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() - ERemConExtSpeedDial command" );
       
   725     	            	
       
   726         	InitializeSpeedDialL();
       
   727         	pService = CPhoneHandlerDialCall::NewL( *this, 
       
   728         											aOperation );
       
   729             break;	
       
   730 		    } 
       
   731 				    
       
   732         default:
       
   733         	{
       
   734         	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() Unspecified state" );
       
   735 			break;
       
   736 	       	}
       
   737         };
       
   738         
       
   739     COM_TRACE_1( "[PHONECMDHANDLER] CPhoneHandlerControl::CreateServiceL() end, %d", pService );
       
   740     return pService;
       
   741     }
       
   742 
       
   743 // -----------------------------------------------------------------------------
       
   744 // CPhoneHandlerControl::InitializeSpeedDialL
       
   745 // (other items were commented in a header).
       
   746 // -----------------------------------------------------------------------------
       
   747 //
       
   748 void CPhoneHandlerControl::InitializeSpeedDialL()
       
   749     {
       
   750     COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::InitializeSpeedDialL() start" );
       
   751     
       
   752     // first check contack engine is not in busy
       
   753   TInt cntEngState( 0 );
       
   754 	TInt err = iProperty.Get( KUidSystemCategory, conn::KUidBackupRestoreKey, cntEngState ); 
       
   755   
       
   756 	if( err == KErrNotFound || cntEngState == 0 || 
       
   757 			cntEngState & conn::KBURPartTypeMask == conn::EBURNormal || 
       
   758 			cntEngState & conn::KBackupIncTypeMask == conn::ENoBackup )
       
   759 		{
       
   760 	    // Get phone number from phonebook by index	
       
   761 		CPbkContactEngine* ptr = CPbkContactEngine::NewL();
       
   762     CleanupStack::PushL( ptr );       
       
   763 		TRACE_ASSERT( ptr != NULL );
       
   764 		ptr->GetSpeedDialFieldL( iIndex, iTelNumber );
       
   765 		COM_TRACE_1( "[PHONECMDHANDLER] CPhoneHandlerControl::InitializeSpeedDialL() speed dial number is %S", &iTelNumber );
       
   766 		CleanupStack::PopAndDestroy( ptr );
       
   767 		}
       
   768 	else
       
   769 		{
       
   770 		// contact engine is in busy
       
   771 		COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::InitializeSpeedDialL() contact engine is in backup/restore" );
       
   772 		User::Leave( KErrInUse );
       
   773 		}
       
   774 		
       
   775 	COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::InitializeSpeedDialL() end" );
       
   776 	}
       
   777 
       
   778 // -----------------------------------------------------------------------------
       
   779 // CPhoneHandlerControl::SwitchCall
       
   780 // (other items were commented in a header).
       
   781 // -----------------------------------------------------------------------------
       
   782 //
       
   783 TBool CPhoneHandlerControl::SwitchCall()
       
   784     {
       
   785     return iSwitchCall;
       
   786 	}
       
   787 
       
   788 // ---------------------------------------------------------
       
   789 // CPhoneHandlerControl::IsAutoLockOn
       
   790 // ---------------------------------------------------------
       
   791 //
       
   792 TBool CPhoneHandlerControl::IsAutoLockOn() const
       
   793     {
       
   794     COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::IsAutoLockOn() start " );
       
   795     TInt err( KErrNone );
       
   796     TInt value( EAutolockStatusUninitialized );
       
   797 
       
   798     err = RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, value );
       
   799     if ( err != KErrNone )
       
   800         {
       
   801         value = err;
       
   802         }
       
   803     COM_TRACE_1( "[PHONECMDHANDLER] CPhoneHandlerControl::IsAutoLockOn() autolock value = %d", value );
       
   804     
       
   805     return value > EAutolockOff ? ETrue : EFalse;
       
   806       
       
   807     }
       
   808 // ---------------------------------------------------------
       
   809 // CPhoneHandlerControl::IsBTAccessoryCmd
       
   810 // ---------------------------------------------------------
       
   811 //
       
   812 TBool CPhoneHandlerControl::IsBTAccessoryCmd() const
       
   813     {
       
   814     COM_TRACE_( "[PHONECMDHANDLER] CPhoneHandlerControl::IsBTAccessoryCmd() start " );
       
   815     TBool retval( EFalse );
       
   816     
       
   817     TRemConExtCmdSource source;             
       
   818     iTarget->GetCommandSourceInfo( source );
       
   819     if ( source == ERemConExtCmdSourceBluetooth )
       
   820         {       
       
   821         retval = ETrue;
       
   822         }
       
   823     
       
   824     COM_TRACE_1( "[PHONECMDHANDLER] CPhoneHandlerControl::IsBTAccessoryCmd() GetCommandSourceInfo = %d", source );
       
   825        
       
   826     return retval;
       
   827     }
       
   828 
       
   829  
       
   830 
       
   831  
       
   832 // ======================== OTHER EXPORTED FUNCTIONS ===========================
       
   833 
       
   834 // End of File