mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/csendobject.cpp
branchRCL_3
changeset 14 05b0d2323768
parent 9 bee149131e4b
child 17 780c925249c1
equal deleted inserted replaced
9:bee149131e4b 14:05b0d2323768
   107 // -----------------------------------------------------------------------------
   107 // -----------------------------------------------------------------------------
   108 //
   108 //
   109 CSendObject::CSendObject( MMTPDataProviderFramework& aFramework,
   109 CSendObject::CSendObject( MMTPDataProviderFramework& aFramework,
   110     MMTPConnection& aConnection,
   110     MMTPConnection& aConnection,
   111     MMmMtpDpConfig& aDpConfig ) :
   111     MMmMtpDpConfig& aDpConfig ) :
   112         CRequestProcessor( aFramework, aConnection, 0, NULL),
   112         CRequestProcessor( aFramework, aConnection, 0, NULL ),
   113         iFs( iFramework.Fs() ),
   113         iFs( iFramework.Fs() ),
   114         iObjectMgr( iFramework.ObjectMgr() ),
   114         iObjectMgr( iFramework.ObjectMgr() ),
   115         iDpConfig( aDpConfig )
   115         iDpConfig( aDpConfig )
   116     {
   116     {
   117     PRINT( _L( "Operation: SendObjectInfo/SendObject/SendObjectPropList(0x100C/0x100D/0x9808)" ) );
   117     PRINT( _L( "Operation: SendObjectInfo/SendObject/SendObjectPropList(0x100C/0x100D/0x9808)" ) );
   579     {
   579     {
   580     PRINT( _L( "MM MTP => CSendObject::DoHandleResponsePhaseObjectL" ) );
   580     PRINT( _L( "MM MTP => CSendObject::DoHandleResponsePhaseObjectL" ) );
   581 
   581 
   582     TBool result = ETrue;
   582     TBool result = ETrue;
   583 
   583 
   584     delete iFileReceived;
       
   585     iFileReceived = NULL;
       
   586 
       
   587     TEntry fileEntry;
   584     TEntry fileEntry;
   588     User::LeaveIfError( iFs.Entry( iFullPath, fileEntry ) );
   585     User::LeaveIfError( iFs.Entry( iFullPath, fileEntry ) );
   589     if ( fileEntry.FileSize() != iObjectSize )
   586     if ( fileEntry.FileSize() != iObjectSize )
   590         {
   587         {
   591         iFs.Delete( iFullPath );
   588         iFs.Delete( iFullPath );
   609         }
   606         }
   610     else if ( result && !iCancelled )
   607     else if ( result && !iCancelled )
   611         {
   608         {
   612         if ( iObjectSize > 0 ) // media file
   609         if ( iObjectSize > 0 ) // media file
   613             {
   610             {
   614             AddMediaToStoreL();
   611             TRAPD( err, AddMediaToStoreL() );
   615 
   612             PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL err = %d" ), err );
   616             if( iPreviousOperation == EMTPOpCodeSendObjectPropList )
   613 
   617                 {
   614             if ( ( iPreviousOperation == EMTPOpCodeSendObjectPropList )
   618                 SetObjectPropListL( *iObjectPropList );
   615                 && ( err == KErrNone ) )
       
   616                 {
       
   617                 // Only leave when getting proplist element from data received by fw.
       
   618                 // It should not happen after ReceiveDataL in which construction of proplist already succeed.
       
   619                 SetObjectPropListL();
   619                 }
   620                 }
   620 
   621 
   621             // Commits into MTP data object enumeration store the object handle and
   622             // Commits into MTP data object enumeration store the object handle and
   622             // storage space previously reserved for the specified object.
   623             // storage space previously reserved for the specified object.
   623             iFramework.ObjectMgr().CommitReservedObjectHandleL( *iReceivedObjectInfo );
   624             iFramework.ObjectMgr().CommitReservedObjectHandleL( *iReceivedObjectInfo );
   886 // -----------------------------------------------------------------------------
   887 // -----------------------------------------------------------------------------
   887 // CSendObject::SetObjectPropListL
   888 // CSendObject::SetObjectPropListL
   888 // Reserve object proplist into database
   889 // Reserve object proplist into database
   889 // -----------------------------------------------------------------------------
   890 // -----------------------------------------------------------------------------
   890 //
   891 //
   891 TMTPResponseCode CSendObject::SetObjectPropListL( const CMTPTypeObjectPropList& aPropList )
   892 TMTPResponseCode CSendObject::SetObjectPropListL()
   892     {
   893     {
   893     PRINT( _L( "MM MTP => CSendObject::SetObjectPropListL" ) );
   894     PRINT( _L( "MM MTP => CSendObject::SetObjectPropListL" ) );
   894 
   895 
   895     TMTPResponseCode responseCode( EMTPRespCodeOK );
   896     TMTPResponseCode responseCode( EMTPRespCodeOK );
   896 
   897 
   901         const CMTPTypeObjectPropListElement& element( iObjectPropList->GetNextElementL() );
   902         const CMTPTypeObjectPropListElement& element( iObjectPropList->GetNextElementL() );
   902 
   903 
   903         TUint16 propertyCode = element.Uint16L( CMTPTypeObjectPropListElement::EPropertyCode );
   904         TUint16 propertyCode = element.Uint16L( CMTPTypeObjectPropListElement::EPropertyCode );
   904         TUint16 dataType = element.Uint16L( CMTPTypeObjectPropListElement::EDatatype );
   905         TUint16 dataType = element.Uint16L( CMTPTypeObjectPropListElement::EDatatype );
   905         PRINT2( _L( "MM MTP <> SetObjectPropListL propertyCode = 0x%x, dataType = 0x%x" ),
   906         PRINT2( _L( "MM MTP <> SetObjectPropListL propertyCode = 0x%x, dataType = 0x%x" ),
   906             propertyCode, dataType );
   907             propertyCode,
       
   908             dataType );
   907 
   909 
   908         switch ( propertyCode )
   910         switch ( propertyCode )
   909             {
   911             {
   910             case EMTPObjectPropCodeStorageID:
   912             case EMTPObjectPropCodeStorageID:
   911             case EMTPObjectPropCodeObjectFormat:
   913             case EMTPObjectPropCodeObjectFormat:
   922 
   924 
   923             case EMTPObjectPropCodeDateAdded:
   925             case EMTPObjectPropCodeDateAdded:
   924             case EMTPObjectPropCodeDateCreated:
   926             case EMTPObjectPropCodeDateCreated:
   925             case EMTPObjectPropCodeDateModified:
   927             case EMTPObjectPropCodeDateModified:
   926             case EMTPObjectPropCodeObjectFileName:
   928             case EMTPObjectPropCodeObjectFileName:
   927                 // TODO: Does anything need to be done on these read-only properties?
   929                 // Do nothing for read-only properties
   928                 /* spec:
   930                 /* spec:
   929                  * Object properties that are get-only (0x00 GET)
   931                  * Object properties that are get-only (0x00 GET)
   930                  * should accept values during object creation by
   932                  * should accept values during object creation by
   931                  * way of the SendObjectPropList command.
   933                  * way of the SendObjectPropList command.
   932                  */
   934                  */
   933                 break;
   935                 break;
   934 
   936 
   935             case EMTPObjectPropCodeProtectionStatus:
   937             case EMTPObjectPropCodeProtectionStatus:
   936                 SetProtectionStatusL();
   938                 // Already done in AddMediaToStore, it's not necessary to set it again.
       
   939                 // SetProtectionStatus();
   937                 break;
   940                 break;
   938 
   941 
   939             case EMTPObjectPropCodeName:
   942             case EMTPObjectPropCodeName:
   940                 {
   943                 {
   941                 CMTPTypeString* stringData = CMTPTypeString::NewLC( element.StringL( CMTPTypeObjectPropListElement::EValue ) );// + stringData
   944                 CMTPTypeString* stringData = CMTPTypeString::NewLC( element.StringL( CMTPTypeObjectPropListElement::EValue ) );// + stringData
   942 
   945 
   943                 responseCode = iDpConfig.PropSettingUtility()->SetMetaDataToWrapperL( iDpConfig,
   946                 responseCode = iDpConfig.PropSettingUtility()->SetMetaDataToWrapper( iDpConfig,
   944                     propertyCode,
   947                     propertyCode,
   945                     *stringData,
   948                     *stringData,
   946                     *iReceivedObjectInfo );
   949                     *iReceivedObjectInfo );
   947 
   950 
   948                 CleanupStack::PopAndDestroy( stringData );// - stringData
   951                 CleanupStack::PopAndDestroy( stringData );// - stringData
  1154         iObjectFormat );
  1157         iObjectFormat );
  1155 
  1158 
  1156     // Reserves space for and assigns an object handle to the object described
  1159     // Reserves space for and assigns an object handle to the object described
  1157     // by the specified object information record.
  1160     // by the specified object information record.
  1158     TRAP( err, iObjectMgr.ReserveObjectHandleL( *iReceivedObjectInfo,
  1161     TRAP( err, iObjectMgr.ReserveObjectHandleL( *iReceivedObjectInfo,
  1159                 iObjectSize ) );
  1162         iObjectSize ) );
  1160 
  1163 
  1161     PRINT2( _L( "MM MTP => CSendObject::ReserveObjectL iObjectsize = %Lu, Operation: 0x%x" ), iObjectSize, iOperationCode );
  1164     PRINT2( _L( "MM MTP => CSendObject::ReserveObjectL iObjectsize = %Lu, Operation: 0x%x" ), iObjectSize, iOperationCode );
  1162     if ( err != KErrNone )
  1165     if ( err != KErrNone )
  1163         PRINT1( _L( "MM MTP <> CSendObject::ReserveObjectL err = %d" ), err );
  1166         PRINT1( _L( "MM MTP <> CSendObject::ReserveObjectL err = %d" ), err );
  1164     if ( iObjectSize == 0 )
  1167     if ( iObjectSize == 0 )
  1165         {
  1168         {
       
  1169         // Already trapped inside SaveEmptyFileL.
  1166         SaveEmptyFileL();
  1170         SaveEmptyFileL();
  1167         SetObjectPropListL( *iObjectPropList );
  1171         if( iOperationCode == EMTPOpCodeSendObjectPropList )
       
  1172             {
       
  1173             // Only leave when getting proplist element from data received by fw.
       
  1174             // It should not happen after ReceiveDataL in which construction of proplist already succeed.
       
  1175             SetObjectPropListL();
       
  1176             }
       
  1177 
  1168         iObjectMgr.CommitReservedObjectHandleL( *iReceivedObjectInfo );
  1178         iObjectMgr.CommitReservedObjectHandleL( *iReceivedObjectInfo );
  1169         }
  1179         }
  1170 
  1180 
  1171     iExpectedSendObjectRequest.SetUint32( TMTPTypeRequest::ERequestSessionID,
  1181     iExpectedSendObjectRequest.SetUint32( TMTPTypeRequest::ERequestSessionID,
  1172         iSessionId );
  1182         iSessionId );
  1180 
  1190 
  1181     PRINT( _L( "MM MTP <= CSendObject::ReserveObjectL" ) );
  1191     PRINT( _L( "MM MTP <= CSendObject::ReserveObjectL" ) );
  1182     }
  1192     }
  1183 
  1193 
  1184 // -----------------------------------------------------------------------------
  1194 // -----------------------------------------------------------------------------
  1185 // CSendObject::SetProtectionStatusL
  1195 // CSendObject::SetProtectionStatus
  1186 // -----------------------------------------------------------------------------
  1196 // -----------------------------------------------------------------------------
  1187 //
  1197 //
  1188 void CSendObject::SetProtectionStatusL()
  1198 void CSendObject::SetProtectionStatus()
  1189     {
  1199     {
  1190     PRINT1( _L( "MM MTP => CSendObject::SetProtectionStatusL iProtectionStatus = %d" ), iProtectionStatus );
  1200     PRINT1( _L( "MM MTP => CSendObject::SetProtectionStatus iProtectionStatus = %d" ), iProtectionStatus );
  1191 
  1201 
  1192     if ( iProtectionStatus == EMTPProtectionNoProtection
  1202     if ( iFileReceived != NULL )
  1193         || iProtectionStatus == EMTPProtectionReadOnly )
  1203         {
  1194         {
  1204         if ( iProtectionStatus == EMTPProtectionNoProtection
  1195         // TODO: wait for review
  1205             || iProtectionStatus == EMTPProtectionReadOnly )
  1196         TInt err = KErrNone;
  1206             {
  1197         if ( iProtectionStatus == EMTPProtectionNoProtection )
  1207             TInt err = KErrNone;
  1198             {
  1208             if ( iProtectionStatus == EMTPProtectionNoProtection )
  1199             err = iFs.SetAtt( iFullPath, KEntryAttNormal, KEntryAttReadOnly );
  1209                 {
  1200             }
  1210                 err = iFileReceived->File().SetAtt( KEntryAttNormal, KEntryAttReadOnly );
  1201         else
  1211                 }
  1202             {
  1212             else
  1203             err = iFs.SetAtt( iFullPath, KEntryAttReadOnly, KEntryAttNormal );
  1213                 {
  1204             }
  1214                 err = iFileReceived->File().SetAtt( KEntryAttReadOnly, KEntryAttNormal );
  1205         User::LeaveIfError( err );
  1215                 }
  1206         }
  1216     
  1207     PRINT( _L( "MM MTP <= CSendObject::SetProtectionStatusL" ) );
  1217             if ( err != KErrNone )
       
  1218                 {
       
  1219                 PRINT1( _L("MM MTP <> CSendObject::SetProtectionStatus err = %d" ), err );
       
  1220                 }
       
  1221             }
       
  1222         // Close the file after SetProtectionStatus to make sure other process won't open
       
  1223         // the file successfully right at the time calling RFile::SetAtt.
       
  1224         delete iFileReceived;
       
  1225         iFileReceived = NULL;
       
  1226         }
       
  1227 
       
  1228     PRINT( _L( "MM MTP <= CSendObject::SetProtectionStatus" ) );
  1208     }
  1229     }
  1209 
  1230 
  1210 // -----------------------------------------------------------------------------
  1231 // -----------------------------------------------------------------------------
  1211 // CSendObject::SaveEmptyFileL
  1232 // CSendObject::SaveEmptyFileL
  1212 // -----------------------------------------------------------------------------
  1233 // -----------------------------------------------------------------------------
  1215     {
  1236     {
  1216     PRINT( _L( "MM MTP => CSendObject::SaveEmptyFileL" ) );
  1237     PRINT( _L( "MM MTP => CSendObject::SaveEmptyFileL" ) );
  1217 
  1238 
  1218     RFile file;
  1239     RFile file;
  1219     User::LeaveIfError( file.Create( iFs, iFullPath, EFileWrite ) );
  1240     User::LeaveIfError( file.Create( iFs, iFullPath, EFileWrite ) );
  1220     file.Close();
  1241     CleanupClosePushL( file );  // + file
  1221 
       
  1222     // set entry protection status and modified date
       
  1223     SetProtectionStatusL();
       
  1224 
       
  1225     // add playlist to MPX DB
       
  1226     TParsePtrC parse( iFullPath );
       
  1227     iDpConfig.GetWrapperL().SetStorageRootL( parse.Drive() );
       
  1228     iDpConfig.GetWrapperL().AddObjectL( iFullPath, iObjectFormat, EMTPSubFormatCodeUnknown );
       
  1229 
  1242 
  1230     if ( EMTPFormatCodeAbstractAudioVideoPlaylist == iObjectFormat )
  1243     if ( EMTPFormatCodeAbstractAudioVideoPlaylist == iObjectFormat )
  1231         {
  1244         {
  1232         TInt err = KErrNone;
  1245         TInt err = KErrNone;
  1233         err = iFs.SetAtt( iFullPath,
  1246         err = file.SetAtt( KEntryAttSystem | KEntryAttHidden,
  1234             KEntryAttSystem | KEntryAttHidden,
       
  1235             KEntryAttReadOnly | KEntryAttNormal );
  1247             KEntryAttReadOnly | KEntryAttNormal );
  1236         if ( err != KErrNone )
  1248         if ( err != KErrNone )
  1237             PRINT1( _L( "MM MTP <> CSendObject::SaveEmptyFileL err = %d" ), err );
  1249             PRINT1( _L( "MM MTP <> CSendObject::SaveEmptyFileL err = %d" ), err );
  1238         iDpConfig.GetWrapperL().AddDummyFileL( iFullPath );
  1250         iDpConfig.GetWrapperL().AddDummyFileL( iFullPath );
  1239         }
  1251         }
  1240 
  1252     CleanupStack::PopAndDestroy( &file );   // - file
  1241     PRINT( _L( "MM MTP <= CSendObject::SaveEmptyFileL" ) );
  1253 
       
  1254     // add playlist to MPX DB
       
  1255     TRAPD( err, AddMediaToStoreL() );
       
  1256 
       
  1257     if ( err != KErrNone )
       
  1258         {
       
  1259         // Ignore err even add into MPX get failed.
       
  1260         }
       
  1261 
       
  1262     PRINT1( _L( "MM MTP <= CSendObject::SaveEmptyFileLerr = %d" ), err );
  1242     }
  1263     }
  1243 
  1264 
  1244 // -----------------------------------------------------------------------------
  1265 // -----------------------------------------------------------------------------
  1245 // CSendObject::AddMediaToStoreL()
  1266 // CSendObject::AddMediaToStoreL()
  1246 //
  1267 //
  1248 //
  1269 //
  1249 void CSendObject::AddMediaToStoreL()
  1270 void CSendObject::AddMediaToStoreL()
  1250     {
  1271     {
  1251     PRINT( _L( "MM MTP => CSendObject::AddMediaToStoreL" ) );
  1272     PRINT( _L( "MM MTP => CSendObject::AddMediaToStoreL" ) );
  1252 
  1273 
       
  1274     // SetProtectionStatus here make sure no matter the previous operation is SendObjectInfo
       
  1275     // or SendObjectPropList
       
  1276     // Might need to set dateadded and datemodify for further extension.
       
  1277     SetProtectionStatus();
       
  1278 
  1253     TBool isVideo = EFalse;
  1279     TBool isVideo = EFalse;
  1254     TMmMtpSubFormatCode subFormatCode;
  1280     TMmMtpSubFormatCode subFormatCode = EMTPSubFormatCodeUnknown;
  1255     switch ( iObjectFormat )
  1281     switch ( iObjectFormat )
  1256         {
  1282         {
  1257         case EMTPFormatCode3GPContainer:
  1283         case EMTPFormatCode3GPContainer:
  1258         case EMTPFormatCodeMP4Container:
  1284         case EMTPFormatCodeMP4Container:
  1259         case EMTPFormatCodeASF:
  1285         case EMTPFormatCodeASF:
  1260             {
  1286             {
  1261 
  1287             if ( MmMtpDpUtility::IsVideo( iFullPath ) )
  1262             if ( MmMtpDpUtility::IsVideoL( iFullPath ) )
       
  1263                 {
  1288                 {
  1264                 subFormatCode = EMTPSubFormatCodeVideo;
  1289                 subFormatCode = EMTPSubFormatCodeVideo;
  1265                 isVideo = ETrue;
  1290                 isVideo = ETrue;
  1266                 }
  1291                 }
  1267             else
  1292             else
  1285         default:
  1310         default:
  1286             PRINT( _L( "MM MTP <> CSendObject::DoHandleResponsePhaseObjectL default" ) );
  1311             PRINT( _L( "MM MTP <> CSendObject::DoHandleResponsePhaseObjectL default" ) );
  1287             break;
  1312             break;
  1288         }
  1313         }
  1289 
  1314 
  1290     TPtrC suid( iReceivedObjectInfo->DesC( CMTPObjectMetaData::ESuid ) );
  1315     iDpConfig.GetWrapperL().SetStorageRootL( iFullPath );
  1291     PRINT1( _L( "MM MTP <> CSendObject::AddMediaToStoreL suid = %S" ), &suid );
  1316     PRINT1( _L( "MM MTP <> CSendObject::AddMediaToStoreL iFullPath = %S" ), &iFullPath );
  1292     TParsePtrC parse( suid );
       
  1293     iDpConfig.GetWrapperL().SetStorageRootL( parse.Drive() );
       
  1294     iDpConfig.GetWrapperL().AddObjectL( iFullPath, iObjectFormat, subFormatCode );
  1317     iDpConfig.GetWrapperL().AddObjectL( iFullPath, iObjectFormat, subFormatCode );
  1295 
  1318 
  1296     if ( isVideo )
  1319     if ( isVideo )
  1297         {
  1320         {
  1298         TInt err = KErrNone;
  1321         iDpConfig.GetWrapperL().SetImageObjPropL( iFullPath, iWidth, iHeight );
  1299             TRAP( err, iDpConfig.GetWrapperL().SetImageObjPropL( iFullPath, iWidth, iHeight ) );
       
  1300 
       
  1301         PRINT1( _L( "MM MTP <= CSendObject::AddVideoToStoreL err = %d" ), err );
       
  1302         }
  1322         }
  1303 
  1323 
  1304     PRINT( _L( "MM MTP <= CSendObject::AddMediaToStoreL" ) );
  1324     PRINT( _L( "MM MTP <= CSendObject::AddMediaToStoreL" ) );
  1305     }
  1325     }
  1306 
  1326