mtpfws/mtpfw/dataproviders/dputility/src/cmtpcopyobject.cpp
branchRCL_3
changeset 14 60a94a45d437
parent 12 8b094906a049
child 19 ef55b168cedb
equal deleted inserted replaced
12:8b094906a049 14:60a94a45d437
    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 "cmtpfsentrycache.h"
    26 #include "cmtpstoragemgr.h"
    27 #include "cmtpstoragemgr.h"
    27 #include "cmtpcopyobject.h"
    28 #include "cmtpcopyobject.h"
    28 #include "mtpdppanic.h"
    29 #include "mtpdppanic.h"
    29 
    30 
    30 __FLOG_STMT(_LIT8(KComponent,"CopyObject");)
    31 __FLOG_STMT(_LIT8(KComponent,"CopyObject");)
    59 /**
    60 /**
    60 Destructor
    61 Destructor
    61 */	
    62 */	
    62 EXPORT_C CMTPCopyObject::~CMTPCopyObject()
    63 EXPORT_C CMTPCopyObject::~CMTPCopyObject()
    63 	{	
    64 	{	
       
    65 	__FLOG(_L8("~CMTPCopyObject - Entry"));
       
    66 	Cancel();
       
    67 	iDpSingletons.Close();
       
    68 	iSingletons.Close();
       
    69 	
       
    70 	delete iTimer;
    64 	delete iDest;
    71 	delete iDest;
       
    72 	delete iNewFileName;
    65 	delete iFileMan;
    73 	delete iFileMan;
    66 	iSingletons.Close();
    74 	
       
    75 	__FLOG(_L8("~CMTPCopyObject - Exit"));
    67 	__FLOG_CLOSE;
    76 	__FLOG_CLOSE;
    68 	}
    77 	}
    69 
    78 
    70 /**
    79 /**
    71 Standard c++ constructor
    80 Standard c++ constructor
    72 */	
    81 */	
    73 CMTPCopyObject::CMTPCopyObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) :
    82 CMTPCopyObject::CMTPCopyObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) :
    74 	CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPCopyObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPCopyObjectPolicy)
    83 	CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPCopyObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPCopyObjectPolicy),
       
    84 	iTimer(NULL)
    75 	{
    85 	{
    76 	__FLOG_OPEN(KMTPSubsystem, KComponent);
    86 	__FLOG_OPEN(KMTPSubsystem, KComponent);
    77 	}
    87 	}
    78 
    88 
    79 
    89 
    80 
    90 
    81 TMTPResponseCode CMTPCopyObject::CheckRequestL()
    91 TMTPResponseCode CMTPCopyObject::CheckRequestL()
    82 	{
    92 	{
    83     __FLOG(_L8("CheckRequestL - Entry"));
    93 	__FLOG(_L8("CheckRequestL - Entry"));
    84 	TMTPResponseCode result = CMTPRequestProcessor::CheckRequestL();
    94 	TMTPResponseCode result = CMTPRequestProcessor::CheckRequestL();
    85 	if ( (EMTPRespCodeOK == result) && (!iSingletons.StorageMgr().IsReadWriteStorage(Request().Uint32(TMTPTypeRequest::ERequestParameter2))) )
    95 	if ( (EMTPRespCodeOK == result) && (!iSingletons.StorageMgr().IsReadWriteStorage(Request().Uint32(TMTPTypeRequest::ERequestParameter2))) )
    86 		{
    96 		{
    87 		result = EMTPRespCodeStoreReadOnly;
    97 		result = EMTPRespCodeStoreReadOnly;
    88 		}
    98 		}
    89 	
    99 	if(result == EMTPRespCodeOK)
    90     __FLOG(_L8("CheckRequestL - Exit"));
   100 		{
       
   101 		const TUint32 KHandle(Request().Uint32(TMTPTypeRequest::ERequestParameter1));
       
   102 		CMTPObjectMetaData* object(CMTPObjectMetaData::NewLC());
       
   103 		if(iFramework.ObjectMgr().ObjectL(KHandle, *object))
       
   104 			{
       
   105 			const TDesC& suid(object->DesC(CMTPObjectMetaData::ESuid));
       
   106 			iIsFolder = EFalse;
       
   107 			User::LeaveIfError(BaflUtils::IsFolder(iFramework.Fs(), suid, iIsFolder));
       
   108 			if(!iIsFolder)
       
   109 				{
       
   110 				if(iDpSingletons.CopyingBigFileCache().IsOnGoing())
       
   111 					{
       
   112 					__FLOG(_L8("CheckRequestL - A big file copying is ongoing, respond with access denied"));
       
   113 					result = EMTPRespCodeAccessDenied;
       
   114 					}
       
   115 				}
       
   116 			}
       
   117 		CleanupStack::PopAndDestroy(object); 
       
   118 		}
       
   119 	__FLOG(_L8("CheckRequestL - Exit"));
    91 	return result;	
   120 	return result;	
    92 	} 
   121 	} 
    93 
   122 
    94 /**
   123 /**
    95 CopyObject request handler
   124 CopyObject request handler
    96 */		
   125 */		
    97 void CMTPCopyObject::ServiceL()
   126 void CMTPCopyObject::ServiceL()
    98 	{	
   127 	{	
       
   128 	__FLOG(_L8("ServiceL - Entry"));
    99 	TUint32 handle = KMTPHandleNone;
   129 	TUint32 handle = KMTPHandleNone;
   100 	TMTPResponseCode responseCode = CopyObjectL(handle);
   130 	TMTPResponseCode responseCode = CopyObjectL(handle);
   101 	if(responseCode == EMTPRespCodeOK)
   131 	if(responseCode != EMTPRespCodeOK)
   102 		{
   132 		{
       
   133 		__FLOG_VA((_L8("ServiceL, sending response with respond code %d"), responseCode));
       
   134 		SendResponseL(responseCode);
       
   135 		}
       
   136 	else if (iIsFolder)
       
   137 		{
       
   138 		__FLOG_VA((_L8("ServiceL, sending response with handle=%d, respond code OK"), handle));
   103 		SendResponseL(EMTPRespCodeOK, 1, &handle);
   139 		SendResponseL(EMTPRespCodeOK, 1, &handle);
   104 		}
   140 		}
   105 	else
   141 	__FLOG(_L8("ServiceL - Exit"));
   106 		{
       
   107 		SendResponseL(responseCode);
       
   108 		}
       
   109 	}
   142 	}
   110 
   143 
   111 
   144 
   112 /**
   145 /**
   113  Second phase constructor
   146  Second phase constructor
   114 */
   147 */
   115 void CMTPCopyObject::ConstructL()
   148 void CMTPCopyObject::ConstructL()
   116     {
   149 	{
   117 	iSingletons.OpenL();
   150 	iSingletons.OpenL();
   118     }
   151 	iDpSingletons.OpenL(iFramework);
       
   152 	}
   119 
   153 
   120 	
   154 	
   121 /**
   155 /**
   122 A helper function of CopyObjectL.
   156 A helper function of CopyObjectL.
   123 @param aNewFileName the new full filename after copy.
   157 @param aNewFileName the new full filename after copy.
   124 @return objectHandle of new copy of object.
   158 @return objectHandle of new copy of object.
   125 */
   159 */
   126 TUint32 CMTPCopyObject::CopyFileL(const TDesC& aNewFileName)
   160 void CMTPCopyObject::CopyFileL(const TDesC& aNewFileName)
   127 	{
   161 	{
   128 	__FLOG(_L8("CopyFileL - Entry"));
   162 	__FLOG(_L8("CopyFileL - Entry"));
       
   163 	delete iNewFileName;
       
   164 	iNewFileName = NULL;
       
   165 	iNewFileName = aNewFileName.AllocL(); // Store the new file name	
   129 	const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
   166 	const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
   130 	GetPreviousPropertiesL(suid);
   167 	GetPreviousPropertiesL(suid);
   131 	User::LeaveIfError(iFileMan->Copy(suid, *iDest));
   168 	
   132 	SetPreviousPropertiesL(aNewFileName);
   169 	User::LeaveIfError(iFileMan->Copy(suid, *iDest, CFileMan::EOverWrite, iStatus));
   133 	
   170 	if ( !IsActive() )
   134 	TUint32 handle = UpdateObjectInfoL(aNewFileName);
   171 	{  
       
   172 	SetActive();
       
   173 	}
       
   174 	
       
   175 	delete iTimer;
       
   176 	iTimer = NULL;
       
   177 	iTimer = CPeriodic::NewL(EPriorityStandard);
       
   178 	TTimeIntervalMicroSeconds32 KCopyObjectIntervalNone = 0;	
       
   179 	iTimer->Start(TTimeIntervalMicroSeconds32(KCopyObjectTimeOut), KCopyObjectIntervalNone, TCallBack(CMTPCopyObject::OnTimeoutL, this));
   135 	
   180 	
   136 	__FLOG(_L8("CopyFileL - Exit"));
   181 	__FLOG(_L8("CopyFileL - Exit"));
   137 	
       
   138 	return handle;
       
   139 	}
   182 	}
   140 
   183 
   141 /**
   184 /**
   142 A helper function of CopyObjectL.
   185 A helper function of CopyObjectL.
   143 @param aNewFolderName the new full file folder name after copy.
   186 @param aNewFolderName the new full file folder name after copy.
   181 	newObjectName = *iDest;
   224 	newObjectName = *iDest;
   182 	
   225 	
   183 	const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
   226 	const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
   184 	TParsePtrC fileNameParser(suid);
   227 	TParsePtrC fileNameParser(suid);
   185 	
   228 	
   186 	// Check if the object is a folder or a file.
   229 	if(!iIsFolder)
   187 	TBool isFolder = EFalse;
       
   188 	User::LeaveIfError(BaflUtils::IsFolder(iFramework.Fs(), suid, isFolder));	
       
   189 	
       
   190 	if(!isFolder)
       
   191 		{
   230 		{
   192 		if((newObjectName.Length() + fileNameParser.NameAndExt().Length()) <= newObjectName.MaxLength())
   231 		if((newObjectName.Length() + fileNameParser.NameAndExt().Length()) <= newObjectName.MaxLength())
   193 			{
   232 			{
   194 			newObjectName.Append(fileNameParser.NameAndExt());
   233 			newObjectName.Append(fileNameParser.NameAndExt());
   195 			}
   234 			}
   211 		{			
   250 		{			
   212 		delete iFileMan;
   251 		delete iFileMan;
   213 		iFileMan = NULL;
   252 		iFileMan = NULL;
   214 		iFileMan = CFileMan::NewL(iFramework.Fs());
   253 		iFileMan = CFileMan::NewL(iFramework.Fs());
   215 		
   254 		
   216 		if(!isFolder) // It is a file.
   255 		if(!iIsFolder) // It is a file.
   217 			{
   256 			{
   218 			aNewHandle = CopyFileL(newObjectName);
   257 			CopyFileL(newObjectName);
   219 			}
   258 			}
   220 		else // It is a folder.
   259 		else // It is a folder.
   221 			{
   260 			{
   222 			aNewHandle = CopyFolderL(newObjectName);
   261 			aNewHandle = CopyFolderL(newObjectName);
   223 			}
   262 			}
   355 	
   394 	
   356 	__FLOG(_L8("UpdateObjectInfoL - Exit"));
   395 	__FLOG(_L8("UpdateObjectInfoL - Exit"));
   357 	
   396 	
   358 	return handle;	
   397 	return handle;	
   359 	}
   398 	}
       
   399 
       
   400 /**
       
   401  Call back function, called when the timer expired for big file copying.
       
   402  Send response to initiator and cache the target file entry info, which is used to send response 
       
   403  to getobjectproplist and getobjectinfo.
       
   404 */
       
   405 TInt CMTPCopyObject::OnTimeoutL(TAny* aPtr)
       
   406 	{
       
   407 	CMTPCopyObject* copyObjectProcessor = static_cast<CMTPCopyObject*>(aPtr);
       
   408 	copyObjectProcessor->DoOnTimeoutL();
       
   409 	return KErrNone;
       
   410 	}
       
   411 
       
   412 void CMTPCopyObject::DoOnTimeoutL()
       
   413 	{
       
   414 	__FLOG(_L8("DoOnTimeoutL - Entry"));
       
   415 	
       
   416 	if (iTimer)
       
   417 		{
       
   418 		if (iTimer->IsActive())
       
   419 			{
       
   420 			iTimer->Cancel();
       
   421 			}
       
   422 		delete iTimer;
       
   423 		iTimer = NULL;
       
   424 		}
       
   425 	
       
   426 	const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
       
   427 	TEntry fileEntry;
       
   428 	User::LeaveIfError(iFramework.Fs().Entry(suid, fileEntry));
       
   429 	TUint32 handle = KMTPHandleNone;
       
   430 	handle = UpdateObjectInfoL(*iNewFileName);
       
   431 	CMTPFSEntryCache& aCache = iDpSingletons.CopyingBigFileCache();
       
   432 	
       
   433 	// Cache the target file entry info, which is used to send response to getobjectproplist and getobjectinfo
       
   434 	aCache.SetOnGoing(ETrue);
       
   435 	aCache.SetTargetHandle(handle);
       
   436 	aCache.SetFileEntry(fileEntry);
       
   437 	
       
   438 	__FLOG_VA((_L8("UpdateFSEntryCache, sending response with handle=%d, respond code OK for a big file copy"), handle));
       
   439 	SendResponseL(EMTPRespCodeOK, 1, &handle);
       
   440 	
       
   441 	__FLOG(_L8("DoOnTimeoutL - Exit"));
       
   442 	}
       
   443 
       
   444 /**
       
   445  CMTPCopyObject::RunL
       
   446 */
       
   447 void CMTPCopyObject::RunL()
       
   448 	{
       
   449 	__FLOG(_L8("RunL - Entry"));
       
   450 	
       
   451 	User::LeaveIfError(iStatus.Int());
       
   452 	SetPreviousPropertiesL(*iNewFileName);
       
   453 	CMTPFSEntryCache& aCache = iDpSingletons.CopyingBigFileCache();
       
   454 	// Check to see if we are copying a big file
       
   455 	if(aCache.IsOnGoing())
       
   456 		{
       
   457 		__FLOG(_L8("RunL - Big file copy complete"));
       
   458 		aCache.SetOnGoing(EFalse);
       
   459 		aCache.SetTargetHandle(KMTPHandleNone);
       
   460 		}	
       
   461 	else
       
   462 		{
       
   463 		//Cancel the timer
       
   464 		if(iTimer)
       
   465 			{
       
   466 			if (iTimer->IsActive())
       
   467 				{
       
   468 				iTimer->Cancel();
       
   469 				}
       
   470 			delete iTimer;
       
   471 			iTimer = NULL;
       
   472 			}
       
   473 		
       
   474 		TUint32 handle = UpdateObjectInfoL(*iNewFileName);
       
   475 		__FLOG_VA((_L8("RunL, sending response with handle=%d, respond code OK for a normal file copy"), handle));
       
   476 		SendResponseL(EMTPRespCodeOK, 1, &handle);
       
   477 		}
       
   478 	__FLOG(_L8("RunL - Exit"));
       
   479 	}
       
   480 
       
   481 /**
       
   482 Override to handle the complete phase of copy object
       
   483 @return EFalse
       
   484 */
       
   485 TBool CMTPCopyObject::DoHandleCompletingPhaseL()
       
   486 	{
       
   487 	CMTPRequestProcessor::DoHandleCompletingPhaseL();
       
   488 	
       
   489 	CMTPFSEntryCache& aCache = iDpSingletons.CopyingBigFileCache();
       
   490 	if(aCache.IsOnGoing())
       
   491 		{
       
   492 		return EFalse;
       
   493 		}
       
   494 	else
       
   495 		{
       
   496 		return ETrue;
       
   497 		}
       
   498 	}
       
   499 
       
   500 /**
       
   501 Override to match CopyObject request
       
   502 @param aRequest    The request to match
       
   503 @param aConnection The connection from which the request comes
       
   504 @return ETrue if the processor can handle the request, otherwise EFalse
       
   505 */        
       
   506 TBool CMTPCopyObject::Match(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) const
       
   507 	{
       
   508 	__FLOG(_L8("Match - Entry"));
       
   509 	TBool result = EFalse;
       
   510 	TUint16 operationCode = aRequest.Uint16(TMTPTypeRequest::ERequestOperationCode);
       
   511 	if ((operationCode == EMTPOpCodeCopyObject) && &iConnection == &aConnection)
       
   512 	{
       
   513 	result = ETrue;
       
   514 	}    
       
   515 	__FLOG_VA((_L8("Match -- Exit with result = %d"), result));
       
   516 	return result;    
       
   517 	}