|
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 opeartion SetObjectPropValue |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <mtp/mmtpdataproviderframework.h> |
|
20 #include <mtp/cmtptypestring.h> |
|
21 #include <mtp/cmtptypearray.h> |
|
22 #include <mtp/mmtpobjectmgr.h> |
|
23 |
|
24 #include "csetobjectpropvalue.h" |
|
25 #include "mmmtpdputility.h" |
|
26 #include "cmmmtpdpmetadataaccesswrapper.h" |
|
27 #include "tmmmtpdppanic.h" |
|
28 #include "mmmtpdplogger.h" |
|
29 #include "mmmtpdpconfig.h" |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // Verification data for the SetObjectPropValue request |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 const TMTPRequestElementInfo KMTPSetObjectPropValuePolicy[] = |
|
36 { |
|
37 { |
|
38 TMTPTypeRequest::ERequestParameter1, |
|
39 EMTPElementTypeObjectHandle, |
|
40 EMTPElementAttrWrite, |
|
41 0, |
|
42 0, |
|
43 0 |
|
44 }, |
|
45 }; |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CSetObjectPropValue::NewL |
|
49 // Two-phase construction method |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 //EXPORT_C MMmRequestProcessor* CSetObjectPropValue::NewL( MMTPDataProviderFramework& aFramework, |
|
53 // MMTPConnection& aConnection, |
|
54 // CMmMtpDpMetadataAccessWrapper& aWrapper ) |
|
55 // { |
|
56 // CSetObjectPropValue* self = new (ELeave) CSetObjectPropValue( aFramework, aConnection, aWrapper ); |
|
57 // |
|
58 // return self; |
|
59 // } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CSetObjectPropValue::CSetObjectPropValue |
|
63 // Standard c++ constructor |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 EXPORT_C CSetObjectPropValue::CSetObjectPropValue( |
|
67 MMTPDataProviderFramework& aFramework, |
|
68 MMTPConnection& aConnection, |
|
69 MMmMtpDpConfig& aDpConfig ) : |
|
70 CRequestProcessor( aFramework, |
|
71 aConnection, |
|
72 sizeof(KMTPSetObjectPropValuePolicy) / sizeof(TMTPRequestElementInfo), |
|
73 KMTPSetObjectPropValuePolicy ), |
|
74 iObjectMgr( aFramework.ObjectMgr() ), |
|
75 iDpConfig( aDpConfig ) |
|
76 { |
|
77 SetPSStatus(); |
|
78 PRINT( _L( "Operation: SetObjectPropValue(0x9804)" ) ); |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CSetObjectPropValue::~CSetObjectPropValue |
|
83 // Destructor |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 EXPORT_C CSetObjectPropValue::~CSetObjectPropValue() |
|
87 { |
|
88 delete iMTPTypeString; |
|
89 delete iMTPTypeArray; |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CSetObjectPropValue::IsPropCodeReadonly |
|
94 // A helper function of CheckRequestL. |
|
95 // To check whether the object property code is readonly. |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 TBool CSetObjectPropValue::IsPropCodeReadonly( TUint16 aPropCode ) |
|
99 { |
|
100 TBool returnCode = EFalse; |
|
101 |
|
102 switch (aPropCode) |
|
103 { |
|
104 case EMTPObjectPropCodeStorageID: |
|
105 case EMTPObjectPropCodeObjectFormat: |
|
106 case EMTPObjectPropCodeProtectionStatus: |
|
107 case EMTPObjectPropCodeObjectSize: |
|
108 case EMTPObjectPropCodeParentObject: |
|
109 case EMTPObjectPropCodePersistentUniqueObjectIdentifier: |
|
110 case EMTPObjectPropCodeNonConsumable: |
|
111 case EMTPObjectPropCodeDateAdded: |
|
112 case EMTPObjectPropCodeDateCreated: |
|
113 case EMTPObjectPropCodeDateModified: |
|
114 //case EMTPObjectPropCodeVideoBitRate: // move to specific dp |
|
115 returnCode = ETrue; |
|
116 break; |
|
117 |
|
118 default: |
|
119 returnCode = IsSpecificPropCodeReadOnly(aPropCode); |
|
120 break; |
|
121 } |
|
122 |
|
123 return returnCode; |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CSetObjectPropValue::CheckRequestL |
|
128 // Verify the reqeust |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 EXPORT_C TMTPResponseCode CSetObjectPropValue::CheckRequestL() |
|
132 { |
|
133 PRINT( _L( "MM MTP => CSetObjectPropValue::CheckRequestL" ) ); |
|
134 |
|
135 TMTPResponseCode result = CRequestProcessor::CheckRequestL(); |
|
136 |
|
137 // Check if property is supported |
|
138 if ( result == EMTPRespCodeOK ) |
|
139 { |
|
140 iPropCode = Request().Uint32( TMTPTypeRequest::ERequestParameter2 ); |
|
141 PRINT1( _L( "MM MTP <> CSetObjectPropValue::CheckRequestL iPropCode = 0x%x" ), iPropCode ); |
|
142 result = EMTPRespCodeInvalidObjectPropCode; |
|
143 |
|
144 TUint32 objectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 ); |
|
145 CMTPObjectMetaData* objectInfo = iRequestChecker->GetObjectInfo( objectHandle ); |
|
146 |
|
147 if (!objectInfo) |
|
148 { |
|
149 PRINT(_L("MM MTP <> CGetObjectPropValue::CheckRequestL, objectInfo is NULL")); |
|
150 return EMTPRespCodeInvalidObjectHandle; |
|
151 } |
|
152 |
|
153 TFileName fileName = objectInfo->DesC(CMTPObjectMetaData::ESuid); |
|
154 TUint32 formatCode = objectInfo->Uint(CMTPObjectMetaData::EFormatCode); |
|
155 |
|
156 PRINT3( _L( "MM MTP <> CGetObjectPropValue::CheckRequestL, handle = 0x%x, filename = %S, formatCode = 0x%x" ), |
|
157 objectHandle, |
|
158 &fileName, |
|
159 formatCode ); |
|
160 const RArray<TUint>* properties = iDpConfig.GetSupportedPropertiesL( formatCode ); |
|
161 TInt count = properties->Count(); |
|
162 for ( TInt i = 0; i < count; i++ ) |
|
163 { |
|
164 // Object property code is supported, but can not be set which is read only. |
|
165 if ( (*properties)[i] == iPropCode |
|
166 && IsPropCodeReadonly( iPropCode ) ) |
|
167 { |
|
168 result = EMTPRespCodeAccessDenied; |
|
169 break; |
|
170 } |
|
171 // Object property code is supported and can be set. |
|
172 else if ( iPropCode == (*properties)[i] ) |
|
173 { |
|
174 result = EMTPRespCodeOK; |
|
175 break; |
|
176 } |
|
177 } // end of for |
|
178 } |
|
179 |
|
180 PRINT( _L( "MM MTP <= CSetObjectPropValue::CheckRequestL" ) ); |
|
181 return result; |
|
182 } |
|
183 |
|
184 EXPORT_C TBool CSetObjectPropValue::HasDataphase() const |
|
185 { |
|
186 return ETrue; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CSetObjectPropValue::ServiceL |
|
191 // SetObjectPropValue request handler |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 EXPORT_C void CSetObjectPropValue::ServiceL() |
|
195 { |
|
196 PRINT( _L( "MM MTP => CSetObjectPropValue::ServiceL" ) ); |
|
197 __ASSERT_DEBUG( iRequestChecker, Panic( EMmMTPDpRequestCheckNull ) ); |
|
198 TUint32 handle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 ); |
|
199 PRINT1( _L( "MM MTP <> CSetObjectPropValue::ServiceL handle = 0x%x" ), handle ); |
|
200 |
|
201 iObjectInfo = iRequestChecker->GetObjectInfo( handle ); |
|
202 |
|
203 switch ( iPropCode ) |
|
204 { |
|
205 // Access not allowed on these properties: (so send error) |
|
206 case EMTPObjectPropCodeStorageID: |
|
207 case EMTPObjectPropCodeObjectFormat: |
|
208 case EMTPObjectPropCodeProtectionStatus: |
|
209 case EMTPObjectPropCodeObjectSize: |
|
210 case EMTPObjectPropCodeParentObject: |
|
211 case EMTPObjectPropCodePersistentUniqueObjectIdentifier: |
|
212 case EMTPObjectPropCodeDateAdded: // 0xDC4E |
|
213 case EMTPObjectPropCodeDateCreated: // Date Created(0xDC08) |
|
214 case EMTPObjectPropCodeDateModified: // Modified Date(0xDC09) |
|
215 case EMTPObjectPropCodeNonConsumable: // Non Consumable(0xDC4F) |
|
216 case EMTPObjectPropCodeVideoBitRate: // 0xDE9C |
|
217 { |
|
218 SendResponseL( EMTPRespCodeAccessDenied ); |
|
219 } |
|
220 break; |
|
221 |
|
222 // Get Data for String objects |
|
223 case EMTPObjectPropCodeObjectFileName: // 0xDC07 |
|
224 case EMTPObjectPropCodeName: // 0xDC44 |
|
225 { |
|
226 delete iMTPTypeString; |
|
227 iMTPTypeString = NULL; |
|
228 iMTPTypeString = CMTPTypeString::NewL(); |
|
229 ReceiveDataL( *iMTPTypeString ); |
|
230 } |
|
231 break; |
|
232 |
|
233 default: |
|
234 { |
|
235 ReceiveDataSpecificObjectPropertyL( iPropCode ); |
|
236 } |
|
237 break; |
|
238 } |
|
239 PRINT( _L( "MM MTP <= CSetObjectPropValue::ServiceL" ) ); |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CSetObjectPropValue::DoHandleResponsePhaseL |
|
244 // Edit the file to update the prop value |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 EXPORT_C TBool CSetObjectPropValue::DoHandleResponsePhaseL() |
|
248 { |
|
249 PRINT( _L( "MM MTP => CSetObjectPropValue::DoHandleResponsePhaseL" ) ); |
|
250 __ASSERT_DEBUG( iObjectInfo, Panic( EMmMTPDpObjectNull ) ); |
|
251 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
252 |
|
253 switch ( iPropCode ) |
|
254 { |
|
255 case EMTPObjectPropCodeObjectFileName: |
|
256 { |
|
257 TPtrC suid( iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) ); |
|
258 TBuf<KMaxFileName> newSuid( iMTPTypeString->StringChars() ); |
|
259 PRINT2( _L( "MM MTP <> old name = %S, new name = %S" ), &suid, &newSuid ); |
|
260 TInt err = KErrNone; |
|
261 err = MmMtpDpUtility::UpdateObjectFileName( iFramework.Fs(), |
|
262 suid, |
|
263 newSuid ); |
|
264 PRINT1( _L( "MM MTP <> Update object file name err = %d" ), err ); |
|
265 if ( KErrOverflow == err ) // full path name is too long |
|
266 { |
|
267 responseCode = EMTPRespCodeInvalidDataset; |
|
268 } |
|
269 else if ( ( KErrNone == err ) || ( KErrAlreadyExists == err ) ) |
|
270 { |
|
271 TRAP( err, iDpConfig.GetWrapperL().RenameObjectL( suid, newSuid ) ); //Update MPX DB |
|
272 PRINT1( _L( "MM MTP <> Rename MPX object file name err = %d" ), err ); |
|
273 // it is ok if file is not found in DB, following S60 solution |
|
274 if ( KErrNotFound == err ) |
|
275 { |
|
276 TRAP( err, iDpConfig.GetWrapperL().AddObjectL( newSuid ) ); |
|
277 PRINT1( _L( "MM MTP <> Add MPX object file name err = %d" ), err ); |
|
278 } |
|
279 |
|
280 if ( KErrNone == err ) |
|
281 { |
|
282 iObjectInfo->SetDesCL( CMTPObjectMetaData::ESuid, newSuid ); |
|
283 iFramework.ObjectMgr().ModifyObjectL( *iObjectInfo ); |
|
284 } |
|
285 else |
|
286 { |
|
287 responseCode = EMTPRespCodeGeneralError; |
|
288 } |
|
289 } |
|
290 } |
|
291 break; |
|
292 |
|
293 case EMTPObjectPropCodeName: // 0xDC44 |
|
294 { |
|
295 responseCode = ServiceMetaDataToWrapperL( iPropCode, |
|
296 *iMTPTypeString, |
|
297 *iObjectInfo ); |
|
298 } |
|
299 break; |
|
300 |
|
301 default: |
|
302 { |
|
303 responseCode = ServiceSpecificObjectPropertyL( iPropCode ); |
|
304 } |
|
305 break; |
|
306 } |
|
307 |
|
308 SendResponseL( responseCode ); |
|
309 PRINT1( _L( "MM MTP <= CSetObjectPropValue::DoHandleResponsePhaseL responseCode = 0x%x" ), responseCode ); |
|
310 |
|
311 return EFalse; |
|
312 } |
|
313 |
|
314 // ----------------------------------------------------------------------------- |
|
315 // CSetObjectPropValue::ServiceMetaDataToWrapperL |
|
316 // |
|
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 EXPORT_C TMTPResponseCode CSetObjectPropValue::ServiceMetaDataToWrapperL( const TUint16 aPropCode, |
|
320 MMTPType& aNewData, |
|
321 const CMTPObjectMetaData& aObjectMetaData ) |
|
322 { |
|
323 TMTPResponseCode resCode = EMTPRespCodeOK; |
|
324 |
|
325 TRAPD( err, iDpConfig.GetWrapperL().SetObjectMetadataValueL( aPropCode, |
|
326 aNewData, |
|
327 aObjectMetaData ) ); |
|
328 |
|
329 PRINT1( _L( "MM MTP <> CSetObjectPropValue::ServiceMetaDataToWrapperL err = %d" ), err); |
|
330 |
|
331 if ( err == KErrNone ) |
|
332 { |
|
333 resCode = EMTPRespCodeOK; |
|
334 } |
|
335 else if ( err == KErrTooBig ) |
|
336 // according to the codes of S60 |
|
337 { |
|
338 resCode = EMTPRespCodeInvalidDataset; |
|
339 } |
|
340 else if ( err == KErrPermissionDenied ) |
|
341 { |
|
342 resCode = EMTPRespCodeAccessDenied; |
|
343 } |
|
344 else if ( err == KErrNotFound ) |
|
345 { |
|
346 // TMTPFormatCode formatCode = |
|
347 // MmMtpDpUtility::FormatFromFilename( aObjectMetaData.DesC( CMTPObjectMetaData::ESuid ) ); |
|
348 if( MmMtpDpUtility::HasMetadata( aObjectMetaData.Uint( CMTPObjectMetaData::EFormatCode ) ) ) |
|
349 SendResponseL( EMTPRespCodeAccessDenied ); |
|
350 else |
|
351 SendDataL( aNewData ); |
|
352 } |
|
353 else |
|
354 { |
|
355 resCode = EMTPRespCodeGeneralError; |
|
356 } |
|
357 |
|
358 PRINT1( _L( "MM MTP <> CSetObjectPropValue::ServiceMetaDataToWrapperL resCode = 0x%x" ), resCode ); |
|
359 |
|
360 return resCode; |
|
361 } |
|
362 |
|
363 // end of file |