diff -r 22de2e391156 -r 20ac952a623c remotecontrol/avrcp/playerinformation/src/playerapplicationsetting.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/remotecontrol/avrcp/playerinformation/src/playerapplicationsetting.cpp Wed Oct 13 16:20:29 2010 +0300 @@ -0,0 +1,133 @@ +// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// This file contains the CPlayerApplicationSettings class. +// This is used to contain the Player application Setting Attributes +// defined by the Bluetooth AVRCP 1.3 specification +// +// + +/** + @file + @internalComponent + @released +*/ + +#include + +#include "playerapplicationsetting.h" +#include "playerinformation.h" + +CPlayerApplicationSettings* CPlayerApplicationSettings::NewL( TUint aAttributeID, + TDesC8& aAttributeText, + const RArray& aValues, + RArray& aValueTexts, + TUint aInitialValue ) + { + CPlayerApplicationSettings* self = new(ELeave) CPlayerApplicationSettings(); + CleanupStack::PushL(self); + self->ConstructL( aAttributeID, aAttributeText, aValues, aValueTexts, aInitialValue); + CleanupStack::Pop(self); + return self; + } + + +CPlayerApplicationSettings::~CPlayerApplicationSettings() + { + delete iAttributeText; + iValues.Close(); + iValueText.ResetAndDestroy(); + } + +CPlayerApplicationSettings::CPlayerApplicationSettings( ) + { + } + +void CPlayerApplicationSettings::ConstructL(TUint aAttributeID, + TDesC8& aAttributeText, + const RArray& aValues, + RArray& aValueText, + TUint aInitialValue ) + { + iAttributeID = aAttributeID; + + // copy the attribute description + iAttributeText = aAttributeText.AllocL(); + + // copy the allowed values + for (TInt i=0; i < aValues.Count(); i++ ) + { + + // avoid duplicated defined values + if (iValues.Find(aValues[i]) != KErrNotFound) + { + User::Leave(KErrArgument); + } + + iValues.AppendL( aValues[i] ); + + // copy the value description into a HBuf and add pointer to iValueTexts + HBufC8 * valueText = aValueText[i].AllocL(); + CleanupStack::PushL(valueText); + iValueText.AppendL(valueText); + CleanupStack::Pop(valueText); + } + + TInt error = SetCurrentValue( aInitialValue ); + if ( error != KErrNone ) + { + User::Leave( error ); + } + } + +TUint CPlayerApplicationSettings::GetAttributeID() + { + return( iAttributeID ); + } + +TUint CPlayerApplicationSettings::GetCurrentValue() + { + return( iCurrentValue ); + } + +TPtrC8 CPlayerApplicationSettings::GetAttributeText() + { + return( *iAttributeText ); + } + +RArray* CPlayerApplicationSettings::GetValues() + { + return( &iValues ); + } + +RPointerArray* CPlayerApplicationSettings::GetValuesTexts() + { + return( &iValueText ); + } + +TInt CPlayerApplicationSettings::SetCurrentValue(TUint aValue) + { + // Only allow setting already defined values + for (TInt i=0; i < iValues.Count(); i++ ) + { + if ( aValue == iValues[i] ) + { + iCurrentValue = aValue; + return KErrNone; + } + } + + // value was not already defined, so return KErrArgument + return KErrArgument; + } +