|
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 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <mtp/cmtptypeservicepropdesclist.h> |
|
22 #include <mtp/mtpdatatypeconstants.h> |
|
23 #include <mtp/mtpprotocolconstants.h> |
|
24 |
|
25 #include "mtpdatatypespanic.h" |
|
26 |
|
27 // Dataset constants |
|
28 |
|
29 const TUint CMTPTypeServicePropDesc::KFlat1ChunkSize(6); |
|
30 const TUint CMTPTypeServicePropDesc::KNumChunksWithoutForm(EIdFlat1Chunk + 1); |
|
31 const TUint CMTPTypeServicePropDesc::KNumChunksWithForm(EIdFormChunk + 1); |
|
32 |
|
33 //Dataset element metadata |
|
34 const CMTPTypeCompoundBase::TElementInfo CMTPTypeServicePropDesc::iElementMetaData[CMTPTypeServicePropDesc::ENumElements] = |
|
35 { |
|
36 {EIdFlat1Chunk, EMTPTypeFlat, {EMTPTypeUINT16, 0, KMTPTypeUINT16Size}}, // EServicePropertyCode |
|
37 {EIdFlat1Chunk, EMTPTypeFlat, {EMTPTypeUINT16, 2, KMTPTypeUINT16Size}}, // EDataType1 |
|
38 {EIdFlat1Chunk, EMTPTypeFlat, {EMTPTypeUINT8, 4, KMTPTypeUINT8Size}}, // EGetSet1 |
|
39 {EIdFlat1Chunk, EMTPTypeFlat, {EMTPTypeUINT8, 5, KMTPTypeUINT8Size}}, // EFormFlag |
|
40 {EIdFormChunk, EMTPTypeReference, {EMTPTypeUndefined, KMTPNotApplicable, KMTPNotApplicable}}, // EForm |
|
41 }; |
|
42 |
|
43 |
|
44 |
|
45 EXPORT_C CMTPTypeServicePropDescList* CMTPTypeServicePropDescList::NewL() |
|
46 { |
|
47 CMTPTypeServicePropDescList* self = CMTPTypeServicePropDescList::NewLC(); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 |
|
53 EXPORT_C CMTPTypeServicePropDescList* CMTPTypeServicePropDescList::NewLC() |
|
54 { |
|
55 CMTPTypeServicePropDescList* self = new(ELeave) CMTPTypeServicePropDescList(); |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(); |
|
58 return self; |
|
59 } |
|
60 |
|
61 /** |
|
62 Destructor. |
|
63 */ |
|
64 EXPORT_C CMTPTypeServicePropDescList::~CMTPTypeServicePropDescList() |
|
65 { |
|
66 |
|
67 } |
|
68 |
|
69 CMTPTypeServicePropDescList::CMTPTypeServicePropDescList() : |
|
70 CMTPTypeList(EMTPTypeServicePropDescList,EMTPTypeServicePropDesc) |
|
71 { |
|
72 } |
|
73 |
|
74 void CMTPTypeServicePropDescList::ConstructL() |
|
75 { |
|
76 InitListL(); |
|
77 } |
|
78 |
|
79 EXPORT_C void CMTPTypeServicePropDescList::AppendL(CMTPTypeServicePropDesc* aElement) |
|
80 { |
|
81 CMTPTypeList::AppendL(aElement); |
|
82 } |
|
83 |
|
84 EXPORT_C CMTPTypeServicePropDesc& CMTPTypeServicePropDescList::ElementL(TUint aIndex) const |
|
85 { |
|
86 return static_cast<CMTPTypeServicePropDesc&>( CMTPTypeList::ElementL(aIndex) ); |
|
87 } |
|
88 |
|
89 /** |
|
90 MTP Service Object Property Extension FORM dataset factory method. This method is used to |
|
91 create an empty MTP Service Object Property Extension FORM of the specified Datatype. |
|
92 @return A pointer to the form type. Ownership IS |
|
93 transfered. |
|
94 @leave One of the system wide error codes, if unsuccessful. |
|
95 */ |
|
96 EXPORT_C CMTPTypeServicePropDesc* CMTPTypeServicePropDesc::NewL() |
|
97 { |
|
98 CMTPTypeServicePropDesc* self = CMTPTypeServicePropDesc::NewLC(); |
|
99 CleanupStack::Pop(self); |
|
100 return self; |
|
101 } |
|
102 /** |
|
103 MTP DevicePropDesc Service Object Property Extension FORM factory method. This method is used to |
|
104 create an empty MTP Service Object Property Extension FORM of the specified Datatype. |
|
105 @return A pointer to the form type. Ownership IS |
|
106 transfered. |
|
107 @leave One of the system wide error codes, if unsuccessful. |
|
108 */ |
|
109 EXPORT_C CMTPTypeServicePropDesc* CMTPTypeServicePropDesc::NewLC() |
|
110 { |
|
111 CMTPTypeServicePropDesc* self = new(ELeave) CMTPTypeServicePropDesc(); |
|
112 CleanupStack::PushL(self); |
|
113 const TUint16 KUndefinedCode = 0; |
|
114 self->ConstructL( KUndefinedCode , EMTPTypeUndefined,CMTPTypeObjectPropDesc::EReadOnly , CMTPTypeObjectPropDesc::ENone, NULL ); |
|
115 return self; |
|
116 } |
|
117 |
|
118 EXPORT_C CMTPTypeServicePropDesc* CMTPTypeServicePropDesc::NewL( const TUint16 aServicePropCode, const TUint16 aDataType, const TUint8 aGetSet, const TUint8 aFormFlag, const MMTPType* aForm ) |
|
119 { |
|
120 CMTPTypeServicePropDesc* self = CMTPTypeServicePropDesc::NewLC( aServicePropCode, aDataType, aGetSet, aFormFlag, aForm ); |
|
121 CleanupStack::Pop(self); |
|
122 return self; |
|
123 } |
|
124 |
|
125 |
|
126 EXPORT_C CMTPTypeServicePropDesc* CMTPTypeServicePropDesc::NewLC( const TUint16 aServicePropCode, const TUint16 aDataType, const TUint8 aGetSet, const TUint8 aFormFlag, const MMTPType* aForm) |
|
127 { |
|
128 CMTPTypeServicePropDesc* self = new(ELeave) CMTPTypeServicePropDesc(); |
|
129 CleanupStack::PushL(self); |
|
130 self->ConstructL( aServicePropCode, aDataType, aGetSet, aFormFlag, aForm ); |
|
131 return self; |
|
132 } |
|
133 |
|
134 |
|
135 /** |
|
136 Destructor. |
|
137 */ |
|
138 EXPORT_C CMTPTypeServicePropDesc::~CMTPTypeServicePropDesc() |
|
139 { |
|
140 iChunkFlat1.Close(); |
|
141 iChunkForm.Close(); |
|
142 } |
|
143 |
|
144 CMTPTypeServicePropDesc::CMTPTypeServicePropDesc() : |
|
145 CMTPTypeCompoundBase((KJustInTimeConstruction), KNumChunksWithoutForm), |
|
146 iElementInfo(iElementMetaData, ENumElements), |
|
147 iChunkFlat1(KFlat1ChunkSize, *this) |
|
148 { |
|
149 |
|
150 } |
|
151 |
|
152 EXPORT_C TUint CMTPTypeServicePropDesc::Type() const |
|
153 { |
|
154 return EMTPTypeServicePropDesc; |
|
155 } |
|
156 |
|
157 |
|
158 |
|
159 EXPORT_C TInt CMTPTypeServicePropDesc::FirstWriteChunk(TPtr8& aChunk) |
|
160 { |
|
161 /* |
|
162 Reset the type in preparation for the data stream, by deleting all |
|
163 except the first chunk. |
|
164 */ |
|
165 for (TUint i(ChunkCount() - 1); (i >= (EIdFlat1Chunk + 1)); i--) |
|
166 { |
|
167 ChunkRemove(i); |
|
168 } |
|
169 |
|
170 // Setup the write chunk pointer. |
|
171 TInt err(CMTPTypeCompoundBase::FirstWriteChunk(aChunk)); |
|
172 switch (err) |
|
173 { |
|
174 case KMTPChunkSequenceCompletion: |
|
175 err = KErrNone; |
|
176 // Don't break, fall through to set the write sequence state. |
|
177 |
|
178 case KErrNone: |
|
179 // Set the write sequence state. |
|
180 iWriteSequenceState = EFormChunk; |
|
181 iWriteSequenceCompletionState = EFormChunk; |
|
182 break; |
|
183 |
|
184 default: |
|
185 break; |
|
186 } |
|
187 |
|
188 return err; |
|
189 } |
|
190 |
|
191 EXPORT_C TInt CMTPTypeServicePropDesc::NextWriteChunk(TPtr8& /*aChunk*/) |
|
192 { |
|
193 return KMTPChunkSequenceCompletion; |
|
194 } |
|
195 |
|
196 |
|
197 EXPORT_C TBool CMTPTypeServicePropDesc::CommitRequired() const |
|
198 { |
|
199 return ETrue; |
|
200 } |
|
201 |
|
202 |
|
203 EXPORT_C MMTPType* CMTPTypeServicePropDesc::CommitChunkL(TPtr8& aChunk) |
|
204 { |
|
205 switch (iWriteSequenceState) |
|
206 { |
|
207 case EFormChunk: |
|
208 { |
|
209 iChunkForm.Close(); |
|
210 TUint8 flag(Uint8L(EFormFlag)); |
|
211 TUint16 type(Uint16L(EDataType1)); |
|
212 iChunkForm.SetMeta(flag, type); |
|
213 if (HasFormField(flag)) |
|
214 { |
|
215 iChunkForm.OpenL(iElementInfo[EForm].iType); |
|
216 ChunkAppendL(iChunkForm); |
|
217 SetExpectedChunkCount(KNumChunksWithForm); |
|
218 } |
|
219 else |
|
220 { |
|
221 // Adjust the write sequence completion state. |
|
222 iWriteSequenceCompletionState = EFormChunk; |
|
223 } |
|
224 } |
|
225 break; |
|
226 |
|
227 case EIdle: |
|
228 // Completing the last element in the write sequence. |
|
229 break; |
|
230 |
|
231 default: |
|
232 Panic(EMTPTypeBadStorage); |
|
233 break; |
|
234 } |
|
235 |
|
236 if ( (iWriteSequenceState != EIdle ) && (iWriteSequenceState < iWriteSequenceCompletionState) ) |
|
237 { |
|
238 iWriteSequenceState++; |
|
239 } |
|
240 else |
|
241 { |
|
242 iWriteSequenceState = EIdle; |
|
243 } |
|
244 |
|
245 |
|
246 if (CMTPTypeCompoundBase::CommitRequired()) |
|
247 { |
|
248 CMTPTypeCompoundBase::CommitChunkL(aChunk); |
|
249 } |
|
250 return NULL; |
|
251 } |
|
252 |
|
253 |
|
254 TBool CMTPTypeServicePropDesc::HasFormField(TUint8 aFormFlag) const |
|
255 { |
|
256 return ((aFormFlag != CMTPTypeObjectPropDesc::EDateTimeForm) && (aFormFlag != CMTPTypeObjectPropDesc::ENone)&&(aFormFlag != CMTPTypeObjectPropDesc::EObjectIDForm)); |
|
257 } |
|
258 |
|
259 |
|
260 const CMTPTypeCompoundBase::TElementInfo& CMTPTypeServicePropDesc::ElementInfo(TInt aElementId) const |
|
261 { |
|
262 __ASSERT_ALWAYS((aElementId < ENumElements), Panic(EMTPTypeBoundsError)); |
|
263 |
|
264 return iElementInfo[aElementId]; |
|
265 } |
|
266 |
|
267 void CMTPTypeServicePropDesc::ConstructL( const TUint16 aServicePropCode, const TUint16 aDataType, const TUint8 aGetSet, const TUint8 aFormFlag, const MMTPType* aForm ) |
|
268 { |
|
269 for (TUint i(0); (i < ENumElements); i++) |
|
270 { |
|
271 const TElementInfo& element(iElementInfo[i]); |
|
272 if (ChunkCount() <= element.iChunkId) |
|
273 { |
|
274 MMTPType* chunk(NULL); |
|
275 switch (element.iChunkId) |
|
276 { |
|
277 case EIdFlat1Chunk: |
|
278 iChunkFlat1.OpenL(); |
|
279 chunk = &iChunkFlat1; |
|
280 break; |
|
281 |
|
282 case EIdFormChunk: |
|
283 iChunkForm.SetMeta(aFormFlag, aDataType); |
|
284 if (HasFormField(aFormFlag)) |
|
285 { |
|
286 iChunkForm.OpenL(element.iType); |
|
287 chunk = &iChunkForm; |
|
288 SetExpectedChunkCount(KNumChunksWithForm); |
|
289 } |
|
290 break; |
|
291 |
|
292 default: |
|
293 Panic(EMTPTypeBoundsError); |
|
294 break; |
|
295 } |
|
296 if (chunk) |
|
297 { |
|
298 ChunkAppendL(*chunk); |
|
299 } |
|
300 } |
|
301 } |
|
302 |
|
303 // Set the construction values. |
|
304 SetUint16L( EServicePropertyCode, aServicePropCode ); |
|
305 SetUint16L( EDataType1, aDataType ); |
|
306 SetUint8L( EGetSet1, aGetSet ); |
|
307 SetUint8L(EFormFlag, aFormFlag); |
|
308 |
|
309 if (aForm) |
|
310 { |
|
311 if (!HasFormField(aFormFlag)) |
|
312 { |
|
313 User::Leave(KMTPDataTypeInvalid); |
|
314 } |
|
315 else |
|
316 { |
|
317 SetL(EForm, *aForm); |
|
318 } |
|
319 } |
|
320 } |
|
321 |
|
322 |
|
323 |
|
324 |