|
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 #include <f32file.h> |
|
17 #include <mtp/tmtptyperequest.h> |
|
18 #include <mtp/mmtpdataproviderframework.h> |
|
19 #include <mtp/mtpprotocolconstants.h> |
|
20 #include <mtp/mmtpobjectmgr.h> |
|
21 #include <mtp/cmtptypeobjectpropdesc.h> |
|
22 |
|
23 #include <mtp/cmtptypestring.h> |
|
24 #include "cmtpgetobjectpropdesc.h" |
|
25 #include "mtpdpconst.h" |
|
26 #include "mtpdppanic.h" |
|
27 |
|
28 |
|
29 _LIT(KMtpObjDescObjFileName, "[a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~][a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~ ]{0, 7}\\.[[a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~][a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~ ]{0, 2}]?"); |
|
30 |
|
31 /** |
|
32 Two-phase construction method |
|
33 @param aPlugin The data provider plugin |
|
34 @param aFramework The data provider framework |
|
35 @param aConnection The connection from which the request comes |
|
36 @return a pointer to the created request processor object |
|
37 */ |
|
38 EXPORT_C MMTPRequestProcessor* CMTPGetObjectPropDesc::NewL( |
|
39 MMTPDataProviderFramework& aFramework, |
|
40 MMTPConnection& aConnection) |
|
41 { |
|
42 CMTPGetObjectPropDesc* self = new (ELeave) CMTPGetObjectPropDesc(aFramework, aConnection); |
|
43 CleanupStack::PushL(self); |
|
44 self->ConstructL(); |
|
45 CleanupStack::Pop(self); |
|
46 return self; |
|
47 } |
|
48 |
|
49 /** |
|
50 Destructor |
|
51 */ |
|
52 EXPORT_C CMTPGetObjectPropDesc::~CMTPGetObjectPropDesc() |
|
53 { |
|
54 delete iObjectProperty; |
|
55 } |
|
56 |
|
57 /** |
|
58 Standard c++ constructor |
|
59 */ |
|
60 CMTPGetObjectPropDesc::CMTPGetObjectPropDesc( |
|
61 MMTPDataProviderFramework& aFramework, |
|
62 MMTPConnection& aConnection) |
|
63 :CMTPRequestProcessor(aFramework, aConnection, 0, NULL) |
|
64 { |
|
65 } |
|
66 |
|
67 /** |
|
68 check format code and property code |
|
69 */ |
|
70 TMTPResponseCode CMTPGetObjectPropDesc::CheckRequestL() |
|
71 { |
|
72 TMTPResponseCode response = CMTPRequestProcessor::CheckRequestL(); |
|
73 TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
74 TUint32 formatCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2); |
|
75 |
|
76 /** |
|
77 * [SP-Format-0x3002]Special processing for PictBridge DP which own 6 dps file with format 0x3002, |
|
78 * but it does not really own the format 0x3002. |
|
79 * |
|
80 * Make the same behavior betwen 0x3000 and 0x3002. |
|
81 */ |
|
82 if((formatCode != EMTPFormatCodeUndefined) && (formatCode != EMTPFormatCodeAssociation) &&( EMTPFormatCodeScript != formatCode )) |
|
83 { |
|
84 response = EMTPRespCodeInvalidObjectFormatCode; |
|
85 } |
|
86 else |
|
87 { |
|
88 if(propCode != EMTPObjectPropCodeAssociationType && propCode != EMTPObjectPropCodeAssociationDesc) |
|
89 { |
|
90 const TInt count = sizeof(KMTPDpSupportedProperties) / sizeof(TUint16); |
|
91 TInt i = 0; |
|
92 for(i = 0; i < count; i++) |
|
93 { |
|
94 if(KMTPDpSupportedProperties[i] == propCode) |
|
95 { |
|
96 break; |
|
97 } |
|
98 } |
|
99 if(i == count) |
|
100 { |
|
101 response = EMTPRespCodeInvalidObjectPropCode; |
|
102 } |
|
103 } |
|
104 else |
|
105 { |
|
106 if(formatCode != EMTPFormatCodeAssociation) |
|
107 response = EMTPRespCodeInvalidObjectPropCode; |
|
108 } |
|
109 } |
|
110 return response; |
|
111 } |
|
112 |
|
113 /** |
|
114 GetObjectPropDesc request handler |
|
115 */ |
|
116 void CMTPGetObjectPropDesc::ServiceL() |
|
117 { |
|
118 delete iObjectProperty; |
|
119 iObjectProperty = NULL; |
|
120 |
|
121 TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
122 switch(propCode) |
|
123 { |
|
124 case EMTPObjectPropCodeStorageID: |
|
125 ServiceStorageIdL(); |
|
126 break; |
|
127 case EMTPObjectPropCodeObjectFormat: |
|
128 ServiceObjectFormatL(); |
|
129 break; |
|
130 case EMTPObjectPropCodeProtectionStatus: |
|
131 ServiceProtectionStatusL(); |
|
132 break; |
|
133 case EMTPObjectPropCodeObjectSize: |
|
134 ServiceObjectSizeL(); |
|
135 break; |
|
136 case EMTPObjectPropCodeAssociationType: |
|
137 ServiceAssociationTypeL(); |
|
138 break; |
|
139 case EMTPObjectPropCodeAssociationDesc: |
|
140 ServiceAssociationDescL(); |
|
141 break; |
|
142 case EMTPObjectPropCodeObjectFileName: |
|
143 ServiceFileNameL(); |
|
144 break; |
|
145 case EMTPObjectPropCodeDateModified: |
|
146 ServiceDateModifiedL(); |
|
147 break; |
|
148 case EMTPObjectPropCodeParentObject: |
|
149 ServiceParentObjectL(); |
|
150 break; |
|
151 case EMTPObjectPropCodePersistentUniqueObjectIdentifier: |
|
152 ServicePuidL(); |
|
153 break; |
|
154 case EMTPObjectPropCodeName: |
|
155 ServiceNameL(); |
|
156 break; |
|
157 case EMTPObjectPropCodeNonConsumable: |
|
158 ServiceNonConsumableL(); |
|
159 break; |
|
160 default: |
|
161 Panic(EMTPDpUnsupportedProperty); |
|
162 } |
|
163 __ASSERT_DEBUG(iObjectProperty, Panic(EMTPDpObjectPropertyNull)); |
|
164 iObjectProperty->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode,GetPropertyGroupNumber(propCode)); |
|
165 SendDataL(*iObjectProperty); |
|
166 } |
|
167 |
|
168 |
|
169 /** |
|
170 Second-phase construction |
|
171 */ |
|
172 void CMTPGetObjectPropDesc::ConstructL() |
|
173 { |
|
174 } |
|
175 |
|
176 |
|
177 void CMTPGetObjectPropDesc::ServiceStorageIdL() |
|
178 { |
|
179 iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeStorageID); |
|
180 } |
|
181 |
|
182 void CMTPGetObjectPropDesc::ServiceObjectFormatL() |
|
183 { |
|
184 iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeObjectFormat); |
|
185 } |
|
186 |
|
187 void CMTPGetObjectPropDesc::ServiceProtectionStatusL() |
|
188 { |
|
189 CMTPTypeObjectPropDescEnumerationForm* expectedForm = CMTPTypeObjectPropDescEnumerationForm::NewL(EMTPTypeUINT16); |
|
190 CleanupStack::PushL(expectedForm); |
|
191 //Currently, we only support EMTPProtectionNoProtection and EMTPProtectionReadOnly |
|
192 // TUint16 values[] = {EMTPProtectionNoProtection, EMTPProtectionReadOnly, EMTPProtectionReadOnlyData, EMTPProtectionNonTransferable}; |
|
193 TUint16 values[] = {EMTPProtectionNoProtection, EMTPProtectionReadOnly}; |
|
194 TUint numValues((sizeof(values) / sizeof(values[0]))); |
|
195 for (TUint i = 0; i < numValues; i++) |
|
196 { |
|
197 TMTPTypeUint16 data(values[i]); |
|
198 expectedForm->AppendSupportedValueL(data); |
|
199 } |
|
200 iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeProtectionStatus, *expectedForm); |
|
201 CleanupStack::PopAndDestroy(expectedForm); |
|
202 } |
|
203 |
|
204 void CMTPGetObjectPropDesc::ServiceObjectSizeL() |
|
205 { |
|
206 iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeObjectSize); |
|
207 } |
|
208 |
|
209 void CMTPGetObjectPropDesc::ServiceAssociationTypeL() |
|
210 { |
|
211 CMTPTypeObjectPropDescEnumerationForm* expectedForm = CMTPTypeObjectPropDescEnumerationForm::NewL(EMTPTypeUINT16); |
|
212 CleanupStack::PushL(expectedForm); |
|
213 |
|
214 const TUint16 KMtpValues[] = { EMTPAssociationTypeGenericFolder }; |
|
215 const TUint KNumMtpValues(sizeof(KMtpValues) / sizeof(KMtpValues[0])); |
|
216 const TUint16 KPtpValues[] = {EMTPAssociationTypeUndefined, EMTPAssociationTypeGenericFolder, EMTPAssociationTypeAlbum, EMTPAssociationTypeTimeSequence, EMTPAssociationTypeHorizontalPanoramic, EMTPAssociationTypeVerticalPanoramic, EMTPAssociationType2DPanoramic,EMTPAssociationTypeAncillaryData}; |
|
217 const TUint KNumPtpValues(sizeof(KPtpValues) / sizeof(KPtpValues[0])); |
|
218 |
|
219 TUint numValues(KNumMtpValues); |
|
220 const TUint16* values = KMtpValues; |
|
221 if (EModeMTP != iFramework.Mode()) |
|
222 { |
|
223 numValues = KNumPtpValues; |
|
224 values = KPtpValues; |
|
225 } |
|
226 |
|
227 for (TUint i = 0; i < numValues; i++) |
|
228 { |
|
229 TMTPTypeUint16 data(values[i]); |
|
230 expectedForm->AppendSupportedValueL(data); |
|
231 } |
|
232 |
|
233 iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeAssociationType, *expectedForm); |
|
234 CleanupStack::PopAndDestroy(expectedForm); |
|
235 } |
|
236 |
|
237 void CMTPGetObjectPropDesc::ServiceAssociationDescL() |
|
238 { |
|
239 iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeAssociationDesc); |
|
240 } |
|
241 |
|
242 void CMTPGetObjectPropDesc::ServiceFileNameL() |
|
243 { |
|
244 CMTPTypeString* form = CMTPTypeString::NewLC( KMtpObjDescObjFileName ); // + form |
|
245 // Althrough iObjectProperty is released in ServiceL(), |
|
246 // release it here maybe a more safer way |
|
247 if ( iObjectProperty != NULL ) |
|
248 { |
|
249 delete iObjectProperty; |
|
250 iObjectProperty = NULL; |
|
251 } |
|
252 |
|
253 iObjectProperty = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeObjectFileName, |
|
254 CMTPTypeObjectPropDesc::ERegularExpressionForm, |
|
255 form ); |
|
256 |
|
257 CleanupStack::PopAndDestroy( form ); // - form |
|
258 |
|
259 } |
|
260 |
|
261 void CMTPGetObjectPropDesc::ServiceDateModifiedL() |
|
262 { |
|
263 iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeDateModified); |
|
264 } |
|
265 |
|
266 void CMTPGetObjectPropDesc::ServiceParentObjectL() |
|
267 { |
|
268 iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeParentObject); |
|
269 } |
|
270 |
|
271 void CMTPGetObjectPropDesc::ServicePuidL() |
|
272 { |
|
273 iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodePersistentUniqueObjectIdentifier); |
|
274 } |
|
275 |
|
276 void CMTPGetObjectPropDesc::ServiceNameL() |
|
277 { |
|
278 iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeName); |
|
279 } |
|
280 |
|
281 void CMTPGetObjectPropDesc::ServiceNonConsumableL() |
|
282 { |
|
283 CMTPTypeObjectPropDescEnumerationForm* expectedForm = CMTPTypeObjectPropDescEnumerationForm::NewL(EMTPTypeUINT8); |
|
284 CleanupStack::PushL(expectedForm); |
|
285 TUint8 values[] = {0,1}; |
|
286 TUint numValues((sizeof(values) / sizeof(values[0]))); |
|
287 for (TUint i = 0; i < numValues; i++) |
|
288 { |
|
289 TMTPTypeUint8 data(values[i]); |
|
290 expectedForm->AppendSupportedValueL(data); |
|
291 } |
|
292 iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeNonConsumable, *expectedForm); |
|
293 CleanupStack::PopAndDestroy(expectedForm); |
|
294 } |
|
295 |
|
296 |
|
297 |
|
298 TUint16 CMTPGetObjectPropDesc::GetPropertyGroupNumber(const TUint16 aPropCode) const |
|
299 { |
|
300 |
|
301 // begin from group 1, since group 0 is not used |
|
302 for(int group = 1; group <= KMTPDpPropertyGroupNumber; group++) |
|
303 { |
|
304 for( int propCodeIndex = 0 ; propCodeIndex < KMTPDpPropertyNumber ; propCodeIndex++) |
|
305 { |
|
306 if(KMTPDpPropertyGroups[group][propCodeIndex] == aPropCode) |
|
307 { |
|
308 return group; |
|
309 } |
|
310 } |
|
311 } |
|
312 |
|
313 // if not foud, the group number should be 0. |
|
314 return 0; |
|
315 } |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |