mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/ccopyobject.cpp
branchRCL_3
changeset 9 bee149131e4b
parent 0 a2952bb97e68
child 14 05b0d2323768
--- a/mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/ccopyobject.cpp	Tue Feb 02 00:27:58 2010 +0200
+++ b/mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/ccopyobject.cpp	Fri Feb 19 23:18:32 2010 +0200
@@ -1,20 +1,19 @@
 /*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description:  Implement the operation: CopyObject
-*
-*/
-
+ * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:  Implement the operation: CopyObject
+ *
+ */
 
 #include <bautils.h>
 
@@ -33,16 +32,17 @@
 #include "mmmtpdputility.h"
 #include "mmmtpdpconfig.h"
 #include "cmmmtpdpmetadataaccesswrapper.h"
+#include "cpropertysettingutility.h"
 
 /**
-* Verification data for the CopyObject request
-*/
+ * Verification data for the CopyObject request
+ */
 const TMTPRequestElementInfo KMTPCopyObjectPolicy[] =
     {
         {
         TMTPTypeRequest::ERequestParameter1,
         EMTPElementTypeObjectHandle,
-        EMTPElementAttrFileOrDir,
+        EMTPElementAttrFile,
         0,
         0,
         0
@@ -75,13 +75,10 @@
     Cancel();
 
     delete iDest;
-    delete iFileMan;
-    iObjectHandles.Close();
+
     if ( iPropertyElement )
         delete iPropertyElement;
     delete iPropertyList;
-    delete iPathToCopy;
-    delete iNewRootFolder;
     }
 
 // -----------------------------------------------------------------------------
@@ -92,17 +89,30 @@
 EXPORT_C CCopyObject::CCopyObject( MMTPDataProviderFramework& aFramework,
     MMTPConnection& aConnection,
     MMmMtpDpConfig& aDpConfig ) :
-    CRequestProcessor( aFramework,
-        aConnection,
-        sizeof ( KMTPCopyObjectPolicy ) / sizeof(TMTPRequestElementInfo),
-        KMTPCopyObjectPolicy ),
-    iDpConfig( aDpConfig ),
-    iObjectHandles( KMmMtpRArrayGranularity )
+        CRequestProcessor( aFramework,
+            aConnection, 
+            sizeof( KMTPCopyObjectPolicy ) / sizeof( TMTPRequestElementInfo ),
+            KMTPCopyObjectPolicy ),
+        iDpConfig( aDpConfig )
     {
     PRINT( _L( "Operation: CopyObject(0x101A)" ) );
     }
 
 // -----------------------------------------------------------------------------
+// CCopyObject::ConstructL
+// Second phase constructor
+// -----------------------------------------------------------------------------
+//
+EXPORT_C void CCopyObject::ConstructL()
+    {
+    iPropertyList = CMTPTypeObjectPropList::NewL();
+
+    // Set the CenRep value of MTP status,
+    // also need to do in other processors which related to MPX
+    SetPSStatus();
+    }
+
+// -----------------------------------------------------------------------------
 // CCopyObject::ServiceL
 // CopyObject request handler
 // -----------------------------------------------------------------------------
@@ -110,223 +120,52 @@
 EXPORT_C void CCopyObject::ServiceL()
     {
     PRINT( _L( "MM MTP => CCopyObject::ServiceL" ) );
-    iHandle = KMTPHandleNone;
 
-    CopyObjectL( iHandle );
+    CopyObjectL();
 
     PRINT( _L( "MM MTP <= CCopyObject::ServiceL" ) );
     }
 
 // -----------------------------------------------------------------------------
-// CCopyObject::ConstructL
-// Second phase constructor
-// -----------------------------------------------------------------------------
-//
-EXPORT_C void CCopyObject::ConstructL()
-    {
-    CActiveScheduler::Add( this );
-
-    iPropertyList = CMTPTypeObjectPropList::NewL();
-
-    // Set the CenRep value of MTP status,
-    // also need to do in other processors which related to MPX
-    SetPSStatus();
-    }
-
-// -----------------------------------------------------------------------------
-// CCopyObject::RunL
-//
-// -----------------------------------------------------------------------------
-//
-EXPORT_C void CCopyObject::RunL()
-    {
-    PRINT( _L( "MM MTP => CCopyObject::RunL" ) );
-
-    if ( iCopyObjectIndex < iNumberOfObjects )
-        {
-        CopyAndUpdateL( iObjectHandles[iCopyObjectIndex++] );
-
-        TRequestStatus* status = &iStatus;
-        User::RequestComplete( status, iStatus.Int() );
-        SetActive();
-        }
-    else
-        {
-        PRINT1( _L( "MM MTP <> CCopyObject::RunL iHandle = 0x%x" ), iHandle );
-        SendResponseL( EMTPRespCodeOK, 1, &iHandle );
-        }
-
-    PRINT( _L( "MM MTP <= CCopyObject::RunL" ) );
-    }
-
-// -----------------------------------------------------------------------------
-// CCopyObject::CopyFileL
-// A helper function of CopyObjectL
-// -----------------------------------------------------------------------------
-//
-TUint32 CCopyObject::CopyFileL( const TDesC& aNewFileName )
-    {
-    const TDesC& suid( iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
-    PRINT2( _L( "MM MTP => CCopyObject::CopyFileL old name = %S, aNewFileName = %S" ),
-        &suid,
-        &aNewFileName );
-
-    GetPreviousPropertiesL( *iObjectInfo );
-    User::LeaveIfError( iFileMan->Copy( suid, aNewFileName ) ); // iDest just folder
-    User::LeaveIfError( iFramework.Fs().SetModified( aNewFileName, iPreviousModifiedTime ) );
-    TUint32 handle = UpdateObjectInfoL( suid, aNewFileName );
-
-    PRINT1( _L( "MM MTP <= CCopyObject::CopyFileL handle = 0x%x" ), handle );
-
-    return handle;
-    }
-
-// -----------------------------------------------------------------------------
-// CCopyObject::GenerateObjectHandleListL
-// Generate the list of handles that need to be copied to the new location
-// -----------------------------------------------------------------------------
-//
-void CCopyObject::GenerateObjectHandleListL( TUint32 aParentHandle )
-    {
-    PRINT1( _L( "MM MTP => CCopyObject::GenerateObjectHandleListL aParentHandle = 0x%x" ),
-        aParentHandle );
-    RMTPObjectMgrQueryContext context;
-    RArray<TUint> handles;
-    CleanupClosePushL( context ); // + context
-    CleanupClosePushL( handles ); // + handles
-
-    TMTPObjectMgrQueryParams params( KMTPStorageAll, KMTPFormatsAll,
-            aParentHandle );
-    do
-        {
-        iFramework.ObjectMgr().GetObjectHandlesL( params, context, handles );
-
-        TInt numberOfObjects = handles.Count();
-        for ( TInt i = 0; i < numberOfObjects; i++ )
-            {
-            if ( iFramework.ObjectMgr().ObjectOwnerId( handles[i] ) == iFramework.DataProviderId() )
-                {
-                iObjectHandles.AppendL( handles[i] );
-                continue;
-                }
-
-            // Folder
-            if ( iFramework.ObjectMgr().ObjectOwnerId( handles[i] ) == 0 ) // We know that the device dp id is always 0, otherwise the whole MTP won't work.
-                {
-                GenerateObjectHandleListL( handles[i] );
-                }
-            }
-        }
-    while ( !context.QueryComplete() );
-
-    CleanupStack::PopAndDestroy( &handles ); // - handles
-    CleanupStack::PopAndDestroy( &context ); // - context
-    PRINT( _L( "MM MTP <= CCopyObject::GenerateObjectHandleListL" ) );
-    }
-
-// -----------------------------------------------------------------------------
-// CCopyObject::CopyFolderL
-// A helper function of CopyObjectL
-// -----------------------------------------------------------------------------
-//
-TUint32 CCopyObject::CopyFolderL( const TDesC& aNewFolderName )
-    {
-    PRINT1( _L( "MM MTP => CCopyObject::CopyFolderL aNewFolderName = %S" ), &aNewFolderName );
-    TUint32 handle = iFramework.ObjectMgr().HandleL( aNewFolderName ); // just get it
-
-    GenerateObjectHandleListL( iObjectInfo->Uint( CMTPObjectMetaData::EHandle ) );
-    iCopyObjectIndex = 0;
-    iNumberOfObjects = iObjectHandles.Count();
-    PRINT1( _L( "MM MTP <> CCopyObject::CopyFolderL iNumberOfObjects = %d" ), iNumberOfObjects );
-
-    TRequestStatus* status = &iStatus;
-    User::RequestComplete( status, iStatus.Int() );
-    SetActive();
-
-    PRINT1( _L( "MM MTP <= CCopyObject::CopyFolderL handle = 0x%x" ), handle );
-    return handle;
-    }
-
-// -----------------------------------------------------------------------------
 // CCopyObject::CopyObjectL
 // Copy object operation
 // -----------------------------------------------------------------------------
 //
-void CCopyObject::CopyObjectL( TUint32& aNewHandle )
+void CCopyObject::CopyObjectL()
     {
     PRINT( _L( "MM MTP => CCopyObject::CopyObjectL" ) );
+
     TMTPResponseCode responseCode = EMTPRespCodeOK;
-    aNewHandle = KMTPHandleNone;
 
     GetParametersL();
 
     RBuf newObjectName;
+    newObjectName.CreateL( KMaxFileName );
     newObjectName.CleanupClosePushL(); // + newObjectName
-    newObjectName.CreateL( KMaxFileName );
     newObjectName = *iDest;
 
     const TDesC& suid( iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
     TParsePtrC fileNameParser( suid );
-
-    // Check if the object is a folder or a file.
-    TBool isFolder = EFalse;
-    User::LeaveIfError( BaflUtils::IsFolder( iFramework.Fs(), suid, isFolder ) );
-
-    if ( !isFolder )
-        {
-        if ( ( newObjectName.Length() + fileNameParser.NameAndExt().Length() ) <= newObjectName.MaxLength() )
-            {
-            newObjectName.Append( fileNameParser.NameAndExt() );
-            }
-        responseCode = CanCopyObjectL( suid, newObjectName );
-        }
-    else // It is a folder.
+    if ( ( newObjectName.Length() + fileNameParser.NameAndExt().Length() )
+        <= newObjectName.MaxLength() )
         {
-        TFileName rightMostFolderName;
-        User::LeaveIfError( BaflUtils::MostSignificantPartOfFullName( suid,
-            rightMostFolderName ) );
-        if ( ( newObjectName.Length() + rightMostFolderName.Length() + 1 ) <= newObjectName.MaxLength() )
-            {
-            newObjectName.Append( rightMostFolderName );
-            // Add backslash.
-            _LIT( KBackSlash, "\\" );
-            newObjectName.Append( KBackSlash );
-            }
+        newObjectName.Append( fileNameParser.NameAndExt() );
         }
+    responseCode = CanCopyObjectL( suid, newObjectName );
 
-    delete iNewRootFolder;
-    iNewRootFolder = NULL;
-    iNewRootFolder = newObjectName.AllocL();
-
+    TUint32 newHandle = KMTPHandleNone;
     if ( responseCode == EMTPRespCodeOK )
         {
-        delete iFileMan;
-        iFileMan = NULL;
-        iFileMan = CFileMan::NewL( iFramework.Fs() );
-
-        if ( !isFolder ) // It is a file.
-            {
-            aNewHandle = CopyFileL( newObjectName );
-//            if ( responseCode == EMTPRespCodeOK  )
-            SendResponseL( EMTPRespCodeOK, 1, &aNewHandle );
-//            else
-//                SendResponseL( responseCode );
-            }
-        else // It is a folder.
-            {
-            delete iPathToCopy;
-            iPathToCopy = NULL;
-            iPathToCopy = suid.AllocL();
-            PRINT1( _L( "MM MTP <> CCopyObject::CopyObjectL iPathToCopy = %S" ), iPathToCopy );
-            aNewHandle = CopyFolderL( newObjectName );
-            }
+        newHandle = CopyFileL( newObjectName );
+        SendResponseL( EMTPRespCodeOK, 1, &newHandle );
         }
     else
         SendResponseL( responseCode );
 
     CleanupStack::PopAndDestroy( &newObjectName ); // - newObjectName
     PRINT2( _L( "MM MTP <= CCopyObject::CopyObjectL responseCode = 0x%x, aNewHandle = 0x%x" ),
-            responseCode, aNewHandle );
+        responseCode,
+        newHandle );
     }
 
 // -----------------------------------------------------------------------------
@@ -337,30 +176,34 @@
 void CCopyObject::GetParametersL()
     {
     PRINT( _L( "MM MTP => CCopyObject::GetParametersL" ) );
+
     __ASSERT_DEBUG( iRequestChecker, Panic( EMmMTPDpRequestCheckNull ) );
 
     TUint32 objectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
     iStorageId = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
-    TUint32 parentObjectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter3 );
-    PRINT3( _L( "MM MTP <> CCopyObject::GetParametersL Object Hanlde = 0x%x, StorageId = 0x%x, Parent Handle = 0x%x" ),
-            objectHandle, iStorageId, parentObjectHandle );
+    iNewParentHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter3 );
+    PRINT3( _L( "MM MTP <> CCopyObject::GetParametersL Object Handle = 0x%x, StorageId = 0x%x, Parent Handle = 0x%x" ),
+        objectHandle,
+        iStorageId,
+        iNewParentHandle );
 
     // not taking owernship
     iObjectInfo = iRequestChecker->GetObjectInfo( objectHandle );
     __ASSERT_DEBUG( iObjectInfo, Panic( EMmMTPDpObjectNull ) );
 
-    if ( parentObjectHandle == 0 )
+    if ( iNewParentHandle == KMTPHandleNone )
         {
         SetDefaultParentObjectL();
         }
     else
         {
-        CMTPObjectMetaData* parentObjectInfo = iRequestChecker->GetObjectInfo( parentObjectHandle );
-        __ASSERT_DEBUG( parentObjectInfo, Panic( EMmMTPDpObjectNull ) );
+        CMTPObjectMetaData* parentObject = iRequestChecker->GetObjectInfo( iNewParentHandle );
+        __ASSERT_DEBUG( parentObject, Panic( EMmMTPDpObjectNull ) );
+
         delete iDest;
         iDest = NULL;
-        iDest = parentObjectInfo->DesC( CMTPObjectMetaData::ESuid ).AllocL();
-        iNewParentHandle = parentObjectHandle;
+        iDest = parentObject->DesC( CMTPObjectMetaData::ESuid ).AllocL();
+        PRINT1( _L( "MM MTP <> CMoveObject::GetParametersL iDest = %S" ), iDest );
         }
     PRINT( _L( "MM MTP <= CCopyObject::GetParametersL" ) );
     }
