320 |
320 |
321 if (iStorageId == KMTPStorageDefault) |
321 if (iStorageId == KMTPStorageDefault) |
322 { |
322 { |
323 iStorageId = iFramework.StorageMgr().DefaultStorageId(); |
323 iStorageId = iFramework.StorageMgr().DefaultStorageId(); |
324 } |
324 } |
325 |
325 |
326 //if the object size is more,then report this error. |
|
327 if (!CanStoreFileL(iStorageId, iObjectSize)) |
|
328 { |
|
329 *ret = EMTPRespCodeStoreFull; |
|
330 } |
|
331 } |
326 } |
332 |
327 |
333 __FLOG(_L8("CMTPImageDpSendObjectInfo::CheckObjectPropListParamsL - Exit")); |
328 __FLOG(_L8("CMTPImageDpSendObjectInfo::CheckObjectPropListParamsL - Exit")); |
334 return (*ret == EMTPRespCodeOK) ? ETrue : EFalse; |
329 return (*ret == EMTPRespCodeOK) ? ETrue : EFalse; |
335 } |
330 } |
513 { |
508 { |
514 __FLOG(_L8("CMTPImageDpSendObjectInfo::ServiceSendObjectL - Entry")); |
509 __FLOG(_L8("CMTPImageDpSendObjectInfo::ServiceSendObjectL - Entry")); |
515 |
510 |
516 iFramework.ObjectMgr().CommitReservedObjectHandleL(*iReceivedObject); |
511 iFramework.ObjectMgr().CommitReservedObjectHandleL(*iReceivedObject); |
517 //prepare for rollback |
512 //prepare for rollback |
518 iRollbackList.Append(RemoveObjectFromDb); |
513 iRollbackList.Append(RemoveObjectFromDb); |
519 |
514 |
520 delete iFileReceived; |
|
521 iFileReceived = NULL; |
|
522 iFileReceived = CMTPTypeFile::NewL(iFramework.Fs(), iFullPath, EFileWrite); |
|
523 iFileReceived->SetSizeL(iObjectSize); |
|
524 |
|
525 //prepare for rollback |
|
526 iRollbackList.Append(RemoveObjectFromFs); |
|
527 ReceiveDataL(*iFileReceived); |
515 ReceiveDataL(*iFileReceived); |
528 |
516 |
529 __FLOG(_L8("CMTPImageDpSendObjectInfo::ServiceSendObjectL - Exit")); |
517 __FLOG(_L8("CMTPImageDpSendObjectInfo::ServiceSendObjectL - Exit")); |
530 return ETrue; |
518 return ETrue; |
531 } |
519 } |
654 if (!result) |
637 if (!result) |
655 { |
638 { |
656 SendResponseL(EMTPRespCodeAccessDenied); |
639 SendResponseL(EMTPRespCodeAccessDenied); |
657 } |
640 } |
658 else |
641 else |
659 { |
642 { |
660 ReserveObjectL(); |
643 TRAPD(err,CreateFsObjectL()); |
661 imageWidth = iObjectInfo->Uint32L(CMTPTypeObjectInfo::EImagePixWidth); |
644 if (err != KErrNone) |
662 imageHeight = iObjectInfo->Uint32L(CMTPTypeObjectInfo::EImagePixHeight); |
645 { |
663 imageBitDepth = iObjectInfo->Uint32L(CMTPTypeObjectInfo::EImageBitDepth); |
646 __FLOG_1(_L8("Fail to create fs object %d"),err); |
664 iReceivedObject->SetUint(CMTPObjectMetaData::EFormatCode, format); |
647 SendResponseL(ErrorToMTPError(err)); |
665 SetPropertiesL(); |
648 Rollback(); |
666 ReturnResponseL(); |
649 result = EFalse; |
|
650 } |
|
651 else |
|
652 { |
|
653 ReserveObjectL(); |
|
654 imageWidth = iObjectInfo->Uint32L(CMTPTypeObjectInfo::EImagePixWidth); |
|
655 imageHeight = iObjectInfo->Uint32L(CMTPTypeObjectInfo::EImagePixHeight); |
|
656 imageBitDepth = iObjectInfo->Uint32L(CMTPTypeObjectInfo::EImageBitDepth); |
|
657 iReceivedObject->SetUint(CMTPObjectMetaData::EFormatCode, format); |
|
658 SetPropertiesL(); |
|
659 ReturnResponseL(); |
|
660 } |
667 } |
661 } |
668 } |
662 } |
669 |
663 |
670 iSuccessful = result; |
664 iSuccessful = result; |
671 __FLOG(_L8("CMTPImageDpSendObjectInfo::DoHandleSendObjectInfoCompleteL - Exit")); |
665 __FLOG(_L8("CMTPImageDpSendObjectInfo::DoHandleSendObjectInfoCompleteL - Exit")); |
717 } |
711 } |
718 } |
712 } |
719 |
713 |
720 if (result) |
714 if (result) |
721 { |
715 { |
722 //the EFormatCode property has been set in ServiceSendObjectPropListL() function |
716 TRAPD(err,CreateFsObjectL()); |
723 ReserveObjectL(); |
717 if (err != KErrNone) |
724 SetPropertiesL(); |
718 { |
725 ReturnResponseL(); |
719 __FLOG_1(_L8("Fail to create fs object %d"),err); |
|
720 SendResponseL(ErrorToMTPError(err)); |
|
721 Rollback(); |
|
722 result = EFalse; |
|
723 } |
|
724 else |
|
725 { |
|
726 //the EFormatCode property has been set in ServiceSendObjectPropListL() function |
|
727 ReserveObjectL(); |
|
728 SetPropertiesL(); |
|
729 ReturnResponseL(); |
|
730 } |
726 } |
731 } |
727 |
732 |
728 iSuccessful = result; |
733 iSuccessful = result; |
729 __FLOG(_L8("CMTPImageDpSendObjectInfo::DoHandleSendObjectPropListCompleteL - Exit")); |
734 __FLOG(_L8("CMTPImageDpSendObjectInfo::DoHandleSendObjectPropListCompleteL - Exit")); |
730 return result; |
735 return result; |
787 { |
792 { |
788 attValue |= KEntryAttReadOnly; |
793 attValue |= KEntryAttReadOnly; |
789 } |
794 } |
790 User::LeaveIfError(iFileReceived->File().SetAtt(attValue, ~attValue)); |
795 User::LeaveIfError(iFileReceived->File().SetAtt(attValue, ~attValue)); |
791 } |
796 } |
792 |
797 TTime modifiedTime; |
793 //update datemodified property. |
798 //update datemodified property. |
794 if(iDateMod != NULL && iDateMod->Length()) |
799 if(iDateMod != NULL && iDateMod->Length()) |
795 { |
800 { |
796 TTime modifiedTime; |
|
797 iObjectPropertyMgr.ConvertMTPTimeStr2TTimeL(*iDateMod, modifiedTime); |
801 iObjectPropertyMgr.ConvertMTPTimeStr2TTimeL(*iDateMod, modifiedTime); |
798 User::LeaveIfError(iFileReceived->File().SetModified(modifiedTime)); |
802 User::LeaveIfError(iFileReceived->File().SetModified(modifiedTime)); |
799 } |
803 } |
|
804 else if(iDateCreated != NULL && iDateCreated->Length()) |
|
805 { |
|
806 iObjectPropertyMgr.ConvertMTPTimeStr2TTimeL(*iDateCreated, modifiedTime); |
|
807 User::LeaveIfError(iFileReceived->File().SetModified(modifiedTime)); |
|
808 } |
800 |
809 |
801 iFramework.RouteRequestUnregisterL(iExpectedSendObjectRequest, iConnection); |
810 iFramework.RouteRequestUnregisterL(iExpectedSendObjectRequest, iConnection); |
802 |
811 |
803 //The MTP spec states that it is not mandatory for SendObjectInfo/SendObjectPropList |
812 //The MTP spec states that it is not mandatory for SendObjectInfo/SendObjectPropList |
804 //to be followed by a SendObject. An object is reserved in the ObjectStore on |
813 //to be followed by a SendObject. An object is reserved in the ObjectStore on |
839 __ASSERT_DEBUG(iReceivedObject, Panic(EMTPImageDpObjectNull)); |
848 __ASSERT_DEBUG(iReceivedObject, Panic(EMTPImageDpObjectNull)); |
840 TRAP_IGNORE(iFramework.ObjectMgr().UnreserveObjectHandleL(*iReceivedObject)); |
849 TRAP_IGNORE(iFramework.ObjectMgr().UnreserveObjectHandleL(*iReceivedObject)); |
841 } |
850 } |
842 |
851 |
843 void CMTPImageDpSendObjectInfo::RemoveObjectFromFs() |
852 void CMTPImageDpSendObjectInfo::RemoveObjectFromFs() |
844 { |
853 { |
|
854 __FLOG(_L8("RemoveObjectFromFs")); |
845 delete iFileReceived; |
855 delete iFileReceived; |
846 iFileReceived = NULL; |
856 iFileReceived = NULL; |
847 TInt err = iFramework.Fs().Delete(iFullPath); |
857 TInt err = iFramework.Fs().Delete(iFullPath); |
848 if (err != KErrNone) |
858 if (err != KErrNone) |
849 { |
859 { |
913 __FLOG_1(_L16("FullPath: %S"), &iFullPath); |
923 __FLOG_1(_L16("FullPath: %S"), &iFullPath); |
914 } |
924 } |
915 |
925 |
916 __FLOG(_L8("CMTPImageDpSendObjectInfo::GetFullPathNameL - Exit")); |
926 __FLOG(_L8("CMTPImageDpSendObjectInfo::GetFullPathNameL - Exit")); |
917 return result; |
927 return result; |
918 } |
|
919 |
|
920 /** |
|
921 Check if we can store the file on the storage |
|
922 @return ETrue if yes, otherwise EFalse |
|
923 */ |
|
924 TBool CMTPImageDpSendObjectInfo::CanStoreFileL(TUint32 aStorageId, TInt64 aObjectSize) const |
|
925 { |
|
926 __FLOG(_L8("CMTPImageDpSendObjectInfo::CanStoreFileL - Entry")); |
|
927 TBool result(ETrue); |
|
928 if (aStorageId == KMTPStorageDefault) |
|
929 { |
|
930 aStorageId = iFramework.StorageMgr().DefaultStorageId(); |
|
931 } |
|
932 |
|
933 TDriveNumber drive(static_cast<TDriveNumber>(iFramework.StorageMgr().DriveNumber(aStorageId))); |
|
934 User::LeaveIfError(drive); |
|
935 TVolumeInfo volumeInfo; |
|
936 User::LeaveIfError(iFramework.Fs().Volume(volumeInfo, drive)); |
|
937 if (volumeInfo.iFree < aObjectSize) |
|
938 { |
|
939 result = EFalse; |
|
940 } |
|
941 __FLOG(_L8("CMTPImageDpSendObjectInfo::CanStoreFileL - Exit")); |
|
942 return result; |
|
943 } |
928 } |
944 |
929 |
945 /** |
930 /** |
946 Check if the file already exists on the storage. |
931 Check if the file already exists on the storage. |
947 @return ETrue if file is exists, otherwise EFalse |
932 @return ETrue if file is exists, otherwise EFalse |
1254 |
1239 |
1255 iRollbackList.Reset(); |
1240 iRollbackList.Reset(); |
1256 |
1241 |
1257 __FLOG(_L8("CMTPImageDpSendObjectInfo::CleanUndoList - Exit")); |
1242 __FLOG(_L8("CMTPImageDpSendObjectInfo::CleanUndoList - Exit")); |
1258 } |
1243 } |
|
1244 |
|
1245 void CMTPImageDpSendObjectInfo::CreateFsObjectL() |
|
1246 { |
|
1247 delete iFileReceived; |
|
1248 iFileReceived = NULL; |
|
1249 //prepare for rollback |
|
1250 iRollbackList.Append(RemoveObjectFromFs); |
|
1251 |
|
1252 iFileReceived = CMTPTypeFile::NewL(iFramework.Fs(), iFullPath, EFileWrite); |
|
1253 iFileReceived->SetSizeL(iObjectSize); |
|
1254 } |
|
1255 |
|
1256 TMTPResponseCode CMTPImageDpSendObjectInfo::ErrorToMTPError(TInt aError) const |
|
1257 { |
|
1258 TMTPResponseCode resp = EMTPRespCodeGeneralError; |
|
1259 |
|
1260 switch (aError) |
|
1261 { |
|
1262 case KErrNone: |
|
1263 resp = EMTPRespCodeOK; |
|
1264 break; |
|
1265 |
|
1266 case KErrAccessDenied: |
|
1267 resp = EMTPRespCodeAccessDenied; |
|
1268 break; |
|
1269 |
|
1270 case KErrDiskFull: |
|
1271 resp = EMTPRespCodeStoreFull; |
|
1272 break; |
|
1273 |
|
1274 default: |
|
1275 break; |
|
1276 } |
|
1277 |
|
1278 return resp; |
|
1279 } |