|
1 /* |
|
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <s32strm.h> |
|
20 #include "EmbeddedObject.h" |
|
21 #include "cafutils.h" |
|
22 |
|
23 using namespace ContentAccess; |
|
24 |
|
25 EXPORT_C CEmbeddedObject* CEmbeddedObject::NewL(const TDesC& aUniqueId, const TDesC& aName, const TDesC8& aMimeType, TEmbeddedType aType) |
|
26 { |
|
27 CEmbeddedObject* self = new (ELeave) CEmbeddedObject(aType); |
|
28 CleanupStack::PushL(self); |
|
29 self->ConstructL(aUniqueId, aName, aMimeType); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 EXPORT_C CEmbeddedObject* CEmbeddedObject::NewL(const TDesC& aUniqueId, const TDesC8& aMimeType, TEmbeddedType aType) |
|
35 { |
|
36 return CEmbeddedObject::NewL(aUniqueId, KNullDesC(), aMimeType, aType); |
|
37 } |
|
38 |
|
39 EXPORT_C CEmbeddedObject* CEmbeddedObject::NewL(RReadStream& aStream) |
|
40 { |
|
41 CEmbeddedObject* self = new (ELeave) CEmbeddedObject(EContentObject); |
|
42 CleanupStack::PushL(self); |
|
43 self->InternalizeL(aStream); |
|
44 CleanupStack::Pop(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 |
|
49 CEmbeddedObject::CEmbeddedObject(TEmbeddedType aType) : iType(aType) |
|
50 { |
|
51 } |
|
52 |
|
53 CEmbeddedObject::~CEmbeddedObject() |
|
54 { |
|
55 delete iUniqueId; |
|
56 delete iName; |
|
57 } |
|
58 |
|
59 void CEmbeddedObject::ConstructL(const TDesC& aUniqueId, const TDesC& aName, const TDesC8& aMimeType) |
|
60 { |
|
61 // Store the unique Id |
|
62 iUniqueId = aUniqueId.AllocL(); |
|
63 |
|
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) |
|
67 { |
|
68 iName = aName.AllocL(); |
|
69 } |
|
70 iMimeType.Copy(aMimeType.Left(KMaxDataTypeLength)); |
|
71 } |
|
72 |
|
73 EXPORT_C const TDesC& CEmbeddedObject::UniqueId() const |
|
74 { |
|
75 // return the name of the embedded object |
|
76 return *iUniqueId; |
|
77 } |
|
78 |
|
79 EXPORT_C const TDesC& CEmbeddedObject::Name() const |
|
80 { |
|
81 if(iName) |
|
82 { |
|
83 return *iName; |
|
84 } |
|
85 else |
|
86 { |
|
87 // Name is NULL so must be the same as UniqueId |
|
88 return *iUniqueId; |
|
89 } |
|
90 } |
|
91 |
|
92 EXPORT_C const TDesC8& CEmbeddedObject::MimeType() const |
|
93 { |
|
94 // return the mime type of the embedded object |
|
95 return iMimeType; |
|
96 } |
|
97 |
|
98 EXPORT_C TEmbeddedType CEmbeddedObject::Type() const |
|
99 { |
|
100 // return the type of object (container, content, agent specific object) |
|
101 return iType; |
|
102 } |
|
103 |
|
104 |
|
105 EXPORT_C void CEmbeddedObject::ExternalizeL(RWriteStream& aStream) const |
|
106 { |
|
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)); |
|
111 if(iName) |
|
112 { |
|
113 TCafUtils::WriteDescriptor16L(aStream, *iName); |
|
114 } |
|
115 else |
|
116 { |
|
117 TCafUtils::WriteDescriptor16L(aStream, KNullDesC()); |
|
118 } |
|
119 } |
|
120 |
|
121 void CEmbeddedObject::InternalizeL(RReadStream& aStream) |
|
122 { |
|
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) |
|
130 { |
|
131 delete iName; |
|
132 iName=NULL; |
|
133 } |
|
134 } |