@@ -376,11 +219,11 @@
 
     delete iDest;
     iDest = NULL;
-    iDest = ( iFramework.StorageMgr().StorageL( iStorageId ).DesC(
-                CMTPStorageMetaData::EStorageSuid ) ).AllocL();
-    PRINT1( _L( "MM MTP <> CCopyObject::SetDefaultParentObjectL Destination location is %S" ), iDest );
+    iDest = iFramework.StorageMgr().StorageL( iStorageId ).DesC( CMTPStorageMetaData::EStorageSuid ).AllocL();
+
     iNewParentHandle = KMTPHandleNoParent;
-    PRINT( _L( "MM MTP <= CCopyObject::SetDefaultParentObjectL" ) );
+
+    PRINT1( _L( "MM MTP <= CCopyObject::SetDefaultParentObjectL, iDest = %S" ), iDest );
     }
 
 // -----------------------------------------------------------------------------
@@ -392,17 +235,18 @@
     const TDesC& aNewName ) const
     {
     PRINT2( _L( "MM MTP => CCopyObject::CanCopyObjectL aOldName = %S, aNewName = %S" ),
-            &aOldName, &aNewName );
+        &aOldName,
+        &aNewName );
     TMTPResponseCode result = EMTPRespCodeOK;
 
     TEntry fileEntry;
     User::LeaveIfError( iFramework.Fs().Entry( aOldName, fileEntry ) );
