sl@0: /* sl@0: * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include "cafutils.h" sl@0: sl@0: using namespace ContentAccess; sl@0: sl@0: EXPORT_C CVirtualPath* CVirtualPath::NewL(const TDesC& aCombinedUriUniqueId) sl@0: { sl@0: // TVirtualPathPtr performs the separation of URI and UniqueId if required sl@0: return CVirtualPath::NewL(TVirtualPathPtr(aCombinedUriUniqueId)); sl@0: } sl@0: sl@0: EXPORT_C CVirtualPath* CVirtualPath::NewL(const TDesC& aURI, const TDesC& aUniqueId) sl@0: { sl@0: return CVirtualPath::NewL(TVirtualPathPtr(aURI, aUniqueId)); sl@0: } sl@0: sl@0: EXPORT_C CVirtualPath* CVirtualPath::NewL(const TVirtualPathPtr& aPtr) sl@0: { sl@0: CVirtualPath* self = new (ELeave) CVirtualPath(aPtr); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CVirtualPath* CVirtualPath::NewL(RReadStream& aStream) sl@0: { sl@0: CVirtualPath* self = new (ELeave) CVirtualPath(TVirtualPathPtr(KNullDesC())); sl@0: CleanupStack::PushL(self); sl@0: self->InternalizeL(aStream); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: CVirtualPath::CVirtualPath(const TVirtualPathPtr& aVirtualPath) : iCombinedUriUniqueIdPtr(KNullDesC16()), iVirtualPathPtr(aVirtualPath) sl@0: { sl@0: } sl@0: sl@0: void CVirtualPath::ConstructL() sl@0: { sl@0: iURI = iVirtualPathPtr.URI().AllocL(); sl@0: iUniqueId = iVirtualPathPtr.UniqueId().AllocL(); sl@0: sl@0: // Make sure the TVirtualPathPtr points to the member sl@0: // variables not the arguments which could be deleted or modified at any time sl@0: iVirtualPathPtr.Set(*iURI, *iUniqueId); sl@0: sl@0: // Create a combined URI descriptor that stores the URI and UniqueId of the content sl@0: CreateCombinedUriUniqueIdL(*iURI, *iUniqueId); sl@0: iCombinedUriUniqueIdPtr.Set(iCombinedUriUniqueId->Des()); sl@0: } sl@0: sl@0: void CVirtualPath::CreateCombinedUriUniqueIdL(const TDesC& aUri, const TDesC& aUniqueId) sl@0: { sl@0: sl@0: // build a concatenated version of the URI and UniqueId sl@0: // The KCafVirtualPathSeparator is used to separate the URI from the UniqueId sl@0: HBufC* temp = HBufC::NewL(aUri.Length() + 1 + aUniqueId.Length()); sl@0: CleanupStack::PushL(temp); sl@0: sl@0: TPtr combinedUriAndUniqueId = temp->Des(); sl@0: combinedUriAndUniqueId.Append(aUri); sl@0: combinedUriAndUniqueId.Append(KCafVirtualPathSeparator()); sl@0: combinedUriAndUniqueId.Append(aUniqueId); sl@0: sl@0: // Set iCombinedUriUniqueId since everything worked up to this point sl@0: delete iCombinedUriUniqueId; sl@0: iCombinedUriUniqueId = NULL; sl@0: iCombinedUriUniqueId = temp; sl@0: iCombinedUriUniqueIdPtr.Set(iCombinedUriUniqueId->Des()); sl@0: sl@0: // dont delete temp since it's now pointed to by iCombinedUriUniqueId sl@0: CleanupStack::Pop(temp); sl@0: } sl@0: sl@0: sl@0: CVirtualPath::~CVirtualPath() sl@0: { sl@0: delete iURI; sl@0: delete iUniqueId; sl@0: delete iCombinedUriUniqueId; sl@0: } sl@0: sl@0: EXPORT_C const TDesC& CVirtualPath::URI() const sl@0: { sl@0: return *iURI; sl@0: } sl@0: sl@0: EXPORT_C const TDesC& CVirtualPath::UniqueId() const sl@0: { sl@0: return *iUniqueId; sl@0: } sl@0: sl@0: EXPORT_C const TDesC& CVirtualPath::GetCombinedUriUniqueId() sl@0: { sl@0: return iCombinedUriUniqueIdPtr; sl@0: } sl@0: sl@0: EXPORT_C void CVirtualPath::ExternalizeL(RWriteStream& aStream) const sl@0: { sl@0: TCafUtils::WriteDescriptor16L(aStream, *iURI); sl@0: TCafUtils::WriteDescriptor16L(aStream, *iUniqueId); sl@0: } sl@0: sl@0: void CVirtualPath::InternalizeL(RReadStream& aStream) sl@0: { sl@0: // Allocate space for the URI, UniqueId and CombinedURI sl@0: iURI = TCafUtils::ReadDescriptor16L(aStream); sl@0: iUniqueId = TCafUtils::ReadDescriptor16L(aStream); sl@0: sl@0: // Create a combined URI and UniqueId for these two sl@0: CreateCombinedUriUniqueIdL(*iURI, *iUniqueId); sl@0: sl@0: // Set the TVirutalPathPtr member to be the URI and UniqueId sl@0: iVirtualPathPtr.Set(*iURI, *iUniqueId); sl@0: }