bluetoothengine/headsetsimulator/profiles/hfpprofile/src/features/hfpremoteaudiovolumecontrol.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 "hfpremoteaudiovolumecontrol.h"
       
    20 #include "hfpcommand.h"
       
    21 #include "hfpsettings.h"
       
    22 #include "debug.h"
       
    23 
       
    24 CHsHFPRemoteAudioVolumeControl* CHsHFPRemoteAudioVolumeControl::NewL(
       
    25         MHsHFPFeatureProviderObserver* aObserver )
       
    26     {
       
    27     CHsHFPRemoteAudioVolumeControl* self =
       
    28             CHsHFPRemoteAudioVolumeControl::NewLC( aObserver );
       
    29     CleanupStack::Pop( self );
       
    30     return self;
       
    31     }
       
    32 
       
    33 CHsHFPRemoteAudioVolumeControl* CHsHFPRemoteAudioVolumeControl::NewLC(
       
    34         MHsHFPFeatureProviderObserver* aObserver )
       
    35     {
       
    36     CHsHFPRemoteAudioVolumeControl* self =
       
    37             new ( ELeave ) CHsHFPRemoteAudioVolumeControl( aObserver );
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     return self;
       
    41     }
       
    42 CHsHFPRemoteAudioVolumeControl::~CHsHFPRemoteAudioVolumeControl()
       
    43     {
       
    44     TRACE_FUNC_ENTRY
       
    45     if ( iSettings )
       
    46         {
       
    47         iSettings->Release();
       
    48         }
       
    49     TRACE_FUNC_EXIT
       
    50     }
       
    51 
       
    52 TInt CHsHFPRemoteAudioVolumeControl::VolumeLevelSynchronization(
       
    53         const CHsHFPCommand &aInputCmd, CHsHFPCommand &aOutputCmd )
       
    54     {
       
    55     TRACE_FUNC_ENTRY
       
    56 
       
    57     TInt res = KErrNone;
       
    58     if ( aInputCmd.FromAG() )
       
    59         {
       
    60 
       
    61         if ( aInputCmd.Type() == EHFPCmdVGS )
       
    62             {
       
    63             iSettings->iVgsLevel = aInputCmd.Params()[0].IntL();
       
    64             }
       
    65         else if ( aInputCmd.Type() == EHFPCmdVGM )
       
    66             {
       
    67             iSettings->iVgmLevel = aInputCmd.Params()[0].IntL();
       
    68             }
       
    69         else if ( iWaitingForOK && aInputCmd.Type() == EHFPCmdOK )
       
    70             {
       
    71             iWaitingForOK = EFalse;
       
    72             iWaitingForVgmOK = ETrue;
       
    73             aOutputCmd.SetType( EHFPCmdVGM );
       
    74             aOutputCmd.SetMode( ECmdModeWrite );
       
    75             RATParamArray params;
       
    76             TBuf8 <KHsHFPMaxVolumeLevelParamSize> vgmLevel;
       
    77             vgmLevel.AppendNum( iSettings->iVgmLevel );
       
    78             res = params.Append( TATParam( vgmLevel ) );
       
    79             aOutputCmd.SetParams( params );
       
    80             }
       
    81         else if ( iWaitingForVgmOK && aInputCmd.Type() == EHFPCmdOK )
       
    82             {
       
    83             iWaitingForVgmOK = EFalse;
       
    84             iVolumeLevelSynchronized = ETrue;
       
    85             }
       
    86         else
       
    87             {
       
    88             res = KErrArgument;
       
    89             }
       
    90         }
       
    91     else
       
    92         {
       
    93         res = KErrArgument;
       
    94         }
       
    95 
       
    96     TRACE_FUNC_EXIT
       
    97     return res;
       
    98     }
       
    99 
       
   100 void CHsHFPRemoteAudioVolumeControl::Reset()
       
   101     {
       
   102     TRACE_FUNC_ENTRY
       
   103     iVolumeLevelSynchronized = EFalse;
       
   104     iWaitingForOK = ETrue;
       
   105     iWaitingForVgmOK = EFalse;
       
   106     TRACE_FUNC_EXIT
       
   107     }
       
   108 
       
   109 TInt CHsHFPRemoteAudioVolumeControl::ProcessCommand(
       
   110         const CHsHFPCommand &aInputCmd, CHsHFPCommand &aOutputCmd )
       
   111     {
       
   112     TRACE_FUNC_ENTRY
       
   113 
       
   114     TInt res = KErrNone;
       
   115     if ( !iVolumeLevelSynchronized )
       
   116         {
       
   117         res = VolumeLevelSynchronization( aInputCmd, aOutputCmd );
       
   118         }
       
   119     else if ( aInputCmd.FromAG() )
       
   120         {
       
   121         if ( aInputCmd.Type() == EHFPCmdVGS && aInputCmd.Params().Count() == 1 )
       
   122             {
       
   123             TRAP( res, iSettings->iVgsLevel = aInputCmd.Params()[0].IntL() );
       
   124             }
       
   125         else if ( aInputCmd.Type() == EHFPCmdVGM && aInputCmd.Params().Count() == 1 )
       
   126             {
       
   127             TRAP( res, iSettings->iVgmLevel = aInputCmd.Params()[0].IntL() );
       
   128             }
       
   129         else if ( iWaitingForOK && aInputCmd.Type() == EHFPCmdOK )
       
   130             {
       
   131             iWaitingForOK = EFalse;
       
   132             iObserver->HandleProcedureCompleted( KErrNone );
       
   133             }
       
   134         else
       
   135             {
       
   136             res = KErrArgument;
       
   137             }
       
   138         }
       
   139     else
       
   140         {
       
   141         if ( aInputCmd.Type() == EHFPCmdVGS && aInputCmd.Params().Count() == 1 )
       
   142             {
       
   143             iWaitingForOK = ETrue;
       
   144             TRAP( res, iSettings->iVgsLevel = aInputCmd.Params()[0].IntL();
       
   145                     CHsHFPCommand ::CopyL( aInputCmd, aOutputCmd ) );
       
   146             }
       
   147         else if ( aInputCmd.Type() == EHFPCmdVGM && aInputCmd.Params().Count() == 1 )
       
   148             {
       
   149             iWaitingForOK = ETrue;
       
   150             TRAP( res, iSettings->iVgmLevel = aInputCmd.Params()[0].IntL();
       
   151                     CHsHFPCommand::CopyL( aInputCmd, aOutputCmd ) );
       
   152             }
       
   153         else
       
   154             {
       
   155             res = KErrArgument;
       
   156             }
       
   157         }
       
   158 
       
   159     TRACE_FUNC_EXIT
       
   160     return res;
       
   161     }
       
   162 
       
   163 CHsHFPRemoteAudioVolumeControl::CHsHFPRemoteAudioVolumeControl(
       
   164         MHsHFPFeatureProviderObserver* aObserver ) :
       
   165     iObserver( aObserver ), iWaitingForOK( ETrue )
       
   166     {
       
   167     }
       
   168 
       
   169 void CHsHFPRemoteAudioVolumeControl::ConstructL()
       
   170     {
       
   171     iSettings = CHsHFPSettings::InstanceL();
       
   172     }
       
   173