-    TDriveNumber drive( static_cast<TDriveNumber>( iFramework.StorageMgr().DriveNumber( iStorageId ) ) );
+    TInt drive = iFramework.StorageMgr().DriveNumber( iStorageId );
     User::LeaveIfError( drive );
     TVolumeInfo volumeInfo;
     User::LeaveIfError( iFramework.Fs().Volume( volumeInfo, drive ) );
 
-    if ( volumeInfo.iFree < fileEntry.iSize )
+    if ( volumeInfo.iFree < fileEntry.FileSize() )
         {
         result = EMTPRespCodeStoreFull;
         }
@@ -445,6 +289,37 @@
     }
 
 // -----------------------------------------------------------------------------
+// CCopyObject::CopyFileL
+// A helper function of CopyFileL
+// -----------------------------------------------------------------------------
+//
+TUint32 CCopyObject::CopyFileL( const TDesC& aNewFileName )
+    {
+    const TDesC& suid( iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
+    PRINT2( _L( "MM MTP => CCopyObject::CopyFileL old name = %S, aNewFileName = %S" ),
+        &suid,
+        &aNewFileName );
+
+    GetPreviousPropertiesL( *iObjectInfo );
+
+    TUint32 handle = AddObjectToStoreL( suid, aNewFileName );
+
+    SetPreviousPropertiesL( *iObjectInfo );
+
+    CFileMan* fileMan = CFileMan::NewL( iFramework.Fs() );
+    User::LeaveIfError( fileMan->Copy( suid, aNewFileName ) );
+    delete fileMan;
+    fileMan = NULL;
+
+    User::LeaveIfError( iFramework.Fs().SetModified( aNewFileName,
+        iPreviousModifiedTime ) );
+
+    PRINT1( _L( "MM MTP <= CCopyObject::CopyFileL handle = 0x%x" ), handle );
+
+    return handle;
+    }
+
+// -----------------------------------------------------------------------------
 // CCopyObject::GetPreviousPropertiesL
 // Save the object properties before doing the copy
 // -----------------------------------------------------------------------------
@@ -454,29 +329,27 @@
     PRINT( _L( "MM MTP => CCopyObject::GetPreviousPropertiesL" ) );
 
     const TDesC& suid( aObject.DesC( CMTPObjectMetaData::ESuid ) );
-
     User::LeaveIfError( iFramework.Fs().Modified( suid, iPreviousModifiedTime ) );
 
     TUint formatCode = aObject.Uint( CMTPObjectMetaData::EFormatCode );
     const RArray<TUint>* properties = iDpConfig.GetSupportedPropertiesL( formatCode );
     TInt count = properties->Count();
 
-    CMTPTypeString* textData = NULL;
     TInt err = KErrNone;
     TUint16 propCode;
-    TUint32 handle = aObject.Uint( CMTPObjectMetaData::EHandle ) ;
+    TUint32 handle = aObject.Uint( CMTPObjectMetaData::EHandle );
 
-    if ( iPropertyElement )
+    if ( iPropertyElement != NULL )
         {
         delete iPropertyElement;
         iPropertyElement = NULL;
         }
-    
+
     for ( TInt i = 0; i < count; i++ )
         {
-        propCode = (*properties)[i];
+        propCode = ( *properties )[i];
 
-        switch( propCode )
+        switch ( propCode )
             {
             case EMTPObjectPropCodeStorageID:
             case EMTPObjectPropCodeObjectFormat:
@@ -485,31 +358,35 @@
             case EMTPObjectPropCodeObjectFileName:
             case EMTPObjectPropCodeParentObject:
             case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
-            case EMTPObjectPropCodeNonConsumable:
             case EMTPObjectPropCodeDateCreated:
             case EMTPObjectPropCodeDateModified:
                 break;
 
+            case EMTPObjectPropCodeNonConsumable:
+                iPropertyElement = &( iPropertyList->ReservePropElemL( handle, propCode ) );
+                iPropertyElement->SetUint8L( CMTPTypeObjectPropListElement::EValue,
+                    aObject.Uint( CMTPObjectMetaData::ENonConsumable ) );
+                break;
+
             case EMTPObjectPropCodeName:
             case EMTPObjectPropCodeDateAdded:
                 if ( ( propCode == EMTPObjectPropCodeName )
-                   || ( ( !MmMtpDpUtility::IsVideoL( aObject.DesC( CMTPObjectMetaData::ESuid ), iFramework ) )
+                    || ( !MmMtpDpUtility::IsVideoL( aObject.DesC( CMTPObjectMetaData::ESuid ), iFramework )
                         && ( propCode == EMTPObjectPropCodeDateAdded ) ) )
                     {
-                    textData = CMTPTypeString::NewLC(); // + textData
+                    CMTPTypeString* textData = CMTPTypeString::NewLC(); // + textData
 
                     TRAP( err, iDpConfig.GetWrapperL().GetObjectMetadataValueL( propCode,
                         *textData,
                         aObject ) );
 
-                    PRINT1( _L( "MM MTP <> CCopyObject::GetPreviousPropertiesL::ServiceSpecificObjectPropertyL err = %d" ), err );
+                    PRINT1( _L( "MM MTP <> CCopyObject::GetPreviousPropertiesL err = %d" ), err );
 
                     if ( err == KErrNone )
                         {
-                        iPropertyElement = &(iPropertyList->ReservePropElemL(handle, propCode));
-                        iPropertyElement->SetStringL(CMTPTypeObjectPropListElement::EValue, textData->StringChars());
-//                        iPropertyElement = CMTPTypeObjectPropListElement::NewL(
-//                                handle, propCode, *textData );
+                        iPropertyElement = &( iPropertyList->ReservePropElemL( handle, propCode ) );
+                        iPropertyElement->SetStringL( CMTPTypeObjectPropListElement::EValue,
+                            textData->StringChars() );
                         }
                     else if ( err == KErrNotFound )
                         {
@@ -531,7 +408,7 @@
                 break;
             }
 
-        if ( iPropertyElement )
+        if ( iPropertyElement != NULL )
             {
             iPropertyList->CommitPropElemL( *iPropertyElement );
             iPropertyElement = NULL;
@@ -542,54 +419,6 @@
     }
 
 // -----------------------------------------------------------------------------
-// CCopyObject::ServiceMetaDataToWrapper
-//
-// -----------------------------------------------------------------------------
-//
-EXPORT_C TMTPResponseCode CCopyObject::ServiceMetaDataToWrapper(
-    const TUint16 aPropCode,
-    MMTPType& aNewData,
-    const CMTPObjectMetaData& aObject )
-    {
-    TMTPResponseCode resCode = EMTPRespCodeOK;
-
-    TRAPD( err, iDpConfig.GetWrapperL().SetObjectMetadataValueL( aPropCode,
-        aNewData,
-        aObject ) );
-
-    PRINT1( _L("MM MTP <> CCopyObject::ServiceMetaDataToWrapper err = %d"), err);
-
-    if ( err == KErrNone )
-        {
-        resCode = EMTPRespCodeOK;
-        }
-    else if ( err == KErrTooBig )
-        // according to the codes of S60
-        {
-        resCode = EMTPRespCodeInvalidDataset;
-        }
-    else if ( err == KErrPermissionDenied )
-        {
-        resCode = EMTPRespCodeAccessDenied;
-        }
-    else if ( err == KErrNotFound )
-        {
-        if ( MmMtpDpUtility::HasMetadata( aObject.Uint( CMTPObjectMetaData::EFormatCode ) ) )
-            resCode = EMTPRespCodeAccessDenied;
-        else
-            resCode = EMTPRespCodeOK;
-        }
-    else
-        {
-        resCode = EMTPRespCodeGeneralError;
-        }
-
-    PRINT1( _L("MM MTP <= CCopyObject::ServiceMetaDataToWrapper resCode = 0x%x"), resCode);
-
-    return resCode;
-    }
-
-// -----------------------------------------------------------------------------
 // CCopyObject::SetPreviousPropertiesL
 // Set the object properties after doing the copy
 // -----------------------------------------------------------------------------
@@ -597,23 +426,22 @@
 void CCopyObject::SetPreviousPropertiesL( const CMTPObjectMetaData& aObject )
     {
     PRINT( _L( "MM MTP => CCopyObject::SetPreviousPropertiesL" ) );
-    const TInt count( iPropertyList->NumberOfElements() );
-    PRINT1( _L( "MM MTP <> CCopyObject::SetPreviousPropertiesL count = %d" ), count );
+
     TMTPResponseCode respcode = EMTPRespCodeOK;
-    CMTPTypeString* stringData = NULL;
+
     iPropertyList->ResetCursor();
+    const TInt count = iPropertyList->NumberOfElements();
     for ( TInt i = 0; i < count; i++ )
         {
         CMTPTypeObjectPropListElement& element = iPropertyList->GetNextElementL();
 
-        TUint32 handle = element.Uint32L(
-                CMTPTypeObjectPropListElement::EObjectHandle );
-        TUint16 propertyCode = element.Uint16L(
-                CMTPTypeObjectPropListElement::EPropertyCode );
-        TUint16 dataType = element.Uint16L(
-                CMTPTypeObjectPropListElement::EDatatype );
+        TUint32 handle = element.Uint32L( CMTPTypeObjectPropListElement::EObjectHandle );
+        TUint16 propertyCode = element.Uint16L( CMTPTypeObjectPropListElement::EPropertyCode );
+        TUint16 dataType = element.Uint16L( CMTPTypeObjectPropListElement::EDatatype );
         PRINT3( _L( "MM MTP <> CCopyObject::SetPreviousPropertiesL = 0x%x, propertyCode = 0x%x, dataType = 0x%x" ),
-          handle, propertyCode, dataType );
+            handle,
+            propertyCode,
+            dataType );
 
         switch ( propertyCode )
             {
@@ -624,19 +452,26 @@
             case EMTPObjectPropCodeObjectFileName:
             case EMTPObjectPropCodeParentObject:
             case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
-            case EMTPObjectPropCodeNonConsumable:
             case EMTPObjectPropCodeDateCreated:
             case EMTPObjectPropCodeDateModified:
             case EMTPObjectPropCodeDateAdded:
                 break;
 
+            case EMTPObjectPropCodeNonConsumable:
+                iObjectInfo->SetUint( CMTPObjectMetaData::ENonConsumable,
+                    element.Uint8L( CMTPTypeObjectPropListElement::EValue ) );
+                // TODO: need to reconsider,
+                // should wait all property setting finished then insert object, or not?
+                // need to investigate if it will affect performance result
+                iFramework.ObjectMgr().ModifyObjectL( *iObjectInfo );
+                break;
+
             case EMTPObjectPropCodeName:
                 {
-                stringData = CMTPTypeString::NewLC(
-                    element.StringL(
-                    CMTPTypeObjectPropListElement::EValue)); // + stringData
+                CMTPTypeString *stringData = CMTPTypeString::NewLC( element.StringL( CMTPTypeObjectPropListElement::EValue ) ); // + stringData
 
-                respcode = ServiceMetaDataToWrapper( propertyCode,
+                respcode = iDpConfig.PropSettingUtility()->SetMetaDataToWrapperL( iDpConfig,
+                    propertyCode,
                     *stringData,
                     aObject );
 
@@ -646,18 +481,16 @@
 
             default:
                 {
-                respcode = ServiceSetSpecificObjectPropertyL( propertyCode,
-                        aObject,
-                        element );
+                respcode = iDpConfig.PropSettingUtility()->SetSpecificObjectPropertyL( iDpConfig,
+                    propertyCode,
+                    aObject,
+                    element );
                 }
                 break;
             }
         } // end of for loop
 
-    if( respcode == EMTPRespCodeOK )
-        {
-        // do nothing, ignore warning
-        }
+    // ignore errors
 
     PRINT1( _L( "MM MTP <= CCopyObject::SetPreviousPropertiesL respcode = 0x%x" ), respcode );
     }
@@ -667,168 +500,43 @@
 // Update object info in the database
 // -----------------------------------------------------------------------------
 //
-TUint32 CCopyObject::UpdateObjectInfoL( const TDesC& aOldObjectName, const TDesC& aNewObjectName )
+TUint32 CCopyObject::AddObjectToStoreL( const TDesC& aOldObjectName,
+    const TDesC& aNewObjectName )
     {
-    PRINT2( _L( "MM MTP => CCopyObject::UpdateObjectInfoL aOldObjectName = %S, aNewObjectName = %S" ),
-            &aOldObjectName, &aNewObjectName );
-    // We should not modify this object's handle, so just get a "copy".
+    PRINT2( _L( "MM MTP => CCopyObject::AddObjectToStoreL aOldObjectName = %S, aNewObjectName = %S" ),
+        &aOldObjectName,
+        &aNewObjectName );
+
     CMTPObjectMetaData* objectInfo = CMTPObjectMetaData::NewLC(); // + objectInfo
-    const TMTPTypeUint32 objectHandle( iObjectInfo->Uint( CMTPObjectMetaData::EHandle ) );
-    if ( iFramework.ObjectMgr().ObjectL( objectHandle, *objectInfo) )
+
+    // 1. Add new object into objectMgr db
+    objectInfo->SetUint( CMTPObjectMetaData::EDataProviderId, iObjectInfo->Uint( CMTPObjectMetaData::EDataProviderId ) );
+    TUint formatCode = iObjectInfo->Uint( CMTPObjectMetaData::EFormatCode );
+    objectInfo->SetUint( CMTPObjectMetaData::EFormatCode, formatCode );
+    TUint subFormatCode = iObjectInfo->Uint( CMTPObjectMetaData::EFormatSubCode );
+    objectInfo->SetUint( CMTPObjectMetaData::EFormatSubCode, subFormatCode );
+    objectInfo->SetUint( CMTPObjectMetaData::EParentHandle, iNewParentHandle );
+    objectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId );
+    objectInfo->SetDesCL( CMTPObjectMetaData::ESuid, aNewObjectName );
+    iFramework.ObjectMgr().InsertObjectL( *objectInfo );
+
+    // 2. Add new object into MPX db
+    iDpConfig.GetWrapperL().AddObjectL( aNewObjectName, formatCode, subFormatCode );
+
+    // 3. Set references into references db
+    if ( formatCode == EMTPFormatCodeM3UPlaylist )
         {
-        objectInfo->SetDesCL( CMTPObjectMetaData::ESuid, aNewObjectName );
-        objectInfo->SetUint( CMTPObjectMetaData::EParentHandle,
-                iNewParentHandle );
-        // Modify storage Id.
-        objectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId );
-        iFramework.ObjectMgr().InsertObjectL( *objectInfo );
-        }
-    else
-        {
-        User::Leave( KErrCorrupt );
+        MMTPReferenceMgr& referenceMgr = iFramework.ReferenceMgr();
+        CDesCArray* references = referenceMgr.ReferencesLC( aOldObjectName ); // + references
+        referenceMgr.SetReferencesL( aNewObjectName, *references );
+        CleanupStack::PopAndDestroy( references ); // - references
         }
 
     TUint32 handle = objectInfo->Uint( CMTPObjectMetaData::EHandle );
-    PRINT1( _L( "MM MTP <> CCopyObject::UpdateObjectInfoL handle = 0x%x" ), handle );
-    SetPropertiesL( aOldObjectName, aNewObjectName, *objectInfo );
     CleanupStack::PopAndDestroy( objectInfo ); // - objectInfo
-    PRINT( _L( "MM MTP <= CCopyObject::UpdateObjectInfoL" ) );
+
+    PRINT1( _L( "MM MTP <= CCopyObject::AddObjectToStoreL handle = 0x%x" ), handle );
     return handle;
     }
 
-// -----------------------------------------------------------------------------
-// CCopyObject::CopyAndUpdateL
-// Move a single object and update the database
-// -----------------------------------------------------------------------------
-//
-void CCopyObject::CopyAndUpdateL( TUint32 aObjectHandle )
-    {
-    PRINT1( _L( "MM MTP => CopyObject::CopyAndUpdateL aObjectHanlde = 0x%x" ), aObjectHandle );
-    CMTPObjectMetaData* objectInfo = CMTPObjectMetaData::NewLC(); // + objectInfo
-
-    if ( iFramework.ObjectMgr().ObjectL( aObjectHandle, *objectInfo ) )
-        {
-        // This is used to keep the same behavior in mass storage and device file manager.
-        if ( objectInfo->Uint( CMTPObjectMetaData::EFormatCode )
-            == EMTPFormatCodeAbstractAudioVideoPlaylist )
-            {
-            PRINT( _L( "MM MTP <> CopyObject::CopyAndUpdateL Playlist file don't to be copieds" ) );
-            CleanupStack::PopAndDestroy( objectInfo ); // - objectInfo
-            return;
-            }
-
-        RBuf fileName; // This is the source object name.
-        fileName.CleanupClosePushL(); // + fileName
-        fileName.CreateL( KMaxFileName );
-
-        RBuf oldFileName;
-        oldFileName.CleanupClosePushL(); // + oldFileName
-        oldFileName.CreateL( KMaxFileName );
-
-        RBuf rightPartName;
-        rightPartName.CleanupClosePushL(); // + rightPartName
-        rightPartName.CreateL( KMaxFileName );
-
-        fileName = objectInfo->DesC( CMTPObjectMetaData::ESuid );
-        oldFileName = fileName;
-
-        rightPartName = fileName.Right( fileName.Length()
-            - iPathToCopy->Length() );
-
-        if ( ( iNewRootFolder->Length() + rightPartName.Length() ) > fileName.MaxLength() )
-            {
-            User::Leave( KErrCorrupt );
-            }
-
-        fileName.Zero();
-        fileName.Append( *iNewRootFolder );
-        fileName.Append( rightPartName );
-        PRINT1( _L( "MM MTP <> CopyAndUpdateL fileName = %S" ), &fileName );
-
-        if ( objectInfo->Uint( CMTPObjectMetaData::EDataProviderId )
-            == iFramework.DataProviderId() )
-            {
-            // should copy before the set metadata DB
-            GetPreviousPropertiesL( *objectInfo );
-            TInt err = iFileMan->Copy( oldFileName, fileName );
-            PRINT1( _L( "MM MTP <> CCopyObject::CopyAndUpdateL err = %d" ), err );
-            User::LeaveIfError( err );
-            User::LeaveIfError( iFramework.Fs().SetModified( fileName,
-                iPreviousModifiedTime ) );
-
-            // Modify Suid
-            objectInfo->SetDesCL( CMTPObjectMetaData::ESuid, fileName );
-
-            // Modify parentHandle
-            TParsePtrC parentSuid( fileName );
-            PRINT1( _L( "MM MTP <> CCopyObject::CopyAndUpdateL parentSuid = %S" ), &(parentSuid.DriveAndPath()) );
-
-            TUint32 parentHandle = iFramework.ObjectMgr().HandleL( parentSuid.DriveAndPath() );
-            objectInfo->SetUint( CMTPObjectMetaData::EParentHandle, parentHandle );
-            PRINT1( _L( "MM MTP <> CCopyObject::CopyAndUpdateL parentHandle = 0x%x" ), parentHandle );
-
-            // Modify storage Id.
-            objectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId );
-            TRAP( err, iFramework.ObjectMgr().InsertObjectL( *objectInfo ) );
-            if ( err != KErrNone )
-                PRINT1( _L( "MM MTP <> CCopyObject::CopyAndUpdateL err = %d" ), err );
-            // Set the properties of the new object
-            SetPropertiesL( oldFileName, fileName, *objectInfo );
-            }
-        // Else this is not the owner of this object, so don't update the object store.
-
-        CleanupStack::PopAndDestroy( &rightPartName ); // - rightPartName
-        CleanupStack::PopAndDestroy( &oldFileName ); // - oldFileName
-        CleanupStack::PopAndDestroy( &fileName ); // - fileName
-        }
-    else
-        {
-        User::Leave( KErrCorrupt );
-        }
-
-    CleanupStack::PopAndDestroy( objectInfo ); // - objectInfo
-
-    PRINT( _L( "MM MTP <= CopyObject::CopyAndUpdateL" ) );
-    }
-
-// -----------------------------------------------------------------------------
-// CCopyObject::SetPropertiesL
-// Set the object properties in the object property store
-// -----------------------------------------------------------------------------
-//
-void CCopyObject::SetPropertiesL( const TDesC& aOldFileName,
-        const TDesC& aNewFileName,
-        const CMTPObjectMetaData& aObject )
-    {
-    PRINT( _L( "MM MTP => CCopyObject::SetPropertiesL" ) );
-    // won't leave with KErrAlreadyExist
-    iDpConfig.GetWrapperL().AddObjectL( aNewFileName );
-
-    TUint formatCode = aObject.Uint( CMTPObjectMetaData::EFormatCode );
-    if ( formatCode == EMTPFormatCodeM3UPlaylist )
-        {
-        MMTPReferenceMgr& referenceMgr = iFramework.ReferenceMgr();
-        CDesCArray* references = referenceMgr.ReferencesLC( aOldFileName ); // + references
-        referenceMgr.SetReferencesL( aNewFileName, *references );
-        CleanupStack::PopAndDestroy( references ); // - references
-        }
-
-    SetPreviousPropertiesL( aObject );
-    PRINT( _L( "MM MTP <= CCopyObject::SetPropertiesL" ) );
-    }
-
-// -----------------------------------------------------------------------------
-// CCopyObject::RunError
-//
-// -----------------------------------------------------------------------------
-//
-EXPORT_C TInt CCopyObject::RunError( TInt aError )
-    {
-    if ( aError != KErrNone )
-        PRINT1( _L( "MM MTP <> CCopyObject::RunError aError = %d" ), aError );
-
-    TRAP_IGNORE( SendResponseL( EMTPRespCodeGeneralError ) );
-    return KErrNone;
-    }
-
 // end of file