Update contrib.
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #include <caf/virtualpath.h>
23 using namespace ContentAccess;
25 EXPORT_C CVirtualPath* CVirtualPath::NewL(const TDesC& aCombinedUriUniqueId)
27 // TVirtualPathPtr performs the separation of URI and UniqueId if required
28 return CVirtualPath::NewL(TVirtualPathPtr(aCombinedUriUniqueId));
31 EXPORT_C CVirtualPath* CVirtualPath::NewL(const TDesC& aURI, const TDesC& aUniqueId)
33 return CVirtualPath::NewL(TVirtualPathPtr(aURI, aUniqueId));
36 EXPORT_C CVirtualPath* CVirtualPath::NewL(const TVirtualPathPtr& aPtr)
38 CVirtualPath* self = new (ELeave) CVirtualPath(aPtr);
39 CleanupStack::PushL(self);
41 CleanupStack::Pop(self);
45 EXPORT_C CVirtualPath* CVirtualPath::NewL(RReadStream& aStream)
47 CVirtualPath* self = new (ELeave) CVirtualPath(TVirtualPathPtr(KNullDesC()));
48 CleanupStack::PushL(self);
49 self->InternalizeL(aStream);
50 CleanupStack::Pop(self);
55 CVirtualPath::CVirtualPath(const TVirtualPathPtr& aVirtualPath) : iCombinedUriUniqueIdPtr(KNullDesC16()), iVirtualPathPtr(aVirtualPath)
59 void CVirtualPath::ConstructL()
61 iURI = iVirtualPathPtr.URI().AllocL();
62 iUniqueId = iVirtualPathPtr.UniqueId().AllocL();
64 // Make sure the TVirtualPathPtr points to the member
65 // variables not the arguments which could be deleted or modified at any time
66 iVirtualPathPtr.Set(*iURI, *iUniqueId);
68 // Create a combined URI descriptor that stores the URI and UniqueId of the content
69 CreateCombinedUriUniqueIdL(*iURI, *iUniqueId);
70 iCombinedUriUniqueIdPtr.Set(iCombinedUriUniqueId->Des());
73 void CVirtualPath::CreateCombinedUriUniqueIdL(const TDesC& aUri, const TDesC& aUniqueId)
76 // build a concatenated version of the URI and UniqueId
77 // The KCafVirtualPathSeparator is used to separate the URI from the UniqueId
78 HBufC* temp = HBufC::NewL(aUri.Length() + 1 + aUniqueId.Length());
79 CleanupStack::PushL(temp);
81 TPtr combinedUriAndUniqueId = temp->Des();
82 combinedUriAndUniqueId.Append(aUri);
83 combinedUriAndUniqueId.Append(KCafVirtualPathSeparator());
84 combinedUriAndUniqueId.Append(aUniqueId);
86 // Set iCombinedUriUniqueId since everything worked up to this point
87 delete iCombinedUriUniqueId;
88 iCombinedUriUniqueId = NULL;
89 iCombinedUriUniqueId = temp;
90 iCombinedUriUniqueIdPtr.Set(iCombinedUriUniqueId->Des());
92 // dont delete temp since it's now pointed to by iCombinedUriUniqueId
93 CleanupStack::Pop(temp);
97 CVirtualPath::~CVirtualPath()
101 delete iCombinedUriUniqueId;
104 EXPORT_C const TDesC& CVirtualPath::URI() const
109 EXPORT_C const TDesC& CVirtualPath::UniqueId() const
114 EXPORT_C const TDesC& CVirtualPath::GetCombinedUriUniqueId()
116 return iCombinedUriUniqueIdPtr;
119 EXPORT_C void CVirtualPath::ExternalizeL(RWriteStream& aStream) const
121 TCafUtils::WriteDescriptor16L(aStream, *iURI);
122 TCafUtils::WriteDescriptor16L(aStream, *iUniqueId);
125 void CVirtualPath::InternalizeL(RReadStream& aStream)
127 // Allocate space for the URI, UniqueId and CombinedURI
128 iURI = TCafUtils::ReadDescriptor16L(aStream);
129 iUniqueId = TCafUtils::ReadDescriptor16L(aStream);
131 // Create a combined URI and UniqueId for these two
132 CreateCombinedUriUniqueIdL(*iURI, *iUniqueId);
134 // Set the TVirutalPathPtr member to be the URI and UniqueId
135 iVirtualPathPtr.Set(*iURI, *iUniqueId);