mtpfws/mtpfw/dataproviders/dputility/src/cmtpmoveobject.cpp
branchRCL_3
changeset 3 8b094906a049
parent 0 d0791faffa3f
child 4 60a94a45d437
equal deleted inserted replaced
2:4843bb5893b6 3:8b094906a049
    21 #include <mtp/mmtpstoragemgr.h>
    21 #include <mtp/mmtpstoragemgr.h>
    22 #include <mtp/cmtpobjectmetadata.h>
    22 #include <mtp/cmtpobjectmetadata.h>
    23 #include <mtp/cmtptypearray.h>
    23 #include <mtp/cmtptypearray.h>
    24 #include <mtp/cmtptypestring.h>
    24 #include <mtp/cmtptypestring.h>
    25 
    25 
       
    26 #include "cmtpstoragemgr.h"
    26 #include "cmtpmoveobject.h"
    27 #include "cmtpmoveobject.h"
    27 #include "mtpdppanic.h"
    28 #include "mtpdppanic.h"
    28 
    29 
    29 
    30 
    30 __FLOG_STMT(_LIT8(KComponent,"MoveObject");)
    31 __FLOG_STMT(_LIT8(KComponent,"MoveObject");)
    63 	{	
    64 	{	
    64 	delete iDest;
    65 	delete iDest;
    65 	delete iFileMan;
    66 	delete iFileMan;
    66 	delete iPathToMove;
    67 	delete iPathToMove;
    67 	delete iNewRootFolder;
    68 	delete iNewRootFolder;
       
    69 	iSingletons.Close();
    68 	__FLOG_CLOSE;
    70 	__FLOG_CLOSE;
    69 	}
    71 	}
    70 
    72 
    71 /**
    73 /**
    72 Standard c++ constructor
    74 Standard c++ constructor
    75 	CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPMoveObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPMoveObjectPolicy),
    77 	CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPMoveObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPMoveObjectPolicy),
    76 	iMoveObjectIndex(0)
    78 	iMoveObjectIndex(0)
    77 	{
    79 	{
    78 	__FLOG_OPEN(KMTPSubsystem, KComponent);
    80 	__FLOG_OPEN(KMTPSubsystem, KComponent);
    79 	}
    81 	}
    80 	
    82 
       
    83 TMTPResponseCode CMTPMoveObject::CheckRequestL()
       
    84 	{
       
    85     __FLOG(_L8("CheckRequestL - Entry"));
       
    86 	TMTPResponseCode result = CMTPRequestProcessor::CheckRequestL();
       
    87 	if (EMTPRespCodeOK != result)
       
    88 		{
       
    89 		__FLOG(_L8("CheckRequestL with error- Exit"));
       
    90 		return result;
       
    91 		}
       
    92 	
       
    93 	const TUint32 KObjectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
    94 	//not taking owernship
       
    95 	iObjectInfo = iRequestChecker->GetObjectInfo(KObjectHandle); 
       
    96 	__ASSERT_DEBUG(iObjectInfo, Panic(EMTPDpObjectNull));	
       
    97 	if(!iSingletons.StorageMgr().IsReadWriteStorage(iObjectInfo->Uint(CMTPObjectMetaData::EStorageId)))
       
    98 		{
       
    99 		result = EMTPRespCodeStoreReadOnly;
       
   100 		}
       
   101 	
       
   102 	if ( (EMTPRespCodeOK == result) && (!iSingletons.StorageMgr().IsReadWriteStorage(Request().Uint32(TMTPTypeRequest::ERequestParameter2))) )
       
   103 		{
       
   104 		result = EMTPRespCodeStoreReadOnly;
       
   105 		}
       
   106 	
       
   107     __FLOG(_L8("CheckRequestL - Exit"));
       
   108 	return result;	
       
   109 	} 
       
   110 
    81 /**
   111 /**
    82 MoveObject request handler
   112 MoveObject request handler
    83 */		
   113 */		
    84 void CMTPMoveObject::ServiceL()
   114 void CMTPMoveObject::ServiceL()
    85 	{	
   115 	{	
    93 /**
   123 /**
    94  Second phase constructor
   124  Second phase constructor
    95 */
   125 */
    96 void CMTPMoveObject::ConstructL()
   126 void CMTPMoveObject::ConstructL()
    97     {
   127     {
       
   128 	iSingletons.OpenL();
    98     }
   129     }
    99     
   130     
   100 void CMTPMoveObject::RunL()
       
   101 	{
       
   102 	__FLOG(_L8("RunL - Entry"));
       
   103     SendResponseL( EMTPRespCodeOK );
       
   104     __FLOG(_L8("RunL - Exit"));
       
   105 	}
       
   106     
       
   107 TInt CMTPMoveObject::RunError(TInt /*aError*/)
       
   108 	{
       
   109 	TRAP_IGNORE(SendResponseL(EMTPRespCodeGeneralError));
       
   110     return KErrNone;  
       
   111 	}
       
   112 
   131 
   113 /**
   132 /**
   114 A helper function of MoveObjectL.
   133 A helper function of MoveObjectL.
   115 @param aNewFileName the new file name after the object is moved.
   134 @param aNewFileName the new file name after the object is moved.
   116 */
   135 */
   237 void CMTPMoveObject::GetParametersL()
   256 void CMTPMoveObject::GetParametersL()
   238 	{
   257 	{
   239 	__FLOG(_L8("GetParametersL - Entry"));
   258 	__FLOG(_L8("GetParametersL - Entry"));
   240 	__ASSERT_DEBUG(iRequestChecker, Panic(EMTPDpRequestCheckNull));
   259 	__ASSERT_DEBUG(iRequestChecker, Panic(EMTPDpRequestCheckNull));
   241 	
   260 	
   242 	TUint32 objectHandle  = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
   243 	iStorageId = Request().Uint32(TMTPTypeRequest::ERequestParameter2);
   261 	iStorageId = Request().Uint32(TMTPTypeRequest::ERequestParameter2);
   244 	iNewParentHandle  = Request().Uint32(TMTPTypeRequest::ERequestParameter3);
   262 	iNewParentHandle  = Request().Uint32(TMTPTypeRequest::ERequestParameter3);
   245 	
       
   246 	//not taking owernship
       
   247 	iObjectInfo = iRequestChecker->GetObjectInfo(objectHandle); 
       
   248 	__ASSERT_DEBUG(iObjectInfo, Panic(EMTPDpObjectNull));	
       
   249 
   263 
   250 	if(iNewParentHandle == 0)
   264 	if(iNewParentHandle == 0)
   251 		{
   265 		{
   252 		SetDefaultParentObjectL();
   266 		SetDefaultParentObjectL();
   253 		}
   267 		}
   327 	User::LeaveIfError(iFramework.Fs().SetModified(aFileName, iPreviousModifiedTime));
   341 	User::LeaveIfError(iFramework.Fs().SetModified(aFileName, iPreviousModifiedTime));
   328 	__FLOG(_L8("SetPreviousPropertiesL - Exit"));
   342 	__FLOG(_L8("SetPreviousPropertiesL - Exit"));
   329 	}
   343 	}
   330 
   344 
   331 
   345 
   332 /* This function will actually delete the orginal folders from the file system. */
   346 
   333 TMTPResponseCode CMTPMoveObject::FinalPhaseMove()
   347 
   334 	{
   348 
   335 	__FLOG(_L8("FinalPhaseMove - Entry"));
       
   336 	TMTPResponseCode ret = EMTPRespCodeOK;
       
   337 	__FLOG(*iPathToMove);
       
   338 	TInt rel = iFileMan->RmDir(*iPathToMove);
       
   339 	__FLOG_VA((_L8("Error code of RmDir is %d"),rel));
       
   340 	if (rel != KErrNone)
       
   341 		{
       
   342 		ret = EMTPRespCodeGeneralError;
       
   343 		}
       
   344 	__FLOG(_L8("FinalPhaseMove - Exit"));
       
   345 	return ret;
       
   346 	}
       
   347 
       
   348 /* Move a single object and update the database */	
       
   349 void CMTPMoveObject::MoveAndUpdateL(TUint32 aObjectHandle)
       
   350 	{
       
   351 	__FLOG(_L8("MoveAndUpdateL - Entry"));
       
   352 	CMTPObjectMetaData* objectInfo(CMTPObjectMetaData::NewLC());
       
   353 	RBuf fileName;
       
   354 	fileName.CreateL(KMaxFileName);
       
   355 	fileName.CleanupClosePushL();	
       
   356 	RBuf rightPartName;
       
   357 	rightPartName.CreateL(KMaxFileName);
       
   358 	rightPartName.CleanupClosePushL();
       
   359 	RBuf oldName;
       
   360 	oldName.CreateL(KMaxFileName);	
       
   361 	oldName.CleanupClosePushL();
       
   362 		
       
   363 	if(iFramework.ObjectMgr().ObjectL(TMTPTypeUint32(aObjectHandle), *objectInfo))
       
   364 		{	
       
   365 		fileName = objectInfo->DesC(CMTPObjectMetaData::ESuid);
       
   366 		oldName = fileName;
       
   367 				
       
   368 		if (objectInfo->Uint(CMTPObjectMetaData::EDataProviderId) == iFramework.DataProviderId())
       
   369 			{	
       
   370 			rightPartName = fileName.Right(fileName.Length() - iPathToMove->Length());
       
   371 			
       
   372 			if((iNewRootFolder->Length() + rightPartName.Length()) > fileName.MaxLength())
       
   373 				{
       
   374 				User::Leave(KErrCorrupt);
       
   375 				}
       
   376 				
       
   377 			fileName.Zero();
       
   378 			fileName.Append(*iNewRootFolder);
       
   379 			fileName.Append(rightPartName);
       
   380 			objectInfo->SetDesCL(CMTPObjectMetaData::ESuid, fileName);				
       
   381 			objectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId);
       
   382 			iFramework.ObjectMgr().ModifyObjectL(*objectInfo);
       
   383 			}
       
   384 		}
       
   385 	else
       
   386 		{
       
   387 		User::Leave(KErrCorrupt);
       
   388 		}	
       
   389 			
       
   390 	iFileMan->Move(oldName, fileName);
       
   391 	
       
   392 	CleanupStack::PopAndDestroy(&oldName);	
       
   393 	CleanupStack::PopAndDestroy(&rightPartName); 
       
   394 	CleanupStack::PopAndDestroy(&fileName); 	
       
   395 	CleanupStack::PopAndDestroy(objectInfo);
       
   396 	__FLOG(_L8("MoveAndUpdateL - Exit"));	
       
   397 	}
       
   398 
       
   399 
       
   400 
       
   401 
       
   402