bluetoothengine/headsetsimulator/profiles/hfpprofile/src/features/hfpcalltermination.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 "hfpcalltermination.h"
#include "hfpcommand.h"
#include "hfpsettings.h"
#include "debug.h"

CHsHFPCallTerminationProc* CHsHFPCallTerminationProc::NewL(
        MHsHFPFeatureProviderObserver* aObserver )
    {
    CHsHFPCallTerminationProc *self = CHsHFPCallTerminationProc::NewLC(
            aObserver );
    CleanupStack::Pop( self );

    return self;
    }

CHsHFPCallTerminationProc* CHsHFPCallTerminationProc::NewLC(
        MHsHFPFeatureProviderObserver* aObserver )
    {
    CHsHFPCallTerminationProc *self = new ( ELeave ) CHsHFPCallTerminationProc(
            aObserver );
    CleanupStack::PushL( self );
    self->ConstructL();
    return self;
    }

CHsHFPCallTerminationProc::~CHsHFPCallTerminationProc()
    {
    TRACE_FUNC_ENTRY
    if ( iSettings )
        {
        iSettings->Release();
        }
    TRACE_FUNC_EXIT
    }

TInt CHsHFPCallTerminationProc::ProcessCommand( const CHsHFPCommand &aInputCmd,
        CHsHFPCommand &aOutputCmd )
    {
    TRACE_FUNC_ENTRY

    TInt res = KErrNone;
    if ( aInputCmd.FromAG() )
        {
        if ( iWaitingForOK && aInputCmd.Type() == EHFPCmdOK )
            {
            iWaitingForOK = EFalse;
            iWaitingForCIEV = ETrue;
            }
        else if ( iWaitingForCIEV && IsProperCIEV( &aInputCmd ) )
            {
            //call terminated successfully
            iWaitingForCIEV = EFalse;
            iObserver->HandleProcedureCompleted( KErrNone );
            }
        else
            {
            res = KErrArgument;
            }
        }
    else
        {
        if ( aInputCmd.Type() == EHFPCmdCHUP )
            {
            iWaitingForOK = ETrue;
            TRAP(res,CHsHFPCommand::CopyL( aInputCmd, aOutputCmd ));
            }
        else
            {
            res = KErrArgument;
            }
        }

    TRACE_FUNC_EXIT
    return res;
    }

CHsHFPCallTerminationProc::CHsHFPCallTerminationProc(
        MHsHFPFeatureProviderObserver* aObserver ) :
    iObserver( aObserver )
    {

    }

void CHsHFPCallTerminationProc::ConstructL()
    {
    iSettings = CHsHFPSettings::InstanceL();
    }

TBool CHsHFPCallTerminationProc::IsProperCIEV( const CHsHFPCommand* aCommand )
    {
    TRACE_FUNC_ENTRY
    TBool res = EFalse;

    TInt expectedIdx = iSettings->FindIndicatorIndex( KHFPCallIndicatorDes );

    TInt retrievedIdx = KErrNotFound;
    TRAPD(errRetrieveIdx, retrievedIdx = aCommand->Params()[0].IntL() )

    TInt retrievedValue = KErrNotFound;
    TRAPD(errRetrieveValue, retrievedValue = aCommand->Params()[1].IntL() )
    TRACE_INFO((_L8(" Index retrieved = %d, expected = %d"),
                    expectedIdx, retrievedIdx))

    if ( errRetrieveIdx == KErrNone && errRetrieveValue == KErrNone
            && aCommand->Type() == EHFPCmdCIEV && aCommand->FromAG()
            && expectedIdx == retrievedIdx && retrievedValue == 0 )
        {
        res = ETrue;
        }

    TRACE_FUNC_EXIT
    return res;
    }