callcontinuity/vcc/src/cvccperformer.cpp
branchRCL_3
changeset 22 d38647835c2e
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 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:   CCP reference plug-in implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <mccpcall.h>
       
    19 #include <mccpcallobserver.h>
       
    20 #include "ccpdefs.h" 
       
    21 #include <mccpforwardprovider.h>
       
    22 
       
    23 #include "vccdefinitions.h"
       
    24 #include "cvccperformer.h"
       
    25 #include "vcchotrigger.h"
       
    26 #include "vccsettingsreader.h"
       
    27 #include "cvcctransferprovider.h"
       
    28 
       
    29 //state machine
       
    30 #include "tvccstateinit.h"
       
    31 #include "tvccstatecalling.h"
       
    32 #include "tvccstatefailing.h"
       
    33 #include "tvccstatereleasing.h"
       
    34 #include "rubydebug.h"
       
    35 
       
    36 _LIT( KSVPSipPrefix, "sip:" );
       
    37 // -----------------------------------------------------------------------------
       
    38 // 
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CVccPerformer::CVccPerformer(RPointerArray<CConvergedCallProvider>& aProviders,
       
    42 							 TVccState& aState, CVccHoTrigger& aVccHoTrigger,
       
    43 							 TBool aCsOriginated ) :
       
    44     iProviders(aProviders),
       
    45     iCurrentState(&aState),
       
    46     iVccHoTrigger( aVccHoTrigger ),
       
    47     iCsOriginated( aCsOriginated),
       
    48     iTransferProvider( NULL ),
       
    49     iRemotePartiesSet( EFalse )
       
    50     {
       
    51     RUBY_DEBUG_BLOCK( "CVccPerformer::CVccPerformer" );
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // Default C++ destructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CVccPerformer::~CVccPerformer()
       
    59     {
       
    60     RUBY_DEBUG0( "CVccPerformer::~CVccPerformer() - ENTER" );
       
    61 	delete iVccPsp;
       
    62 	delete iTransferProvider;
       
    63     RUBY_DEBUG0( "CVccPerformer::~CVccPerformer() - EXIT" );
       
    64     }
       
    65 // -----------------------------------------------------------------------------
       
    66 // Call creating comes here. In MT case observer is null and CCE will call
       
    67 // SetObserver later on for us
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CVccPerformer* CVccPerformer::NewL(
       
    71 						RPointerArray<CConvergedCallProvider>& aProviders, 
       
    72 						TVccState& aState,
       
    73 						CVccHoTrigger& aVccHoTrigger,
       
    74 						TBool aCsOriginated)
       
    75     {
       
    76     RUBY_DEBUG_BLOCKL( "CVccPerformer::NewL" );
       
    77     CVccPerformer* self = new( ELeave ) CVccPerformer(aProviders, 
       
    78     													aState, 
       
    79     													aVccHoTrigger,
       
    80     													aCsOriginated);
       
    81     CleanupStack::PushL( self );
       
    82     self->ConstructL();
       
    83     CleanupStack::Pop(self);
       
    84 
       
    85     return self;
       
    86     }
       
    87 // -----------------------------------------------------------------------------
       
    88 // 
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CVccPerformer::ConstructL()
       
    92     {
       
    93     RUBY_DEBUG_BLOCKL( "CVccPerformer::ConstructL" );
       
    94         
       
    95     iVccPsp = CVccEngPsProperty::NewL();
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // User has answered the incoming call
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 TInt CVccPerformer::Answer()
       
   103     {
       
   104     RUBY_DEBUG_BLOCK( "CVccPerformer::Answer" );
       
   105  	return iCurrentState->Answer(*iPrimaryCall);
       
   106     }
       
   107     
       
   108 // -----------------------------------------------------------------------------
       
   109 // User has rejected the incoming call
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 TInt CVccPerformer::Reject()
       
   113     {
       
   114     RUBY_DEBUG_BLOCK( "CVccPerformer::Reject" );
       
   115   	return iCurrentState->Reject(*iPrimaryCall);
       
   116     }
       
   117     
       
   118 // -----------------------------------------------------------------------------
       
   119 // Queue incoming call
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 TInt CVccPerformer::Queue()
       
   123     {
       
   124     RUBY_DEBUG_BLOCK( "CVccPerformer::Queue" );
       
   125  	return iCurrentState->Queue(*iPrimaryCall);
       
   126     }
       
   127     
       
   128 // -----------------------------------------------------------------------------
       
   129 // Dial a new call
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 TInt CVccPerformer::Dial()
       
   133     {
       
   134     RUBY_DEBUG_BLOCK( "CVccPerformer::Dial" );
       
   135  	return iCurrentState->Dial(*iPrimaryCall);
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // MT call user ringing now
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 TInt CVccPerformer::Ringing()
       
   143     {
       
   144     RUBY_DEBUG_BLOCK( "CVccPerformer::Ringing" );
       
   145 	return iCurrentState->Ringing(*iPrimaryCall);
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // End current call
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 TInt CVccPerformer::HangUp()
       
   153     {
       
   154     RUBY_DEBUG_BLOCK( "CVccPerformer::HangUp" );
       
   155     return iCurrentState->HangUp(*this, *iPrimaryCall);
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // Cancel ongoing request
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 TInt CVccPerformer::Cancel()
       
   163     {
       
   164     RUBY_DEBUG_BLOCK( "CVccPerformer::Cancel" );
       
   165   	return iCurrentState->Cancel(*iPrimaryCall);
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // Hold call
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 TInt CVccPerformer::Hold()
       
   173     {
       
   174     RUBY_DEBUG_BLOCK( "CVccPerformer::Hold" );
       
   175     return iCurrentState->Hold(*iPrimaryCall); 
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // Resume held call
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 TInt CVccPerformer::Resume()
       
   183     {
       
   184     RUBY_DEBUG_BLOCK( "CVccPerformer::Resume" );
       
   185  	return iCurrentState->Resume(*iPrimaryCall);
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // Swap hold/resume states
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 TInt CVccPerformer::Swap()
       
   193     {
       
   194     RUBY_DEBUG_BLOCK( "CVccPerformer::Swap" );
       
   195     return iCurrentState->Swap(*iPrimaryCall);
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // Get call recipient
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 const TDesC& CVccPerformer::RemoteParty() const
       
   203     {
       
   204     RUBY_DEBUG_BLOCK( "CVccPerformer::RemoteParty" );
       
   205     
       
   206     return iOrigRemoteParty;
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // RemotePartyName
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 const TDesC& CVccPerformer::RemotePartyName()
       
   214     {
       
   215     RUBY_DEBUG_BLOCK( "CVccPerformer::RemotePartyName" );
       
   216     return iOrigRemotePartyName;
       
   217     //return iCurrentState->RemoteParty(*iPrimaryCall);
       
   218     }
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // Get call recipient
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 const TDesC& CVccPerformer::DialledParty() const
       
   225     {
       
   226     RUBY_DEBUG_BLOCK( "CVccPerformer::DialledParty" );
       
   227     return iCurrentState->DialledParty(*iPrimaryCall);
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // Is call forwarded or not
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 TBool CVccPerformer::IsCallForwarded() const
       
   235     {
       
   236     RUBY_DEBUG_BLOCK( "CVccPerformer::IsCallForwarded " );
       
   237  	return iCurrentState->IsCallForwarded(*iPrimaryCall);
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // Is call mobile originated or not
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 TBool CVccPerformer::IsMobileOriginated() const
       
   245     {
       
   246     RUBY_DEBUG_BLOCK( "CVccPerformer::IsMobileOriginated" );
       
   247  	return iCurrentState->IsMobileOriginated(*iPrimaryCall);
       
   248     }
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // Get current call state
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 MCCPCallObserver::TCCPCallState CVccPerformer::State() const
       
   255     {
       
   256     RUBY_DEBUG_BLOCK( "CVccPerformer::State " );
       
   257  	return iCurrentState->State(*iPrimaryCall);
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // Get plug-in UID
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 TUid CVccPerformer::Uid() const
       
   265     {
       
   266     RUBY_DEBUG_BLOCK( "CVccPerformer::Uid " );
       
   267   
       
   268     return TUid::Uid( KVccCallProviderPlugId );
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // get call capabilities
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 MCCPCallObserver::TCCPCallControlCaps CVccPerformer::Caps() const
       
   276     {
       
   277     RUBY_DEBUG_BLOCK( "CVccPerformer::CVccPerformer" );
       
   278  	return iCurrentState->Caps(*iPrimaryCall);
       
   279     }
       
   280 
       
   281 
       
   282 // -----------------------------------------------------------------------------
       
   283 // SecureSpecified()
       
   284 // -----------------------------------------------------------------------------
       
   285 //
       
   286 TBool CVccPerformer::SecureSpecified() const
       
   287     {
       
   288     return iCurrentState->SecureSpecified( *iPrimaryCall );
       
   289     }
       
   290 // -----------------------------------------------------------------------------
       
   291 // Is call secured
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 TBool CVccPerformer::IsSecured() const
       
   295     {
       
   296     RUBY_DEBUG_BLOCK( "CVccPerformer::IsSecured" );
       
   297     return iCurrentState->IsSecured(*iPrimaryCall);
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // Set parameters
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 void CVccPerformer::SetParameters( const CCCPCallParameters& aNewParams )
       
   305     {
       
   306     RUBY_DEBUG_BLOCK( "CVccPerformer::SetParameters " );
       
   307     iCurrentState->SetParameters(aNewParams);
       
   308     }
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // Get parameters
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 const CCCPCallParameters& CVccPerformer::Parameters() const
       
   315     {
       
   316     RUBY_DEBUG_BLOCK( "CVccPerformer::Parameters" );
       
   317     return iCurrentState->Parameters(*iPrimaryCall);
       
   318     }
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // Return used tone.
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 TCCPTone CVccPerformer::Tone() const
       
   325 	{
       
   326 	RUBY_DEBUG_BLOCK( "CVccPerformer::Tone " );
       
   327 	return iCurrentState->Tone(*iPrimaryCall);
       
   328 	}
       
   329   
       
   330 // -----------------------------------------------------------------------------
       
   331 // Get forward call enabling methods for the call
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 MCCPForwardProvider* CVccPerformer::ForwardProviderL
       
   335                                         ( const MCCPForwardObserver& aObserver )
       
   336     {
       
   337     RUBY_DEBUG_BLOCKL( "CVccPerformer::ForwardProviderL " );
       
   338  	return iPrimaryCall->ForwardProviderL(aObserver);
       
   339     }
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // Get transfer call enabling methods for the call
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 MCCPTransferProvider* CVccPerformer::TransferProviderL
       
   346                                         ( const MCCPTransferObserver& aObserver )
       
   347     {
       
   348     RUBY_DEBUG_BLOCKL( "CVccPerformer::TransferProviderL " );
       
   349 	if ( !iTransferProvider )
       
   350           {    
       
   351           iTransferProvider = CVccTransferProvider::NewL(this);
       
   352           iTransferProvider->AddObserverL( aObserver );
       
   353           }
       
   354       
       
   355     return iTransferProvider;
       
   356     }
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // Add observer.
       
   360 // the CCE will call that in the MT call case, to put the observer for a call in place
       
   361 // -----------------------------------------------------------------------------
       
   362 //
       
   363 void CVccPerformer::AddObserverL( const MCCPCallObserver& aObserver )
       
   364     {
       
   365     RUBY_DEBUG_BLOCKL( "CVccPerformer::AddObserverL " );
       
   366  	iCallObs = const_cast<MCCPCallObserver*>( &aObserver );
       
   367  	iCurrentState->AddObserverL(*this, *iPrimaryCall);
       
   368     }
       
   369 
       
   370 // -----------------------------------------------------------------------------
       
   371 // remove observer.
       
   372 // -----------------------------------------------------------------------------
       
   373 //
       
   374 TInt CVccPerformer::RemoveObserver(const MCCPCallObserver& aObserver )
       
   375     {
       
   376     RUBY_DEBUG_BLOCK( "CVccPerformer::RemoveObserver " );
       
   377 	return iCurrentState->RemoveObserver(aObserver, *iPrimaryCall);
       
   378     }
       
   379 
       
   380 // -----------------------------------------------------------------------------
       
   381 // Dial from MCCPCSCall
       
   382 // -----------------------------------------------------------------------------
       
   383 //
       
   384 TInt CVccPerformer::Dial( const TDesC8& aCallParams )
       
   385 	{
       
   386 	RUBY_DEBUG_BLOCK( "CVccPerformer::Dial" );
       
   387 	return iCurrentState->Dial(aCallParams, 
       
   388 	                        *static_cast<MCCPCSCall*>(iPrimaryCall));
       
   389 	}
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // NoFDNCheck from MCCPCSCall
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 void CVccPerformer::NoFDNCheck()
       
   396 	{
       
   397 	RUBY_DEBUG_BLOCK( "CVccPerformer::NoFDNCheck " );
       
   398 	iCurrentState->NoFDNCheck(*static_cast<MCCPCSCall*>(iPrimaryCall));
       
   399 	}
       
   400 
       
   401 // -----------------------------------------------------------------------------
       
   402 // GetMobileCallInfo from MCCPCSCall
       
   403 // -----------------------------------------------------------------------------
       
   404 //
       
   405 TInt CVccPerformer::GetMobileCallInfo( TDes8& aCallInfo ) const
       
   406 	{
       
   407 	RUBY_DEBUG_BLOCK( "CVccPerformer::GetMobileCallInfo " );
       
   408 	return iCurrentState->GetMobileCallInfo(aCallInfo,
       
   409 	                          *static_cast<MCCPCSCall*>(iPrimaryCall));
       
   410 	}
       
   411 	
       
   412 // -----------------------------------------------------------------------------
       
   413 // SwitchAlternatingCall from MCCPCSCall
       
   414 // -----------------------------------------------------------------------------
       
   415 //
       
   416 TInt CVccPerformer::SwitchAlternatingCall()
       
   417 	{
       
   418 	RUBY_DEBUG_BLOCK( "CVccPerformer::SwitchAlternatingCall " );
       
   419 	return iCurrentState->SwitchAlternatingCall(
       
   420 	                         *static_cast<MCCPCSCall*>(iPrimaryCall));
       
   421 	}
       
   422 
       
   423 // -----------------------------------------------------------------------------
       
   424 // GetMobileDataCallCaps from MCCPCSCall
       
   425 // -----------------------------------------------------------------------------
       
   426 //
       
   427 TInt CVccPerformer::GetMobileDataCallCaps( TDes8& aCaps ) const
       
   428 	{
       
   429 	RUBY_DEBUG_BLOCK( "CVccPerformer::GetMobileDataCallCaps " );
       
   430 	return iCurrentState->GetMobileDataCallCaps(aCaps,
       
   431 	                          *static_cast<MCCPCSCall*>(iPrimaryCall));
       
   432 	}
       
   433 
       
   434 // -----------------------------------------------------------------------------
       
   435 // LogDialedNumber from MCCPCSCall
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 TInt CVccPerformer::LogDialedNumber() const
       
   439 	{
       
   440 	RUBY_DEBUG_BLOCK( "CVccPerformer::LogDialedNumber " );
       
   441 	return iCurrentState->LogDialedNumber(
       
   442 	                          *static_cast<MCCPCSCall*>(iPrimaryCall) );
       
   443 	}
       
   444 	
       
   445 // -----------------------------------------------------------------------------
       
   446 // MCCPCallObserver:: ErrorOccurred
       
   447 // -----------------------------------------------------------------------------
       
   448 //
       
   449 void CVccPerformer::ErrorOccurred(const TCCPError aError, MCCPCall* aCall )
       
   450 	{
       
   451 	RUBY_DEBUG_BLOCK( "CVccPerformer::TCCPError ");	
       
   452 	iCurrentState->ErrorOccurred(*this, aError, aCall );
       
   453 	}
       
   454 	
       
   455 // -----------------------------------------------------------------------------
       
   456 // MCCPCallObserver:: CallStateChanged
       
   457 // -----------------------------------------------------------------------------
       
   458 //	
       
   459 void CVccPerformer::CallStateChanged( 
       
   460                                    const MCCPCallObserver::TCCPCallState aState, 
       
   461                                    MCCPCall* aCall  )
       
   462 	{
       
   463 	RUBY_DEBUG_BLOCK( "CVccPerformer::CallStateChanged ");
       
   464 	iCurrentState->CallStateChanged( *this, aState, aCall );		
       
   465 	}
       
   466 
       
   467 // -----------------------------------------------------------------------------
       
   468 // MCCPCallObserver:: CallStateChangedWithInband
       
   469 // -----------------------------------------------------------------------------
       
   470 //	
       
   471 void CVccPerformer::CallStateChangedWithInband( 
       
   472                                    const MCCPCallObserver::TCCPCallState aState,
       
   473                                    MCCPCall* aCall )
       
   474 	{
       
   475 	RUBY_DEBUG_BLOCK( "CVccPerformer::CallStateChanged ");
       
   476 	iCurrentState->CallStateChangedWithInband( *this, aState, aCall );
       
   477 	}
       
   478 
       
   479 // -----------------------------------------------------------------------------
       
   480 // MCCPCallObserver::CallEventOccurred
       
   481 // -----------------------------------------------------------------------------
       
   482 //	
       
   483 void CVccPerformer::CallEventOccurred( 
       
   484                                    const MCCPCallObserver::TCCPCallEvent aEvent, 
       
   485                                    MCCPCall* aCall  )
       
   486 	{
       
   487 	RUBY_DEBUG_BLOCK( "CVccPerformer::CallEventOccurred ");
       
   488 	iCurrentState->CallEventOccurred(*this, aEvent, aCall);
       
   489 	}
       
   490 	
       
   491 // -----------------------------------------------------------------------------
       
   492 // MCCPCallObserver::CallCapsChanged
       
   493 // -----------------------------------------------------------------------------
       
   494 //	
       
   495 void CVccPerformer::CallCapsChanged(const TUint32 aCapsFlags, MCCPCall* aCall )
       
   496 	{
       
   497 	RUBY_DEBUG_BLOCK( "CVccPerformer::CallCapsChanged");
       
   498 	iCurrentState->CallCapsChanged(*this, aCapsFlags, aCall );
       
   499 	}
       
   500 
       
   501 // -----------------------------------------------------------------------------
       
   502 //  Get CallObserver()
       
   503 // -----------------------------------------------------------------------------
       
   504 //
       
   505 MCCPCallObserver* CVccPerformer::CallObserver()
       
   506     {
       
   507     RUBY_DEBUG_BLOCK( "CVccPerformer::CallObserver " );
       
   508   	return iCallObs;
       
   509     }
       
   510 
       
   511 // -----------------------------------------------------------------------------
       
   512 //  Creates actual implementation
       
   513 // -----------------------------------------------------------------------------
       
   514 //
       
   515 MCCPCall* CVccPerformer::CreatePrimaryCallL( 
       
   516                                  const CCCPCallParameters& aParameters,
       
   517                                  const TDesC& aRecipient,
       
   518                                  const MCCPCallObserver& aObserver )
       
   519 	{
       
   520     RUBY_DEBUG_BLOCKL( "CVccPerformer::CreatePrimaryCallL" );
       
   521 
       
   522     iPrimaryCall = NULL;
       
   523     TInt index = KErrNotFound;
       
   524     if (aParameters.CallType() != CCPCall::ECallTypePS )
       
   525 	    {
       
   526 	    index = VoipProviderIndex( EFalse );
       
   527 	    }
       
   528     else
       
   529  	    {
       
   530  	    index = VoipProviderIndex( ETrue );
       
   531  	    }
       
   532     if( index != KErrNotFound )
       
   533         {
       
   534         iPrimaryCall = iProviders[ index ]->NewCallL(aParameters, aRecipient, *this);
       
   535         }
       
   536             
       
   537 	if( !iPrimaryCall )
       
   538 	    {
       
   539 	    User::Leave( KErrNotFound );
       
   540 	    }
       
   541     iCallObs = const_cast< MCCPCallObserver* >( &aObserver ); 
       
   542     
       
   543     SetRemoteParties();
       
   544     
       
   545 	return this;
       
   546 	}
       
   547 	
       
   548 // -----------------------------------------------------------------------------
       
   549 //  saves incoming call and returns itself
       
   550 // -----------------------------------------------------------------------------
       
   551 //
       
   552 MCCPCall* CVccPerformer::IncomingCall( MCCPCall* aCall )
       
   553     {
       
   554     RUBY_DEBUG_BLOCK( "CVccPerformer::IncomingCall" );
       
   555     iPrimaryCall = aCall;
       
   556     SetRemoteParties();
       
   557     
       
   558     return this;
       
   559      }
       
   560 
       
   561 // -----------------------------------------------------------------------------
       
   562 //  saves 3rd party mo call and returns itself
       
   563 // -----------------------------------------------------------------------------
       
   564 //
       
   565 MCCPCall* CVccPerformer::MoCall( MCCPCall* aCall )
       
   566     {
       
   567     RUBY_DEBUG_BLOCK( "CVccPerformer::MoCall" );
       
   568     iPrimaryCall = aCall;
       
   569     return this;
       
   570      }
       
   571 
       
   572 // -----------------------------------------------------------------------------
       
   573 //  Returns actual call implementation
       
   574 // -----------------------------------------------------------------------------
       
   575 //	
       
   576 MCCPCall* CVccPerformer::PrimaryCall()
       
   577 	{
       
   578 	RUBY_DEBUG_BLOCK( "CVccPerformer::PrimaryCall" );
       
   579 	return iPrimaryCall;	
       
   580 	}
       
   581 	
       
   582 // -----------------------------------------------------------------------------
       
   583 //  Returns actual CS provider implementation
       
   584 // -----------------------------------------------------------------------------
       
   585 //
       
   586 CConvergedCallProvider& CVccPerformer::CsProvider()
       
   587 	{
       
   588 	RUBY_DEBUG_BLOCK( "CVccPerformer::CsProvider" );
       
   589 	return *iProviders[ VoipProviderIndex( EFalse ) ];
       
   590 	            
       
   591 	}
       
   592 	
       
   593 // -----------------------------------------------------------------------------
       
   594 //  Returns actual PS provider implementation
       
   595 // -----------------------------------------------------------------------------
       
   596 //
       
   597 CConvergedCallProvider& CVccPerformer::PsProvider()
       
   598 	{
       
   599 	RUBY_DEBUG_BLOCK( "CVccPerformer::PsProvider" );
       
   600 	return *iProviders[ VoipProviderIndex( ETrue ) ];
       
   601 	}
       
   602 
       
   603 // -----------------------------------------------------------------------------
       
   604 //  Updates the actual call
       
   605 // -----------------------------------------------------------------------------
       
   606 //
       
   607 void CVccPerformer::SetCall(MCCPCall* aCall)
       
   608     {
       
   609     TRAP_IGNORE( SetCallL( aCall) );
       
   610     }
       
   611 
       
   612 
       
   613 // -----------------------------------------------------------------------------
       
   614 //  Updates the actual call
       
   615 // -----------------------------------------------------------------------------
       
   616 //
       
   617 void CVccPerformer::SetCallL(MCCPCall* aCall)
       
   618 	{
       
   619 	__ASSERT_DEBUG(aCall == iSecondaryCall, User::Leave(KErrArgument));
       
   620     RUBY_DEBUG_BLOCK( "CVccPerformer::SetCall" );
       
   621     
       
   622     //inform through phone engine to phone about call bubble update needs
       
   623     MCCPCallObserver::TCCPCallEvent event = 
       
   624                               MCCPCallObserver::ECCPNotifyRemotePartyInfoChange;
       
   625     iCallObs->CallEventOccurred( event, this );
       
   626     
       
   627     //both secure call and not secure call events result in same 
       
   628     //securestatuschanged message in phone engine.
       
   629         
       
   630         
       
   631     MCCPCall* temp = iPrimaryCall;
       
   632 	iPrimaryCall = aCall;
       
   633 	iSecondaryCall = temp; //taking old call pointer
       
   634 	if (iTransferProvider)
       
   635 	    {
       
   636 	    iTransferProvider->UpdateL();
       
   637 	    }
       
   638 
       
   639 	MCCPCallObserver::TCCPCallEvent event2;
       
   640 	//if( iPrimaryCall->IsSecured() )
       
   641 	//    {
       
   642 	//    event2 = MCCPCallObserver::ECCPSecureCall;
       
   643 	//    }
       
   644 	//else
       
   645 	//    {
       
   646 	    event2 = MCCPCallObserver::ECCPNotSecureCall;
       
   647 	//    }
       
   648     iCallObs->CallEventOccurred( event2, this );
       
   649         
       
   650 	}
       
   651 	
       
   652 // -----------------------------------------------------------------------------
       
   653 //  Releases ongoing call
       
   654 // -----------------------------------------------------------------------------
       
   655 //
       
   656 TInt CVccPerformer::ReleaseCall(MCCPCall& /*aCall*/)
       
   657 	{
       
   658 	RUBY_DEBUG_BLOCK( "CVccPerformer::ReleaseCall" );
       
   659 	TInt err = KErrNotFound;
       
   660 	err = iCurrentState->ReleaseCall(*iPrimaryCall, iProviders);
       
   661 	iPrimaryCall = NULL;
       
   662 	return err;
       
   663 	}
       
   664 	
       
   665 // -----------------------------------------------------------------------------
       
   666 //  Suppressor calls this when HO is done
       
   667 // -----------------------------------------------------------------------------
       
   668 //    
       
   669 void CVccPerformer::HandoverReady()
       
   670     {
       
   671     RUBY_DEBUG_BLOCK( "CVccPerformer::HandoverReady" );    
       
   672 	iSecondaryCall = NULL;
       
   673     ActivateTrigger( ETrue );
       
   674     //get new service id for voip call and set it to parameters
       
   675     //this is used later for loading correct CTI plugins
       
   676     TInt VoIPServiceId(KErrNotFound);
       
   677     TRAP_IGNORE( VoIPServiceId = VccSettingsReader::VoIPServiceIdL() );
       
   678     RUBY_DEBUG1( "CVccPerformer::HandoverReady() -- new Service Id: %d", VoIPServiceId );
       
   679     CCCPCallParameters* params = NULL;
       
   680     TRAP_IGNORE( params = iPrimaryCall->Parameters().CloneL() );
       
   681     params->SetServiceId( VoIPServiceId );
       
   682     iPrimaryCall->SetParameters( *params );
       
   683     //inform through phone engine to phone about call bubble update needs
       
   684     MCCPCallObserver::TCCPCallEvent event = 
       
   685                               MCCPCallObserver::ECCPNotifyRemotePartyInfoChange;
       
   686     iCallObs->CallEventOccurred( event, this );
       
   687     
       
   688     RUBY_DEBUG0("Let HoTrigger know about changed domain");
       
   689 
       
   690     if( params->CallType() == CCPCall::ECallTypeCSVoice )
       
   691           {
       
   692           RUBY_DEBUG0("New domain is CS");
       
   693           iVccHoTrigger.SetCurrentDomainType( CVccHoTrigger::ECallDomainTypeCS );
       
   694           }
       
   695       else
       
   696           {
       
   697           RUBY_DEBUG0("New domain is PS");
       
   698           iVccHoTrigger.SetCurrentDomainType( CVccHoTrigger::ECallDomainTypePS );
       
   699           }
       
   700     
       
   701     delete params;
       
   702     }
       
   703 
       
   704 // -----------------------------------------------------------------------------
       
   705 //  Creates a new call to be handled
       
   706 // -----------------------------------------------------------------------------
       
   707 // 
       
   708 void CVccPerformer::CreateSecondaryCallL(
       
   709                                const CCCPCallParameters& aParameters,
       
   710 					      	   const TDesC& aRecipient,
       
   711 					      	   const MCCPCallObserver& aObserver)
       
   712 	{
       
   713 	RUBY_DEBUG_BLOCKL( "CVccPerformer::CreateLocalSecondaryCallL" );
       
   714 	iSecondaryCall = NULL;
       
   715 	TInt index = KErrNotFound;
       
   716 	if (aParameters.CallType() != CCPCall::ECallTypePS )
       
   717 	    {
       
   718 	    index = VoipProviderIndex( EFalse );
       
   719 	    }
       
   720 	else
       
   721 	    {
       
   722 	    index = VoipProviderIndex( ETrue );
       
   723 	    }
       
   724 	if( index != KErrNotFound )
       
   725 	    {
       
   726 	    iSecondaryCall = iProviders[ index ]->NewCallL(aParameters, 
       
   727 	                                                   aRecipient, 
       
   728 	                                                   aObserver);
       
   729 	    }
       
   730 	            
       
   731 	if( !iSecondaryCall )
       
   732 	    {
       
   733 	    User::Leave( KErrNotFound );
       
   734 	    }
       
   735 	}
       
   736 
       
   737 // -----------------------------------------------------------------------------
       
   738 //  Creates a new call to be handled
       
   739 // -----------------------------------------------------------------------------
       
   740 // 
       
   741 MCCPCall* CVccPerformer::SecondaryCall()
       
   742 	{
       
   743 	RUBY_DEBUG_BLOCK( "CVccPerformer::SecondaryCall" );
       
   744 	return iSecondaryCall;
       
   745 	}
       
   746 	
       
   747 // -----------------------------------------------------------------------------
       
   748 //  Updates the state with the next one
       
   749 // -----------------------------------------------------------------------------
       
   750 // 
       
   751 void CVccPerformer::SetState(TVccState& aState)
       
   752 	{
       
   753 	RUBY_DEBUG_BLOCK( "CVccPerformer::SetState" );
       
   754 	iCurrentState = &aState;
       
   755 	}
       
   756 
       
   757 // -----------------------------------------------------------------------------
       
   758 //  Returns the state name
       
   759 // -----------------------------------------------------------------------------
       
   760 // 
       
   761 TUint CVccPerformer::StateName() const
       
   762 	{
       
   763 	RUBY_DEBUG_BLOCK( "CVccPerformer::StateName" );
       
   764 	return iCurrentState->Name();
       
   765 	}
       
   766 
       
   767 // -----------------------------------------------------------------------------
       
   768 //  Returns the Notifier
       
   769 // -----------------------------------------------------------------------------
       
   770 // 
       
   771 CVccEngPsProperty& CVccPerformer::Notifier()
       
   772 	{
       
   773 	RUBY_DEBUG_BLOCK( "CVccPerformer::Notifier" );
       
   774 	return *iVccPsp;
       
   775 	}
       
   776 
       
   777 // -----------------------------------------------------------------------------
       
   778 //  Starts Handover procedure
       
   779 // -----------------------------------------------------------------------------
       
   780 // 
       
   781 void CVccPerformer::SwitchL( const TInt aValue )
       
   782 	{
       
   783 	RUBY_DEBUG_BLOCK( "CVccPerformer::DoHandover" );
       
   784 	//there must be an actuall call implementation created
       
   785 	__ASSERT_DEBUG(iPrimaryCall != NULL, User::Leave(KErrArgument));
       
   786     
       
   787 	//dont change remote party after/during handover
       
   788 	iRemotePartiesSet = ETrue;
       
   789 	// check which call is active and do handover for that call. other calls
       
   790 	// are dropped.
       
   791 	if( iPrimaryCall->State() == MCCPCallObserver::ECCPStateConnected )
       
   792 		{
       
   793         switch ( iPrimaryCall->Parameters().CallType() )
       
   794             {
       
   795             case CCPCall::ECallTypeCSVoice:
       
   796                 {
       
   797                 // CS call active
       
   798                 if ( aValue == EVccAutomaticStartCsToPsHoRequest || 
       
   799                      aValue == EVccManualStartCsToPsHoRequest ||
       
   800                      aValue == EVccAutomaticStartCsToPsHoRequestIfSingleCall )
       
   801                     {
       
   802                     // HO direction OK
       
   803                     RUBY_DEBUG0( "- CS to PS HO OK" );
       
   804             		iCurrentState->SwitchL(*this);
       
   805                     }
       
   806                 break;
       
   807                 }
       
   808             case CCPCall::ECallTypePS:
       
   809                 {
       
   810                 // PS call active
       
   811                 if ( aValue == EVccAutomaticStartPsToCsHoRequest || 
       
   812                      aValue == EVccManualStartPsToCsHoRequest ||
       
   813                      aValue == EVccAutomaticStartPsToCsHoRequestIfSingleCall )
       
   814                     {
       
   815                     // HO direction OK
       
   816                     RUBY_DEBUG0( "- PS to CS HO OK" );
       
   817 					iCurrentState->SwitchL(*this);
       
   818                     }
       
   819                 break;
       
   820                 }
       
   821             }        
       
   822 		}
       
   823 	}
       
   824 
       
   825 // -----------------------------------------------------------------------------
       
   826 //  Activates trigger when call becomes active
       
   827 // -----------------------------------------------------------------------------
       
   828 // 
       
   829 void CVccPerformer::ActivateTrigger( TBool aActivation )
       
   830 	{
       
   831 	RUBY_DEBUG_BLOCK( "CVccPerformer::ActivateTrigger" );
       
   832 	//Dont activate trigger if ho not allowed
       
   833 	if( aActivation )
       
   834 		{
       
   835 		// Trigger is started only if call type is CS or PS
       
   836 		CCPCall::TCallType type = iPrimaryCall->Parameters().CallType(); 
       
   837 		if ( type == CCPCall::ECallTypeCSVoice || 
       
   838 		     type == CCPCall::ECallTypePS )
       
   839 		    {
       
   840 		    //call became active, start trigger for automatic HOs
       
   841 		    //inform trigger about the original domain so it can check
       
   842 		    //possible HO restrictions
       
   843 		    iVccHoTrigger.Start( *this, iCsOriginated );
       
   844 		    }
       
   845 		}
       
   846 	else
       
   847 		{
       
   848 		//call is not active anymore, stop trigger
       
   849 		iVccHoTrigger.Stop( *this );
       
   850 		}
       
   851 	}
       
   852 
       
   853 // -----------------------------------------------------------------------------
       
   854 //  Updates PS key using trigger
       
   855 // -----------------------------------------------------------------------------
       
   856 // 
       
   857 void CVccPerformer::AllowHo( TBool aAllow )
       
   858     {
       
   859     TRAP_IGNORE( AllowHoL( aAllow) );
       
   860     }
       
   861 
       
   862 // -----------------------------------------------------------------------------
       
   863 //  Updates PS key using trigger
       
   864 // -----------------------------------------------------------------------------
       
   865 // 
       
   866 void CVccPerformer::AllowHoL( TBool aAllow )
       
   867     {
       
   868     RUBY_DEBUG_BLOCK( "CVccPerformer::AllowHoL" );
       
   869     if( aAllow )
       
   870         {
       
   871         //HO is allowed, item can be in in call options menu
       
   872         iVccHoTrigger.HoAllowed();
       
   873         }
       
   874     else
       
   875         {
       
   876         //HO is not allowed (f.ex. remote hold) and UI item needs to be removed
       
   877         iVccHoTrigger.HoNotAllowedL();
       
   878         }
       
   879     }
       
   880 
       
   881 // -----------------------------------------------------------------------------
       
   882 //  Checks call state and starts trigger if connected
       
   883 //  Conference call doesnt notify state Connected after conference ended
       
   884 //  Only one call can be in Connected state
       
   885 // -----------------------------------------------------------------------------
       
   886 // 
       
   887 void CVccPerformer::ConferenceEnded()
       
   888 	{
       
   889 	RUBY_DEBUG_BLOCK( "CVccPerformer::ConferenceEnded" );
       
   890 	if( iPrimaryCall->State() == MCCPCallObserver::ECCPStateConnected )
       
   891 		{
       
   892 		ActivateTrigger( ETrue );
       
   893 		}
       
   894 	}
       
   895 
       
   896 // -----------------------------------------------------------------------------
       
   897 // Release secondary call leg, if needed, before calling destructor
       
   898 // -----------------------------------------------------------------------------
       
   899 // 
       
   900 void CVccPerformer::ReleaseSecondaryCallLeg()
       
   901     {
       
   902     RUBY_DEBUG_BLOCK( "CVccPerformer::ReleaseSecondaryCallLeg" );
       
   903     if ( iSecondaryCall )
       
   904         {
       
   905         TInt err = iCurrentState->ReleaseCall(*iSecondaryCall, iProviders);
       
   906         if( err != KErrNone )
       
   907             {
       
   908             RUBY_DEBUG0("CVccPerformer::ReleaseSecondaryCallLeg:" );
       
   909             RUBY_DEBUG1("Error releasing secondary call leg: %d", err );
       
   910             }
       
   911         }
       
   912     }
       
   913 
       
   914 // -----------------------------------------------------------------------------
       
   915 // Save original RemoteParty and RemotePartyName
       
   916 // -----------------------------------------------------------------------------
       
   917 // 
       
   918 void CVccPerformer::SetRemoteParties()
       
   919     {
       
   920     RUBY_DEBUG_BLOCK( "CVccPerformer::SetRemoteParties" );
       
   921     if( !iRemotePartiesSet )
       
   922         {
       
   923         iOrigRemoteParty = iPrimaryCall->RemoteParty();
       
   924         iOrigRemotePartyName = iPrimaryCall->RemotePartyName();
       
   925         ParseRemoteParty();
       
   926         }
       
   927     } 
       
   928 
       
   929 // -----------------------------------------------------------------------------
       
   930 // Return ps/cs provider index
       
   931 // -----------------------------------------------------------------------------
       
   932 // 
       
   933 TInt CVccPerformer::VoipProviderIndex( TBool aVoipIndexWanted )
       
   934     {
       
   935     TInt index = KErrNotFound;
       
   936     CSInfo info;
       
   937     if( aVoipIndexWanted )
       
   938         {
       
   939         for( TInt i = 0; i < iProviders.Count(); i++ )
       
   940             {
       
   941             if( !iProviders[ i ]->GetCSInfo( info ) )
       
   942                 {
       
   943                 index = i;
       
   944                 break;
       
   945                 }
       
   946             }
       
   947         }
       
   948     else
       
   949         {
       
   950         for( TInt i = 0; i < iProviders.Count(); i++ )
       
   951             {
       
   952             if( iProviders[ i ]->GetCSInfo( info ) )
       
   953                 {
       
   954                 index = i;
       
   955                 break;
       
   956                 }
       
   957             }
       
   958         }
       
   959     return index;
       
   960     }
       
   961 
       
   962 // -----------------------------------------------------------------------------
       
   963 // Parse remoteparty number if call is VoIP call
       
   964 // -----------------------------------------------------------------------------
       
   965 // 
       
   966 void CVccPerformer::ParseRemoteParty()
       
   967     {
       
   968     RUBY_DEBUG_BLOCK( "CVccPerformer::ParseRemoteParty" );
       
   969     TInt position = 0;
       
   970         
       
   971      // seek '@' sign (returns KErrNotFound if none)
       
   972     position = iOrigRemoteParty.Locate('@');
       
   973         
       
   974      // if found
       
   975      if(position != KErrNotFound)
       
   976            {
       
   977            TInt length = iOrigRemoteParty.Length();
       
   978             // remove the domain part from sip uri
       
   979            iOrigRemoteParty.Delete(position, length - position);
       
   980            //and delete 'sip:' prefix if found
       
   981            if ( iOrigRemoteParty.Find( KSVPSipPrefix ) != KErrNotFound )
       
   982                {
       
   983                RUBY_DEBUG0("SIP: prefix found, delete it");
       
   984                iOrigRemoteParty.Delete(0, 4);
       
   985                }
       
   986            }
       
   987 
       
   988     }