mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/csendobject.cpp
changeset 32 edd273b3192a
parent 27 cbb1bfb7ebfb
child 35 2ee890d2f7e7
equal deleted inserted replaced
27:cbb1bfb7ebfb 32:edd273b3192a
    30 #include "tmmmtpdppanic.h"
    30 #include "tmmmtpdppanic.h"
    31 #include "mmmtpdplogger.h"
    31 #include "mmmtpdplogger.h"
    32 #include "cpropertysettingutility.h"
    32 #include "cpropertysettingutility.h"
    33 #include "cmmmtpdpmetadataaccesswrapper.h"
    33 #include "cmmmtpdpmetadataaccesswrapper.h"
    34 
    34 
       
    35 const TInt KMtpRollbackFuncCnt = 3;
       
    36 
    35 // Verification data for the SendObjectInfo request
    37 // Verification data for the SendObjectInfo request
    36 const TMTPRequestElementInfo KMTPSendObjectInfoPolicy[] =
    38 const TMTPRequestElementInfo KMTPSendObjectInfoPolicy[] =
    37     {
    39     {
    38         {
    40         {
    39         TMTPTypeRequest::ERequestParameter1,
    41         TMTPTypeRequest::ERequestParameter1,
    77 // Destructor
    79 // Destructor
    78 // -----------------------------------------------------------------------------
    80 // -----------------------------------------------------------------------------
    79 //
    81 //
    80 EXPORT_C CSendObject::~CSendObject()
    82 EXPORT_C CSendObject::~CSendObject()
    81     {
    83     {
    82     if ( !iNoRollback )
    84     Rollback();
    83         {
    85     iRollbackList.Close();
    84         // Not finished SendObjectInfo \ SendObject pair detected.
       
    85         Rollback();
       
    86         PRINT( _L( "MM MTP <> CSendObject::~CSendObject, Rollback" ) );
       
    87         }
       
    88 
    86 
    89     delete iFileReceived;
    87     delete iFileReceived;
    90     delete iParentSuid;
    88     delete iParentSuid;
    91     delete iObjectInfo;
    89     delete iObjectInfo;
    92     delete iObjectPropList;
    90     delete iObjectPropList;
   105     MMTPConnection& aConnection,
   103     MMTPConnection& aConnection,
   106     MMmMtpDpConfig& aDpConfig ) :
   104     MMmMtpDpConfig& aDpConfig ) :
   107         CRequestProcessor( aFramework, aConnection, 0, NULL ),
   105         CRequestProcessor( aFramework, aConnection, 0, NULL ),
   108         iFs( iFramework.Fs() ),
   106         iFs( iFramework.Fs() ),
   109         iObjectMgr( iFramework.ObjectMgr() ),
   107         iObjectMgr( iFramework.ObjectMgr() ),
   110         iDpConfig( aDpConfig )
   108         iDpConfig( aDpConfig ),
       
   109         iRollbackList( KMtpRollbackFuncCnt )
   111     {
   110     {
   112     PRINT( _L( "Operation: SendObjectInfo/SendObject/SendObjectPropList(0x100C/0x100D/0x9808)" ) );
   111     PRINT( _L( "Operation: SendObjectInfo/SendObject/SendObjectPropList(0x100C/0x100D/0x9808)" ) );
   113     }
   112     }
   114 
   113 
   115 // -----------------------------------------------------------------------------
   114 // -----------------------------------------------------------------------------
   128     iReceivedObjectInfo->SetUint( CMTPObjectMetaData::EDataProviderId,
   127     iReceivedObjectInfo->SetUint( CMTPObjectMetaData::EDataProviderId,
   129         iFramework.DataProviderId() );
   128         iFramework.DataProviderId() );
   130 
   129 
   131     PRINT1( _L( "MM MTP <> CSendObject::ConstructL DataProviderId = 0x%x" ), iFramework.DataProviderId());
   130     PRINT1( _L( "MM MTP <> CSendObject::ConstructL DataProviderId = 0x%x" ), iFramework.DataProviderId());
   132 
   131 
   133     iNoRollback = EFalse;
   132   
   134 
       
   135     SetPSStatus();
       
   136     PRINT( _L( "MM MTP <= CSendObject::ConstructL" ) );
   133     PRINT( _L( "MM MTP <= CSendObject::ConstructL" ) );
   137     }
   134     }
   138 
   135 
   139 // -----------------------------------------------------------------------------
   136 // -----------------------------------------------------------------------------
   140 // CSendObject::Match
   137 // CSendObject::Match
   298 
   295 
   299             if ( IsTooLarge( iObjectSize ) )
   296             if ( IsTooLarge( iObjectSize ) )
   300                 {
   297                 {
   301                 responseCode = EMTPRespCodeObjectTooLarge;
   298                 responseCode = EMTPRespCodeObjectTooLarge;
   302                 }
   299                 }
   303 
       
   304             if ( ( responseCode != EMTPRespCodeOK ) && !CanStoreFileL( iStorageId, iObjectSize ) )
       
   305                 {
       
   306                 responseCode = EMTPRespCodeStoreFull;
       
   307                 }
       
   308             }
   300             }
   309         }
   301         }
   310 
   302 
   311     PRINT1( _L( "MM MTP <= CSendObject::CheckRequestL, responseCode = 0x%x" ), responseCode );
   303     PRINT1( _L( "MM MTP <= CSendObject::CheckRequestL, responseCode = 0x%x" ), responseCode );
   312     return responseCode;
   304     return responseCode;
   330 // -----------------------------------------------------------------------------
   322 // -----------------------------------------------------------------------------
   331 //
   323 //
   332 EXPORT_C void CSendObject::ServiceL()
   324 EXPORT_C void CSendObject::ServiceL()
   333     {
   325     {
   334     PRINT( _L( "MM MTP => CSendObject::ServiceL" ) );
   326     PRINT( _L( "MM MTP => CSendObject::ServiceL" ) );
       
   327     
       
   328     MmMtpDpUtility::SetPSStatus(EMtpPSStatusActive);
   335 
   329 
   336     if ( iProgress == EObjectNone )
   330     if ( iProgress == EObjectNone )
   337         {
   331         {
   338         if ( iOperationCode == EMTPOpCodeSendObjectInfo )
   332         if ( iOperationCode == EMTPOpCodeSendObjectInfo )
   339             {
   333             {
   390 // -----------------------------------------------------------------------------
   384 // -----------------------------------------------------------------------------
   391 //
   385 //
   392 void CSendObject::ServiceObjectL()
   386 void CSendObject::ServiceObjectL()
   393     {
   387     {
   394     PRINT( _L( "MM MTP => CSendObject::ServiceObjectL" ) );
   388     PRINT( _L( "MM MTP => CSendObject::ServiceObjectL" ) );
   395 
       
   396     delete iFileReceived;
       
   397     iFileReceived = NULL;
       
   398 
       
   399     PRINT2( _L( "MM MTP <> CSendObject::ServiceObjectL, iFullPath is %S, iObjectSize: %Lu" ), &iFullPath, iObjectSize );
       
   400     TRAPD( err, iFileReceived = CMTPTypeFile::NewL( iFs,
       
   401         iFullPath,
       
   402         EFileWrite ) );
       
   403 
       
   404     PRINT1( _L("MM MTP <> CSendObject::ServiceObjectL, Leave Code is: %d"), err );
       
   405     User::LeaveIfError( err );
       
   406 
       
   407     iFileReceived->SetSizeL( iObjectSize );
       
   408 
       
   409     ReceiveDataL( *iFileReceived );
   389     ReceiveDataL( *iFileReceived );
   410 
       
   411     iProgress = ESendObjectInProgress;
   390     iProgress = ESendObjectInProgress;
   412 
   391 
   413     PRINT( _L( "MM MTP <= CSendObject::ServiceObjectL" ) );
   392     PRINT( _L( "MM MTP <= CSendObject::ServiceObjectL" ) );
   414     }
   393     }
   415 
   394 
   477     PRINT1( _L("MM MTP <> CSendObject::DoHandleResponsePhaseInfoL, iObjectSize = %Lu"), iObjectSize );
   456     PRINT1( _L("MM MTP <> CSendObject::DoHandleResponsePhaseInfoL, iObjectSize = %Lu"), iObjectSize );
   478 
   457 
   479     if ( IsTooLarge( iObjectSize ) )
   458     if ( IsTooLarge( iObjectSize ) )
   480         {
   459         {
   481         SendResponseL( EMTPRespCodeObjectTooLarge );
   460         SendResponseL( EMTPRespCodeObjectTooLarge );
   482         result = EFalse;
   461         Rollback();
   483         }
       
   484 
       
   485     if ( result && !CanStoreFileL( iStorageId, iObjectSize ) )
       
   486         {
       
   487         SendResponseL( EMTPRespCodeStoreFull );
       
   488         result = EFalse;
   462         result = EFalse;
   489         }
   463         }
   490 
   464 
   491     if ( result )
   465     if ( result )
   492         {
   466         {
   494         PRINT1( _L( "MM MTP <> CSendObject::DoHandleResponsePhaseInfoL iProtectionStatus = %d" ), iProtectionStatus );
   468         PRINT1( _L( "MM MTP <> CSendObject::DoHandleResponsePhaseInfoL iProtectionStatus = %d" ), iProtectionStatus );
   495         if ( iProtectionStatus != EMTPProtectionNoProtection
   469         if ( iProtectionStatus != EMTPProtectionNoProtection
   496             && iProtectionStatus != EMTPProtectionReadOnly )
   470             && iProtectionStatus != EMTPProtectionReadOnly )
   497             {
   471             {
   498             SendResponseL( EMTPRespCodeParameterNotSupported );
   472             SendResponseL( EMTPRespCodeParameterNotSupported );
       
   473             Rollback();
   499             result = EFalse;
   474             result = EFalse;
   500             }
   475             }
   501         }
   476         }
   502 
   477 
   503     if ( result )
   478     if ( result )
   505         result = GetFullPathNameL( iObjectInfo->StringCharsL( CMTPTypeObjectInfo::EFilename ) );
   480         result = GetFullPathNameL( iObjectInfo->StringCharsL( CMTPTypeObjectInfo::EFilename ) );
   506         if ( !result )
   481         if ( !result )
   507             {
   482             {
   508             // File and/or parent pathname invalid.
   483             // File and/or parent pathname invalid.
   509             SendResponseL( EMTPRespCodeInvalidDataset );
   484             SendResponseL( EMTPRespCodeInvalidDataset );
       
   485             Rollback();
   510             }
   486             }
   511         }
   487         }
   512 
   488 
   513     if ( result )
   489     if ( result )
   514         {
   490         {
   515         if ( ExistsL( iFullPath ) )
   491         if ( ExistsL( iFullPath ) )
   516             {
   492             {
   517             // Object with the same name already exists.
       
   518             iNoRollback = ETrue;
       
   519             SendResponseL( EMTPRespCodeAccessDenied );
   493             SendResponseL( EMTPRespCodeAccessDenied );
       
   494             Rollback();
   520             result = EFalse;
   495             result = EFalse;
   521             }
   496             }
   522         }
   497         }
   523 
   498 
   524     if ( result )
   499     if ( result )
   525         ReserveObjectL();
   500         {
   526 
   501         if ( KErrNone != ReserveObjectL() )
       
   502             {
       
   503             result = EFalse;
       
   504             }
       
   505         }
   527     PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseInfoL result = %d" ), result );
   506     PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseInfoL result = %d" ), result );
   528 
   507 
   529     return result;
   508     return result;
   530     }
   509     }
   531 
   510 
   540 
   519 
   541     TMTPResponseCode responseCode = EMTPRespCodeOK;
   520     TMTPResponseCode responseCode = EMTPRespCodeOK;
   542 
   521 
   543     TInt invalidParameterIndex = KErrNotFound;
   522     TInt invalidParameterIndex = KErrNotFound;
   544     responseCode = VerifyObjectPropListL( invalidParameterIndex );
   523     responseCode = VerifyObjectPropListL( invalidParameterIndex );
       
   524     TInt err = KErrNone;
   545 
   525 
   546     if ( responseCode != EMTPRespCodeOK )
   526     if ( responseCode != EMTPRespCodeOK )
   547         {
   527         {
   548         TUint32 parameters[4];
   528         TUint32 parameters[4];
   549         parameters[0] = 0;
   529         parameters[0] = 0;
   550         parameters[1] = 0;
   530         parameters[1] = 0;
   551         parameters[2] = 0;
   531         parameters[2] = 0;
   552         parameters[3] = invalidParameterIndex;
   532         parameters[3] = invalidParameterIndex;
   553         SendResponseL( responseCode, 4, parameters );
   533         SendResponseL( responseCode, 4, parameters );
       
   534         Rollback();
   554         }
   535         }
   555     else if ( ExistsL( iFullPath ) )
   536     else if ( ExistsL( iFullPath ) )
   556         {
   537         {
   557         // Object with the same name already exists.
       
   558         iNoRollback = ETrue;
       
   559         SendResponseL( EMTPRespCodeAccessDenied );
   538         SendResponseL( EMTPRespCodeAccessDenied );
       
   539         Rollback();
   560         }
   540         }
   561     else
   541     else
   562         ReserveObjectL();
   542         err = ReserveObjectL();
   563 
   543 
   564     PRINT( _L( "MM MTP <= CSendObject::DoHandleResponsePhasePropListL" ) );
   544     PRINT( _L( "MM MTP <= CSendObject::DoHandleResponsePhasePropListL" ) );
   565     return ( responseCode == EMTPRespCodeOK );
   545     return ( responseCode == EMTPRespCodeOK && err == KErrNone);
   566     }
   546     }
   567 
   547 
   568 // -----------------------------------------------------------------------------
   548 // -----------------------------------------------------------------------------
   569 // CSendObject::DoHandleResponsePhaseObjectL
   549 // CSendObject::DoHandleResponsePhaseObjectL
   570 // SendObject
   550 // SendObject
   574     {
   554     {
   575     PRINT( _L( "MM MTP => CSendObject::DoHandleResponsePhaseObjectL" ) );
   555     PRINT( _L( "MM MTP => CSendObject::DoHandleResponsePhaseObjectL" ) );
   576 
   556 
   577     TBool result = ETrue;
   557     TBool result = ETrue;
   578 
   558 
       
   559     TEntry fileEntry;
       
   560     User::LeaveIfError( iFs.Entry( iFullPath, fileEntry ) );
       
   561     if ( fileEntry.FileSize() != iObjectSize )
       
   562         {
       
   563         iFs.Delete( iFullPath );
       
   564         iObjectMgr.UnreserveObjectHandleL( *iReceivedObjectInfo );
       
   565         TMTPResponseCode responseCode = EMTPRespCodeObjectTooLarge;
       
   566         if ( fileEntry.FileSize() < iObjectSize )
       
   567             {
       
   568             responseCode = EMTPRespCodeIncompleteTransfer;
       
   569             }
       
   570         SendResponseL( responseCode );
       
   571         Rollback();
       
   572         result = EFalse;
       
   573         }
       
   574 
   579     // SendObject is cancelled or connection is dropped.
   575     // SendObject is cancelled or connection is dropped.
   580     if ( iCancelled )
   576     if ( result && iCancelled )
   581         {
   577         {
   582         // In SendObject response phase, unregister is not necessary.
       
   583         // But there's no harm, still keep it here.
       
   584         iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest,
   578         iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest,
   585             iConnection );
   579             iConnection );
   586 
   580         SendResponseL( EMTPRespCodeTransactionCancelled );
   587         Rollback();
   581         Rollback();
   588         SendResponseL( EMTPRespCodeTransactionCancelled );
   582         }
   589         }
   583     else if ( result && !iCancelled )
   590     else
   584         {
   591         {
   585         if ( iObjectSize > 0 ) // media file
   592         TEntry fileEntry;
   586             {
   593         User::LeaveIfError( iFs.Entry( iFullPath, fileEntry ) );
   587             TRAPD( err, AddMediaToStoreL() );
   594 
   588             PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL err = %d" ), err );
   595         if ( fileEntry.FileSize() != iObjectSize )
   589 
   596             {
   590             if ( ( iPreviousOperation == EMTPOpCodeSendObjectPropList )
   597             Rollback();
   591                 && ( err == KErrNone ) )
   598             TMTPResponseCode responseCode = EMTPRespCodeObjectTooLarge;
   592                 {
   599             if ( fileEntry.FileSize() < iObjectSize )
   593                 // Only leave when getting proplist element from data received by fw.
   600                 {
   594                 // It should not happen after ReceiveDataL in which construction of proplist already succeed.
   601                 responseCode = EMTPRespCodeIncompleteTransfer;
   595                 SetObjectPropListL();
   602                 }
   596                 }
   603             SendResponseL( responseCode );
   597 
   604             result = EFalse;
   598             // Commits into MTP data object enumeration store the object handle and
   605             }
   599             // storage space previously reserved for the specified object.
   606         else
   600             iFramework.ObjectMgr().CommitReservedObjectHandleL( *iReceivedObjectInfo );
   607             {
   601             iRollbackList.Append( &CSendObject::RemoveObjectFromDbL );
   608             if ( iObjectSize > 0 ) // media file
   602             }
   609                 {
   603 
   610                 TRAPD( err, AddMediaToStoreL() );
   604         // Commit object to MTP data store
   611                 PRINT1( _L( "MM MTP <> CSendObject::DoHandleResponsePhaseObjectL err = %d" ), err );
   605         iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest,
   612 
   606             iConnection );
   613                 if ( ( iPreviousOperation == EMTPOpCodeSendObjectPropList )
   607 
   614                     && ( err == KErrNone ) )
   608         SendResponseL( EMTPRespCodeOK );
   615                     {
       
   616                     // Only leave when getting proplist element from data received by fw.
       
   617                     // It should not happen after ReceiveDataL in which construction of proplist already succeed.
       
   618                     SetObjectPropListL();
       
   619                     }
       
   620 
       
   621                 // Commits into MTP data object enumeration store the object handle and
       
   622                 // storage space previously reserved for the specified object.
       
   623                 iFramework.ObjectMgr().CommitReservedObjectHandleL( *iReceivedObjectInfo );
       
   624                 }
       
   625 
       
   626             // In SendObject response phase, unregister is not necessary.
       
   627             // But there's no harm, still keep it here.
       
   628             iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest,
       
   629                 iConnection );
       
   630 
       
   631             SendResponseL( EMTPRespCodeOK );
       
   632             }
       
   633         }
   609         }
   634 
   610 
   635     PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL result = %d" ), result );
   611     PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL result = %d" ), result );
   636 
   612 
   637     return result;
   613     return result;
   658         {
   634         {
   659         //Sending Object failed, but still do not delete request, can try again with current info
   635         //Sending Object failed, but still do not delete request, can try again with current info
   660         iProgress = EObjectInfoSucceed;
   636         iProgress = EObjectInfoSucceed;
   661         result = EFalse;
   637         result = EFalse;
   662         }
   638         }
       
   639 
       
   640     if ( result )
       
   641         iRollbackList.Reset();
   663 
   642 
   664     PRINT2( _L( "MM MTP <= CSendObject::DoHandleCompletingPhaseL iProgress= %d, result = %d" ),
   643     PRINT2( _L( "MM MTP <= CSendObject::DoHandleCompletingPhaseL iProgress= %d, result = %d" ),
   665         iProgress,
   644         iProgress,
   666         result );
   645         result );
   667 
   646 
  1040     TBool ret = ( aObjectSize > KMaxSupportedFileSize );
  1019     TBool ret = ( aObjectSize > KMaxSupportedFileSize );
  1041     PRINT2( _L( "MM MTP <> CSendObject::IsTooLarge aObjectSize = 0x%Lx, ret = %d" ), aObjectSize, ret );
  1020     PRINT2( _L( "MM MTP <> CSendObject::IsTooLarge aObjectSize = 0x%Lx, ret = %d" ), aObjectSize, ret );
  1042     return ret;
  1021     return ret;
  1043     }
  1022     }
  1044 
  1023 
  1045 // -----------------------------------------------------------------------------
       
  1046 // CSendObject::CanStoreFileL
       
  1047 // Check if we can store the file on the storage
       
  1048 // @return ETrue if yes, otherwise EFalse
       
  1049 // -----------------------------------------------------------------------------
       
  1050 //
       
  1051 TBool CSendObject::CanStoreFileL( TUint32 aStorageId,
       
  1052     TInt64 aObjectSize ) const
       
  1053     {
       
  1054     PRINT( _L( "MM MTP => CSendObject::CanStoreFileL" ) );
       
  1055 
       
  1056     TBool result = ETrue;
       
  1057     TVolumeInfo volumeInfo;
       
  1058     TInt driveNo = iFramework.StorageMgr().DriveNumber( aStorageId );
       
  1059     User::LeaveIfError( iFs.Volume( volumeInfo, driveNo ) );
       
  1060 
       
  1061     if ( volumeInfo.iFree < aObjectSize )
       
  1062         {
       
  1063         result = EFalse;
       
  1064         }
       
  1065 
       
  1066     PRINT1( _L( "MM MTP <= CSendObject::CanStoreFileL , result = %d" ), result );
       
  1067 
       
  1068     return result;
       
  1069     }
       
  1070 
  1024 
  1071 // -----------------------------------------------------------------------------
  1025 // -----------------------------------------------------------------------------
  1072 // CSendObject::GetFullPathNameL
  1026 // CSendObject::GetFullPathNameL
  1073 // Get the full path name of the object to be saved
  1027 // Get the full path name of the object to be saved
  1074 // @param aFileName, on entry, contains the file name of the object,
  1028 // @param aFileName, on entry, contains the file name of the object,
  1169 
  1123 
  1170 // -----------------------------------------------------------------------------
  1124 // -----------------------------------------------------------------------------
  1171 // CSendObject::ReserveObjectL
  1125 // CSendObject::ReserveObjectL
  1172 // -----------------------------------------------------------------------------
  1126 // -----------------------------------------------------------------------------
  1173 //
  1127 //
  1174 void CSendObject::ReserveObjectL()
  1128 TInt CSendObject::ReserveObjectL()
  1175     {
  1129     {
  1176     PRINT( _L( "MM MTP => CSendObject::ReserveObjectL" ) );
  1130     PRINT( _L( "MM MTP => CSendObject::ReserveObjectL" ) );
  1177     TInt err = KErrNone;
  1131     TInt err = KErrNone;
  1178 
  1132 
  1179     iReceivedObjectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId );
  1133     iReceivedObjectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId );
  1185 
  1139 
  1186     // Reserves space for and assigns an object handle to the object described
  1140     // Reserves space for and assigns an object handle to the object described
  1187     // by the specified object information record.
  1141     // by the specified object information record.
  1188     TRAP( err, iObjectMgr.ReserveObjectHandleL( *iReceivedObjectInfo,
  1142     TRAP( err, iObjectMgr.ReserveObjectHandleL( *iReceivedObjectInfo,
  1189         iObjectSize ) );
  1143         iObjectSize ) );
       
  1144     iRollbackList.Append( &CSendObject::UnreserveObjectL );
  1190 
  1145 
  1191     PRINT2( _L( "MM MTP => CSendObject::ReserveObjectL iObjectsize = %Lu, Operation: 0x%x" ), iObjectSize, iOperationCode );
  1146     PRINT2( _L( "MM MTP => CSendObject::ReserveObjectL iObjectsize = %Lu, Operation: 0x%x" ), iObjectSize, iOperationCode );
  1192     if ( err != KErrNone )
  1147     if ( err != KErrNone )
  1193         PRINT1( _L( "MM MTP <> CSendObject::ReserveObjectL err = %d" ), err );
  1148         {
  1194     if ( iObjectSize == 0 )
  1149         PRINT1( _L( "MM MTP <> ReserveObjectHandleL err = %d" ), err );
       
  1150         }
       
  1151 
       
  1152     if ( err == KErrNone )
       
  1153         {
       
  1154         delete iFileReceived;
       
  1155         iFileReceived = NULL;
       
  1156         PRINT2( _L( "MM MTP <> CSendObject::ServiceObjectL, iFullPath is %S, iObjectSize: %Lu" ), &iFullPath, iObjectSize );
       
  1157         iRollbackList.Append( &CSendObject::RemoveObjectFromFs );
       
  1158         TRAP( err, iFileReceived = CMTPTypeFile::NewL( iFs, iFullPath, EFileWrite ) );
       
  1159 
       
  1160         PRINT1( _L("MM MTP <> CMTPTypeFile::NewL Leave Code is: %d"), err );
       
  1161         }
       
  1162 
       
  1163     if ( err == KErrNone )
       
  1164         {
       
  1165         TRAP( err, iFileReceived->SetSizeL( iObjectSize ) );
       
  1166         PRINT1( _L( "MM MTP <> SetSizeL leave code:%d" ), err );
       
  1167         if ( err == KErrDiskFull )
       
  1168             {
       
  1169             SendResponseL( EMTPRespCodeStoreFull );
       
  1170             Rollback();
       
  1171             return err;
       
  1172             }
       
  1173         }
       
  1174 
       
  1175     if ( err == KErrNone && iObjectSize == 0 )
  1195         {
  1176         {
  1196         // Already trapped inside SaveEmptyFileL.
  1177         // Already trapped inside SaveEmptyFileL.
  1197         SaveEmptyFileL();
  1178         SaveEmptyFileL();
  1198         if( iOperationCode == EMTPOpCodeSendObjectPropList )
  1179         if ( iOperationCode == EMTPOpCodeSendObjectPropList )
  1199             {
  1180             {
  1200             // Only leave when getting proplist element from data received by fw.
  1181             // Only leave when getting proplist element from data received by fw.
  1201             // It should not happen after ReceiveDataL in which construction of proplist already succeed.
  1182             // It should not happen after ReceiveDataL in which construction of proplist already succeed.
  1202             SetObjectPropListL();
  1183             SetObjectPropListL();
  1203             }
  1184             }
  1204 
  1185 
  1205         iObjectMgr.CommitReservedObjectHandleL( *iReceivedObjectInfo );
  1186         iObjectMgr.CommitReservedObjectHandleL( *iReceivedObjectInfo );
  1206         }
  1187         iRollbackList.Reset();
  1207 
  1188         }
  1208     iExpectedSendObjectRequest.SetUint32( TMTPTypeRequest::ERequestSessionID,
  1189 
  1209         iSessionId );
  1190     if ( err == KErrNone )
  1210     iFramework.RouteRequestRegisterL( iExpectedSendObjectRequest, iConnection );
  1191         {
  1211 
  1192         iExpectedSendObjectRequest.SetUint32( TMTPTypeRequest::ERequestSessionID, iSessionId );
  1212     TUint32 parameters[3];
  1193         iFramework.RouteRequestRegisterL( iExpectedSendObjectRequest, iConnection );
  1213     parameters[0] = iStorageId;
  1194 
  1214     parameters[1] = iParentHandle;
  1195         TUint32 parameters[3];
  1215     parameters[2] = iReceivedObjectInfo->Uint( CMTPObjectMetaData::EHandle );
  1196         parameters[0] = iStorageId;
  1216     SendResponseL( EMTPRespCodeOK, 3, parameters );
  1197         parameters[1] = iParentHandle;
       
  1198         parameters[2] = iReceivedObjectInfo->Uint( CMTPObjectMetaData::EHandle );
       
  1199         SendResponseL( EMTPRespCodeOK, 3, parameters );
       
  1200         }
       
  1201     else
       
  1202         {
       
  1203         SendResponseL( EMTPRespCodeGeneralError );
       
  1204         Rollback();
       
  1205         }
  1217 
  1206 
  1218     PRINT( _L( "MM MTP <= CSendObject::ReserveObjectL" ) );
  1207     PRINT( _L( "MM MTP <= CSendObject::ReserveObjectL" ) );
       
  1208     return err;
  1219     }
  1209     }
  1220 
  1210 
  1221 // -----------------------------------------------------------------------------
  1211 // -----------------------------------------------------------------------------
  1222 // CSendObject::SetProtectionStatus
  1212 // CSendObject::SetProtectionStatus
  1223 // -----------------------------------------------------------------------------
  1213 // -----------------------------------------------------------------------------
  1246                 PRINT1( _L("MM MTP <> CSendObject::SetProtectionStatus err = %d" ), err );
  1236                 PRINT1( _L("MM MTP <> CSendObject::SetProtectionStatus err = %d" ), err );
  1247                 }
  1237                 }
  1248             }
  1238             }
  1249         // Close the file after SetProtectionStatus to make sure other process won't open
  1239         // Close the file after SetProtectionStatus to make sure other process won't open
  1250         // the file successfully right at the time calling RFile::SetAtt.
  1240         // the file successfully right at the time calling RFile::SetAtt.
  1251         delete iFileReceived;
  1241         if ( iObjectSize > 0 )
  1252         iFileReceived = NULL;
  1242             {
       
  1243             delete iFileReceived;
       
  1244             iFileReceived = NULL;
       
  1245             }
       
  1246         else
       
  1247             iFileReceived->File().Close();
  1253         }
  1248         }
  1254 
  1249 
  1255     PRINT( _L( "MM MTP <= CSendObject::SetProtectionStatus" ) );
  1250     PRINT( _L( "MM MTP <= CSendObject::SetProtectionStatus" ) );
  1256     }
  1251     }
  1257 
  1252 
  1261 //
  1256 //
  1262 void CSendObject::SaveEmptyFileL()
  1257 void CSendObject::SaveEmptyFileL()
  1263     {
  1258     {
  1264     PRINT( _L( "MM MTP => CSendObject::SaveEmptyFileL" ) );
  1259     PRINT( _L( "MM MTP => CSendObject::SaveEmptyFileL" ) );
  1265 
  1260 
  1266     RFile file;
       
  1267     User::LeaveIfError( file.Create( iFs, iFullPath, EFileWrite ) );
       
  1268     CleanupClosePushL( file );  // + file
       
  1269 
       
  1270     if ( EMTPFormatCodeAbstractAudioVideoPlaylist == iObjectFormat )
  1261     if ( EMTPFormatCodeAbstractAudioVideoPlaylist == iObjectFormat )
  1271         {
  1262         {
  1272         TInt err = KErrNone;
  1263         TInt err = iFileReceived->File().SetAtt( KEntryAttSystem | KEntryAttHidden,
  1273         err = file.SetAtt( KEntryAttSystem | KEntryAttHidden,
       
  1274             KEntryAttReadOnly | KEntryAttNormal );
  1264             KEntryAttReadOnly | KEntryAttNormal );
  1275         if ( err != KErrNone )
  1265         if ( err != KErrNone )
  1276             PRINT1( _L( "MM MTP <> CSendObject::SaveEmptyFileL err = %d" ), err );
  1266             PRINT1( _L( "MM MTP <> CSendObject::SaveEmptyFileL err = %d" ), err );
  1277         iDpConfig.GetWrapperL().AddDummyFileL( iFullPath );
  1267         iDpConfig.GetWrapperL().AddDummyFileL( iFullPath );
  1278         }
  1268         }
  1279     CleanupStack::PopAndDestroy( &file );   // - file
       
  1280 
  1269 
  1281     // add playlist to MPX DB
  1270     // add playlist to MPX DB
  1282     TRAPD( err, AddMediaToStoreL() );
  1271     TRAPD( err, AddMediaToStoreL() );
  1283 
  1272 
  1284     if ( err != KErrNone )
  1273     if ( err != KErrNone )
  1285         {
  1274         iRollbackList.Append( &CSendObject::RemoveObjectFromDbL );
  1286         // Ignore err even add into MPX get failed.
  1275     else
  1287         }
  1276         iRollbackList.Reset();
  1288 
  1277 
  1289     PRINT1( _L( "MM MTP <= CSendObject::SaveEmptyFileLerr = %d" ), err );
  1278     PRINT1( _L( "MM MTP <= CSendObject::SaveEmptyFileL err = %d" ), err );
  1290     }
  1279     }
  1291 
  1280 
  1292 // -----------------------------------------------------------------------------
  1281 // -----------------------------------------------------------------------------
  1293 // CSendObject::AddMediaToStoreL()
  1282 // CSendObject::AddMediaToStoreL()
  1294 //
  1283 //
  1301     // SetProtectionStatus here make sure no matter the previous operation is SendObjectInfo
  1290     // SetProtectionStatus here make sure no matter the previous operation is SendObjectInfo
  1302     // or SendObjectPropList
  1291     // or SendObjectPropList
  1303     // Might need to set dateadded and datemodify for further extension.
  1292     // Might need to set dateadded and datemodify for further extension.
  1304     SetProtectionStatus();
  1293     SetProtectionStatus();
  1305 
  1294 
  1306     iDpConfig.GetWrapperL().SetStorageRootL( iFullPath );
       
  1307     PRINT1( _L( "MM MTP <> CSendObject::AddMediaToStoreL iFullPath = %S" ), &iFullPath );
  1295     PRINT1( _L( "MM MTP <> CSendObject::AddMediaToStoreL iFullPath = %S" ), &iFullPath );
  1308     iDpConfig.GetWrapperL().AddObjectL( *iReceivedObjectInfo );
  1296     iDpConfig.GetWrapperL().AddObjectL( *iReceivedObjectInfo );
  1309 
  1297 
  1310     iDpConfig.GetWrapperL().SetImageObjPropL( *iReceivedObjectInfo, iWidth, iHeight );
  1298     iDpConfig.GetWrapperL().SetImageObjPropL( *iReceivedObjectInfo, iWidth, iHeight );
  1311 
  1299 
  1329 // delete the file, which transfer incompletely
  1317 // delete the file, which transfer incompletely
  1330 // -----------------------------------------------------------------------------
  1318 // -----------------------------------------------------------------------------
  1331 //
  1319 //
  1332 void CSendObject::Rollback()
  1320 void CSendObject::Rollback()
  1333     {
  1321     {
  1334     // Delete this object from file system.
  1322     PRINT( _L("MM MTP => CSendObject::Rollback") );
  1335     if ( iProgress == ESendObjectInProgress )
  1323 
  1336             // || iProgress == EObjectInfoSucceed   // this line is to be commented out until SetSize is done in SendObjectInfo/SendObjectPropList
  1324     TInt count = iRollbackList.Count();
  1337             //||iProgress == EObjectInfoFail )
  1325     PRINT1( _L("MM MTP => CSendObject::Rollback, iRollbackList.Count() = %d"), iRollbackList.Count() );
  1338         {
  1326 
  1339         PRINT1( _L( "MM MTP <> CSendObject::Rollback ROLLBACK_FILE %S" ), &iFullPath );
  1327     for ( TInt i = 0; i < count; i++ )
  1340         // Close the interrupted transfer file by delete iFileReceived object
  1328         {
  1341         delete iFileReceived;
  1329         TMmMtpRollbackAction tmp = iRollbackList[i];
  1342         iFileReceived = NULL;
  1330         ( this->*((TMmMtpRollbackAction)(iRollbackList[i])))();
  1343 
  1331         }
  1344         iFramework.Fs().Delete( iFullPath );
  1332     iRollbackList.Reset();
  1345         TRAP_IGNORE( iFramework.ObjectMgr().UnreserveObjectHandleL( *iReceivedObjectInfo ) );
  1333 
  1346         iProgress = EObjectNone;
  1334     PRINT( _L("MM MTP <= CSendObject::Rollback") );
  1347         }
  1335     }
       
  1336 
       
  1337 void CSendObject::UnreserveObjectL()
       
  1338     {
       
  1339     PRINT( _L("MM MTP => CSendObject::UnreserveObjectL") );
       
  1340     iFramework.ObjectMgr().UnreserveObjectHandleL( *iReceivedObjectInfo );
       
  1341     PRINT( _L("MM MTP <= CSendObject::UnreserveObjectL") );
       
  1342     }
       
  1343 
       
  1344 void CSendObject::RemoveObjectFromDbL()
       
  1345     {
       
  1346     PRINT( _L("MM MTP => CSendObject::RemoveObjectFromDbL") );
       
  1347     iFramework.ObjectMgr().RemoveObjectL( iReceivedObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
       
  1348     iDpConfig.GetWrapperL().DeleteObjectL( *iReceivedObjectInfo );
       
  1349     PRINT( _L("MM MTP <= CSendObject::RemoveObjectFromDbL") );
       
  1350     }
       
  1351 
       
  1352 void CSendObject::RemoveObjectFromFs()
       
  1353     {
       
  1354     PRINT( _L("MM MTP => CSendObject::RemoveObjectFromFs") );
       
  1355 
       
  1356     delete iFileReceived;
       
  1357     iFileReceived = NULL;
       
  1358 
       
  1359     TInt err = iFramework.Fs().Delete( iFullPath );
       
  1360     if ( err != KErrNone )
       
  1361         {
       
  1362         PRINT1( _L("MM MTP <> CSendObject::RemoveObjectFromFs err = %d"), err );
       
  1363         }
       
  1364     PRINT( _L("MM MTP <= CSendObject::RemoveObjectFromFs") );
  1348     }
  1365     }
  1349 
  1366 
  1350 // end of file
  1367 // end of file