os/security/contentmgmt/contentaccessfwfordrm/source/cafutils/Metadata.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/contentmgmt/contentaccessfwfordrm/source/cafutils/Metadata.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 <charconv.h>
    1.23 +#include <s32strm.h>
    1.24 +#include <caf/metadata.h>
    1.25 +#include "cafutils.h"
    1.26 +
    1.27 +
    1.28 +using namespace ContentAccess;
    1.29 +
    1.30 +CMetaData* CMetaData::NewL(const TDesC8& aField, const TDesC8& aData)
    1.31 +	{
    1.32 +	CMetaData* self = new (ELeave) CMetaData(EFalse);
    1.33 +	CleanupStack::PushL(self);
    1.34 +	self->ConstructL(aField, aData);
    1.35 +	CleanupStack::Pop(self);
    1.36 +	return self;
    1.37 +	}
    1.38 +
    1.39 +CMetaData* CMetaData::NewL(const TDesC16& aField, const TDesC16& aData)
    1.40 +	{
    1.41 +	CMetaData* self = new (ELeave) CMetaData(ETrue);
    1.42 +	CleanupStack::PushL(self);
    1.43 +	self->ConstructL(aField, aData);
    1.44 +	CleanupStack::Pop(self);
    1.45 +	return self;
    1.46 +	}
    1.47 +
    1.48 +CMetaData* CMetaData::NewL(RReadStream& aStream)
    1.49 +	{
    1.50 +	CMetaData* self = new (ELeave) CMetaData(ETrue);
    1.51 +	CleanupStack::PushL(self);
    1.52 +	self->InternalizeL(aStream);
    1.53 +	CleanupStack::Pop(self);
    1.54 +	return self;
    1.55 +	}
    1.56 +
    1.57 +CMetaData::CMetaData(TBool aUnicode) : iUnicode(aUnicode)
    1.58 +	{
    1.59 +	}
    1.60 +
    1.61 +void CMetaData::ConstructL(const TDesC8& aField, const TDesC8& aData)
    1.62 +	{
    1.63 +	// Store supplied data in both 8 bit and unicode forms
    1.64 +	iField8 = aField.AllocL();
    1.65 +	iData8 = aData.AllocL();
    1.66 +
    1.67 +	// Allocate space for 16 bit versions
    1.68 +	iField = HBufC::NewL(iField8->Length());
    1.69 +	iData = HBufC::NewL(iData8->Length());
    1.70 +
    1.71 +	// populate 16 bit versions with 8 bit values
    1.72 +	iField->Des().Copy(*iField8);
    1.73 +	iData->Des().Copy(*iData8);
    1.74 +	}
    1.75 +
    1.76 +void CMetaData::ConstructL(const TDesC16& aField, const TDesC16& aData)
    1.77 +	{
    1.78 +	// Store supplied data in both 8 bit and unicode forms
    1.79 +	iField = aField.AllocL();
    1.80 +	iData = aData.AllocL();
    1.81 +
    1.82 +	// Allocate space for 8 bit versions
    1.83 +	iField8 = HBufC8::NewL(iField->Des().Length());
    1.84 +	iData8 = HBufC8::NewL(iData->Des().Length());
    1.85 +
    1.86 +	// populate 8 bit versions with 16 bit values
    1.87 +	iField8->Des().Copy(*iField);
    1.88 +	iData8->Des().Copy(*iData);
    1.89 +	}
    1.90 +
    1.91 +CMetaData::~CMetaData()
    1.92 +	{
    1.93 +	delete iField;
    1.94 +	delete iData;
    1.95 +	delete iField8;
    1.96 +	delete iData8;
    1.97 +	}
    1.98 +
    1.99 +EXPORT_C const TDesC& CMetaData::Field() const
   1.100 +	{
   1.101 +	return *iField;
   1.102 +	}
   1.103 +		
   1.104 +EXPORT_C const TDesC& CMetaData::Data() const
   1.105 +	{
   1.106 +	return *iData;
   1.107 +	}
   1.108 +
   1.109 +EXPORT_C const TDesC8& CMetaData::Field8() const
   1.110 +	{
   1.111 +	return *iField8;
   1.112 +	}
   1.113 +		
   1.114 +EXPORT_C const TDesC8& CMetaData::Data8() const
   1.115 +	{
   1.116 +	return *iData8;
   1.117 +	}
   1.118 +	
   1.119 +void CMetaData::InternalizeL(RReadStream& aStream)
   1.120 +	{
   1.121 +	// Read the unicode field from the stream
   1.122 +	iField = TCafUtils::ReadDescriptor16L(aStream);
   1.123 +
   1.124 +	// Read the unicode data from the stream
   1.125 +	iData = TCafUtils::ReadDescriptor16L(aStream);
   1.126 +
   1.127 +	// Allocate space for 8 bit versions
   1.128 +	iField8 = HBufC8::NewL(iField->Length());
   1.129 +	iData8 = HBufC8::NewL(iData->Length());
   1.130 +
   1.131 +	// populate 8 bit versions with 16 bit values
   1.132 +	iField8->Des().Copy(*iField);
   1.133 +	iData8->Des().Copy(*iData);
   1.134 +	}
   1.135 +
   1.136 +void CMetaData::ExternalizeL(RWriteStream& aStream) const
   1.137 +	{
   1.138 +	// Write unicode field to the stream
   1.139 +	TCafUtils::WriteDescriptor16L(aStream, *iField);
   1.140 +	TCafUtils::WriteDescriptor16L(aStream, *iData);
   1.141 +	}