mtpfws/mtpfw/src/cmtpobjectstore.cpp
changeset 17 aabe5387f5ce
parent 0 d0791faffa3f
child 18 1b39655331a3
equal deleted inserted replaced
0:d0791faffa3f 17:aabe5387f5ce
   278 	return i;
   278 	return i;
   279 	}
   279 	}
   280 
   280 
   281 void CMTPObjectStore::CommitReservedObjectHandleL(CMTPObjectMetaData& aObject)
   281 void CMTPObjectStore::CommitReservedObjectHandleL(CMTPObjectMetaData& aObject)
   282 	{
   282 	{
       
   283 	TFileName suid;
       
   284 	suid.CopyLC(aObject.DesC(CMTPObjectMetaData::ESuid));
       
   285 	TUint32 handle = HandleL(suid);
       
   286 	if (handle != KMTPHandleNone)
       
   287 	    {
       
   288 	    __FLOG(_L8("CommitReserverd leave for duplicate suid."));
       
   289 	    User::Leave(KErrAlreadyExists);
       
   290 	    }
       
   291 	TUint32 suidHash = DefaultHash::Des16(suid);
       
   292 	
   283 	//After the PutL called the cursor's position is not well defined.
   293 	//After the PutL called the cursor's position is not well defined.
   284 	iCachedHandle = 0;
   294 	iCachedHandle = 0;
   285 	iCachedSuidHash = 0;
   295 	iCachedSuidHash = 0;
   286 	TInt64 id = iHandleAllocator->NextPOUIDL();
   296 	TInt64 id = iHandleAllocator->NextPOUIDL();
   287 	aObject.SetUint(CMTPObjectMetaData::EIdentifier, id);
   297 	aObject.SetUint(CMTPObjectMetaData::EIdentifier, id);
   288 
   298 
   289 	TFileName suid;
   299 	handle = aObject.Uint(CMTPObjectMetaData::EHandle);
   290 	suid.CopyLC(aObject.DesC(CMTPObjectMetaData::ESuid));
       
   291 	TUint32 suidHash = DefaultHash::Des16(suid);
       
   292 
       
   293 	TUint32 handle = aObject.Uint(CMTPObjectMetaData::EHandle);
       
   294 	CleanupStack::PushL(TCleanupItem(CMTPObjectStore::DBUpdateFailRecover, &iBatched));
   300 	CleanupStack::PushL(TCleanupItem(CMTPObjectStore::DBUpdateFailRecover, &iBatched));
   295 	iBatched.InsertL();
   301 	iBatched.InsertL();
   296 	iBatched.SetColL(EObjectStoreHandleId, handle);
   302 	iBatched.SetColL(EObjectStoreHandleId, handle);
   297 	iBatched.SetColL(EObjectStoreSUIDHash, suidHash);
   303 	iBatched.SetColL(EObjectStoreSUIDHash, suidHash);
   298 	DbColWriteStreamL(iBatched, EObjectStoreSUID, aObject.DesC(CMTPObjectMetaData::ESuid));	
   304 	DbColWriteStreamL(iBatched, EObjectStoreSUID, aObject.DesC(CMTPObjectMetaData::ESuid));	
   383 	iCachedHandle = 0;
   389 	iCachedHandle = 0;
   384 	iCachedSuidHash = 0;
   390 	iCachedSuidHash = 0;
   385 	TBool needToInsert = EFalse;
   391 	TBool needToInsert = EFalse;
   386 	TBool needUpdateOwner = EFalse;
   392 	TBool needUpdateOwner = EFalse;
   387 	TUint dpId(aObject.Uint(CMTPObjectMetaData::EDataProviderId));
   393 	TUint dpId(aObject.Uint(CMTPObjectMetaData::EDataProviderId));
       
   394 
   388 	TFileName suid;
   395 	TFileName suid;
   389 	suid.CopyLC(aObject.DesC(CMTPObjectMetaData::ESuid));
   396 	suid.CopyLC(aObject.DesC(CMTPObjectMetaData::ESuid));
   390 	TUint32 suidHash = DefaultHash::Des16(suid);
   397 	TUint32 suidHash = DefaultHash::Des16(suid);
   391 	TUint32 parentHandle = aObject.Uint(CMTPObjectMetaData::EParentHandle);
   398 	TUint32 parentHandle = aObject.Uint(CMTPObjectMetaData::EParentHandle);
   392 	TUint32 handle = KMTPHandleNone, handleInDB = KMTPHandleAll;
   399 	TUint32 handle = KMTPHandleNone, handleInDB = KMTPHandleAll;
   393 	TInt64 id = 0;
   400 	TInt64 id = 0;
   394 	// Check if the dp is enumerating
   401 	// Check if the dp is enumerating
   395 	if (iSingletons.DpController().EnumerateState() != CMTPDataProviderController::EEnumerated && iCacheExist)
   402 	if (iSingletons.DpController().EnumerateState() != CMTPDataProviderController::EEnumeratedFulllyCompleted && iCacheExist)
   396 		{
   403 		{
   397 		//it is in the object enumeration phase. 
   404 		//it is in the object enumeration phase. 
   398 		// if it's see if we have an object with the same SUID
   405 		// if it's see if we have an object with the same SUID
   399 		//When the MTP server startup the object enumeration, it will fetch all of the object's (SUIDHash and Handles) into in-memory ordered array.
   406 		//When the MTP server startup the object enumeration, it will fetch all of the object's (SUIDHash and Handles) into in-memory ordered array.
   400 		//this function is to try to match the handleID for the incoming suidHash/SUID/DPID, if matched in memory, it will return the handleID
   407 		//this function is to try to match the handleID for the incoming suidHash/SUID/DPID, if matched in memory, it will return the handleID
   436 				{
   443 				{
   437 				needToInsert = ETrue;
   444 				needToInsert = ETrue;
   438 				}
   445 				}
   439 			else
   446 			else
   440 				{
   447 				{
   441 				User::Leave(KErrAlreadyExists);
   448 				//while enumerating, we ignore the repeatedly INSERT operations.
       
   449 				//User::Leave(KErrAlreadyExists);
   442 				}
   450 				}
   443 			}
   451 			}
   444 		}
   452 		}
   445 	else
   453 	else
   446 		{
   454 		{
   554 	suid.CopyLC(aObject.DesC(CMTPObjectMetaData::ESuid));
   562 	suid.CopyLC(aObject.DesC(CMTPObjectMetaData::ESuid));
   555 	TUint32 suidHash = DefaultHash::Des16(suid);
   563 	TUint32 suidHash = DefaultHash::Des16(suid);
   556 
   564 
   557 	if (LocateByHandleL(handle))
   565 	if (LocateByHandleL(handle))
   558 		{
   566 		{
       
   567 		//To avoid this modification will not generate duplicate SUID
       
   568 		TUint32 handle2 = HandleL(suid);
       
   569 		if (handle2 != KMTPHandleNone && handle2 != handle)
       
   570 		    {
       
   571 		    __FLOG(_L8("ModifyObjectL leave for duplicate suid."));
       
   572 		    User::Leave(KErrAlreadyExists); 
       
   573 		    }
       
   574 		
   559 		//After the PutL called the cursor's position is not well defined.
   575 		//After the PutL called the cursor's position is not well defined.
   560 		iCachedHandle = 0;
   576 		iCachedHandle = 0;
   561 		iCachedSuidHash = 0;
   577 		iCachedSuidHash = 0;
   562 		TInt64 id = iBatched.ColInt64(EObjectStorePOUID);
   578 		TInt64 id = iBatched.ColInt64(EObjectStorePOUID);
   563 		TUint32 suidHashOld = iBatched.ColUint32(EObjectStoreSUIDHash);
   579 		TUint32 suidHashOld = iBatched.ColUint32(EObjectStoreSUIDHash);
   684 
   700 
   685 void CMTPObjectStore::RemoveObjectL(const TMTPTypeUint32& aHandle)
   701 void CMTPObjectStore::RemoveObjectL(const TMTPTypeUint32& aHandle)
   686 	{
   702 	{
   687 	if (LocateByHandleL(aHandle.Value()))
   703 	if (LocateByHandleL(aHandle.Value()))
   688 		{
   704 		{
   689 		if (iSingletons.DpController().EnumerateState() != CMTPDataProviderController::EEnumerated &&
   705 		if (iSingletons.DpController().EnumerateState() != CMTPDataProviderController::EEnumeratedFulllyCompleted &&
   690 			IsMediaFormat(iBatched.ColUint16(EObjectStoreFormatCode)))
   706 			IsMediaFormat(iBatched.ColUint16(EObjectStoreFormatCode)))
   691 			{
   707 			{
   692 			iMtpDeltaDataMgr->UpdateDeltaDataTableL(iBatched.ColInt64(EObjectStorePOUID), CMtpDeltaDataMgr::EDeleted);
   708 			iMtpDeltaDataMgr->UpdateDeltaDataTableL(iBatched.ColInt64(EObjectStorePOUID), CMtpDeltaDataMgr::EDeleted);
   693 			}
   709 			}
   694 		iCachedSuidHash = 0;
   710 		iCachedSuidHash = 0;
   700 
   716 
   701 void CMTPObjectStore::RemoveObjectL(const TDesC& aSuid)
   717 void CMTPObjectStore::RemoveObjectL(const TDesC& aSuid)
   702 	{
   718 	{
   703 	if(LocateBySuidL(aSuid))
   719 	if(LocateBySuidL(aSuid))
   704 		{
   720 		{
   705 		if (iSingletons.DpController().EnumerateState() != CMTPDataProviderController::EEnumerated &&
   721 		if (iSingletons.DpController().EnumerateState() != CMTPDataProviderController::EEnumeratedFulllyCompleted &&
   706 			IsMediaFormat(iBatched_SuidHashID.ColUint16(EObjectStoreFormatCode)))
   722 			IsMediaFormat(iBatched_SuidHashID.ColUint16(EObjectStoreFormatCode)))
   707 			{
   723 			{
   708 			iMtpDeltaDataMgr->UpdateDeltaDataTableL(iBatched_SuidHashID.ColInt64(EObjectStorePOUID), CMtpDeltaDataMgr::EDeleted);
   724 			iMtpDeltaDataMgr->UpdateDeltaDataTableL(iBatched_SuidHashID.ColInt64(EObjectStorePOUID), CMtpDeltaDataMgr::EDeleted);
   709 			}
   725 			}
   710 		iCachedSuidHash = 0;
   726 		iCachedSuidHash = 0;