mtpdataproviders/mtpimagedp/src/cmtpimagedpmoveobject.cpp
changeset 47 63cf70d3ecd8
parent 33 883e91c086aa
equal deleted inserted replaced
44:a5deb6b96675 47:63cf70d3ecd8
    34 #include "mtpimagedppanic.h"
    34 #include "mtpimagedppanic.h"
    35 #include "cmtpimagedpobjectpropertymgr.h"
    35 #include "cmtpimagedpobjectpropertymgr.h"
    36 #include "mtpimagedputilits.h"
    36 #include "mtpimagedputilits.h"
    37 #include "cmtpimagedpthumbnailcreator.h"
    37 #include "cmtpimagedpthumbnailcreator.h"
    38 #include "cmtpimagedp.h"
    38 #include "cmtpimagedp.h"
    39 
    39 #include "OstTraceDefinitions.h"
    40 __FLOG_STMT(_LIT8(KComponent,"MoveObject");)
    40 #ifdef OST_TRACE_COMPILER_IN_USE
       
    41 #include "cmtpimagedpmoveobjectTraces.h"
       
    42 #endif
       
    43 
    41 
    44 
    42 /**
    45 /**
    43 Verification data for the MoveObject request
    46 Verification data for the MoveObject request
    44 */    
    47 */    
    45 const TMTPRequestElementInfo KMTPMoveObjectPolicy[] = 
    48 const TMTPRequestElementInfo KMTPMoveObjectPolicy[] = 
    67 /**
    70 /**
    68 Destructor
    71 Destructor
    69 */	
    72 */	
    70 CMTPImageDpMoveObject::~CMTPImageDpMoveObject()
    73 CMTPImageDpMoveObject::~CMTPImageDpMoveObject()
    71     {
    74     {
    72     __FLOG(_L8(">> CMTPImageDpMoveObject::~CMTPImageDpMoveObject")); 
    75     OstTraceFunctionEntry0( CMTPIMAGEDPMOVEOBJECT_CMTPIMAGEDPMOVEOBJECT_ENTRY );
    73     delete iDest;
    76     delete iDest;
    74     delete iFileMan;
    77     delete iFileMan;
    75     delete iObjectInfo;
    78     delete iObjectInfo;
    76     __FLOG(_L8("<< CMTPImageDpMoveObject::~CMTPImageDpMoveObject"));
    79     OstTraceFunctionExit0( CMTPIMAGEDPMOVEOBJECT_CMTPIMAGEDPMOVEOBJECT_EXIT );
    77     __FLOG_CLOSE;
       
    78     }
    80     }
    79 
    81 
    80 /**
    82 /**
    81 Standard c++ constructor
    83 Standard c++ constructor
    82 */	
    84 */	
    83 CMTPImageDpMoveObject::CMTPImageDpMoveObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection,CMTPImageDataProvider& aDataProvider) :
    85 CMTPImageDpMoveObject::CMTPImageDpMoveObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection,CMTPImageDataProvider& aDataProvider) :
    84     CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPMoveObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPMoveObjectPolicy),
    86     CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPMoveObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPMoveObjectPolicy),
    85     iDataProvider(aDataProvider)
    87     iDataProvider(aDataProvider)
    86     {
    88     {
    87     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    88     }
    89     }
    89 	
    90 	
    90 /**
    91 /**
    91  Second phase constructor
    92  Second phase constructor
    92 */
    93 */
    93 void CMTPImageDpMoveObject::ConstructL()
    94 void CMTPImageDpMoveObject::ConstructL()
    94     {
    95     {
    95     __FLOG(_L8(">> CMTPImageDpMoveObject::ConstructL")); 
    96     OstTraceFunctionEntry0( CMTPIMAGEDPMOVEOBJECT_CONSTRUCTL_ENTRY );
    96     iFileMan = CFileMan::NewL(iFramework.Fs());
    97     iFileMan = CFileMan::NewL(iFramework.Fs());
    97     iObjectInfo = CMTPObjectMetaData::NewL();
    98     iObjectInfo = CMTPObjectMetaData::NewL();
    98     __FLOG(_L8("<< CMTPImageDpMoveObject::ConstructL")); 
    99     OstTraceFunctionExit0( CMTPIMAGEDPMOVEOBJECT_CONSTRUCTL_EXIT );
    99     }
   100     }
   100 
   101 
   101 TMTPResponseCode CMTPImageDpMoveObject::CheckRequestL()
   102 TMTPResponseCode CMTPImageDpMoveObject::CheckRequestL()
   102     {
   103     {
   103     __FLOG(_L8(">> CMTPImageDpCopyObject::CheckRequestL"));
   104     OstTraceFunctionEntry0( CMTPIMAGEDPMOVEOBJECT_CHECKREQUESTL_ENTRY );
   104     TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL();
   105     TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL();
   105     if (EMTPRespCodeOK == responseCode)
   106     if (EMTPRespCodeOK == responseCode)
   106         {
   107         {
   107         TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
   108         TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
   108         // Check whether object handle is valid
   109         // Check whether object handle is valid
   111     else if(EMTPRespCodeInvalidObjectHandle == responseCode) //we only check the parent handle
   112     else if(EMTPRespCodeInvalidObjectHandle == responseCode) //we only check the parent handle
   112         {
   113         {
   113         responseCode = EMTPRespCodeInvalidParentObject;
   114         responseCode = EMTPRespCodeInvalidParentObject;
   114         }
   115         }
   115     
   116     
   116     __FLOG_VA((_L8("CheckRequestL - Exit with responseCode = 0x%04X"), responseCode));
   117     OstTrace1( TRACE_NORMAL, CMTPIMAGEDPMOVEOBJECT_CHECKREQUESTL, 
   117     __FLOG(_L8("<< CMTPImageDpCopyObject::CheckRequestL"));
   118             "CheckRequestL - Exit with responseCode = 0x%04X", responseCode );
       
   119     OstTraceFunctionExit0( CMTPIMAGEDPMOVEOBJECT_CHECKREQUESTL_EXIT );
   118     return responseCode;
   120     return responseCode;
   119     }
   121     }
   120 
   122 
   121 /**
   123 /**
   122 MoveObject request handler
   124 MoveObject request handler
   123 */		
   125 */		
   124 void CMTPImageDpMoveObject::ServiceL()
   126 void CMTPImageDpMoveObject::ServiceL()
   125     {
   127     {
   126     __FLOG(_L8(">> CMTPImageDpMoveObject::ServiceL"));
   128     OstTraceFunctionEntry0( CMTPIMAGEDPMOVEOBJECT_SERVICEL_ENTRY );
   127     
   129     
   128     TMTPResponseCode ret = MoveObjectL();
   130     TMTPResponseCode ret = MoveObjectL();
   129     SendResponseL(ret);
   131     SendResponseL(ret);
   130     
   132 
   131     __FLOG(_L8("<< CMTPImageDpMoveObject::ServiceL")); 
   133     OstTraceFunctionExit0( CMTPIMAGEDPMOVEOBJECT_SERVICEL_EXIT );
   132     }
   134     }
   133 
   135 
   134 /**
   136 /**
   135 A helper function of MoveObjectL.
   137 A helper function of MoveObjectL.
   136 @param aNewFileName the new file name after the object is moved.
   138 @param aNewFileName the new file name after the object is moved.
   137 */
   139 */
   138 TMTPResponseCode CMTPImageDpMoveObject::MoveFileL(const TDesC& aOldFileName, const TDesC& aNewFileName)	
   140 TMTPResponseCode CMTPImageDpMoveObject::MoveFileL(const TDesC& aOldFileName, const TDesC& aNewFileName)	
   139     {
   141     {
   140     __FLOG(_L8(">> CMTPImageDpMoveObject::MoveFileL"));
   142     OstTraceFunctionEntry0( CMTPIMAGEDPMOVEOBJECT_MOVEFILEL_ENTRY );
   141     
   143     
   142     TMTPResponseCode responseCode = EMTPRespCodeOK;    
   144     TMTPResponseCode responseCode = EMTPRespCodeOK;    
   143     /**
   145     /**
   144      * File system process the move operation has two different ways:
   146      * File system process the move operation has two different ways:
   145      * 1. move object between the same storage.
   147      * 1. move object between the same storage.
   171     TUint oldParentHandle = iObjectInfo->Uint(CMTPObjectMetaData::EParentHandle);    
   173     TUint oldParentHandle = iObjectInfo->Uint(CMTPObjectMetaData::EParentHandle);    
   172     iObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, aNewFileName);
   174     iObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, aNewFileName);
   173     iObjectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId);
   175     iObjectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId);
   174     iObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, iNewParentHandle);
   176     iObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, iNewParentHandle);
   175     iFramework.ObjectMgr().ModifyObjectL(*iObjectInfo);
   177     iFramework.ObjectMgr().ModifyObjectL(*iObjectInfo);
   176     __FLOG_VA((_L16("CMTPImageDpMoveObject::MoveFileL - Update object info:%S"), &aNewFileName));
   178     OstTraceExt1( TRACE_NORMAL, DUP2_CMTPIMAGEDPMOVEOBJECT_MOVEFILEL, 
       
   179             "CMTPImageDpMoveObject::MoveFileL - Update object info:%S", aNewFileName );
   177     
   180     
   178     TInt ret = MoveImageFile(aOldFileName, *iDest);
   181     TInt ret = MoveImageFile(aOldFileName, *iDest);
   179     if (ret != KErrNone)
   182     if (ret != KErrNone)
   180         {
   183         {
   181         //rollback
   184         //rollback
   182         __FLOG_VA((_L16("CMTPImageDpMoveObject::MoveFileL - Rollback")));
   185         OstTrace0( TRACE_NORMAL, DUP1_CMTPIMAGEDPMOVEOBJECT_MOVEFILEL, "CMTPImageDpMoveObject::MoveFileL - Rollback" );
   183         iObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, aOldFileName);
   186         iObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, aOldFileName);
   184         iObjectInfo->SetUint(CMTPObjectMetaData::EStorageId, oldStoradId);
   187         iObjectInfo->SetUint(CMTPObjectMetaData::EStorageId, oldStoradId);
   185         iObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, oldParentHandle);
   188         iObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, oldParentHandle);
   186         iFramework.ObjectMgr().ModifyObjectL(*iObjectInfo);       
   189         iFramework.ObjectMgr().ModifyObjectL(*iObjectInfo);       
   187         responseCode = EMTPRespCodeGeneralError;        
   190         responseCode = EMTPRespCodeGeneralError;        
   188         }
   191         }
   189     __FLOG_VA((_L8("CMTPImageDpMoveObject::MoveFileL - MoveImageFile:%d"), ret));
   192     OstTrace1( TRACE_NORMAL, CMTPIMAGEDPMOVEOBJECT_MOVEFILEL, "- MoveImageFile:%d", ret );
   190     
   193 
   191     __FLOG(_L8("<< CMTPImageDpMoveObject::MoveFileL")); 	
   194     OstTraceFunctionExit0( CMTPIMAGEDPMOVEOBJECT_MOVEFILEL_EXIT );
   192     return responseCode;
   195     return responseCode;
   193     }
   196     }
   194 /**
   197 /**
   195 move object operations
   198 move object operations
   196 @return A valid MTP response code.
   199 @return A valid MTP response code.
   197 */
   200 */
   198 TMTPResponseCode CMTPImageDpMoveObject::MoveObjectL()
   201 TMTPResponseCode CMTPImageDpMoveObject::MoveObjectL()
   199     {
   202     {
   200     __FLOG(_L8(">> CMTPImageDpMoveObject::MoveObjectL"));
   203     OstTraceFunctionEntry0( CMTPIMAGEDPMOVEOBJECT_MOVEOBJECTL_ENTRY );
   201     TMTPResponseCode responseCode = EMTPRespCodeOK;
   204     TMTPResponseCode responseCode = EMTPRespCodeOK;
   202     GetParametersL();
   205     GetParametersL();
   203     RBuf newObjectName;
   206     RBuf newObjectName;
   204     newObjectName.CreateL(KMaxFileName);
   207     newObjectName.CreateL(KMaxFileName);
   205     newObjectName.CleanupClosePushL();
   208     newObjectName.CleanupClosePushL();
   219     if(responseCode == EMTPRespCodeOK)
   222     if(responseCode == EMTPRespCodeOK)
   220         {
   223         {
   221         responseCode = MoveFileL(oldFileName, newObjectName);
   224         responseCode = MoveFileL(oldFileName, newObjectName);
   222         }
   225         }
   223     CleanupStack::PopAndDestroy(); // newObjectName.
   226     CleanupStack::PopAndDestroy(); // newObjectName.
   224     __FLOG(_L8("<< CMTPImageDpMoveObject::MoveObjectL")); 	
   227     OstTraceFunctionExit0( CMTPIMAGEDPMOVEOBJECT_MOVEOBJECTL_EXIT );
   225     return responseCode;
   228     return responseCode;
   226     }
   229     }
   227 
   230 
   228 /**
   231 /**
   229 Retrieve the parameters of the request
   232 Retrieve the parameters of the request
   230 */	
   233 */	
   231 void CMTPImageDpMoveObject::GetParametersL()
   234 void CMTPImageDpMoveObject::GetParametersL()
   232     {
   235     {
   233     __FLOG(_L8(">> CMTPImageDpMoveObject::GetParametersL"));
   236     OstTraceFunctionEntry0( CMTPIMAGEDPMOVEOBJECT_GETPARAMETERSL_ENTRY );
   234     __ASSERT_DEBUG(iRequestChecker, Panic(EMTPImageDpRequestCheckNull));
   237     __ASSERT_DEBUG(iRequestChecker, Panic(EMTPImageDpRequestCheckNull));
   235     
   238     
   236     TUint32 objectHandle  = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
   239     TUint32 objectHandle  = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
   237     iStorageId = Request().Uint32(TMTPTypeRequest::ERequestParameter2);
   240     iStorageId = Request().Uint32(TMTPTypeRequest::ERequestParameter2);
   238     iNewParentHandle  = Request().Uint32(TMTPTypeRequest::ERequestParameter3);
   241     iNewParentHandle  = Request().Uint32(TMTPTypeRequest::ERequestParameter3);
   247         __ASSERT_DEBUG(parentObjectInfo, Panic(EMTPImageDpObjectNull));
   250         __ASSERT_DEBUG(parentObjectInfo, Panic(EMTPImageDpObjectNull));
   248         delete iDest;
   251         delete iDest;
   249         iDest = NULL;
   252         iDest = NULL;
   250         iDest = parentObjectInfo->DesC(CMTPObjectMetaData::ESuid).AllocL();
   253         iDest = parentObjectInfo->DesC(CMTPObjectMetaData::ESuid).AllocL();
   251         }
   254         }
   252     __FLOG(_L8("<< CMTPImageDpMoveObject::GetParametersL"));
   255     OstTraceFunctionExit0( CMTPIMAGEDPMOVEOBJECT_GETPARAMETERSL_EXIT );
   253     }
   256     }
   254     
   257     
   255 /**
   258 /**
   256 Get a default parent object, ff the request does not specify a parent object, 
   259 Get a default parent object, ff the request does not specify a parent object, 
   257 */
   260 */
   258 void CMTPImageDpMoveObject::SetDefaultParentObjectL()
   261 void CMTPImageDpMoveObject::SetDefaultParentObjectL()
   259     {
   262     {
   260     __FLOG(_L8(">> CMTPImageDpMoveObject::SetDefaultParentObjectL"));  
   263     OstTraceFunctionEntry0( CMTPIMAGEDPMOVEOBJECT_SETDEFAULTPARENTOBJECTL_ENTRY );
   261     const CMTPStorageMetaData& storage = iFramework.StorageMgr().StorageL(iStorageId);
   264     const CMTPStorageMetaData& storage = iFramework.StorageMgr().StorageL(iStorageId);
   262     delete iDest;
   265     delete iDest;
   263     iDest = NULL;
   266     iDest = NULL;
   264     iDest = storage.DesC(CMTPStorageMetaData::EStorageSuid).AllocL();
   267     iDest = storage.DesC(CMTPStorageMetaData::EStorageSuid).AllocL();
   265     iNewParentHandle = KMTPHandleNoParent;
   268     iNewParentHandle = KMTPHandleNoParent;
   266     __FLOG(_L8("<< CMTPImageDpMoveObject::SetDefaultParentObjectL"));  
   269     OstTraceFunctionExit0( CMTPIMAGEDPMOVEOBJECT_SETDEFAULTPARENTOBJECTL_EXIT );
   267     }
   270     }
   268 
   271 
   269 /**
   272 /**
   270 Check if we can move the file to the new location
   273 Check if we can move the file to the new location
   271 */
   274 */
   272 TMTPResponseCode CMTPImageDpMoveObject::CanMoveObjectL(const TDesC& aOldName, const TDesC& aNewName) const
   275 TMTPResponseCode CMTPImageDpMoveObject::CanMoveObjectL(const TDesC& aOldName, const TDesC& aNewName) const
   273     {
   276     {
   274     __FLOG(_L8(">> CMTPImageDpMoveObject::CanMoveObjectL"));     
   277     OstTraceFunctionEntry0( CMTPIMAGEDPMOVEOBJECT_CANMOVEOBJECTL_ENTRY );   
   275     TMTPResponseCode result = EMTPRespCodeOK;
   278     TMTPResponseCode result = EMTPRespCodeOK;
   276 
   279 
   277     TEntry fileEntry;
   280     TEntry fileEntry;
   278     User::LeaveIfError(iFramework.Fs().Entry(aOldName, fileEntry));
   281     LEAVEIFERROR(iFramework.Fs().Entry(aOldName, fileEntry),
       
   282             OstTraceExt2( TRACE_ERROR, CMTPIMAGEDPMOVEOBJECT_CANMOVEOBJECTL, 
       
   283                     "Gets the entry details for %S failed! error code %d", aOldName, munged_err ));
   279     TDriveNumber drive(static_cast<TDriveNumber>(iFramework.StorageMgr().DriveNumber(iStorageId)));
   284     TDriveNumber drive(static_cast<TDriveNumber>(iFramework.StorageMgr().DriveNumber(iStorageId)));
   280     User::LeaveIfError(drive);
   285     LEAVEIFERROR(drive,
       
   286             OstTraceExt2( TRACE_ERROR, DUP1_CMTPIMAGEDPMOVEOBJECT_CANMOVEOBJECTL, 
       
   287                     "Gets drive for storage %d failed! error code %d", iStorageId, munged_err ));
   281     TVolumeInfo volumeInfo;
   288     TVolumeInfo volumeInfo;
   282     User::LeaveIfError(iFramework.Fs().Volume(volumeInfo, drive));
   289     LEAVEIFERROR(iFramework.Fs().Volume(volumeInfo, drive),
       
   290             OstTraceExt2( TRACE_ERROR, DUP2_CMTPIMAGEDPMOVEOBJECT_CANMOVEOBJECTL, 
       
   291                     "Gets volume information for driver %d failed! error code %d", drive, munged_err ));
   283     
   292     
   284     if(volumeInfo.iFree < fileEntry.FileSize())
   293     if(volumeInfo.iFree < fileEntry.FileSize())
   285         {
   294         {
   286         result = EMTPRespCodeStoreFull;
   295         result = EMTPRespCodeStoreFull;
   287         }
   296         }
   288     else if (BaflUtils::FileExists(iFramework.Fs(), aNewName))			
   297     else if (BaflUtils::FileExists(iFramework.Fs(), aNewName))			
   289         {
   298         {
   290         result = EMTPRespCodeInvalidParentObject;
   299         result = EMTPRespCodeInvalidParentObject;
   291         }
   300         }
   292     __FLOG_VA((_L8("CanMoveObjectL - Exit with response code 0x%04X"), result));
   301     OstTrace1( TRACE_NORMAL, DUP3_CMTPIMAGEDPMOVEOBJECT_CANMOVEOBJECTL, "Exit with response code 0x%04X", result );
   293     __FLOG(_L8("<< CMTPImageDpMoveObject::CanMoveObjectL"));     
   302     OstTraceFunctionExit0( CMTPIMAGEDPMOVEOBJECT_CANMOVEOBJECTL_EXIT );
   294     return result;	
   303     return result;	
   295     }
   304     }
   296 
   305 
   297 TInt CMTPImageDpMoveObject::MoveImageFile(const TDesC& aOldImageName, const TDesC& aNewImageName)
   306 TInt CMTPImageDpMoveObject::MoveImageFile(const TDesC& aOldImageName, const TDesC& aNewImageName)
   298     {
   307     {
   299     __FLOG(_L8(">> CMTPImageDpMoveObject::MoveImageFile"));
   308     OstTraceFunctionEntry0( CMTPIMAGEDPMOVEOBJECT_MOVEIMAGEFILE_ENTRY ); 
   300     __FLOG_VA((_L8("move image src: %S dest: %S"), &aOldImageName, &aNewImageName));        
   309     OstTraceExt2( TRACE_NORMAL, CMTPIMAGEDPMOVEOBJECT_MOVEIMAGEFILE, "move image src: %S dest: %S", aOldImageName, aNewImageName );
   301     __FLOG(_L8("<< CMTPImageDpMoveObject::MoveImageFile"));
   310     OstTraceFunctionExit0( CMTPIMAGEDPMOVEOBJECT_MOVEIMAGEFILE_EXIT ); 
   302     return iFileMan->Move(aOldImageName, aNewImageName);
   311     return iFileMan->Move(aOldImageName, aNewImageName);
   303     }
   312     }
   304 
   313 
   305 // End of file
   314 // End of file