bluetoothengine/headsetsimulator/profiles/hspprofile/src/features/hspremoteaudiovolumecontrol.cpp
branchheadsetsimulator
changeset 60 90dbfc0435e3
equal deleted inserted replaced
59:02103bf20ee5 60:90dbfc0435e3
       
     1 /* 
       
     2  *
       
     3  * Copyright (c) <2010> Comarch S.A. and/or its subsidiary(-ies).
       
     4  * All rights reserved.
       
     5  * This component and the accompanying materials are made available
       
     6  * under the terms of the License "Eclipse Public License v1.0"
       
     7  * which accompanies this distribution, and is available
       
     8  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9  *
       
    10  * Original Contributors:
       
    11  * Comarch S.A. - original contribution.
       
    12  *
       
    13  * Contributors:
       
    14  *
       
    15  * Description:
       
    16  *
       
    17  */
       
    18 
       
    19 #include "hspremoteaudiovolumecontrol.h"
       
    20 #include "hspcommand.h"
       
    21 #include "hspsettings.h"
       
    22 #include "debug.h"
       
    23 
       
    24 CHsHSPRemoteAudioVolumeControl* CHsHSPRemoteAudioVolumeControl::NewL(
       
    25         MHsHSPFeatureProviderObserver* aObserver )
       
    26     {
       
    27     CHsHSPRemoteAudioVolumeControl* self =
       
    28             CHsHSPRemoteAudioVolumeControl::NewLC( aObserver );
       
    29     CleanupStack::Pop( self );
       
    30     return self;
       
    31     }
       
    32 
       
    33 CHsHSPRemoteAudioVolumeControl* CHsHSPRemoteAudioVolumeControl::NewLC(
       
    34         MHsHSPFeatureProviderObserver* aObserver )
       
    35     {
       
    36     CHsHSPRemoteAudioVolumeControl* self =
       
    37             new ( ELeave ) CHsHSPRemoteAudioVolumeControl( aObserver );
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     return self;
       
    41     }
       
    42 
       
    43 CHsHSPRemoteAudioVolumeControl::~CHsHSPRemoteAudioVolumeControl()
       
    44     {
       
    45     if ( iSettings )
       
    46         {
       
    47         iSettings->Release();
       
    48         }
       
    49     }
       
    50 
       
    51 void CHsHSPRemoteAudioVolumeControl::Reset()
       
    52     {
       
    53     TRACE_FUNC_ENTRY
       
    54 
       
    55     iWaitingForVgmOK = EFalse;
       
    56     iWaitingForVgsOK = EFalse;
       
    57     TRACE_FUNC_EXIT
       
    58     }
       
    59 
       
    60 TInt CHsHSPRemoteAudioVolumeControl::ProcessCommand(
       
    61         const CHsHSPCommand* aInputCmd, CHsHSPCommand &aOutputCmd )
       
    62     {
       
    63     TRACE_FUNC_ENTRY
       
    64 
       
    65     TInt res = KErrNone;
       
    66     if ( aInputCmd -> FromAG() )
       
    67         {
       
    68         if ( aInputCmd -> Type() == EHSPCmdVGS )
       
    69             {
       
    70             TRAP( res, SetVolumeLevelL(aInputCmd));
       
    71             TRACE_INFO(_L("Speaker volume changed : AG initiated"))
       
    72             InformObserver( res );
       
    73             }
       
    74         else if ( aInputCmd -> Type() == EHSPCmdVGM )
       
    75             {
       
    76             TRAP( res, SetMicGainLevelL(aInputCmd));
       
    77             TRACE_INFO(_L("Mic gain changed : AG initiated"))
       
    78             InformObserver( res );
       
    79             }
       
    80         else if ( aInputCmd -> Type() == EHSPCmdOK )
       
    81             {
       
    82             if ( iWaitingForVgmOK )
       
    83                 {
       
    84                 TRACE_INFO(_L("Mic gain changed"))
       
    85                 InformObserver( res );
       
    86                 }
       
    87             else if ( iWaitingForVgsOK )
       
    88                 {
       
    89                 TRACE_INFO(_L("Speaker volume changed"))
       
    90                 InformObserver( res );
       
    91                 }
       
    92             else
       
    93                 res = KErrArgument;
       
    94             }
       
    95         else
       
    96             {
       
    97             res = KErrArgument;
       
    98             }
       
    99         }
       
   100     else
       
   101         {
       
   102         if ( aInputCmd-> Type() == EHSPCmdVGS )
       
   103             {
       
   104             iWaitingForVgsOK = ETrue;
       
   105             iWaitingForVgmOK = EFalse;
       
   106             TRAP( res, SetVolumeLevelL(aInputCmd);
       
   107                     CHsHSPCommand ::CopyL( aInputCmd, aOutputCmd ) );
       
   108             }
       
   109         else if ( aInputCmd->Type() == EHSPCmdVGM )
       
   110             {
       
   111             iWaitingForVgmOK = ETrue;
       
   112             iWaitingForVgsOK = EFalse;
       
   113             TRAP( res, SetMicGainLevelL(aInputCmd);
       
   114                     CHsHSPCommand::CopyL( aInputCmd, aOutputCmd ) );
       
   115             }
       
   116         else
       
   117             {
       
   118             res = KErrArgument;
       
   119             }
       
   120         }
       
   121 
       
   122     TRACE_FUNC_EXIT
       
   123     return res;
       
   124     }
       
   125 
       
   126 CHsHSPRemoteAudioVolumeControl::CHsHSPRemoteAudioVolumeControl(
       
   127         MHsHSPFeatureProviderObserver* aObserver ) :
       
   128     iObserver( aObserver )
       
   129     {
       
   130     }
       
   131 
       
   132 void CHsHSPRemoteAudioVolumeControl::ConstructL()
       
   133     {
       
   134     iSettings = CHsHSPSettings::InstanceL();
       
   135     }
       
   136 
       
   137 void CHsHSPRemoteAudioVolumeControl::InformObserver( TInt aErr )
       
   138     {
       
   139     __ASSERT_ALWAYS(iObserver, User::Panic(_L("Observer missing"),KErrGeneral));
       
   140     iObserver ->HandleProcedureCompleted( aErr, iHSPProc );
       
   141     }
       
   142 
       
   143 void CHsHSPRemoteAudioVolumeControl::SetVolumeLevelL( 
       
   144         const CHsHSPCommand* aCmd )
       
   145     {
       
   146     TRACE_FUNC_ENTRY
       
   147 
       
   148     CheckParamsL( aCmd );
       
   149     iSettings->SetSpeakerVolumeLevel( aCmd->Params()[0].IntL() );
       
   150 
       
   151     TRACE_FUNC_EXIT
       
   152     }
       
   153 
       
   154 void CHsHSPRemoteAudioVolumeControl::SetMicGainLevelL(
       
   155         const CHsHSPCommand* aCmd )
       
   156     {
       
   157 
       
   158     TRACE_FUNC_ENTRY
       
   159 
       
   160     CheckParamsL( aCmd );
       
   161     iSettings->SetMicGainLevel( aCmd->Params()[0].IntL() );
       
   162 
       
   163     TRACE_FUNC_EXIT
       
   164     }
       
   165 
       
   166 void CHsHSPRemoteAudioVolumeControl::CheckParamsL( const CHsHSPCommand* aCmd )
       
   167     {
       
   168     TRACE_FUNC_ENTRY
       
   169 
       
   170     TInt params = 1;
       
   171     if ( params != aCmd -> Params().Count() )
       
   172         User::Leave( KErrArgument );
       
   173 
       
   174     TRACE_FUNC_EXIT
       
   175     }