phoneclientserver/phoneclient/Src/ExtCallWrapper/ExtCallWrapper_Aiw/CPhCltExtPhone.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 16 Apr 2010 15:31:58 +0300
changeset 13 e32024264ebb
parent 12 ae8abd0db65c
permissions -rw-r--r--
Revision: 201011 Kit: 201015

/*
* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). 
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Ext Phone for dialing.
*
*/



// INCLUDE FILES
#include    <e32std.h>
#include    "mphcltextphoneobserver.h" 
#include    "cphcltextphone.h" 
#include    "cphcltextphonedialdata.h" 

// LOCAL CONSTANTS AND MACROS

// Panic codes.
enum TPhCltExtPhonePanic
    {
    EPhCltExtPhonePanicNoObserver,           // No observer found.
    EPhCltExtPhonePanicInvalidOperationMode  // Operation mode was invalid.
    };


// LOCAL FUNCTION PROTOTYPES

// Panic function. Called if panic situation happens.
void Panic( TPhCltExtPhonePanic aPanic );


// ============================= LOCAL FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// Panic
// 
// Panics the client
//
// -----------------------------------------------------------------------------
//
void Panic( TPhCltExtPhonePanic aPanic )
    {
    _LIT(KPhCltExtPhonePanicCategory, "CPhCltExtPhone");
    User::Panic( KPhCltExtPhonePanicCategory, aPanic );
    }

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CPhCltExtPhone::NewL
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CPhCltExtPhone* CPhCltExtPhone::NewL( MPhCltExtPhoneObserver* aObserver )
    {
    CPhCltExtPhone* self = new ( ELeave ) CPhCltExtPhone( aObserver );
    CleanupStack::PushL( self );
    self->ConstructL();
    CleanupStack::Pop();
    return self;
    }   

// Destructor
CPhCltExtPhone::~CPhCltExtPhone()
    {
    delete iPackage;
    
    // Cancel, close subsessions and finally close the session.
    Cancel();
    iCall.Close();
    iServer.Close();
    }

// -----------------------------------------------------------------------------
// CPhCltExtPhone::DialL
// 
// If a request is pending, leave with error code KErrInUse.
// Otherwise, create a dial request. 
// -----------------------------------------------------------------------------
//
void CPhCltExtPhone::DialL( CPhCltExtPhoneDialData& aData )
    {
    DialPreconditionCheckL();
    delete iPackage;
    iPackage = NULL;
    
    // packs params 
    iPackage = aData.PackLC();
    CleanupStack::Pop( iPackage );    
    TInt datalength = aData.CalculatePackageSize();
    if ( iPackage )
        {
        iCall.Dial( iStatus, *iPackage, datalength );
        }
    }

// -----------------------------------------------------------------------------
// CPhCltExtPhone::CPhCltExtPhone
// -----------------------------------------------------------------------------
//
CPhCltExtPhone::CPhCltExtPhone( MPhCltExtPhoneObserver* aObserver )
    : CPhCltExtPhoneBase( aObserver ), iMode( EIdle )
    {
    CActiveScheduler::Add( this );
    }

// -----------------------------------------------------------------------------
// CPhCltExtPhone::ConstructL
// -----------------------------------------------------------------------------
//
void CPhCltExtPhone::ConstructL() 
    {
    User::LeaveIfError( iServer.Connect() );
    User::LeaveIfError( iCall.Open( iServer ) );
    }

// -----------------------------------------------------------------------------
// CPhCltExtPhone::RunL
// 
// The method is called when a request is completed. Thus,
// it calls appropriate observer method.
// -----------------------------------------------------------------------------
//
void CPhCltExtPhone::RunL()
    {
    __ASSERT_ALWAYS( iObserver, Panic( EPhCltExtPhonePanicNoObserver ) );
    switch( iMode )
        {                         
        case EDialling:
            iObserver->HandleDialL( iStatus.Int() );
            break;
        case EIdle:
            break;
        default:
            Panic( EPhCltExtPhonePanicInvalidOperationMode );
            break;
        }
    }

// -----------------------------------------------------------------------------
// CPhCltExtPhone::DoCancel
// 
// Cancels the pending request.
// -----------------------------------------------------------------------------
//
void CPhCltExtPhone::DoCancel()
    {
    switch( iMode )
        {                         
        case EDialling:
            iCall.CancelDial();
            break;
        case EIdle:
            break;
        default:
            Panic( EPhCltExtPhonePanicInvalidOperationMode );
            break;
        }
    }

// -----------------------------------------------------------------------------
// CPhCltExtPhone::DialPreconditionCheckL
// 
// See header
// -----------------------------------------------------------------------------
//
void CPhCltExtPhone::DialPreconditionCheckL()
    {
    if( IsActive() )
        {
        User::Leave( KErrInUse );
        }
    if( iCall.SubSessionHandle() == 0 ) 
        {
        User::Leave( KErrBadHandle );
        }
    iMode = EDialling;
    SetActive();
    }

//  End of File