bluetoothengine/headsetsimulator/profiles/hfpprofile/src/features/hfpphonestatusinformation.cpp
branchheadsetsimulator
changeset 60 90dbfc0435e3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/headsetsimulator/profiles/hfpprofile/src/features/hfpphonestatusinformation.cpp	Wed Sep 15 15:59:44 2010 +0200
@@ -0,0 +1,253 @@
+/* 
+ *
+ * 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 "hfpphonestatusinformation.h"
+#include "hfpcommand.h"
+#include "hfpsettings.h"
+#include "debug.h"
+
+CHsHFPPhoneStatusInformation* CHsHFPPhoneStatusInformation::NewL(
+        MHsHFPFeatureProviderObserver* aObserver )
+    {
+    CHsHFPPhoneStatusInformation* self = CHsHFPPhoneStatusInformation::NewLC(
+            aObserver );
+    CleanupStack::Pop( self );
+    return self;
+    }
+
+CHsHFPPhoneStatusInformation* CHsHFPPhoneStatusInformation::NewLC(
+        MHsHFPFeatureProviderObserver* aObserver )
+    {
+    CHsHFPPhoneStatusInformation* self =
+            new ( ELeave ) CHsHFPPhoneStatusInformation( aObserver );
+    CleanupStack::PushL( self );
+    self->ConstructL();
+    return self;
+    }
+
+CHsHFPPhoneStatusInformation::~CHsHFPPhoneStatusInformation()
+    {
+    TRACE_FUNC_ENTRY
+    if ( iSettings )
+        {
+        iSettings->Release();
+        }
+    TRACE_FUNC_ENTRY
+    }
+
+TInt CHsHFPPhoneStatusInformation::ProcessCommand(
+        const CHsHFPCommand &aInputCmd, CHsHFPCommand &aOutputCmd )
+    {
+    TRACE_FUNC_ENTRY
+
+    TInt res = KErrNone;
+    if ( aInputCmd.FromAG() )
+        {
+        if ( aInputCmd.Type() == EHFPCmdCIEV )
+            {
+            TRAP( res, HandleIndicatorL( &aInputCmd ) );
+            }
+        else if ( iWaitingForOK && aInputCmd.Type() == EHFPCmdOK )
+            {
+            iWaitingForOK = EFalse;
+            iWaitingForCOPSFromAG = ETrue;
+            aOutputCmd.SetType( EHFPCmdCOPS );
+            aOutputCmd.SetMode( ECmdModeRead );
+
+            }
+        else if ( iWaitingForCOPSFromAG && aInputCmd.Type() == EHFPCmdCOPS )
+            {
+            iWaitingForCOPSFromAG = EFalse;
+            iObserver->HandleProcedureCompleted( KErrNone );
+            }
+
+        else
+            {
+            res = KErrArgument;
+            }
+        }
+    else
+        {
+        if ( aInputCmd.Type() == EHFPCmdCOPS )
+            {
+            iWaitingForOK = ETrue;
+            TRAP(res, CHsHFPCommand::CopyL( aInputCmd, aOutputCmd ));
+            }
+        else
+            {
+            res = KErrArgument;
+            }
+        }
+    TRACE_FUNC_EXIT
+    return res;
+    }
+
+TBool CHsHFPPhoneStatusInformation::IsCallOngoing()
+    {
+    TRACE_FUNC_ENTRY
+    TInt index = iSettings->FindIndicatorIndex( KHFPCallIndicatorDes );
+    TRACE_FUNC_EXIT
+    if ( index != KErrNotFound )
+        {
+        return ( iSettings->iSettingsArr[index].Int() == 1 ? ETrue : EFalse );
+        }
+    else
+        {
+        return EFalse;
+        }
+    }
+
+CHsHFPPhoneStatusInformation::CHsHFPPhoneStatusInformation(
+        MHsHFPFeatureProviderObserver* aObserver ) :
+    iObserver( aObserver )
+    {
+    }
+
+void CHsHFPPhoneStatusInformation::ConstructL()
+    {
+    TRACE_FUNC_ENTRY
+    iSettings = CHsHFPSettings::InstanceL();
+    TRACE_FUNC_EXIT
+    }
+
+void CHsHFPPhoneStatusInformation::HandleIndicatorL(
+        const CHsHFPCommand* aCommand )
+    {
+    TRACE_FUNC_ENTRY
+    if ( aCommand->Params().Count() != 2 )
+        {
+        User::Leave( KErrArgument );        
+        }
+    
+    THFPIndicatorDes indicatorBuf =
+            iSettings->iSettingsArr[aCommand->Params()[0].IntL()].Des();
+
+    TRACE_INFO( (_L8("INDICATOR before: %S - value: %d "), &indicatorBuf,
+                    iSettings->iSettingsArr[aCommand->Params()[0].IntL()].Int() ) );
+    TRACE_INFO( (_L8("INDICATOR after: %S - value: %d "), &indicatorBuf,
+                    aCommand->Params()[1].IntL() ) );
+
+    if ( indicatorBuf.Compare( KHFPCallIndicatorDes ) == 0 )
+        {
+        TRACE_INFO(_L8("KHFPCallIndicatorDes"))
+        HandleCallIndicatorL( aCommand );
+        }
+    else if ( indicatorBuf.Compare( KHFPServiceIndicatorDes ) == 0 )
+        {
+        TRACE_INFO(_L8("KHFPServiceIndicatorDes"))
+        HandleServiceIndicatorL( aCommand );
+        }
+    else if ( indicatorBuf.Compare( KHFPCallsetupIndicatorDes ) == 0 )
+        {
+        TRACE_INFO(_L8("KHFPCallsetupIndicatorDes"))
+        HandleCallsetupIndicatorL( aCommand );
+        }
+    else if ( indicatorBuf.Compare( KHFPCall_setupIndicatorDes ) == 0 )
+        {
+        TRACE_INFO(_L8("KHFPCall_setupIndicatorDes"))
+        }
+    else if ( indicatorBuf.Compare( KHFPCallheldIndicatorDes ) == 0 )
+        {
+        TRACE_INFO(_L8("KHFPCallheldIndicatorDes"))
+        HandleCallheldIndicatorL( aCommand );
+        }
+    else if ( indicatorBuf.Compare( KHFPSignalIndicatorDes ) == 0 )
+        {
+        TRACE_INFO(_L8("KHFPSignalIndicatorDes"))
+        HandleSignalIndicatorL( aCommand );
+        }
+    else if ( indicatorBuf.Compare( KHFPRoamIndicatorDes ) == 0 )
+        {
+        TRACE_INFO(_L8("KHFPRoamIndicatorDes"))
+        HandleRoamingIndicatorL( aCommand );
+        }
+    else if ( indicatorBuf.Compare( KHFPBattchgIndicatorDes ) == 0 )
+        {
+        TRACE_INFO(_L8("KHFPBattchgIndicatorDes"))
+        HandleBatteryIndicatorL( aCommand );
+        }
+    else
+        {
+        User::Leave( KErrArgument );
+        }
+
+    TRACE_FUNC_EXIT
+    }
+
+void CHsHFPPhoneStatusInformation::HandleCallIndicatorL(
+        const CHsHFPCommand* aCommand )
+    {
+    TRACE_FUNC_ENTRY
+    iSettings->iSettingsArr[aCommand->Params()[0].IntL()].SetValueL(
+            aCommand->Params()[1].Des() );
+    TRACE_FUNC_EXIT
+    }
+
+void CHsHFPPhoneStatusInformation::HandleServiceIndicatorL(
+        const CHsHFPCommand* aCommand )
+    {
+    TRACE_FUNC_ENTRY
+    iSettings->iSettingsArr[aCommand->Params()[0].IntL()].SetValueL(
+            aCommand->Params()[1].Des() );
+    TRACE_FUNC_EXIT
+    }
+
+void CHsHFPPhoneStatusInformation::HandleCallsetupIndicatorL(
+        const CHsHFPCommand* aCommand )
+    {
+    TRACE_FUNC_ENTRY
+    iSettings->iSettingsArr[aCommand->Params()[0].IntL()].SetValueL(
+            aCommand->Params()[1].Des() );
+    TRACE_FUNC_EXIT
+    }
+
+void CHsHFPPhoneStatusInformation::HandleCallheldIndicatorL(
+        const CHsHFPCommand* aCommand )
+    {
+    TRACE_FUNC_ENTRY
+    iSettings->iSettingsArr[aCommand->Params()[0].IntL()].SetValueL(
+            aCommand->Params()[1].Des() );
+    TRACE_FUNC_EXIT
+    }
+
+void CHsHFPPhoneStatusInformation::HandleSignalIndicatorL(
+        const CHsHFPCommand* aCommand )
+    {
+    TRACE_FUNC_ENTRY
+    iSettings->iSettingsArr[aCommand->Params()[0].IntL()].SetValueL(
+            aCommand->Params()[1].Des() );
+    TRACE_FUNC_EXIT
+    }
+
+void CHsHFPPhoneStatusInformation::HandleRoamingIndicatorL(
+        const CHsHFPCommand* aCommand )
+    {
+    TRACE_FUNC_ENTRY
+    iSettings->iSettingsArr[aCommand->Params()[0].IntL()].SetValueL(
+            aCommand->Params()[1].Des() );
+    TRACE_FUNC_EXIT
+    }
+
+void CHsHFPPhoneStatusInformation::HandleBatteryIndicatorL(
+        const CHsHFPCommand* aCommand )
+    {
+    TRACE_FUNC_ENTRY
+    iSettings->iSettingsArr[aCommand->Params()[0].IntL()].SetValueL(
+            aCommand->Params()[1].Des() );
+    TRACE_FUNC_EXIT
+    }