|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @publishedPartner |
|
19 */ |
|
20 |
|
21 #include <mtp/tmtptypeflatbase.h> |
|
22 #include <mtp/cmtptypestring.h> |
|
23 #include <mtp/cmtptypeserviceformat.h> |
|
24 |
|
25 #include "mtpdatatypespanic.h" |
|
26 |
|
27 // Dataset constants |
|
28 |
|
29 const TUint CMTPTypeServiceFormatElement::KFlat1ChunkSize(18); |
|
30 const TUint CMTPTypeServiceFormatElement::KFlat2ChunkSize(2); |
|
31 |
|
32 |
|
33 const CMTPTypeCompoundBase::TElementInfo CMTPTypeServiceFormatElement::iElementMetaData[CMTPTypeServiceFormatElement::ENumElements] = |
|
34 { |
|
35 {EIdFlat1Chunk, EMTPTypeFlat, {EMTPTypeUINT16, 0, KMTPTypeUINT16Size}}, // EMTPServiceFormatCode |
|
36 {EIdFlat1Chunk, EMTPTypeFlat, {EMTPTypeUINT128, 2, KMTPTypeUINT128Size}}, // EMTPServiceFormatGUID |
|
37 {EIdFormatNameChunk, EMTPTypeString, {EMTPTypeString, KMTPNotApplicable, KMTPNotApplicable}}, // EMTPServiceFormatName |
|
38 {EIdFlat2Chunk, EMTPTypeFlat, {EMTPTypeUINT16, 0, KMTPTypeUINT16Size}}, // EMTPServiceFormatBase |
|
39 {EIdFormatMIMETypeChunk, EMTPTypeString, {EMTPTypeString, KMTPNotApplicable, KMTPNotApplicable}}, // EMTPServiceFormatMIMTType |
|
40 }; |
|
41 |
|
42 EXPORT_C CMTPTypeServiceFormatList* CMTPTypeServiceFormatList::NewL() |
|
43 { |
|
44 CMTPTypeServiceFormatList* self = CMTPTypeServiceFormatList::NewLC(); |
|
45 CleanupStack::Pop(self); |
|
46 return self; |
|
47 } |
|
48 |
|
49 EXPORT_C CMTPTypeServiceFormatList* CMTPTypeServiceFormatList::NewLC() |
|
50 { |
|
51 CMTPTypeServiceFormatList* self = new(ELeave) CMTPTypeServiceFormatList(); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 return self; |
|
55 } |
|
56 |
|
57 EXPORT_C CMTPTypeServiceFormatList::~CMTPTypeServiceFormatList() |
|
58 { |
|
59 |
|
60 } |
|
61 |
|
62 EXPORT_C void CMTPTypeServiceFormatList::AppendL(CMTPTypeServiceFormatElement* aElement) |
|
63 { |
|
64 CMTPTypeList::AppendL(aElement); |
|
65 } |
|
66 |
|
67 CMTPTypeServiceFormatList::CMTPTypeServiceFormatList() : |
|
68 CMTPTypeList(EMTPTypeServiceFormatListDataset,EMTPTypeServiceFormatElementDataset) |
|
69 { |
|
70 } |
|
71 |
|
72 void CMTPTypeServiceFormatList::ConstructL() |
|
73 { |
|
74 InitListL(); |
|
75 } |
|
76 |
|
77 EXPORT_C CMTPTypeServiceFormatElement& CMTPTypeServiceFormatList::ElementL(TUint aIndex) const |
|
78 { |
|
79 return static_cast<CMTPTypeServiceFormatElement&>( CMTPTypeList::ElementL(aIndex) ); |
|
80 } |
|
81 |
|
82 EXPORT_C CMTPTypeServiceFormatElement* CMTPTypeServiceFormatElement::NewL() |
|
83 { |
|
84 CMTPTypeServiceFormatElement* self = NewLC(); |
|
85 CleanupStack::Pop(self); |
|
86 return self; |
|
87 } |
|
88 |
|
89 EXPORT_C CMTPTypeServiceFormatElement* CMTPTypeServiceFormatElement::NewLC() |
|
90 { |
|
91 CMTPTypeServiceFormatElement* self = new(ELeave) CMTPTypeServiceFormatElement(); |
|
92 CleanupStack::PushL(self); |
|
93 self->ConstructL(); |
|
94 return self; |
|
95 } |
|
96 |
|
97 EXPORT_C CMTPTypeServiceFormatElement* CMTPTypeServiceFormatElement::NewL(const TUint16 aFormatCode,const TMTPTypeGuid& aFormatGUID,const TDesC& aFormatName,const TUint16 aFormatBase,const TDesC& aMIMEType) |
|
98 { |
|
99 CMTPTypeServiceFormatElement* self = NewLC( aFormatCode, aFormatGUID, aFormatName, aFormatBase, aMIMEType); |
|
100 CleanupStack::Pop(self); |
|
101 return self; |
|
102 } |
|
103 |
|
104 EXPORT_C CMTPTypeServiceFormatElement* CMTPTypeServiceFormatElement::NewLC(const TUint16 aFormatCode,const TMTPTypeGuid& aFormatGUID,const TDesC& aFormatName,const TUint16 aFormatBase,const TDesC& aMIMEType) |
|
105 { |
|
106 CMTPTypeServiceFormatElement* self = new (ELeave) CMTPTypeServiceFormatElement(); |
|
107 CleanupStack::PushL(self); |
|
108 self->ConstructL(aFormatCode, aFormatGUID, aFormatName, aFormatBase, aMIMEType); |
|
109 return self; |
|
110 } |
|
111 |
|
112 /** |
|
113 Destructor. |
|
114 */ |
|
115 EXPORT_C CMTPTypeServiceFormatElement::~CMTPTypeServiceFormatElement() |
|
116 { |
|
117 iChunkFlat1.Close(); |
|
118 iChunkFlat2.Close(); |
|
119 delete iChunkFormatNameString; |
|
120 delete iChunkMIMETypeString; |
|
121 } |
|
122 |
|
123 |
|
124 |
|
125 EXPORT_C TUint CMTPTypeServiceFormatElement::Type() const |
|
126 { |
|
127 return EMTPTypeServiceFormatElementDataset; |
|
128 } |
|
129 |
|
130 const CMTPTypeCompoundBase::TElementInfo& CMTPTypeServiceFormatElement::ElementInfo(TInt aElementId) const |
|
131 { |
|
132 return iElementInfo[aElementId]; |
|
133 } |
|
134 |
|
135 CMTPTypeServiceFormatElement::CMTPTypeServiceFormatElement() : |
|
136 CMTPTypeCompoundBase((!KJustInTimeConstruction), EIdNumChunks), |
|
137 iElementInfo(iElementMetaData, ENumElements), |
|
138 iChunkFlat1(KFlat1ChunkSize, *this), |
|
139 iChunkFlat2(KFlat2ChunkSize, *this) |
|
140 { |
|
141 |
|
142 } |
|
143 |
|
144 void CMTPTypeServiceFormatElement::ConstructL() |
|
145 { |
|
146 for (TUint i(0); (i < ENumElements); i++) |
|
147 { |
|
148 const TElementInfo& info(iElementInfo[i]); |
|
149 if (ChunkCount() <= info.iChunkId) |
|
150 { |
|
151 MMTPType* chunk(NULL); |
|
152 |
|
153 switch (info.iType) |
|
154 { |
|
155 case EMTPTypeFlat: |
|
156 chunk = NewFlatChunkL(info); |
|
157 break; |
|
158 case EMTPTypeString: |
|
159 chunk = NewStringChunkL(info); |
|
160 break; |
|
161 default: |
|
162 break; |
|
163 } |
|
164 |
|
165 __ASSERT_DEBUG(chunk, User::Invariant()); |
|
166 ChunkAppendL(*chunk); |
|
167 } |
|
168 } |
|
169 } |
|
170 |
|
171 MMTPType* CMTPTypeServiceFormatElement::NewFlatChunkL(const TElementInfo& aElementInfo) |
|
172 { |
|
173 MMTPType* chunk(NULL); |
|
174 if (aElementInfo.iChunkId == EIdFlat1Chunk) |
|
175 { |
|
176 iChunkFlat1.OpenL(); |
|
177 chunk = &iChunkFlat1; |
|
178 } |
|
179 else if ( aElementInfo.iChunkId == EIdFlat2Chunk ) |
|
180 { |
|
181 iChunkFlat2.OpenL(); |
|
182 chunk = &iChunkFlat2; |
|
183 } |
|
184 else |
|
185 {} |
|
186 __ASSERT_DEBUG(chunk, User::Invariant()); |
|
187 return chunk; |
|
188 } |
|
189 |
|
190 MMTPType* CMTPTypeServiceFormatElement::NewStringChunkL(const TElementInfo& aElementInfo) |
|
191 { |
|
192 MMTPType* chunk(NULL); |
|
193 if (aElementInfo.iChunkId == EIdFormatNameChunk) |
|
194 { |
|
195 iChunkFormatNameString = CMTPTypeString::NewL(); |
|
196 chunk = iChunkFormatNameString ; |
|
197 } |
|
198 else if ( aElementInfo.iChunkId == EIdFormatMIMETypeChunk ) |
|
199 { |
|
200 iChunkMIMETypeString = CMTPTypeString::NewL(); |
|
201 chunk = iChunkMIMETypeString ; |
|
202 } |
|
203 else |
|
204 {} |
|
205 __ASSERT_DEBUG(chunk, User::Invariant()); |
|
206 return chunk; |
|
207 } |
|
208 |
|
209 void CMTPTypeServiceFormatElement::ConstructL(const TUint16 aFormatCode,const TMTPTypeGuid& aFormatGUID,const TDesC& aFormatName,const TUint16 aFormatBase,const TDesC& aMIMEType) |
|
210 { |
|
211 |
|
212 ConstructL(); |
|
213 |
|
214 // Set mandatory construction values. |
|
215 SetUint16L(EFormatCode, aFormatCode); |
|
216 SetL(EFormatGUID, aFormatGUID); |
|
217 SetStringL(EFormatName,aFormatName); |
|
218 SetUint16L(EFormatBase,aFormatBase); |
|
219 |
|
220 SetStringL(EFormatMIMEType,aMIMEType); |
|
221 |
|
222 } |