mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/cgetpartialobject.cpp
changeset 25 d881023c13eb
parent 0 a2952bb97e68
child 32 edd273b3192a
equal deleted inserted replaced
21:a05c44bc3c61 25:d881023c13eb
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <mtp/cmtptypefile.h>
    19 #include <mtp/cmtptypefile.h>
    20 #include <mtp/mmtpdataproviderframework.h>
       
    21 #include <mtp/cmtpobjectmetadata.h>
       
    22 
    20 
    23 #include "cgetpartialobject.h"
    21 #include "cgetpartialobject.h"
    24 #include "mmmtpdplogger.h"
    22 #include "mmmtpdplogger.h"
    25 #include "tmmmtpdppanic.h"
    23 #include "tmmmtpdppanic.h"
    26 #include "ttypeflatbuf.h"
       
    27 #include "mmmtpdpconfig.h"
    24 #include "mmmtpdpconfig.h"
    28 
    25 
    29 /**
    26 /**
    30 * Verification data for the GetPartialObject request
    27 * Verification data for the GetPartialObject request
    31 */
    28 */
    39 // Two-phase construction method
    36 // Two-phase construction method
    40 // -----------------------------------------------------------------------------
    37 // -----------------------------------------------------------------------------
    41 //
    38 //
    42 EXPORT_C MMmRequestProcessor* CGetPartialObject::NewL( MMTPDataProviderFramework& aFramework,
    39 EXPORT_C MMmRequestProcessor* CGetPartialObject::NewL( MMTPDataProviderFramework& aFramework,
    43     MMTPConnection& aConnection,
    40     MMTPConnection& aConnection,
    44     MMmMtpDpConfig& aDpConfig )
    41     MMmMtpDpConfig& /*aDpConfig*/ )
    45     {
    42     {
    46     CGetPartialObject* self = new (ELeave) CGetPartialObject( aFramework, aConnection );
    43     CGetPartialObject* self = new (ELeave) CGetPartialObject( aFramework, aConnection );
    47     CleanupStack::PushL( self );
    44     CleanupStack::PushL( self );
    48     self->ConstructL();
    45     self->ConstructL();
    49     CleanupStack::Pop( self );
    46     CleanupStack::Pop( self );
    55 // Destructor
    52 // Destructor
    56 // -----------------------------------------------------------------------------
    53 // -----------------------------------------------------------------------------
    57 //
    54 //
    58 EXPORT_C CGetPartialObject::~CGetPartialObject()
    55 EXPORT_C CGetPartialObject::~CGetPartialObject()
    59     {
    56     {
    60     delete iBuffer;
       
    61     delete iPartialData;
       
    62     delete iFileObject;
    57     delete iFileObject;
    63     }
    58     }
    64 
    59 
    65 // -----------------------------------------------------------------------------
    60 // -----------------------------------------------------------------------------
    66 // CGetPartialObject::CGetPartialObject
    61 // CGetPartialObject::CGetPartialObject
    67 // Standard c++ constructor
    62 // Standard c++ constructor
    68 // -----------------------------------------------------------------------------
    63 // -----------------------------------------------------------------------------
    69 //
    64 //
    70 EXPORT_C CGetPartialObject::CGetPartialObject( MMTPDataProviderFramework& aFramework,
    65 EXPORT_C CGetPartialObject::CGetPartialObject( MMTPDataProviderFramework& aFramework,
    71     MMTPConnection& aConnection ) :
    66     MMTPConnection& aConnection ) :
    72     CRequestProcessor( aFramework,
    67         CRequestProcessor( aFramework,
    73         aConnection,
    68             aConnection,
    74         sizeof( KMTPGetPartialObjectPolicy ) / sizeof( TMTPRequestElementInfo ),
    69             sizeof( KMTPGetPartialObjectPolicy ) / sizeof( TMTPRequestElementInfo ),
    75         KMTPGetPartialObjectPolicy ),
    70             KMTPGetPartialObjectPolicy ),
    76     iFramework ( aFramework ),
    71         iFramework ( aFramework )
    77     iFs( iFramework.Fs() ),
       
    78     iBufferPtr8( NULL, 0 )
       
    79     {
    72     {
    80     PRINT( _L( "Operation: GetPartialObject(0x101B)" ) );
    73     PRINT( _L( "Operation: GetPartialObject(0x101B)" ) );
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CGetPartialObject::ConstructL()
       
    78 // Second-phase construction
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 void CGetPartialObject::ConstructL()
       
    82     {
       
    83     SetPSStatus();
    81     }
    84     }
    82 
    85 
    83 // -----------------------------------------------------------------------------
    86 // -----------------------------------------------------------------------------
    84 // CGetPartialObject::CheckRequestL
    87 // CGetPartialObject::CheckRequestL
    85 // Check the GetPartialObject reqeust
    88 // Check the GetPartialObject reqeust
   104 // -----------------------------------------------------------------------------
   107 // -----------------------------------------------------------------------------
   105 //
   108 //
   106 TBool CGetPartialObject::VerifyParametersL()
   109 TBool CGetPartialObject::VerifyParametersL()
   107     {
   110     {
   108     PRINT( _L( "MM MTP => CGetPartialObject::VerifyParametersL" ) );
   111     PRINT( _L( "MM MTP => CGetPartialObject::VerifyParametersL" ) );
       
   112 
   109     __ASSERT_DEBUG( iRequestChecker, Panic( EMmMTPDpRequestCheckNull ) );
   113     __ASSERT_DEBUG( iRequestChecker, Panic( EMmMTPDpRequestCheckNull ) );
   110     TBool result = EFalse;
   114     TBool result = EFalse;
   111     iObjectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
   115     iObjectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
   112     PRINT1( _L( "MM MTP <> CGetPartialObject::VerifyParametersL iObjectHandle = 0x%x" ), iObjectHandle );
       
   113     iOffset = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
   116     iOffset = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
   114     PRINT1( _L( "MM MTP <> CGetPartialObject::VerifyParametersL iOffset = %d" ), iOffset );
   117     iPartialDataLength = Request().Uint32( TMTPTypeRequest::ERequestParameter3 );
   115     TUint32 maxLength = Request().Uint32( TMTPTypeRequest::ERequestParameter3 );
   118 
   116     PRINT1( _L( "MM MTP <> CGetPartialObject::VerifyParametersL maxLength = %d" ), maxLength );
   119     PRINT3( _L( "MM MTP <> CGetPartialObject::VerifyParametersL iObjectHandle = 0x%x, iOffset = 0x%x, iMaxLength = 0x%x " ),
       
   120         iObjectHandle,
       
   121         iOffset,
       
   122         iPartialDataLength );
   117 
   123 
   118     //get object info, but do not have the ownship of the object
   124     //get object info, but do not have the ownship of the object
   119     CMTPObjectMetaData* objectInfo = iRequestChecker->GetObjectInfo( iObjectHandle );
   125     CMTPObjectMetaData* objectInfo = iRequestChecker->GetObjectInfo( iObjectHandle );
   120     __ASSERT_DEBUG( objectInfo, Panic( EMmMTPDpObjectNull ) );
   126     __ASSERT_DEBUG( objectInfo, Panic( EMmMTPDpObjectNull ) );
   121 
   127 
   122     const TDesC& suid( objectInfo->DesC( CMTPObjectMetaData::ESuid ) );
   128     const TDesC& suid( objectInfo->DesC( CMTPObjectMetaData::ESuid ) );
   123     PRINT1( _L( "MM MTP <> CGetPartialObject::VerifyParametersL suid = %S" ), &suid );
   129     PRINT1( _L( "MM MTP <> CGetPartialObject::VerifyParametersL suid = %S" ), &suid );
   124 
   130 
   125     if ( objectInfo->Uint( CMTPObjectMetaData::EDataProviderId )
       
   126         == iFramework.DataProviderId() )
       
   127         result = ETrue;
       
   128 
       
   129     TEntry fileEntry;
   131     TEntry fileEntry;
   130     User::LeaveIfError( iFs.Entry( suid, fileEntry ) );
   132     User::LeaveIfError( iFramework.Fs().Entry( suid, fileEntry ) );
   131     TInt64 fileSize = fileEntry.iSize;
   133     if ( iOffset < fileEntry.FileSize() )
   132     if( ( iOffset < fileEntry.iSize ) && result )
       
   133         {
   134         {
   134         if ( maxLength == fileSize )
       
   135             {
       
   136             iCompleteFile = ETrue;
       
   137             }
       
   138 
       
   139         if( iOffset + maxLength > fileSize )
       
   140             {
       
   141             maxLength = fileSize - iOffset;
       
   142             }
       
   143         iPartialDataLength = maxLength;
       
   144         result = ETrue;
   135         result = ETrue;
   145         }
   136         }
   146     PRINT1( _L( "MM MTP <> CGetPartialObject::VerifyParametersL iPartialDataLength = %d" ), iPartialDataLength );
       
   147 
   137 
   148     PRINT1( _L( "MM MTP <= CGetPartialObject::VerifyParametersL result = %d" ), result );
   138     PRINT1( _L( "MM MTP <= CGetPartialObject::VerifyParametersL result = %d" ), result );
   149     return result;
   139     return result;
   150     }
   140     }
   151 
   141 
   155 // -----------------------------------------------------------------------------
   145 // -----------------------------------------------------------------------------
   156 //
   146 //
   157 EXPORT_C void CGetPartialObject::ServiceL()
   147 EXPORT_C void CGetPartialObject::ServiceL()
   158     {
   148     {
   159     PRINT( _L( "MM MTP => CGetPartialObject::ServiceL" ) );
   149     PRINT( _L( "MM MTP => CGetPartialObject::ServiceL" ) );
       
   150 
   160     // Get file information
   151     // Get file information
   161     CMTPObjectMetaData* objectInfo = iRequestChecker->GetObjectInfo( iObjectHandle );
   152     CMTPObjectMetaData* objectInfo = iRequestChecker->GetObjectInfo( iObjectHandle );
   162     __ASSERT_DEBUG( objectInfo, Panic( EMmMTPDpObjectNull ) );
   153     __ASSERT_DEBUG( objectInfo, Panic( EMmMTPDpObjectNull ) );
   163     iFileSuid.SetLength( 0 );
       
   164     iFileSuid.Append( objectInfo->DesC( CMTPObjectMetaData::ESuid ) );
       
   165 
   154 
   166     if ( iCompleteFile )
   155     // NOTE: Change all TBuf<KMaxFileName> into TFileName for easily change when fs change the limitation of filename
   167         {
   156     TFileName fileSuid;
   168         // Pass the complete file back to the host
   157     fileSuid.Append( objectInfo->DesC( CMTPObjectMetaData::ESuid ) );
   169         delete iFileObject;
   158 
   170         iFileObject = NULL;
   159     iFileObject = CMTPTypeFile::NewL( iFramework.Fs(),
   171         iFileObject = CMTPTypeFile::NewL( iFramework.Fs(), iFileSuid, EFileRead );
   160         fileSuid,
   172         SendDataL( *iFileObject );
   161         ( TFileMode ) ( EFileRead | EFileShareReadersOnly ),
   173         }
   162         iPartialDataLength,
   174     else
   163         iOffset );
   175         {
   164 
   176         // Send partial file fragment back.
   165     SendDataL( *iFileObject );
   177         BuildPartialDataL();
   166 
   178         delete iPartialData;
       
   179         iPartialData = NULL;
       
   180         iPartialData  = new (ELeave) TMTPTypeFlatBuf( iBufferPtr8 );
       
   181         SendDataL( *iPartialData );
       
   182         }
       
   183     PRINT( _L( "MM MTP <= CGetPartialObject::ServiceL" ) );
   167     PRINT( _L( "MM MTP <= CGetPartialObject::ServiceL" ) );
   184     }
   168     }
   185 
   169 
   186 // -----------------------------------------------------------------------------
   170 // -----------------------------------------------------------------------------
   187 // CGetPartialObject::DoHandleResponsePhaseL
   171 // CGetPartialObject::DoHandleResponsePhaseL
   189 // -----------------------------------------------------------------------------
   173 // -----------------------------------------------------------------------------
   190 //
   174 //
   191 EXPORT_C TBool CGetPartialObject::DoHandleResponsePhaseL()
   175 EXPORT_C TBool CGetPartialObject::DoHandleResponsePhaseL()
   192     {
   176     {
   193     PRINT( _L( "MM MTP => CGetPartialObject::DoHandleResponsePhaseL" ) );
   177     PRINT( _L( "MM MTP => CGetPartialObject::DoHandleResponsePhaseL" ) );
   194     TUint32 dataLength = iPartialDataLength;
   178 
   195     PRINT1( _L( "MM MTP <> CGetPartialObject::DoHandleResponsePhaseL dataLength = %d" ), dataLength );
   179     TUint32 dataLength = iFileObject->GetByteSent();
   196     SendResponseL( EMTPRespCodeOK, 1, &dataLength );
   180     SendResponseL( EMTPRespCodeOK, 1, &dataLength );
   197     PRINT( _L( "MM MTP <= CGetPartialObject::DoHandleResponsePhaseL" ) );
   181 
       
   182     PRINT1( _L( "MM MTP <= CGetPartialObject::DoHandleResponsePhaseL dataLength = %d" ), dataLength );
   198     return EFalse;
   183     return EFalse;
   199     }
   184     }
   200 
   185 
   201 // -----------------------------------------------------------------------------
       
   202 // CGetPartialObject::ConstructL()
       
   203 // Second-phase construction
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 void CGetPartialObject::ConstructL()
       
   207     {
       
   208     SetPSStatus();
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CGetPartialObject::BuildPartialDataL()
       
   213 // Populate the partial data object
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 void CGetPartialObject::BuildPartialDataL()
       
   217     {
       
   218     PRINT( _L( "MM MTP => CGetPartialObject::BuildPartialDataL" ) );
       
   219     __ASSERT_DEBUG( iRequestChecker, Panic( EMmMTPDpRequestCheckNull ) );
       
   220 
       
   221     if ( iBuffer )
       
   222         {
       
   223         delete iBuffer;
       
   224         iBuffer = NULL;
       
   225         }
       
   226 
       
   227     // We might fail if we have insufficient memory...
       
   228     iBuffer = HBufC8::NewL( iPartialDataLength );
       
   229     iBuffer->Des().Zero();
       
   230     iBufferPtr8.Set( iBuffer->Des() );
       
   231 
       
   232     RFile file;
       
   233     User::LeaveIfError( file.Open( iFs, iFileSuid, EFileRead ) );
       
   234     CleanupClosePushL( file ); // + file
       
   235     User::LeaveIfError( file.Read( iOffset, iBufferPtr8, iPartialDataLength ) );
       
   236     CleanupStack::PopAndDestroy( &file ); // - file
       
   237     PRINT( _L( "MM MTP <= CGetPartialObject::BuildPartialDataL" ) );
       
   238     }
       
   239 
       
   240 // end of file
   186 // end of file