os/security/contentmgmt/contentaccessfwfordrm/source/cafutils/virtualpath.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/virtualpath.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,136 @@
     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/virtualpath.h>
    1.24 +#include "cafutils.h"
    1.25 +
    1.26 +using namespace ContentAccess;
    1.27 +
    1.28 +EXPORT_C CVirtualPath* CVirtualPath::NewL(const TDesC& aCombinedUriUniqueId)
    1.29 +	{	
    1.30 +	// TVirtualPathPtr performs the separation of URI and UniqueId if required
    1.31 +	return CVirtualPath::NewL(TVirtualPathPtr(aCombinedUriUniqueId));
    1.32 +	}
    1.33 +
    1.34 +EXPORT_C CVirtualPath* CVirtualPath::NewL(const TDesC& aURI, const TDesC& aUniqueId)
    1.35 +	{	
    1.36 +	return CVirtualPath::NewL(TVirtualPathPtr(aURI, aUniqueId));
    1.37 +	}
    1.38 +
    1.39 +EXPORT_C CVirtualPath* CVirtualPath::NewL(const TVirtualPathPtr& aPtr)
    1.40 +	{	
    1.41 +	CVirtualPath* self = new (ELeave) CVirtualPath(aPtr);
    1.42 +	CleanupStack::PushL(self);
    1.43 +	self->ConstructL();
    1.44 +	CleanupStack::Pop(self);
    1.45 +	return self;
    1.46 +	}
    1.47 +
    1.48 +EXPORT_C CVirtualPath* CVirtualPath::NewL(RReadStream& aStream)
    1.49 +	{
    1.50 +	CVirtualPath* self = new (ELeave) CVirtualPath(TVirtualPathPtr(KNullDesC()));
    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 +
    1.58 +CVirtualPath::CVirtualPath(const TVirtualPathPtr& aVirtualPath) : iCombinedUriUniqueIdPtr(KNullDesC16()), iVirtualPathPtr(aVirtualPath) 
    1.59 +	{
    1.60 +	}
    1.61 +
    1.62 +void CVirtualPath::ConstructL()
    1.63 +	{
    1.64 +	iURI = iVirtualPathPtr.URI().AllocL();
    1.65 +	iUniqueId = iVirtualPathPtr.UniqueId().AllocL();
    1.66 +	
    1.67 +	// Make sure the TVirtualPathPtr points to the member
    1.68 +	// variables not the arguments which could be deleted or modified at any time
    1.69 +	iVirtualPathPtr.Set(*iURI, *iUniqueId);
    1.70 +
    1.71 +	// Create a combined URI descriptor that stores the URI and UniqueId of the content
    1.72 +	CreateCombinedUriUniqueIdL(*iURI, *iUniqueId);
    1.73 +	iCombinedUriUniqueIdPtr.Set(iCombinedUriUniqueId->Des());
    1.74 +	}
    1.75 +
    1.76 +void CVirtualPath::CreateCombinedUriUniqueIdL(const TDesC& aUri, const TDesC& aUniqueId)
    1.77 +	{
    1.78 +	
    1.79 +	// build a concatenated version of the URI and UniqueId
    1.80 +	// The KCafVirtualPathSeparator is used to separate the URI from the UniqueId
    1.81 +	HBufC* temp = HBufC::NewL(aUri.Length() + 1 + aUniqueId.Length());
    1.82 +	CleanupStack::PushL(temp);
    1.83 +
    1.84 +	TPtr combinedUriAndUniqueId = temp->Des();
    1.85 +	combinedUriAndUniqueId.Append(aUri);
    1.86 +	combinedUriAndUniqueId.Append(KCafVirtualPathSeparator());
    1.87 +	combinedUriAndUniqueId.Append(aUniqueId);
    1.88 +
    1.89 +	// Set iCombinedUriUniqueId since everything worked up to this point
    1.90 +	delete iCombinedUriUniqueId;
    1.91 +	iCombinedUriUniqueId = NULL;
    1.92 +	iCombinedUriUniqueId = temp;
    1.93 +	iCombinedUriUniqueIdPtr.Set(iCombinedUriUniqueId->Des());
    1.94 +
    1.95 +	// dont delete temp since it's now pointed to by iCombinedUriUniqueId
    1.96 +	CleanupStack::Pop(temp);
    1.97 +	}
    1.98 +
    1.99 +
   1.100 +CVirtualPath::~CVirtualPath()
   1.101 +	{
   1.102 +	delete iURI;
   1.103 +	delete iUniqueId;
   1.104 +	delete iCombinedUriUniqueId;
   1.105 +	}
   1.106 +
   1.107 +EXPORT_C const TDesC& CVirtualPath::URI() const
   1.108 +	{
   1.109 +	return *iURI;
   1.110 +	}
   1.111 +
   1.112 +EXPORT_C const TDesC& CVirtualPath::UniqueId() const
   1.113 +	{
   1.114 +	return *iUniqueId;
   1.115 +	}
   1.116 +
   1.117 +EXPORT_C const TDesC& CVirtualPath::GetCombinedUriUniqueId()
   1.118 +	{
   1.119 +	return iCombinedUriUniqueIdPtr;
   1.120 +	}
   1.121 +
   1.122 +EXPORT_C void CVirtualPath::ExternalizeL(RWriteStream& aStream) const
   1.123 +	{
   1.124 +	TCafUtils::WriteDescriptor16L(aStream, *iURI);
   1.125 +	TCafUtils::WriteDescriptor16L(aStream, *iUniqueId);
   1.126 +	}	
   1.127 +
   1.128 +void CVirtualPath::InternalizeL(RReadStream& aStream)
   1.129 +	{
   1.130 +	// Allocate space for the URI, UniqueId and CombinedURI
   1.131 +	iURI = TCafUtils::ReadDescriptor16L(aStream);
   1.132 +	iUniqueId = TCafUtils::ReadDescriptor16L(aStream);
   1.133 +
   1.134 +	// Create a combined URI and UniqueId for these two
   1.135 +	CreateCombinedUriUniqueIdL(*iURI, *iUniqueId);
   1.136 +
   1.137 +	// Set the TVirutalPathPtr member to be the URI and UniqueId
   1.138 +	iVirtualPathPtr.Set(*iURI, *iUniqueId);
   1.139 +	}