bluetoothengine/headsetsimulator/profiles/hfpprofile/src/features/hfpincomingcallacceptance.cpp
branchheadsetsimulator
changeset 60 90dbfc0435e3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/headsetsimulator/profiles/hfpprofile/src/features/hfpincomingcallacceptance.cpp	Wed Sep 15 15:59:44 2010 +0200
@@ -0,0 +1,150 @@
+/* 
+ *
+ * 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 "hfpincomingcallacceptance.h"
+#include "hfpcommand.h"
+#include "hfpsettings.h"
+#include "debug.h"
+
+CHsHFPIncomingCallAcceptance* CHsHFPIncomingCallAcceptance::NewL(
+        MHsHFPFeatureProviderObserver* aObserver )
+    {
+    CHsHFPIncomingCallAcceptance* self = CHsHFPIncomingCallAcceptance::NewLC(
+            aObserver );
+    CleanupStack::Pop( self );
+    return self;
+    }
+CHsHFPIncomingCallAcceptance* CHsHFPIncomingCallAcceptance::NewLC(
+        MHsHFPFeatureProviderObserver* aObserver )
+    {
+    CHsHFPIncomingCallAcceptance* self =
+            new ( ELeave ) CHsHFPIncomingCallAcceptance( aObserver );
+    CleanupStack::PushL( self );
+    self->ConstructL();
+    return self;
+    }
+
+CHsHFPIncomingCallAcceptance::~CHsHFPIncomingCallAcceptance()
+    {
+    TRACE_FUNC_ENTRY
+    if ( iSettings )
+        {
+        iSettings->Release();
+        }
+    TRACE_FUNC_EXIT
+    }
+
+TInt CHsHFPIncomingCallAcceptance::ProcessCommand(
+        const CHsHFPCommand &aInputCmd, CHsHFPCommand &aOutputCmd )
+    {
+    TRACE_FUNC_ENTRY
+
+    TInt res = KErrNone;
+    if ( aInputCmd.FromAG() )
+        {
+        if ( aInputCmd.Type() == EHFPCmdRING )
+            {
+            TInt ind =
+                    iSettings->FindIndicatorIndex( KHFPCallsetupIndicatorDes );
+            if ( ind != KErrNotFound && iSettings->iSettingsArr[ind].Int() == 1 )
+                {
+                iWaitingForATA = ETrue;
+                }
+            }
+        else if ( iWaitingForOK && aInputCmd.Type() == EHFPCmdOK )
+            {
+            iWaitingForOK = EFalse;
+            iWaitingForCIEVCall1 = ETrue;
+            }
+        else if ( iWaitingForCIEVCall1 && IsProperCIEV( &aInputCmd,
+                KHFPCallIndicatorDes, 1 ) )
+            {
+            iWaitingForCIEVCall1 = EFalse;
+            iWaitingForCIEVCallsetup0 = ETrue;
+            }
+        else if ( iWaitingForCIEVCallsetup0 && IsProperCIEV( &aInputCmd,
+                KHFPCallsetupIndicatorDes, 0 ) )
+            {
+            iWaitingForCIEVCallsetup0 = EFalse;
+            iObserver->HandleProcedureCompleted( KErrNone );
+            }
+        else
+            {
+            res = KErrArgument;
+            }
+        }
+    else
+        {
+        if ( iWaitingForATA && aInputCmd.Type() == EHFPCmdATA )
+            {
+            iWaitingForATA = EFalse;
+            iWaitingForOK = ETrue;
+            TRAP(res,CHsHFPCommand::CopyL( aInputCmd, aOutputCmd ));
+            }
+        else
+            {
+            res = KErrArgument;
+            }
+        }
+
+    TRACE_FUNC_EXIT
+    return res;
+    }
+
+CHsHFPIncomingCallAcceptance::CHsHFPIncomingCallAcceptance(
+        MHsHFPFeatureProviderObserver* aObserver ) :
+    iObserver( aObserver )
+    {
+    }
+
+void CHsHFPIncomingCallAcceptance::ConstructL()
+    {
+    iSettings = CHsHFPSettings::InstanceL();
+    }
+
+TBool CHsHFPIncomingCallAcceptance::IsProperCIEV(
+        const CHsHFPCommand* aCommand, const TDesC8& aIndicatorDes,
+        const TInt aIndicatorValue )
+    {
+    TRACE_FUNC_ENTRY
+    TBool res = EFalse;
+
+    if ( aCommand->Params().Count() == 2 )
+        {
+        TInt expectedIdx = iSettings->FindIndicatorIndex( aIndicatorDes );
+
+        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
+                == aIndicatorValue )
+            {
+            res = ETrue;
+            }
+        }
+
+    TRACE_FUNC_EXIT
+    return res;
+    }