/*
*
* 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 "hfpsettings.h"
#include "hfpcommand.h"
#include "debug.h"
THsHFPIndicatorSetting::THsHFPIndicatorSetting( const TDesC8& aDes,
const TInt aValue )
{
TRACE_FUNC_ENTRY
iDesc.Copy( aDes );
iValue = aValue;
TRACE_FUNC_EXIT
}
void THsHFPIndicatorSetting::SetValueL( const TDesC8& aDesValue )
{
TRACE_FUNC_ENTRY
TLex8 lex( aDesValue );
TInt parsedValue;
User::LeaveIfError( lex.Val( parsedValue ) );
SetValue( parsedValue );
TRACE_FUNC_EXIT
}
void THsHFPIndicatorSetting::SetValue( const TInt aValue )
{
iValue = aValue;
}
TInt THsHFPIndicatorSetting::Int() const
{
return iValue;
}
const THFPIndicatorDes& THsHFPIndicatorSetting::Des() const
{
return iDesc;
}
CHsHFPSettings* CHsHFPSettings::InstanceL()
{
TRACE_STATIC_FUNC_ENTRY
CHsHFPSettings* self = NULL;
TAny* tlsPtr = Dll::Tls();
if ( !tlsPtr )
{
self = new ( ELeave ) CHsHFPSettings;
CleanupStack::PushL( self );
self->ConstructL();
User::LeaveIfError( Dll::SetTls( self ) );
CleanupStack::Pop( self );
}
else
{
self = static_cast <CHsHFPSettings*> ( tlsPtr );
++self->iReferenceCounter;
}
TRACE_FUNC_EXIT
return self;
}
void CHsHFPSettings::Release()
{
TRACE_FUNC_ENTRY
TAny* tlsPtr = Dll::Tls();
__ASSERT_DEBUG( tlsPtr != NULL, User::Panic( _L( "HFP Settings error" ),
KErrNotFound ) );
CHsHFPSettings* self = static_cast <CHsHFPSettings*> ( tlsPtr );
if ( --self->iReferenceCounter == 0 )
{
Dll::FreeTls();
delete self;
}
TRACE_FUNC_EXIT
}
TInt CHsHFPSettings::FindIndicatorIndex( const TDesC8& aIndicatorDes )
{
TRACE_FUNC_ENTRY
TInt idx = KErrNotFound;
for ( TInt i = 0; i < iSettingsArr.Count(); i++ )
{
if ( iSettingsArr[i].Des().Compare( aIndicatorDes ) == 0 )
{
TRACE_INFO((_L8("Found index = %d"), i ))
idx = i;
break;
}
}
TRACE_FUNC_EXIT
return idx;
}
CHsHFPSettings::~CHsHFPSettings()
{
TRACE_FUNC_ENTRY
iSettingsArr.Close();
TRACE_FUNC_EXIT
}
CHsHFPSettings::CHsHFPSettings() :
iReferenceCounter( 1 )
{
}
void CHsHFPSettings::ConstructL()
{
TRACE_FUNC_ENTRY
iSettingsArr.AppendL( THsHFPIndicatorSetting( KNullDesC8, 0 ) );
TRACE_FUNC_EXIT
}