bluetoothengine/headsetsimulator/profiles/hfpprofile/src/features/hfpfeaturemanager.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/headsetsimulator/profiles/hfpprofile/src/features/hfpfeaturemanager.cpp Wed Sep 15 15:59:44 2010 +0200
@@ -0,0 +1,451 @@
+/*
+ *
+ * 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 "hfpfeaturemanager.h"
+#include "hfpcalltermination.h"
+#include "hfpconnectionmanagement.h"
+#include "hfpincomingcallacceptance.h"
+#include "hfpincomingcallrejection.h"
+#include "hfpphonestatusinformation.h"
+#include "hfpremoteaudiovolumecontrol.h"
+#include "hfplastnumberredialing.h"
+#include "hfpphonenumberdialing.h"
+#include "hfpcallinglineidentification.h"
+#include "hfpcommand.h"
+#include "debug.h"
+
+CHsHFPFeatureManager* CHsHFPFeatureManager::NewL()
+ {
+ CHsHFPFeatureManager *self = CHsHFPFeatureManager::NewLC();
+ CleanupStack::Pop( self );
+
+ return self;
+ }
+
+CHsHFPFeatureManager* CHsHFPFeatureManager::NewLC()
+ {
+
+ CHsHFPFeatureManager *self = new ( ELeave ) CHsHFPFeatureManager();
+ CleanupStack::PushL( self );
+ self->ConstructL();
+ return self;
+ }
+
+CHsHFPFeatureManager::~CHsHFPFeatureManager()
+ {
+ TRACE_FUNC_ENTRY
+ if ( iConnectionManagement )
+ {
+ delete iConnectionManagement;
+ }
+ if ( iCallTermProc )
+ {
+ delete iCallTermProc;
+ }
+ if ( iCallAcceptProc )
+ {
+ delete iCallAcceptProc;
+ }
+ if ( iCallRejectProc )
+ {
+ delete iCallRejectProc;
+ }
+ if ( iPhoneStatus )
+ {
+ delete iPhoneStatus;
+ }
+ if ( iVolumeControl )
+ {
+ delete iVolumeControl;
+ }
+ if ( iLastNumberRedialing )
+ {
+ delete iLastNumberRedialing;
+ }
+ if ( iPhoneNumberDialing )
+ {
+ delete iPhoneNumberDialing;
+ }
+ if ( iCallingLineIdentification )
+ {
+ delete iCallingLineIdentification;
+ }
+ TRACE_FUNC_EXIT
+
+ }
+
+void CHsHFPFeatureManager::PerformDataProcessingL(
+ const CHsHFPCommand* aATCommandIn, CHsHFPCommand& aATCommandOut )
+ {
+ TRACE_FUNC_ENTRY
+ if ( iSrvLvlConnEstablished )
+ {
+ //decide which procedure should be used
+ switch ( aATCommandIn->Type() )
+ {
+ case EHFPCmdCHUP:
+ {
+ if ( iPhoneStatus->IsCallOngoing() )
+ {
+ //start releasing connection
+ User::LeaveIfNull( iCallTermProc );
+ User::LeaveIfError( iCallTermProc->ProcessCommand(
+ *aATCommandIn, aATCommandOut ) );
+ iProcedureStarted = EHFPCallTerminate;
+ }
+ else
+ {
+ //start call rejection
+ User::LeaveIfNull( iCallRejectProc );
+ User::LeaveIfError( iCallRejectProc->ProcessCommand(
+ *aATCommandIn, aATCommandOut ) );
+ iProcedureStarted = EHFPCallReject;
+ }
+ }
+ break;
+
+ case EHFPCmdOK:
+ {
+ HandleOKCommandL( aATCommandIn, aATCommandOut );
+ }
+ break;
+ case EHFPCmdERROR:
+ {
+ if ( iProcedureStarted == EHFPLastNumberRedialing )
+ {
+ User::LeaveIfNull( iLastNumberRedialing );
+ User::LeaveIfError( iLastNumberRedialing->ProcessCommand(
+ *aATCommandIn, aATCommandOut ) );
+ }
+ else if ( iProcedureStarted == EHFPPhoneNumberDialing )
+ {
+ User::LeaveIfNull( iPhoneNumberDialing );
+ User::LeaveIfError( iPhoneNumberDialing->ProcessCommand(
+ *aATCommandIn, aATCommandOut ) );
+ }
+ else
+ {
+ User::Leave( KErrArgument );
+ }
+ }
+ break;
+ case EHFPCmdCIEV:
+ {
+ HandleCIEVCommandL( aATCommandIn, aATCommandOut );
+ }
+ break;
+ case EHFPCmdRING:
+ {
+ User::LeaveIfNull( iCallAcceptProc );
+ User::LeaveIfError( iCallAcceptProc->ProcessCommand(
+ *aATCommandIn, aATCommandOut ) );
+ iProcedureStarted = EHFPCallAccept;
+ }
+ break;
+ case EHFPCmdATA:
+ {
+ if ( iProcedureStarted == EHFPCallAccept )
+ {
+ User::LeaveIfNull( iCallAcceptProc );
+ User::LeaveIfError( iCallAcceptProc->ProcessCommand(
+ *aATCommandIn, aATCommandOut ) );
+ }
+ else
+ {
+ User::Leave( KErrArgument );
+ }
+ }
+ break;
+ case EHFPCmdCOPS:
+ {
+ iProcedureStarted = EHFPOperatorSelection;
+ User::LeaveIfNull( iPhoneStatus );
+ User::LeaveIfError( iPhoneStatus->ProcessCommand(
+ *aATCommandIn, aATCommandOut ) );
+ }
+ break;
+ case EHFPCmdVGS: // fall-through intended here
+ case EHFPCmdVGM:
+ {
+ iProcedureStarted = EHFPVolumeControl;
+ User::LeaveIfNull( iVolumeControl );
+ User::LeaveIfError( iVolumeControl->ProcessCommand(
+ *aATCommandIn, aATCommandOut ) );
+ }
+ break;
+ case EHFPCmdBLDN:
+ {
+ iProcedureStarted = EHFPLastNumberRedialing;
+ User::LeaveIfNull( iLastNumberRedialing );
+ User::LeaveIfError( iLastNumberRedialing->ProcessCommand(
+ *aATCommandIn, aATCommandOut ) );
+ }
+ break;
+ case EHFPCmdATD:
+ {
+ iProcedureStarted = EHFPPhoneNumberDialing;
+ User::LeaveIfNull( iPhoneNumberDialing );
+ User::LeaveIfError( iPhoneNumberDialing->ProcessCommand(
+ *aATCommandIn, aATCommandOut ) );
+ }
+ break;
+ case EHFPCmdCLIP:
+ {
+ iProcedureStarted = EHFPCallingLineIdentification;
+ User::LeaveIfNull( iCallingLineIdentification );
+ User::LeaveIfError( iCallingLineIdentification->ProcessCommand(
+ *aATCommandIn, aATCommandOut ) );
+ }
+ break;
+ default:
+ User::Leave( KErrArgument );
+ }
+ }
+ else
+ {
+ //start ServiceLevelConnectionProcedure
+ User::LeaveIfNull( iConnectionManagement );
+ iProcedureStarted = EHFPServiceLevelConnectionEstablishment;
+ User::LeaveIfError(
+ iConnectionManagement->EstablishServiceLevelConnection(
+ *aATCommandIn, aATCommandOut ) );
+ }
+
+ TRACE_FUNC_EXIT
+ }
+
+void CHsHFPFeatureManager::HandleClientDisconnected( TInt aErr )
+ {
+ TRACE_FUNC_ENTRY
+ iProcedureStarted = EHFPServiceLevelConnectionRelease;
+ iConnectionManagement->HandleServiceLevelConnectionRelease( aErr );
+ iVolumeControl->Reset();
+ TRACE_FUNC_EXIT
+ }
+
+void CHsHFPFeatureManager::HandleClientConnectedL( TDes8& aCommandOut )
+ {
+ TRACE_FUNC_ENTRY
+ CHsHFPCommand* cmdIn = CHsHFPCommand::NewL();
+ CleanupStack::PushL( cmdIn );
+ CHsHFPCommand* cmdOut = CHsHFPCommand::NewL();
+ CleanupStack::Pop( cmdIn );
+ iProcedureStarted = EHFPServiceLevelConnectionEstablishment;
+ iConnectionManagement->EstablishServiceLevelConnection( *cmdIn, *cmdOut );
+ cmdOut->ToDes8( aCommandOut );
+
+ delete cmdIn;
+ delete cmdOut;
+
+ TRACE_FUNC_EXIT
+ }
+
+void CHsHFPFeatureManager::HandleProcedureCompleted( TInt aErr )
+ {
+ TRACE_FUNC_ENTRY
+ switch ( iProcedureStarted )
+ {
+ case EHFPServiceLevelConnectionEstablishment:
+ if ( aErr == KErrNone )
+ {
+ TRACE_INFO(_L8("Connection established"))
+ iSrvLvlConnEstablished = ETrue;
+ iProcedureStarted = EHFPVolumeControl;
+ }
+ break;
+ case EHFPServiceLevelConnectionRelease:
+ if ( aErr == KErrNone )
+ {
+ TRACE_INFO(_L8("Connection released"))
+ iSrvLvlConnEstablished = EFalse;
+ iProcedureStarted = EHFPIdle;
+ }
+ break;
+ case EHFPCallTerminate:
+ iProcedureStarted = EHFPIdle;
+ TRACE_INFO(_L8("Call terminated"))
+ break;
+ case EHFPCallAccept:
+ TRACE_INFO(_L("Call answered"))
+ iProcedureStarted = EHFPIdle;
+ break;
+ case EHFPCallReject:
+ TRACE_INFO(_L("Call rejected"))
+ iProcedureStarted = EHFPIdle;
+ break;
+ case EHFPOperatorSelection:
+ TRACE_INFO(_L("Operator selection"))
+ iProcedureStarted = EHFPIdle;
+ break;
+ case EHFPVolumeControl:
+ TRACE_INFO(_L("Volume control"))
+ break;
+ case EHFPLastNumberRedialing:
+ TRACE_INFO(_L("Last number re-dial"))
+ iProcedureStarted = EHFPIdle;
+ break;
+ case EHFPPhoneNumberDialing:
+ TRACE_INFO(_L("Phone number dialing"))
+ iProcedureStarted = EHFPIdle;
+ break;
+ case EHFPCallingLineIdentification:
+ TRACE_INFO(_L("Calling line identification"))
+ iProcedureStarted = EHFPCallAccept;
+ break;
+ default:
+ iProcedureStarted = EHFPIdle;
+ }
+ TRACE_FUNC_EXIT
+ }
+
+CHsHFPFeatureManager::CHsHFPFeatureManager()
+ {
+
+ }
+
+void CHsHFPFeatureManager::ConstructL()
+ {
+ TRACE_FUNC_ENTRY
+ iConnectionManagement = CHsHFPConnectionManagement::NewL( this );
+ iCallTermProc = CHsHFPCallTerminationProc::NewL( this );
+ iCallAcceptProc = CHsHFPIncomingCallAcceptance::NewL( this );
+ iCallRejectProc = CHsHFPIncomingCallRejection::NewL( this );
+ iPhoneStatus = CHsHFPPhoneStatusInformation::NewL( this );
+ iVolumeControl = CHsHFPRemoteAudioVolumeControl::NewL( this );
+ iLastNumberRedialing = CHsHFPLastNumberRedialing::NewL( this );
+ iPhoneNumberDialing = CHsHFPPhoneNumberDialing::NewL( this );
+ iCallingLineIdentification = CHsHFPCallingLineIdentification::NewL( this );
+ TRACE_FUNC_EXIT
+ }
+
+void CHsHFPFeatureManager::HandleOKCommandL( const CHsHFPCommand* aATCommandIn,
+ CHsHFPCommand& aATCommandOut )
+ {
+ TRACE_FUNC_ENTRY
+ if ( iProcedureStarted == EHFPCallTerminate )
+ {
+ User::LeaveIfNull( iCallTermProc );
+ User::LeaveIfError( iCallTermProc->ProcessCommand( *aATCommandIn,
+ aATCommandOut ) );
+ }
+ else if ( iProcedureStarted == EHFPCallAccept )
+ {
+ TRACE_INFO(_L("iProcedureStarted == EHFPCallAccept"))
+ User::LeaveIfNull( iCallAcceptProc );
+ User::LeaveIfError( iCallAcceptProc->ProcessCommand( *aATCommandIn,
+ aATCommandOut ) );
+ }
+ else if ( iProcedureStarted == EHFPCallReject )
+ {
+ TRACE_INFO(_L("iProcedureStarted == EHFPCallReject"))
+ User::LeaveIfNull( iCallRejectProc );
+ User::LeaveIfError( iCallRejectProc->ProcessCommand( *aATCommandIn,
+ aATCommandOut ) );
+ }
+ else if ( iProcedureStarted == EHFPOperatorSelection )
+ {
+ TRACE_INFO(_L("iProcedureStarted == EHFPOperatorSelection"))
+ User::LeaveIfNull( iPhoneStatus );
+ User::LeaveIfError( iPhoneStatus->ProcessCommand( *aATCommandIn,
+ aATCommandOut ) );
+ }
+ else if ( iProcedureStarted == EHFPVolumeControl )
+ {
+ TRACE_INFO(_L("iProcedureStarted == EHFPVolumeControl"))
+ User::LeaveIfNull( iVolumeControl );
+ User::LeaveIfError( iVolumeControl->ProcessCommand( *aATCommandIn,
+ aATCommandOut ) );
+ }
+ else if ( iProcedureStarted == EHFPLastNumberRedialing )
+ {
+ TRACE_INFO(_L("iProcedureStarted == EHFPLastNumberRedialing"))
+ User::LeaveIfNull( iLastNumberRedialing );
+ User::LeaveIfError( iLastNumberRedialing->ProcessCommand(
+ *aATCommandIn, aATCommandOut ) );
+ }
+ else if ( iProcedureStarted == EHFPPhoneNumberDialing )
+ {
+ TRACE_INFO(_L("iProcedureStarted == EHFPPhoneNumberDialing"))
+ User::LeaveIfNull( iPhoneNumberDialing );
+ User::LeaveIfError( iPhoneNumberDialing->ProcessCommand( *aATCommandIn,
+ aATCommandOut ) );
+ }
+ else if ( iProcedureStarted == EHFPCallingLineIdentification )
+ {
+ TRACE_INFO(_L("iProcedureStarted == EHFPCallingLineIdentification"))
+ User::LeaveIfNull( iCallingLineIdentification );
+ User::LeaveIfError( iCallingLineIdentification->ProcessCommand(
+ *aATCommandIn, aATCommandOut ) );
+ }
+ else
+ {
+ User::Leave( KErrArgument );
+ }
+ TRACE_FUNC_EXIT
+ }
+
+void CHsHFPFeatureManager::HandleCIEVCommandL(
+ const CHsHFPCommand* aATCommandIn, CHsHFPCommand& aATCommandOut )
+ {
+ TRACE_FUNC_ENTRY
+
+ // refresh settings
+ iPhoneStatus->ProcessCommand( *aATCommandIn, aATCommandOut );
+
+ if ( iProcedureStarted == EHFPCallTerminate )
+ {
+ TRACE_INFO(_L8("CIEV : CALL TERMINATE"))
+ User::LeaveIfNull( iCallTermProc );
+ User::LeaveIfError( iCallTermProc->ProcessCommand( *aATCommandIn,
+ aATCommandOut ) );
+ }
+ else if ( iProcedureStarted == EHFPCallReject )
+ {
+ TRACE_INFO(_L("CIEV : CALL REJECT"))
+ User::LeaveIfNull( iCallRejectProc );
+ User::LeaveIfError( iCallRejectProc->ProcessCommand( *aATCommandIn,
+ aATCommandOut ) );
+ }
+ else if ( iProcedureStarted == EHFPCallAccept )
+ {
+ TRACE_INFO(_L("CIEV : CALL ACCEPT"))
+ User::LeaveIfNull( iCallAcceptProc );
+ User::LeaveIfError( iCallAcceptProc->ProcessCommand( *aATCommandIn,
+ aATCommandOut ) );
+ }
+ else if ( iProcedureStarted == EHFPLastNumberRedialing )
+ {
+ TRACE_INFO(_L("CIEV : LAST NUMBER REDIAL"))
+ User::LeaveIfNull( iLastNumberRedialing );
+ User::LeaveIfError( iLastNumberRedialing->ProcessCommand(
+ *aATCommandIn, aATCommandOut ) );
+ }
+ else if ( iProcedureStarted == EHFPPhoneNumberDialing )
+ {
+ TRACE_INFO(_L("CIEV : PHONE NUMBER DIALING"))
+ User::LeaveIfNull( iPhoneNumberDialing );
+ User::LeaveIfError( iPhoneNumberDialing->ProcessCommand( *aATCommandIn,
+ aATCommandOut ) );
+ }
+ else
+ {
+ User::Leave( KErrArgument );
+ }
+
+ TRACE_FUNC_EXIT
+ }