1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/contentmgmt/contentaccessfwfordrm/source/cafutils/attributeset.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,138 @@
1.4 +/*
1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include <s32strm.h>
1.23 +#include <caf/attributeset.h>
1.24 +#include <caf/caferr.h>
1.25 +
1.26 +using namespace ContentAccess;
1.27 +
1.28 +EXPORT_C RAttributeSet::RAttributeSet()
1.29 + {
1.30 + }
1.31 +
1.32 +EXPORT_C void RAttributeSet::Close()
1.33 + {
1.34 + // Clean up array
1.35 + iAttributes.Reset();
1.36 + iAttributes.Close();
1.37 + }
1.38 +
1.39 +EXPORT_C void RAttributeSet::AddL(TInt aAttribute)
1.40 + {
1.41 + // Can't have duplicates so if the attribute already exists just reset its
1.42 + // value back to KErrCANotSupported
1.43 + if(SetValue(aAttribute, 0, KErrCANotSupported) != KErrNone)
1.44 + {
1.45 + // Doesn't exist so add it
1.46 + AddL(aAttribute, 0, KErrCANotSupported);
1.47 + }
1.48 + }
1.49 +
1.50 +EXPORT_C TInt RAttributeSet::GetValue(TInt aAttribute, TInt& aValue) const
1.51 + {
1.52 + TInt i;
1.53 + TInt count = iAttributes.Count();
1.54 + for(i = 0; i < count; i++)
1.55 + {
1.56 + if(iAttributes[i].iAttribute == aAttribute)
1.57 + {
1.58 + // Set the value and return the associated error code
1.59 + aValue = iAttributes[i].iValue;
1.60 + return iAttributes[i].iError;
1.61 + }
1.62 + }
1.63 + return KErrNotFound;
1.64 + }
1.65 +
1.66 +EXPORT_C TInt RAttributeSet::SetValue(TInt aAttribute, TInt aValue, TInt aErrorCode)
1.67 + {
1.68 + TInt i;
1.69 + TInt count = iAttributes.Count();
1.70 + for(i = 0; i < count; i++)
1.71 + {
1.72 + if(iAttributes[i].iAttribute == aAttribute)
1.73 + {
1.74 + iAttributes[i].iValue = aValue;
1.75 + iAttributes[i].iError = aErrorCode;
1.76 + return KErrNone;
1.77 + }
1.78 + }
1.79 + return KErrNotFound;
1.80 + }
1.81 +
1.82 +EXPORT_C TInt RAttributeSet::operator [] (TInt aIndex) const
1.83 + {
1.84 + return iAttributes[aIndex].iAttribute;
1.85 + }
1.86 +
1.87 +EXPORT_C TInt RAttributeSet::Count() const
1.88 + {
1.89 + return iAttributes.Count();
1.90 + }
1.91 +
1.92 +EXPORT_C void RAttributeSet::ExternalizeL(RWriteStream& aStream) const
1.93 + {
1.94 + TInt i;
1.95 + TInt count = iAttributes.Count();
1.96 + aStream.WriteInt32L(count);
1.97 + for(i = 0; i < count; i++)
1.98 + {
1.99 + aStream.WriteInt32L(iAttributes[i].iAttribute);
1.100 + aStream.WriteInt32L(iAttributes[i].iValue);
1.101 + aStream.WriteInt32L(iAttributes[i].iError);
1.102 + }
1.103 + }
1.104 +
1.105 +EXPORT_C void RAttributeSet::InternalizeL(RReadStream& aStream)
1.106 + {
1.107 + TInt i;
1.108 + TInt attribute;
1.109 + TInt value;
1.110 + TInt errorCode;
1.111 +
1.112 + // Read the number of attributes to internalize
1.113 + TInt count = aStream.ReadInt32L();
1.114 +
1.115 + // loop through all the attributes
1.116 + for(i = 0; i < count; i++)
1.117 + {
1.118 + // Read the attribute and value from the stream
1.119 + attribute = aStream.ReadInt32L();
1.120 + value = aStream.ReadInt32L();
1.121 + errorCode = aStream.ReadInt32L();
1.122 +
1.123 + // try setting the attribute value first in case it already exists
1.124 + if(SetValue(attribute, value, errorCode) != KErrNone)
1.125 + {
1.126 + // Doesn't exist so set a new values
1.127 + AddL(attribute, value, errorCode);
1.128 + }
1.129 + }
1.130 + }
1.131 +
1.132 +void RAttributeSet::AddL(TInt aAttribute, TInt aValue, TInt aErrorCode)
1.133 + {
1.134 + TAttributeValue attribute;
1.135 + attribute.iAttribute = aAttribute;
1.136 + attribute.iValue = aValue;
1.137 + attribute.iError = aErrorCode;
1.138 +
1.139 + // Append the new values to the iAttributes array
1.140 + User::LeaveIfError(iAttributes.Append(attribute));
1.141 + }