|
1 /* |
|
2 * Copyright (c) 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 "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: Implement operation: GetObjectPropDesc |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <mtp/cmtptypeobjectpropdesc.h> |
|
20 #include <mtp/cmtptypestring.h> |
|
21 |
|
22 #include "cgetobjectpropdesc.h" |
|
23 #include "tmmmtpdppanic.h" |
|
24 #include "mmmtpdplogger.h" |
|
25 #include "tobjectdescription.h" |
|
26 #include "mmmtpdpconfig.h" |
|
27 |
|
28 _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}]?" ); |
|
29 // RegEx is [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 // CGetObjectPropDesc::~CGetObjectPropDesc |
|
33 // Destructor |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 EXPORT_C CGetObjectPropDesc::~CGetObjectPropDesc() |
|
37 { |
|
38 delete iObjectProperty; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CGetObjectPropDesc::CGetObjectPropDesc |
|
43 // Standard c++ constructor |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 EXPORT_C CGetObjectPropDesc::CGetObjectPropDesc( MMTPDataProviderFramework& aFramework, |
|
47 MMTPConnection& aConnection, |
|
48 MMmMtpDpConfig& aDpConfig ) : |
|
49 CRequestProcessor( aFramework, aConnection, 0, NULL ), |
|
50 iObjectProperty( NULL ), |
|
51 iDpConfig( aDpConfig ) |
|
52 { |
|
53 PRINT( _L( "Operation: GetObjectPropDesc(0x9802)" ) ); |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CGetObjectPropDesc::ConstructL |
|
58 // Second phase constructor |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 EXPORT_C void CGetObjectPropDesc::ConstructL() |
|
62 { |
|
63 |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CGetObjectPropList::CheckRequestL |
|
68 // Verify the reqeust and returns it |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 EXPORT_C TMTPResponseCode CGetObjectPropDesc::CheckRequestL() |
|
72 { |
|
73 TMTPResponseCode response = CRequestProcessor::CheckRequestL(); |
|
74 |
|
75 if ( response == EMTPRespCodeOK ) |
|
76 { |
|
77 response = CheckFormatL(); |
|
78 } |
|
79 |
|
80 if ( response == EMTPRespCodeOK ) |
|
81 { |
|
82 response = CheckPropCodeL(); |
|
83 } |
|
84 |
|
85 PRINT1( _L("MM MTP <= CGetObjectPropDesc::CheckRequestL response = 0x%x"), response ); |
|
86 return response; |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CGetObjectPropDesc::ServiceL |
|
91 // GetObjectPropDesc request handler |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 EXPORT_C void CGetObjectPropDesc::ServiceL() |
|
95 { |
|
96 PRINT( _L( "MM MTP => CGetObjectPropDesc::ServiceL" ) ); |
|
97 delete iObjectProperty; |
|
98 iObjectProperty = NULL; |
|
99 |
|
100 TUint32 propCode = Request().Uint32( TMTPTypeRequest::ERequestParameter1 ); |
|
101 iFormatCode = Request().Uint32( TMTPTypeRequest::ERequestParameter2 ); |
|
102 PRINT2( _L( "MM MTP <> CGetObjectPropDesc::ServiceL propCode = 0x%x, iFormatCode = 0x%x" ), |
|
103 propCode, |
|
104 iFormatCode ); |
|
105 |
|
106 CMTPTypeObjectPropDesc::TPropertyInfo propertyInfo; |
|
107 |
|
108 /* Create new PropDesc object to return to device |
|
109 m - signals only limited supported values - hence these requests require the expected form |
|
110 variable to be passed into the NewL contstuctor as well */ |
|
111 switch ( propCode ) |
|
112 { |
|
113 case EMTPObjectPropCodeStorageID: // Storage ID |
|
114 case EMTPObjectPropCodeObjectFormat: // Format Code |
|
115 case EMTPObjectPropCodeObjectSize: // Object Size |
|
116 case EMTPObjectPropCodeParentObject: // Parent Object |
|
117 case EMTPObjectPropCodePersistentUniqueObjectIdentifier: // Unique Object Identifier |
|
118 case EMTPObjectPropCodeName: // Name |
|
119 case EMTPObjectPropCodeDateAdded: // Date Added |
|
120 iObjectProperty = CMTPTypeObjectPropDesc::NewL( propCode ); |
|
121 break; |
|
122 |
|
123 // Protection Status (m) |
|
124 case EMTPObjectPropCodeProtectionStatus: |
|
125 ServiceProtectionStatusL(); |
|
126 break; |
|
127 |
|
128 // FileName |
|
129 case EMTPObjectPropCodeObjectFileName: |
|
130 ServiceFileNameL(); |
|
131 break; |
|
132 |
|
133 // Consumable (m) |
|
134 case EMTPObjectPropCodeNonConsumable: |
|
135 ServiceNonConsumableL(); |
|
136 break; |
|
137 |
|
138 case EMTPObjectPropCodeDateModified: // Date Modified |
|
139 case EMTPObjectPropCodeDateCreated: // Date Created |
|
140 propertyInfo.iDataType = EMTPTypeString; |
|
141 propertyInfo.iFormFlag = CMTPTypeObjectPropDesc::EDateTimeForm; |
|
142 propertyInfo.iGetSet = CMTPTypeObjectPropDesc::EReadOnly; |
|
143 iObjectProperty = CMTPTypeObjectPropDesc::NewL( propCode, propertyInfo, NULL); |
|
144 break; |
|
145 |
|
146 // Error - Should be caught by CheckRequestL |
|
147 default: |
|
148 ServiceSpecificObjectPropertyL( propCode ); |
|
149 break; |
|
150 } |
|
151 |
|
152 // Set group code |
|
153 TUint32 groupCode = GetGroupCode( propCode ); |
|
154 PRINT1( _L("MM MTP <> CGetObjectPropDesc::ServiceL, groupCode = 0x%x"), groupCode ); |
|
155 iObjectProperty->SetUint32L( CMTPTypeObjectPropDesc::EGroupCode, groupCode ); |
|
156 |
|
157 __ASSERT_DEBUG( iObjectProperty, Panic( EMmMTPDpObjectPropertyNull ) ); |
|
158 |
|
159 SendDataL( *iObjectProperty ); |
|
160 |
|
161 PRINT( _L( "MM MTP <= CGetObjectPropDesc::ServiceL" ) ); |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CGetObjectPropDesc::ServiceProtectionStatusL |
|
166 // Create list of possible protection status and create new ObjectPropDesc |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void CGetObjectPropDesc::ServiceProtectionStatusL() |
|
170 { |
|
171 CMTPTypeObjectPropDescEnumerationForm* expectedForm = |
|
172 CMTPTypeObjectPropDescEnumerationForm::NewL( EMTPTypeUINT16 ); |
|
173 CleanupStack::PushL( expectedForm ); // + expectedForm |
|
174 |
|
175 TUint16 values[] = |
|
176 { |
|
177 EMTPProtectionNoProtection, |
|
178 EMTPProtectionReadOnly |
|
179 }; |
|
180 |
|
181 TInt numValues = sizeof ( values ) / sizeof ( values[0] ) ; |
|
182 for ( TInt i = 0; i < numValues; i++ ) |
|
183 { |
|
184 TMTPTypeUint16 data( values[i] ); |
|
185 expectedForm->AppendSupportedValueL( data ); |
|
186 } |
|
187 |
|
188 // Althrough iObjectProperty is released in ServiceL(), |
|
189 // release it here maybe a more safer way :) |
|
190 if ( iObjectProperty != NULL ) |
|
191 { |
|
192 delete iObjectProperty; |
|
193 iObjectProperty = NULL; |
|
194 } |
|
195 |
|
196 iObjectProperty = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeProtectionStatus, *expectedForm ); |
|
197 CleanupStack::PopAndDestroy( expectedForm ); // - expectedForm |
|
198 } |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CGetObjectPropDesc::ServiceFileNameL() |
|
202 // Create Regular expression for a file name and create new ObjectPropDesc |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void CGetObjectPropDesc::ServiceFileNameL() |
|
206 { |
|
207 CMTPTypeString* form = CMTPTypeString::NewLC( KMtpObjDescObjFileName ); // + form |
|
208 |
|
209 // Althrough iObjectProperty is released in ServiceL(), |
|
210 // release it here maybe a more safer way |
|
211 if ( iObjectProperty != NULL ) |
|
212 { |
|
213 delete iObjectProperty; |
|
214 iObjectProperty = NULL; |
|
215 } |
|
216 |
|
217 iObjectProperty = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeObjectFileName, |
|
218 CMTPTypeObjectPropDesc::ERegularExpressionForm, |
|
219 form ); |
|
220 |
|
221 CleanupStack::PopAndDestroy( form ); // - form |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CGetObjectPropDesc::ServiceNonConsumableL |
|
226 // Create list of possible nonConsumable values and create new ObjectPropDesc |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 void CGetObjectPropDesc::ServiceNonConsumableL() |
|
230 { |
|
231 CMTPTypeObjectPropDescEnumerationForm* expectedForm = |
|
232 CMTPTypeObjectPropDescEnumerationForm::NewL( EMTPTypeUINT8 ); |
|
233 CleanupStack::PushL( expectedForm ); // + expectedForm |
|
234 TUint8 values[] = |
|
235 { |
|
236 EMTPConsumable, |
|
237 EMTPNonConsumable |
|
238 }; |
|
239 |
|
240 TInt numValues = sizeof ( values ) / sizeof ( values[0] ); |
|
241 for ( TInt i = 0; i < numValues; i++ ) |
|
242 { |
|
243 TMTPTypeUint8 data( values[i] ); |
|
244 expectedForm->AppendSupportedValueL( data ); |
|
245 } |
|
246 |
|
247 // Althrough iObjectProperty is released in ServiceL(), |
|
248 // release it here maybe a more safer way :) |
|
249 if ( iObjectProperty != NULL ) |
|
250 { |
|
251 delete iObjectProperty; |
|
252 iObjectProperty = NULL; |
|
253 } |
|
254 |
|
255 CMTPTypeObjectPropDesc::TPropertyInfo propertyInfo; |
|
256 propertyInfo.iDataType = EMTPTypeUINT8; |
|
257 propertyInfo.iFormFlag = CMTPTypeObjectPropDesc::EEnumerationForm; |
|
258 propertyInfo.iGetSet = CMTPTypeObjectPropDesc::EReadOnly; |
|
259 iObjectProperty = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeNonConsumable, |
|
260 propertyInfo, |
|
261 expectedForm ); |
|
262 CleanupStack::PopAndDestroy( expectedForm ); // - expectedForm |
|
263 } |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // CGetObjectPropList::CheckFormatL |
|
267 // Ensures the object format operation parameter is valid |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 TMTPResponseCode CGetObjectPropDesc::CheckFormatL() const |
|
271 { |
|
272 TMTPResponseCode response = EMTPRespCodeOK; |
|
273 |
|
274 TUint32 formatCode = Request().Uint32( TMTPTypeRequest::ERequestParameter2 ); |
|
275 PRINT1( _L( "MM MTP <> CGetObjectPropDesc::CheckFormatL formatCode = 0x%x" ), formatCode ); |
|
276 |
|
277 if( formatCode != 0) |
|
278 { |
|
279 response = EMTPRespCodeInvalidObjectFormatCode; |
|
280 |
|
281 const RArray<TUint>* format = iDpConfig.GetSupportedFormat(); |
|
282 TInt count = format->Count(); |
|
283 |
|
284 for ( TInt i = 0; i < count; i++ ) |
|
285 { |
|
286 if ( formatCode == (*format)[i] ) |
|
287 { |
|
288 response = EMTPRespCodeOK; |
|
289 break; |
|
290 } |
|
291 } |
|
292 } |
|
293 |
|
294 return response; |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CGetObjectPropDesc::CheckPropCodeL |
|
299 // Ensures the object prop code operation parameter is valid |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 TMTPResponseCode CGetObjectPropDesc::CheckPropCodeL() const |
|
303 { |
|
304 TMTPResponseCode response = EMTPRespCodeOK; |
|
305 |
|
306 TUint32 propCode = Request().Uint32( TMTPTypeRequest::ERequestParameter1 ); |
|
307 PRINT1( _L( "MM MTP <> CGetObjectPropDesc::CheckPropCode, propCode = 0x%x" ), propCode ); |
|
308 |
|
309 if ( propCode == 0 ) |
|
310 { |
|
311 // A propCode of 0 means specification by group (which is not supported) |
|
312 response = EMTPRespCodeSpecificationByGroupUnsupported; |
|
313 } |
|
314 else |
|
315 { |
|
316 TUint32 formatCode = Request().Uint32( TMTPTypeRequest::ERequestParameter2 ); |
|
317 |
|
318 const RArray<TUint>* properties = NULL; |
|
319 if ( formatCode == KMTPFormatsAll ) |
|
320 properties= iDpConfig.GetAllSupportedProperties(); |
|
321 else |
|
322 properties = iDpConfig.GetSupportedPropertiesL( formatCode ); |
|
323 |
|
324 const TInt count = properties->Count(); |
|
325 TInt i = 0; |
|
326 for( i = 0; i < count; i++ ) |
|
327 { |
|
328 if ( (*properties)[i] == propCode ) |
|
329 { |
|
330 break; |
|
331 } |
|
332 } |
|
333 |
|
334 if ( i == count ) |
|
335 { |
|
336 response = EMTPRespCodeInvalidObjectPropCode; |
|
337 } |
|
338 } |
|
339 |
|
340 return response; |
|
341 } |
|
342 |
|
343 TUint32 CGetObjectPropDesc::GetGroupCode( TUint16 aPropCode ) |
|
344 { |
|
345 TInt count = sizeof( KPropGroupMapTable ); |
|
346 // TODO: if need to refine the search approach to improve performance |
|
347 for( TInt i = 0; i < count; i++ ) |
|
348 { |
|
349 if ( aPropCode == KPropGroupMapTable[i].iPropCode ) |
|
350 return KPropGroupMapTable[i].iGroupCode; |
|
351 } |
|
352 return EGroupCodeNotDefined; |
|
353 } |
|
354 |
|
355 // end of file |