bluetoothengine/headsetsimulator/profiles/hspprofile/src/features/hspincomingcallacceptance.cpp
author michal.sulewski
Wed, 15 Sep 2010 15:59:44 +0200
branchheadsetsimulator
changeset 60 90dbfc0435e3
permissions -rw-r--r--
source code commit

/* 
 *
 * Copyright (c) <2010> Comarch S.A. and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of the License "Eclipse Public License v1.0"
 * which accompanies this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
 * Original Contributors:
 * Comarch S.A. - original contribution.
 *
 * Contributors:
 *
 * Description:
 *
 */

#include "hspincomingcallacceptance.h"
#include "hspcommand.h"
#include "hspsettings.h"
#include "debug.h"

CHsHSPIncomingCallAcceptance* CHsHSPIncomingCallAcceptance::NewL(
        MHsHSPFeatureProviderObserver* aObserver )
    {
    CHsHSPIncomingCallAcceptance* self = CHsHSPIncomingCallAcceptance::NewLC(
            aObserver );
    CleanupStack::Pop( self );
    return self;
    }
CHsHSPIncomingCallAcceptance* CHsHSPIncomingCallAcceptance::NewLC(
        MHsHSPFeatureProviderObserver* aObserver )
    {
    CHsHSPIncomingCallAcceptance* self =
            new ( ELeave ) CHsHSPIncomingCallAcceptance( aObserver );
    CleanupStack::PushL( self );
    self->ConstructL();
    return self;
    }

CHsHSPIncomingCallAcceptance::~CHsHSPIncomingCallAcceptance()
    {
    }

TInt CHsHSPIncomingCallAcceptance::ProcessCommand(
        const CHsHSPCommand *aInputCmd, CHsHSPCommand &aOutputCmd )
    {
    TRACE_FUNC_ENTRY

    TInt res = KErrNone;
    if ( aInputCmd -> FromAG() )
        {
        if ( aInputCmd -> Type() == EHSPCmdRING )
            {
            iWaitingForCKPD200 = ETrue;
            }
        else if ( iWaitingForOK && aInputCmd -> Type() == EHSPCmdOK )
            {
            iWaitingForOK = EFalse;
            iObserver->HandleProcedureCompleted( KErrNone, EHSPCallAccept );
            }
        else
            {
            res = KErrArgument;
            }
        }
    else
        {
        if ( iWaitingForCKPD200 && IsCKPD200( aInputCmd ) )
            {
            iWaitingForCKPD200 = EFalse;
            iWaitingForOK = ETrue;
            TRAP(res,CHsHSPCommand::CopyL( aInputCmd, aOutputCmd ));
            }
        /** Incoming call not indicated by RING command */
        else if ( !iWaitingForCKPD200 && IsCKPD200( aInputCmd ) )
            {
            iWaitingForCKPD200 = EFalse;
            iWaitingForOK = ETrue;
            TRAP(res,CHsHSPCommand::CopyL( aInputCmd, aOutputCmd ));
            }
        else
            {
            res = KErrArgument;
            }
        }

    TRACE_FUNC_EXIT
    return res;
    }

CHsHSPIncomingCallAcceptance::CHsHSPIncomingCallAcceptance(
        MHsHSPFeatureProviderObserver* aObserver ) :
    iObserver( aObserver )
    {
    }

void CHsHSPIncomingCallAcceptance::ConstructL()
    {
    }

TBool CHsHSPIncomingCallAcceptance::IsCKPD200( const CHsHSPCommand* aCommand )
    {
    TBool res = EFalse;

    if ( ( EHSPCmdCKPD == aCommand -> Type() )
            && ( aCommand -> Params().Count() == 1 )
            && ( ( aCommand -> Params()[0].Des().Compare( _L8("200") ) ) == 0 ) )
        {
        res = ETrue;
        }

    return res;
    }

void CHsHSPIncomingCallAcceptance::InformObserver( TInt aErr )
    {
    __ASSERT_ALWAYS(iObserver, User::Panic(_L("Observer missing"),KErrGeneral));
    iObserver ->HandleProcedureCompleted( aErr, iHSPProc );
    }