bluetoothengine/headsetsimulator/profiles/hfpprofile/src/hfpsettings.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 "hfpsettings.h"
       
    20 #include "hfpcommand.h"
       
    21 #include "debug.h"
       
    22 
       
    23 THsHFPIndicatorSetting::THsHFPIndicatorSetting( const TDesC8& aDes,
       
    24         const TInt aValue )
       
    25     {
       
    26     TRACE_FUNC_ENTRY
       
    27     iDesc.Copy( aDes );
       
    28     iValue = aValue;
       
    29     TRACE_FUNC_EXIT
       
    30     }
       
    31 
       
    32 void THsHFPIndicatorSetting::SetValueL( const TDesC8& aDesValue )
       
    33     {
       
    34     TRACE_FUNC_ENTRY
       
    35     TLex8 lex( aDesValue );
       
    36 
       
    37     TInt parsedValue;
       
    38     User::LeaveIfError( lex.Val( parsedValue ) );
       
    39     SetValue( parsedValue );
       
    40     TRACE_FUNC_EXIT
       
    41     }
       
    42 
       
    43 void THsHFPIndicatorSetting::SetValue( const TInt aValue )
       
    44     {
       
    45     iValue = aValue;
       
    46     }
       
    47 
       
    48 TInt THsHFPIndicatorSetting::Int() const
       
    49     {
       
    50     return iValue;
       
    51     }
       
    52 
       
    53 const THFPIndicatorDes& THsHFPIndicatorSetting::Des() const
       
    54     {
       
    55     return iDesc;
       
    56     }
       
    57 
       
    58 CHsHFPSettings* CHsHFPSettings::InstanceL()
       
    59     {
       
    60     TRACE_STATIC_FUNC_ENTRY
       
    61     CHsHFPSettings* self = NULL;
       
    62 
       
    63     TAny* tlsPtr = Dll::Tls();
       
    64     if ( !tlsPtr )
       
    65         {
       
    66         self = new ( ELeave ) CHsHFPSettings;
       
    67         CleanupStack::PushL( self );
       
    68         self->ConstructL();
       
    69         User::LeaveIfError( Dll::SetTls( self ) );
       
    70         CleanupStack::Pop( self );
       
    71         }
       
    72     else
       
    73         {
       
    74         self = static_cast <CHsHFPSettings*> ( tlsPtr );
       
    75         ++self->iReferenceCounter;
       
    76         }
       
    77 
       
    78     TRACE_FUNC_EXIT
       
    79     return self;
       
    80     }
       
    81 
       
    82 void CHsHFPSettings::Release()
       
    83     {
       
    84     TRACE_FUNC_ENTRY
       
    85     TAny* tlsPtr = Dll::Tls();
       
    86     __ASSERT_DEBUG( tlsPtr != NULL, User::Panic( _L( "HFP Settings error" ),
       
    87                     KErrNotFound ) );
       
    88 
       
    89     CHsHFPSettings* self = static_cast <CHsHFPSettings*> ( tlsPtr );
       
    90     if ( --self->iReferenceCounter == 0 )
       
    91         {
       
    92         Dll::FreeTls();
       
    93         delete self;
       
    94         }
       
    95     TRACE_FUNC_EXIT
       
    96     }
       
    97 
       
    98 TInt CHsHFPSettings::FindIndicatorIndex( const TDesC8& aIndicatorDes )
       
    99     {
       
   100     TRACE_FUNC_ENTRY
       
   101     TInt idx = KErrNotFound;
       
   102     for ( TInt i = 0; i < iSettingsArr.Count(); i++ )
       
   103         {
       
   104 
       
   105         if ( iSettingsArr[i].Des().Compare( aIndicatorDes ) == 0 )
       
   106             {
       
   107             TRACE_INFO((_L8("Found index = %d"), i ))
       
   108             idx = i;
       
   109             break;
       
   110             }
       
   111 
       
   112         }
       
   113     TRACE_FUNC_EXIT
       
   114     return idx;
       
   115     }
       
   116 
       
   117 CHsHFPSettings::~CHsHFPSettings()
       
   118     {
       
   119     TRACE_FUNC_ENTRY
       
   120     iSettingsArr.Close();
       
   121     TRACE_FUNC_EXIT
       
   122     }
       
   123 
       
   124 CHsHFPSettings::CHsHFPSettings() :
       
   125     iReferenceCounter( 1 )
       
   126     {
       
   127 
       
   128     }
       
   129 
       
   130 void CHsHFPSettings::ConstructL()
       
   131     {
       
   132     TRACE_FUNC_ENTRY
       
   133     iSettingsArr.AppendL( THsHFPIndicatorSetting( KNullDesC8, 0 ) );
       
   134     TRACE_FUNC_EXIT
       
   135     }
       
   136