diff -r 02103bf20ee5 -r 90dbfc0435e3 bluetoothengine/headsetsimulator/profiles/hspprofile/src/features/hspremoteaudiovolumecontrol.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/headsetsimulator/profiles/hspprofile/src/features/hspremoteaudiovolumecontrol.cpp Wed Sep 15 15:59:44 2010 +0200 @@ -0,0 +1,175 @@ +/* + * + * 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 "hspremoteaudiovolumecontrol.h" +#include "hspcommand.h" +#include "hspsettings.h" +#include "debug.h" + +CHsHSPRemoteAudioVolumeControl* CHsHSPRemoteAudioVolumeControl::NewL( + MHsHSPFeatureProviderObserver* aObserver ) + { + CHsHSPRemoteAudioVolumeControl* self = + CHsHSPRemoteAudioVolumeControl::NewLC( aObserver ); + CleanupStack::Pop( self ); + return self; + } + +CHsHSPRemoteAudioVolumeControl* CHsHSPRemoteAudioVolumeControl::NewLC( + MHsHSPFeatureProviderObserver* aObserver ) + { + CHsHSPRemoteAudioVolumeControl* self = + new ( ELeave ) CHsHSPRemoteAudioVolumeControl( aObserver ); + CleanupStack::PushL( self ); + self->ConstructL(); + return self; + } + +CHsHSPRemoteAudioVolumeControl::~CHsHSPRemoteAudioVolumeControl() + { + if ( iSettings ) + { + iSettings->Release(); + } + } + +void CHsHSPRemoteAudioVolumeControl::Reset() + { + TRACE_FUNC_ENTRY + + iWaitingForVgmOK = EFalse; + iWaitingForVgsOK = EFalse; + TRACE_FUNC_EXIT + } + +TInt CHsHSPRemoteAudioVolumeControl::ProcessCommand( + const CHsHSPCommand* aInputCmd, CHsHSPCommand &aOutputCmd ) + { + TRACE_FUNC_ENTRY + + TInt res = KErrNone; + if ( aInputCmd -> FromAG() ) + { + if ( aInputCmd -> Type() == EHSPCmdVGS ) + { + TRAP( res, SetVolumeLevelL(aInputCmd)); + TRACE_INFO(_L("Speaker volume changed : AG initiated")) + InformObserver( res ); + } + else if ( aInputCmd -> Type() == EHSPCmdVGM ) + { + TRAP( res, SetMicGainLevelL(aInputCmd)); + TRACE_INFO(_L("Mic gain changed : AG initiated")) + InformObserver( res ); + } + else if ( aInputCmd -> Type() == EHSPCmdOK ) + { + if ( iWaitingForVgmOK ) + { + TRACE_INFO(_L("Mic gain changed")) + InformObserver( res ); + } + else if ( iWaitingForVgsOK ) + { + TRACE_INFO(_L("Speaker volume changed")) + InformObserver( res ); + } + else + res = KErrArgument; + } + else + { + res = KErrArgument; + } + } + else + { + if ( aInputCmd-> Type() == EHSPCmdVGS ) + { + iWaitingForVgsOK = ETrue; + iWaitingForVgmOK = EFalse; + TRAP( res, SetVolumeLevelL(aInputCmd); + CHsHSPCommand ::CopyL( aInputCmd, aOutputCmd ) ); + } + else if ( aInputCmd->Type() == EHSPCmdVGM ) + { + iWaitingForVgmOK = ETrue; + iWaitingForVgsOK = EFalse; + TRAP( res, SetMicGainLevelL(aInputCmd); + CHsHSPCommand::CopyL( aInputCmd, aOutputCmd ) ); + } + else + { + res = KErrArgument; + } + } + + TRACE_FUNC_EXIT + return res; + } + +CHsHSPRemoteAudioVolumeControl::CHsHSPRemoteAudioVolumeControl( + MHsHSPFeatureProviderObserver* aObserver ) : + iObserver( aObserver ) + { + } + +void CHsHSPRemoteAudioVolumeControl::ConstructL() + { + iSettings = CHsHSPSettings::InstanceL(); + } + +void CHsHSPRemoteAudioVolumeControl::InformObserver( TInt aErr ) + { + __ASSERT_ALWAYS(iObserver, User::Panic(_L("Observer missing"),KErrGeneral)); + iObserver ->HandleProcedureCompleted( aErr, iHSPProc ); + } + +void CHsHSPRemoteAudioVolumeControl::SetVolumeLevelL( + const CHsHSPCommand* aCmd ) + { + TRACE_FUNC_ENTRY + + CheckParamsL( aCmd ); + iSettings->SetSpeakerVolumeLevel( aCmd->Params()[0].IntL() ); + + TRACE_FUNC_EXIT + } + +void CHsHSPRemoteAudioVolumeControl::SetMicGainLevelL( + const CHsHSPCommand* aCmd ) + { + + TRACE_FUNC_ENTRY + + CheckParamsL( aCmd ); + iSettings->SetMicGainLevel( aCmd->Params()[0].IntL() ); + + TRACE_FUNC_EXIT + } + +void CHsHSPRemoteAudioVolumeControl::CheckParamsL( const CHsHSPCommand* aCmd ) + { + TRACE_FUNC_ENTRY + + TInt params = 1; + if ( params != aCmd -> Params().Count() ) + User::Leave( KErrArgument ); + + TRACE_FUNC_EXIT + }