mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/cgetpartialobject.cpp
branchRCL_3
changeset 8 bee149131e4b
parent 0 a2952bb97e68
child 9 05b0d2323768
equal deleted inserted replaced
4:d45095c2f4f3 8:bee149131e4b
    21 #include <mtp/cmtpobjectmetadata.h>
    21 #include <mtp/cmtpobjectmetadata.h>
    22 
    22 
    23 #include "cgetpartialobject.h"
    23 #include "cgetpartialobject.h"
    24 #include "mmmtpdplogger.h"
    24 #include "mmmtpdplogger.h"
    25 #include "tmmmtpdppanic.h"
    25 #include "tmmmtpdppanic.h"
    26 #include "ttypeflatbuf.h"
       
    27 #include "mmmtpdpconfig.h"
    26 #include "mmmtpdpconfig.h"
    28 
    27 
    29 /**
    28 /**
    30 * Verification data for the GetPartialObject request
    29 * Verification data for the GetPartialObject request
    31 */
    30 */
    39 // Two-phase construction method
    38 // Two-phase construction method
    40 // -----------------------------------------------------------------------------
    39 // -----------------------------------------------------------------------------
    41 //
    40 //
    42 EXPORT_C MMmRequestProcessor* CGetPartialObject::NewL( MMTPDataProviderFramework& aFramework,
    41 EXPORT_C MMmRequestProcessor* CGetPartialObject::NewL( MMTPDataProviderFramework& aFramework,
    43     MMTPConnection& aConnection,
    42     MMTPConnection& aConnection,
    44     MMmMtpDpConfig& aDpConfig )
    43     MMmMtpDpConfig& /*aDpConfig*/ )
    45     {
    44     {
    46     CGetPartialObject* self = new (ELeave) CGetPartialObject( aFramework, aConnection );
    45     CGetPartialObject* self = new (ELeave) CGetPartialObject( aFramework, aConnection );
    47     CleanupStack::PushL( self );
    46     CleanupStack::PushL( self );
    48     self->ConstructL();
    47     self->ConstructL();
    49     CleanupStack::Pop( self );
    48     CleanupStack::Pop( self );
    55 // Destructor
    54 // Destructor
    56 // -----------------------------------------------------------------------------
    55 // -----------------------------------------------------------------------------
    57 //
    56 //
    58 EXPORT_C CGetPartialObject::~CGetPartialObject()
    57 EXPORT_C CGetPartialObject::~CGetPartialObject()
    59     {
    58     {
    60     delete iBuffer;
       
    61     delete iPartialData;
       
    62     delete iFileObject;
    59     delete iFileObject;
    63     }
    60     }
    64 
    61 
    65 // -----------------------------------------------------------------------------
    62 // -----------------------------------------------------------------------------
    66 // CGetPartialObject::CGetPartialObject
    63 // CGetPartialObject::CGetPartialObject
    67 // Standard c++ constructor
    64 // Standard c++ constructor
    68 // -----------------------------------------------------------------------------
    65 // -----------------------------------------------------------------------------
    69 //
    66 //
    70 EXPORT_C CGetPartialObject::CGetPartialObject( MMTPDataProviderFramework& aFramework,
    67 EXPORT_C CGetPartialObject::CGetPartialObject( MMTPDataProviderFramework& aFramework,
    71     MMTPConnection& aConnection ) :
    68     MMTPConnection& aConnection ) :
    72     CRequestProcessor( aFramework,
    69         CRequestProcessor( aFramework,
    73         aConnection,
    70             aConnection,
    74         sizeof( KMTPGetPartialObjectPolicy ) / sizeof( TMTPRequestElementInfo ),
    71             sizeof( KMTPGetPartialObjectPolicy ) / sizeof( TMTPRequestElementInfo ),
    75         KMTPGetPartialObjectPolicy ),
    72             KMTPGetPartialObjectPolicy ),
    76     iFramework ( aFramework ),
    73         iFramework ( aFramework )
    77     iFs( iFramework.Fs() ),
       
    78     iBufferPtr8( NULL, 0 )
       
    79     {
    74     {
    80     PRINT( _L( "Operation: GetPartialObject(0x101B)" ) );
    75     PRINT( _L( "Operation: GetPartialObject(0x101B)" ) );
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CGetPartialObject::ConstructL()
       
    80 // Second-phase construction
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CGetPartialObject::ConstructL()
       
    84     {
       
    85     SetPSStatus();
    81     }
    86     }
    82 
    87 
    83 // -----------------------------------------------------------------------------
    88 // -----------------------------------------------------------------------------
    84 // CGetPartialObject::CheckRequestL
    89 // CGetPartialObject::CheckRequestL
    85 // Check the GetPartialObject reqeust
    90 // Check the GetPartialObject reqeust
   104 // -----------------------------------------------------------------------------
   109 // -----------------------------------------------------------------------------
   105 //
   110 //
   106 TBool CGetPartialObject::VerifyParametersL()
   111 TBool CGetPartialObject::VerifyParametersL()
   107     {
   112     {
   108     PRINT( _L( "MM MTP => CGetPartialObject::VerifyParametersL" ) );
   113     PRINT( _L( "MM MTP => CGetPartialObject::VerifyParametersL" ) );
       
   114 
   109     __ASSERT_DEBUG( iRequestChecker, Panic( EMmMTPDpRequestCheckNull ) );
   115     __ASSERT_DEBUG( iRequestChecker, Panic( EMmMTPDpRequestCheckNull ) );
   110     TBool result = EFalse;
   116     TBool result = EFalse;
   111     iObjectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
   117     iObjectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
   112     PRINT1( _L( "MM MTP <> CGetPartialObject::VerifyParametersL iObjectHandle = 0x%x" ), iObjectHandle );
       
   113     iOffset = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
   118     iOffset = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
   114     PRINT1( _L( "MM MTP <> CGetPartialObject::VerifyParametersL iOffset = %d" ), iOffset );
   119     iPartialDataLength = Request().Uint32( TMTPTypeRequest::ERequestParameter3 );
   115     TUint32 maxLength = Request().Uint32( TMTPTypeRequest::ERequestParameter3 );
   120 
   116     PRINT1( _L( "MM MTP <> CGetPartialObject::VerifyParametersL maxLength = %d" ), maxLength );
   121     PRINT3( _L( "MM MTP <> CGetPartialObject::VerifyParametersL iObjectHandle = 0x%x, iOffset = 0x%x, iMaxLength = 0x%x " ),
       
   122         iObjectHandle,
       
   123         iOffset,
       
   124         iPartialDataLength );
   117 
   125 
   118     //get object info, but do not have the ownship of the object
   126     //get object info, but do not have the ownship of the object
   119     CMTPObjectMetaData* objectInfo = iRequestChecker->GetObjectInfo( iObjectHandle );
   127     CMTPObjectMetaData* objectInfo = iRequestChecker->GetObjectInfo( iObjectHandle );
   120     __ASSERT_DEBUG( objectInfo, Panic( EMmMTPDpObjectNull ) );
   128     __ASSERT_DEBUG( objectInfo, Panic( EMmMTPDpObjectNull ) );
   121 
   129 
   122     const TDesC& suid( objectInfo->DesC( CMTPObjectMetaData::ESuid ) );
   130     const TDesC& suid( objectInfo->DesC( CMTPObjectMetaData::ESuid ) );
   123     PRINT1( _L( "MM MTP <> CGetPartialObject::VerifyParametersL suid = %S" ), &suid );
   131     PRINT1( _L( "MM MTP <> CGetPartialObject::VerifyParametersL suid = %S" ), &suid );
   124 
   132 
   125     if ( objectInfo->Uint( CMTPObjectMetaData::EDataProviderId )
       
   126         == iFramework.DataProviderId() )
       
   127         result = ETrue;
       
   128 
       
   129     TEntry fileEntry;
   133     TEntry fileEntry;
   130     User::LeaveIfError( iFs.Entry( suid, fileEntry ) );
   134     User::LeaveIfError( iFramework.Fs().Entry( suid, fileEntry ) );
   131     TInt64 fileSize = fileEntry.iSize;
   135     if ( iOffset < fileEntry.FileSize() )
   132     if( ( iOffset < fileEntry.iSize ) && result )
       
   133         {
   136         {
   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;
   137         result = ETrue;
   145         }
   138         }
   146     PRINT1( _L( "MM MTP <> CGetPartialObject::VerifyParametersL iPartialDataLength = %d" ), iPartialDataLength );
       
   147 
   139 
   148     PRINT1( _L( "MM MTP <= CGetPartialObject::VerifyParametersL result = %d" ), result );
   140     PRINT1( _L( "MM MTP <= CGetPartialObject::VerifyParametersL result = %d" ), result );
   149     return result;
   141     return result;
   150     }
   142     }
   151 
   143 
   155 // -----------------------------------------------------------------------------
   147 // -----------------------------------------------------------------------------
   156 //
   148 //
   157 EXPORT_C void CGetPartialObject::ServiceL()
   149 EXPORT_C void CGetPartialObject::ServiceL()
   158     {
   150     {
   159     PRINT( _L( "MM MTP => CGetPartialObject::ServiceL" ) );
   151     PRINT( _L( "MM MTP => CGetPartialObject::ServiceL" ) );
       
   152 
   160     // Get file information
   153     // Get file information
   161     CMTPObjectMetaData* objectInfo = iRequestChecker->GetObjectInfo( iObjectHandle );
   154     CMTPObjectMetaData* objectInfo = iRequestChecker->GetObjectInfo( iObjectHandle );
   162     __ASSERT_DEBUG( objectInfo, Panic( EMmMTPDpObjectNull ) );
   155     __ASSERT_DEBUG( objectInfo, Panic( EMmMTPDpObjectNull ) );
   163     iFileSuid.SetLength( 0 );
   156     TBuf<KMaxFileName> fileSuid;
   164     iFileSuid.Append( objectInfo->DesC( CMTPObjectMetaData::ESuid ) );
   157     fileSuid.Append( objectInfo->DesC( CMTPObjectMetaData::ESuid ) );
   165 
   158 
   166     if ( iCompleteFile )
   159     iFileObject = CMTPTypeFile::NewL( iFramework.Fs(),
   167         {
   160         fileSuid,
   168         // Pass the complete file back to the host
   161         ( TFileMode ) ( EFileRead | EFileShareReadersOnly ),
   169         delete iFileObject;
   162         iPartialDataLength,
   170         iFileObject = NULL;
   163         iOffset );
   171         iFileObject = CMTPTypeFile::NewL( iFramework.Fs(), iFileSuid, EFileRead );
   164 
   172         SendDataL( *iFileObject );
   165     SendDataL( *iFileObject );
   173         }
   166 
   174     else
       
   175         {
       
   176         // Send partial file fragment back.
       
   177         BuildPartialDataL();
       
   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