mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/csendobject.cpp
branchGCC_SURGE
changeset 47 f3d2589f22d6
parent 35 2ee890d2f7e7
child 48 b7b49303d0c0
child 51 e61a04404bdf
equal deleted inserted replaced
36:3b7506f63335 47:f3d2589f22d6
    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;
       
   134 
       
   135     SetPSStatus();
       
   136     PRINT( _L( "MM MTP <= CSendObject::ConstructL" ) );
   132     PRINT( _L( "MM MTP <= CSendObject::ConstructL" ) );
   137     }
   133     }
   138 
   134 
   139 // -----------------------------------------------------------------------------
   135 // -----------------------------------------------------------------------------
   140 // CSendObject::Match
   136 // CSendObject::Match
   298 
   294 
   299             if ( IsTooLarge( iObjectSize ) )
   295             if ( IsTooLarge( iObjectSize ) )
   300                 {
   296                 {
   301                 responseCode = EMTPRespCodeObjectTooLarge;
   297                 responseCode = EMTPRespCodeObjectTooLarge;
   302                 }
   298                 }
   303 
       
   304             if ( ( responseCode != EMTPRespCodeOK ) && !CanStoreFileL( iStorageId, iObjectSize ) )
       
   305                 {
       
   306                 responseCode = EMTPRespCodeStoreFull;
       
   307                 }
       
   308             }
   299             }
   309         }
   300         }
   310 
   301 
   311     PRINT1( _L( "MM MTP <= CSendObject::CheckRequestL, responseCode = 0x%x" ), responseCode );
   302     PRINT1( _L( "MM MTP <= CSendObject::CheckRequestL, responseCode = 0x%x" ), responseCode );
   312     return responseCode;
   303     return responseCode;
   330 // -----------------------------------------------------------------------------
   321 // -----------------------------------------------------------------------------
   331 //
   322 //
   332 EXPORT_C void CSendObject::ServiceL()
   323 EXPORT_C void CSendObject::ServiceL()
   333     {
   324     {
   334     PRINT( _L( "MM MTP => CSendObject::ServiceL" ) );
   325     PRINT( _L( "MM MTP => CSendObject::ServiceL" ) );
       
   326     
       
   327     MmMtpDpUtility::SetPSStatus(EMtpPSStatusActive);
   335 
   328 
   336     if ( iProgress == EObjectNone )
   329     if ( iProgress == EObjectNone )
   337         {
   330         {
   338         if ( iOperationCode == EMTPOpCodeSendObjectInfo )
   331         if ( iOperationCode == EMTPOpCodeSendObjectInfo )
   339             {
   332             {
   390 // -----------------------------------------------------------------------------
   383 // -----------------------------------------------------------------------------
   391 //
   384 //
   392 void CSendObject::ServiceObjectL()
   385 void CSendObject::ServiceObjectL()
   393     {
   386     {
   394     PRINT( _L( "MM MTP => CSendObject::ServiceObjectL" ) );
   387     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 );
   388     ReceiveDataL( *iFileReceived );
   410 
       
   411     iProgress = ESendObjectInProgress;
   389     iProgress = ESendObjectInProgress;
   412 
   390 
   413     PRINT( _L( "MM MTP <= CSendObject::ServiceObjectL" ) );
   391     PRINT( _L( "MM MTP <= CSendObject::ServiceObjectL" ) );
   414     }
   392     }
   415 
   393 
   477     PRINT1( _L("MM MTP <> CSendObject::DoHandleResponsePhaseInfoL, iObjectSize = %Lu"), iObjectSize );
   455     PRINT1( _L("MM MTP <> CSendObject::DoHandleResponsePhaseInfoL, iObjectSize = %Lu"), iObjectSize );
   478 
   456 
   479     if ( IsTooLarge( iObjectSize ) )
   457     if ( IsTooLarge( iObjectSize ) )
   480         {
   458         {
   481         SendResponseL( EMTPRespCodeObjectTooLarge );
   459         SendResponseL( EMTPRespCodeObjectTooLarge );
   482         result = EFalse;
   460         Rollback();
   483         }
       
   484 
       
   485     if ( result && !CanStoreFileL( iStorageId, iObjectSize ) )
       
   486         {
       
   487         SendResponseL( EMTPRespCodeStoreFull );
       
   488         result = EFalse;
   461         result = EFalse;
   489         }
   462         }
   490 
   463 
   491     if ( result )
   464     if ( result )
   492         {
   465         {
   494         PRINT1( _L( "MM MTP <> CSendObject::DoHandleResponsePhaseInfoL iProtectionStatus = %d" ), iProtectionStatus );
   467         PRINT1( _L( "MM MTP <> CSendObject::DoHandleResponsePhaseInfoL iProtectionStatus = %d" ), iProtectionStatus );
   495         if ( iProtectionStatus != EMTPProtectionNoProtection
   468         if ( iProtectionStatus != EMTPProtectionNoProtection
   496             && iProtectionStatus != EMTPProtectionReadOnly )
   469             && iProtectionStatus != EMTPProtectionReadOnly )
   497             {
   470             {
   498             SendResponseL( EMTPRespCodeParameterNotSupported );
   471             SendResponseL( EMTPRespCodeParameterNotSupported );
       
   472             Rollback();
   499             result = EFalse;
   473             result = EFalse;
   500             }
   474             }
   501         }
   475         }
   502 
   476 
   503     if ( result )
   477     if ( result )
   505         result = GetFullPathNameL( iObjectInfo->StringCharsL( CMTPTypeObjectInfo::EFilename ) );
   479         result = GetFullPathNameL( iObjectInfo->StringCharsL( CMTPTypeObjectInfo::EFilename ) );
   506         if ( !result )
   480         if ( !result )
   507             {
   481             {
   508             // File and/or parent pathname invalid.
   482             // File and/or parent pathname invalid.
   509             SendResponseL( EMTPRespCodeInvalidDataset );
   483             SendResponseL( EMTPRespCodeInvalidDataset );
       
   484             Rollback();
   510             }
   485             }
   511         }
   486         }
   512 
   487 
   513     if ( result )
   488     if ( result )
   514         {
   489         {
   515         if ( ExistsL( iFullPath ) )
   490         if ( ExistsL( iFullPath ) )
   516             {
   491             {
   517             // Object with the same name already exists.
       
   518             iNoRollback = ETrue;
       
   519             SendResponseL( EMTPRespCodeAccessDenied );
   492             SendResponseL( EMTPRespCodeAccessDenied );
       
   493             Rollback();
   520             result = EFalse;
   494             result = EFalse;
   521             }
   495             }
   522         }
   496         }
   523 
   497 
   524     if ( result )
   498     if ( result )
   525         ReserveObjectL();
   499         {
   526 
   500         if ( KErrNone != ReserveObjectL() )
       
   501             {
       
   502             result = EFalse;
       
   503             }
       
   504         }
   527     PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseInfoL result = %d" ), result );
   505     PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseInfoL result = %d" ), result );
   528 
   506 
   529     return result;
   507     return result;
   530     }
   508     }
   531 
   509 
   540 
   518 
   541     TMTPResponseCode responseCode = EMTPRespCodeOK;
   519     TMTPResponseCode responseCode = EMTPRespCodeOK;
   542 
   520 
   543     TInt invalidParameterIndex = KErrNotFound;
   521     TInt invalidParameterIndex = KErrNotFound;
   544     responseCode = VerifyObjectPropListL( invalidParameterIndex );
   522     responseCode = VerifyObjectPropListL( invalidParameterIndex );
       
   523     TInt err = KErrNone;
   545 
   524 
   546     if ( responseCode != EMTPRespCodeOK )
   525     if ( responseCode != EMTPRespCodeOK )
   547         {
   526         {
   548         TUint32 parameters[4];
   527         TUint32 parameters[4];
   549         parameters[0] = 0;
   528         parameters[0] = 0;
   550         parameters[1] = 0;
   529         parameters[1] = 0;
   551         parameters[2] = 0;
   530         parameters[2] = 0;
   552         parameters[3] = invalidParameterIndex;
   531         parameters[3] = invalidParameterIndex;
   553         SendResponseL( responseCode, 4, parameters );
   532         SendResponseL( responseCode, 4, parameters );
       
   533         Rollback();
   554         }
   534         }
   555     else if ( ExistsL( iFullPath ) )
   535     else if ( ExistsL( iFullPath ) )
   556         {
   536         {
   557         // Object with the same name already exists.
       
   558         iNoRollback = ETrue;
       
   559         SendResponseL( EMTPRespCodeAccessDenied );
   537         SendResponseL( EMTPRespCodeAccessDenied );
       
   538         Rollback();
   560         }
   539         }
   561     else
   540     else
   562         ReserveObjectL();
   541         err = ReserveObjectL();
   563 
   542 
   564     PRINT( _L( "MM MTP <= CSendObject::DoHandleResponsePhasePropListL" ) );
   543     PRINT( _L( "MM MTP <= CSendObject::DoHandleResponsePhasePropListL" ) );
   565     return ( responseCode == EMTPRespCodeOK );
   544     return ( responseCode == EMTPRespCodeOK && err == KErrNone);
   566     }
   545     }
   567 
   546 
   568 // -----------------------------------------------------------------------------
   547 // -----------------------------------------------------------------------------
   569 // CSendObject::DoHandleResponsePhaseObjectL
   548 // CSendObject::DoHandleResponsePhaseObjectL
   570 // SendObject
   549 // SendObject
   574     {
   553     {
   575     PRINT( _L( "MM MTP => CSendObject::DoHandleResponsePhaseObjectL" ) );
   554     PRINT( _L( "MM MTP => CSendObject::DoHandleResponsePhaseObjectL" ) );
   576 
   555 
   577     TBool result = ETrue;
   556     TBool result = ETrue;
   578 
   557 
       
   558     TEntry fileEntry;
       
   559     User::LeaveIfError( iFs.Entry( iFullPath, fileEntry ) );
       
   560     if ( fileEntry.FileSize() != iObjectSize )
       
   561         {
       
   562         iFs.Delete( iFullPath );
       
   563         iObjectMgr.UnreserveObjectHandleL( *iReceivedObjectInfo );
       
   564         TMTPResponseCode responseCode = EMTPRespCodeObjectTooLarge;
       
   565         if ( fileEntry.FileSize() < iObjectSize )
       
   566             {
       
   567             responseCode = EMTPRespCodeIncompleteTransfer;
       
   568             }
       
   569         SendResponseL( responseCode );
       
   570         Rollback();
       
   571         result = EFalse;
       
   572         }
       
   573 
   579     // SendObject is cancelled or connection is dropped.
   574     // SendObject is cancelled or connection is dropped.
   580     if ( iCancelled )
   575     if ( result && iCancelled )
   581         {
   576         {
   582         // In SendObject response phase, unregister is not necessary.
       
   583         // But there's no harm, still keep it here.
       
   584         iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest,
   577         iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest,
   585             iConnection );
   578             iConnection );
   586 
   579         SendResponseL( EMTPRespCodeTransactionCancelled );
   587         Rollback();
   580         Rollback();
   588         SendResponseL( EMTPRespCodeTransactionCancelled );
   581         }
   589         }
   582     else if ( result && !iCancelled )
   590     else
   583         {
   591         {
   584         if ( iObjectSize > 0 ) // media file
   592         TEntry fileEntry;
   585             {
   593         User::LeaveIfError( iFs.Entry( iFullPath, fileEntry ) );
   586             TRAPD( err, AddMediaToStoreL() );
   594 
   587             PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL err = %d" ), err );
   595         if ( fileEntry.FileSize() != iObjectSize )
   588 
   596             {
   589             if ( ( iPreviousOperation == EMTPOpCodeSendObjectPropList )
   597             Rollback();
   590                 && ( err == KErrNone ) )
   598             TMTPResponseCode responseCode = EMTPRespCodeObjectTooLarge;
   591                 {
   599             if ( fileEntry.FileSize() < iObjectSize )
   592                 // Only leave when getting proplist element from data received by fw.
   600                 {
   593                 // It should not happen after ReceiveDataL in which construction of proplist already succeed.
   601                 responseCode = EMTPRespCodeIncompleteTransfer;
   594                 SetObjectPropListL();
   602                 }
   595                 }
   603             SendResponseL( responseCode );
   596 
   604             result = EFalse;
   597             // Commits into MTP data object enumeration store the object handle and
   605             }
   598             // storage space previously reserved for the specified object.
   606         else
   599             iFramework.ObjectMgr().CommitReservedObjectHandleL( *iReceivedObjectInfo );
   607             {
   600             iRollbackList.Append( &CSendObject::RemoveObjectFromDbL );
   608             if ( iObjectSize > 0 ) // media file
   601             }
   609                 {
   602 
   610                 TRAPD( err, AddMediaToStoreL() );
   603         // Commit object to MTP data store
   611                 PRINT1( _L( "MM MTP <> CSendObject::DoHandleResponsePhaseObjectL err = %d" ), err );
   604         iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest,
   612 
   605             iConnection );
   613                 if ( ( iPreviousOperation == EMTPOpCodeSendObjectPropList )
   606 
   614                     && ( err == KErrNone ) )
   607         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         }
   608         }
   634 
   609 
   635     PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL result = %d" ), result );
   610     PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL result = %d" ), result );
   636 
   611 
   637     return result;
   612     return result;
   658         {
   633         {
   659         //Sending Object failed, but still do not delete request, can try again with current info
   634         //Sending Object failed, but still do not delete request, can try again with current info
   660         iProgress = EObjectInfoSucceed;
   635         iProgress = EObjectInfoSucceed;
   661         result = EFalse;
   636         result = EFalse;
   662         }
   637         }
       
   638 
       
   639     if ( result )
       
   640         iRollbackList.Reset();
   663 
   641 
   664     PRINT2( _L( "MM MTP <= CSendObject::DoHandleCompletingPhaseL iProgress= %d, result = %d" ),
   642     PRINT2( _L( "MM MTP <= CSendObject::DoHandleCompletingPhaseL iProgress= %d, result = %d" ),
   665         iProgress,
   643         iProgress,
   666         result );
   644         result );
   667 
   645 
  1040     TBool ret = ( aObjectSize > KMaxSupportedFileSize );
  1018     TBool ret = ( aObjectSize > KMaxSupportedFileSize );
  1041     PRINT2( _L( "MM MTP <> CSendObject::IsTooLarge aObjectSize = 0x%Lx, ret = %d" ), aObjectSize, ret );
  1019     PRINT2( _L( "MM MTP <> CSendObject::IsTooLarge aObjectSize = 0x%Lx, ret = %d" ), aObjectSize, ret );
  1042     return ret;
  1020     return ret;
  1043     }
  1021     }
  1044 
  1022 
  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 
  1023 
  1071 // -----------------------------------------------------------------------------
  1024 // -----------------------------------------------------------------------------
  1072 // CSendObject::GetFullPathNameL
  1025 // CSendObject::GetFullPathNameL
  1073 // Get the full path name of the object to be saved
  1026 // Get the full path name of the object to be saved
  1074 // @param aFileName, on entry, contains the file name of the object,
  1027 // @param aFileName, on entry, contains the file name of the object,
  1079     {
  1032     {
  1080     PRINT1( _L("MM MTP => CSendObject::GetFullPathNameL aFileName = %S"), &aFileName );
  1033     PRINT1( _L("MM MTP => CSendObject::GetFullPathNameL aFileName = %S"), &aFileName );
  1081 
  1034 
  1082     TBool result( EFalse );
  1035     TBool result( EFalse );
  1083 
  1036 
       
  1037     TParsePtrC parser( aFileName );
  1084     if ( aFileName.Length() > 0 )
  1038     if ( aFileName.Length() > 0 )
  1085         {
  1039         {
  1086         iFullPath.Zero();
  1040         iFullPath.Zero();
  1087         iFullPath.Append( *iParentSuid );
  1041         iFullPath.Append( *iParentSuid );
  1088 
  1042 
  1089         // TODO: need to be done in derived class
  1043         // TODO: need to be done in derived class
  1090         // Only add extension for alb to pass winlogo test cases
  1044         // Only add extension for alb to pass winlogo test cases
  1091         TInt length = iFullPath.Length() + aFileName.Length();
  1045         TInt length = iFullPath.Length() + aFileName.Length();
  1092 
  1046 
  1093         TParsePtrC parser( aFileName );
       
  1094         TBool isAlbWithoutExt =
  1047         TBool isAlbWithoutExt =
  1095             ( ( iObjectFormat == EMTPFormatCodeAbstractAudioAlbum ) && ( !parser.ExtPresent() ) );
  1048             ( ( iObjectFormat == EMTPFormatCodeAbstractAudioAlbum ) && ( !parser.ExtPresent() ) );
  1096         if ( isAlbWithoutExt )
  1049         if ( isAlbWithoutExt )
  1097             length += KTxtExtensionALB().Length();
  1050             length += KTxtExtensionALB().Length();
  1098 
  1051 
  1106             }
  1059             }
  1107         }
  1060         }
  1108 
  1061 
  1109     if ( result && ( iObjectFormat != MmMtpDpUtility::FormatFromFilename( iFullPath ) ) )
  1062     if ( result && ( iObjectFormat != MmMtpDpUtility::FormatFromFilename( iFullPath ) ) )
  1110         {
  1063         {
  1111         TParsePtrC file( aFileName );
  1064         if ( ( iObjectFormat == EMTPFormatCode3GPContainer ) && ( parser.Ext().CompareF( KTxtExtensionODF ) == 0))
  1112         if ( ( iObjectFormat == EMTPFormatCode3GPContainer ) && (file.Ext().CompareF( KTxtExtensionODF ) == 0))
       
  1113             {
  1065             {
  1114             PRINT( _L( "MM MTP <> might happen if function is called before physical file arrives" ) );
  1066             PRINT( _L( "MM MTP <> might happen if function is called before physical file arrives" ) );
  1115             // might happen if function is called before physical file arrives
  1067             // might happen if function is called before physical file arrives
  1116             // do nothing
  1068             // do nothing
  1117             }
  1069             }
  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( &CSendObject::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( &CSendObject::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
  1267 
       
  1268     // Set subformat code to avoid MPX query for the first time to GetObjectReference,
       
  1269     // in which case references has been kept in fw.
       
  1270     if ( MmMtpDpUtility::HasReference( iObjectFormat ) )
       
  1271         iReceivedObjectInfo->SetUint( CMTPObjectMetaData::EFormatSubCode, EMTPSubFormatCodeUndefined );
  1280 
  1272 
  1281     // add playlist to MPX DB
  1273     // add playlist to MPX DB
  1282     TRAPD( err, AddMediaToStoreL() );
  1274     TRAPD( err, AddMediaToStoreL() );
  1283 
  1275 
  1284     if ( err != KErrNone )
  1276     if ( err != KErrNone )
  1285         {
  1277         iRollbackList.Append( &CSendObject::RemoveObjectFromDbL );
  1286         // Ignore err even add into MPX get failed.
  1278     else
  1287         }
  1279         iRollbackList.Reset();
  1288 
  1280 
  1289     PRINT1( _L( "MM MTP <= CSendObject::SaveEmptyFileLerr = %d" ), err );
  1281     PRINT1( _L( "MM MTP <= CSendObject::SaveEmptyFileL err = %d" ), err );
  1290     }
  1282     }
  1291 
  1283 
  1292 // -----------------------------------------------------------------------------
  1284 // -----------------------------------------------------------------------------
  1293 // CSendObject::AddMediaToStoreL()
  1285 // CSendObject::AddMediaToStoreL()
  1294 //
  1286 //
  1301     // SetProtectionStatus here make sure no matter the previous operation is SendObjectInfo
  1293     // SetProtectionStatus here make sure no matter the previous operation is SendObjectInfo
  1302     // or SendObjectPropList
  1294     // or SendObjectPropList
  1303     // Might need to set dateadded and datemodify for further extension.
  1295     // Might need to set dateadded and datemodify for further extension.
  1304     SetProtectionStatus();
  1296     SetProtectionStatus();
  1305 
  1297 
  1306     iDpConfig.GetWrapperL().SetStorageRootL( iFullPath );
       
  1307     PRINT1( _L( "MM MTP <> CSendObject::AddMediaToStoreL iFullPath = %S" ), &iFullPath );
  1298     PRINT1( _L( "MM MTP <> CSendObject::AddMediaToStoreL iFullPath = %S" ), &iFullPath );
  1308     iDpConfig.GetWrapperL().AddObjectL( *iReceivedObjectInfo );
  1299     iDpConfig.GetWrapperL().AddObjectL( *iReceivedObjectInfo );
  1309 
  1300 
  1310     iDpConfig.GetWrapperL().SetImageObjPropL( *iReceivedObjectInfo, iWidth, iHeight );
  1301     iDpConfig.GetWrapperL().SetImageObjPropL( *iReceivedObjectInfo, iWidth, iHeight );
  1311 
  1302 
  1329 // delete the file, which transfer incompletely
  1320 // delete the file, which transfer incompletely
  1330 // -----------------------------------------------------------------------------
  1321 // -----------------------------------------------------------------------------
  1331 //
  1322 //
  1332 void CSendObject::Rollback()
  1323 void CSendObject::Rollback()
  1333     {
  1324     {
  1334     // Delete this object from file system.
  1325     PRINT( _L("MM MTP => CSendObject::Rollback") );
  1335     if ( iProgress == ESendObjectInProgress )
  1326 
  1336             // || iProgress == EObjectInfoSucceed   // this line is to be commented out until SetSize is done in SendObjectInfo/SendObjectPropList
  1327     TInt count = iRollbackList.Count();
  1337             //||iProgress == EObjectInfoFail )
  1328     PRINT1( _L("MM MTP => CSendObject::Rollback, iRollbackList.Count() = %d"), iRollbackList.Count() );
  1338         {
  1329 
  1339         PRINT1( _L( "MM MTP <> CSendObject::Rollback ROLLBACK_FILE %S" ), &iFullPath );
  1330     for ( TInt i = 0; i < count; i++ )
  1340         // Close the interrupted transfer file by delete iFileReceived object
  1331         {
  1341         delete iFileReceived;
  1332         TMmMtpRollbackAction tmp = iRollbackList[i];
  1342         iFileReceived = NULL;
  1333         ( this->*((TMmMtpRollbackAction)(iRollbackList[i])))();
  1343 
  1334         }
  1344         iFramework.Fs().Delete( iFullPath );
  1335     iRollbackList.Reset();
  1345         TRAP_IGNORE( iFramework.ObjectMgr().UnreserveObjectHandleL( *iReceivedObjectInfo ) );
  1336 
  1346         iProgress = EObjectNone;
  1337     PRINT( _L("MM MTP <= CSendObject::Rollback") );
  1347         }
  1338     }
       
  1339 
       
  1340 void CSendObject::UnreserveObjectL()
       
  1341     {
       
  1342     PRINT( _L("MM MTP => CSendObject::UnreserveObjectL") );
       
  1343     iFramework.ObjectMgr().UnreserveObjectHandleL( *iReceivedObjectInfo );
       
  1344     PRINT( _L("MM MTP <= CSendObject::UnreserveObjectL") );
       
  1345     }
       
  1346 
       
  1347 void CSendObject::RemoveObjectFromDbL()
       
  1348     {
       
  1349     PRINT( _L("MM MTP => CSendObject::RemoveObjectFromDbL") );
       
  1350     iFramework.ObjectMgr().RemoveObjectL( iReceivedObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
       
  1351     iDpConfig.GetWrapperL().DeleteObjectL( *iReceivedObjectInfo );
       
  1352     PRINT( _L("MM MTP <= CSendObject::RemoveObjectFromDbL") );
       
  1353     }
       
  1354 
       
  1355 void CSendObject::RemoveObjectFromFs()
       
  1356     {
       
  1357     PRINT( _L("MM MTP => CSendObject::RemoveObjectFromFs") );
       
  1358 
       
  1359     delete iFileReceived;
       
  1360     iFileReceived = NULL;
       
  1361 
       
  1362     TInt err = iFramework.Fs().Delete( iFullPath );
       
  1363     if ( err != KErrNone )
       
  1364         {
       
  1365         PRINT1( _L("MM MTP <> CSendObject::RemoveObjectFromFs err = %d"), err );
       
  1366         }
       
  1367     PRINT( _L("MM MTP <= CSendObject::RemoveObjectFromFs") );
  1348     }
  1368     }
  1349 
  1369 
  1350 // end of file
  1370 // end of file