14 * Description: Implement the operation: SendObjectInfo/SendObjectPropList/SendObject |
14 * Description: Implement the operation: SendObjectInfo/SendObjectPropList/SendObject |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 #include <mtp/mmtpdataproviderframework.h> |
|
20 #include <mtp/mmtpobjectmgr.h> |
19 #include <mtp/mmtpobjectmgr.h> |
21 #include <mtp/cmtptypestring.h> |
20 #include <mtp/cmtptypestring.h> |
22 #include <mtp/cmtptypeobjectinfo.h> |
21 #include <mtp/cmtptypeobjectinfo.h> |
23 #include <mtp/cmtptypefile.h> |
22 #include <mtp/cmtptypefile.h> |
24 #include <mtp/mmtpstoragemgr.h> |
23 #include <mtp/mmtpstoragemgr.h> |
25 #include <mtp/cmtpobjectmetadata.h> |
|
26 #include <bautils.h> |
24 #include <bautils.h> |
27 #include <mtp/cmtptypeobjectproplist.h> |
25 #include <mtp/cmtptypeobjectproplist.h> |
28 |
26 |
29 #include "csendobject.h" |
27 #include "csendobject.h" |
30 #include "mmmtpdpconfig.h" |
28 #include "mmmtpdpconfig.h" |
579 { |
574 { |
580 PRINT( _L( "MM MTP => CSendObject::DoHandleResponsePhaseObjectL" ) ); |
575 PRINT( _L( "MM MTP => CSendObject::DoHandleResponsePhaseObjectL" ) ); |
581 |
576 |
582 TBool result = ETrue; |
577 TBool result = ETrue; |
583 |
578 |
584 TEntry fileEntry; |
|
585 User::LeaveIfError( iFs.Entry( iFullPath, fileEntry ) ); |
|
586 if ( fileEntry.FileSize() != iObjectSize ) |
|
587 { |
|
588 iFs.Delete( iFullPath ); |
|
589 iObjectMgr.UnreserveObjectHandleL( *iReceivedObjectInfo ); |
|
590 TMTPResponseCode responseCode = EMTPRespCodeObjectTooLarge; |
|
591 if ( fileEntry.FileSize() < iObjectSize ) |
|
592 { |
|
593 responseCode = EMTPRespCodeIncompleteTransfer; |
|
594 } |
|
595 SendResponseL( responseCode ); |
|
596 result = EFalse; |
|
597 } |
|
598 |
|
599 // SendObject is cancelled or connection is dropped. |
579 // SendObject is cancelled or connection is dropped. |
600 if ( result && iCancelled ) |
580 if ( iCancelled ) |
601 { |
581 { |
|
582 // In SendObject response phase, unregister is not necessary. |
|
583 // But there's no harm, still keep it here. |
602 iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest, |
584 iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest, |
603 iConnection ); |
585 iConnection ); |
|
586 |
604 Rollback(); |
587 Rollback(); |
605 SendResponseL( EMTPRespCodeTransactionCancelled ); |
588 SendResponseL( EMTPRespCodeTransactionCancelled ); |
606 } |
589 } |
607 else if ( result && !iCancelled ) |
590 else |
608 { |
591 { |
609 if ( iObjectSize > 0 ) // media file |
592 TEntry fileEntry; |
610 { |
593 User::LeaveIfError( iFs.Entry( iFullPath, fileEntry ) ); |
611 TRAPD( err, AddMediaToStoreL() ); |
594 |
612 PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL err = %d" ), err ); |
595 if ( fileEntry.FileSize() != iObjectSize ) |
613 |
596 { |
614 if ( ( iPreviousOperation == EMTPOpCodeSendObjectPropList ) |
597 Rollback(); |
615 && ( err == KErrNone ) ) |
598 TMTPResponseCode responseCode = EMTPRespCodeObjectTooLarge; |
616 { |
599 if ( fileEntry.FileSize() < iObjectSize ) |
617 // Only leave when getting proplist element from data received by fw. |
600 { |
618 // It should not happen after ReceiveDataL in which construction of proplist already succeed. |
601 responseCode = EMTPRespCodeIncompleteTransfer; |
619 SetObjectPropListL(); |
602 } |
620 } |
603 SendResponseL( responseCode ); |
621 |
604 result = EFalse; |
622 // Commits into MTP data object enumeration store the object handle and |
605 } |
623 // storage space previously reserved for the specified object. |
606 else |
624 iFramework.ObjectMgr().CommitReservedObjectHandleL( *iReceivedObjectInfo ); |
607 { |
625 } |
608 if ( iObjectSize > 0 ) // media file |
626 |
609 { |
627 // Commit object to MTP data store |
610 TRAPD( err, AddMediaToStoreL() ); |
628 iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest, |
611 PRINT1( _L( "MM MTP <> CSendObject::DoHandleResponsePhaseObjectL err = %d" ), err ); |
629 iConnection ); |
612 |
630 |
613 if ( ( iPreviousOperation == EMTPOpCodeSendObjectPropList ) |
631 SendResponseL( EMTPRespCodeOK ); |
614 && ( err == KErrNone ) ) |
|
615 { |
|
616 // Only leave when getting proplist element from data received by fw. |
|
617 // It should not happen after ReceiveDataL in which construction of proplist already succeed. |
|
618 SetObjectPropListL(); |
|
619 } |
|
620 |
|
621 // Commits into MTP data object enumeration store the object handle and |
|
622 // storage space previously reserved for the specified object. |
|
623 iFramework.ObjectMgr().CommitReservedObjectHandleL( *iReceivedObjectInfo ); |
|
624 } |
|
625 |
|
626 // In SendObject response phase, unregister is not necessary. |
|
627 // But there's no harm, still keep it here. |
|
628 iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest, |
|
629 iConnection ); |
|
630 |
|
631 SendResponseL( EMTPRespCodeOK ); |
|
632 } |
632 } |
633 } |
633 |
634 |
634 PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL result = %d" ), result ); |
635 PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL result = %d" ), result ); |
635 |
636 |
636 return result; |
637 return result; |
938 // Already done in AddMediaToStore, it's not necessary to set it again. |
939 // Already done in AddMediaToStore, it's not necessary to set it again. |
939 // SetProtectionStatus(); |
940 // SetProtectionStatus(); |
940 break; |
941 break; |
941 |
942 |
942 case EMTPObjectPropCodeName: |
943 case EMTPObjectPropCodeName: |
|
944 case EMTPObjectPropCodeAlbumArtist: |
943 { |
945 { |
944 CMTPTypeString* stringData = CMTPTypeString::NewLC( element.StringL( CMTPTypeObjectPropListElement::EValue ) );// + stringData |
946 CMTPTypeString* stringData = CMTPTypeString::NewLC( element.StringL( CMTPTypeObjectPropListElement::EValue ) );// + stringData |
945 |
947 |
946 responseCode = iDpConfig.PropSettingUtility()->SetMetaDataToWrapper( iDpConfig, |
948 responseCode = iDpConfig.PropSettingUtility()->SetMetaDataToWrapper( iDpConfig, |
947 propertyCode, |
949 propertyCode, |
1076 TBool CSendObject::GetFullPathNameL( const TDesC& aFileName ) |
1078 TBool CSendObject::GetFullPathNameL( const TDesC& aFileName ) |
1077 { |
1079 { |
1078 PRINT1( _L("MM MTP => CSendObject::GetFullPathNameL aFileName = %S"), &aFileName ); |
1080 PRINT1( _L("MM MTP => CSendObject::GetFullPathNameL aFileName = %S"), &aFileName ); |
1079 |
1081 |
1080 TBool result( EFalse ); |
1082 TBool result( EFalse ); |
|
1083 |
1081 if ( aFileName.Length() > 0 ) |
1084 if ( aFileName.Length() > 0 ) |
1082 { |
1085 { |
1083 iFullPath.Zero(); |
1086 iFullPath.Zero(); |
1084 iFullPath.Append( *iParentSuid ); |
1087 iFullPath.Append( *iParentSuid ); |
1085 if ( ( iFullPath.Length() + aFileName.Length() ) < KMaxFileName ) |
1088 |
|
1089 // TODO: need to be done in derived class |
|
1090 // Only add extension for alb to pass winlogo test cases |
|
1091 TInt length = iFullPath.Length() + aFileName.Length(); |
|
1092 |
|
1093 TParsePtrC parser( aFileName ); |
|
1094 TBool isAlbWithoutExt = |
|
1095 ( ( iObjectFormat == EMTPFormatCodeAbstractAudioAlbum ) && ( !parser.ExtPresent() ) ); |
|
1096 if ( isAlbWithoutExt ) |
|
1097 length += KTxtExtensionALB().Length(); |
|
1098 |
|
1099 if ( length < KMaxFileName ) |
1086 { |
1100 { |
1087 iFullPath.Append( aFileName ); |
1101 iFullPath.Append( aFileName ); |
|
1102 if ( isAlbWithoutExt ) |
|
1103 iFullPath.Append( KTxtExtensionALB ); |
1088 PRINT1( _L( "MM MTP <> CSendObject::GetFullPathNameL iFullPath = %S" ), &iFullPath ); |
1104 PRINT1( _L( "MM MTP <> CSendObject::GetFullPathNameL iFullPath = %S" ), &iFullPath ); |
1089 result = iFramework.Fs().IsValidName( iFullPath ); |
1105 result = iFramework.Fs().IsValidName( iFullPath ); |
1090 } |
1106 } |
1091 } |
1107 } |
|
1108 |
1092 if ( result && ( iObjectFormat != MmMtpDpUtility::FormatFromFilename( iFullPath ) ) ) |
1109 if ( result && ( iObjectFormat != MmMtpDpUtility::FormatFromFilename( iFullPath ) ) ) |
1093 { |
1110 { |
1094 PRINT2( _L( "MM MTP <> %S does not match 0x%x" ), &iFullPath, iObjectFormat ); |
1111 PRINT2( _L( "MM MTP <> %S does not match 0x%x" ), &iFullPath, iObjectFormat ); |
1095 result = EFalse; |
1112 result = EFalse; |
1096 } |
1113 } |
1274 // SetProtectionStatus here make sure no matter the previous operation is SendObjectInfo |
1291 // SetProtectionStatus here make sure no matter the previous operation is SendObjectInfo |
1275 // or SendObjectPropList |
1292 // or SendObjectPropList |
1276 // Might need to set dateadded and datemodify for further extension. |
1293 // Might need to set dateadded and datemodify for further extension. |
1277 SetProtectionStatus(); |
1294 SetProtectionStatus(); |
1278 |
1295 |
1279 TBool isVideo = EFalse; |
|
1280 TMmMtpSubFormatCode subFormatCode = EMTPSubFormatCodeUnknown; |
|
1281 switch ( iObjectFormat ) |
|
1282 { |
|
1283 case EMTPFormatCode3GPContainer: |
|
1284 case EMTPFormatCodeMP4Container: |
|
1285 case EMTPFormatCodeASF: |
|
1286 { |
|
1287 if ( MmMtpDpUtility::IsVideo( iFullPath ) ) |
|
1288 { |
|
1289 subFormatCode = EMTPSubFormatCodeVideo; |
|
1290 isVideo = ETrue; |
|
1291 } |
|
1292 else |
|
1293 { |
|
1294 subFormatCode = EMTPSubFormatCodeAudio; |
|
1295 isVideo = EFalse; |
|
1296 } |
|
1297 |
|
1298 iReceivedObjectInfo->SetUint( CMTPObjectMetaData::EFormatSubCode, |
|
1299 ( TUint ) subFormatCode ); |
|
1300 } |
|
1301 break; |
|
1302 |
|
1303 // put all just video format codes here |
|
1304 case EMTPFormatCodeWMV: |
|
1305 { |
|
1306 isVideo = ETrue; |
|
1307 } |
|
1308 break; |
|
1309 |
|
1310 default: |
|
1311 PRINT( _L( "MM MTP <> CSendObject::DoHandleResponsePhaseObjectL default" ) ); |
|
1312 break; |
|
1313 } |
|
1314 |
|
1315 iDpConfig.GetWrapperL().SetStorageRootL( iFullPath ); |
1296 iDpConfig.GetWrapperL().SetStorageRootL( iFullPath ); |
1316 PRINT1( _L( "MM MTP <> CSendObject::AddMediaToStoreL iFullPath = %S" ), &iFullPath ); |
1297 PRINT1( _L( "MM MTP <> CSendObject::AddMediaToStoreL iFullPath = %S" ), &iFullPath ); |
1317 iDpConfig.GetWrapperL().AddObjectL( iFullPath, iObjectFormat, subFormatCode ); |
1298 iDpConfig.GetWrapperL().AddObjectL( *iReceivedObjectInfo ); |
1318 |
1299 |
1319 if ( isVideo ) |
1300 iDpConfig.GetWrapperL().SetImageObjPropL( *iReceivedObjectInfo, iWidth, iHeight ); |
1320 { |
|
1321 iDpConfig.GetWrapperL().SetImageObjPropL( iFullPath, iWidth, iHeight ); |
|
1322 } |
|
1323 |
1301 |
1324 PRINT( _L( "MM MTP <= CSendObject::AddMediaToStoreL" ) ); |
1302 PRINT( _L( "MM MTP <= CSendObject::AddMediaToStoreL" ) ); |
1325 } |
1303 } |
1326 |
1304 |
1327 // ----------------------------------------------------------------------------- |
1305 // ----------------------------------------------------------------------------- |
1342 // ----------------------------------------------------------------------------- |
1320 // ----------------------------------------------------------------------------- |
1343 // |
1321 // |
1344 void CSendObject::Rollback() |
1322 void CSendObject::Rollback() |
1345 { |
1323 { |
1346 // Delete this object from file system. |
1324 // Delete this object from file system. |
1347 if ( iProgress == ESendObjectInProgress ) |
1325 if ( iProgress == ESendObjectInProgress |
|
1326 || iProgress == EObjectInfoSucceed |
|
1327 ||iProgress == EObjectInfoFail ) |
1348 { |
1328 { |
1349 PRINT1( _L( "MM MTP <> CSendObject::Rollback ROLLBACK_FILE %S" ), &iFullPath ); |
1329 PRINT1( _L( "MM MTP <> CSendObject::Rollback ROLLBACK_FILE %S" ), &iFullPath ); |
1350 // Close the interrupted transfer file by delete iFileReceived object |
1330 // Close the interrupted transfer file by delete iFileReceived object |
1351 delete iFileReceived; |
1331 delete iFileReceived; |
1352 iFileReceived = NULL; |
1332 iFileReceived = NULL; |