mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/csendobject.cpp
branchRCL_3
changeset 28 f56ec6ce2732
parent 23 4740b34b83ce
child 30 6f9f6e99a23e
equal deleted inserted replaced
23:4740b34b83ce 28:f56ec6ce2732
    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 // -----------------------------------------------------------------------------
   127     iReceivedObjectInfo = CMTPObjectMetaData::NewL();
   126     iReceivedObjectInfo = CMTPObjectMetaData::NewL();
   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 
       
   133     iNoRollback = EFalse;
       
   134 
   131 
   135     SetPSStatus();
   132     SetPSStatus();
   136     PRINT( _L( "MM MTP <= CSendObject::ConstructL" ) );
   133     PRINT( _L( "MM MTP <= CSendObject::ConstructL" ) );
   137     }
   134     }
   138 
   135 
   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;
   390 // -----------------------------------------------------------------------------
   382 // -----------------------------------------------------------------------------
   391 //
   383 //
   392 void CSendObject::ServiceObjectL()
   384 void CSendObject::ServiceObjectL()
   393     {
   385     {
   394     PRINT( _L( "MM MTP => CSendObject::ServiceObjectL" ) );
   386     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 );
   387     ReceiveDataL( *iFileReceived );
   410 
       
   411     iProgress = ESendObjectInProgress;
   388     iProgress = ESendObjectInProgress;
   412 
   389 
   413     PRINT( _L( "MM MTP <= CSendObject::ServiceObjectL" ) );
   390     PRINT( _L( "MM MTP <= CSendObject::ServiceObjectL" ) );
   414     }
   391     }
   415 
   392 
   477     PRINT1( _L("MM MTP <> CSendObject::DoHandleResponsePhaseInfoL, iObjectSize = %Lu"), iObjectSize );
   454     PRINT1( _L("MM MTP <> CSendObject::DoHandleResponsePhaseInfoL, iObjectSize = %Lu"), iObjectSize );
   478 
   455 
   479     if ( IsTooLarge( iObjectSize ) )
   456     if ( IsTooLarge( iObjectSize ) )
   480         {
   457         {
   481         SendResponseL( EMTPRespCodeObjectTooLarge );
   458         SendResponseL( EMTPRespCodeObjectTooLarge );
   482         result = EFalse;
   459         Rollback();
   483         }
       
   484 
       
   485     if ( result && !CanStoreFileL( iStorageId, iObjectSize ) )
       
   486         {
       
   487         SendResponseL( EMTPRespCodeStoreFull );
       
   488         result = EFalse;
   460         result = EFalse;
   489         }
   461         }
   490 
   462 
   491     if ( result )
   463     if ( result )
   492         {
   464         {
   494         PRINT1( _L( "MM MTP <> CSendObject::DoHandleResponsePhaseInfoL iProtectionStatus = %d" ), iProtectionStatus );
   466         PRINT1( _L( "MM MTP <> CSendObject::DoHandleResponsePhaseInfoL iProtectionStatus = %d" ), iProtectionStatus );
   495         if ( iProtectionStatus != EMTPProtectionNoProtection
   467         if ( iProtectionStatus != EMTPProtectionNoProtection
   496             && iProtectionStatus != EMTPProtectionReadOnly )
   468             && iProtectionStatus != EMTPProtectionReadOnly )
   497             {
   469             {
   498             SendResponseL( EMTPRespCodeParameterNotSupported );
   470             SendResponseL( EMTPRespCodeParameterNotSupported );
       
   471             Rollback();
   499             result = EFalse;
   472             result = EFalse;
   500             }
   473             }
   501         }
   474         }
   502 
   475 
   503     if ( result )
   476     if ( result )
   505         result = GetFullPathNameL( iObjectInfo->StringCharsL( CMTPTypeObjectInfo::EFilename ) );
   478         result = GetFullPathNameL( iObjectInfo->StringCharsL( CMTPTypeObjectInfo::EFilename ) );
   506         if ( !result )
   479         if ( !result )
   507             {
   480             {
   508             // File and/or parent pathname invalid.
   481             // File and/or parent pathname invalid.
   509             SendResponseL( EMTPRespCodeInvalidDataset );
   482             SendResponseL( EMTPRespCodeInvalidDataset );
       
   483             Rollback();
   510             }
   484             }
   511         }
   485         }
   512 
   486 
   513     if ( result )
   487     if ( result )
   514         {
   488         {
   515         if ( ExistsL( iFullPath ) )
   489         if ( ExistsL( iFullPath ) )
   516             {
   490             {
   517             // Object with the same name already exists.
       
   518             iNoRollback = ETrue;
       
   519             SendResponseL( EMTPRespCodeAccessDenied );
   491             SendResponseL( EMTPRespCodeAccessDenied );
       
   492             Rollback();
   520             result = EFalse;
   493             result = EFalse;
   521             }
   494             }
   522         }
   495         }
   523 
   496 
   524     if ( result )
   497     if ( result )
   525         ReserveObjectL();
   498         {
   526 
   499         if ( KErrNone != ReserveObjectL() )
       
   500             {
       
   501             result = EFalse;
       
   502             }
       
   503         }
   527     PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseInfoL result = %d" ), result );
   504     PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseInfoL result = %d" ), result );
   528 
   505 
   529     return result;
   506     return result;
   530     }
   507     }
   531 
   508 
   540 
   517 
   541     TMTPResponseCode responseCode = EMTPRespCodeOK;
   518     TMTPResponseCode responseCode = EMTPRespCodeOK;
   542 
   519 
   543     TInt invalidParameterIndex = KErrNotFound;
   520     TInt invalidParameterIndex = KErrNotFound;
   544     responseCode = VerifyObjectPropListL( invalidParameterIndex );
   521     responseCode = VerifyObjectPropListL( invalidParameterIndex );
       
   522     TInt err = KErrNone;
   545 
   523 
   546     if ( responseCode != EMTPRespCodeOK )
   524     if ( responseCode != EMTPRespCodeOK )
   547         {
   525         {
   548         TUint32 parameters[4];
   526         TUint32 parameters[4];
   549         parameters[0] = 0;
   527         parameters[0] = 0;
   550         parameters[1] = 0;
   528         parameters[1] = 0;
   551         parameters[2] = 0;
   529         parameters[2] = 0;
   552         parameters[3] = invalidParameterIndex;
   530         parameters[3] = invalidParameterIndex;
   553         SendResponseL( responseCode, 4, parameters );
   531         SendResponseL( responseCode, 4, parameters );
       
   532         Rollback();
   554         }
   533         }
   555     else if ( ExistsL( iFullPath ) )
   534     else if ( ExistsL( iFullPath ) )
   556         {
   535         {
   557         // Object with the same name already exists.
       
   558         iNoRollback = ETrue;
       
   559         SendResponseL( EMTPRespCodeAccessDenied );
   536         SendResponseL( EMTPRespCodeAccessDenied );
       
   537         Rollback();
   560         }
   538         }
   561     else
   539     else
   562         ReserveObjectL();
   540         err = ReserveObjectL();
   563 
   541 
   564     PRINT( _L( "MM MTP <= CSendObject::DoHandleResponsePhasePropListL" ) );
   542     PRINT( _L( "MM MTP <= CSendObject::DoHandleResponsePhasePropListL" ) );
   565     return ( responseCode == EMTPRespCodeOK );
   543     return ( responseCode == EMTPRespCodeOK && err == KErrNone);
   566     }
   544     }
   567 
   545 
   568 // -----------------------------------------------------------------------------
   546 // -----------------------------------------------------------------------------
   569 // CSendObject::DoHandleResponsePhaseObjectL
   547 // CSendObject::DoHandleResponsePhaseObjectL
   570 // SendObject
   548 // SendObject
   574     {
   552     {
   575     PRINT( _L( "MM MTP => CSendObject::DoHandleResponsePhaseObjectL" ) );
   553     PRINT( _L( "MM MTP => CSendObject::DoHandleResponsePhaseObjectL" ) );
   576 
   554 
   577     TBool result = ETrue;
   555     TBool result = ETrue;
   578 
   556 
       
   557     TEntry fileEntry;
       
   558     User::LeaveIfError( iFs.Entry( iFullPath, fileEntry ) );
       
   559     if ( fileEntry.FileSize() != iObjectSize )
       
   560         {
       
   561         iFs.Delete( iFullPath );
       
   562         iObjectMgr.UnreserveObjectHandleL( *iReceivedObjectInfo );
       
   563         TMTPResponseCode responseCode = EMTPRespCodeObjectTooLarge;
       
   564         if ( fileEntry.FileSize() < iObjectSize )
       
   565             {
       
   566             responseCode = EMTPRespCodeIncompleteTransfer;
       
   567             }
       
   568         SendResponseL( responseCode );
       
   569         Rollback();
       
   570         result = EFalse;
       
   571         }
       
   572 
   579     // SendObject is cancelled or connection is dropped.
   573     // SendObject is cancelled or connection is dropped.
   580     if ( iCancelled )
   574     if ( result && iCancelled )
   581         {
   575         {
   582         // In SendObject response phase, unregister is not necessary.
       
   583         // But there's no harm, still keep it here.
       
   584         iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest,
   576         iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest,
   585             iConnection );
   577             iConnection );
   586 
   578         SendResponseL( EMTPRespCodeTransactionCancelled );
   587         Rollback();
   579         Rollback();
   588         SendResponseL( EMTPRespCodeTransactionCancelled );
   580         }
   589         }
   581     else if ( result && !iCancelled )
   590     else
   582         {
   591         {
   583         if ( iObjectSize > 0 ) // media file
   592         TEntry fileEntry;
   584             {
   593         User::LeaveIfError( iFs.Entry( iFullPath, fileEntry ) );
   585             TRAPD( err, AddMediaToStoreL() );
   594 
   586             PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL err = %d" ), err );
   595         if ( fileEntry.FileSize() != iObjectSize )
   587 
   596             {
   588             if ( ( iPreviousOperation == EMTPOpCodeSendObjectPropList )
   597             Rollback();
   589                 && ( err == KErrNone ) )
   598             TMTPResponseCode responseCode = EMTPRespCodeObjectTooLarge;
   590                 {
   599             if ( fileEntry.FileSize() < iObjectSize )
   591                 // Only leave when getting proplist element from data received by fw.
   600                 {
   592                 // It should not happen after ReceiveDataL in which construction of proplist already succeed.
   601                 responseCode = EMTPRespCodeIncompleteTransfer;
   593                 SetObjectPropListL();
   602                 }
   594                 }
   603             SendResponseL( responseCode );
   595 
   604             result = EFalse;
   596             // Commits into MTP data object enumeration store the object handle and
   605             }
   597             // storage space previously reserved for the specified object.
   606         else
   598             iFramework.ObjectMgr().CommitReservedObjectHandleL( *iReceivedObjectInfo );
   607             {
   599             iRollbackList.Append( RemoveObjectFromDbL );
   608             if ( iObjectSize > 0 ) // media file
   600             }
   609                 {
   601 
   610                 TRAPD( err, AddMediaToStoreL() );
   602         // Commit object to MTP data store
   611                 PRINT1( _L( "MM MTP <> CSendObject::DoHandleResponsePhaseObjectL err = %d" ), err );
   603         iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest,
   612 
   604             iConnection );
   613                 if ( ( iPreviousOperation == EMTPOpCodeSendObjectPropList )
   605 
   614                     && ( err == KErrNone ) )
   606         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         }
   607         }
   634 
   608 
   635     PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL result = %d" ), result );
   609     PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL result = %d" ), result );
   636 
   610 
   637     return result;
   611     return result;
   658         {
   632         {
   659         //Sending Object failed, but still do not delete request, can try again with current info
   633         //Sending Object failed, but still do not delete request, can try again with current info
   660         iProgress = EObjectInfoSucceed;
   634         iProgress = EObjectInfoSucceed;
   661         result = EFalse;
   635         result = EFalse;
   662         }
   636         }
       
   637 
       
   638     if ( result )
       
   639         iRollbackList.Reset();
   663 
   640 
   664     PRINT2( _L( "MM MTP <= CSendObject::DoHandleCompletingPhaseL iProgress= %d, result = %d" ),
   641     PRINT2( _L( "MM MTP <= CSendObject::DoHandleCompletingPhaseL iProgress= %d, result = %d" ),
   665         iProgress,
   642         iProgress,
   666         result );
   643         result );
   667 
   644 
  1040     TBool ret = ( aObjectSize > KMaxSupportedFileSize );
  1017     TBool ret = ( aObjectSize > KMaxSupportedFileSize );
  1041     PRINT2( _L( "MM MTP <> CSendObject::IsTooLarge aObjectSize = 0x%Lx, ret = %d" ), aObjectSize, ret );
  1018     PRINT2( _L( "MM MTP <> CSendObject::IsTooLarge aObjectSize = 0x%Lx, ret = %d" ), aObjectSize, ret );
  1042     return ret;
  1019     return ret;
  1043     }
  1020     }
  1044 
  1021 
  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 
  1022 
  1071 // -----------------------------------------------------------------------------
  1023 // -----------------------------------------------------------------------------
  1072 // CSendObject::GetFullPathNameL
  1024 // CSendObject::GetFullPathNameL
  1073 // Get the full path name of the object to be saved
  1025 // Get the full path name of the object to be saved
  1074 // @param aFileName, on entry, contains the file name of the object,
  1026 // @param aFileName, on entry, contains the file name of the object,
  1169 
  1121 
  1170 // -----------------------------------------------------------------------------
  1122 // -----------------------------------------------------------------------------
  1171 // CSendObject::ReserveObjectL
  1123 // CSendObject::ReserveObjectL
  1172 // -----------------------------------------------------------------------------
  1124 // -----------------------------------------------------------------------------
  1173 //
  1125 //
  1174 void CSendObject::ReserveObjectL()
  1126 TInt CSendObject::ReserveObjectL()
  1175     {
  1127     {
  1176     PRINT( _L( "MM MTP => CSendObject::ReserveObjectL" ) );
  1128     PRINT( _L( "MM MTP => CSendObject::ReserveObjectL" ) );
  1177     TInt err = KErrNone;
  1129     TInt err = KErrNone;
  1178 
  1130 
  1179     iReceivedObjectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId );
  1131     iReceivedObjectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId );
  1185 
  1137 
  1186     // Reserves space for and assigns an object handle to the object described
  1138     // Reserves space for and assigns an object handle to the object described
  1187     // by the specified object information record.
  1139     // by the specified object information record.
  1188     TRAP( err, iObjectMgr.ReserveObjectHandleL( *iReceivedObjectInfo,
  1140     TRAP( err, iObjectMgr.ReserveObjectHandleL( *iReceivedObjectInfo,
  1189         iObjectSize ) );
  1141         iObjectSize ) );
       
  1142     iRollbackList.Append( UnreserveObjectL );
  1190 
  1143 
  1191     PRINT2( _L( "MM MTP => CSendObject::ReserveObjectL iObjectsize = %Lu, Operation: 0x%x" ), iObjectSize, iOperationCode );
  1144     PRINT2( _L( "MM MTP => CSendObject::ReserveObjectL iObjectsize = %Lu, Operation: 0x%x" ), iObjectSize, iOperationCode );
  1192     if ( err != KErrNone )
  1145     if ( err != KErrNone )
  1193         PRINT1( _L( "MM MTP <> CSendObject::ReserveObjectL err = %d" ), err );
  1146         {
  1194     if ( iObjectSize == 0 )
  1147         PRINT1( _L( "MM MTP <> ReserveObjectHandleL err = %d" ), err );
       
  1148         }
       
  1149 
       
  1150     if ( err == KErrNone )
       
  1151         {
       
  1152         delete iFileReceived;
       
  1153         iFileReceived = NULL;
       
  1154         PRINT2( _L( "MM MTP <> CSendObject::ServiceObjectL, iFullPath is %S, iObjectSize: %Lu" ), &iFullPath, iObjectSize );
       
  1155         iRollbackList.Append( RemoveObjectFromFs );
       
  1156         TRAP( err, iFileReceived = CMTPTypeFile::NewL( iFs, iFullPath, EFileWrite ) );
       
  1157 
       
  1158         PRINT1( _L("MM MTP <> CMTPTypeFile::NewL Leave Code is: %d"), err );
       
  1159         }
       
  1160 
       
  1161     if ( err == KErrNone )
       
  1162         {
       
  1163         TRAP( err, iFileReceived->SetSizeL( iObjectSize ) );
       
  1164         PRINT1( _L( "MM MTP <> SetSizeL leave code:%d" ), err );
       
  1165         if ( err == KErrDiskFull )
       
  1166             {
       
  1167             SendResponseL( EMTPRespCodeStoreFull );
       
  1168             Rollback();
       
  1169             return err;
       
  1170             }
       
  1171         }
       
  1172 
       
  1173     if ( err == KErrNone && iObjectSize == 0 )
  1195         {
  1174         {
  1196         // Already trapped inside SaveEmptyFileL.
  1175         // Already trapped inside SaveEmptyFileL.
  1197         SaveEmptyFileL();
  1176         SaveEmptyFileL();
  1198         if( iOperationCode == EMTPOpCodeSendObjectPropList )
  1177         if ( iOperationCode == EMTPOpCodeSendObjectPropList )
  1199             {
  1178             {
  1200             // Only leave when getting proplist element from data received by fw.
  1179             // 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.
  1180             // It should not happen after ReceiveDataL in which construction of proplist already succeed.
  1202             SetObjectPropListL();
  1181             SetObjectPropListL();
  1203             }
  1182             }
  1204 
  1183 
  1205         iObjectMgr.CommitReservedObjectHandleL( *iReceivedObjectInfo );
  1184         iObjectMgr.CommitReservedObjectHandleL( *iReceivedObjectInfo );
  1206         }
  1185         iRollbackList.Reset();
  1207 
  1186         }
  1208     iExpectedSendObjectRequest.SetUint32( TMTPTypeRequest::ERequestSessionID,
  1187 
  1209         iSessionId );
  1188     if ( err == KErrNone )
  1210     iFramework.RouteRequestRegisterL( iExpectedSendObjectRequest, iConnection );
  1189         {
  1211 
  1190         iExpectedSendObjectRequest.SetUint32( TMTPTypeRequest::ERequestSessionID, iSessionId );
  1212     TUint32 parameters[3];
  1191         iFramework.RouteRequestRegisterL( iExpectedSendObjectRequest, iConnection );
  1213     parameters[0] = iStorageId;
  1192 
  1214     parameters[1] = iParentHandle;
  1193         TUint32 parameters[3];
  1215     parameters[2] = iReceivedObjectInfo->Uint( CMTPObjectMetaData::EHandle );
  1194         parameters[0] = iStorageId;
  1216     SendResponseL( EMTPRespCodeOK, 3, parameters );
  1195         parameters[1] = iParentHandle;
       
  1196         parameters[2] = iReceivedObjectInfo->Uint( CMTPObjectMetaData::EHandle );
       
  1197         SendResponseL( EMTPRespCodeOK, 3, parameters );
       
  1198         }
       
  1199     else
       
  1200         {
       
  1201         SendResponseL( EMTPRespCodeGeneralError );
       
  1202         Rollback();
       
  1203         }
  1217 
  1204 
  1218     PRINT( _L( "MM MTP <= CSendObject::ReserveObjectL" ) );
  1205     PRINT( _L( "MM MTP <= CSendObject::ReserveObjectL" ) );
       
  1206     return err;
  1219     }
  1207     }
  1220 
  1208 
  1221 // -----------------------------------------------------------------------------
  1209 // -----------------------------------------------------------------------------
  1222 // CSendObject::SetProtectionStatus
  1210 // CSendObject::SetProtectionStatus
  1223 // -----------------------------------------------------------------------------
  1211 // -----------------------------------------------------------------------------
  1246                 PRINT1( _L("MM MTP <> CSendObject::SetProtectionStatus err = %d" ), err );
  1234                 PRINT1( _L("MM MTP <> CSendObject::SetProtectionStatus err = %d" ), err );
  1247                 }
  1235                 }
  1248             }
  1236             }
  1249         // Close the file after SetProtectionStatus to make sure other process won't open
  1237         // Close the file after SetProtectionStatus to make sure other process won't open
  1250         // the file successfully right at the time calling RFile::SetAtt.
  1238         // the file successfully right at the time calling RFile::SetAtt.
  1251         delete iFileReceived;
  1239         if ( iObjectSize > 0 )
  1252         iFileReceived = NULL;
  1240             {
       
  1241             delete iFileReceived;
       
  1242             iFileReceived = NULL;
       
  1243             }
       
  1244         else
       
  1245             iFileReceived->File().Close();
  1253         }
  1246         }
  1254 
  1247 
  1255     PRINT( _L( "MM MTP <= CSendObject::SetProtectionStatus" ) );
  1248     PRINT( _L( "MM MTP <= CSendObject::SetProtectionStatus" ) );
  1256     }
  1249     }
  1257 
  1250 
  1261 //
  1254 //
  1262 void CSendObject::SaveEmptyFileL()
  1255 void CSendObject::SaveEmptyFileL()
  1263     {
  1256     {
  1264     PRINT( _L( "MM MTP => CSendObject::SaveEmptyFileL" ) );
  1257     PRINT( _L( "MM MTP => CSendObject::SaveEmptyFileL" ) );
  1265 
  1258 
  1266     RFile file;
       
  1267     User::LeaveIfError( file.Create( iFs, iFullPath, EFileWrite ) );
       
  1268     CleanupClosePushL( file );  // + file
       
  1269 
       
  1270     if ( EMTPFormatCodeAbstractAudioVideoPlaylist == iObjectFormat )
  1259     if ( EMTPFormatCodeAbstractAudioVideoPlaylist == iObjectFormat )
  1271         {
  1260         {
  1272         TInt err = KErrNone;
  1261         TInt err = iFileReceived->File().SetAtt( KEntryAttSystem | KEntryAttHidden,
  1273         err = file.SetAtt( KEntryAttSystem | KEntryAttHidden,
       
  1274             KEntryAttReadOnly | KEntryAttNormal );
  1262             KEntryAttReadOnly | KEntryAttNormal );
  1275         if ( err != KErrNone )
  1263         if ( err != KErrNone )
  1276             PRINT1( _L( "MM MTP <> CSendObject::SaveEmptyFileL err = %d" ), err );
  1264             PRINT1( _L( "MM MTP <> CSendObject::SaveEmptyFileL err = %d" ), err );
  1277         iDpConfig.GetWrapperL().AddDummyFileL( iFullPath );
  1265         iDpConfig.GetWrapperL().AddDummyFileL( iFullPath );
  1278         }
  1266         }
  1279     CleanupStack::PopAndDestroy( &file );   // - file
       
  1280 
  1267 
  1281     // add playlist to MPX DB
  1268     // add playlist to MPX DB
  1282     TRAPD( err, AddMediaToStoreL() );
  1269     TRAPD( err, AddMediaToStoreL() );
  1283 
  1270 
  1284     if ( err != KErrNone )
  1271     if ( err != KErrNone )
  1285         {
  1272         iRollbackList.Append( RemoveObjectFromDbL );
  1286         // Ignore err even add into MPX get failed.
  1273     else
  1287         }
  1274         iRollbackList.Reset();
  1288 
  1275 
  1289     PRINT1( _L( "MM MTP <= CSendObject::SaveEmptyFileLerr = %d" ), err );
  1276     PRINT1( _L( "MM MTP <= CSendObject::SaveEmptyFileL err = %d" ), err );
  1290     }
  1277     }
  1291 
  1278 
  1292 // -----------------------------------------------------------------------------
  1279 // -----------------------------------------------------------------------------
  1293 // CSendObject::AddMediaToStoreL()
  1280 // CSendObject::AddMediaToStoreL()
  1294 //
  1281 //
  1301     // SetProtectionStatus here make sure no matter the previous operation is SendObjectInfo
  1288     // SetProtectionStatus here make sure no matter the previous operation is SendObjectInfo
  1302     // or SendObjectPropList
  1289     // or SendObjectPropList
  1303     // Might need to set dateadded and datemodify for further extension.
  1290     // Might need to set dateadded and datemodify for further extension.
  1304     SetProtectionStatus();
  1291     SetProtectionStatus();
  1305 
  1292 
  1306     iDpConfig.GetWrapperL().SetStorageRootL( iFullPath );
       
  1307     PRINT1( _L( "MM MTP <> CSendObject::AddMediaToStoreL iFullPath = %S" ), &iFullPath );
  1293     PRINT1( _L( "MM MTP <> CSendObject::AddMediaToStoreL iFullPath = %S" ), &iFullPath );
  1308     iDpConfig.GetWrapperL().AddObjectL( *iReceivedObjectInfo );
  1294     iDpConfig.GetWrapperL().AddObjectL( *iReceivedObjectInfo );
  1309 
  1295 
  1310     iDpConfig.GetWrapperL().SetImageObjPropL( *iReceivedObjectInfo, iWidth, iHeight );
  1296     iDpConfig.GetWrapperL().SetImageObjPropL( *iReceivedObjectInfo, iWidth, iHeight );
  1311 
  1297 
  1329 // delete the file, which transfer incompletely
  1315 // delete the file, which transfer incompletely
  1330 // -----------------------------------------------------------------------------
  1316 // -----------------------------------------------------------------------------
  1331 //
  1317 //
  1332 void CSendObject::Rollback()
  1318 void CSendObject::Rollback()
  1333     {
  1319     {
  1334     // Delete this object from file system.
  1320     PRINT( _L("MM MTP => CSendObject::Rollback") );
  1335     if ( iProgress == ESendObjectInProgress )
  1321 
  1336             // || iProgress == EObjectInfoSucceed   // this line is to be commented out until SetSize is done in SendObjectInfo/SendObjectPropList
  1322     TInt count = iRollbackList.Count();
  1337             //||iProgress == EObjectInfoFail )
  1323     PRINT1( _L("MM MTP => CSendObject::Rollback, iRollbackList.Count() = %d"), iRollbackList.Count() );
  1338         {
  1324 
  1339         PRINT1( _L( "MM MTP <> CSendObject::Rollback ROLLBACK_FILE %S" ), &iFullPath );
  1325     for ( TInt i = 0; i < count; i++ )
  1340         // Close the interrupted transfer file by delete iFileReceived object
  1326         {
  1341         delete iFileReceived;
  1327         TMmMtpRollbackAction tmp = iRollbackList[i];
  1342         iFileReceived = NULL;
  1328         ( this->*((TMmMtpRollbackAction)(iRollbackList[i])))();
  1343 
  1329         }
  1344         iFramework.Fs().Delete( iFullPath );
  1330     iRollbackList.Reset();
  1345         TRAP_IGNORE( iFramework.ObjectMgr().UnreserveObjectHandleL( *iReceivedObjectInfo ) );
  1331 
  1346         iProgress = EObjectNone;
  1332     PRINT( _L("MM MTP <= CSendObject::Rollback") );
  1347         }
  1333     }
       
  1334 
       
  1335 void CSendObject::UnreserveObjectL()
       
  1336     {
       
  1337     PRINT( _L("MM MTP => CSendObject::UnreserveObjectL") );
       
  1338     iFramework.ObjectMgr().UnreserveObjectHandleL( *iReceivedObjectInfo );
       
  1339     PRINT( _L("MM MTP <= CSendObject::UnreserveObjectL") );
       
  1340     }
       
  1341 
       
  1342 void CSendObject::RemoveObjectFromDbL()
       
  1343     {
       
  1344     PRINT( _L("MM MTP => CSendObject::RemoveObjectFromDbL") );
       
  1345     iFramework.ObjectMgr().RemoveObjectL( iReceivedObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
       
  1346     iDpConfig.GetWrapperL().DeleteObjectL( *iReceivedObjectInfo );
       
  1347     PRINT( _L("MM MTP <= CSendObject::RemoveObjectFromDbL") );
       
  1348     }
       
  1349 
       
  1350 void CSendObject::RemoveObjectFromFs()
       
  1351     {
       
  1352     PRINT( _L("MM MTP => CSendObject::RemoveObjectFromFs") );
       
  1353 
       
  1354     delete iFileReceived;
       
  1355     iFileReceived = NULL;
       
  1356 
       
  1357     TInt err = iFramework.Fs().Delete( iFullPath );
       
  1358     if ( err != KErrNone )
       
  1359         {
       
  1360         PRINT1( _L("MM MTP <> CSendObject::RemoveObjectFromFs err = %d"), err );
       
  1361         }
       
  1362     PRINT( _L("MM MTP <= CSendObject::RemoveObjectFromFs") );
  1348     }
  1363     }
  1349 
  1364 
  1350 // end of file
  1365 // end of file