First public contribution.
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/embeddedobject.h>
23 using namespace ContentAccess;
25 EXPORT_C CEmbeddedObject* CEmbeddedObject::NewL(const TDesC& aUniqueId, const TDesC& aName, const TDesC8& aMimeType, TEmbeddedType aType)
27 CEmbeddedObject* self = new (ELeave) CEmbeddedObject(aType);
28 CleanupStack::PushL(self);
29 self->ConstructL(aUniqueId, aName, aMimeType);
30 CleanupStack::Pop(self);
34 EXPORT_C CEmbeddedObject* CEmbeddedObject::NewL(const TDesC& aUniqueId, const TDesC8& aMimeType, TEmbeddedType aType)
36 return CEmbeddedObject::NewL(aUniqueId, KNullDesC(), aMimeType, aType);
39 EXPORT_C CEmbeddedObject* CEmbeddedObject::NewL(RReadStream& aStream)
41 CEmbeddedObject* self = new (ELeave) CEmbeddedObject(EContentObject);
42 CleanupStack::PushL(self);
43 self->InternalizeL(aStream);
44 CleanupStack::Pop(self);
49 CEmbeddedObject::CEmbeddedObject(TEmbeddedType aType) : iType(aType)
53 CEmbeddedObject::~CEmbeddedObject()
59 void CEmbeddedObject::ConstructL(const TDesC& aUniqueId, const TDesC& aName, const TDesC8& aMimeType)
61 // Store the unique Id
62 iUniqueId = aUniqueId.AllocL();
64 // Only store the name if it is non zero, otherwise we presume the name
65 // is the same as the UniqueId
66 if(aName.Length() != 0)
68 iName = aName.AllocL();
70 iMimeType.Copy(aMimeType.Left(KMaxDataTypeLength));
73 EXPORT_C const TDesC& CEmbeddedObject::UniqueId() const
75 // return the name of the embedded object
79 EXPORT_C const TDesC& CEmbeddedObject::Name() const
87 // Name is NULL so must be the same as UniqueId
92 EXPORT_C const TDesC8& CEmbeddedObject::MimeType() const
94 // return the mime type of the embedded object
98 EXPORT_C TEmbeddedType CEmbeddedObject::Type() const
100 // return the type of object (container, content, agent specific object)
105 EXPORT_C void CEmbeddedObject::ExternalizeL(RWriteStream& aStream) const
107 // write the name, mime type and embedded object type to the stream
108 TCafUtils::WriteDescriptor16L(aStream, *iUniqueId);
109 TCafUtils::WriteDescriptor8L(aStream, iMimeType);
110 aStream.WriteInt32L(static_cast<TInt>(iType));
113 TCafUtils::WriteDescriptor16L(aStream, *iName);
117 TCafUtils::WriteDescriptor16L(aStream, KNullDesC());
121 void CEmbeddedObject::InternalizeL(RReadStream& aStream)
123 // Read name, mime type and embedded object type from the stream
124 iUniqueId = TCafUtils::ReadDescriptor16L(aStream);
125 TCafUtils::ReadDescriptor8L(aStream, iMimeType);
126 iType = static_cast<TEmbeddedType> (aStream.ReadInt32L());
127 iName = TCafUtils::ReadDescriptor16L(aStream);
128 // If the name is zero length it is supposed to be iName = NULL
129 if(iName->Des().Length() == 0)